nixpkgs-tools/treewideMainProgram/verify_main_programs.sh

48 lines
1.3 KiB
Bash
Raw Normal View History

2023-11-27 02:36:30 +01:00
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash ripgrep nix
if [ "$1" == "head" ]; then
ADDED_MAINPROGRAMS=$(git diff-tree --no-commit-id --name-only -r HEAD)
elif [ "$1" == "wip" ]; then
ADDED_MAINPROGRAMS=$(git diff --name-only --cached)
else
echo "USAGE: $0 [ head | wip ]"
exit 1
fi
trap "exit 0" SIGINT
TOTAL_COUNT=$(echo $ADDED_MAINPROGRAMS | wc -w)
COUNTER=0
for FILE in $ADDED_MAINPROGRAMS; do
PACKAGE_PATH=$(dirname "$FILE")
PACKAGE="${PACKAGE_PATH%/}"
PACKAGE="${PACKAGE##*/}"
COUNTER=$((COUNTER + 1))
echo "($COUNTER/$TOTAL_COUNT) Verifying mainProgram of: $PACKAGE"
NIXPKGS_ALLOW_UNFREE=1 nix build ".#$PACKAGE" --option builders '' --impure || {
echo "$PACKAGE" >> missing_main_program.txt && continue;
}
MAIN_PROGRAM=$(rg "mainProgram = \"(.+?)\";" --replace "\$1" --only-matching --no-line-number "$FILE" | xargs)
echo "mainProgram: $PACKAGE"
if ! {
{
[ -d "result/bin" ] && [ "$(ls result/bin | xargs)" == "$MAIN_PROGRAM" ];
} || {
[ -d "result-bin/bin" ] && [ "$(ls result-bin/bin | xargs)" == "$MAIN_PROGRAM" ];
};
}; then
echo "mainProgram doesn't match contents:"
ls result/bin 2>/dev/null || true
ls result-bin/bin 2>/dev/null || true
echo "$PACKAGE" >> missing_main_program.txt
fi
rm result* || true
done