-
Notifications
You must be signed in to change notification settings - Fork 503
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
Allow overriding when an optional import took place #2523
Comments
Thanks for the issue! I think of these, some way to get the value of a variable, or a fallback if undefined, would be pretty reasonable. I'm not sure about Maybe a |
That sounds very reasonable to me! However, I also thought a bit more about my use case, and it might be that some way to have imported recipes override local ones would actually suit me better, so let me describe it (sorry if I'm changing the original issue a bit here and posting another wall of text!) In our case, we have two repositories, one public and one private. The public one is also a submodule of the private one. Now, we have two ways of building things. Very roughly speaking, parts of the public repo can be built standalone using host toolchains, but when we build those parts as a checked out submodule of the private repo, we want to build those parts integrated into the build system of the private repo. So in a nutshell, The answer to my original question (and the
So all in all we would probably benefit most from some mechanism achieving what I described in the first bullet point, where I would be able to override the
By the way, as a reward for reading this all, let me congratulate you for this project 🙂. I heard about it first time this week, and started trying it out yesterday, and I really find it awesome, kudos! If you prefer to keep this issue scoped to the |
Hey @casey, I just found out that you can actually achieve what I was aiming for with the existing version: the trick is to put the things one wants to override (recipes or variables) behind an import as well. The ordering is somewhat unintuitive, as the topmost imports seem to override bottom ones, which seems to contradict the documentation (last definition is used). But here's a full working example: # maybe.just
hi := 'hello override!'
foo:
echo "I'm overridden"
# base.just
hi := 'hi'
foo:
echo "I'm not overridden"
# justfile
set allow-duplicate-variables
set allow-duplicate-recipes
import? 'maybe.just' # notice overriding import must come first!
import 'base.just'
hi:
echo {{ hi }} Then The order in which duplicate definitions are resolved from imports might need a look though: I guess making it more intuitive (last import takes the spot) might break some configurations out there, but maybe a note in the docs might help? Feel free to take whatever idea I've thrown at you that seems worthwhile. For example I still think |
Hmm, yah that's definitely a bit odd. I dug in and it's because:
This is not great behavior. When
When the duplicate recipes are behind imports, however, recipes in earlier imports override recipes in earlier imports.
I'm going to create a separate issue to discuss this. Weird ordering aside, is this a good enough for your use-case? I'm a little bit hesitant about |
Created an issue in #2540 to track this weird order issue. |
Documented the weirdness in #2541. |
Hi!
I would like to be able to detect within a justfile whether an optional import took place.
I found out a workaround to do that within recipe bodies, namely
however I did not find a way to have that information available in expressions.
If there's no way currently, here's a couple of things I tried that might be good features in their own right, and would solve this problem:
when
allow-duplicate-variables
is set, one could have the position of the import be relevant for overriding. Reading the documentation ofallow-duplicate-variables
, I actually expected this to work:If imports are allowed anywhere in a just file, I would expect duplicates from imports to override previous definitions (if duplicates are allowed).
If this held for recipes as well, I would probably even not need to use an
if
, and would just overwrite some recipes inmaybe.just
.Afterwards I could see this goes directly in contrast with the way imports are specified in the documentation... so maybe this route could be taken with a new directive like
include
/include?
?a
?
postfix operator could allow using undefined variables:var?
would evaluate to the value ofvar
ifvar
is defined, and to""
otherwise.an
imported
function. It could be specified to return"true"
for modules that were importedfor completeness, though I don't particularly like such a solution, an optional variable name after an
import?
could be filled with"true"
or""
depending on whether the import took placeThe text was updated successfully, but these errors were encountered: