diff --git a/crate_universe/src/context/crate_context.rs b/crate_universe/src/context/crate_context.rs index 80b8c5d0e1..6de4bb4af7 100644 --- a/crate_universe/src/context/crate_context.rs +++ b/crate_universe/src/context/crate_context.rs @@ -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 { @@ -874,7 +875,7 @@ fn get_attributes( TargetAttributes { crate_name, crate_root, - srcs: Glob::new_rust_srcs().into(), + srcs: Glob::new_rust_srcs(true).into(), compile_data: None, } } else { @@ -890,14 +891,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(), }])); @@ -1159,7 +1160,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, })]), ); @@ -1186,7 +1187,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, @@ -1318,7 +1319,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, diff --git a/crate_universe/src/metadata/metadata_annotation.rs b/crate_universe/src/metadata/metadata_annotation.rs index 85ac9dc193..e390e39814 100644 --- a/crate_universe/src/metadata/metadata_annotation.rs +++ b/crate_universe/src/metadata/metadata_annotation.rs @@ -213,6 +213,7 @@ impl LockfileAnnotation { workspace_metadata: &WorkspaceMetadata, ) -> Result { let pkg = &metadata[&node.id]; + println!("{} : {}", pkg.name, pkg.id.repr); // Locate the matching lock package for the current crate let lock_pkg = match cargo_meta_pkg_to_locked_pkg(pkg, &lockfile.packages) { @@ -239,7 +240,19 @@ impl LockfileAnnotation { patches: None, }) } - None => return Ok(SourceAnnotation::Path), + None => { + // this is a hack to determine whether a dep is patched. cargo + // metadata doesn't expose that info other than as part of the + // technically opaque id field + if pkg.id.repr.starts_with("path+file://") { + return Ok(SourceAnnotation::Path); + } + bail!( + "The package '{:?} {:?}' has no source info so no annotation can be made", + lock_pkg.name, + lock_pkg.version + ); + } }, }; diff --git a/crate_universe/src/rendering.rs b/crate_universe/src/rendering.rs index 237d58c588..38b56c6785 100644 --- a/crate_universe/src/rendering.rs +++ b/crate_universe/src/rendering.rs @@ -455,7 +455,7 @@ impl Renderer { platforms, ), compile_data: { - make_data( + let mut data = make_data( platforms, Default::default(), attrs @@ -657,7 +657,7 @@ impl Renderer { ) -> Result { Ok(CommonAttrs { compile_data: { - make_data( + let mut data = make_data( platforms, krate.common_attrs.compile_data_glob.clone(), krate.common_attrs.compile_data.clone(), diff --git a/crate_universe/src/utils.rs b/crate_universe/src/utils.rs index d625e0572c..f4b4714365 100644 --- a/crate_universe/src/utils.rs +++ b/crate_universe/src/utils.rs @@ -23,7 +23,7 @@ pub(crate) fn sanitize_repository_name(name: &str) -> String { /// Vendored crates are generated by cargo itself in `src/metadata.rs` in the /// `VendorGenerator::generate()` method. This means that the semver metadata will -/// always contain a (+) symbol, which is not compatible with bazel's labels. +/// always contain a (+) symbol, which is not compatible with bazel's labels. /// This function will rename the cargo vendor generated file paths to be compatible with bazel /// labels by simply replacing the (+) with a (-). If this file is called by any other cli mod, /// it just simply joins the out dir to the path diff --git a/crate_universe/src/utils/starlark/glob.rs b/crate_universe/src/utils/starlark/glob.rs index c3cfa49ce2..af676bbb63 100644 --- a/crate_universe/src/utils/starlark/glob.rs +++ b/crate_universe/src/utils/starlark/glob.rs @@ -149,7 +149,7 @@ impl Serialize for GlobOrLabels { impl GlobOrLabels { pub fn is_empty(&self) -> bool { match self { - Self::Glob(g) => g.is_empty(), + Self::Glob(g) => !g.has_any_include(), Self::Labels(l) => l.is_empty(), } } diff --git a/crate_universe/src/utils/starlark/serialize.rs b/crate_universe/src/utils/starlark/serialize.rs index b6dc7d8887..581a71ebac 100644 --- a/crate_universe/src/utils/starlark/serialize.rs +++ b/crate_universe/src/utils/starlark/serialize.rs @@ -130,7 +130,7 @@ impl Serialize for ExportsFiles { impl Data { pub(crate) fn is_empty(&self) -> bool { - self.glob.has_any_include() && self.select.is_empty() + self.glob.is_empty() && self.select.is_empty() } } @@ -140,10 +140,10 @@ impl Serialize for Data { S: Serializer, { let mut plus = serializer.serialize_tuple_struct("+", MULTILINE)?; - if !self.glob.has_any_include() { + if !self.glob.is_empty() { plus.serialize_field(&self.glob)?; } - if !self.select.is_empty() || self.glob.has_any_include() { + if !self.select.is_empty() || self.glob.is_empty() { plus.serialize_field(&self.select)?; } plus.end()