mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Merge pull request #2513 from rtsuk/master
Restore cargo fmt behavior in workspaces
This commit is contained in:
commit
f5ebcd922e
@ -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"
|
||||
|
||||
|
@ -249,10 +249,16 @@ 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 {
|
||||
for target in package.targets {
|
||||
targets.insert(Target::from_target(&target));
|
||||
if in_workspace_root || PathBuf::from(&package.manifest_path) == current_dir_manifest {
|
||||
for target in package.targets {
|
||||
targets.insert(Target::from_target(&target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user