Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
cargo_features = ["some unstable features"]
[[bench]]
edition = "2015"
harness = true
name = "bench1"
path = "src/bench1.rs"
proc_macro = false

[[bench]]
edition = "2018"
harness = false
name = "bench2"
path = "src/bench2.rs"
proc_macro = false

[[bin]]
edition = "2015"
harness = true
name = "bin1"
path = "src/bin1.rs"
proc_macro = false

[[bin]]
edition = "2018"
harness = true
name = "bin2"
path = "src/bin2.rs"
proc_macro = false

[[example]]
crate_type = ["staticlib"]
edition = "2015"
harness = true
name = "example1"
path = "src/example1.rs"
proc_macro = false

[[example]]
edition = "2018"
harness = true
name = "example2"
path = "src/example2.rs"
proc_macro = false

[[test]]
edition = "2015"
harness = true
name = "test1"
path = "src/test1.rs"
proc_macro = false

[[test]]
edition = "2018"
harness = true
name = "test2"
path = "src/test2.rs"
proc_macro = false

[build_dependencies.corge]
version = "6"

[dependencies]
foo = "1"

[dependencies.bar]
features = ["bar_feature", "bar_another_feature"]
version = "2"

[dependencies.baz]
features = ["baz_feature", "baz_feature2"]
version = "3"

[dev_dependencies]
qux = "4"

[dev_dependencies.zuul]
version = "5"

[features]
barfeature = ["foofeature"]
foofeature = []

[lib]
crate_type = ["lib", "rlib"]
edition = "2021"
harness = true
name = "foo"
path = "src/lib.rs"
proc_macro = false

[package]
edition = "2021"
name = "some name"
resolver = "2"
version = "1.2.3"
workspace = "some/path/to/workspace"

[patch.crates_io]
[patch.crates_io.bar]
path = "my/local/bar"

[patch.crates_io.foo]
git = "https://github.com/example/foo"

[profile]
[profile.dev]
opt_level = 1
overflow_checks = false

[profile.release]
opt_level = 2
overflow_checks = true

[replace]
[replace."bar3:1.0.2"]
path = "my/local/bar3"

[replace."foo2:0.1.0"]
git = "https://github.com/example/foo2"

[target]
[target."cfg(target_arch = \"x86\")".dependencies]
garply = "8"

[target."cfg(unix)".dependencies]
grault = "7"

[workspace]
resolver = "2"
default_members = ["path/to/member2", "path/to/member3/foo"]
exclude = ["crates/foo", "path/to/other"]
members = ["member1", "path/to/member2", "crates/*"]
132 changes: 132 additions & 0 deletions checks/cleanCargoTomlTests/complex/expected-cargoTomlAggressive.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
cargo-features = ["some unstable features"]
[[bench]]
edition = "2015"
harness = true
name = "bench1"
path = "src/bench1.rs"
proc-macro = false

[[bench]]
edition = "2018"
harness = true
name = "bench2"
path = "src/bench2.rs"
proc-macro = false

[[bin]]
edition = "2015"
harness = false
name = "bin1"
path = "src/bin1.rs"
proc-macro = false

[[bin]]
edition = "2018"
harness = true
name = "bin2"
path = "src/bin2.rs"
proc-macro = false

[[example]]
crate-type = ["staticlib"]
edition = "2015"
harness = true
name = "example1"
path = "src/example1.rs"
proc-macro = false

[[example]]
edition = "2018"
harness = true
name = "example2"
path = "src/example2.rs"
proc-macro = false

[[test]]
edition = "2015"
harness = true
name = "test1"
path = "src/test1.rs"
proc-macro = false

[[test]]
edition = "2018"
harness = true
name = "test2"
path = "src/test2.rs"
proc-macro = false

[build-dependencies.corge]
version = "6"

[dependencies]
foo = "1"

[dependencies.bar]
features = ["bar-feature", "bar-another-feature"]
version = "2"

[dependencies.baz]
features = ["baz-feature", "baz-feature2"]
version = "3"

[dev-dependencies]
qux = "4"

