Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCL:*UNPROCESSED-COMMAND-LINE-ARGUMENTS* is NIL when running an image #177

Open
sjl opened this issue Dec 22, 2018 · 6 comments
Open

CCL:*UNPROCESSED-COMMAND-LINE-ARGUMENTS* is NIL when running an image #177

sjl opened this issue Dec 22, 2018 · 6 comments

Comments

@sjl
Copy link
Contributor

sjl commented Dec 22, 2018

I'm trying to produce a stand-alone application with CCL that takes command line arguments. I know CCL doesn't have anything like SBCL's :save-runtime-options feature so I won't be able to make this work perfectly, but I can't even seem to get the workaround mentioned in that ticket working.

When I run CCL normally, ccl:*command-line-argument-list* and ccl:*unprocessed-command-line-arguments* appear to work like so:

echo '(progn (print ccl:*command-line-argument-list*)
             (print ccl:*unprocessed-command-line-arguments*)
             (values))' \
    | ./lx86cl64 -R 1000000 --quiet --batch -- foo

("./lx86cl64" "--quiet" "--" "foo")
("foo")

I'm a little confused about how ccl:*command-line-argument-list* works. At first I thought it was removing arguments that were used by CCL itself (like --batch) but that can't be it, because it passes through other things like --quiet. So I don't know exactly what this variable is supposed to contain.

But that's okay, because ccl:*unprocessed-command-line-arguments* is what the workaround says to use, and that does appear to work as described (containing all arguments after the -- terminator). Great.

Now I dump an image:

echo '(ccl:save-application "foo"
        :prepend-kernel t
        :toplevel-function (lambda ()
                             (progn (print ccl:*command-line-argument-list*)
                                    (print ccl:*unprocessed-command-line-arguments*)
                                    (values))))' \
    | ./lx86cl64 --quiet --batch

And run it with some arguments:

./foo -V --batch --quiet -- what

("./foo" "-V" "--quiet" "--" "what")
NIL

Now ccl:*unprocessed-command-line-arguments* is just completely empty, even with -- in the argument list. The same thing happens even if I create an image (without :prepend-kernel) and run CCL itself:

echo '(ccl:save-application "foo.image"
        :toplevel-function (lambda ()
                             (progn (print ccl:*command-line-argument-list*)
                                    (print ccl:*unprocessed-command-line-arguments*)
                                    (values))))' \
    | ./lx86cl64 --quiet --batch

./lx86cl64 -I foo.image -V --batch --quiet -- what

("./lx86cl64" "-V" "--quiet" "--" "what")
NIL

So now I'm just totally confused. Is this a bug in CCL, or am I not understanding what ccl:*unprocessed-command-line-arguments* is supposed to do?

I'm running CCL Version 1.11.5/v1.11.5 (LinuxX8664) on Ubuntu 18.04.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@sjl
Copy link
Contributor Author

sjl commented Dec 22, 2018

Okay, I took a swim in the source and at least I see why this is happening.

The weirdness with some CCL options being missing from ccl:*command-line-argument-list* is because some options are handled by the C kernel and removed before Lisp ever has a chance to see them:

ccl/lisp-kernel/pmcl-kernel.c

Lines 1250 to 1253 in 316ff87

The set of arguments recognized by the kernel is
likely to remain pretty small and pretty simple.
This removes everything it recognizes from argv;
remaining args will be processed by lisp code.

The code that handles processing the rest of the command line arguments is called from a :before method on toplevel-function. This method is only called when you don't specify a :toplevel-function argument to save-image. So that explains why ccl:*unprocessed-command-line-arguments* is empty when I dump an image.

I don't have enough knowledge/context to know if this is all intentional, or if it's a bug that should be fixed.

@svetlyak40wt
Copy link

svetlyak40wt commented Dec 22, 2018 via email

@eugeneia
Copy link
Contributor

eugeneia commented Dec 23, 2018

@sjl something you might also be interested in is that save-application accepts an :application-class argument that affects which command line arguments are parsed as well. Here is an example how to disable the default handling: https://github.com/eugeneia/athens/blob/master/build/athens.lisp

I don’t think there is a way to disable the hidden kernel options, I think of it as a feature. :-)

@sjl
Copy link
Contributor Author

sjl commented Dec 24, 2018

@svetlyak40wt I don't want to get into a discussion about whether ASDF/UIOP are good or not here. This ticket is about a variable that CCL exports having a seemingly-buggy value is some situations. Whether UIOP works around that or not is orthogonal to CCL having/not having a bug.

@eugeneia Yeah, I see that application class is doing the same workaround as UIOP (just parsing *command-line-argument-list* instead of *unprocessed-command-line-options*). Unfortunately in my case the option I want to add to my program just happens to be named the same thing as one of the kernel options (--batch) so the "feature" isn't doing me any favors, hah.

@eugeneia
Copy link
Contributor

eugeneia commented Dec 25, 2018

@sjl One possible workaround might be an indirection between your app executable and the ccl binary. From ccl --help:

Any arguments following the pseudoargument "--" are
not processed and are available to the application as
the value of CCL:*UNPROCESSED-COMMAND-LINE-ARGUMENTS*.

I.e., you could have a shell script that passes its arguments to exec ccl -n -I myapp.image -- ....

@sjl
Copy link
Contributor Author

sjl commented Dec 25, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants