Skip to content

Commit cb06018

Browse files
committed
Fixup rebase
1 parent c77dd8d commit cb06018

File tree

6 files changed

+34
-20
lines changed

6 files changed

+34
-20
lines changed

crate_universe/src/context/crate_context.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ use serde::{Deserialize, Serialize};
88

99
use crate::config::{AliasRule, CrateId, GenBinaries};
1010
use crate::metadata::{
11-
CrateAnnotation, Dependency, PairedExtras, SourceAnnotation, TreeResolverMetadata,
11+
CrateAnnotation, Dependency, MetadataAnnotation, PairedExtras, SourceAnnotation,
12+
TreeResolverMetadata,
1213
};
1314
use crate::select::Select;
1415
use crate::splicing::WorkspaceMetadata;
1516
use crate::utils::sanitize_module_name;
16-
use crate::utils::starlark::{ Glob, GlobOrLabels, Label, SelectList };
17+
use crate::utils::starlark::{Glob, GlobOrLabels, Label, Repository};
1718

1819
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
1920
pub struct CrateDependency {
@@ -874,7 +875,7 @@ fn get_attributes(
874875
TargetAttributes {
875876
crate_name,
876877
crate_root,
877-
srcs: Glob::new_rust_srcs().into(),
878+
srcs: Glob::new_rust_srcs(true).into(),
878879
compile_data: None,
879880
}
880881
} else {
@@ -890,14 +891,14 @@ fn get_attributes(
890891
println!(
891892
"'crate_root', 'srcs', 'compile_data', and (if necessary) 'build_script_crate_root'"
892893
);
893-
let srcs = GlobOrLabels::Labels(vec![Label {
894-
repository: None,
895-
package: Some(pkg.clone()),
894+
let srcs = GlobOrLabels::Labels(vec![Label::Absolute {
895+
repository: Repository::Local,
896+
package: pkg.clone(),
896897
target: "srcs".to_string(),
897898
}]);
898-
let compile_data = Some(GlobOrLabels::Labels(vec![Label {
899-
repository: None,
900-
package: Some(pkg.clone()),
899+
let compile_data = Some(GlobOrLabels::Labels(vec![Label::Absolute {
900+
repository: Repository::Local,
901+
package: pkg.clone(),
901902
target: "compile_data".to_string(),
902903
}]));
903904

@@ -1159,7 +1160,7 @@ mod test {
11591160
BTreeSet::from([Rule::Library(TargetAttributes {
11601161
crate_name: "sysinfo".to_owned(),
11611162
crate_root: Some("src/lib.rs".to_owned()),
1162-
srcs: Glob::new_rust_srcs(!are_sources_present),
1163+
srcs: Glob::new_rust_srcs(!are_sources_present).into(),
11631164
compile_data: None,
11641165
})]),
11651166
);
@@ -1186,7 +1187,7 @@ mod test {
11861187

11871188
let context = CrateContext::new(
11881189
crate_annotation,
1189-
&annotations.metadata.packages,
1190+
&annotations.metadata,
11901191
&annotations.lockfile.crates,
11911192
&annotations.pairred_extras,
11921193
&annotations.metadata.workspace_metadata.tree_metadata,
@@ -1318,7 +1319,7 @@ mod test {
13181319

13191320
let context = CrateContext::new(
13201321
crate_annotation,
1321-
&annotations.metadata.packages,
1322+
&annotations.metadata,
13221323
&annotations.lockfile.crates,
13231324
&annotations.pairred_extras,
13241325
&annotations.metadata.workspace_metadata.tree_metadata,

crate_universe/src/metadata/metadata_annotation.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ impl LockfileAnnotation {
213213
workspace_metadata: &WorkspaceMetadata,
214214
) -> Result<SourceAnnotation> {
215215
let pkg = &metadata[&node.id];
216+
println!("{} : {}", pkg.name, pkg.id.repr);
216217

217218
// Locate the matching lock package for the current crate
218219
let lock_pkg = match cargo_meta_pkg_to_locked_pkg(pkg, &lockfile.packages) {
@@ -239,7 +240,19 @@ impl LockfileAnnotation {
239240
patches: None,
240241
})
241242
}
242-
None => return Ok(SourceAnnotation::Path),
243+
None => {
244+
// this is a hack to determine whether a dep is patched. cargo
245+
// metadata doesn't expose that info other than as part of the
246+
// technically opaque id field
247+
if pkg.id.repr.starts_with("path+file://") {
248+
return Ok(SourceAnnotation::Path);
249+
}
250+
bail!(
251+
"The package '{:?} {:?}' has no source info so no annotation can be made",
252+
lock_pkg.name,
253+
lock_pkg.version
254+
);
255+
}
243256
},
244257
};
245258

crate_universe/src/rendering.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl Renderer {
455455
platforms,
456456
),
457457
compile_data: {
458-
make_data(
458+
let mut data = make_data(
459459
platforms,
460460
Default::default(),
461461
attrs
@@ -657,7 +657,7 @@ impl Renderer {
657657
) -> Result<CommonAttrs> {
658658
Ok(CommonAttrs {
659659
compile_data: {
660-
make_data(
660+
let mut data = make_data(
661661
platforms,
662662
krate.common_attrs.compile_data_glob.clone(),
663663
krate.common_attrs.compile_data.clone(),

crate_universe/src/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) fn sanitize_repository_name(name: &str) -> String {
2323

2424
/// Vendored crates are generated by cargo itself in `src/metadata.rs` in the
2525
/// `VendorGenerator::generate()` method. This means that the semver metadata will
26-
/// always contain a (+) symbol, which is not compatible with bazel's labels.
26+
/// always contain a (+) symbol, which is not compatible with bazel's labels.
2727
/// This function will rename the cargo vendor generated file paths to be compatible with bazel
2828
/// labels by simply replacing the (+) with a (-). If this file is called by any other cli mod,
2929
/// it just simply joins the out dir to the path

crate_universe/src/utils/starlark/glob.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Serialize for GlobOrLabels {
149149
impl GlobOrLabels {
150150
pub fn is_empty(&self) -> bool {
151151
match self {
152-
Self::Glob(g) => g.is_empty(),
152+
Self::Glob(g) => !g.has_any_include(),
153153
Self::Labels(l) => l.is_empty(),
154154
}
155155
}

crate_universe/src/utils/starlark/serialize.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl Serialize for ExportsFiles {
130130

131131
impl Data {
132132
pub(crate) fn is_empty(&self) -> bool {
133-
self.glob.has_any_include() && self.select.is_empty()
133+
self.glob.is_empty() && self.select.is_empty()
134134
}
135135
}
136136

@@ -140,10 +140,10 @@ impl Serialize for Data {
140140
S: Serializer,
141141
{
142142
let mut plus = serializer.serialize_tuple_struct("+", MULTILINE)?;
143-
if !self.glob.has_any_include() {
143+
if !self.glob.is_empty() {
144144
plus.serialize_field(&self.glob)?;
145145
}
146-
if !self.select.is_empty() || self.glob.has_any_include() {
146+
if !self.select.is_empty() || self.glob.is_empty() {
147147
plus.serialize_field(&self.select)?;
148148
}
149149
plus.end()

0 commit comments

Comments
 (0)