Skip to content

Commit c14436c

Browse files
committed
Work-around child processes being blocked on piped output.
See DanielKeep#50.
1 parent e6992ae commit c14436c

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ use rustc_version::{version_matches};
1313
fn main() {
1414
println!("cargo:rerun-if-changed=build.rs");
1515

16+
/*
17+
Environment might suffer from <https://github.com/DanielKeep/cargo-script/issues/50>.
18+
*/
19+
if cfg!(windows) {
20+
println!("cargo:rustc-cfg=issue_50");
21+
}
22+
1623
/*
1724
With 1.15, linking on Windows was changed in regards to when it emits `dllimport`. This means that the *old* code for linking to `FOLDERID_LocalAppData` no longer works. Unfortunately, it *also* means that the *new* code doesn't work prior to 1.15.
1825

src/main.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,16 @@ where P: AsRef<Path> {
15111511
let cargo_ver = try!(cargo_version()
15121512
.err_tag("could not determine target filename"));
15131513

1514-
let exe_path = if cargo_ver < *VER_JSON_MSGS {
1514+
let mut use_guess = false;
1515+
use_guess |= work_around_issue_50();
1516+
use_guess |= if cargo_ver < *VER_JSON_MSGS {
1517+
trace!(".. cargo {:?} is too old to support JSON output", cargo_ver);
1518+
true
1519+
} else {
1520+
false
1521+
};
1522+
1523+
let exe_path = if use_guess {
15151524
try!(cargo_target_by_guess(input, use_bincache, pkg_path.as_ref(), meta))
15161525
} else {
15171526
try!(cargo_target_by_message(input, manifest, use_bincache, meta))
@@ -1652,3 +1661,18 @@ fn cargo_version() -> Result<Version> {
16521661
Ok(try!(Version::parse(ver.as_str())
16531662
.map_err(Box::new)))
16541663
}
1664+
1665+
/**
1666+
Do we need to work around [issue #50](https://github.com/DanielKeep/cargo-script/issues/50)?
1667+
1668+
Sometimes, `cargo-script` will hang when trying to read the JSON output of `cargo build`.
1669+
*/
1670+
fn work_around_issue_50() -> bool {
1671+
let suffers = cfg!(issue_50);
1672+
let ignored = std::env::var_os("CARGO_SCRIPT_IGNORE_ISSUE_50").is_some();
1673+
match (suffers, ignored) {
1674+
(true, true) => { trace!(".. issue 50 relevant, but ignored"); false },
1675+
(true, false) => { trace!(".. working around issue 50"); true },
1676+
(false, _) => { false },
1677+
}
1678+
}

0 commit comments

Comments
 (0)