Skip to content

Commit 308ce33

Browse files
committed
Add pre-globals
1 parent 0ec54db commit 308ce33

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ features are currently supported, however. A list of supported features follows:
6363
* `$VAR` environment variables
6464
* `$(echo)` internal subcommands
6565
* `$1` positional arguments
66+
* `$@` all positional arguments
6667
* Single and double-quoted arguments
6768
* Command chaining by `&&`, `||`, and `|` (no `;`, just use newlines)
68-
69-
(In the latest pre-release):
7069
* `VAR=val` Environment variable setting (with interpolation)

src/main.rs

+13
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,19 @@ pub fn run(args: &[&str], cwd: &Path, inherit_verbosity: Verbosity, capture_stdo
300300
let mut output_acc = Vec::new();
301301
//TODO: Instead, find all scripts that would run given the target and phases?
302302
for &phase in phases {
303+
match &rf.get_pre_global_script(phase) {
304+
Some(script) => {
305+
out::phase_message(&output_stream, phase, "pre-global");
306+
let (success, output) = exec::shell(&script.commands, &rf, &exec_config, capture_stdout, env_remap);
307+
if capture_stdout {
308+
output_acc.extend(output.into_iter());
309+
}
310+
if !success {
311+
return (expect_fail, output_acc);
312+
}
313+
},
314+
None => {}
315+
}
303316
if let Some(ref run_target) = run_target {
304317
match rf.get_target(&run_target) {
305318
Some(target) => match &target[phase] {

src/parser.rs

+10
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pub fn parse_runscript(source: RunscriptSource) -> Result<Runscript, RunscriptPa
176176
source: source.source.clone(),
177177
includes: Vec::new(),
178178
scripts: Scripts {
179+
pre_global_target: EnumMap::new(),
179180
global_target: EnumMap::new(),
180181
default_target: EnumMap::new(),
181182
targets: HashMap::new(),
@@ -325,6 +326,15 @@ fn parse_root<T: Iterator<Item = (usize, char)> + std::fmt::Debug>(context: &mut
325326
});
326327
}
327328
context.runfile.scripts.global_target[phase] = Some(script);
329+
} else if name == "<" {
330+
if let Some(prev_script) = &context.runfile.scripts.pre_global_target[phase] {
331+
return Err(RunscriptParseErrorData::MultipleDefinition {
332+
previous_location: prev_script.location.clone(),
333+
new_location: script.location,
334+
target_name: name,
335+
})
336+
}
337+
context.runfile.scripts.pre_global_target[phase] = Some(script);
328338
} else {
329339
if name.chars().any(|c| !(c.is_ascii_alphanumeric() || c == '_' || c == '-')) {
330340
return Err(RunscriptParseErrorData::InvalidID { location: context.get_loc(i + 1), found: name });

src/script.rs

+20
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ pub struct RunscriptInclude {
3131
/// The exectable scripts defined by a [`Runscript`](struct.Runscript.html)
3232
#[derive(Debug)]
3333
pub struct Scripts {
34+
/// The scripts defined under `#<`
35+
///
36+
/// These scripts are executed in their respective `ScriptPhase` before the targeted target.
37+
pub pre_global_target: EnumMap<ScriptPhase, Option<Script>>,
3438
/// The scripts defined under `##`
3539
///
3640
/// These scripts are executed in their respective `ScriptPhase` after the targeted target.
@@ -174,6 +178,22 @@ impl Runscript {
174178
}
175179
}
176180
}
181+
182+
pub fn get_pre_global_script(&self, phase: ScriptPhase) -> Option<&Script> {
183+
match self.scripts.pre_global_target[phase].as_ref() {
184+
Some(script) => {
185+
Some(&script)
186+
},
187+
_ => {
188+
for include in &self.includes {
189+
if let Some(script) = include.runscript.scripts.pre_global_target[phase].as_ref() {
190+
return Some(&script);
191+
}
192+
}
193+
None
194+
}
195+
}
196+
}
177197
}
178198

179199
impl Display for ScriptEntry {

test/phases.run

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ echo Build
1010
echo BuildAndRun Default
1111
#/
1212

13-
## br
13+
#< br
1414
echo BuildAndRun Explicit
1515
#/
1616

0 commit comments

Comments
 (0)