2022-06-30 06:49:12 +03:00
|
|
|
{ lib
|
|
|
|
, linkFarmFromDrvs
|
2022-01-06 07:46:05 +03:00
|
|
|
, mkDummySrc
|
2023-09-03 22:04:55 +03:00
|
|
|
, remarshal
|
2022-02-17 08:07:10 +03:00
|
|
|
, runCommand
|
2022-11-28 06:23:35 +03:00
|
|
|
, writeText
|
2022-01-06 07:46:05 +03:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2022-09-28 05:05:06 +03:00
|
|
|
doCompare = name: expected: orig_actual:
|
|
|
|
let
|
|
|
|
actual = runCommand "trim-actual-${name}" { } ''
|
|
|
|
cp --recursive ${orig_actual} --no-target-directory $out --no-preserve=mode,ownership
|
|
|
|
find $out -name Cargo.toml | xargs sed -i"" 's!/nix/store/[^-]\+-dummy.rs!cranespecific-dummy.rs!'
|
|
|
|
'';
|
2023-09-03 22:04:55 +03:00
|
|
|
|
|
|
|
# 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";
|
2022-09-28 05:05:06 +03:00
|
|
|
in
|
2022-09-27 09:25:09 +03:00
|
|
|
runCommand "compare-${name}" { } ''
|
|
|
|
echo ${expected} ${actual}
|
2023-09-03 22:04:55 +03:00
|
|
|
cp -r --no-preserve=ownership,mode ${expected} ./expected
|
|
|
|
cp -r --no-preserve=ownership,mode ${actual} ./actual
|
|
|
|
|
|
|
|
find ./expected ./actual \
|
|
|
|
-name Cargo.toml \
|
|
|
|
-exec mv '{}' '{}.bak' \; \
|
|
|
|
-exec ${remarshal}/bin/remarshal ${sortKeys} --if toml -i '{}.bak' --of toml -o '{}' \;
|
|
|
|
find ./expected ./actual -name Cargo.toml.bak -delete
|
|
|
|
|
|
|
|
diff -r ./expected ./actual
|
2022-09-27 09:25:09 +03:00
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
|
|
cmpDummySrcRaw = name: expected: input:
|
2022-01-06 07:46:05 +03:00
|
|
|
let
|
|
|
|
dummySrc = mkDummySrc {
|
2022-06-30 06:49:12 +03:00
|
|
|
src = input;
|
2022-01-06 07:46:05 +03:00
|
|
|
};
|
|
|
|
in
|
2022-09-27 09:25:09 +03:00
|
|
|
doCompare name expected dummySrc;
|
2022-06-30 06:49:12 +03:00
|
|
|
|
|
|
|
cmpDummySrc = name: path:
|
|
|
|
let
|
|
|
|
expected = path + "/expected";
|
|
|
|
input = path + "/input";
|
|
|
|
|
|
|
|
# Regression test for https://github.com/ipetkov/crane/issues/46
|
|
|
|
filteredInput = lib.cleanSourceWith {
|
|
|
|
src = input;
|
|
|
|
filter = path: type:
|
|
|
|
type == "directory" || lib.any (s: lib.hasPrefix s (builtins.baseNameOf path)) [
|
|
|
|
"Cargo"
|
|
|
|
"config"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
[
|
2022-09-27 09:25:09 +03:00
|
|
|
(cmpDummySrcRaw name expected input)
|
|
|
|
(cmpDummySrcRaw "${name}-filtered" expected filteredInput)
|
2022-06-30 06:49:12 +03:00
|
|
|
];
|
2022-09-27 09:25:09 +03:00
|
|
|
|
2022-11-28 06:23:35 +03:00
|
|
|
customized =
|
2022-09-27 09:25:09 +03:00
|
|
|
let
|
|
|
|
expected = ./customized/expected;
|
|
|
|
input = ./customized/input;
|
|
|
|
in
|
|
|
|
doCompare "customized" expected (mkDummySrc {
|
|
|
|
src = input;
|
|
|
|
extraDummyScript = ''
|
|
|
|
cp ${input}/extra-custom-file.txt $out
|
|
|
|
echo 'another additional file' >$out/another-custom-file.txt
|
|
|
|
'';
|
|
|
|
});
|
2022-11-28 06:23:35 +03:00
|
|
|
|
|
|
|
customizedDummyrs =
|
|
|
|
let
|
|
|
|
expected = ./custom-dummyrs/expected;
|
|
|
|
input = ./custom-dummyrs/input;
|
|
|
|
in
|
|
|
|
doCompare "customized-dummyrs" expected (mkDummySrc {
|
|
|
|
src = input;
|
|
|
|
dummyrs = writeText "dummy.rs" ''
|
|
|
|
#![feature(no_core, lang_items, start)]
|
|
|
|
#[no_std]
|
|
|
|
#[no_core]
|
|
|
|
// #[no_gods]
|
|
|
|
// #[no_masters]
|
|
|
|
|
|
|
|
#[start]
|
|
|
|
fn main(_: isize, _: *const *const u8) -> isize {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
});
|
2022-01-06 07:46:05 +03:00
|
|
|
in
|
2022-06-30 06:49:12 +03:00
|
|
|
linkFarmFromDrvs "cleanCargoToml" (lib.flatten [
|
2022-01-06 07:46:05 +03:00
|
|
|
(cmpDummySrc "single" ./single)
|
|
|
|
(cmpDummySrc "single-alt" ./single-alt)
|
2022-01-08 04:36:31 +03:00
|
|
|
(cmpDummySrc "workspace" ./workspace)
|
2023-03-07 04:24:21 +03:00
|
|
|
(cmpDummySrc "workspace-bindeps" ./workspace-bindeps)
|
2022-10-24 01:56:18 +03:00
|
|
|
(cmpDummySrc "workspace-inheritance" ./workspace-inheritance)
|
2022-09-27 09:25:09 +03:00
|
|
|
|
2022-11-28 06:23:35 +03:00
|
|
|
customized
|
|
|
|
customizedDummyrs
|
2022-06-30 06:49:12 +03:00
|
|
|
])
|