Skip to content

Commit b23317f

Browse files
committed
Refactor creation of make commands
1 parent 7994e07 commit b23317f

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

jemalloc-sys/build.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -302,36 +302,25 @@ fn main() {
302302

303303
// Make:
304304
let make = make_cmd(&host);
305-
let mut cmd = Command::new(make);
306-
cmd.current_dir(&build_dir);
307-
if let Ok(makeflags) = std::env::var("CARGO_MAKEFLAGS") {
308-
cmd.env("MAKEFLAGS", makeflags);
309-
} else {
310-
cmd.arg("-j").arg(num_jobs.clone());
311-
}
312-
run(&mut cmd);
305+
run(&mut make_command(make, &build_dir, &num_jobs));
313306

314307
// Skip watching this environment variables to avoid rebuild in CI.
315308
if env::var("JEMALLOC_SYS_RUN_JEMALLOC_TESTS").is_ok() {
316309
info!("Building and running jemalloc tests...");
310+
311+
let mut cmd = make_command(make, &build_dir, &num_jobs);
312+
317313
// Make tests:
318-
run(Command::new(make)
319-
.current_dir(&build_dir)
320-
.arg("-j")
321-
.arg(num_jobs.clone())
322-
.arg("tests"));
314+
run(cmd.arg("tests"));
323315

324316
// Run tests:
325-
run(Command::new(make).current_dir(&build_dir).arg("check"));
317+
run(make_command(make, &build_dir, &num_jobs).arg("check"));
326318
}
327319

328320
// Make install:
329-
run(Command::new(make)
330-
.current_dir(&build_dir)
321+
run(make_command(make, &build_dir, &num_jobs)
331322
.arg("install_lib_static")
332-
.arg("install_include")
333-
.arg("-j")
334-
.arg(num_jobs));
323+
.arg("install_include"));
335324

336325
println!("cargo:root={}", out_dir.display());
337326

@@ -371,6 +360,23 @@ fn main() {
371360
}
372361
}
373362

363+
fn make_command(make_cmd: &str, build_dir: &Path, num_jobs: &str) -> Command {
364+
let mut cmd = Command::new(make_cmd);
365+
cmd.current_dir(build_dir);
366+
367+
if let Ok(makeflags) = std::env::var("CARGO_MAKEFLAGS") {
368+
let makeflags = if let Ok(orig_makeflags) = std::env::var("MAKEFLAGS") {
369+
format!("{orig_makeflags} {makeflags}")
370+
} else {
371+
makeflags
372+
};
373+
cmd.env("MAKEFLAGS", makeflags);
374+
} else {
375+
cmd.arg("-j").arg(num_jobs);
376+
}
377+
cmd
378+
}
379+
374380
fn run_and_log(cmd: &mut Command, log_file: &Path) {
375381
execute(cmd, || {
376382
run(Command::new("tail").arg("-n").arg("100").arg(log_file));

0 commit comments

Comments
 (0)