casey / just

🤖 Just a command runner
https://just.systems
Creative Commons Zero v1.0 Universal
21.03k stars 463 forks source link

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

Open Splines opened 3 months ago

Splines commented 3 months ago

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 commented 3 months ago

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 commented 2 months ago

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

casey commented 2 months ago

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 commented 2 months ago

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