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

justfile_directory() -> canonical_justfile_directory() #2018

Open
woutervh opened this issue May 1, 2024 · 6 comments
Open

justfile_directory() -> canonical_justfile_directory() #2018

woutervh opened this issue May 1, 2024 · 6 comments

Comments

@woutervh
Copy link

woutervh commented May 1, 2024

usecase: I started to make a symlink to my justfile in the root of my filesystem /
to have access to my just-recipes from anywhere.

in this case the justfile is a symlink, this introduces an error justfile_directory() which is not resolved

ln -s /path/to/justfile /

It would be nice the have a resolved canonical directory "canonical_justfile_directory()"

@casey
Copy link
Owner

casey commented May 15, 2024

Can you provide steps to reproduce the issue? I was able to create a justfile, symlink it to /justfile, and then print justfile_directory() which was equal to /.

Is the goal to have justfile_directory() print out the original directory of the justfile?

I think you could use:

dir := `parent(canonicalize(justfile()))`

Does that work for you?

@woutervh
Copy link
Author

dir := `parent(canonicalize(justfile()))`

this line fails:

bash: -c: line 1: syntax error near unexpected token `canonicalize'
bash: -c: line 1: `parent(canonicalize(justfile()))'
error: Backtick failed with exit code 2
  ——▶ justfile:31:8
   │
31 │ dir := `parent(canonicalize(justfile()))`
   │        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@woutervh
Copy link
Author

this works to get the canonical justfile-directory:

canonical_justfile_dir := parent_directory(canonicalize(justfile()))

with a symlinked justfile in the root of the linux filesystem
/justfile -> /etc/justfile

just --evaluate
...
canonical_justfile_dir := "/etc"

but now I want to use this variable to import justfiles from
/etc/just/.justfile to replace hardcoded paths:

canonical_justfile_dir := parent_directory(canonicalize(justfile()))
import_dir := canonical_justfile_dir / "just"

import '/etc/just/doc8.justfile'
import '/etc/just/docker.justfile'

@woutervh
Copy link
Author

import "${import_dir}/doc8.justfile"

or

import "{{import_dir}}/doc8.justfile"

gives:

tsc@661febeb270f:~$ just --evaluate
error: Could not find source file for import.
  ——▶ justfile:33:8
   │
33 │ import "{{import_dir}}/doc8.justfile"
   │        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tsc@661febeb270f:~$ vi  /etc/justfile
tsc@661febeb270f:~$ just --evaluate
error: Could not find source file for import.
  ——▶ justfile:33:8
   │
33 │ import "${import_dir}/doc8.justfile"
   │        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@woutervh
Copy link
Author

Note that imports are currently happening relative to the non-canonical justfile-dir.
This is incorrect behaviour since you can symlink from many different directories

(I started out using multiple symlinks, ending up with a symlink in /)

directory-structure (in a docker)

/justfile  --> symlink to /etc/justfile
/etc/
    justfile
    just/
        docker.justfile
        git.justfile

in /etc/justfile imports relative to the canonical location of the justfile fail
except when $PWD is /etc;

import 'just/docker.justfile'
tsc@661febeb270f:~$ just
error: Could not find source file for import.
  ——▶ justfile:34:8
   │
34 │ import 'just/docker.justfile'
   │        ^^^^^^^^^^^^^^^^^^^^^^

@casey
Copy link
Owner

casey commented May 19, 2024

Gotcha, that makes sense. Whoops, yeah, I meant dir := parent_directory(canonicalize(justfile())).

Hmm, this is a tricky one.

Could you make your justfile like this:

import '/etc/justfile'`

Instead of a symlink?

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