Skip to content

Commit b750c2b

Browse files
authored
Merge pull request #31 from jyn514/close-to-home
Don't normalize commands
2 parents de7e3e7 + aaf1b56 commit b750c2b

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- New method `Toolchain::remove_component`
1111

12+
### Fixed
13+
14+
- When passed a global command with the same name as a file in the current directory,
15+
Rustwide will now execute the global command instead of the file.
16+
1217
## [0.8.0] - 2020-06-05
1318

1419
### Added

src/cmd/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,19 +370,22 @@ impl<'w, 'pl> Command<'w, 'pl> {
370370
)
371371
} else {
372372
let (binary, managed_by_rustwide) = match self.binary {
373+
// global paths should never be normalized
373374
Binary::Global(path) => (path, false),
374-
Binary::ManagedByRustwide(path) => (
375-
self.workspace
375+
Binary::ManagedByRustwide(path) => {
376+
let binary = self
377+
.workspace
376378
.expect("calling rustwide bins without a workspace is not supported")
377379
.cargo_home()
378380
.join("bin")
379-
.join(exe_suffix(path.as_os_str())),
380-
true,
381-
),
381+
.join(exe_suffix(path.as_os_str()));
382+
// `cargo_home()` might a relative path
383+
(crate::utils::normalize_path(&binary), true)
384+
}
382385
Binary::__NonExaustive => panic!("do not create __NonExaustive variants manually"),
383386
};
384-
let mut cmd = AsyncCommand::new(crate::utils::normalize_path(&binary));
385387

388+
let mut cmd = AsyncCommand::new(&binary);
386389
cmd.args(&self.args);
387390

388391
if managed_by_rustwide {

tests/issue_30.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use failure::Error;
2+
use rustwide::cmd::Command;
3+
4+
mod utils;
5+
6+
#[test]
7+
fn run_binary_with_same_name_as_file() -> Result<(), Error> {
8+
use std::fs;
9+
10+
let tmpdir = tempfile::tempdir()?;
11+
std::env::set_current_dir(&tmpdir)?;
12+
fs::write("true", b"foobar")?;
13+
let workspace = crate::utils::init_workspace()?;
14+
Command::new(&workspace, "true").run()?;
15+
16+
Ok(())
17+
}

0 commit comments

Comments
 (0)