Merge pull request #21272 from ShoyuVanilla/sysroot-target
fix: Prefix json target file with workspace root for sysroot metadata
This commit is contained in:
commit
6ec08dc647
1 changed files with 20 additions and 1 deletions
|
|
@ -391,6 +391,7 @@ impl ProjectWorkspace {
|
|||
sysroot.load_workspace(
|
||||
&RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config(
|
||||
config,
|
||||
workspace_dir,
|
||||
&targets,
|
||||
toolchain.clone(),
|
||||
)),
|
||||
|
|
@ -500,6 +501,7 @@ impl ProjectWorkspace {
|
|||
sysroot.load_workspace(
|
||||
&RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config(
|
||||
config,
|
||||
project_json.project_root(),
|
||||
&targets,
|
||||
toolchain.clone(),
|
||||
)),
|
||||
|
|
@ -555,6 +557,7 @@ impl ProjectWorkspace {
|
|||
let loaded_sysroot = sysroot.load_workspace(
|
||||
&RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config(
|
||||
config,
|
||||
dir,
|
||||
&targets,
|
||||
toolchain.clone(),
|
||||
)),
|
||||
|
|
@ -1907,12 +1910,28 @@ fn add_dep_inner(graph: &mut CrateGraphBuilder, from: CrateBuilderId, dep: Depen
|
|||
|
||||
fn sysroot_metadata_config(
|
||||
config: &CargoConfig,
|
||||
workspace_root: &AbsPath,
|
||||
targets: &[String],
|
||||
toolchain_version: Option<Version>,
|
||||
) -> CargoMetadataConfig {
|
||||
// If the target is a JSON path, prefix it with workspace root directory.
|
||||
// Since `cargo metadata` command for sysroot is run inside sysroots dir, it may fail to
|
||||
// locate the target file if it is given as a relative path.
|
||||
let targets = targets
|
||||
.iter()
|
||||
.map(|target| {
|
||||
if target.ends_with(".json") {
|
||||
// If `target` is an absolute path, this will replace the whole path.
|
||||
workspace_root.join(target).to_string()
|
||||
} else {
|
||||
target.to_owned()
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
CargoMetadataConfig {
|
||||
features: Default::default(),
|
||||
targets: targets.to_vec(),
|
||||
targets,
|
||||
extra_args: Default::default(),
|
||||
extra_env: config.extra_env.clone(),
|
||||
toolchain_version,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue