Skip to content

Standalone executable symlink #1004

@danmasta

Description

@danmasta

When running a standalone executable from a symlink in PATH, qjs seems to only execute the qjs runtime, instead of the packaged bytecode

Example:
First install a package that was compiled with qjs

brew install danmasta/tap/envstr
which envstr
/home/linuxbrew/.linuxbrew/bin/envstr

Then if we try and execute the package, we get the qjs help menu:

envstr -v

qjs: unknown option '-v'
QuickJS-ng version 0.9.0
usage: qjs [options] [file [args]]
-h  --help         list options
-e  --eval EXPR    evaluate EXPR
-i  --interactive  go to interactive mode
-m  --module       load as ES6 module (default=autodetect)
    --script       load as ES6 script (default=autodetect)
-I  --include file include an additional file
    --std          make 'std', 'os' and 'bjson' available to script
-T  --trace        trace memory allocation
-d  --dump         dump the memory usage stats
-D  --dump-flags   flags for dumping debug data (see DUMP_* defines)
-c  --compile FILE compile the given JS file as a standalone executable
-o  --out FILE     output file for standalone executables
    --exe          select the executable to use as the base, defaults to the current one
    --memory-limit n       limit the memory usage to 'n' Kbytes
    --stack-size n         limit the stack size to 'n' Kbytes
-q  --quit         just instantiate the interpreter and quit

However, if we check the symlink and run using the absolute path

ls -la /home/linuxbrew/.linuxbrew/bin/envstr
lrwxrwxrwx 1 user user 33 Mar 30 18:35 /home/linuxbrew/.linuxbrew/bin/envstr -> ../Cellar/envstr/0.0.1/bin/envstr

It works as expected

/home/linuxbrew/.linuxbrew/bin/envstr -v
0.0.1

/home/linuxbrew/.linuxbrew/Cellar/envstr/0.0.1/bin/envstr -v
0.0.1

I verified this behavior by symlinking the locally compiled binary to /usr/local/bin as well:

ln -s /home/user/projects/envstr/build/bin/envstr-linux-x64 /usr/local/bin/envstr
which envstr
/usr/local/bin/envstr

Calling with the file name fails:

envstr -v

qjs: unknown option '-v'
QuickJS-ng version 0.9.0
usage: qjs [options] [file [args]]
-h  --help         list options
-e  --eval EXPR    evaluate EXPR
-i  --interactive  go to interactive mode
-m  --module       load as ES6 module (default=autodetect)
    --script       load as ES6 script (default=autodetect)
-I  --include file include an additional file
    --std          make 'std', 'os' and 'bjson' available to script
-T  --trace        trace memory allocation
-d  --dump         dump the memory usage stats
-D  --dump-flags   flags for dumping debug data (see DUMP_* defines)
-c  --compile FILE compile the given JS file as a standalone executable
-o  --out FILE     output file for standalone executables
    --exe          select the executable to use as the base, defaults to the current one
    --memory-limit n       limit the memory usage to 'n' Kbytes
    --stack-size n         limit the stack size to 'n' Kbytes
-q  --quit         just instantiate the interpreter and quit

But the absolute path works again:

/usr/local/bin/envstr -v
0.0.1

I tested this behavior on linux and mac, it was the same for both systems.

Do you think this is a bug, or am I missing some compile option?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions