[PATCH] gnu: Add libfreenect.

DoneSubmitted by Ekaitz Zarraga.
Details
2 participants
  • Ekaitz Zarraga
  • 宋文武
Owner
unassigned
Severity
normal
E
E
Ekaitz Zarraga wrote on 15 May 2020 23:47
(name . guix-patches@gnu.org)(address . guix-patches@gnu.org)
5kf9uJF2SDo9zwlTUoFI13o7P7q68o-AuSp72MvOp5PUaF2SlAPxzQJvFws5aaTOB5EHY4T3-En0Mhba7hADMIeJkgCeWUOY_Ciy0fv24Ck=@elenq.tech
Hi,

Adding libfreenect as discussed here:


I have some doubts with this package:

- It has some extra flags that can be set in the configure step to build some python bindings. I didn't set them because they also require a python interpreter. How is the best way to handle that? Make another package with the flags set? Activate them by default? Leave them as I did?

- The package is 300 megs checking `guix size` that's because it has some testing binaries that have extra dependencies. If only the library is compiled it doesn't depend on GLUT and that reduces the size a lot. I tried to separate the package's outputs but I don't know how to do it correctly (I checked the docs but it doesn't go in detail). I'd like to do it but I need some help.

- I'm not sure if the file where I added it is a good choice.

Best,

Ekaitz

---

From aa74e0b4872f6a2748ed919ebe3c265472d04664 Mon Sep 17 00:00:00 2001
From: Ekaitz Zarraga <ekaitz@elenq.tech>
Date: Fri, 15 May 2020 23:22:04 +0200
Subject: [PATCH] gnu: Add libfreenect.

* gnu/packages/libusb (libfreenect): New variable.
---
gnu/packages/libusb.scm | 39 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)

Toggle diff (61 lines)
diff --git a/gnu/packages/libusb.scm b/gnu/packages/libusb.scm
index 3842f3fead..a27373c15a 100644
--- a/gnu/packages/libusb.scm
+++ b/gnu/packages/libusb.scm
@@ -10,6 +10,7 @@
 ;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org>
 ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
 ;;; Copyright © 2020 Christopher Howard <christopher@librehacker.com>
+;;; Copyright © 2020 Ekaitz Zarraga <ekaitz@elenq.tech>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -48,7 +49,8 @@
   #:use-module (gnu packages python)
   #:use-module (gnu packages python-xyz)
   #:use-module (gnu packages tls)
