Subject: Re: bug#61448: [PATCH] ignu: opencv: Update to 4.6.0

From: Maxim Cournoyer <[email-masked]>
Date: Wed, 22 Mar 2023 14:21:10 -0400

Hello,

Andy Tai <[email-masked]> writes:

> * gnu/packages/image-processing.scm (opencv-next): New variable
>   as opencv (4.5.4) is depended on by aiscm which does not build
>   with later opencv (4.6.0 and later) so make later opencv release
>   as opencv-next, now at version 4.7.0

There's no need to repeat the explanation in the change log, as it's
written in the code as a comment, where it belongs.

> ---
>  gnu/packages/image-processing.scm | 79 +++++++++++++++++++++++++++++++
>  1 file changed, 79 insertions(+)
>
> diff --git a/gnu/packages/image-processing.scm b/gnu/packages/image-processing.scm
> index 70c820e76b..0482984e32 100644
> --- a/gnu/packages/image-processing.scm
> +++ b/gnu/packages/image-processing.scm
> @@ -673,6 +673,85 @@ (define-public opencv
>      (home-page "https://opencv.org/")
>      (license license:bsd-3)))
>  
> +;; aiscm depends on opencv 4.5.4 so we cannot just update opencv to 4.7.0
> +;; for now we place newer opencv as opencv-next
> +(define-public opencv-next
> +  (package
> +    (inherit opencv)
> +    (name "opencv-next")

You can leave the name as "opencv", so users doing 'guix install opencv'
will get the latest version.  The only time where it may be better use
use "-next" in the name, is when both versions are expected to be
propagated together and found in the same profile, where they'd conflict
if same-named (that's very niche though).

> +    (version "4.7.0")
> +    (source (origin
> +              (method git-fetch)
> +              (uri (git-reference
> +                    (url "https://github.com/opencv/opencv")
> +                    (commit version)))
> +              (file-name (git-file-name name version))
> +              (sha256
> +               (base32
> +                "0l45v41nns2jmn9nr9fb0yvhqzfjpxjxn75i1c02rsfy3r3lv22v"))
> +              (modules '((guix build utils)))
> +              (snippet '(begin
> +                          ;; Remove external libraries. We have almost all available
> +                          ;; in Guix:
> +                          (with-directory-excursion "3rdparty"
> +                            (for-each delete-file-recursively
> +                                      '("carotene" "cpufeatures"
> +                                        "ffmpeg"
> +                                        "include"
> +                                        "ippicv"
> +                                        "ittnotify"
> +                                        "libjasper"
> +                                        "libjpeg"
> +                                        "libjpeg-turbo"
> +                                        "libpng"
> +                                        "libtengine"
> +                                        "libtiff"
> +                                        "libwebp"
> +                                        "openexr"
> +                                        "openjpeg"
> +                                        "openvx"
> +                                        "protobuf"
> +                                        ;; "quirc"
> +                                        "tbb"
> +                                        "zlib")))
> +
> +                          ;; Some jars found:
> +                          (for-each delete-file
> +                                    '("modules/java/test/pure_test/lib/junit-4.11.jar"

[...]

> +    (native-inputs `(("pkg-config" ,pkg-config)
> +                     ("xorg-server" ,xorg-server-for-tests) ;For running the tests
> +                     ("opencv-extra" ,(origin
> +                                        (method git-fetch)
> +                                        (uri (git-reference (url
> +                                                             "https://github.com/opencv/opencv_extra")
> +                                                            (commit version)))
> +                                        (file-name (git-file-name
> +                                                    "opencv_extra" version))
> +                                        (sha256 (base32
> +                                                 "0bdg5kwwdimnl2zp4ry5cmfxr9xb7zk2ml59853d90llsqjis47a"))))
> +                     ("opencv-contrib" ,(origin
> +                                          (method git-fetch)
> +                                          (uri (git-reference (url
> +                                                               "https://github.com/opencv/opencv_contrib")
> +                                                              (commit version)))
> +                                          (file-name (git-file-name
> +                                                      "opencv_contrib" version))
> +                                          (sha256 (base32
> +                                                   "0hbfn835kxh3hwmwvzgdglm2np1ri3z7nfnf60gf4x6ikp89mv4r"))))))

This indentation is way off; was this 'guix style'?

> +    (arguments
> +     (substitute-keyword-arguments (package-arguments opencv)
> +       ((#:phases phases
> +         '%standard-phases)
> +        `(modify-phases ,phases
> +           (add-after 'unpack 'disable-broken-tests-opencv-4.7-specific
> +             (lambda _
> +               (substitute* "modules/dnn/test/test_layers.cpp"
> +                 (("(TEST_P\\(Test_Caffe_layers, )(Interp\\).*)"
> +                   all pre post)
> +                  (string-append pre "DISABLED_" post)))))))))))
> +
>  (define-public vips
>    (package
>      (name "vips")
>
> base-commit: a97a102d21edc0c9624cf92c1fbc0c01b1067290

I've made the adjustments below;

--8<---------------cut here---------------start------------->8---
@@ -699,11 +699,11 @@ (define-public opencv
     (home-page "https://opencv.org/")
     (license license:bsd-3)))
 
-;; TODO: Make the default opencv after aiscm can use a newer one.
+;; TODO: Make this the default opencv after aiscm is able to use it.
 (define-public opencv-next
   (package
     (inherit opencv)
-    (name "opencv-next")
+    (name "opencv")
     (version "4.7.0")
     (source (origin
               (method git-fetch)
@@ -711,71 +711,70 @@ (define-public opencv-next
                     (url "https://github.com/opencv/opencv")
                     (commit version)))
               (file-name (git-file-name name version))
-              (sha256
-               (base32
-                "0l45v41nns2jmn9nr9fb0yvhqzfjpxjxn75i1c02rsfy3r3lv22v"))
               (modules '((guix build utils)))
-              (snippet '(begin
-                          ;; Remove external libraries. We have almost all available
-                          ;; in Guix:
-                          (with-directory-excursion "3rdparty"
-                            (for-each delete-file-recursively
-                                      '("carotene" "cpufeatures"
-                                        "ffmpeg"
-                                        "include"
-                                        "ippicv"
-                                        "ittnotify"
-                                        "libjasper"
-                                        "libjpeg"
-                                        "libjpeg-turbo"
-                                        "libpng"
-                                        "libtengine"
-                                        "libtiff"
-                                        "libwebp"
-                                        "openexr"
-                                        "openjpeg"
-                                        "openvx"
-                                        "protobuf"
-                                        ;; "quirc"
-                                        "tbb"
-                                        "zlib")))
-
-                          ;; Some jars found:
-                          (for-each delete-file
-                                    '("modules/java/test/pure_test/lib/junit-4.11.jar"
-                                      "samples/java/sbt/sbt/sbt-launch.jar"))))))
-    (native-inputs `(("pkg-config" ,pkg-config)
-                     ("xorg-server" ,xorg-server-for-tests) ;For running the tests
-                     ("opencv-extra" ,(origin
-                                        (method git-fetch)
-                                        (uri (git-reference (url
-                                                             "https://github.com/opencv/opencv_extra")
-                                                            (commit version)))
-                                        (file-name (git-file-name
-                                                    "opencv_extra" version))
-                                        (sha256 (base32
-                                                 "0bdg5kwwdimnl2zp4ry5cmfxr9xb7zk2ml59853d90llsqjis47a"))))
-                     ("opencv-contrib" ,(origin
-                                          (method git-fetch)
-                                          (uri (git-reference (url
-                                                               "https://github.com/opencv/opencv_contrib")
-                                                              (commit version)))
-                                          (file-name (git-file-name
-                                                      "opencv_contrib" version))
-                                          (sha256 (base32
-                                                   "0hbfn835kxh3hwmwvzgdglm2np1ri3z7nfnf60gf4x6ikp89mv4r"))))))
+              (snippet
+               '(begin
+                  ;; Remove external libraries.  Almost all of them are
+                  ;; available in Guix.
+                  (with-directory-excursion "3rdparty"
+                    (for-each delete-file-recursively
+                              '("carotene"
+                                "cpufeatures"
+                                "ffmpeg"
+                                "include"
+                                "ippicv"
+                                "ittnotify"
+                                "libjasper"
+                                "libjpeg"
+                                "libjpeg-turbo"
+                                "libpng"
+                                "libtengine"
+                                "libtiff"
+                                "libwebp"
+                                "openexr"
+                                "openjpeg"
+                                "openvx"
+                                "protobuf"
+                                ;;"quirc"
+                                "tbb"
+                                "zlib")))
 
+                  ;; Delete any bundled .jar files.
+                  (for-each delete-file (find-files "." "\\.jar$"))))
+              (sha256
+               (base32
+                "0l45v41nns2jmn9nr9fb0yvhqzfjpxjxn75i1c02rsfy3r3lv22v"))))
+    (native-inputs
+     `(("pkg-config" ,pkg-config)
+       ("xorg-server" ,xorg-server-for-tests) ;For running the tests
+       ("opencv-extra"
+        ,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/opencv/opencv_extra")
+                 (commit version)))
+           (file-name (git-file-name "opencv_extra" version))
+           (sha256
+            (base32
+             "0bdg5kwwdimnl2zp4ry5cmfxr9xb7zk2ml59853d90llsqjis47a"))))
+       ("opencv-contrib"
+        ,(origin
+           (method git-fetch)
+           (uri (git-reference (url "https://github.com/opencv/opencv_contrib")
+                               (commit version)))
+           (file-name (git-file-name "opencv_contrib" version))
+           (sha256
+            (base32
+             "0hbfn835kxh3hwmwvzgdglm2np1ri3z7nfnf60gf4x6ikp89mv4r"))))))
     (arguments
      (substitute-keyword-arguments (package-arguments opencv)
-       ((#:phases phases
-         '%standard-phases)
-        `(modify-phases ,phases
-           (add-after 'unpack 'disable-broken-tests-opencv-4.7-specific
-             (lambda _
-               (substitute* "modules/dnn/test/test_layers.cpp"
-                 (("(TEST_P\\(Test_Caffe_layers, )(Interp\\).*)"
-                   all pre post)
-                  (string-append pre "DISABLED_" post)))))))))))
+       ((#:phases phases '%standard-phases)
+        #~(modify-phases #$phases
+            (add-after 'unpack 'disable-broken-tests-opencv-4.7-specific
+              (lambda _
+                (substitute* "modules/dnn/test/test_layers.cpp"
+                  (("(TEST_P\\(Test_Caffe_layers, )(Interp\\).*)" _ pre post)
+                   (string-append pre "DISABLED_" post)))))))))))
 
 (define-public vips
   (package
--8<---------------cut here---------------end--------------->8---

And installed the change.  Thank you!

-- 
Thanks,
Maxim