From ff13bbf50629eb3ccfc91f85c21edc1bcfab8e9e Mon Sep 17 00:00:00 2001 From: Douglas Katzman Date: Mon, 5 Feb 2024 03:51:28 -0500 Subject: [PATCH] Accept -jN arg to build-all-cores and don't redirect *stdout* and *stderr* if -j1. You can specify more than one target, and they will follow one another with no chance of overlap since it's sequential. This should give more-or-less the same behavior as the deleted crossbuild-runner/build-all.sh script. We can add a few more indicators of where each build starts, but this is probably adequate for now. --- build-all-cores.sh | 19 +++++++++++++++++-- crossbuild-runner/pass-1.lisp | 10 ++++++---- crossbuild-runner/pass-2.lisp | 12 +++++++----- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/build-all-cores.sh b/build-all-cores.sh index c87206d8d..6260024ad 100755 --- a/build-all-cores.sh +++ b/build-all-cores.sh @@ -2,7 +2,6 @@ ./run-sbcl.sh --noprint --disable-debugger $* <<\EOF (defvar *configs-to-build* (cdr *posix-argv*)) -;;; TODO: allow this to be specified on the command line (defparameter *jobs* (max 1 #+unix @@ -11,7 +10,22 @@ (function sb-alien:long sb-alien:int)) sb-unix::sc-nprocessors-onln) 2))) -(format t "~&Using up to ~D job~:P~%" *jobs*) + +(let ((first (car *configs-to-build*))) + (if (and (stringp first) + (>= (length first) 2) + (string= first "-j" :end1 2)) + ;; allow "-jN" as two args + (cond ((= (length first) 2) + (pop *configs-to-build*) + (setq *jobs* (parse-integer (pop *configs-to-build*)))) + ((digit-char-p (char first 2)) ; or "-jN" as one arg + (setq *jobs* (parse-integer first :start 2)) + (pop *configs-to-build*)) + (t + (error "-j requires a number"))))) + +(when (> *jobs* 1) (format t "~&Using up to ~D job~:P~%" *jobs*)) ;;; I should probably have a way to add a fixed set of features in ;;; for an architecture, such as :LITTLE-ENDIAN for x86{-64}. @@ -102,6 +116,7 @@ obj/xbuild/{cfg}.core: obj/xbuild/{cfg}/xc.core *all-configurations*)))) (ensure-directories-exist "obj/xbuild/") +;; if it's just one target this could exec() instead (defvar *process* (run-program "make" `(,(format nil "-j~D" *jobs*) diff --git a/crossbuild-runner/pass-1.lisp b/crossbuild-runner/pass-1.lisp index df3c2db0e..da5441abc 100644 --- a/crossbuild-runner/pass-1.lisp +++ b/crossbuild-runner/pass-1.lisp @@ -12,10 +12,12 @@ ;; (format t "~&added features: ~S~%" add-features) (ensure-directories-exist objroot) (defvar *sbcl-host-obj-prefix* objroot) - (setq sb-sys:*stdout* (open (format nil "~A/stdout" objroot) :direction :output - :if-does-not-exist :create :if-exists :supersede) - sb-sys:*stderr* (open (format nil "~A/stderr" objroot) :direction :output - :if-does-not-exist :create :if-exists :supersede)) + (let ((makeflags (sb-ext:posix-getenv "MAKEFLAGS"))) + (when (search "--jobserver-fds" makeflags) + (setq sb-sys:*stdout* (open (format nil "~A/stdout" objroot) :direction :output + :if-does-not-exist :create :if-exists :supersede) + sb-sys:*stderr* (open (format nil "~A/stderr" objroot) :direction :output + :if-does-not-exist :create :if-exists :supersede)))) (defvar *sbcl-local-target-features-file* ltf) (with-open-file (*standard-output* ltf :direction :output :if-does-not-exist :create diff --git a/crossbuild-runner/pass-2.lisp b/crossbuild-runner/pass-2.lisp index b934e365c..e814f246e 100644 --- a/crossbuild-runner/pass-2.lisp +++ b/crossbuild-runner/pass-2.lisp @@ -9,11 +9,13 @@ (defparameter *host-obj-prefix* (format nil "~A/from-host/" build-dir)) (defparameter *target-obj-prefix* objroot) (defparameter *build-dependent-generated-sources-root* objroot) - (setq sb-sys:*stdout* (open (format nil "~A/stdout" objroot) :direction :output - :if-does-not-exist :create :if-exists :supersede) - sb-sys:*stderr* (open (format nil "~A/stderr" objroot) :direction :output - :if-does-not-exist :create :if-exists :supersede))) -(setf (sb-impl::fd-stream-buffering sb-sys:*stdout*) :line) + (let ((makeflags (sb-ext:posix-getenv "MAKEFLAGS"))) + (when (search "--jobserver-fds" makeflags) + (setq sb-sys:*stdout* (open (format nil "~A/stdout" objroot) :direction :output + :if-does-not-exist :create :if-exists :supersede) + sb-sys:*stderr* (open (format nil "~A/stderr" objroot) :direction :output + :if-does-not-exist :create :if-exists :supersede)) + (setf (sb-impl::fd-stream-buffering sb-sys:*stdout*) :line)))) (load "src/cold/set-up-cold-packages.lisp") (load "src/cold/defun-load-or-cload-xcompiler.lisp") (load-or-cload-xcompiler #'host-load-stem)