From 6999db6f89c78e89083c41c252bf0476b644a6f9 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 12 Apr 2018 00:04:58 +0200 Subject: [PATCH] Error out early on empty targets --- src/cargo/ops/cargo_clean.rs | 2 +- src/cargo/ops/cargo_compile.rs | 2 +- src/cargo/ops/cargo_rustc/layout.rs | 2 +- src/cargo/ops/cargo_rustc/mod.rs | 11 ++++++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 035999de2..cf1923ae7 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -83,7 +83,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> { } } - let mut build_config = BuildConfig::new(&opts.config.rustc()?.host, &opts.target); + let mut build_config = BuildConfig::new(&opts.config.rustc()?.host, &opts.target)?; build_config.release = opts.release; let mut cx = Context::new( ws, diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 83a303b06..e5b0f8132 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -857,7 +857,7 @@ fn scrape_build_config( let jobs = jobs.or(cfg_jobs).unwrap_or(::num_cpus::get() as u32); let cfg_target = config.get_string("build.target")?.map(|s| s.val); let target = target.or(cfg_target); - let mut base = ops::BuildConfig::new(&config.rustc()?.host, &target); + let mut base = ops::BuildConfig::new(&config.rustc()?.host, &target)?; base.jobs = jobs; base.host = scrape_target_config(config, &base.host_triple)?; base.target = match target.as_ref() { diff --git a/src/cargo/ops/cargo_rustc/layout.rs b/src/cargo/ops/cargo_rustc/layout.rs index 52af1defa..c29b55768 100644 --- a/src/cargo/ops/cargo_rustc/layout.rs +++ b/src/cargo/ops/cargo_rustc/layout.rs @@ -92,7 +92,7 @@ impl Layout { if let Some(triple) = triple { path.push(Path::new(triple) .file_stem() - .ok_or_else(|| format_err!("target was empty"))?); + .ok_or_else(|| format_err!("invalid target"))?); } path.push(dest); Layout::at(ws.config(), path) diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 6e4785982..02efdde70 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -77,13 +77,18 @@ pub struct BuildConfig { } impl BuildConfig { - pub fn new(host_triple: &str, requested_target: &Option) -> BuildConfig { - BuildConfig { + pub fn new(host_triple: &str, requested_target: &Option) -> CargoResult { + if let Some(ref s) = *requested_target { + if s.trim().is_empty() { + bail!("target was empty") + } + } + Ok(BuildConfig { host_triple: host_triple.to_string(), requested_target: (*requested_target).clone(), jobs: 1, ..Default::default() - } + }) } } -- 2.30.2