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

Treat paths in submodule relative to directory of root .justfile #2222

Open
Splines opened this issue Jul 4, 2024 · 4 comments
Open

Treat paths in submodule relative to directory of root .justfile #2222

Splines opened this issue Jul 4, 2024 · 4 comments

Comments

@Splines
Copy link

Splines commented Jul 4, 2024

It'd be great to have an option to treat all paths in a submodule relative to the directory containing the root .justfile. I think I'd prefer a per-module flag for this instead of a global one.

This would allow me to let my submodules reside in other file locations (e.g. in a folder .config/commands/), while not having to issue a cd {{justfile_directory()}} or cd ../../ at the beginning of every recipe.

@casey
Copy link
Owner

casey commented Jul 5, 2024

I think this would be great. I can imagine a few options that might be useful:

  1. Use the working directory of the root justfile
  2. Use the working directory of the parent module, even if it isn't the root.
  3. Use a specific working directory

The syntax could be:

# default value
set working-dir := default
set working-dir := self

# use the working directory of the parent module
set working-dir := parent

# use the working directory of the root justfile
set working-dir := root

# use some other working directory
set working-dir := "some/other/directory"

@Splines
Copy link
Author

Splines commented Aug 1, 2024

This is probably related to #2273 and the respective PR #2283.

@casey
Copy link
Owner

casey commented Aug 1, 2024

#2283 added support for the form that takes a string:

set working-dir := "some/other/directory"

So we're still lacking the ability to use the working directory of a parent justfile.

I think the best syntax for using the working directory of the parent is:

set working-dir := super

However, I'd like to keep the door open for eventually allowing the use of a variable. I.e.:

set working-dir := foo

just currently doesn't allow the use of variables in settings, since settings may affect how backticks and the shell(…) function run, including their working directory and exported variables.

So, this syntax:

set working-dir := super

Would change meaning if the RHS of a setting became an expression:

super := "hello"
set working-dir := super

One option is to use some kind of syntax which isn't a valid expression:

set working-dir := @super
set working-dir := super.working_dir
set working-dir := super::working_dir
set working-dir := super->working_dir
set working-dir := super#working_dir
set working-dir := super@working_dir

This is a bit wonky, but the fact that expressions can't be used in setting values has been an issue many times, so I wouldn't want to preclude fixing it.

@casey
Copy link
Owner

casey commented Aug 1, 2024

This is all horrifically complicated by the fact that variables, recipes, and settings can all have the same name.

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

No branches or pull requests

2 participants