about summary refs log tree commit diff
path: root/nix/buildLisp
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2022-01-29T12·59+0100
committersterni <sternenseemann@systemli.org>2022-02-02T18·21+0000
commitb57854e24df1f5a72369b44345219f650227ad53 (patch)
tree1c4f9b1fcca36935476b48fa5811d605f23c2d03 /nix/buildLisp
parent49c8d8371ca17207157058b4daecded67ade1e5f (diff)
fix(nix/buildLisp): make uiop:argv0 work also for ccl and sbcl r/3745
Detection is broken there, too, as UIOP relies on setting the variable
before dumping the image in its portability wrapper dump-image which we
don't use at all.

Change-Id: If7bea5a8522a2e64707b1ee88d62d420bd00a952
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5112
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'nix/buildLisp')
-rw-r--r--nix/buildLisp/default.nix11
-rw-r--r--nix/buildLisp/tests/argv0.nix36
2 files changed, 46 insertions, 1 deletions
diff --git a/nix/buildLisp/default.nix b/nix/buildLisp/default.nix
index 30b90d9049..f483e36765 100644
--- a/nix/buildLisp/default.nix
+++ b/nix/buildLisp/default.nix
@@ -319,6 +319,11 @@ let
         (let* ((bindir (concatenate 'string (sb-posix:getenv "out") "/bin"))
                (outpath (make-pathname :name "${name}"
                                        :directory bindir)))
+
+          ;; Tell UIOP that argv[0] will refer to running image, not the lisp impl
+          (when (find-package :uiop)
+            (eval `(setq ,(find-symbol "*IMAGE-DUMPED-P*" :uiop) :executable)))
+
           (save-lisp-and-die outpath
                              :executable t
                              :toplevel
@@ -438,7 +443,7 @@ let
                           ;; to handle argument parsing and such properly. Since
                           ;; this needs to work even when we're not using UIOP,
                           ;; we need to do some compile-time acrobatics.
-                          ,(when (find-package 'uiop)
+                          ,(when (find-package :uiop)
                             `(setf ,(find-symbol "*IMAGE-DUMPED-P*" :uiop) :executable))
                           ;; Run the actual application…
                           (${main})
@@ -561,6 +566,10 @@ let
                (bindir (concatenate 'string out "/bin/"))
                (executable (make-pathname :directory bindir :name "${name}")))
 
+          ;; Tell UIOP that argv[0] will refer to running image, not the lisp impl
+          (when (find-package :uiop)
+            (eval `(setf ,(find-symbol "*IMAGE-DUMPED-P*" :uiop) :executable)))
+
           (save-application executable
                             :purify t
                             :error-handler :quit
diff --git a/nix/buildLisp/tests/argv0.nix b/nix/buildLisp/tests/argv0.nix
new file mode 100644
index 0000000000..bc29337d06
--- /dev/null
+++ b/nix/buildLisp/tests/argv0.nix
@@ -0,0 +1,36 @@
+{ depot, pkgs, ... }:
+
+depot.nix.buildLisp.program {
+  name = "argv0-test";
+
+  srcs = [
+    (pkgs.writeText "argv0-test.lisp" ''
+      (defpackage :argv0-test (:use :common-lisp :uiop) (:export :main))
+      (in-package :argv0-test)
+
+      (defun main ()
+        (format t "~A~%" (uiop:argv0)))
+    '')
+  ];
+
+  deps = [
+    {
+      sbcl = depot.nix.buildLisp.bundled "uiop";
+      default = depot.nix.buildLisp.bundled "asdf";
+    }
+  ];
+
+  passthru.meta.ci = {
+    extraSteps.verify = {
+      label = "verify argv[0] output";
+      needsOutput = true;
+      command = pkgs.writeShellScript "check-argv0" ''
+        set -eux
+
+        for invocation in "$(pwd)/result/bin/argv0-test" "./result/bin/argv0-test"; do
+          test "$invocation" = "$("$invocation")"
+        done
+      '';
+    };
+  };
+}