Skip to content

Commit c87c85e

Browse files
fix: cargoTomlAggressive only keeps top-level keys (#960)
1 parent 0bda7e7 commit c87c85e

File tree

4 files changed

+286
-14
lines changed

4 files changed

+286
-14
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
cargo_features = ["some unstable features"]
2+
[[bench]]
3+
edition = "2015"
4+
harness = true
5+
name = "bench1"
6+
path = "src/bench1.rs"
7+
proc_macro = false
8+
9+
[[bench]]
10+
edition = "2018"
11+
harness = false
12+
name = "bench2"
13+
path = "src/bench2.rs"
14+
proc_macro = false
15+
16+
[[bin]]
17+
edition = "2015"
18+
harness = true
19+
name = "bin1"
20+
path = "src/bin1.rs"
21+
proc_macro = false
22+
23+
[[bin]]
24+
edition = "2018"
25+
harness = true
26+
name = "bin2"
27+
path = "src/bin2.rs"
28+
proc_macro = false
29+
30+
[[example]]
31+
crate_type = ["staticlib"]
32+
edition = "2015"
33+
harness = true
34+
name = "example1"
35+
path = "src/example1.rs"
36+
proc_macro = false
37+
38+
[[example]]
39+
edition = "2018"
40+
harness = true
41+
name = "example2"
42+
path = "src/example2.rs"
43+
proc_macro = false
44+
45+
[[test]]
46+
edition = "2015"
47+
harness = true
48+
name = "test1"
49+
path = "src/test1.rs"
50+
proc_macro = false
51+
52+
[[test]]
53+
edition = "2018"
54+
harness = true
55+
name = "test2"
56+
path = "src/test2.rs"
57+
proc_macro = false
58+
59+
[build_dependencies.corge]
60+
version = "6"
61+
62+
[dependencies]
63+
foo = "1"
64+
65+
[dependencies.bar]
66+
features = ["bar_feature", "bar_another_feature"]
67+
version = "2"
68+
69+
[dependencies.baz]
70+
features = ["baz_feature", "baz_feature2"]
71+
version = "3"
72+
73+
[dev_dependencies]
74+
qux = "4"
75+
76+
[dev_dependencies.zuul]
77+
version = "5"
78+
79+
[features]
80+
barfeature = ["foofeature"]
81+
foofeature = []
82+
83+
[lib]
84+
crate_type = ["lib", "rlib"]
85+
edition = "2021"
86+
harness = true
87+
name = "foo"
88+
path = "src/lib.rs"
89+
proc_macro = false
90+
91+
[package]
92+
edition = "2021"
93+
name = "some name"
94+
resolver = "2"
95+
version = "1.2.3"
96+
workspace = "some/path/to/workspace"
97+
98+
[patch.crates_io]
99+
[patch.crates_io.bar]
100+
path = "my/local/bar"
101+
102+
[patch.crates_io.foo]
103+
git = "https://github.com/example/foo"
104+
105+
[profile]
106+
[profile.dev]
107+
opt_level = 1
108+
overflow_checks = false
109+
110+
[profile.release]
111+
opt_level = 2
112+
overflow_checks = true
113+
114+
[replace]
115+
[replace."bar3:1.0.2"]
116+
path = "my/local/bar3"
117+
118+
[replace."foo2:0.1.0"]
119+
git = "https://github.com/example/foo2"
120+
121+
[target]
122+
[target."cfg(target_arch = \"x86\")".dependencies]
123+
garply = "8"
124+
125+
[target."cfg(unix)".dependencies]
126+
grault = "7"
127+
128+
[workspace]
129+
resolver = "2"
130+
default_members = ["path/to/member2", "path/to/member3/foo"]
131+
exclude = ["crates/foo", "path/to/other"]
132+
members = ["member1", "path/to/member2", "crates/*"]
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
cargo-features = ["some unstable features"]
2+
[[bench]]
3+
edition = "2015"
4+
harness = true
5+
name = "bench1"
6+
path = "src/bench1.rs"
7+
proc-macro = false
8+
9+
[[bench]]
10+
edition = "2018"
11+
harness = true
12+
name = "bench2"
13+
path = "src/bench2.rs"
14+
proc-macro = false
15+
16+
[[bin]]
17+
edition = "2015"
18+
harness = false
19+
name = "bin1"
20+
path = "src/bin1.rs"
21+
proc-macro = false
22+
23+
[[bin]]
24+
edition = "2018"
25+
harness = true
26+
name = "bin2"
27+
path = "src/bin2.rs"
28+
proc-macro = false
29+
30+
[[example]]
31+
crate-type = ["staticlib"]
32+
edition = "2015"
33+
harness = true
34+
name = "example1"
35+
path = "src/example1.rs"
36+
proc-macro = false
37+
38+
[[example]]
39+
edition = "2018"
40+
harness = true
41+
name = "example2"
42+
path = "src/example2.rs"
43+
proc-macro = false
44+
45+
[[test]]
46+
edition = "2015"
47+
harness = true
48+
name = "test1"
49+
path = "src/test1.rs"
50+
proc-macro = false
51+
52+
[[test]]
53+
edition = "2018"
54+
harness = true
55+
name = "test2"
56+
path = "src/test2.rs"
57+
proc-macro = false
58+
59+
[build-dependencies.corge]
60+
version = "6"
61+
62+
[dependencies]
63+
foo = "1"
64+
65+
[dependencies.bar]
66+
features = ["bar-feature", "bar-another-feature"]
67+
version = "2"
68+
69+
[dependencies.baz]
70+
features = ["baz-feature", "baz-feature2"]
71+
version = "3"
72+
73+
[dev-dependencies]
74+
qux = "4"
75+
76+
[dev-dependencies.zuul]
77+
version = "5"
78+
79+
[features]
80+
barfeature = ["foofeature"]
81+
foofeature = []
82+
83+
[lib]
84+
crate-type = ["lib", "rlib"]
85+
edition = "2021"
86+
harness = true
87+
name = "foo"
88+
path = "src/lib.rs"
89+
proc-macro = false
90+
91+
[package]
92+
edition = "2021"
93+
name = "some name"
94+
resolver = "2"
95+
version = "1.2.3"
96+
workspace = "some/path/to/workspace"
97+
98+
[patch.crates-io]
99+
[patch.crates-io.bar]
100+
path = "my/local/bar"
101+
102+
[patch.crates-io.foo]
103+
git = "https://github.com/example/foo"
104+
105+
[profile]
106+
[profile.dev]
107+
opt-level = 1
108+
overflow-checks = false
109+
110+
[profile.release]
111+
opt-level = 2
112+
overflow-checks = true
113+
114+
[replace]
115+
[replace."bar3:1.0.2"]
116+
path = "my/local/bar3"
117+
118+
[replace."foo2:0.1.0"]
119+
git = "https://github.com/example/foo2"
120+
121+
[target]
122+
[target."cfg(target_arch = \"x86\")".dependencies]
123+
garply = "8"
124+
125+
[target."cfg(unix)".dependencies]
126+
grault = "7"
127+
128+
[workspace]
129+
resolver = "2"
130+
default-members = ["path/to/member2", "path/to/member3/foo"]
131+
exclude = ["crates/foo", "path/to/other"]
132+
members = ["member1", "path/to/member2", "crates/*"]
Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
cleanCargoToml,
3+
filters,
34
lib,
45
linkFarmFromDrvs,
56
remarshal,
@@ -9,33 +10,40 @@
910

1011
let
1112
cmpCleanCargoToml =
12-
name: path:
13+
folderName: path: filterName: filter:
1314
let
1415
cleaned = cleanCargoToml {
1516
cargoToml = path + "/Cargo.toml";
17+
cleanCargoTomlFilter = filter;
1618
};
17-
cleanedToml = writeTOML "cleaned.toml" cleaned;
18-
expected = path + "/expected.toml";
19-
19+
cleanedToml = writeTOML "cleaned-${folderName}-${filterName}.toml" cleaned;
20+
expectedPathSpecific = path + "/expected-${filterName}.toml";
21+
expected =
22+
if lib.pathExists expectedPathSpecific then expectedPathSpecific else path + "/expected.toml";
2023
# 23.05 has remarshal 0.14 which sorts keys by default
2124
# starting with version 0.16 ordering is preserved unless
2225
# --sort-keys is specified
2326
sortKeys = lib.optionalString (lib.strings.versionAtLeast remarshal.version "0.16.0") "--sort-keys";
2427
in
25-
runCommand "compare-${name}" { } ''
28+
runCommand "compare-${folderName}-${filterName}" { } ''
2629
function reformat {
2730
${remarshal}/bin/remarshal ${sortKeys} -i "$1" --of toml
2831
}
2932
3033
diff <(reformat ${expected}) <(reformat ${cleanedToml})
3134
touch $out
3235
'';
36+
cmpAllFilters =
37+
name: path:
38+
lib.mapAttrsToList (filterName: filter: cmpCleanCargoToml name path filterName filter) filters;
39+
40+
testMatrix = {
41+
barebones = ./barebones;
42+
complex = ./complex;
43+
# https://github.com/ipetkov/crane/issues/610
44+
complex-underscores = ./complex-underscores;
45+
# https://github.com/ipetkov/crane/issues/800
46+
proc-macro = ./proc-macro;
47+
};
3348
in
34-
linkFarmFromDrvs "cleanCargoToml" [
35-
(cmpCleanCargoToml "barebones" ./barebones)
36-
(cmpCleanCargoToml "complex" ./complex)
37-
# https://github.com/ipetkov/crane/issues/610
38-
(cmpCleanCargoToml "complex-underscores" ./complex-underscores)
39-
#https://github.com/ipetkov/crane/issues/800
40-
(cmpCleanCargoToml "proc-macro" ./proc-macro)
41-
]
49+
linkFarmFromDrvs "cleanCargoToml" (lib.concatLists (lib.mapAttrsToList cmpAllFilters testMatrix))

lib/filters/cargoTomlAggressive.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ let
5353
++ (pathsToKeepPerTarget "test")
5454
++ (pathsToKeepPerTarget "bench");
5555

56-
cargoTomlAggressive = path: builtins.any (lib.lists.hasPrefix path) pathsToKeep;
56+
cargoTomlAggressive = path: builtins.any (p: lib.lists.hasPrefix path p || lib.lists.hasPrefix p path) pathsToKeep;
5757
in
5858
cargoTomlAggressive

0 commit comments

Comments
 (0)