Skip to content

Commit

Permalink
Fixup rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
P1n3appl3 committed Nov 1, 2024
1 parent c77dd8d commit 285c36a
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 119 deletions.
79 changes: 27 additions & 52 deletions crate_universe/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crate_universe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ anyhow = "1.0.75"
camino = "1.1.6"
cargo_metadata = "0.18.1"
cargo_toml = "0.19.2"
cargo-lock = "9.0.0"
cargo-lock = "10.0.0"
cargo-platform = "0.1.4"
cfg-expr = "0.15.5"
clap = { version = "4.3.11", features = ["derive", "env"] }
Expand Down
1 change: 1 addition & 0 deletions crate_universe/src/cli/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub fn vendor(opt: VendorOptions) -> Result<()> {
// Generate a splicer for creating a Cargo workspace manifest
let splicer = Splicer::new(PathBuf::from(temp_dir.as_ref()), splicing_manifest)
.context("Failed to create splicer")?;
// std::mem::forget(temp_dir);

let cargo = Cargo::new(opt.cargo, opt.rustc.clone());

Expand Down
76 changes: 20 additions & 56 deletions crate_universe/src/context/crate_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ use serde::{Deserialize, Serialize};

use crate::config::{AliasRule, CrateId, GenBinaries};
use crate::metadata::{
CrateAnnotation, Dependency, PairedExtras, SourceAnnotation, TreeResolverMetadata,
CrateAnnotation, Dependency, MetadataAnnotation, PairedExtras, SourceAnnotation,
TreeResolverMetadata,
};
use crate::select::Select;
use crate::splicing::WorkspaceMetadata;
use crate::utils::sanitize_module_name;
use crate::utils::starlark::{ Glob, GlobOrLabels, Label, SelectList };
use crate::utils::starlark::{Glob, GlobOrLabels, Label, Repository};

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct CrateDependency {
Expand Down Expand Up @@ -779,55 +780,18 @@ impl CrateContext {
.flat_map(|target| {
let attrs = get_attributes(target, package, workspace, package_root);
target.kind.iter().filter_map(move |kind| {
// Unfortunately, The package graph and resolve graph of cargo metadata have different representations
// for the crate names (resolve graph sanitizes names to match module names) so to get the rest of this
// content to align when rendering, the package target names are always sanitized.
let crate_name = sanitize_module_name(&target.name);

// Locate the crate's root source file relative to the package root normalized for unix
let crate_root = pathdiff::diff_paths(&target.src_path, package_root).map(
// Normalize the path so that it always renders the same regardless of platform
|root| root.to_string_lossy().replace('\\', "/"),
);
let crate_root = crate_root.map(|r| {
if package.id.repr.contains("(path+file://") {
let temp_components = std::env::temp_dir().components().count() + 1;
package_root
.components()
.skip(temp_components)
.collect::<PathBuf>()
.join(r)
.to_string_lossy()
.to_string()
} else {
r
}
});

let attrs = attrs.clone();

// Conditionally check to see if the dependencies is a build-script target
if include_build_scripts && kind == "custom-build" {
return Some(Rule::BuildScript(TargetAttributes {
crate_name,
crate_root,
srcs: Glob::new_rust_srcs(!sources_are_present).into(),
compile_data: attrs.compile_data,
}));
}

// Check to see if the dependencies is a proc-macro target
if kind == "proc-macro" {
Some(Rule::ProcMacro(attrs))
Some(Rule::ProcMacro(attrs.clone()))
} else if ["lib", "rlib"].contains(&kind.as_str()) {
Some(Rule::Library(attrs))
Some(Rule::Library(attrs.clone()))
} else if include_build_scripts && kind == "custom-build" {
let build_script_crate_root = attrs
.crate_root
.clone()
.map(|s| s.replace(":crate_root", ":build_script_crate_root"));
Some(Rule::BuildScript(TargetAttributes {
crate_root: build_script_crate_root,
..attrs
..attrs.clone()
}))
} else if kind == "bin" {
match gen_binaries {
Expand All @@ -837,7 +801,7 @@ impl CrateContext {
.then(|| {
Rule::Binary(TargetAttributes {
crate_name: target.name.clone(),
..attrs
..attrs.clone()
})
})
} else {
Expand Down Expand Up @@ -867,14 +831,14 @@ fn get_attributes(
// Normalize the path so that it always renders the same regardless of platform
|root| root.to_string_lossy().replace('\\', "/"),
);
let local_patch = package.id.repr.contains("(path+file://");
let path_dep = package.id.repr.starts_with("path+file://");
let temp_components = std::env::temp_dir().components().count() + 1;
let real_root: PathBuf = package_root.components().skip(temp_components).collect();
if !local_patch || real_root.as_os_str().is_empty() {
if !path_dep || real_root.as_os_str().is_empty() {
TargetAttributes {
crate_name,
crate_root,
srcs: Glob::new_rust_srcs().into(),
srcs: Glob::new_rust_srcs(true).into(),
compile_data: None,
}
} else {
Expand All @@ -890,14 +854,14 @@ fn get_attributes(
println!(
"'crate_root', 'srcs', 'compile_data', and (if necessary) 'build_script_crate_root'"
);
let srcs = GlobOrLabels::Labels(vec![Label {
repository: None,
package: Some(pkg.clone()),
let srcs = GlobOrLabels::Labels(vec![Label::Absolute {
repository: Repository::Local,
package: pkg.clone(),
target: "srcs".to_string(),
}]);
let compile_data = Some(GlobOrLabels::Labels(vec![Label {
repository: None,
package: Some(pkg.clone()),
let compile_data = Some(GlobOrLabels::Labels(vec![Label::Absolute {
repository: Repository::Local,
package: pkg.clone(),
target: "compile_data".to_string(),
}]));

Expand Down Expand Up @@ -1159,7 +1123,7 @@ mod test {
BTreeSet::from([Rule::Library(TargetAttributes {
crate_name: "sysinfo".to_owned(),
crate_root: Some("src/lib.rs".to_owned()),
srcs: Glob::new_rust_srcs(!are_sources_present),
srcs: Glob::new_rust_srcs(!are_sources_present).into(),
compile_data: None,
})]),
);
Expand All @@ -1186,7 +1150,7 @@ mod test {

let context = CrateContext::new(
crate_annotation,
&annotations.metadata.packages,
&annotations.metadata,
&annotations.lockfile.crates,
&annotations.pairred_extras,
&annotations.metadata.workspace_metadata.tree_metadata,
Expand Down Expand Up @@ -1318,7 +1282,7 @@ mod test {

let context = CrateContext::new(
crate_annotation,
&annotations.metadata.packages,
&annotations.metadata,
&annotations.lockfile.crates,
&annotations.pairred_extras,
&annotations.metadata.workspace_metadata.tree_metadata,
Expand Down
Loading

0 comments on commit 285c36a

Please sign in to comment.