Fix for issue #1942 'cargo run fails if called from executable folder'
authormseri <mseri@users.noreply.github.com>
Wed, 26 Aug 2015 14:37:07 +0000 (15:37 +0100)
committermseri <mseri@users.noreply.github.com>
Wed, 26 Aug 2015 14:37:07 +0000 (15:37 +0100)
It maybe a hacky way but I think that changing `util::without_prefix` is a bad approach. Maybe modify `process.build_command` could be another possible approach.

src/cargo/ops/cargo_run.rs

index 79bd505c5a1add15d31782c08d1feed88c1cfea2..6b9d285d7b5df045eebaad7abaebea75d30edc9e 100644 (file)
@@ -48,7 +48,9 @@ pub fn run(manifest_path: &Path,
     let compile = try!(ops::compile(manifest_path, options));
     let exe = &compile.binaries[0];
     let exe = match util::without_prefix(&exe, config.cwd()) {
-        Some(path) => path,
+        Some(path) => if path.as_os_str() == path.file_name().unwrap() { &**exe } 
+                      else { path }, // workaround for being able to use
+                                     // `cargo run` from the executable path itself
         None => &**exe,
     };
     let mut process = try!(compile.target_process(exe, &root))