Patch cargo script root files back to manifest

This commit is contained in:
Lukas Wirth 2024-04-19 15:50:27 +02:00
parent 0b24599cf9
commit 46f05543a2
4 changed files with 26 additions and 16 deletions

View file

@ -379,11 +379,12 @@ impl CargoWorkspace {
let is_local = source.is_none();
let is_member = ws_members.contains(&id);
let manifest = AbsPathBuf::assert(manifest_path);
let pkg = packages.alloc(PackageData {
id: id.repr.clone(),
name,
version,
manifest: AbsPathBuf::assert(manifest_path).try_into().unwrap(),
manifest: manifest.clone().try_into().unwrap(),
targets: Vec::new(),
is_local,
is_member,
@ -406,11 +407,22 @@ impl CargoWorkspace {
for meta_tgt in meta_targets {
let cargo_metadata::Target { name, kind, required_features, src_path, .. } =
meta_tgt;
let kind = TargetKind::new(&kind);
let tgt = targets.alloc(TargetData {
package: pkg,
name,
root: AbsPathBuf::assert(src_path),
kind: TargetKind::new(&kind),
root: if kind == TargetKind::Bin
&& manifest.extension().is_some_and(|ext| ext == "rs")
{
// cargo strips the script part of a cargo script away and places the
// modified manifest file into a special target dir which is then used as
// the source path. We don't want that, we want the original here so map it
// back
manifest.clone()
} else {
AbsPathBuf::assert(src_path)
},
kind,
required_features,
});
pkg_data.targets.push(tgt);

View file

@ -437,7 +437,7 @@ impl ProjectWorkspace {
detached_files: Vec<AbsPathBuf>,
config: &CargoConfig,
) -> Vec<anyhow::Result<ProjectWorkspace>> {
dbg!(detached_files
detached_files
.into_iter()
.map(|detached_file| {
let dir = detached_file
@ -508,7 +508,7 @@ impl ProjectWorkspace {
cargo_script,
})
})
.collect())
.collect()
}
/// Runs the build scripts for this [`ProjectWorkspace`].
@ -822,7 +822,7 @@ impl ProjectWorkspace {
} => (
if let Some(cargo) = cargo_script {
cargo_to_crate_graph(
load,
&mut |path| load(path),
None,
cargo,
sysroot.as_ref().ok(),

View file

@ -718,9 +718,7 @@ pub fn ws_to_crate_graph(
let mut toolchains = Vec::default();
let e = Err(Arc::from("missing layout"));
for ws in workspaces {
dbg!(ws);
let (other, mut crate_proc_macros) = ws.to_crate_graph(&mut load, extra_env);
dbg!(&other);
let num_layouts = layouts.len();
let num_toolchains = toolchains.len();
let (ProjectWorkspace::Cargo { toolchain, target_layout, .. }

View file

@ -139,10 +139,10 @@ version = "0.1.0"
pub struct SpecialHashMap2;
//- /src/lib.rs
#!/usr/bin/env -S cargo +nightly -Zscript
//! ---cargo
//! [dependencies]
//! dependency = { path = "../dependency" }
//! ---
---cargo
[dependencies]
dependency = { path = "../dependency" }
---
use dependency::Spam;
use dependency2::Spam;
"#,
@ -178,10 +178,10 @@ use dependency2::Spam;
server.write_file_and_save(
"src/lib.rs",
r#"#!/usr/bin/env -S cargo +nightly -Zscript
//! ---cargo
//! [dependencies]
//! dependency2 = { path = "../dependency2" }
//! ---
---cargo
[dependencies]
dependency2 = { path = "../dependency2" }
---
use dependency::Spam;
use dependency2::Spam;
"#