diff mbox series

[bug#49934,1/3] gnu: Add libx86emu

Message ID dv4hfMlNt3nZfXASs419gzeP1mFxIEOrH5yHul0FZWtEjR7Uv8ruRfTpr4ER4YkkvP0o8OQlqpe-lRZ4uwcztWBpayZU0GnmGOBDHyJEsps=@protonmail.com
State Accepted
Headers show
Series [bug#49934,1/3] gnu: Add libx86emu | expand

Commit Message

phodina Aug. 7, 2021, 9:58 p.m. UTC
* gnu/packages/hardware.scm: (libx86emu): New variable.

--
2.32.0

Comments

pelzflorian (Florian Pelz) Aug. 8, 2021, 10:10 a.m. UTC | #1
On Sat, Aug 07, 2021 at 09:58:55PM +0000, phodina via Guix-patches via wrote:
> +  (home-page "https://github.com/wfeldt/libx86emu")

FYI this is the same package as <http://issues.guix.gnu.org/45744>.

I don’t know what became of it.
phodina Aug. 9, 2021, noon UTC | #2
Hi

On Sunday, August 8th, 2021 at 12:10 PM, pelzflorian (Florian Pelz) <pelzflorian@pelzflorian.de> wrote:

> On Sat, Aug 07, 2021 at 09:58:55PM +0000, phodina via Guix-patches via wrote:
>
> > -   (home-page "https://github.com/wfeldt/libx86emu")
>
> FYI this is the same package as http://issues.guix.gnu.org/45744.
>
> I don’t know what became of it.

Thanks. I didn't know there's a patch already. The aim of this one is to get the hwinfo and hw-prober to get the hardware details.

I've not encountered this situation. So what do you think is the best approach?

Use the patch from Vincent Legoll and refactor the other two?

So that both issues are closed?

Kind regards
Petr
pelzflorian (Florian Pelz) Aug. 9, 2021, 5:06 p.m. UTC | #3
On Mon, Aug 09, 2021 at 12:00:00PM +0000, phodina wrote:
> Thanks. I didn't know there's a patch already. The aim of this one is to get the hwinfo and hw-prober to get the hardware details.

I think it is good to get your patch into shape and merged.  While I
haven’t been involved in package review (shame on me), I’ll give it a
try.

You should, after applying each of your patches, cd to the guix repo
and run `./etc/indent-code.el gnu/packages/hardware.scm` as described
in `info '(guix)Formatting Code'`.

`./pre-inst-env guix lint libx86emu` warns that your custom check
phase does not consider #:tests?  (i.e. it does not work with the
--without-tests transform option).

As for the package libx86emu proper:

> (define-public libx86emu
>   (package
>     (name "libx86emu")
>     (version "3.1")
>     (source (origin
>               (method git-fetch)
>               (uri (git-reference
>                     (url "https://github.com/wfeldt/libx86emu")
>                     (commit version)))
>               (file-name (git-file-name name version))
>               (sha256
>                (base32
>                 "104xqc6nj9rpi7knl3dfqvasf087hlz2n5yndb1iycw35a6j509b"))))
>     (build-system gnu-build-system)
>     (arguments
>      `(#:make-flags (list
>                      (string-append "CC=" ,(cc-for-target))
>                      (string-append "DESTDIR=" %output)
>                      (string-append "LIBDIR=/lib"))
>        #:phases (modify-phases %standard-phases
>                   (delete 'configure)
>                   (add-after 'unpack 'fix-version-and-usr
>                     (lambda* (#:key inputs #:allow-other-keys)
>                       (delete-file "git2log")

I am not sure, would it be better to delete this git2log in an origin
snippet?  I have not checked.



>                       (let* ((file (open-file "VERSION" "a")))
>                         (display ,version file)
>                         (close-port file))
>                       (substitute* "Makefile"
>                         (("/usr") "/"))))
>                   (replace 'check
>                     (lambda* _
>                       (invoke "make" "test"))))))
>     (native-inputs `(("git" ,git) ("perl" ,perl) ("nasm" ,nasm)))
>     (synopsis "Library for x86 emulation")
>     (description "Small library to emulate x86 instructions.  The focus here
> is not a complete emulation (go for qemu for this) but to cover enough for
> typical firmware blobs.

The start of the sentence is missing before @enumerate.  “You can”?

> @enumerate
> @item intercept any memory access or directly map real memory ranges
> @item intercept any i/o access, map real i/o ports, or block any real i/o
> @item intercept any interrupt
> @item provides hook to run after each instruction

Either “provides a hook” or “provides hooks”.


> @item recognizes a special x86 instruction that can trigger logging

s/recognizes/recognize/


> @item has integrated logging

Maybe s/has/use/


> @end enumerate")
>     (home-page "https://github.com/wfeldt/libx86emu")
>     (license license:bsd-1)))

The license is not bsd-1 but x11-style, I think.

Regards,
Florian
Raghav Gururajan Aug. 30, 2021, 9:34 p.m. UTC | #4
Hi Petr!

I have merged #49934 and #50283.

I'll combine our patches and send a new one. :)

Regards,
RG.
Raghav Gururajan Oct. 1, 2021, 11:26 p.m. UTC | #5
Hi,

I have sent a patch for hw-probe (https://issues.guix.gnu.org/49934#9), 
which requires some refinements.

[1] Some programs in the script are not patched, hence doesn't work in 
pure environment.
[2] Synopsis and description has to be revised.
[3] Finding a way to avoid propagation of hw-info.

@phodina, Would you be able to hack on the above.

Regards,
RG.
Ricardo Wurmus Dec. 16, 2021, 5:53 a.m. UTC | #6
Thanks for the patch!

I’m afraid the 'patch build phase is much too repetitive.  You can
greatly simplify it by doing a substitution like this:

--8<---------------cut here---------------start------------->8---
(substitute* "hw-probe.pl"
  (("Cmd\\(\"([^\"]+)" _ command)
   (string-append "Cmd(\"" (which command))))
--8<---------------cut here---------------end--------------->8---

The regular expression has a sub-group that matches everything after the
opening double quote until it hits another double quote.  That group is
captured as “command”.  We then look up that string in the build
environment with “which” (not the executable of the same name), which
returns the absolute file name corresponding to the command.
Raghav Gururajan Dec. 25, 2021, 9:17 p.m. UTC | #7
Hi Ricardo!

> --8<---------------cut here---------------start------------->8---
> (substitute* "hw-probe.pl"
>    (("Cmd\\(\"([^\"]+)" _ command)
>     (string-append "Cmd(\"" (which command))))
> --8<---------------cut here---------------end--------------->8---

Thanks for the snippet and explanation.

I am wondering these,
[1] Does require import of specific modules?
[2] If `(which command)`'s output is empty, will it return #f?

Regards,
RG.
Efraim Flashner Dec. 27, 2021, 9:59 a.m. UTC | #8
On Sat, Dec 25, 2021 at 04:17:32PM -0500, Raghav Gururajan via Guix-patches via wrote:
> Hi Ricardo!
> 
> > --8<---------------cut here---------------start------------->8---
> > (substitute* "hw-probe.pl"
> >    (("Cmd\\(\"([^\"]+)" _ command)
> >     (string-append "Cmd(\"" (which command))))
> > --8<---------------cut here---------------end--------------->8---
> 
> Thanks for the snippet and explanation.
> 
> I am wondering these,
> [1] Does require import of specific modules?
> [2] If `(which command)`'s output is empty, will it return #f?

For 2, looks like yes

(ins)efraim@3900XT ~$ which -a svn
which: no svn in (/home/efraim/Applications/.bin:/gnu/store/4iyar3w7k30b5j13v9cf5gmiz5livkyj-enlightenment-0.24.2/bin:/run/setuid-programs:/home/efraim/.config/guix/current/bin:/home/efraim/.guix-profile/bin:/home/efraim/.guix-profile/sbin:/run/current-system/profile/bin:/run/current-system/profile/sbin)
(ins)efraim@3900XT ~$ guile
GNU Guile 3.0.7
Copyright (C) 1995-2021 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
(ins)scheme@(guile-user)> (use-modules (guix build utils))
(ins)scheme@(guile-user)> (which "svn")
$1 = #f
(ins)scheme@(guile-user)>
Maxim Cournoyer June 23, 2022, 3:35 p.m. UTC | #9
Hi,

Raghav Gururajan <rg@raghavgururajan.name> writes:

> Hi Ricardo!
>
>> --8<---------------cut here---------------start------------->8---
>> (substitute* "hw-probe.pl"
>>    (("Cmd\\(\"([^\"]+)" _ command)
>>     (string-append "Cmd(\"" (which command))))
>> --8<---------------cut here---------------end--------------->8---
>
> Thanks for the snippet and explanation.
>
> I am wondering these,
> [1] Does require import of specific modules?

No.  `which', the Scheme procedure, is part of (guix build utils).

> [2] If `(which command)`'s output is empty, will it return #f?

Yes, and I agree that's a problem.

Fortunately, the recently added search-input-file more usefully raises
an error when the file it is looking for doesn't exist, so I used that.

It was a bit painful to hunt all the commands but in the end it works
beautifully!  I pushed the result as
3611f99affc4d2edcf4141e3022dd0d2a0b04068.

Closing, thanks!

Maxim
Raghav Gururajan June 24, 2022, 8:31 a.m. UTC | #10
Maxim,

> Yes, and I agree that's a problem.
> 
> Fortunately, the recently added search-input-file more usefully raises
> an error when the file it is looking for doesn't exist, so I used that.
> 
> It was a bit painful to hunt all the commands but in the end it works
> beautifully!  I pushed the result as
> 3611f99affc4d2edcf4141e3022dd0d2a0b04068.
> 
> Closing, thanks!

Thank a lot.

Regards,
RG.
diff mbox series

Patch

diff --git a/gnu/packages/hardware.scm b/gnu/packages/hardware.scm
index 707a47fb4b..93be54cb18 100644
--- a/gnu/packages/hardware.scm
+++ b/gnu/packages/hardware.scm
@@ -4,6 +4,7 @@ 
 ;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
 ;;; Copyright © 2021 Evgeny Pisemsky <evgeny@pisemsky.com>
 ;;; Copyright © 2021 Léo Le Bouter <lle-bout@zaclys.net>
+;;; Copyright © 2021 Petr Hodina <phodina@protonmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -22,6 +23,7 @@ 

 (define-module (gnu packages hardware)
   #:use-module (gnu packages admin)
+  #:use-module (gnu packages assembly)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages bash)
   #:use-module (gnu packages compression)
@@ -45,6 +47,7 @@ 
   #:use-module (gnu packages python)
   #:use-module (gnu packages qt)
   #:use-module (gnu packages tls)
+  #:use-module (gnu packages version-control)
   #:use-module (gnu packages web)
   #:use-module (gnu packages xdisorg)
   #:use-module (gnu packages xml)
@@ -256,6 +259,54 @@  specific SMBIOS tables.")
     (license
      (list license:osl2.1 license:gpl2+ license:bsd-3 license:boost1.0))))

+(define-public libx86emu
+(package
+  (name "libx86emu")
+  (version "3.1")
+  (source (origin
+            (method git-fetch)
+            (uri (git-reference
+             (url "https://github.com/wfeldt/libx86emu")
+             (commit version)))
+            (file-name (git-file-name name version))
+            (sha256
+             (base32
+              "104xqc6nj9rpi7knl3dfqvasf087hlz2n5yndb1iycw35a6j509b"))))
+  (build-system gnu-build-system)
+  (arguments
+    `(#:make-flags (list
+                    (string-append "CC=" ,(cc-for-target))
+                    (string-append "DESTDIR=" %output)
+                    (string-append "LIBDIR=/lib"))
+      #:phases (modify-phases %standard-phases
+                (delete 'configure)
+                (add-after 'unpack 'fix-version-and-usr
+                 (lambda* (#:key inputs #:allow-other-keys)
+                  (delete-file "git2log")
+                  (let* ((file (open-file "VERSION" "a")))
+                   (display ,version file)
+                   (close-port file))
+                  (substitute* "Makefile"
+                           (("/usr") "/"))))
+                (replace 'check
+                 (lambda* _
+                  (invoke "make" "test"))))))
+  (native-inputs `(("git" ,git) ("perl" ,perl) ("nasm" ,nasm)))
+  (synopsis "Library for x86 emulation")
+  (description "Small library to emulate x86 instructions.  The focus here
+is not a complete emulation (go for qemu for this) but to cover enough for
+typical firmware blobs.
+@enumerate
+@item intercept any memory access or directly map real memory ranges
+@item intercept any i/o access, map real i/o ports, or block any real i/o
+@item intercept any interrupt
+@item provides hook to run after each instruction
+@item recognizes a special x86 instruction that can trigger logging
+@item has integrated logging
+@end enumerate")
+  (home-page "https://github.com/wfeldt/libx86emu")
+  (license license:bsd-1)))
+
 ;; Distinct from memtest86, which is obsolete.
 (define-public memtest86+
   (package