crane/checks/mkDummySrcTests/default.nix
Ivan Petkov 66303545d7
Update flake.lock (#382)
Flake lock file updates:

• Updated input 'flake-utils':
    'github:numtide/flake-utils/919d646de7be200f3bf08cb76ae1f09402b6f9b4' (2023-07-11)
  → 'github:numtide/flake-utils/f9e7cf818399d17d347f847525c5a5a8032e4e44' (2023-08-23)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/5068bc8fe943bde3c446326da8d0ca9c93d5a682' (2023-08-07)
  → 'github:NixOS/nixpkgs/e7f35e03abd06a2faef6684d0de813370e13bda8' (2023-09-02)
• Updated input 'rust-overlay':
    'github:oxalica/rust-overlay/b520a3889b24aaf909e287d19d406862ced9ffc9' (2023-08-07)
  → 'github:oxalica/rust-overlay/98ccb73e6eefc481da6039ee57ad8818d1ca8d56' (2023-09-03)

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-09-03 12:04:55 -07:00

112 lines
3.0 KiB
Nix

{ lib
, linkFarmFromDrvs
, mkDummySrc
, remarshal
, runCommand
, writeText
}:
let
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!'
'';
# 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}" { } ''
echo ${expected} ${actual}
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
touch $out
'';
cmpDummySrcRaw = name: expected: input:
let
dummySrc = mkDummySrc {
src = input;
};
in
doCompare name expected dummySrc;
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
[
(cmpDummySrcRaw name expected input)
(cmpDummySrcRaw "${name}-filtered" expected filteredInput)
];
customized =
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
'';
});
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
}
'';
});
in
linkFarmFromDrvs "cleanCargoToml" (lib.flatten [
(cmpDummySrc "single" ./single)
(cmpDummySrc "single-alt" ./single-alt)
(cmpDummySrc "workspace" ./workspace)
(cmpDummySrc "workspace-bindeps" ./workspace-bindeps)
(cmpDummySrc "workspace-inheritance" ./workspace-inheritance)
customized
customizedDummyrs
])