Skip to content

Commit e363df6

Browse files
authored
[path_patching] Shrink size of lockfiles (#3334)
... by only plumbing local patched paths. Change-Id: Idfaf53d93fe11776a70d706726ed4bff0bf5233e
1 parent aa977b2 commit e363df6

20 files changed

+1015
-6887
lines changed

crate_universe/src/api/lockfile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ mod test {
176176
},
177177
target: String::from("anyhow"),
178178
alias: None,
179-
source_annotation: None,
179+
local_path: None,
180180
},
181181
CrateDependency {
182182
id: CrateId {
@@ -185,7 +185,7 @@ mod test {
185185
},
186186
target: String::from("reqwest"),
187187
alias: None,
188-
source_annotation: None,
188+
local_path: None,
189189
},
190190
],
191191
);

crate_universe/src/context/crate_context.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::collections::{BTreeMap, BTreeSet};
44

5+
use camino::Utf8PathBuf;
56
use cargo_metadata::{Node, Package, PackageId};
67
use serde::{Deserialize, Serialize};
78

@@ -26,9 +27,10 @@ pub struct CrateDependency {
2627
#[serde(default, skip_serializing_if = "Option::is_none")]
2728
pub alias: Option<String>,
2829

29-
/// Where to acquire the source of this dependency.
30+
/// Local path of this dependency if provided. This captures local paths from both the
31+
/// [dependencies] table and the [patches] table so they can be used in rendering.
3032
#[serde(default, skip_serializing_if = "Option::is_none")]
31-
pub(crate) source_annotation: Option<SourceAnnotation>,
33+
pub(crate) local_path: Option<Utf8PathBuf>,
3234
}
3335

3436
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Clone)]
@@ -390,7 +392,10 @@ impl CrateContext {
390392
id: CrateId::new(pkg.name.clone(), pkg.version.clone()),
391393
target,
392394
alias: dep.alias,
393-
source_annotation: Some(source_annotations[&dep.package_id].clone()),
395+
local_path: match source_annotations.get(&dep.package_id) {
396+
Some(SourceAnnotation::Path { path }) => Some(path.clone()),
397+
_ => None,
398+
},
394399
}
395400
};
396401

@@ -488,7 +493,10 @@ impl CrateContext {
488493
id: current_crate_id,
489494
target: target.crate_name.clone(),
490495
alias: None,
491-
source_annotation: source_annotations.get(&annotation.node.id).cloned(),
496+
local_path: match source_annotations.get(&annotation.node.id) {
497+
Some(SourceAnnotation::Path { path }) => Some(path.clone()),
498+
_ => None,
499+
},
492500
},
493501
None,
494502
);

crate_universe/src/context/platforms.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ mod test {
135135
id: CrateId::new("mock_crate_b".to_owned(), VERSION_ZERO_ONE_ZERO),
136136
target: "mock_crate_b".to_owned(),
137137
alias: None,
138-
source_annotation: None,
138+
local_path: None,
139139
},
140140
None,
141141
);
@@ -194,7 +194,7 @@ mod test {
194194
id: CrateId::new("mock_crate_b".to_owned(), VERSION_ZERO_ONE_ZERO),
195195
target: "mock_crate_b".to_owned(),
196196
alias: None,
197-
source_annotation: None,
197+
local_path: None,
198198
},
199199
Some(configuration),
200200
);
@@ -281,7 +281,7 @@ mod test {
281281
id: CrateId::new("mock_crate_b".to_owned(), VERSION_ZERO_ONE_ZERO),
282282
target: "mock_crate_b".to_owned(),
283283
alias: None,
284-
source_annotation: None,
284+
local_path: None,
285285
},
286286
Some(configuration.clone()),
287287
);
@@ -348,7 +348,7 @@ mod test {
348348
id: CrateId::new("mock_crate_b".to_owned(), VERSION_ZERO_ONE_ZERO),
349349
target: "mock_crate_b".to_owned(),
350350
alias: None,
351-
source_annotation: None,
351+
local_path: None,
352352
},
353353
Some(configuration.clone()),
354354
);

crate_universe/src/rendering.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -840,10 +840,8 @@ impl Renderer {
840840
extra_deps: Select<BTreeSet<Label>>,
841841
) -> Select<BTreeSet<Label>> {
842842
Select::merge(
843-
deps.map(|dep| match dep.source_annotation {
844-
Some(SourceAnnotation::Path { path }) => {
845-
Label::from_str(&format!("//{}:{}", path, &dep.target)).unwrap()
846-
}
843+
deps.map(|dep| match dep.local_path {
844+
Some(path) => Label::from_str(&format!("//{}:{}", path, &dep.target)).unwrap(),
847845
_ => self.crate_label(&dep.id.name, &dep.id.version.to_string(), &dep.target),
848846
}),
849847
extra_deps,
@@ -2008,7 +2006,7 @@ mod test {
20082006
// this is identical to what we have in the `name` attribute
20092007
// which creates conflict in `render_module_build_file`
20102008
alias: Some("mock_crate".into()),
2011-
source_annotation: None,
2009+
local_path: None,
20122010
}])),
20132011
..Default::default()
20142012
},

