Skip to content

Commit 66aa9bf

Browse files
committed
extracted duplicated chunk of code into fn emit_build_output, removed redundant line from compiler_json_error_format test
1 parent f101d88 commit 66aa9bf

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ pub fn prepare<'a, 'cfg>(
105105
}
106106
}
107107

108+
fn emit_build_output(output: &BuildOutput, id: &PackageId) {
109+
let library_paths = output
110+
.library_paths
111+
.iter()
112+
.map(|l| l.display().to_string())
113+
.collect::<Vec<_>>();
114+
115+
machine_message::emit(&machine_message::BuildScript {
116+
package_id: id,
117+
linked_libs: &output.library_links,
118+
linked_paths: &library_paths,
119+
cfgs: &output.cfgs,
120+
env: &output.env,
121+
});
122+
}
123+
108124
fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult<(Work, Work)> {
109125
assert!(unit.mode.is_run_custom_build());
110126
let bcx = &cx.bcx;
@@ -336,18 +352,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
336352
BuildOutput::parse(&output.stdout, &pkg_name, &root_output, &root_output)?;
337353

338354
if json_messages {
339-
let library_paths = parsed_output
340-
.library_paths
341-
.iter()
342-
.map(|l| l.display().to_string())
343-
.collect::<Vec<_>>();
344-
machine_message::emit(&machine_message::BuildScript {
345-
package_id: &id,
346-
linked_libs: &parsed_output.library_links,
347-
linked_paths: &library_paths,
348-
cfgs: &parsed_output.cfgs,
349-
env: &parsed_output.env,
350-
});
355+
emit_build_output(&parsed_output, &id);
351356
}
352357
build_state.insert(id, kind, parsed_output);
353358
}
@@ -367,18 +372,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
367372
};
368373

369374
if json_messages {
370-
let library_paths = output
371-
.library_paths
372-
.iter()
373-
.map(|l| l.display().to_string())
374-
.collect::<Vec<_>>();
375-
machine_message::emit(&machine_message::BuildScript {
376-
package_id: &id,
377-
linked_libs: &output.library_links,
378-
linked_paths: &library_paths,
379-
cfgs: &output.cfgs,
380-
env: &output.env,
381-
});
375+
emit_build_output(&output, &id);
382376
}
383377

384378
build_state.insert(id, kind, output);

tests/testsuite/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3976,7 +3976,6 @@ fn compiler_json_error_format() {
39763976
name = "foo"
39773977
version = "0.5.0"
39783978
authors = ["[email protected]"]
3979-
build = "build.rs"
39803979
39813980
[dependencies.bar]
39823981
path = "bar"

0 commit comments

Comments
 (0)