Do not evaluate backticks in assignments during dry runs (#253)
This commit is contained in:
parent
13a124d659
commit
acb5d6f98b
@ -7,6 +7,7 @@ pub fn evaluate_assignments<'a>(
|
||||
overrides: &Map<&str, &str>,
|
||||
quiet: bool,
|
||||
shell: &'a str,
|
||||
dry_run: bool,
|
||||
) -> RunResult<'a, Map<&'a str, String>> {
|
||||
let mut evaluator = AssignmentEvaluator {
|
||||
assignments: assignments,
|
||||
@ -16,6 +17,7 @@ pub fn evaluate_assignments<'a>(
|
||||
quiet: quiet,
|
||||
scope: &empty(),
|
||||
shell: shell,
|
||||
dry_run: dry_run,
|
||||
};
|
||||
|
||||
for name in assignments.keys() {
|
||||
@ -25,31 +27,6 @@ pub fn evaluate_assignments<'a>(
|
||||
Ok(evaluator.evaluated)
|
||||
}
|
||||
|
||||
fn run_backtick<'a, 'b>(
|
||||
raw: &str,
|
||||
token: &Token<'a>,
|
||||
scope: &Map<&'a str, String>,
|
||||
exports: &Set<&'a str>,
|
||||
quiet: bool,
|
||||
shell: &'b str,
|
||||
) -> RunResult<'a, String> {
|
||||
let mut cmd = Command::new(shell);
|
||||
|
||||
cmd.export_environment_variables(scope, exports)?;
|
||||
|
||||
cmd.arg("-cu")
|
||||
.arg(raw);
|
||||
|
||||
cmd.stderr(if quiet {
|
||||
process::Stdio::null()
|
||||
} else {
|
||||
process::Stdio::inherit()
|
||||
});
|
||||
|
||||
brev::output(cmd)
|
||||
.map_err(|output_error| RuntimeError::Backtick{token: token.clone(), output_error})
|
||||
}
|
||||
|
||||
pub struct AssignmentEvaluator<'a: 'b, 'b> {
|
||||
pub assignments: &'b Map<&'a str, Expression<'a>>,
|
||||
pub evaluated: Map<&'a str, String>,
|
||||
@ -58,6 +35,7 @@ pub struct AssignmentEvaluator<'a: 'b, 'b> {
|
||||
pub quiet: bool,
|
||||
pub scope: &'b Map<&'a str, String>,
|
||||
pub shell: &'b str,
|
||||
pub dry_run: bool,
|
||||
}
|
||||
|
||||
impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
|
||||
@ -123,7 +101,11 @@ impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
|
||||
}
|
||||
Expression::String{ref cooked_string} => cooked_string.cooked.clone(),
|
||||
Expression::Backtick{raw, ref token} => {
|
||||
run_backtick(raw, token, self.scope, self.exports, self.quiet, self.shell)?
|
||||
if self.dry_run {
|
||||
format!("`{}`", raw)
|
||||
} else {
|
||||
self.run_backtick(raw, token)?
|
||||
}
|
||||
}
|
||||
Expression::Concatination{ref lhs, ref rhs} => {
|
||||
self.evaluate_expression(lhs, arguments)?
|
||||
@ -132,6 +114,28 @@ impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn run_backtick(
|
||||
&self,
|
||||
raw: &str,
|
||||
token: &Token<'a>,
|
||||
) -> RunResult<'a, String> {
|
||||
let mut cmd = Command::new(self.shell);
|
||||
|
||||
cmd.export_environment_variables(self.scope, self.exports)?;
|
||||
|
||||
cmd.arg("-cu")
|
||||
.arg(raw);
|
||||
|
||||
cmd.stderr(if self.quiet {
|
||||
process::Stdio::null()
|
||||
} else {
|
||||
process::Stdio::inherit()
|
||||
});
|
||||
|
||||
brev::output(cmd)
|
||||
.map_err(|output_error| RuntimeError::Backtick{token: token.clone(), output_error})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -60,6 +60,7 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b {
|
||||
&options.overrides,
|
||||
options.quiet,
|
||||
options.shell,
|
||||
options.dry_run,
|
||||
)?;
|
||||
|
||||
if options.evaluate {
|
||||
|
@ -91,6 +91,7 @@ impl<'a> Recipe<'a> {
|
||||
overrides: &empty(),
|
||||
quiet: options.quiet,
|
||||
shell: options.shell,
|
||||
dry_run: options.dry_run,
|
||||
};
|
||||
|
||||
if self.shebang {
|
||||
|
@ -497,14 +497,13 @@ shebang:
|
||||
echo {{`echo shebang interpolation`}}"#,
|
||||
args: ("--dry-run", "shebang", "command"),
|
||||
stdout: "",
|
||||
stderr: "stderr
|
||||
#!/bin/sh
|
||||
stderr: "#!/bin/sh
|
||||
touch /this/is/not/a/file
|
||||
backtick
|
||||
echo shebang interpolation
|
||||
`echo stderr 1>&2; echo backtick`
|
||||
echo `echo shebang interpolation`
|
||||
touch /this/is/not/a/file
|
||||
backtick
|
||||
echo command interpolation
|
||||
`echo stderr 1>&2; echo backtick`
|
||||
echo `echo command interpolation`
|
||||
",
|
||||
status: EXIT_SUCCESS,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user