Skip to content

Don't normalize commands #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- New method `Toolchain::remove_component`

### Fixed

- When passed a global command with the same name as a file in the current directory,
Rustwide will now execute the global command instead of the file.

## [0.8.0] - 2020-06-05

### Added
Expand Down
15 changes: 9 additions & 6 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,19 +370,22 @@ impl<'w, 'pl> Command<'w, 'pl> {
)
} else {
let (binary, managed_by_rustwide) = match self.binary {
// global paths should never be normalized
Binary::Global(path) => (path, false),
Binary::ManagedByRustwide(path) => (
self.workspace
Binary::ManagedByRustwide(path) => {
let binary = self
.workspace
.expect("calling rustwide bins without a workspace is not supported")
.cargo_home()
.join("bin")
.join(exe_suffix(path.as_os_str())),
true,
),
.join(exe_suffix(path.as_os_str()));
// `cargo_home()` might a relative path
(crate::utils::normalize_path(&binary), true)
}
Binary::__NonExaustive => panic!("do not create __NonExaustive variants manually"),
};
let mut cmd = AsyncCommand::new(crate::utils::normalize_path(&binary));

let mut cmd = AsyncCommand::new(&binary);
cmd.args(&self.args);

if managed_by_rustwide {
Expand Down
17 changes: 17 additions & 0 deletions tests/issue_30.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use failure::Error;
use rustwide::cmd::Command;

mod utils;

#[test]
fn run_binary_with_same_name_as_file() -> Result<(), Error> {
use std::fs;

let tmpdir = tempfile::tempdir()?;
std::env::set_current_dir(&tmpdir)?;
fs::write("true", b"foobar")?;
let workspace = crate::utils::init_workspace()?;
Command::new(&workspace, "true").run()?;

Ok(())
}