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

'import' relative path issue when run symbol linked self-executbale justfile #1977

Open
Ziqi-Yang opened this issue Mar 25, 2024 · 3 comments

Comments

@Ziqi-Yang
Copy link

Ziqi-Yang commented Mar 25, 2024

I have these content in my justfile:

#!/usr/bin/env -S just --working-directory . --justfile

import 'lib.just'
import 'config.just'
import 'template_var.just'

I can run the file normally. However, when I symbol linked file (for example ln -sf) and run the symbol link, it prompts error: Could not find source file for import.. (Note the symbol link is at the different directory than targeted justfile)

@Ziqi-Yang Ziqi-Yang changed the title import relative path issue when using a 'import' relative path issue when self-executbale justfile is symbol linked Mar 25, 2024
@Ziqi-Yang Ziqi-Yang changed the title 'import' relative path issue when self-executbale justfile is symbol linked 'import' relative path issue when run symbol linked self-executbale justfile Mar 25, 2024
@casey
Copy link
Owner

casey commented May 15, 2024

I tried using a symlinked import source file, and I was able to get it to work:

: tree
8192 B symlink-justfile
4096 B ├─ bar.just
4096 B ├─ justfile
   0 B └─ foo.just → /Users/rodarmor/tmp/symlink-justfile/bar.just

2 files, 1 link
: cat justfile
import 'foo.just'
: cat foo.just
bar:
  echo BAR
: just bar
echo BAR
BAR

Can you provide steps to reproduce the issue you're getting?

@Ziqi-Yang
Copy link
Author

Yes, here is the steps for reproducing this issue (make sure you use bash or bash-compatible shells.

cd /tmp
mkdir ./issue-reproduce
cd ./issue-reproduce/

# write justfile
cat > justfile << EOF
#!/usr/bin/env -S just --working-directory . --justfile
pwd:
    pwd

import 'foo.just'
EOF

chmod +x ./justfile

# write foo.just
cat > foo.just << EOF
foo:
    pwd
EOF

Then

cd .. # go back to /tmp
ln -s /tmp/issue-reproduce/justfile ./justfile
./justfile

Finally we can see the error:

❯ ./justfile 
error: Could not find source file for import.
 ——▶ justfile:5:8
  │
5 │ import 'foo.just'
  │        ^^^^^^^^^^

@casey
Copy link
Owner

casey commented May 15, 2024

Ahh gotcha, I see the issue. This could be fixed by interpreting imports relative to the canonicalized path to the current justfile, since canonicalization resolves symlinks. However, I worry that this would be somewhat unexpected behavior. I.e., if you didn't want this behavior, and you had a justfile which was symlinked from somewhere else, you would get a pretty confusing error. I could see enabling this with a setting.

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

2 participants