-  #:use-module (gnu packages xiph))
+  #:use-module (gnu packages xiph)
+  #:use-module (gnu packages gl))

 (define-public libusb
   (package
@@ -679,3 +681,38 @@ HID-Class devices.")

 (define-public python2-hidapi
   (package-with-python2 python-hidapi))
+
+(define-public libfreenect
+  (let ((version "0.6.1"))
+    (package
+      (name "libfreenect")
+      (version version)
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/OpenKinect/libfreenect")
+                      (commit (string-append "v" version))))
+                (sha256
+                 (base32 "0was1va167rqshmpn382h36yyprpfi9cwillb6ylppmnfdrfrhrr"))))
+      (build-system cmake-build-system)
+      (arguments
+       `(#:tests? #f ;; Project has not tests
+         #:phases
+         (modify-phases %standard-phases
+           (add-after 'install 'install-udev-rules
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let* ((out (assoc-ref outputs "out"))
+                      (rules-out (string-append out "/lib/udev/rules.d")))
+                 (install-file "../source/platform/linux/udev/51-kinect.rules"
+                               (string-append rules-out "51-kinect.rules"))
+                 #t))))))
+      (native-inputs
+       `(("libusb" ,libusb)
+         ("pkg-config" ,pkg-config)))
+      (inputs
+       `(("glut" ,freeglut)))
+      (synopsis "Drivers and libraries for the Xbox Kinect device")
+      (description "libfreenect is a userspace driver for the Microsoft Kinect.
+It supports: RGB and Depth Images, Motors, Accelerometer, LED and Audio.")
+      (home-page "https://openkinect.org/")
+      (license license:gpl2+))))
--
2.26.1
E
E
Ekaitz Zarraga wrote on 16 May 2020 01:09
[PATCH] gnu: libfreenect: Correct native-inputs vs inputs
(name . 41294@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
Ti7SxKb7D1vUyfEegMPRqMNKcsd6O4oBOGKIrW2ICXZPoLijKhZ_tuG2uOIp_RIsnrKhN7cXQmfZ7iQ_z9kBfsONZOVVMf7M9PVTYfGLSjA=@elenq.tech
From 22886e9048c88d607622a3e9dba60c179954b9fc Mon Sep 17 00:00:00 2001
From: Ekaitz Zarraga <ekaitz@elenq.tech>
Date: Sat, 16 May 2020 01:06:24 +0200
Subject: [PATCH] gnu: libfreenect: Correct native-inputs vs inputs

* gnu/packages/libusb.scm (libfreenect): Change inputs
---
gnu/packages/libusb.scm | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

Toggle diff (18 lines)
diff --git a/gnu/packages/libusb.scm b/gnu/packages/libusb.scm
index a27373c15a..51149dea1a 100644
--- a/gnu/packages/libusb.scm
+++ b/gnu/packages/libusb.scm
@@ -707,10 +707,10 @@ HID-Class devices.")
                                (string-append rules-out "51-kinect.rules"))
                  #t))))))
       (native-inputs
-       `(("libusb" ,libusb)
-         ("pkg-config" ,pkg-config)))
+       `(("pkg-config" ,pkg-config)))
       (inputs
-       `(("glut" ,freeglut)))
+       `(("libusb" ,libusb)
+         ("glut" ,freeglut)))
       (synopsis "Drivers and libraries for the Xbox Kinect device")
       (description "libfreenect is a userspace driver for the Microsoft Kinect.
 It supports: RGB and Depth Images, Motors, Accelerometer, LED and Audio.")
--
2.26.1
宋文武 wrote on 16 May 2020 05:48
Re: [bug#41294] [PATCH] gnu: Add libfreenect.
(name . Ekaitz Zarraga)(address . ekaitz@elenq.tech)(address . 41294@debbugs.gnu.org)
87k11c5ymm.fsf@member.fsf.org
Ekaitz Zarraga <ekaitz@elenq.tech> writes:

Toggle quote (2 lines)
> Hi,

Hello,
Toggle quote (9 lines)
>
> Adding libfreenect as discussed here:
>
> https://issues.guix.gnu.org/40492
>
> I have some doubts with this package:
>
> - It has some extra flags that can be set in the configure step to build some python bindings. I didn't set them because they also require a python interpreter. How is the best way to handle that? Make another package with the flags set? Activate them by default? Leave them as I did?

We generally try to enable all optional features when adding a package,
I'd go with:

1. Build the python bindings by default.

2. Try seperate the python bindings into another output. (eg: newt)

3. If 1 and 2 seems difficult, try add a seperate package for the
python bindings, and it better only contains the bindings, reuse the
original package as input. (eg: python-libxml2)

4. If not feel lucky, just leave a TODO comment for it...


Toggle quote (3 lines)
>
> - The package is 300 megs checking `guix size` that's because it has some testing binaries that have extra dependencies. If only the library is compiled it doesn't depend on GLUT and that reduces the size a lot. I tried to separate the package's outputs but I don't know how to do it correctly (I checked the docs but it doesn't go in detail). I'd like to do it but I need some help.

To define a packages with multiple outputs:

- Decide what ‘outputs’ can be made, eg: ‘doc’, ‘bin’, ‘examples’,
etc. In this case, I’d add an ‘examples’ output, to put those
‘freenect-*’ binaries, built from the “examples” directory.
- Add an ‘outputs’ field, it default to ‘(list "out")’, We’d use
‘(outputs '("out" "examples")’.

- Modify the install flags or phases to get files into their output
directory. Sometimes we can configure the target directory by flags,
but usually we have to move the files around after the install phase…
You can see ‘newt’ in ‘gnu/packages/slang.scm’ for a example.

Toggle quote (3 lines)
>
> - I'm not sure if the file where I added it is a good choice.

Same here, we can always move it later…

Toggle quote (59 lines)
>
> Best,
>
> Ekaitz
>
> ---
>
>>From aa74e0b4872f6a2748ed919ebe3c265472d04664 Mon Sep 17 00:00:00 2001
> From: Ekaitz Zarraga <ekaitz@elenq.tech>
> Date: Fri, 15 May 2020 23:22:04 +0200
> Subject: [PATCH] gnu: Add libfreenect.
>
> * gnu/packages/libusb (libfreenect): New variable.
> ---
> gnu/packages/libusb.scm | 39 ++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 38 insertions(+), 1 deletion(-)
>
> diff --git a/gnu/packages/libusb.scm b/gnu/packages/libusb.scm
> index 3842f3fead..a27373c15a 100644
> --- a/gnu/packages/libusb.scm
> +++ b/gnu/packages/libusb.scm
> @@ -10,6 +10,7 @@
> ;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org>
> ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
> ;;; Copyright © 2020 Christopher Howard <christopher@librehacker.com>
> +;;; Copyright © 2020 Ekaitz Zarraga <ekaitz@elenq.tech>
> ;;;
> ;;; This file is part of GNU Guix.
> ;;;
> @@ -48,7 +49,8 @@
> #:use-module (gnu packages python)
> #:use-module (gnu packages python-xyz)
> #:use-module (gnu packages tls)
> - #:use-module (gnu packages xiph))
> + #:use-module (gnu packages xiph)
> + #:use-module (gnu packages gl))
>
> (define-public libusb
> (package
> @@ -679,3 +681,38 @@ HID-Class devices.")
>
> (define-public python2-hidapi
> (package-with-python2 python-hidapi))
> +
> +(define-public libfreenect
> + (let ((version "0.6.1"))
> + (package
> + (name "libfreenect")
> + (version version)
> + (source (origin
> + (method git-fetch)
> + (uri (git-reference
> + (url "https://github.com/OpenKinect/libfreenect")
> + (commit (string-append "v" version))))
> + (sha256
> + (base32 "0was1va167rqshmpn382h36yyprpfi9cwillb6ylppmnfdrfrhrr"))))
> + (build-system cmake-build-system)
> + (arguments
> + `(#:tests? #f ;; Project has not tests
This ` quasiquote is unnecessary here, a ' quote is enough, because we
refer nothing outside in the arguments list.

By convention, a single semicolon is for comment after expression in the
same line. a double semicolon is for comment the next lines.

Toggle quote (22 lines)
> + #:phases
> + (modify-phases %standard-phases
> + (add-after 'install 'install-udev-rules
> + (lambda* (#:key outputs #:allow-other-keys)
> + (let* ((out (assoc-ref outputs "out"))
> + (rules-out (string-append out "/lib/udev/rules.d")))
> + (install-file "../source/platform/linux/udev/51-kinect.rules"
> + (string-append rules-out "51-kinect.rules"))
> + #t))))))
> + (native-inputs
> + `(("libusb" ,libusb)
> + ("pkg-config" ,pkg-config)))
> + (inputs
> + `(("glut" ,freeglut)))
> + (synopsis "Drivers and libraries for the Xbox Kinect device")
> + (description "libfreenect is a userspace driver for the Microsoft Kinect.
> +It supports: RGB and Depth Images, Motors, Accelerometer, LED and Audio.")
> + (home-page "https://openkinect.org/")
> + (license license:gpl2+))))
> --
> 2.26.1

Otherwise, look goods to me, hope it helps!
E
E
Ekaitz Zarraga wrote on 16 May 2020 12:18
(name . iyzsong@member.fsf.org)(address . iyzsong@member.fsf.org)(name . 41294@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
anygGLcrTLR-L_lbGpsSCRwfeCxVv7GdmryjPmzGc1M7AxdMInuEmimpAI_u3lst7LBl-xg4LHJBqOi1gYLiRyUJX8_kw0F9RcI723VUjQU=@elenq.tech
Hi,

On Saturday, May 16, 2020 5:48 AM, <iyzsong@member.fsf.org> wrote:

Toggle quote (12 lines)
> We generally try to enable all optional features when adding a package,
> I'd go with:
>
> 1. Build the python bindings by default.
> 2. Try seperate the python bindings into another output. (eg: newt)
> 3. If 1 and 2 seems difficult, try add a seperate package for the
> python bindings, and it better only contains the bindings, reuse the
> original package as input. (eg: python-libxml2)
>
> 4. If not feel lucky, just leave a TODO comment for it...
>

I don't really like the first because it forces you to add a python interpreter that is not needed otherwise.
2 and 3 sound good to me.
It can handle both python2 and 3. What would you do with that?
Maybe make option 3 and add two outputs to that with python2 and python3? Or two different packages?
(or just forget the python2?)

Toggle quote (18 lines)
>
> > - The package is 300 megs checking `guix size` that's because it has some testing binaries that have extra dependencies. If only the library is compiled it doesn't depend on GLUT and that reduces the size a lot. I tried to separate the package's outputs but I don't know how to do it correctly (I checked the docs but it doesn't go in detail). I'd like to do it but I need some help.
>
> To define a packages with multiple outputs:
>
> - Decide what ‘outputs’ can be made, eg: ‘doc’, ‘bin’, ‘examples’,
> etc. In this case, I’d add an ‘examples’ output, to put those
> ‘freenect-*’ binaries, built from the “examples” directory.
>
> - Add an ‘outputs’ field, it default to ‘(list "out")’, We’d use
> ‘(outputs '("out" "examples")’.
>
> - Modify the install flags or phases to get files into their output
> directory. Sometimes we can configure the target directory by flags,
> but usually we have to move the files around after the install phase…
>
> You can see ‘newt’ in ‘gnu/packages/slang.scm’ for a example.

Great! Thank you. That's more or less what I understood from some code examples I checked but they were complex and I tried to make the same thing and didn't work for me. I'll give it a new try with this example.

Inputs can also be defined with an extra argument for different outputs, right? It should be something like:

`(inputs `("freeglut" ,freeglut "examples"))

Am I right?

Toggle quote (5 lines)
>
> > - I'm not sure if the file where I added it is a good choice.
>
> Same here, we can always move it later…

Yeah, sure.

Thank you very much for your help.

Best,
Ekaitz
E
E
Ekaitz Zarraga wrote on 16 May 2020 15:06
(name . iyzsong@member.fsf.org)(address . iyzsong@member.fsf.org)(name . 41294@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
BxJab7z2VOD-VeXpKiEpcbdx5pJVou3NuReW9G63QWzmMbMwDRgTFYp2eYlMyntlcAlH3cas1XMml6CsUQIABP80dy1fLQ8lbae0dClfaDI=@elenq.tech
Toggle quote (6 lines)
> Inputs can also be defined with an extra argument for different outputs, right? It should be something like:
>
> `(inputs`("freeglut" ,freeglut "examples"))
>
> Am I right?

Nope!

I've been digging and I got this wrong. The third part in the tuple is the output of the dependency.
So there's no way to indicate which dependencies are needed for each output.

I also found a flag to compile OpenCV wrappers, which depends on OpenCV. OpenCV is huge and it's going to be downloaded regardless if its output is used or not. Best choice here seems to be to separate the package in multiple sub-packages.

I made this with the examples (see below), how does it look?
I used libfreenect as a dependency for examples too, so I needed to patch the CMakeLists.txt to avoid it compile the `src` folder again.
Is it cool if I do the same thing with OpenCV and Python?

(now we can move it to its own module because it's going to be long :) )

---

(define-public libfreenect
(let ((version "0.6.1"))
(package
(name "libfreenect")
(version version)
(source (origin
(method git-fetch)
(uri (git-reference
(commit (string-append "v" version))))
(sha256
(base32 "0was1va167rqshmpn382h36yyprpfi9cwillb6ylppmnfdrfrhrr"))))
(build-system cmake-build-system)
(outputs '("out" "opencv" "examples"))
(arguments
'(#:tests? #f ; Project has not tests
#:configure-flags '("-DBUILD_EXAMPLES=ON"
"-DBUILD_FAKENECT=ON"
"-DBUILD_CPP=ON"
"-DBUILD_CV=OFF"
"-DBUILD_C_SYNC=ON")
#:phases
(modify-phases %standard-phases
(add-after 'install 'install-udev-rules
(lambda* (#:key outputs #:allow-other-keys)
(let* ((out (assoc-ref outputs "out"))
(rules-out (string-append out "/lib/udev/rules.d")))
(install-file "../source/platform/linux/udev/51-kinect.rules"
(string-append rules-out "51-kinect.rules"))
#t))))))
(native-inputs
`(("pkg-config" ,pkg-config)))
(inputs
`(("libusb" ,libusb)))
(synopsis "Drivers and libraries for the Xbox Kinect device")
(description "libfreenect is a userspace driver for the Microsoft Kinect.
It supports: RGB and Depth Images, Motors, Accelerometer, LED and Audio.")
(license license:gpl2+))))

(define-public libfreenect-examples
(package
(inherit libfreenect)
(name "libfreenect-examples")
(inputs
`(("libusb" ,libusb)
("libfreenect" ,libfreenect)
("glut" ,freeglut)))
(arguments
'(#:tests? #f ; Project has not tests
#:configure-flags '("-DBUILD_EXAMPLES=ON"
"-DBUILD_FAKENECT=OFF"
"-DBUILD_CPP=OFF"
"-DBUILD_C_SYNC=OFF")
#:phases
(modify-phases
%standard-phases
(add-after
'unpack 'remove-sources
(lambda* (#:key outputs #:allow-other-keys)
(substitute* "CMakeLists.txt"
(("add_subdirectory \\(src\\)") "")
((".*libfreenectConfig.cmake.*") "")))))))
(synopsis "Examples for libfreenect, the Xbox Kinect device library")))
E
E
Ekaitz Zarraga wrote on 16 May 2020 15:28
(name . iyzsong@member.fsf.org)(address . iyzsong@member.fsf.org)(name . 41294@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
y7x4rXqlC8fYzhl0T6xYJJDS7LKs93KkRIvkTq41FcutzhOjFtWSgiJp7_WE-bPhBFyyfTR2x01ReNZDpoXSn761boukIDP64AE_g4GNFQI=@elenq.tech
Toggle quote (2 lines)
> (outputs '("out" "opencv" "examples"))

Ignore this line, I forgot to remove it :S
宋文武 wrote on 17 May 2020 03:56
(name . Ekaitz Zarraga)(address . ekaitz@elenq.tech)(name . 41294@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
87wo5b1fz8.fsf@member.fsf.org
Ekaitz Zarraga <ekaitz@elenq.tech> writes:

Toggle quote (18 lines)
> Hi,
>
> On Saturday, May 16, 2020 5:48 AM, <iyzsong@member.fsf.org> wrote:
>
>> We generally try to enable all optional features when adding a package,
>> I'd go with:
>>
>> 1. Build the python bindings by default.
>> 2. Try seperate the python bindings into another output. (eg: newt)
>> 3. If 1 and 2 seems difficult, try add a seperate package for the
>> python bindings, and it better only contains the bindings, reuse the
>> original package as input. (eg: python-libxml2)
>>
>> 4. If not feel lucky, just leave a TODO comment for it...
>>
>
> I don't really like the first because it forces you to add a python interpreter that is not needed otherwise.
> 2 and 3 sound good to me.
Sure, to me both are acceptable.

Toggle quote (4 lines)
> It can handle both python2 and 3. What would you do with that?
> Maybe make option 3 and add two outputs to that with python2 and python3? Or two different packages?
> (or just forget the python2?)

Unless there is a need for the python2 bindings, we should forget it, as
Python 2 is end-of-life.

Toggle quote (35 lines)
>
>>
>> > - The package is 300 megs checking `guix size` that's because it
>> > has some testing binaries that have extra dependencies. If only
>> > the library is compiled it doesn't depend on GLUT and that reduces
>> > the size a lot. I tried to separate the package's outputs but I
>> > don't know how to do it correctly (I checked the docs but it
>> > doesn't go in detail). I'd like to do it but I need some help.
>>
>> To define a packages with multiple outputs:
>>
>> - Decide what ‘outputs’ can be made, eg: ‘doc’, ‘bin’, ‘examples’,
>> etc. In this case, I’d add an ‘examples’ output, to put those
>> ‘freenect-*’ binaries, built from the “examples” directory.
>>
>> - Add an ‘outputs’ field, it default to ‘(list "out")’, We’d use
>> ‘(outputs '("out" "examples")’.
>>
>> - Modify the install flags or phases to get files into their output
>> directory. Sometimes we can configure the target directory by flags,
>> but usually we have to move the files around after the install phase…
>>
>> You can see ‘newt’ in ‘gnu/packages/slang.scm’ for a example.
>
> Great! Thank you. That's more or less what I understood from some code
> examples I checked but they were complex and I tried to make the same
> thing and didn't work for me. I'll give it a new try with this
> example.
>
> Inputs can also be defined with an extra argument for different outputs, right? It should be something like:
>
> `(inputs `("freeglut" ,freeglut "examples"))
>
> Am I right?

Inputs are used (not defined) here, the code you wrote:

- Need a freeglut package, which should contain a "examples" output.

- In the build environment of this package, a "freeglut" input is
available, and its path is store path of the "examples" output of that
freeglut package. freeglut's "out" output is not available here.

Toggle quote (4 lines)
> Nope!

> I've been digging and I got this wrong. The third part in the tuple is the output of the dependency.
> So there's no way to indicate which dependencies are needed for each output.
Yes, the dependencies of outputs are scanned after the build results,
not before. This works by searching '/gnu/store' paths in all files
from the output's store path.


Toggle quote (1 lines)
> I also found a flag to compile OpenCV wrappers, which depends on OpenCV. OpenCV is huge and it's going to be downloaded regardless if its output is used or not. Best choice here seems to be to separate the package in multiple sub-packages.
If in the same package (multiple outputs), all inputs are needed when
build a package, but not all dependencies are needed when install a
output by binary substitutes.


Toggle quote (2 lines)
> I made this with the examples (see below), how does it look?
> [...]
Will reply to in that email...
宋文武 wrote on 17 May 2020 04:15
(name . Ekaitz Zarraga)(address . ekaitz@elenq.tech)(name . 41294@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
87sgfz1f43.fsf@member.fsf.org
Ekaitz Zarraga <ekaitz@elenq.tech> writes:

Toggle quote (24 lines)
> [...]
>
> I made this with the examples (see below), how does it look?
> I used libfreenect as a dependency for examples too, so I needed to patch the CMakeLists.txt to avoid it compile the `src` folder again.
> Is it cool if I do the same thing with OpenCV and Python?
>
> (now we can move it to its own module because it's going to be long :) )
>
> ---
>
> (define-public libfreenect
> (let ((version "0.6.1"))
> (package
> (name "libfreenect")
> (version version)
> (source (origin
> (method git-fetch)
> (uri (git-reference
> (url "https://github.com/OpenKinect/libfreenect")
> (commit (string-append "v" version))))
> (sha256
> (base32 "0was1va167rqshmpn382h36yyprpfi9cwillb6ylppmnfdrfrhrr"))))
> (build-system cmake-build-system)
> (outputs '("out" "opencv" "examples"))
As note in your latest email, this line should be removed, as it's a single
output package now.

Toggle quote (3 lines)
> (arguments
> '(#:tests? #f ; Project has not tests
> #:configure-flags '("-DBUILD_EXAMPLES=ON"
Should be "-DBUILD_EXAMPLES=OFF"?

Toggle quote (42 lines)
> "-DBUILD_FAKENECT=ON"
> "-DBUILD_CPP=ON"
> "-DBUILD_CV=OFF"
> "-DBUILD_C_SYNC=ON")
> #:phases
> (modify-phases %standard-phases
> (add-after 'install 'install-udev-rules
> (lambda* (#:key outputs #:allow-other-keys)
> (let* ((out (assoc-ref outputs "out"))
> (rules-out (string-append out "/lib/udev/rules.d")))
> (install-file "../source/platform/linux/udev/51-kinect.rules"
> (string-append rules-out "51-kinect.rules"))
> #t))))))
> (native-inputs
> `(("pkg-config" ,pkg-config)))
> (inputs
> `(("libusb" ,libusb)))
> (synopsis "Drivers and libraries for the Xbox Kinect device")
> (description "libfreenect is a userspace driver for the Microsoft Kinect.
> It supports: RGB and Depth Images, Motors, Accelerometer, LED and Audio.")
> (home-page "https://openkinect.org/")
> (license license:gpl2+))))
>
> (define-public libfreenect-examples
> (package
> (inherit libfreenect)
> (name "libfreenect-examples")
> (inputs
> `(("libusb" ,libusb)
> ("libfreenect" ,libfreenect)
> ("glut" ,freeglut)))
> (arguments
> '(#:tests? #f ; Project has not tests
> #:configure-flags '("-DBUILD_EXAMPLES=ON"
> "-DBUILD_FAKENECT=OFF"
> "-DBUILD_CPP=OFF"
> "-DBUILD_C_SYNC=OFF")
> #:phases
> (modify-phases
> %standard-phases
> (add-after
> 'unpack 'remove-sources
Maybe 'configure-examples? This phases doesn't remove sources, but
avoid building them.

Toggle quote (1 lines)
> (lambda* (#:key outputs #:allow-other-keys)
How about add a comment here: Reuse "libfreenect" from input, avoid building it again.

Toggle quote (5 lines)
> (substitute* "CMakeLists.txt"
> (("add_subdirectory \(src\)") "")
> ((".*libfreenectConfig.cmake.*") "")))))))
> (synopsis "Examples for libfreenect, the Xbox Kinect device library")))

Also check the outputs of libfreenect and libfreenect-examples, they
shouldn't have same files (maybe by guix install them).

Otherwise, look goods to me.
E
E
Ekaitz Zarraga wrote on 17 May 2020 11:37
(name . iyzsong@member.fsf.org)(address . iyzsong@member.fsf.org)(name . 41294\@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
Tm4Gn-oOCCKkN_lXgi0Ratd53rukPCo0cCdUiedNp5yWWy9EOgKhRRTvWyUZzKFaL_8SIJHbYoti5YofNZTA8Z4wzULhbbFGqedOTpgrGBk=@elenq.tech
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Sunday, May 17, 2020 4:15 AM, <iyzsong@member.fsf.org> wrote:

Toggle quote (96 lines)
> Ekaitz Zarraga ekaitz@elenq.tech writes:
>
> > [...]
> > I made this with the examples (see below), how does it look?
> > I used libfreenect as a dependency for examples too, so I needed to patch the CMakeLists.txt to avoid it compile the `src` folder again.
> > Is it cool if I do the same thing with OpenCV and Python?
> > (now we can move it to its own module because it's going to be long :) )
> >
> > (define-public libfreenect
> > (let ((version "0.6.1"))
> > (package
> > (name "libfreenect")
> > (version version)
> > (source (origin
> > (method git-fetch)
> > (uri (git-reference
> > (url "https://github.com/OpenKinect/libfreenect")
> > (commit (string-append "v" version))))
> > (sha256
> > (base32 "0was1va167rqshmpn382h36yyprpfi9cwillb6ylppmnfdrfrhrr"))))
> > (build-system cmake-build-system)
> > (outputs '("out" "opencv" "examples"))
>
> As note in your latest email, this line should be removed, as it's a single
> output package now.
>
> > (arguments
> > '(#:tests? #f ; Project has not tests
> > #:configure-flags '("-DBUILD_EXAMPLES=ON"
> >
>
> Should be "-DBUILD_EXAMPLES=OFF"?
>
> > "-DBUILD_FAKENECT=ON"
> > "-DBUILD_CPP=ON"
> > "-DBUILD_CV=OFF"
> > "-DBUILD_C_SYNC=ON")
> > #:phases
> > (modify-phases %standard-phases
> > (add-after 'install 'install-udev-rules
> > (lambda* (#:key outputs #:allow-other-keys)
> > (let* ((out (assoc-ref outputs "out"))
> > (rules-out (string-append out "/lib/udev/rules.d")))
> > (install-file "../source/platform/linux/udev/51-kinect.rules"
> > (string-append rules-out "51-kinect.rules"))
> > #t))))))
> > (native-inputs
> > `(("pkg-config" ,pkg-config)))
> > (inputs
> > `(("libusb" ,libusb)))
> > (synopsis "Drivers and libraries for the Xbox Kinect device")
> > (description "libfreenect is a userspace driver for the Microsoft Kinect.
> >
> >
> > It supports: RGB and Depth Images, Motors, Accelerometer, LED and Audio.")
> > (home-page "https://openkinect.org/")
> > (license license:gpl2+))))
> > (define-public libfreenect-examples
> > (package
> > (inherit libfreenect)
> > (name "libfreenect-examples")
> > (inputs
> > `(("libusb" ,libusb)
> > ("libfreenect" ,libfreenect)
> > ("glut" ,freeglut)))
> > (arguments
> > '(#:tests? #f ; Project has not tests
> > #:configure-flags '("-DBUILD_EXAMPLES=ON"
> > "-DBUILD_FAKENECT=OFF"
> > "-DBUILD_CPP=OFF"
> > "-DBUILD_C_SYNC=OFF")
> > #:phases
> > (modify-phases
> > %standard-phases
> > (add-after
> > 'unpack 'remove-sources
>
> Maybe 'configure-examples? This phases doesn't remove sources, but
> avoid building them.
>
> > (lambda* (#:key outputs #:allow-other-keys)
> >
>
> How about add a comment here: Reuse "libfreenect" from input, avoid building it again.
>
> > (substitute* "CMakeLists.txt"
> > (("add_subdirectory \\(src\\)") "")
> > ((".*libfreenectConfig.cmake.*") "")))))))
> > (synopsis "Examples for libfreenect, the Xbox Kinect device library")))
> >
>
> Also check the outputs of libfreenect and libfreenect-examples, they
> shouldn't have same files (maybe by guix install them).
>
> Otherwise, look goods to me.

Hi!

Thanks. I was worried about if this is a common practice.

I already prepared something. I'll send the patch soon. Thanks for your explanations, they are very helpful.

Best,
Ekaitz
E
E
Ekaitz Zarraga wrote on 17 May 2020 14:15
(name . iyzsong@member.fsf.org)(address . iyzsong@member.fsf.org)(name . 41294\@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
zgYthp30GnrnAddRXlGZx4viwqwoXH-IAl4YyIpaZPVi9RGq33qbQ6Sg1r3Kg4QnVYCmwY0xpoxJVyv8xhARPY-cHsbdsoA1gfKKr9k-VL0=@elenq.tech
Hi,
I came up with this. It's just a diff because I'd like to improve something.

There's the same lambda sent to all the packages that need to disable sources compilation but I'm not able to create it in a function that I send later to all those.

How can I do that? I'm getting `Unknown object` errors.

I tried to create a new function with `define*` with the same body the lambda has. Quasiquote the `arguments` and unquote the function there.
Nothing. There's some kind of weird magic I'm not getting.


Toggle diff (144 lines)
diff --git a/gnu/packages/openkinect.scm b/gnu/packages/openkinect.scm
new file mode 100644
index 0000000000..1aebb34384
--- /dev/null
+++ b/gnu/packages/openkinect.scm
@@ -0,0 +1,137 @@
+(define-module (gnu packages openkinect)
+  #:use-module (guix packages)
+  #:use-module (guix git-download)
+  #:use-module (guix build-system cmake)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages libusb)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages python-xyz)
+  #:use-module (gnu packages gl)
+  #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages image-processing))
+
+(define-public libfreenect
+  (let ((version "0.6.1"))
+    (package
+      (name "libfreenect")
+      (version version)
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/OpenKinect/libfreenect")
+                      (commit (string-append "v" version))))
+                (sha256
+                 (base32 "0was1va167rqshmpn382h36yyprpfi9cwillb6ylppmnfdrfrhrr"))))
+      (build-system cmake-build-system)
+      (arguments
+       '(#:tests? #f ; Project has not tests
+         #:configure-flags
+         '("-DBUILD_FAKENECT=ON"
+           "-DBUILD_CPP=ON"
+           "-DBUILD_EXAMPLES=OFF" ; Available in libfreenect-examples
+           "-DBUILD_CV=OFF"       ; Available in libfreenect-cv
+           "-DBUILD_PYTHON=OFF"   ; Available in libfreenect-python
+           "-DBUILD_C_SYNC=ON")
+         #:phases
+         (modify-phases %standard-phases
+           (add-after 'install 'install-udev-rules
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let* ((out (assoc-ref outputs "out"))
+                      (rules-out (string-append out "/lib/udev/rules.d")))
+                 (install-file "../source/platform/linux/udev/51-kinect.rules"
+                               (string-append rules-out "51-kinect.rules"))
+                 #t))))))
+      (native-inputs
+       `(("pkg-config" ,pkg-config)))
+      (inputs
+       `(("libusb" ,libusb)))
+      (synopsis "Drivers and libraries for the Xbox Kinect device")
+      (description "libfreenect is a userspace driver for the Microsoft Kinect.
+It supports: RGB and Depth Images, Motors, Accelerometer, LED and Audio.")
+      (home-page "https://openkinect.org/")
+      (license license:gpl2+))))
+
+
+
+(define-public libfreenect-examples
+  (package
+    (inherit libfreenect)
+    (name "libfreenect-examples")
+    (inputs
+     `(("libfreenect" ,libfreenect)
+       ("glut" ,freeglut)))
+    (arguments
+     `(#:tests? #f ; Project has not tests
+       #:configure-flags '("-DBUILD_EXAMPLES=ON"
+                           "-DBUILD_FAKENECT=OFF"
+                           "-DBUILD_CPP=OFF"
+                           "-DBUILD_C_SYNC=OFF"
+                           "-DBUILD_CV=OFF")
+       #:phases
+       (modify-phases %standard-phases
+         ;; Sources are already compiled in libfreenect input
+         (add-after 'unpack 'disable-sources
+                    (lambda* (#:key outputs #:allow-other-keys)
+                             (substitute* "CMakeLists.txt"
+                               ((".*libusb.*") "")
+                               (("add_subdirectory \\(src\\)") "")
+                               ((".*libfreenectConfig.cmake.*") "")))
+                    ))))
+    (synopsis "Examples for libfreenect, the Xbox Kinect device library")))
+
+(define-public libfreenect-cv
+  (package
+    (inherit libfreenect)
+    (name "libfreenect-cv")
+    (inputs
+     `(("libfreenect" ,libfreenect)
+       ("opencv" ,opencv)))
+    (arguments
+     '(#:tests? #f ; Project has not tests
+       #:configure-flags '("-DBUILD_EXAMPLES=OFF"
+                           "-DBUILD_FAKENECT=OFF"
+                           "-DBUILD_CPP=OFF"
+                           "-DBUILD_C_SYNC=OFF"
+                           "-DBUILD_CV=ON")
+       #:phases
+       (modify-phases %standard-phases
+         ;; Sources are already compiled in libfreenect input
+         (add-after 'unpack 'disable-sources
+           (lambda* (#:key outputs #:allow-other-keys)
+             (substitute* "CMakeLists.txt"
+               ((".*libusb.*") "")
+               (("add_subdirectory \\(src\\)") "")
+               ((".*libfreenectConfig.cmake.*") "")))))))
+    (synopsis "OpenCV wrapper for libfreenect, the Xbox Kinect device
+library")))
+
+(define-public libfreenect-python
+  (package
+    (inherit libfreenect)
+    (name "libfreenect-python")
+    (native-inputs
+     `(("python-cython" ,python-cython)))
+    (inputs
+     `(("libfreenect" ,libfreenect)))
+    (propagated-inputs
+     `(("python" ,python)
+       ("python-numpy" ,python-numpy)))
+    (arguments
+     '(#:tests? #f ; Project has not tests
+       #:configure-flags '("-DBUILD_EXAMPLES=OFF"
+                           "-DBUILD_FAKENECT=OFF"
+                           "-DBUILD_CPP=OFF"
+                           "-DBUILD_C_SYNC=OFF"
+                           "-DBUILD_CV=OFF"
+                           "-DBUILD_PYTHON3=ON")
+       #:phases
+       (modify-phases %standard-phases
+         ;; Sources are already compiled in libfreenect input
+         (add-after 'unpack 'disable-sources
+           (lambda* (#:key outputs #:allow-other-keys)
+             (substitute* "CMakeLists.txt"
+               ((".*libusb.*") "")
+               (("add_subdirectory \\(src\\)") "")
+               ((".*libfreenectConfig.cmake.*") "")))))))
+    (synopsis "Python wrapper for libfreenect, the Xbox Kinect device
+library")))
宋文武 wrote on 19 May 2020 15:26
(name . Ekaitz Zarraga)(address . ekaitz@elenq.tech)(name . 41294@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
87eergqcn4.fsf@member.fsf.org
Ekaitz Zarraga <ekaitz@elenq.tech> writes:

Toggle quote (14 lines)
> Hi,
> I came up with this. It's just a diff because I'd like to improve something.
>
> There's the same lambda sent to all the packages that need to disable
> sources compilation but I'm not able to create it in a function that I
> send later to all those.
>
> How can I do that? I'm getting `Unknown object` errors.
>
> I tried to create a new function with `define*` with the same body the
> lambda has. Quasiquote the `arguments` and unquote the function there.
> Nothing. There's some kind of weird magic I'm not getting.
>

Hello, I don't know the whole detail too, but to build a package, guix likely:

- Load and eval the package module, to get the package object. The
'arguments' field is a list.

- Convert this package object to a derivation, and write it in store as
a file (/gnu/store/*.drv). Where 'arguments' being part of the
builder, serialize as string to the file, it dosen't do complex things
for procedure bindings, only write their string descriptions... So
when the builder file is loaded, you get `Unknown object` errors.


Here, to avoid duplicating the code, you can:

1. Unquote list value into `arguments`. (eg: 'asdf-substitutions' in lisp.scm)

2. Use `(package-arguments libfreenect-examples)` with
`substitute-keyword-arguments` to reuse arguments, but modify
`configure-flags` etc. (eg: qtx11extras)


The build system can use 'imported-modules' to make a set of guile
modules (which can contains useful procedures, etc.) available to the
builder, but thas's overkill to be used here...


Toggle quote (35 lines)
>
> diff --git a/gnu/packages/openkinect.scm b/gnu/packages/openkinect.scm
> new file mode 100644
> index 0000000000..1aebb34384
> --- /dev/null
> +++ b/gnu/packages/openkinect.scm
> @@ -0,0 +1,137 @@
> +(define-module (gnu packages openkinect)
> + #:use-module (guix packages)
> + #:use-module (guix git-download)
> + #:use-module (guix build-system cmake)
> + #:use-module ((guix licenses) #:prefix license:)
> + #:use-module (gnu packages pkg-config)
> + #:use-module (gnu packages libusb)
> + #:use-module (gnu packages python)
> + #:use-module (gnu packages python-xyz)
> + #:use-module (gnu packages gl)
> + #:use-module (gnu packages pkg-config)
> + #:use-module (gnu packages image-processing))
> +
> +(define-public libfreenect
> + (let ((version "0.6.1"))
> + (package
> + (name "libfreenect")
> + (version version)
> + (source (origin
> + (method git-fetch)
> + (uri (git-reference
> + (url "https://github.com/OpenKinect/libfreenect")
> + (commit (string-append "v" version))))
> + (sha256
> + (base32 "0was1va167rqshmpn382h36yyprpfi9cwillb6ylppmnfdrfrhrr"))))
> + (build-system cmake-build-system)
> + (arguments
> + '(#:tests? #f ; Project has not tests
"has not tests" sounds wrong be me, maybe: "package has no tests".

Otherwise, look good to me!
E
E
Ekaitz Zarraga wrote on 19 May 2020 15:42
(name . iyzsong@member.fsf.org)(address . iyzsong@member.fsf.org)(name . 41294\@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
dwdu0IFP-FBpKY7y534ks2EfI-mzljVFIhzsFddw0aV0LiBC-4QVKl_rkYuoqO1vzW9-MlAE_IbnvdgGtlieqn1nyJNFuwPnlL3asTzvgts=@elenq.tech
Hi,


Toggle quote (17 lines)
> > There's some kind of weird magic I'm not getting.
>
> Hello, I don't know the whole detail too, but to build a package, guix likely:
>
> - Load and eval the package module, to get the package object. The
> 'arguments' field is a list.
> - Convert this package object to a derivation, and write it in store as
> a file (/gnu/store/*.drv). Where 'arguments' being part of the
> builder, serialize as string to the file, it dosen't do complex things
> for procedure bindings, only write their string descriptions... So
> when the builder file is loaded, you get `Unknown object` errors.
>
> Here, to avoid duplicating the code, you can:
>
>
> 1. Unquote list value into `arguments`. (eg: 'asdf-substitutions' in lisp.scm)

This doesn't work for me. I don't know why.

Just moved the lambda to a (define* deactivate-sources ...) and then when I try to put the name like

(arguments `( #tests? .... ,deactivate-sources ...)

Shoots an Unknown object error. I add a diff below to let you see the whole picture of what I did and doesn't work.

Toggle quote (8 lines)
> 2. Use `(package-arguments libfreenect-examples)` with
> `substitute-keyword-arguments` to reuse arguments, but modify
> `configure-flags` etc. (eg: qtx11extras)
>
> The build system can use 'imported-modules' to make a set of guile
> modules (which can contains useful procedures, etc.) available to the
> builder, but thas's overkill to be used here...

I'll check that option too.


Thank you for your help!


Toggle diff (145 lines)
diff --git a/gnu/local.mk b/gnu/local.mk
index ab2bac9bc5..b9c09cc5e3 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -394,6 +394,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/nvi.scm				\
   %D%/packages/ocaml.scm			\
   %D%/packages/ocr.scm				\
+  %D%/packages/openkinect.scm			\
   %D%/packages/onc-rpc.scm			\
   %D%/packages/opencl.scm			\
   %D%/packages/openbox.scm			\
diff --git a/gnu/packages/openkinect.scm b/gnu/packages/openkinect.scm
new file mode 100644
index 0000000000..5a17acef0e
--- /dev/null
+++ b/gnu/packages/openkinect.scm
@@ -0,0 +1,127 @@
+(define-module (gnu packages openkinect)
+  #:use-module (guix packages)
+  #:use-module (guix git-download)
+  #:use-module (guix build-system cmake)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages libusb)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages python-xyz)
+  #:use-module (gnu packages gl)
+  #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages image-processing))
+
+(define-public libfreenect
+  (let ((version "0.6.1"))
+    (package
+      (name "libfreenect")
+      (version version)
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/OpenKinect/libfreenect")
+                      (commit (string-append "v" version))))
+                (sha256
+                 (base32 "0was1va167rqshmpn382h36yyprpfi9cwillb6ylppmnfdrfrhrr"))))
+      (build-system cmake-build-system)
+      (arguments
+       '(#:tests? #f ; Project has not tests
+         #:configure-flags
+         '("-DBUILD_FAKENECT=ON"
+           "-DBUILD_CPP=ON"
+           "-DBUILD_EXAMPLES=OFF" ; Available in libfreenect-examples
+           "-DBUILD_CV=OFF"       ; Available in libfreenect-cv
+           "-DBUILD_PYTHON=OFF"   ; Available in libfreenect-python
+           "-DBUILD_C_SYNC=ON")
+         #:phases
+         (modify-phases %standard-phases
+           (add-after 'install 'install-udev-rules
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let* ((out (assoc-ref outputs "out"))
+                      (rules-out (string-append out "/lib/udev/rules.d")))
+                 (install-file "../source/platform/linux/udev/51-kinect.rules"
+                               (string-append rules-out "51-kinect.rules"))
+                 #t))))))
+      (native-inputs
+       `(("pkg-config" ,pkg-config)))
+      (inputs
+       `(("libusb" ,libusb)))
+      (synopsis "Drivers and libraries for the Xbox Kinect device")
+      (description "libfreenect is a userspace driver for the Microsoft Kinect.
+It supports: RGB and Depth Images, Motors, Accelerometer, LED and Audio.")
+      (home-page "https://openkinect.org/")
+      (license license:gpl2+))))
+
+(define (disable-sources)
+  (lambda* (#:key outputs #:allow-other-keys)
+           (substitute* "CMakeLists.txt"
+                        ((".*libusb.*") "")
+                        (("add_subdirectory \\(src\\)") "")
+                        ((".*libfreenectConfig.cmake.*") ""))))
+
+(define-public libfreenect-examples
+  (package
+    (inherit libfreenect)
+    (name "libfreenect-examples")
+    (inputs
+     `(("libfreenect" ,libfreenect)
+       ("glut" ,freeglut)))
+    (arguments
+     `(#:tests? #f ; Project has not tests
+       #:configure-flags '("-DBUILD_EXAMPLES=ON"
+                           "-DBUILD_FAKENECT=OFF"
+                           "-DBUILD_CPP=OFF"
+                           "-DBUILD_C_SYNC=OFF"
+                           "-DBUILD_CV=OFF")
+       #:phases
+       (modify-phases %standard-phases
+         ;; Sources are already compiled in libfreenect input
+         (add-after 'unpack 'disable-sources ,disable-sources)))) ;; UNKNOW OBJECT!
+    (synopsis "Examples for libfreenect, the Xbox Kinect device library")))
+
+(define-public libfreenect-cv
+  (package
+    (inherit libfreenect)
+    (name "libfreenect-cv")
+    (inputs
+     `(("libfreenect" ,libfreenect)
+       ("opencv" ,opencv)))
+    (arguments
+     `(#:tests? #f ; Project has not tests
+       #:configure-flags '("-DBUILD_EXAMPLES=OFF"
+                           "-DBUILD_FAKENECT=OFF"
+                           "-DBUILD_CPP=OFF"
+                           "-DBUILD_C_SYNC=OFF"
+                           "-DBUILD_CV=ON")
+       #:phases
+       (modify-phases %standard-phases
+         ;; Sources are already compiled in libfreenect input
+         (add-after 'unpack 'disable-sources ,disable-sources))))
+    (synopsis "OpenCV wrapper for libfreenect, the Xbox Kinect device
+library")))
+
+(define-public libfreenect-python
+  (package
+    (inherit libfreenect)
+    (name "libfreenect-python")
+    (native-inputs
+     `(("python-cython" ,python-cython)))
+    (inputs
+     `(("libfreenect" ,libfreenect)))
+    (propagated-inputs
+     `(("python" ,python)
+       ("python-numpy" ,python-numpy)))
+    (arguments
+     `(#:tests? #f ; Project has not tests
+       #:configure-flags '("-DBUILD_EXAMPLES=OFF"
+                           "-DBUILD_FAKENECT=OFF"
+                           "-DBUILD_CPP=OFF"
+                           "-DBUILD_C_SYNC=OFF"
+                           "-DBUILD_CV=OFF"
+                           "-DBUILD_PYTHON3=ON")
+       #:phases
+       (modify-phases %standard-phases
+         ;; Sources are already compiled in libfreenect input
+         (add-after 'unpack 'disable-sources ,disable-sources))))
+    (synopsis "Python wrapper for libfreenect, the Xbox Kinect device
+library")))
E
E
Ekaitz Zarraga wrote on 19 May 2020 15:52
(name . iyzsong@member.fsf.org)(address . iyzsong@member.fsf.org)(name . 41294\@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
9ZfB8rv2oVS3f1P4KqZV9twP9VRoO9GNuPvbzT_BjLAzXCs6kumdqaIPD_TMejSv5B0D34dg6tpbmKPmIQxuLW64pU35VX5LGNn5tM9Ka04=@elenq.tech
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Tuesday, May 19, 2020 3:42 PM, Ekaitz Zarraga <ekaitz@elenq.tech> wrote:

Toggle quote (359 lines)
> Hi,
>
> > > There's some kind of weird magic I'm not getting.
> >
> > Hello, I don't know the whole detail too, but to build a package, guix likely:
> >
> > - Load and eval the package module, to get the package object. The
> > 'arguments' field is a list.
> >
> > - Convert this package object to a derivation, and write it in store as
> > a file (/gnu/store/*.drv). Where 'arguments' being part of the
> > builder, serialize as string to the file, it dosen't do complex things
> > for procedure bindings, only write their string descriptions... So
> > when the builder file is loaded, you get `Unknown object` errors.
> > Here, to avoid duplicating the code, you can:
> >
> >
> > 1. Unquote list value into `arguments`. (eg: 'asdf-substitutions' in lisp.scm)
>
> This doesn't work for me. I don't know why.
>
> Just moved the lambda to a (define* deactivate-sources ...) and then when I try to put the name like
>
> (arguments `( #tests? .... ,deactivate-sources ...)
>
> Shoots an Unknown object error. I add a diff below to let you see the whole picture of what I did and doesn't work.
>
> > 2. Use `(package-arguments libfreenect-examples)` with
> > `substitute-keyword-arguments` to reuse arguments, but modify
> > `configure-flags` etc. (eg: qtx11extras)
> > The build system can use 'imported-modules' to make a set of guile
> > modules (which can contains useful procedures, etc.) available to the
> > builder, but thas's overkill to be used here...
> >
>
> I'll check that option too.
>
> Thank you for your help!
>
> diff --git a/gnu/local.mk b/gnu/local.mk
> index ab2bac9bc5..b9c09cc5e3 100644
> --- a/gnu/local.mk
> +++ b/gnu/local.mk
> @@ -394,6 +394,7 @@ GNU_SYSTEM_MODULES = \
> %D%/packages/nvi.scm \
> %D%/packages/ocaml.scm \
> %D%/packages/ocr.scm \
>
> - %D%/packages/openkinect.scm \
> %D%/packages/onc-rpc.scm \
> %D%/packages/opencl.scm \
> %D%/packages/openbox.scm \
> diff --git a/gnu/packages/openkinect.scm b/gnu/packages/openkinect.scm
> new file mode 100644
> index 0000000000..5a17acef0e
> --- /dev/null
> +++ b/gnu/packages/openkinect.scm
> @@ -0,0 +1,127 @@
> +(define-module (gnu packages openkinect)
>
> - #:use-module (guix packages)
> - #:use-module (guix git-download)
> - #:use-module (guix build-system cmake)
> - #:use-module ((guix licenses) #:prefix license:)
> - #:use-module (gnu packages pkg-config)
> - #:use-module (gnu packages libusb)
> - #:use-module (gnu packages python)
> - #:use-module (gnu packages python-xyz)
> - #:use-module (gnu packages gl)
> - #:use-module (gnu packages pkg-config)
> - #:use-module (gnu packages image-processing))
> -
>
> +(define-public libfreenect
>
> - (let ((version "0.6.1"))
> - (package
> - (name "libfreenect")
>
>
> - (version version)
>
>
> - (source (origin
>
>
> - (method git-fetch)
>
>
> - (uri (git-reference
>
>
> - (url "https://github.com/OpenKinect/libfreenect")
>
>
> - (commit (string-append "v" version))))
>
>
> - (sha256
>
>
> - (base32 "0was1va167rqshmpn382h36yyprpfi9cwillb6ylppmnfdrfrhrr"))))
>
>
> - (build-system cmake-build-system)
>
>
> - (arguments
>
>
> - '(#:tests? #f ; Project has not tests
>
>
> - #:configure-flags
>
>
> - '("-DBUILD_FAKENECT=ON"
>
>
> - "-DBUILD_CPP=ON"
>
>
> - "-DBUILD_EXAMPLES=OFF" ; Available in libfreenect-examples
>
>
> - "-DBUILD_CV=OFF" ; Available in libfreenect-cv
>
>
> - "-DBUILD_PYTHON=OFF" ; Available in libfreenect-python
>
>
> - "-DBUILD_C_SYNC=ON")
>
>
> - #:phases
>
>
> - (modify-phases %standard-phases
>
>
> - (add-after 'install 'install-udev-rules
>
>
> - (lambda* (#:key outputs #:allow-other-keys)
>
>
> - (let* ((out (assoc-ref outputs "out"))
>
>
> - (rules-out (string-append out "/lib/udev/rules.d")))
>
>
> - (install-file "../source/platform/linux/udev/51-kinect.rules"
>
>
> - (string-append rules-out "51-kinect.rules"))
>
>
> - #t))))))
>
>
> - (native-inputs
>
>
> - `(("pkg-config" ,pkg-config)))
>
>
> - (inputs
>
>
> - `(("libusb" ,libusb)))
>
>
> - (synopsis "Drivers and libraries for the Xbox Kinect device")
>
>
> - (description "libfreenect is a userspace driver for the Microsoft Kinect.
>
>
>
> +It supports: RGB and Depth Images, Motors, Accelerometer, LED and Audio.")
>
> - (home-page "https://openkinect.org/")
>
>
> - (license license:gpl2+))))
>
>
> -
>
> +(define (disable-sources)
>
> - (lambda* (#:key outputs #:allow-other-keys)
> - (substitute* "CMakeLists.txt"
>
>
> - ((".*libusb.*") "")
>
>
> - (("add_subdirectory \\\\(src\\\\)") "")
>
>
> - ((".*libfreenectConfig.cmake.*") ""))))
>
>
> -
>
> +(define-public libfreenect-examples
>
> - (package
> - (inherit libfreenect)
> - (name "libfreenect-examples")
> - (inputs
> - `(("libfreenect" ,libfreenect)
>
>
> - ("glut" ,freeglut)))
>
>
> - (arguments
> - `(#:tests? #f ; Project has not tests
>
>
> - #:configure-flags '("-DBUILD_EXAMPLES=ON"
>
>
> - "-DBUILD_FAKENECT=OFF"
>
>
> - "-DBUILD_CPP=OFF"
>
>
> - "-DBUILD_C_SYNC=OFF"
>
>
> - "-DBUILD_CV=OFF")
>
>
> - #:phases
>
>
> - (modify-phases %standard-phases
>
>
> - ;; Sources are already compiled in libfreenect input
>
>
> - (add-after 'unpack 'disable-sources ,disable-sources)))) ;; UNKNOW OBJECT!
>
>
> - (synopsis "Examples for libfreenect, the Xbox Kinect device library")))
> -
>
> +(define-public libfreenect-cv
>
> - (package
> - (inherit libfreenect)
> - (name "libfreenect-cv")
> - (inputs
> - `(("libfreenect" ,libfreenect)
>
>
> - ("opencv" ,opencv)))
>
>
> - (arguments
> - `(#:tests? #f ; Project has not tests
>
>
> - #:configure-flags '("-DBUILD_EXAMPLES=OFF"
>
>
> - "-DBUILD_FAKENECT=OFF"
>
>
> - "-DBUILD_CPP=OFF"
>
>
> - "-DBUILD_C_SYNC=OFF"
>
>
> - "-DBUILD_CV=ON")
>
>
> - #:phases
>
>
> - (modify-phases %standard-phases
>
>
> - ;; Sources are already compiled in libfreenect input
>
>
> - (add-after 'unpack 'disable-sources ,disable-sources))))
>
>
> - (synopsis "OpenCV wrapper for libfreenect, the Xbox Kinect device
> +library")))
>
> -
>
> +(define-public libfreenect-python
>
> - (package
> - (inherit libfreenect)
> - (name "libfreenect-python")
> - (native-inputs
> - `(("python-cython" ,python-cython)))
>
>
> - (inputs
> - `(("libfreenect" ,libfreenect)))
>
>
> - (propagated-inputs
> - `(("python" ,python)
>
>
> - ("python-numpy" ,python-numpy)))
>
>
> - (arguments
> - `(#:tests? #f ; Project has not tests
>
>
> - #:configure-flags '("-DBUILD_EXAMPLES=OFF"
>
>
> - "-DBUILD_FAKENECT=OFF"
>
>
> - "-DBUILD_CPP=OFF"
>
>
> - "-DBUILD_C_SYNC=OFF"
>
>
> - "-DBUILD_CV=OFF"
>
>
> - "-DBUILD_PYTHON3=ON")
>
>
> - #:phases
>
>
> - (modify-phases %standard-phases
>
>
> - ;; Sources are already compiled in libfreenect input
>
>
> - (add-after 'unpack 'disable-sources ,disable-sources))))
>
>
> - (synopsis "Python wrapper for libfreenect, the Xbox Kinect device
> +library")))
>

oh,

the code is wrong, there parenthesis on the define are making it a function but anyway:
- Tested using ,(disable-sources) FAIL
- Tested removing the parenthesis and leaving (define disable-sources (lambda*...))

There must be something I'm missing.
宋文武 wrote on 20 May 2020 15:33
(name . Ekaitz Zarraga)(address . ekaitz@elenq.tech)(name . 41294@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
87h7wak9yj.fsf@member.fsf.org
Ekaitz Zarraga <ekaitz@elenq.tech> writes:

Toggle quote (47 lines)
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Tuesday, May 19, 2020 3:42 PM, Ekaitz Zarraga <ekaitz@elenq.tech> wrote:
>
>> Hi,
>>
>> > > There's some kind of weird magic I'm not getting.
>> >
>> > Hello, I don't know the whole detail too, but to build a package, guix likely:
>> >
>> > - Load and eval the package module, to get the package object. The
>> > 'arguments' field is a list.
>> >
>> > - Convert this package object to a derivation, and write it in store as
>> > a file (/gnu/store/*.drv). Where 'arguments' being part of the
>> > builder, serialize as string to the file, it dosen't do complex things
>> > for procedure bindings, only write their string descriptions... So
>> > when the builder file is loaded, you get `Unknown object` errors.
>> > Here, to avoid duplicating the code, you can:
>> >
>> >
>> > 1. Unquote list value into `arguments`. (eg: 'asdf-substitutions' in lisp.scm)
>>
>> This doesn't work for me. I don't know why.
>>
>> Just moved the lambda to a (define* deactivate-sources ...) and then when I try to put the name like
>>
>> (arguments `( #tests? .... ,deactivate-sources ...)
>>
>> Shoots an Unknown object error. I add a diff below to let you see the whole picture of what I did and doesn't work.
>>
>> > 2. Use `(package-arguments libfreenect-examples)` with
>> > `substitute-keyword-arguments` to reuse arguments, but modify
>> > `configure-flags` etc. (eg: qtx11extras)
>> > The build system can use 'imported-modules' to make a set of guile
>> > modules (which can contains useful procedures, etc.) available to the
>> > builder, but thas's overkill to be used here...
>> >
>> [...]
>
> oh,
>
> the code is wrong, there parenthesis on the define are making it a function but anyway:
> - Tested using ,(disable-sources) FAIL
> - Tested removing the parenthesis and leaving (define disable-sources (lambda*...))
>
> There must be something I'm missing.

Um, I mean something like this:

(define libfreenect-derived-phases
'(modify-phases %standard-phases
(lambda* (#:key outputs #:allow-other-keys)
...)))

...
(arguments
`(#:phases ,libfreenect-derived-phases))
...


Here 'libfreenect-derived-phases' is a list of symbols, the arguments
field we want is a list of symbols too.
E
E
Ekaitz Zarraga wrote on 20 May 2020 18:37
(name . iyzsong@member.fsf.org)(address . iyzsong@member.fsf.org)(name . 41294\@debbugs.gnu.org)(address . 41294@debbugs.gnu.org)
QLWnu8KtNBTHA51a59dkF3pxVUigT96IOwcqgtejj0Bmi5AmUuSOMIm3BCHfrR4YUIBN7dNK0bLnv9l5qnyy6iTCIvga0qTmmfLO_2ZmDaE=@elenq.tech
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Wednesday, May 20, 2020 3:33 PM, <iyzsong@member.fsf.org> wrote:
Toggle quote (16 lines)
>
> Um, I mean something like this:
>
> (define libfreenect-derived-phases
> '(modify-phases %standard-phases
> (lambda* (#:key outputs #:allow-other-keys)
> ...)))
>
> ...
> (arguments
> `(#:phases ,libfreenect-derived-phases))
> ...
>
> Here 'libfreenect-derived-phases' is a list of symbols, the arguments
> field we want is a list of symbols too.

Hi,

That makes way more sense than what I was trying to do.
I applied that and separated libfreenect to a different module. Patch below.

Thank you very much for your support.

PS: I'm still wondering what kind of weird magic is involved in the example I shown.


From efcf2b3fcb4b422939550e614d20abafaaed3d7f Mon Sep 17 00:00:00 2001
From: Ekaitz Zarraga <ekaitz@elenq.tech>
Date: Wed, 20 May 2020 18:18:23 +0200
Subject: [PATCH] gnu: openkinect: New module

* gnu/packages/openkinect.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
---
gnu/local.mk | 1 +
gnu/packages/openkinect.scm | 140 ++++++++++++++++++++++++++++++++++++
2 files changed, 141 insertions(+)
create mode 100644 gnu/packages/openkinect.scm

Toggle diff (158 lines)
diff --git a/gnu/local.mk b/gnu/local.mk
index ab2bac9bc5..b9c09cc5e3 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -394,6 +394,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/nvi.scm				\
   %D%/packages/ocaml.scm			\
   %D%/packages/ocr.scm				\
+  %D%/packages/openkinect.scm			\
   %D%/packages/onc-rpc.scm			\
   %D%/packages/opencl.scm			\
   %D%/packages/openbox.scm			\
diff --git a/gnu/packages/openkinect.scm b/gnu/packages/openkinect.scm
new file mode 100644
index 0000000000..96150801e6
--- /dev/null
+++ b/gnu/packages/openkinect.scm
@@ -0,0 +1,140 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2020 Ekaitz Zarraga <ekaitz@elenq.tech>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages openkinect)
+  #:use-module (guix packages)
+  #:use-module (guix git-download)
+  #:use-module (guix build-system cmake)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages libusb)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages python-xyz)
+  #:use-module (gnu packages gl)
+  #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages image-processing))
+
+(define-public libfreenect
+  (let ((version "0.6.1"))
+    (package
+      (name "libfreenect")
+      (version version)
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/OpenKinect/libfreenect")
+                      (commit (string-append "v" version))))
+                (sha256
+                 (base32 "0was1va167rqshmpn382h36yyprpfi9cwillb6ylppmnfdrfrhrr"))))
+      (build-system cmake-build-system)
+      (arguments
+       '(#:tests? #f ; Project has not tests
+         #:configure-flags
+         '("-DBUILD_FAKENECT=ON"
+           "-DBUILD_CPP=ON"
+           "-DBUILD_EXAMPLES=OFF" ; Available in libfreenect-examples
+           "-DBUILD_CV=OFF"       ; Available in libfreenect-cv
+           "-DBUILD_PYTHON=OFF"   ; Available in libfreenect-python
+           "-DBUILD_C_SYNC=ON")
+         #:phases
+         (modify-phases %standard-phases
+           (add-after 'install 'install-udev-rules
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let* ((out (assoc-ref outputs "out"))
+                      (rules-out (string-append out "/lib/udev/rules.d")))
+                 (install-file "../source/platform/linux/udev/51-kinect.rules"
+                               (string-append rules-out "51-kinect.rules"))
+                 #t))))))
+      (native-inputs
+       `(("pkg-config" ,pkg-config)))
+      (inputs
+       `(("libusb" ,libusb)))
+      (synopsis "Drivers and libraries for the Xbox Kinect device")
+      (description "libfreenect is a userspace driver for the Microsoft Kinect.
+It supports: RGB and Depth Images, Motors, Accelerometer, LED and Audio.")
+      (home-page "https://openkinect.org/")
+      (license license:gpl2+))))
+
+;; Sources are already compiled in libfreenect input: remove them from the
+;; compilation
+(define libfreenect-derived-phases
+  '(modify-phases %standard-phases
+     (add-after 'unpack 'disable-sources
+       (lambda* (#:key outputs #:allow-other-keys)
+         (substitute* "CMakeLists.txt"
+           ((".*libusb.*") "")
+           (("add_subdirectory \\(src\\)") "")
+           ((".*libfreenectConfig.cmake.*") ""))))))
+
+(define-public libfreenect-examples
+  (package
+    (inherit libfreenect)
+    (name "libfreenect-examples")
+    (inputs
+     `(("libfreenect" ,libfreenect)
+       ("glut" ,freeglut)))
+    (arguments
+     `(#:tests? #f ; Project has not tests
+       #:configure-flags '("-DBUILD_EXAMPLES=ON"
+                           "-DBUILD_FAKENECT=OFF"
+                           "-DBUILD_CPP=OFF"
+                           "-DBUILD_C_SYNC=OFF"
+                           "-DBUILD_CV=OFF")
+       #:phases ,libfreenect-derived-phases))
+    (synopsis "Examples for libfreenect, the Xbox Kinect device library")))
+
+(define-public libfreenect-cv
+  (package
+    (inherit libfreenect)
+    (name "libfreenect-cv")
+    (inputs
+     `(("libfreenect" ,libfreenect)
+       ("opencv" ,opencv)))
+    (arguments
+     `(#:tests? #f ; Project has not tests
+       #:configure-flags '("-DBUILD_EXAMPLES=OFF"
+                           "-DBUILD_FAKENECT=OFF"
+                           "-DBUILD_CPP=OFF"
+                           "-DBUILD_C_SYNC=OFF"
+                           "-DBUILD_CV=ON")
+       #:phases ,libfreenect-derived-phases))
+    (synopsis "OpenCV wrapper for libfreenect, the Xbox Kinect device
+library")))
+
+(define-public libfreenect-python
+  (package
+    (inherit libfreenect)
+    (name "libfreenect-python")
+    (native-inputs
+     `(("python-cython" ,python-cython)))
+    (inputs
+     `(("libfreenect" ,libfreenect)))
+    (propagated-inputs
+     `(("python" ,python)
+       ("python-numpy" ,python-numpy)))
+    (arguments
+     `(#:tests? #f ; Project has not tests
+       #:configure-flags '("-DBUILD_EXAMPLES=OFF"
+                           "-DBUILD_FAKENECT=OFF"
+                           "-DBUILD_CPP=OFF"
+                           "-DBUILD_C_SYNC=OFF"
+                           "-DBUILD_CV=OFF"
+                           "-DBUILD_PYTHON3=ON")
+       #:phases ,libfreenect-derived-phases))
+    (synopsis "Python wrapper for libfreenect, the Xbox Kinect device
+library")))
--
2.26.2
宋文武 wrote on 21 May 2020 13:38
(name . Ekaitz Zarraga)(address . ekaitz@elenq.tech)(name . 41294@debbugs.gnu.org)(address . 41294-done@debbugs.gnu.org)
87ftbt8qmw.fsf@member.fsf.org
Ekaitz Zarraga <ekaitz@elenq.tech> writes:

Toggle quote (23 lines)
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Wednesday, May 20, 2020 3:33 PM, <iyzsong@member.fsf.org> wrote:
>>
>> Um, I mean something like this:
>>
>> (define libfreenect-derived-phases
>> '(modify-phases %standard-phases
>> (lambda* (#:key outputs #:allow-other-keys)
>> ...)))
>>
>> ...
>> (arguments
>> `(#:phases ,libfreenect-derived-phases))
>> ...
>>
>> Here 'libfreenect-derived-phases' is a list of symbols, the arguments
>> field we want is a list of symbols too.
>
> Hi,
>
> That makes way more sense than what I was trying to do.
> I applied that and separated libfreenect to a different module. Patch below.

Pushed, with:
- Change libfreenect-python to 'python-libfreenect'.
- Change libfreenect-cv to 'libfreenect-opencv'.
- Change some comments..

Thank you!

Toggle quote (6 lines)
>
> Thank you very much for your support.
>
> PS: I'm still wondering what kind of weird magic is involved in the example I shown.
>

Basically we can't use procedure (defined outside of the builder
environment) values in the package's arguments field, it have to be self
contained, as the package builder is a guile script file serialized from
the package object (procedures serilazied into #<procedure ...>, and
can't be loaded again), and will be executed in an isolated environment.
Closed
E
E
Ekaitz Zarraga wrote on 21 May 2020 13:40
(name . iyzsong@member.fsf.org)(address . iyzsong@member.fsf.org)(name . 41294\@debbugs.gnu.org)(address . 41294-done@debbugs.gnu.org)
UMTlws2bIwQVrF9wtpimlpAml_T_aWhz6udG3lSMOEPtOlfcTx4GkxUu32d9_ASR9Yfy-X2odlLolpqQqjDAMaxdWJSGev4EiaGjFZVAmLY=@elenq.tech
Hi,

Toggle quote (8 lines)
> > PS: I'm still wondering what kind of weird magic is involved in the example I shown.
>
> Basically we can't use procedure (defined outside of the builder
> environment) values in the package's arguments field, it have to be self
> contained, as the package builder is a guile script file serialized from
> the package object (procedures serilazied into #<procedure ...>, and
> can't be loaded again), and will be executed in an isolated environment.

Great. Understood.
Thank you very much.
Closed
?
Your comment

This issue is archived.

To comment on this conversation send email to 41294@debbugs.gnu.org