Skip to content

Commit

Permalink
Fixup rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
P1n3appl3 committed Oct 31, 2024
1 parent c77dd8d commit cb06018
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
25 changes: 13 additions & 12 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 @@ -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 {
Expand All @@ -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(),
}]));

Expand Down Expand Up @@ -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,
})]),
);
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 14 additions & 1 deletion crate_universe/src/metadata/metadata_annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ impl LockfileAnnotation {
workspace_metadata: &WorkspaceMetadata,
) -> Result<SourceAnnotation> {
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) {
Expand All @@ -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
);
}
},
};

Expand Down
4 changes: 2 additions & 2 deletions crate_universe/src/rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl Renderer {
platforms,
),
compile_data: {
make_data(
let mut data = make_data(
platforms,
Default::default(),
attrs
Expand Down Expand Up @@ -657,7 +657,7 @@ impl Renderer {
) -> Result<CommonAttrs> {
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(),
Expand Down
2 changes: 1 addition & 1 deletion crate_universe/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crate_universe/src/utils/starlark/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand Down
6 changes: 3 additions & 3 deletions crate_universe/src/utils/starlark/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand All @@ -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()
Expand Down

0 comments on commit cb06018

Please sign in to comment.