Skip to content

Commit

Permalink
Work-around child processes being blocked on piped output.
Browse files Browse the repository at this point in the history
See #50.
  • Loading branch information
DanielKeep committed Oct 29, 2017
1 parent e6992ae commit c14436c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 7 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ use rustc_version::{version_matches};
fn main() {
println!("cargo:rerun-if-changed=build.rs");

/*
Environment might suffer from <https://github.com/DanielKeep/cargo-script/issues/50>.
*/
if cfg!(windows) {
println!("cargo:rustc-cfg=issue_50");
}

/*
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.
Expand Down
26 changes: 25 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,16 @@ where P: AsRef<Path> {
let cargo_ver = try!(cargo_version()
.err_tag("could not determine target filename"));

let exe_path = if cargo_ver < *VER_JSON_MSGS {
let mut use_guess = false;
use_guess |= work_around_issue_50();
use_guess |= if cargo_ver < *VER_JSON_MSGS {
trace!(".. cargo {:?} is too old to support JSON output", cargo_ver);
true
} else {
false
};

let exe_path = if use_guess {
try!(cargo_target_by_guess(input, use_bincache, pkg_path.as_ref(), meta))
} else {
try!(cargo_target_by_message(input, manifest, use_bincache, meta))
Expand Down Expand Up @@ -1652,3 +1661,18 @@ fn cargo_version() -> Result<Version> {
Ok(try!(Version::parse(ver.as_str())
.map_err(Box::new)))
}

/**
Do we need to work around [issue #50](https://github.com/DanielKeep/cargo-script/issues/50)?
Sometimes, `cargo-script` will hang when trying to read the JSON output of `cargo build`.
*/
fn work_around_issue_50() -> bool {
let suffers = cfg!(issue_50);
let ignored = std::env::var_os("CARGO_SCRIPT_IGNORE_ISSUE_50").is_some();
match (suffers, ignored) {
(true, true) => { trace!(".. issue 50 relevant, but ignored"); false },
(true, false) => { trace!(".. working around issue 50"); true },
(false, _) => { false },
}
}

0 comments on commit c14436c

Please sign in to comment.