Merge pull request #298847 from ShamrockLee/build-go-module-buildflag

buildGoModule: warn about buildFlags only when using buildPhase provided by buildGoModule

authored by Wael Nasreddine and committed by GitHub 7c4cc647 f570a4f0

+11 -9
+11 -9
pkgs/build-support/go/module.nix
··· 163 163 inherit (go) GOOS GOARCH; 164 164 165 165 GOFLAGS = GOFLAGS 166 - ++ lib.optional (!proxyVendor) "-mod=vendor" 167 - ++ lib.optional (!allowGoReference) "-trimpath"; 166 + ++ lib.warnIf (lib.any (lib.hasPrefix "-mod=") GOFLAGS) "use `proxyVendor` to control Go module/vendor behavior instead of setting `-mod=` in GOFLAGS" 167 + (lib.optional (!proxyVendor) "-mod=vendor") 168 + ++ lib.warnIf (builtins.elem "-trimpath" GOFLAGS) "`-trimpath` is added by default to GOFLAGS by buildGoModule when allowGoReference isn't set to true" 169 + (lib.optional (!allowGoReference) "-trimpath"); 168 170 inherit CGO_ENABLED enableParallelBuilding GO111MODULE GOTOOLCHAIN; 169 171 170 172 # If not set to an explicit value, set the buildid empty for reproducibility. ··· 196 198 runHook postConfigure 197 199 ''); 198 200 199 - buildPhase = args.buildPhase or ('' 201 + buildPhase = args.buildPhase or ( 202 + lib.warnIf (buildFlags != "" || buildFlagsArray != "") 203 + "Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`" 204 + lib.warnIf (builtins.elem "-buildid=" ldflags) 205 + "`-buildid=` is set by default as ldflag by buildGoModule" 206 + '' 200 207 runHook preBuild 201 208 202 209 exclude='\(/_\|examples\|Godeps\|testdata' ··· 313 320 } // meta; 314 321 }); 315 322 in 316 - lib.warnIf (buildFlags != "" || buildFlagsArray != "") 317 - "Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`" 318 - lib.warnIf (builtins.elem "-buildid=" ldflags) "`-buildid=` is set by default as ldflag by buildGoModule" 319 - lib.warnIf (builtins.elem "-trimpath" GOFLAGS) "`-trimpath` is added by default to GOFLAGS by buildGoModule when allowGoReference isn't set to true" 320 - lib.warnIf (lib.any (lib.hasPrefix "-mod=") GOFLAGS) "use `proxyVendor` to control Go module/vendor behavior instead of setting `-mod=` in GOFLAGS" 321 - package 323 + package