Skip to content

Commit 5ba1d61

Browse files
Properly report and terminate if cargo acl test fails
Tests for this use-case will be added later, since we need some additional features to be able to effectively test this.
1 parent 327f534 commit 5ba1d61

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

src/build_script_checker.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ impl BuildScriptReport {
2020
) -> Result<BuildScriptReport> {
2121
let mut report = BuildScriptReport::default();
2222
let crate_sel = &outputs.crate_sel;
23-
if outputs.exit_code != 0 {
24-
report.problems.push(Problem::BuildScriptFailed(
25-
crate::problem::BinExecutionFailed {
26-
output: outputs.clone(),
27-
crate_sel: crate_sel.clone(),
28-
},
29-
));
30-
return Ok(report);
31-
}
3223
let perm_sel = PermSel::for_build_script(crate_sel.pkg_name());
3324
let allow_build_instructions = config
3425
.permissions
@@ -117,7 +108,7 @@ mod tests {
117108
stderr: vec![],
118109
crate_sel: CrateSel::build_script(pkg_id("my_pkg")),
119110
sandbox_config: SandboxConfig::default(),
120-
build_script: PathBuf::new(),
111+
binary_path: PathBuf::new(),
121112
sandbox_config_display: None,
122113
};
123114
super::BuildScriptReport::build(&outputs, &config)

src/checker.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,15 @@ impl Checker {
242242
Ok(ProblemList::default())
243243
}
244244
rpc::Request::BinExecutionComplete(output) => {
245-
if output.crate_sel.kind == CrateKind::BuildScript {
245+
if output.exit_code != 0 {
246+
Ok(
247+
Problem::ExecutionFailed(crate::problem::BinExecutionFailed {
248+
output: output.clone(),
249+
crate_sel: output.crate_sel.clone(),
250+
})
251+
.into(),
252+
)
253+
} else if output.crate_sel.kind == CrateKind::BuildScript {
246254
let report =
247255
build_script_checker::BuildScriptReport::build(output, &self.config)?;
248256
crate::sandbox::write_env_vars(

src/config_editor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub(crate) fn fixes_for_problem(problem: &Problem, config: &Config) -> Vec<Box<d
9494
perm_sel: PermSel::for_primary(pkg_id.pkg_name()),
9595
}));
9696
}
97-
Problem::BuildScriptFailed(failure) => {
97+
Problem::ExecutionFailed(failure) => {
9898
if failure.output.sandbox_config.kind != Some(SandboxKind::Disabled) {
9999
let perm_sel = PermSel::for_build_script(failure.crate_sel.pkg_name());
100100
if !failure.output.sandbox_config.allow_network.unwrap_or(false) {
@@ -1337,7 +1337,7 @@ mod tests {
13371337
#[test]
13381338
fn build_script_failed() {
13391339
let crate_sel = CrateSel::build_script(pkg_id("crab1"));
1340-
let failure = Problem::BuildScriptFailed(crate::problem::BinExecutionFailed {
1340+
let failure = Problem::ExecutionFailed(crate::problem::BinExecutionFailed {
13411341
output: BinExecutionOutput {
13421342
exit_code: 1,
13431343
stdout: Vec::new(),
@@ -1350,7 +1350,7 @@ mod tests {
13501350
bind_writable: vec![],
13511351
make_writable: vec![],
13521352
},
1353-
build_script: PathBuf::new(),
1353+
binary_path: PathBuf::new(),
13541354
sandbox_config_display: None,
13551355
},
13561356
crate_sel,

src/problem.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(crate) enum Problem {
3535
IsProcMacro(PackageId),
3636
DisallowedApiUsage(ApiUsages),
3737
OffTreeApiUsage(OffTreeApiUsage),
38-
BuildScriptFailed(BinExecutionFailed),
38+
ExecutionFailed(BinExecutionFailed),
3939
DisallowedBuildInstruction(DisallowedBuildInstruction),
4040
UnusedPackageConfig(PermSel),
4141
UnusedAllowApi(UnusedAllowApi),
@@ -181,7 +181,7 @@ impl Problem {
181181
fn should_send_retry_to_subprocess(&self) -> bool {
182182
matches!(
183183
self,
184-
&Problem::BuildScriptFailed(..) | &Problem::DisallowedUnsafe(..)
184+
&Problem::ExecutionFailed(..) | &Problem::DisallowedUnsafe(..)
185185
)
186186
}
187187

@@ -222,7 +222,7 @@ impl Problem {
222222
Problem::IsProcMacro(pkg_id) => Some(pkg_id),
223223
Problem::DisallowedApiUsage(d) => Some(&d.pkg_id),
224224
Problem::OffTreeApiUsage(d) => Some(&d.usages.pkg_id),
225-
Problem::BuildScriptFailed(d) => Some(d.crate_sel.pkg_id()),
225+
Problem::ExecutionFailed(d) => Some(d.crate_sel.pkg_id()),
226226
Problem::DisallowedBuildInstruction(d) => Some(&d.pkg_id),
227227
Problem::UnusedPackageConfig(_) => None,
228228
Problem::UnusedAllowApi(_) => None,
@@ -282,7 +282,7 @@ impl Display for Problem {
282282
display_usages(f, &info.usages.usages)?;
283283
}
284284
}
285-
Problem::BuildScriptFailed(info) => info.fmt(f)?,
285+
Problem::ExecutionFailed(info) => info.fmt(f)?,
286286
Problem::DisallowedBuildInstruction(info) => {
287287
write!(
288288
f,

src/proxy/rpc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl RpcClient {
5353
read_from_stream(&mut ipc)
5454
}
5555

56-
pub(crate) fn build_script_complete(&self, info: BinExecutionOutput) -> Result<Outcome> {
56+
pub(crate) fn bin_execution_complete(&self, info: BinExecutionOutput) -> Result<Outcome> {
5757
let mut ipc = self.connect()?;
5858
write_to_stream(&Request::BinExecutionComplete(info), &mut ipc)?;
5959
read_from_stream(&mut ipc)
@@ -96,7 +96,7 @@ pub(crate) struct BinExecutionOutput {
9696
pub(crate) stderr: Vec<u8>,
9797
pub(crate) crate_sel: CrateSel,
9898
pub(crate) sandbox_config: SandboxConfig,
99-
pub(crate) build_script: PathBuf,
99+
pub(crate) binary_path: PathBuf,
100100
/// A display string for how the sandbox was configured (e.g. the command line). Only present if
101101
/// the exit code is non-zero.
102102
pub(crate) sandbox_config_display: Option<String>,

src/proxy/subprocess.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ fn proxy_binary(
152152
};
153153

154154
let output = sandbox.run(&command)?;
155-
let rpc_response = rpc_client.build_script_complete({
155+
let rpc_response = rpc_client.bin_execution_complete({
156156
let exit_code = output.status.code().unwrap_or(-1);
157157
BinExecutionOutput {
158158
exit_code,
159159
stdout: output.stdout.clone(),
160160
stderr: output.stderr.clone(),
161161
crate_sel: crate_sel.clone(),
162162
sandbox_config,
163-
build_script: orig_bin.clone(),
163+
binary_path: orig_bin.clone(),
164164
sandbox_config_display: (exit_code != 0)
165165
.then(|| sandbox.display_to_run(&command).to_string()),
166166
}

0 commit comments

Comments
 (0)