Merge pull request #2513 from rtsuk/master

Restore cargo fmt behavior in workspaces
This commit is contained in:
Nick Cameron 2018-03-12 11:26:12 +13:00 committed by GitHub
commit f5ebcd922e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View file

@ -45,7 +45,7 @@ log = "0.4"
env_logger = "0.5"
getopts = "0.2"
derive-new = "0.5"
cargo_metadata = "0.5"
cargo_metadata = "0.5.1"
rustc-ap-syntax = "60.0.0"
rustc-ap-rustc_errors = "60.0.0"

View file

@ -249,12 +249,18 @@ fn get_targets(strategy: &CargoFmtStrategy) -> Result<HashSet<Target>, io::Error
fn get_targets_root_only(targets: &mut HashSet<Target>) -> Result<(), io::Error> {
let metadata = get_cargo_metadata(None)?;
let current_dir = env::current_dir()?.canonicalize()?;
let current_dir_manifest = current_dir.join("Cargo.toml");
let workspace_root_path = PathBuf::from(&metadata.workspace_root).canonicalize()?;
let in_workspace_root = workspace_root_path == current_dir;
for package in metadata.packages {
if in_workspace_root || PathBuf::from(&package.manifest_path) == current_dir_manifest {
for target in package.targets {
targets.insert(Target::from_target(&target));
}
}
}
Ok(())
}