Canonicalize paths passed as `--target`
authorPhilipp Oppermann <dev@phil-opp.com>
Thu, 22 Mar 2018 17:53:19 +0000 (18:53 +0100)
committerPhilipp Oppermann <dev@phil-opp.com>
Sun, 25 Mar 2018 10:53:22 +0000 (12:53 +0200)
src/cargo/ops/cargo_compile.rs

index bec0be93e3f7e23782298dce4eb1666e07b718e4..74cc8949aae520d2b140a4a9dd7ce939d54c0a4c 100644 (file)
@@ -24,7 +24,7 @@
 
 use std::collections::{HashMap, HashSet};
 use std::default::Default;
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
 use std::sync::Arc;
 
 use core::{Package, Source, Target};
@@ -32,7 +32,7 @@ use core::{PackageId, PackageIdSpec, Profile, Profiles, TargetKind, Workspace};
 use core::resolver::{Method, Resolve};
 use ops::{self, BuildOutput, DefaultExecutor, Executor};
 use util::config::Config;
-use util::{profile, CargoResult};
+use util::{profile, CargoResult, CargoResultExt};
 
 /// Contains information about how a package should be compiled.
 #[derive(Debug)]
@@ -235,7 +235,17 @@ pub fn compile_ws<'a>(
         ref target_rustc_args,
     } = *options;
 
-    let target = target.clone();
+    let target = match target {
+        &Some(ref target) if target.ends_with(".json") => {
+            let path = Path::new(target)
+                .canonicalize()
+                .chain_err(|| format_err!("Target path {:?} is not a valid file", target))?;
+            Some(path.into_os_string()
+                .into_string()
+                .map_err(|_| format_err!("Target path is not valid unicode"))?)
+        }
+        other => other.clone(),
+    };
 
     if jobs == Some(0) {
         bail!("jobs must be at least 1")