@@ -82,14 +82,24 @@ impl<'src> Justfile<'src> {
8282 root : & ' run Scope < ' src , ' run > ,
8383 scopes : & mut BTreeMap < String , ( & ' run Self , & ' run Scope < ' src , ' run > ) > ,
8484 search : & ' run Search ,
85+ variable_references : Option < & HashSet < Number > > ,
8586 ) -> RunResult < ' src > {
86- let scope = Evaluator :: evaluate_assignments ( config, dotenv, self , root, search) ?;
87+ let scope =
88+ Evaluator :: evaluate_assignments ( config, dotenv, self , root, search, variable_references) ?;
8789
8890 let scope = arena. alloc ( scope) ;
8991 scopes. insert ( self . module_path . clone ( ) , ( self , scope) ) ;
9092
9193 for module in self . modules . values ( ) {
92- module. evaluate_scopes ( arena, config, dotenv, scope, scopes, search) ?;
94+ module. evaluate_scopes (
95+ arena,
96+ config,
97+ dotenv,
98+ scope,
99+ scopes,
100+ search,
101+ variable_references,
102+ ) ?;
93103 }
94104
95105 Ok ( ( ) )
@@ -123,9 +133,6 @@ impl<'src> Justfile<'src> {
123133 let root = Scope :: root ( ) ;
124134 let arena = Arena :: new ( ) ;
125135 let mut scopes = BTreeMap :: new ( ) ;
126- self . evaluate_scopes ( & arena, config, & dotenv, & root, & mut scopes, search) ?;
127-
128- let scope = scopes. get ( & self . module_path ) . unwrap ( ) . 1 ;
129136
130137 match & config. subcommand {
131138 Subcommand :: Choose { .. } | Subcommand :: Run { .. } => {
@@ -139,6 +146,37 @@ impl<'src> Justfile<'src> {
139146 } ) ;
140147 }
141148
149+ let variable_references = if self . settings . lazy {
150+ let mut variable_references = HashSet :: new ( ) ;
151+
152+ let mut stack = Vec :: new ( ) ;
153+
154+ for invocation in & invocations {
155+ stack. push ( invocation. recipe ) ;
156+ }
157+
158+ while let Some ( recipe) = stack. pop ( ) {
159+ variable_references. extend ( & recipe. variable_references ) ;
160+ for dependency in & recipe. dependencies {
161+ stack. push ( & dependency. recipe ) ;
162+ }
163+ }
164+
165+ Some ( variable_references)
166+ } else {
167+ None
168+ } ;
169+
170+ self . evaluate_scopes (
171+ & arena,
172+ config,
173+ & dotenv,
174+ & root,
175+ & mut scopes,
176+ search,
177+ variable_references. as_ref ( ) ,
178+ ) ?;
179+
142180 let ran = Ran :: default ( ) ;
143181 for invocation in invocations {
144182 Self :: run_recipe (
@@ -170,7 +208,8 @@ impl<'src> Justfile<'src> {
170208 . args ( arguments)
171209 . current_dir ( & search. working_directory ) ;
172210
173- let scope = scope. child ( ) ;
211+ self . evaluate_scopes ( & arena, config, & dotenv, & root, & mut scopes, search, None ) ?;
212+ let scope = scopes. get ( & self . module_path ) . unwrap ( ) . 1 . child ( ) ;
174213
175214 command. export ( & self . settings , & dotenv, & scope, & self . unexports ) ;
176215
@@ -197,6 +236,9 @@ impl<'src> Justfile<'src> {
197236 Ok ( ( ) )
198237 }
199238 Subcommand :: Evaluate { variable, .. } => {
239+ self . evaluate_scopes ( & arena, config, & dotenv, & root, & mut scopes, search, None ) ?;
240+ let scope = scopes. get ( & self . module_path ) . unwrap ( ) . 1 ;
241+
200242 if let Some ( variable) = variable {
201243 if let Some ( value) = scope. value ( variable) {
202244 print ! ( "{value}" ) ;
0 commit comments