scripts: Add --list-systems and --list-targets options.

Also factorize the --system and --target build options. Check that the passed
system and target arguments are known platforms.

* doc/guix.texi (Additional Build Options): Document the new --list-systems
and --list-targets options.
* guix/scripts/build.scm (show-cross-build-options-help,
show-emulated-build-options-help, list-systems, list-targets): New procedures.
(%standard-cross-build-options, %standard-emulated-build-options): New
variables.
(show-help): Remove --system and --target entries and use
show-cross-build-options-help and show-emulated-build-options-help procedures instead.
(%options): Remove --system and --target entries and use
%standard-cross-build-options and %standard-emulated-build-options variables instead.
* guix/scripts/archive.scm (show-help, %options): Adapt them.
* guix/scripts/environment.scm: Ditto.
* guix/scripts/graph.scm: Ditto.
* guix/scripts/pack.scm: Ditto.
* guix/scripts/pull.scm: Ditto.
* guix/scripts/size.scm: Ditto.
* guix/scripts/weather.scm: Ditto.

Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
This commit is contained in:
Mathieu Othacehe 2022-05-02 12:59:14 +02:00
parent dd970122dd
commit ec42d287b4
No known key found for this signature in database
GPG key ID: 8354763531769CA6
9 changed files with 120 additions and 74 deletions

View file

@ -47,6 +47,7 @@
#:use-module (srfi srfi-35)
#:use-module (srfi srfi-37)
#:use-module (gnu packages)
#:use-module (gnu platform)
#:use-module ((guix status) #:select (with-status-verbosity))
#:use-module ((guix progress) #:select (current-terminal-columns))
#:use-module ((guix build syscalls) #:select (terminal-columns))
@ -54,9 +55,15 @@
#:export (log-url
%standard-build-options
%standard-cross-build-options
%standard-native-build-options
set-build-options-from-command-line
set-build-options-from-command-line*
show-build-options-help
show-cross-build-options-help
show-native-build-options-help
guix-build
register-root
@ -184,6 +191,18 @@ options handled by 'set-build-options-from-command-line', and listed in
(display (G_ "
--debug=LEVEL produce debugging output at LEVEL")))
(define (show-cross-build-options-help)
(display (G_ "
--list-targets list available targets"))
(display (G_ "
--target=TRIPLET cross-build for TRIPLET--e.g., \"aarch64-linux-gnu\"")))
(define (show-native-build-options-help)
(display (G_ "
--list-systems list available systems"))
(display (G_ "
-s, --system=SYSTEM attempt to build for SYSTEM--e.g., \"i686-linux\"")))
(define (set-build-options-from-command-line store opts)
"Given OPTS, an alist as returned by 'args-fold' given
'%standard-build-options', set the corresponding build options on STORE."
@ -319,6 +338,52 @@ use '--no-offload' instead~%")))
(leave (G_ "not a number: '~a' option argument: ~a~%")
name arg)))))))
(define (list-systems)
"Print the available systems."
(display (G_ "The available systems are:\n"))
(newline)
(format #t "~{ - ~a ~%~}"
(sort (systems) string<?)))
(define (list-targets)
"Print the available targets."
(display (G_ "The available targets are:\n"))
(newline)
(format #t "~{ - ~a ~%~}"
(sort (targets) string<?)))
(define %standard-cross-build-options
;; Build options related to cross builds.
(list
(option '("list-targets") #f #f
(lambda (opt name arg result)
(list-targets)
(exit 0)))
(option '("target") #t #f
(lambda (opt name arg result . rest)
(let ((t (false-if-exception
(first (member arg (targets))))))
(if t
(apply values (alist-cons 'target t result) rest)
(leave (G_ "'~a' is not a supported target~%")
arg)))))))
(define %standard-native-build-options
;; Build options related to native builds.
(list
(option '("list-systems") #f #f
(lambda (opt name arg result)
(list-systems)
(exit 0)))
(option '(#\s "system") #t #f
(lambda (opt name arg result . rest)
(let ((s (false-if-exception
(first (member arg (systems))))))
(if s
(apply values (alist-cons 'system s result) rest)
(leave (G_ "'~a' is not a supported system~%")
arg)))))))
;;;
;;; Command-line options.
@ -353,10 +418,6 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
--sources[=TYPE] build source derivations; TYPE may optionally be one
of \"package\", \"all\" (default), or \"transitive\""))
(display (G_ "
-s, --system=SYSTEM attempt to build for SYSTEM--e.g., \"i686-linux\""))
(display (G_ "
--target=TRIPLET cross-build for TRIPLET--e.g., \"armel-linux-gnu\""))
(display (G_ "
-d, --derivations return the derivation paths of the given packages"))
(display (G_ "
--check rebuild items to check for non-determinism issues"))
@ -374,6 +435,10 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
(newline)
(show-build-options-help)
(newline)
(show-cross-build-options-help)
(newline)
(show-native-build-options-help)
(newline)
(show-transformation-options-help)
(newline)
(display (G_ "
@ -420,13 +485,6 @@ must be one of 'package', 'all', or 'transitive'~%")
(alist-cons 'build-mode (build-mode repair)
result)
rest)))
(option '(#\s "system") #t #f
(lambda (opt name arg result)
(alist-cons 'system arg result)))
(option '("target") #t #f
(lambda (opt name arg result)
(alist-cons 'target arg
(alist-delete 'target result eq?))))
(option '(#\d "derivations") #f #f
(lambda (opt name arg result)
(alist-cons 'derivations-only? #t result)))
@ -459,7 +517,9 @@ must be one of 'package', 'all', or 'transitive'~%")
(alist-cons 'log-file? #t result)))
(append %transformation-options
%standard-build-options)))
%standard-build-options
%standard-cross-build-options
%standard-native-build-options)))
(define (options->things-to-build opts)
"Read the arguments from OPTS and return a list of high-level objects to