[dev-dependencies.zuul]
version = "5"

[features]
barfeature = ["foofeature"]
foofeature = []

[lib]
crate-type = ["lib", "rlib"]
edition = "2021"
harness = true
name = "foo"
path = "src/lib.rs"
proc-macro = false

[package]
edition = "2021"
name = "some name"
resolver = "2"
version = "1.2.3"
workspace = "some/path/to/workspace"

[patch.crates-io]
[patch.crates-io.bar]
path = "my/local/bar"

[patch.crates-io.foo]
git = "https://github.com/example/foo"

[profile]
[profile.dev]
opt-level = 1
overflow-checks = false

[profile.release]
opt-level = 2
overflow-checks = true

[replace]
[replace."bar3:1.0.2"]
path = "my/local/bar3"

[replace."foo2:0.1.0"]
git = "https://github.com/example/foo2"

[target]
[target."cfg(target_arch = \"x86\")".dependencies]
garply = "8"

[target."cfg(unix)".dependencies]
grault = "7"

[workspace]
resolver = "2"
default-members = ["path/to/member2", "path/to/member3/foo"]
exclude = ["crates/foo", "path/to/other"]
members = ["member1", "path/to/member2", "crates/*"]
34 changes: 21 additions & 13 deletions checks/cleanCargoTomlTests/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
cleanCargoToml,
filters,
lib,
linkFarmFromDrvs,
remarshal,
Expand All @@ -9,33 +10,40 @@

let
cmpCleanCargoToml =
name: path:
folderName: path: filterName: filter:
let
cleaned = cleanCargoToml {
cargoToml = path + "/Cargo.toml";
cleanCargoTomlFilter = filter;
};
cleanedToml = writeTOML "cleaned.toml" cleaned;
expected = path + "/expected.toml";

cleanedToml = writeTOML "cleaned-${folderName}-${filterName}.toml" cleaned;
expectedPathSpecific = path + "/expected-${filterName}.toml";
expected =
if lib.pathExists expectedPathSpecific then expectedPathSpecific else path + "/expected.toml";
# 23.05 has remarshal 0.14 which sorts keys by default
# starting with version 0.16 ordering is preserved unless
# --sort-keys is specified
sortKeys = lib.optionalString (lib.strings.versionAtLeast remarshal.version "0.16.0") "--sort-keys";
in
runCommand "compare-${name}" { } ''
runCommand "compare-${folderName}-${filterName}" { } ''
function reformat {
${remarshal}/bin/remarshal ${sortKeys} -i "$1" --of toml
}

diff <(reformat ${expected}) <(reformat ${cleanedToml})
touch $out
'';
cmpAllFilters =
name: path:
lib.mapAttrsToList (filterName: filter: cmpCleanCargoToml name path filterName filter) filters;

testMatrix = {
barebones = ./barebones;
complex = ./complex;
# https://github.com/ipetkov/crane/issues/610
complex-underscores = ./complex-underscores;
# https://github.com/ipetkov/crane/issues/800
proc-macro = ./proc-macro;
};
in
linkFarmFromDrvs "cleanCargoToml" [
(cmpCleanCargoToml "barebones" ./barebones)
(cmpCleanCargoToml "complex" ./complex)
# https://github.com/ipetkov/crane/issues/610
(cmpCleanCargoToml "complex-underscores" ./complex-underscores)
#https://github.com/ipetkov/crane/issues/800
(cmpCleanCargoToml "proc-macro" ./proc-macro)
]
linkFarmFromDrvs "cleanCargoToml" (lib.concatLists (lib.mapAttrsToList cmpAllFilters testMatrix))
2 changes: 1 addition & 1 deletion lib/filters/cargoTomlAggressive.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ let
++ (pathsToKeepPerTarget "test")
++ (pathsToKeepPerTarget "bench");

cargoTomlAggressive = path: builtins.any (lib.lists.hasPrefix path) pathsToKeep;
cargoTomlAggressive = path: builtins.any (p: lib.lists.hasPrefix path p || lib.lists.hasPrefix p path) pathsToKeep;
in
cargoTomlAggressive