Skip to content

Commit c2b9a8c

Browse files
authored
Fix overrides not being visible in user-defined functions (#3307)
1 parent b31c0fa commit c2b9a8c

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

src/evaluator.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ impl<'src, 'run> Evaluator<'src, 'run> {
152152
config,
153153
dotenv,
154154
module,
155+
overrides,
155156
search,
156157
};
157158

@@ -238,14 +239,13 @@ impl<'src, 'run> Evaluator<'src, 'run> {
238239
});
239240
}
240241

241-
let overrides = HashMap::new();
242242
let mut evaluator = Evaluator {
243243
assignments: Some(&context.module.assignments),
244244
context: Some(context),
245245
env: BTreeMap::new(),
246246
is_dependency: false,
247247
non_const_assignments: Table::new(),
248-
overrides: &overrides,
248+
overrides: self.overrides,
249249
scope,
250250
};
251251

@@ -589,14 +589,13 @@ impl<'src, 'run> Evaluator<'src, 'run> {
589589
is_dependency: bool,
590590
scope: &'run Scope<'src, 'run>,
591591
) -> Self {
592-
static OVERRIDES: LazyLock<HashMap<Number, String>> = LazyLock::new(HashMap::new);
593592
Self {
594593
assignments: None,
595594
context: Some(*context),
596595
env,
597596
is_dependency,
598597
non_const_assignments: Table::new(),
599-
overrides: &OVERRIDES,
598+
overrides: context.overrides,
600599
scope: scope.child(),
601600
}
602601
}

src/execution_context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub(crate) struct ExecutionContext<'src: 'run, 'run> {
55
pub(crate) config: &'run Config,
66
pub(crate) dotenv: &'run BTreeMap<String, String>,
77
pub(crate) module: &'run Justfile<'src>,
8+
pub(crate) overrides: &'run HashMap<Number, String>,
89
pub(crate) search: &'run Search,
910
}
1011

src/justfile.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ impl<'src> Justfile<'src> {
223223
&invocation.arguments,
224224
config,
225225
false,
226+
overrides,
226227
&ran,
227228
invocation.recipe,
228229
&scopes,
@@ -419,6 +420,7 @@ impl<'src> Justfile<'src> {
419420
arguments: &[Vec<String>],
420421
config: &Config,
421422
is_dependency: bool,
423+
overrides: &HashMap<Number, String>,
422424
ran: &Ran,
423425
recipe: &Recipe<'src>,
424426
scopes: &Scopes<'src, '_>,
@@ -440,6 +442,7 @@ impl<'src> Justfile<'src> {
440442
config,
441443
dotenv,
442444
module,
445+
overrides,
443446
search,
444447
};
445448

@@ -467,6 +470,7 @@ impl<'src> Justfile<'src> {
467470
&context,
468471
recipe.priors(),
469472
&mut evaluator,
473+
overrides,
470474
ran,
471475
recipe,
472476
scopes,
@@ -480,6 +484,7 @@ impl<'src> Justfile<'src> {
480484
&context,
481485
recipe.subsequents(),
482486
&mut evaluator,
487+
overrides,
483488
&Ran::default(),
484489
recipe,
485490
scopes,
@@ -496,6 +501,7 @@ impl<'src> Justfile<'src> {
496501
context: &ExecutionContext<'src, 'run>,
497502
dependencies: &[Dependency<'src>],
498503
evaluator: &mut Evaluator<'src, 'run>,
504+
overrides: &HashMap<Number, String>,
499505
ran: &Ran,
500506
recipe: &Recipe<'src>,
501507
scopes: &Scopes<'src, 'run>,
@@ -523,7 +529,9 @@ impl<'src> Justfile<'src> {
523529
let mut handles = Vec::new();
524530
for (recipe, arguments) in evaluated {
525531
handles.push(thread_scope.spawn(move || {
526-
Self::run_recipe(&arguments, config, true, ran, recipe, scopes, search)
532+
Self::run_recipe(
533+
&arguments, config, true, overrides, ran, recipe, scopes, search,
534+
)
527535
}));
528536
}
529537
for handle in handles {
@@ -535,7 +543,9 @@ impl<'src> Justfile<'src> {
535543
})?;
536544
} else {
537545
for (recipe, arguments) in evaluated {
538-
Self::run_recipe(&arguments, config, true, ran, recipe, scopes, search)?;
546+
Self::run_recipe(
547+
&arguments, config, true, overrides, ran, recipe, scopes, search,
548+
)?;
539549
}
540550
}
541551

tests/function_definitions.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,24 @@ fn has_access_to_env_file() {
338338
.success();
339339
}
340340

341+
#[test]
342+
fn may_reference_overrides() {
343+
Test::new()
344+
.justfile(
345+
"
346+
x := 'bar'
347+
foo() := x
348+
349+
a:
350+
@echo {{foo()}}
351+
",
352+
)
353+
.args(["x=baz", "a"])
354+
.stdout("baz\n")
355+
.env("JUST_UNSTABLE", "1")
356+
.success();
357+
}
358+
341359
#[test]
342360
fn may_reference_non_const_assignment() {
343361
Test::new()

0 commit comments

Comments
 (0)