Skip to content

Commit 9a78b05

Browse files
committed
fix bindeps not being added to repo
1 parent 5277d3f commit 9a78b05

File tree

7 files changed

+27
-27
lines changed

7 files changed

+27
-27
lines changed

crate_universe/src/api/lockfile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ mod test {
174174
name: String::from("anyhow"),
175175
version: Version::new(1, 0, 69),
176176
},
177-
target: String::from("anyhow"),
177+
target: Some(String::from("anyhow")),
178178
alias: None,
179179
local_path: None,
180180
},
@@ -183,7 +183,7 @@ mod test {
183183
name: String::from("reqwest"),
184184
version: Version::new(0, 11, 14),
185185
},
186-
target: String::from("reqwest"),
186+
target: Some(String::from("reqwest")),
187187
alias: None,
188188
local_path: None,
189189
},

crate_universe/src/context/crate_context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct CrateDependency {
2424

2525
/// The target name of the dependency. Note this may differ from the
2626
/// dependency's package name in cases such as build scripts.
27-
pub target: String,
27+
pub target: Option<String>,
2828

2929
/// Some dependencies are assigned aliases. This is tracked here
3030
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -533,7 +533,7 @@ impl CrateContext {
533533
// Unfortunately, The package graph and resolve graph of cargo metadata have different representations
534534
// for the crate names (resolve graph sanitizes names to match module names) so to get the rest of this
535535
// content to align when rendering, the dependency target needs to be explicitly sanitized.
536-
let target = sanitize_module_name(&dep.target_name);
536+
let target = dep.target_name.as_deref().map(sanitize_module_name);
537537
let pkg = &metadata.packages[&metadata.package_map[&dep.id]];
538538
if metadata.workspace_members.contains(&pkg.id) {
539539
return None;
@@ -663,7 +663,7 @@ impl CrateContext {
663663
common_attrs.deps.insert(
664664
CrateDependency {
665665
id: crate_id.clone(),
666-
target: target.crate_name.clone(),
666+
target: Some(target.crate_name.clone()),
667667
alias: None,
668668
local_path: match source_annotations.get(&package.id) {
669669
Some(SourceAnnotation::Path { path }) => Some(path.clone()),

crate_universe/src/context/platforms.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ mod test {
149149
deps.insert(
150150
CrateDependency {
151151
id: CrateId::new("mock_crate_b".to_owned(), VERSION_ZERO_ONE_ZERO),
152-
target: "mock_crate_b".to_owned(),
152+
target: Some("mock_crate_b".to_owned()),
153153
alias: None,
154154
local_path: None,
155155
},
@@ -210,7 +210,7 @@ mod test {
210210
deps.insert(
211211
CrateDependency {
212212
id: CrateId::new("mock_crate_b".to_owned(), VERSION_ZERO_ONE_ZERO),
213-
target: "mock_crate_b".to_owned(),
213+
target: Some("mock_crate_b".to_owned()),
214214
alias: None,
215215
local_path: None,
216216
},
@@ -299,7 +299,7 @@ mod test {
299299
deps.insert(
300300
CrateDependency {
301301
id: CrateId::new("mock_crate_b".to_owned(), VERSION_ZERO_ONE_ZERO),
302-
target: "mock_crate_b".to_owned(),
302+
target: Some("mock_crate_b".to_owned()),
303303
alias: None,
304304
local_path: None,
305305
},
@@ -368,7 +368,7 @@ mod test {
368368
deps.insert(
369369
CrateDependency {
370370
id: CrateId::new("mock_crate_b".to_owned(), VERSION_ZERO_ONE_ZERO),
371-
target: "mock_crate_b".to_owned(),
371+
target: Some("mock_crate_b".to_owned()),
372372
alias: None,
373373
local_path: None,
374374
},

crate_universe/src/metadata/cargo_resolver.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub(crate) struct Dependency {
133133
pub(crate) id: CrateId,
134134

135135
/// The library target name of the dependency.
136-
pub(crate) target_name: String,
136+
pub(crate) target_name: Option<String>,
137137

138138
/// The alias for the dependency from the perspective of the current package
139139
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -555,15 +555,12 @@ impl<'a> CargoResolver<'a> {
555555

556556
for ((dep_id, _, kind), dep) in &package.deps {
557557
let dep_pkg = &self.dependency_resolve[dep_id];
558-
if dep_pkg.library_target_name.is_none() {
559-
continue;
560-
}
561558
for (alias, optional) in &dep.aliases_optional {
562559
let dependency = Dependency {
563560
features: dep.features.iter().map(|f| f.to_string()).collect(),
564561
alias: alias.map(|a| a.replace("-", "_")),
565562
id: CrateId::from(dep_pkg.package),
566-
target_name: dep_pkg.library_target_name.unwrap().to_string(),
563+
target_name: dep_pkg.library_target_name.map(|t| t.to_string()),
567564
optional: *optional,
568565
platforms: dep.platforms.iter().copied().cloned().collect(),
569566
};

crate_universe/src/rendering.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -907,11 +907,11 @@ impl Renderer {
907907
let mut aliases: Select<BTreeMap<Label, String>> = Select::default();
908908
for dependency_select in dependency_selects.iter() {
909909
for (configuration, dependency) in dependency_select.items() {
910-
if let Some(alias) = &dependency.alias {
910+
if let (Some(alias), Some(target)) = (&dependency.alias, &dependency.target) {
911911
let label = self.crate_label(
912912
&dependency.id.name,
913913
&dependency.id.version.to_string(),
914-
&dependency.target,
914+
target,
915915
);
916916
aliases.insert((label, alias.clone()), configuration.clone());
917917
}
@@ -926,9 +926,12 @@ impl Renderer {
926926
extra_deps: Select<BTreeSet<Label>>,
927927
) -> Select<BTreeSet<Label>> {
928928
Select::merge(
929-
deps.map(|dep| match dep.local_path {
930-
Some(path) => Label::from_str(&format!("//{}:{}", path, &dep.target)).unwrap(),
931-
_ => self.crate_label(&dep.id.name, &dep.id.version.to_string(), &dep.target),
929+
deps.filter_map(|dep| {
930+
let target = dep.target.as_deref()?;
931+
Some(match dep.local_path {
932+
Some(path) => Label::from_str(&format!("//{}:{}", path, target)).unwrap(),
933+
_ => self.crate_label(&dep.id.name, &dep.id.version.to_string(), target),
934+
})
932935
}),
933936
extra_deps,
934937
)
@@ -2122,7 +2125,7 @@ mod test {
21222125
common_attrs: CommonAttributes {
21232126
deps: Select::from_value(BTreeSet::from([CrateDependency {
21242127
id: crate_id,
2125-
target: "target".into(),
2128+
target: Some("target".into()),
21262129
// this is identical to what we have in the `name` attribute
21272130
// which creates conflict in `render_module_build_file`
21282131
alias: Some("mock_crate".into()),
@@ -2257,13 +2260,13 @@ mod test {
22572260
// These two dependencies are identical, except one is aliased.
22582261
CrateDependency {
22592262
id: dependency_id.clone(),
2260-
target: "my_dependency".into(),
2263+
target: Some("my_dependency".into()),
22612264
alias: None,
22622265
local_path: None,
22632266
},
22642267
CrateDependency {
22652268
id: dependency_id,
2266-
target: "my_dependency".into(),
2269+
target: Some("my_dependency".into()),
22672270
alias: Some("my_dependency_other".into()),
22682271
local_path: None,
22692272
},

crate_universe/src/rendering/templates/partials/module/deps_map.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{%- macro dep_block(deps, context) -%}
22
{%- for dep in deps %}
3-
{%- if dep.id in context.workspace_members %}{% continue %}}{% endif %}{# Workspace member repositories are not defined, skip adding their labels here #}
3+
{%- if dep.id in context.workspace_members or not dep.target %}{% continue %}}{% endif %}{# Workspace member repositories are not defined, skip adding their labels here #}
44
{%- set crate = context.crates | get(key=dep.id) %}
55
"{{ dep | get(key="alias", default=crate.name) }}": Label("{{ crate_alias(name = crate.name, version = crate.version, target = dep.target) }}"),
66
{%- endfor %}

crate_universe/src/select.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,18 +372,18 @@ impl<T> Select<BTreeSet<T>>
372372
where
373373
T: SelectableOrderedValue,
374374
{
375-
pub(crate) fn map<U, F>(self, func: F) -> Select<BTreeSet<U>>
375+
pub(crate) fn filter_map<U, F>(self, func: F) -> Select<BTreeSet<U>>
376376
where
377377
U: SelectableOrderedValue,
378-
F: Copy + FnMut(T) -> U,
378+
F: Copy + FnMut(T) -> Option<U>,
379379
{
380380
Select {
381-
common: self.common.into_iter().map(func).collect(),
381+
common: self.common.into_iter().filter_map(func).collect(),
382382
selects: self
383383
.selects
384384
.into_iter()
385385
.map(|(configuration, values)| {
386-
(configuration, values.into_iter().map(func).collect())
386+
(configuration, values.into_iter().filter_map(func).collect())
387387
})
388388
.collect(),
389389
}

0 commit comments

Comments
 (0)