update raceless

This commit is contained in:
2025-10-28 17:01:12 +00:00
parent 9fe0bbaefe
commit e22fe24f3a

View File

@@ -1,36 +1,33 @@
{ pkgs, go }:
let
go-wrapper = pkgs.writeShellApplication {
name = "go";
text = ''
args=("$@")
new_args=()
has_test=false
found_race=false
go-script = pkgs.writeShellScript "go-raceless" ''
args=("$@")
new_args=()
has_test=false
found_race=false
for arg in "''${args[@]}"; do
if [[ "$arg" == "test" ]]; then
has_test=true
fi
done
for arg in "''${args[@]}"; do
if [[ "$arg" == "test" ]]; then
has_test=true
fi
done
if [[ "$has_test" == "true" ]]; then
for arg in "''${args[@]}"; do
if [[ "$arg" != "-race" ]]; then
new_args+=("$arg")
else
found_race=true
fi
done
if [[ "$has_test" == "true" ]]; then
for arg in "''${args[@]}"; do
if [[ "$arg" != "-race" ]]; then
new_args+=("$arg")
else
found_race=true
fi
done
if [[ "$found_race" == "true" ]]; then
exec "$REAL_GO" "''${new_args[@]}"
fi
fi
if [[ "$found_race" == "true" ]]; then
exec ${go}/bin/go "''${new_args[@]}"
fi
fi
exec "$REAL_GO" "$@"
'';
};
exec ${go}/bin/go "$@"
'';
preservedAttrs = pkgs.lib.attrsets.getAttrs [
"CGO_ENABLED"
@@ -46,9 +43,8 @@ pkgs.symlinkJoin (
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
rm $out/bin/go
makeWrapper ${go-wrapper}/bin/go $out/bin/go \
--set REAL_GO ${go}/bin/go
cp ${go-script} $out/bin/go
chmod +x $out/bin/go
'';
}
// preservedAttrs