examples/crate_universe/alias_rule/cargo-bazel-lock_global_alias_annotation_none.json

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "a6bc08429f8b0c107b6fcc64246695850dd2aac78424adc2bbb679ece9dcc089",
2+
"checksum": "c00d8f828568c40cdc8f40cab902c254cbed12bac1b4a4d322eb942852523463",
33
"crates": {
44
"direct-cargo-bazel-deps 0.0.1": {
55
"name": "direct-cargo-bazel-deps",
@@ -29,13 +29,7 @@
2929
"common": [
3030
{
3131
"id": "test_data_passing_crate 0.1.0",
32-
"target": "test_data_passing_crate",
33-
"source_annotation": {
34-
"Http": {
35-
"url": "https://static.crates.io/crates/test_data_passing_crate/0.1.0/download",
36-
"sha256": "08c67aba3a29c3dc187eaf8080107404abfaee1ae893a02c43a362343ca73286"
37-
}
38-
}
32+
"target": "test_data_passing_crate"
3933
}
4034
],
4135
"selects": {}
@@ -92,13 +86,7 @@
9286
"common": [
9387
{
9488
"id": "test_data_passing_crate 0.1.0",
95-
"target": "build_script_build",
96-
"source_annotation": {
97-
"Http": {
98-
"url": "https://static.crates.io/crates/test_data_passing_crate/0.1.0/download",
99-
"sha256": "08c67aba3a29c3dc187eaf8080107404abfaee1ae893a02c43a362343ca73286"
100-
}
101-
}
89+
"target": "build_script_build"
10290
}
10391
],
10492
"selects": {}

examples/crate_universe/alias_rule/cargo-bazel-lock_global_alias_annotation_opt.json

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "eaa549123840ec0ed4e30e2618eabf5acb376e22fc27d4a064542a18871ba7c4",
2+
"checksum": "ae447fbf37ed546be4da604984ab80a3dd1205cb0dfbdb8e9ec93c85dc44af40",
33
"crates": {
44
"direct-cargo-bazel-deps 0.0.1": {
55
"name": "direct-cargo-bazel-deps",
@@ -29,13 +29,7 @@
2929
"common": [
3030
{
3131
"id": "test_data_passing_crate 0.1.0",
32-
"target": "test_data_passing_crate",
33-
"source_annotation": {
34-
"Http": {
35-
"url": "https://static.crates.io/crates/test_data_passing_crate/0.1.0/download",
36-
"sha256": "08c67aba3a29c3dc187eaf8080107404abfaee1ae893a02c43a362343ca73286"
37-
}
38-
}
32+
"target": "test_data_passing_crate"
3933
}
4034
],
4135
"selects": {}
@@ -92,13 +86,7 @@
9286
"common": [
9387
{
9488
"id": "test_data_passing_crate 0.1.0",
95-
"target": "build_script_build",
96-
"source_annotation": {
97-
"Http": {
98-
"url": "https://static.crates.io/crates/test_data_passing_crate/0.1.0/download",
99-
"sha256": "08c67aba3a29c3dc187eaf8080107404abfaee1ae893a02c43a362343ca73286"
100-
}
101-
}
89+
"target": "build_script_build"
10290
}
10391
],
10492
"selects": {}

examples/crate_universe/alias_rule/cargo-bazel-lock_global_custom_annotation_none.json

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "9c9f5b08c5b53471e832ea3980c57f0ebcc42f9d5ac887e4f8983b05116c2328",
2+
"checksum": "8a2e7c659fdc8db88d3fddd699b0043c1f45e04b9135b8dbc981952a7d050adb",
33
"crates": {
44
"direct-cargo-bazel-deps 0.0.1": {
55
"name": "direct-cargo-bazel-deps",
@@ -29,13 +29,7 @@
2929
"common": [
3030
{
3131
"id": "test_data_passing_crate 0.1.0",
32-
"target": "test_data_passing_crate",
33-
"source_annotation": {
34-
"Http": {
35-
"url": "https://static.crates.io/crates/test_data_passing_crate/0.1.0/download",
36-
"sha256": "08c67aba3a29c3dc187eaf8080107404abfaee1ae893a02c43a362343ca73286"
37-
}
38-
}
32+
"target": "test_data_passing_crate"
3933
}
4034
],
4135
"selects": {}
@@ -92,13 +86,7 @@
9286
"common": [
9387
{
9488
"id": "test_data_passing_crate 0.1.0",
95-
"target": "build_script_build",
96-
"source_annotation": {
97-
"Http": {
98-
"url": "https://static.crates.io/crates/test_data_passing_crate/0.1.0/download",
99-
"sha256": "08c67aba3a29c3dc187eaf8080107404abfaee1ae893a02c43a362343ca73286"
100-
}
101-
}
89+
"target": "build_script_build"
10290
}
10391
],
10492
"selects": {}

examples/crate_universe/alias_rule/cargo-bazel-lock_global_dbg_annotation_fastbuild.json

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "5df2aa0f99c263b2729d3e4cae22b488db361e9cf9b9414088eff14269310da9",
2+
"checksum": "ccfebc4eadfea89a23ecb833ac82ecb39a7ad4198e0b62f99d67be4579024880",
33
"crates": {
44
"direct-cargo-bazel-deps 0.0.1": {
55
"name": "direct-cargo-bazel-deps",
@@ -29,13 +29,7 @@
2929
"common": [
3030
{
3131
"id": "test_data_passing_crate 0.1.0",
32-
"target": "test_data_passing_crate",
33-
"source_annotation": {
34-
"Http": {
35-
"url": "https://static.crates.io/crates/test_data_passing_crate/0.1.0/download",
36-
"sha256": "08c67aba3a29c3dc187eaf8080107404abfaee1ae893a02c43a362343ca73286"
37-
}
38-
}
32+
"target": "test_data_passing_crate"
3933
}
4034
],
4135
"selects": {}
@@ -92,13 +86,7 @@
9286
"common": [
9387
{
9488
"id": "test_data_passing_crate 0.1.0",
95-
"target": "build_script_build",
96-
"source_annotation": {
97-
"Http": {
98-
"url": "https://static.crates.io/crates/test_data_passing_crate/0.1.0/download",
99-
"sha256": "08c67aba3a29c3dc187eaf8080107404abfaee1ae893a02c43a362343ca73286"
100-
}
101-
}
89+
"target": "build_script_build"
10290
}
10391
],
10492
"selects": {}

examples/crate_universe/alias_rule/cargo-bazel-lock_global_opt_annotation_alias.json

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "4eaa48f4cdf9153c59fafd2705838a4030541b350050d5c5054c206f8ed31728",
2+
"checksum": "98a4f8f8b153ab0ce51838792b49a2fad1853bdf6d2515d70f9300a28ba2654e",
33
"crates": {
44
"direct-cargo-bazel-deps 0.0.1": {
55
"name": "direct-cargo-bazel-deps",
@@ -29,13 +29,7 @@
2929
"common": [
3030
{
3131
"id": "test_data_passing_crate 0.1.0",
32-
"target": "test_data_passing_crate",
33-
"source_annotation": {
34-
"Http": {
35-
"url": "https://static.crates.io/crates/test_data_passing_crate/0.1.0/download",
36-
"sha256": "08c67aba3a29c3dc187eaf8080107404abfaee1ae893a02c43a362343ca73286"
37-
}
38-
}
32+
"target": "test_data_passing_crate"
3933
}
4034
],
4135
"selects": {}
@@ -92,13 +86,7 @@
9286
"common": [
9387
{
9488
"id": "test_data_passing_crate 0.1.0",
95-
"target": "build_script_build",
96-
"source_annotation": {
97-
"Http": {
98-
"url": "https://static.crates.io/crates/test_data_passing_crate/0.1.0/download",
99-
"sha256": "08c67aba3a29c3dc187eaf8080107404abfaee1ae893a02c43a362343ca73286"
100-
}
101-
}
89+
"target": "build_script_build"
10290
}
10391
],
10492
"selects": {}

examples/crate_universe/alias_rule/cargo-bazel-lock_global_opt_annotation_dbg.json

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "7e86e66a95ca2da280e72926a8c0d99c5911db7ef770b626cda80298e4fbb268",
2+
"checksum": "8618d21e684186f1e2d2a128c36ee013065cfc1316630876655d0543b289bd3a",
33
"crates": {
44
"direct-cargo-bazel-deps 0.0.1": {
55
"name": "direct-cargo-bazel-deps",
@@ -29,13 +29,7 @@
2929
"common": [
3030
{
3131
"id": "test_data_passing_crate 0.1.0",
32-
"target": "test_data_passing_crate",
33-
"source_annotation": {
34-
"Http": {
35-
"url": "https://static.crates.io/crates/test_data_passing_crate/0.1.0/download",
36-
"sha256": "08c67aba3a29c3dc187eaf8080107404abfaee1ae893a02c43a362343ca73286"
37-
}
38-
}
32+
"target": "test_data_passing_crate"
3933
}
4034
],
4135
"selects": {}
@@ -92,13 +86,7 @@
9286
"common": [
9387
{
9488
"id": "test_data_passing_crate 0.1.0",
95-
"target": "build_script_build",
96-
"source_annotation": {
97-
"Http": {
98-
"url": "https://static.crates.io/crates/test_data_passing_crate/0.1.0/download",
99-
"sha256": "08c67aba3a29c3dc187eaf8080107404abfaee1ae893a02c43a362343ca73286"
100-
}
101-
}
89+
"target": "build_script_build"
10290
}
10391
],
10492
"selects": {}

0 commit comments

Comments
 (0)