From 9441f7075f79d1e4d6b7d4383b231d3209c331aa Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sat, 24 Nov 2018 10:21:23 -0700 Subject: [PATCH] raco setup: add `-M`/`--compile-any` Add `-M`/`--compile-any` to `raco setup`, `raco pkg install`, etc., to build machine-independent bytecode, which is useful in the process of building distributions. --- INSTALL.txt | 6 ++++++ Makefile | 17 ++++++++++------- pkgs/racket-doc/pkg/scribblings/pkg.scrbl | 5 +++++ pkgs/racket-doc/scribblings/raco/setup.scrbl | 5 +++++ racket/collects/pkg/main.rkt | 14 ++++++++------ racket/collects/setup/main.rkt | 4 ++++ racket/collects/setup/option.rkt | 4 ++++ racket/collects/setup/parallel-build.rkt | 7 ++++++- racket/collects/setup/setup-cmdline.rkt | 5 +++++ racket/collects/setup/setup-core.rkt | 5 ++++- racket/collects/setup/setup-go.rkt | 13 ++++++++++--- racket/collects/setup/setup.rkt | 5 +++++ racket/src/Makefile.in | 2 +- racket/src/cs/main.sps | 2 +- racket/src/racket/cmdline.inc | 4 ++-- 15 files changed, 76 insertions(+), 22 deletions(-) diff --git a/INSTALL.txt b/INSTALL.txt index 0f6ec43a66..d2e34491e6 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -243,6 +243,12 @@ cross-compilation mode is used and that any foreign libraries needed for build time can be found, but many cross-compilation scenarios work without `-C`. +Specify `SETUP_MACHINE_FLAGS=...` to set flags for `raco setup` and +`raco pkg install` that control the target machine of compiled +bytecode. For example `SETUP_MACHINE_FLAGS=-M` causes the generated +bytecode to be machine-independent, which is mainly useful when the +generated installation will be used as a template for other platforms. + Installing Packages ------------------- diff --git a/Makefile b/Makefile index fd3f068cc7..d825fd20ad 100644 --- a/Makefile +++ b/Makefile @@ -52,16 +52,19 @@ in-place: cpus-in-place: $(MAKE) -j $(CPUS) plain-in-place JOB_OPTIONS="-j $(CPUS)" PKGS="$(PKGS)" +# For -M, etc., to pick the target machine for compilation: +SETUP_MACHINE_FLAGS = + # Explicitly propagate variables for non-GNU `make's: LIBSETUP = -N raco -l- raco setup # Update before install to avoid needless work on the initial build, # and use `--no-setup` plus an explicit `raco setup` for the same reason. -UPDATE_PKGS_ARGS = --all --auto --no-setup --scope installation -INSTALL_PKGS_ARGS = $(JOB_OPTIONS) --no-setup --pkgs \ +UPDATE_PKGS_ARGS = --all --auto --no-setup --scope installation $(SETUP_MACHINE_FLAGS) +INSTALL_PKGS_ARGS = $(JOB_OPTIONS) $(SETUP_MACHINE_FLAGS) --no-setup --pkgs \ --skip-installed --scope installation --deps search-auto \ $(REQUIRED_PKGS) $(PKGS) -ALL_PLT_SETUP_OPTIONS = $(JOB_OPTIONS) $(PLT_SETUP_OPTIONS) +ALL_PLT_SETUP_OPTIONS = $(JOB_OPTIONS) $(PLT_SETUP_OPTIONS) $(SETUP_MACHINE_FLAGS) plain-in-place: $(MAKE) plain-minimal-in-place @@ -174,7 +177,8 @@ MORE_CONFIGURE_ARGS = SELF_UP = SELF_FLAGS_qq = SELF_RACKET_FLAGS="-G `cd $(SELF_UP)../../../build/config; pwd`" -INSTALL_SETUP_ARGS = $(SELF_FLAGS_qq) PLT_SETUP_OPTIONS="$(JOB_OPTIONS) $(PLT_SETUP_OPTIONS)" +PLT_SETUP_OPTIONS_qq = PLT_SETUP_OPTIONS="$(JOB_OPTIONS) $(PLT_SETUP_OPTIONS) $(SETUP_MACHINE_FLAGS)" +INSTALL_SETUP_ARGS = $(SELF_FLAGS_qq) $(PLT_SETUP_OPTIONS_qq) BASE_INSTALL_TARGET = plain-base-install @@ -545,8 +549,7 @@ WIN32_RACKET = $(WIN32_PLAIN_RACKET) $(USER_CONFIG) WIN32_RACO = $(WIN32_PLAIN_RACKET) $(USER_CONFIG) -N raco -l- raco X_AUTO_OPTIONS = --skip-installed --deps search-auto --pkgs $(JOB_OPTIONS) USER_AUTO_OPTIONS = --scope user $(X_AUTO_OPTIONS) -LOCAL_USER_AUTO = --catalog build/local/catalog $(USER_AUTO_OPTIONS) -SOURCE_USER_AUTO_q = --catalog build/catalog-copy $(USER_AUTO_OPTIONS) +SOURCE_USER_AUTO_q = --catalog build/catalog-copy $(USER_AUTO_OPTIONS) $(SETUP_MACHINE_FLAGS) REMOTE_USER_AUTO = --catalog $(SVR_CAT) $(USER_AUTO_OPTIONS) REMOTE_INST_AUTO = --catalog $(SVR_CAT) --scope installation $(X_AUTO_OPTIONS) CONFIG_MODE_q = "$(CONFIG)" "$(CONFIG_MODE)" @@ -623,7 +626,7 @@ build-from-catalog: $(MAKE) set-server-config $(USER_RACKET) -l- distro-build/pkg-info -o build/pkgs.rktd build/catalog-copy $(USER_RACKET) -l distro-build/install-pkgs $(CONFIG_MODE_q) "$(PKGS) $(TEST_PKGS)" $(SOURCE_USER_AUTO_q) --all-platforms - $(USER_RACO) setup --avoid-main $(JOB_OPTIONS) + $(USER_RACO) setup $(SETUP_MACHINE_FLAGS) --avoid-main $(JOB_OPTIONS) server-cache-config: $(USER_RACO) pkg config -i --set download-cache-dir build/cache diff --git a/pkgs/racket-doc/pkg/scribblings/pkg.scrbl b/pkgs/racket-doc/pkg/scribblings/pkg.scrbl index 01b85affd7..c597cb7189 100644 --- a/pkgs/racket-doc/pkg/scribblings/pkg.scrbl +++ b/pkgs/racket-doc/pkg/scribblings/pkg.scrbl @@ -613,6 +613,8 @@ sub-commands. @item{@DFlag{dry-run} --- Prevents changes to the current installation. All installation and update work is staged and checked, but the final installation step is skipped.} + @item{@DFlag{compile-any} or @Flag{M} --- Compiles bytecode to a machine-independent form.} + @item{@DFlag{no-setup} --- Does not run @exec{raco setup} after installation. This behavior is also the case if the environment variable @envvar{PLT_PKG_NOSETUP} is set to any non-empty value.} @@ -745,6 +747,7 @@ the given @nonterm{pkg-source}s. @item{@DFlag{pull} @nonterm{mode} --- Same as for @command-ref{install}} @item{@DFlag{dry-run} --- Same as for @command-ref{install}.} + @item{@DFlag{compile-any} or @Flag{M} --- Same as for @command-ref{install}.} @item{@DFlag{no-setup} --- Same as for @command-ref{install}.} @item{@DFlag{jobs} @nonterm{n} or @Flag{j} @nonterm{n} --- Same as for @command-ref{install}.} @item{@DFlag{batch} --- Same as for @command-ref{install}.} @@ -786,6 +789,7 @@ the given @nonterm{pkg}s. @item{@Flag{u} or @DFlag{user} --- Shorthand for @exec{--scope user}.} @item{@DFlag{scope-dir} @nonterm{dir} --- Selects @nonterm{dir} as the @tech{package scope}, the same as for @command-ref{install}.} @item{@DFlag{dry-run} --- Same as for @command-ref{install}.} + @item{@DFlag{compile-any} or @Flag{M} --- Same as for @command-ref{install}.} @item{@DFlag{no-setup} --- Same as for @command-ref{install}.} @item{@DFlag{jobs} @nonterm{n} or @Flag{j} @nonterm{n} --- Same as for @command-ref{install}.} @item{@DFlag{batch} --- Same as for @command-ref{install}.} @@ -877,6 +881,7 @@ package is created. @item{@DFlag{strict-doc-conflicts} --- Same as for @command-ref{install}.} @item{@DFlag{no-cache} --- Same as for @command-ref{install}.} @item{@DFlag{dry-run} --- Same as for @command-ref{install}.} + @item{@DFlag{compile-any} or @Flag{M} --- Same as for @command-ref{install}.} @item{@DFlag{no-setup} --- Same as for @command-ref{install}.} @item{@DFlag{jobs} @nonterm{n} or @Flag{j} @nonterm{n} --- Same as for @command-ref{install}.} ] diff --git a/pkgs/racket-doc/scribblings/raco/setup.scrbl b/pkgs/racket-doc/scribblings/raco/setup.scrbl index 6380d2e242..1fa47df6d5 100644 --- a/pkgs/racket-doc/scribblings/raco/setup.scrbl +++ b/pkgs/racket-doc/scribblings/raco/setup.scrbl @@ -236,6 +236,11 @@ flags: content as the main installation.} ]} +@item{Selecting the target machine: +@itemize[ + @item{@DFlag{compile-any} or @Flag{M} --- compile bytecode to a + machine-independent form.} +]} @item{Selecting parallelism and other build modes: @itemize[ diff --git a/racket/collects/pkg/main.rkt b/racket/collects/pkg/main.rkt index 965f9a46d8..a31e9eb045 100644 --- a/racket/collects/pkg/main.rkt +++ b/racket/collects/pkg/main.rkt @@ -14,7 +14,7 @@ (for-syntax racket/base syntax/strip-context)) -(define (setup what no-setup? fail-fast? setup-collects jobs) +(define (setup what no-setup? compile-any? fail-fast? setup-collects jobs) (unless (or (eq? setup-collects 'skip) no-setup? (not (member (getenv "PLT_PKG_NOSETUP") '(#f "")))) @@ -28,6 +28,7 @@ setup-collects)) #:tidy? #t #:make-doc-index? #t + #:compile-any? compile-any? #:jobs jobs #:fail-fast? fail-fast?) ((current-pkg-error) @@ -253,7 +254,7 @@ (pkg-desc p a-type* name checksum #f #:path (and (eq? a-type* 'clone) (path->complete-path clone)))))))) - (setup "installed" no-setup fail-fast setup-collects jobs))))] + (setup "installed" no-setup compile-any fail-fast setup-collects jobs))))] ;; ---------------------------------------- [update "Update packages" @@ -357,7 +358,7 @@ #:infer-clone-from-dir? (not (or link static-link copy)) #:dry-run? dry-run #:use-trash? (not no-trash))))) - (setup "updated" no-setup #f setup-collects jobs))))] + (setup "updated" no-setup compile-any #f setup-collects jobs))))] ;; ---------------------------------------- [remove "Remove packages" @@ -385,7 +386,7 @@ #:force? force #:dry-run? dry-run #:use-trash? (not no-trash)))) - (setup "removed" no-setup #f setup-collects jobs)))] + (setup "removed" no-setup compile-any #f setup-collects jobs)))] ;; ---------------------------------------- [new "Populate a new directory with the stubs of a package" @@ -484,7 +485,7 @@ (and binary-lib 'binary-lib)) #:force-strip? force #:dry-run? dry-run)))) - (setup "migrated" no-setup #f setup-collects jobs)))] + (setup "migrated" no-setup compile-any #f setup-collects jobs)))] ;; ---------------------------------------- [create "Bundle package from a directory or installed package" @@ -674,7 +675,8 @@ #:dry-run-flags ([#:bool dry-run () ("Don't actually change package installation")]) #:job-flags - ([#:bool no-setup () ("Don't `raco setup' after changing packages (usually a bad idea)")] + ([#:bool compile-any ("-M") ("Compile to machine-independent form")] + [#:bool no-setup () ("Don't `raco setup' after changing packages (usually a bad idea)")] [(#:num n #f) jobs ("-j") "Setup with parallel jobs"] [#:bool batch () ("Disable interactive mode and all prompts")]) #:trash-flags diff --git a/racket/collects/setup/main.rkt b/racket/collects/setup/main.rkt index 45bd98e031..7bf9543f7a 100644 --- a/racket/collects/setup/main.rkt +++ b/racket/collects/setup/main.rkt @@ -310,6 +310,10 @@ (if (on? "--trust-zos") (trust-zos #t) (void)) + (if (or (on? "-M") + (on? "--compile-any")) + (current-compile-target-machine #f) + (void)) (current-load/use-compiled (mk)))) ;; This has to be dynamic, so we get a chance to turn off diff --git a/racket/collects/setup/option.rkt b/racket/collects/setup/option.rkt index 0d93dba90a..32a3150389 100644 --- a/racket/collects/setup/option.rkt +++ b/racket/collects/setup/option.rkt @@ -89,6 +89,10 @@ (define-flag-param doc-pdf-dest #f) (define-flag-param fail-fast #f) +(defined-flag-params (cons (cons 'current-compile-target-machine + current-compile-target-machine) + (defined-flag-params))) + (define specific-collections (make-parameter null)) (define specific-packages (make-parameter null)) (define specific-planet-dirs (make-parameter null)) diff --git a/racket/collects/setup/parallel-build.rkt b/racket/collects/setup/parallel-build.rkt index 82de732351..89d60ed4ee 100644 --- a/racket/collects/setup/parallel-build.rkt +++ b/racket/collects/setup/parallel-build.rkt @@ -327,6 +327,9 @@ [current-directory (if (memq 'set-directory options) dir (current-directory))] + [current-compile-target-machine (if (memq 'compile-any options) + #f + (current-compile-target-machine))] [current-load-relative-directory dir] [current-input-port (open-input-string "")] [current-output-port out-str-port] @@ -365,9 +368,11 @@ #:use-places? use-places?)) (define (parallel-compile worker-count setup-fprintf append-error collects-tree + #:options [options '()] #:use-places? [use-places? #t]) (setup-fprintf (current-output-port) #f "--- parallel build using ~a jobs ---" worker-count) - (define collects-queue (make-object collects-queue% collects-tree setup-fprintf append-error '(set-directory))) + (define collects-queue (make-object collects-queue% collects-tree setup-fprintf append-error + (append options '(set-directory)))) (parallel-build collects-queue worker-count #:use-places? use-places?)) diff --git a/racket/collects/setup/setup-cmdline.rkt b/racket/collects/setup/setup-cmdline.rkt index f66ad6b559..20bce15955 100644 --- a/racket/collects/setup/setup-cmdline.rkt +++ b/racket/collects/setup/setup-cmdline.rkt @@ -126,6 +126,11 @@ [("--force-user-docs") "User-specific documentation even if matching installation" (add-flags '((force-user-docs #t)))] #:help-labels + " -------------------------- target machine ------------------------- " + #:once-each + [("-M" "--compile-any") "Compile to machine-independent form" + (add-flags `((current-compile-target-machine #f)))] + #:help-labels " ------------------------------ modes ------------------------------ " #:once-each [("-j" "--jobs" "--workers") n "Use parallel jobs" diff --git a/racket/collects/setup/setup-core.rkt b/racket/collects/setup/setup-core.rkt index 8d576cde1f..614038a2d0 100644 --- a/racket/collects/setup/setup-core.rkt +++ b/racket/collects/setup/setup-core.rkt @@ -1114,7 +1114,10 @@ has-module-suffix?))))) (iterate-cct clean-cc cct) (parallel-compile (parallel-workers) setup-fprintf handle-error cct - #:use-places? (parallel-use-places)) + #:use-places? (parallel-use-places) + #:options (if (not (current-compile-target-machine)) + '(compile-any) + '())) (for/fold ([gcs 0]) ([cc planet-dirs-to-compile]) (compile-cc cc gcs has-module-suffix?))))) (with-specified-mode diff --git a/racket/collects/setup/setup-go.rkt b/racket/collects/setup/setup-go.rkt index 12574bc38f..b690e219fa 100644 --- a/racket/collects/setup/setup-go.rkt +++ b/racket/collects/setup/setup-go.rkt @@ -13,12 +13,17 @@ x-archives) (parse-cmdline (current-command-line-arguments))) -(define (has-x-flag? s) +(define (get-x-flag s default) (define a (assq s x-flags)) - (and a (cadr a))) + (if a + (cadr a) + default)) + +(define (has-x-flag? s) + (get-x-flag s #f)) (define (go orig-compile-file-paths) - ;; Conver parse-cmdline results into parameter settings: + ;; Convert parse-cmdline results into parameter settings: (parameterize ([current-target-plt-directory-getter (if (has-x-flag? 'all-users) (lambda (preferred main-collects-parent-dir choices) @@ -26,6 +31,8 @@ (current-target-plt-directory-getter))] [trust-existing-zos (or (has-x-flag? 'trust-existing-zos) (trust-existing-zos))] + [current-compile-target-machine (get-x-flag 'current-compile-target-machine + (current-compile-target-machine))] [specific-collections x-specific-collections] [specific-packages x-specific-packages] [archives x-archives] diff --git a/racket/collects/setup/setup.rkt b/racket/collects/setup/setup.rkt index 3aa4df8aa3..84d3f6ab7c 100644 --- a/racket/collects/setup/setup.rkt +++ b/racket/collects/setup/setup.rkt @@ -18,6 +18,7 @@ #:tidy? [tidy? #f] #:avoid-main? [avoid-main? #f] #:force-user-docs? [force-user-docs? #f] + #:compile-any? [compile-any? #f] #:jobs [parallel #f] #:fail-fast? [fail-fast? #f]) (parameterize @@ -50,6 +51,10 @@ [force-user-docs (if force-user-docs? #t (force-user-docs))] + [current-compile-target-machine (if compile-any? + #f + (current-compile-target-machine))] + [fail-fast fail-fast?] [clean (if clean? #t (clean))] diff --git a/racket/src/Makefile.in b/racket/src/Makefile.in index e3eec278b4..d3f63e8f9e 100644 --- a/racket/src/Makefile.in +++ b/racket/src/Makefile.in @@ -106,7 +106,7 @@ local/Makefile: # Install (common) ---------------------------------------- INST_CONFIG = -X @DIRCVTPRE@"$(DESTDIR)$(collectsdir)"@DIRCVTPOST@ -G @DIRCVTPRE@"$(DESTDIR)$(configdir)"@DIRCVTPOST@ -SETUP_RACKET_FLAGS = $(INST_CONFIG) $(SELF_RACKET_FLAGS) @INSTALL_SETUP_RACKET_FLAGS@ +SETUP_RACKET_FLAGS = $(INST_CONFIG) $(COMPILE_MACHINE_FLAGS) $(SELF_RACKET_FLAGS) @INSTALL_SETUP_RACKET_FLAGS@ SETUP_SETUP_FLAGS = @INSTALL_SETUP_FLAGS@ $(PLT_SETUP_OPTIONS) $(PLT_ISO) SETUP_ARGS = $(SETUP_RACKET_FLAGS) -N "raco" -l- setup $(SETUP_SETUP_FLAGS) diff --git a/racket/src/cs/main.sps b/racket/src/cs/main.sps index 7de8bc6e96..d932a39893 100644 --- a/racket/src/cs/main.sps +++ b/racket/src/cs/main.sps @@ -426,7 +426,7 @@ (loop (cdr args))] [else (raise-bad-switch arg within-arg)])] - [("-M") + [("-M" "--compile-any") (set! compile-machine-independent? #t) (loop (cdr args))] [("--") diff --git a/racket/src/racket/cmdline.inc b/racket/src/racket/cmdline.inc index ceed3a6e73..c7a61cd1fb 100644 --- a/racket/src/racket/cmdline.inc +++ b/racket/src/racket/cmdline.inc @@ -784,7 +784,7 @@ static int run_from_cmd_line(int argc, char *_argv[], argv[0] = "-q"; else if (!strcmp("--no-jit", argv[0])) argv[0] = "-j"; - else if (!strcmp("--compile-mi", argv[0])) + else if (!strcmp("--compile-any", argv[0])) argv[0] = "-M"; else if (!strcmp("--no-delay", argv[0])) argv[0] = "-d"; @@ -1424,7 +1424,7 @@ static int run_from_cmd_line(int argc, char *_argv[], # else " -j, --no-jit : No effect, since the just-in-time compiler is unavailable\n" # endif - " -M, --compile-mi : Compile to machine-independent form\n" + " -M, --compile-any : Compile to machine-independent form\n" " -d, --no-delay: Disable on-demand loading of syntax and code\n" " -b, --binary : Read stdin and write stdout/stderr in binary mode\n" " -W , --warn : Set stderr logging to \n"