From 6500de413a71678ee741aee7dc7974774091bf18 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 25 Mar 2024 13:09:44 +0800 Subject: buildGoModule: warn about flags only when using provided buildPhase Warn about buildFlags and ldflags only when using buildPhase provided by buildGoModule. This allows developers to use buildFlags in custom buildPhase. --- pkgs/build-support/go/module.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/go/module.nix b/pkgs/build-support/go/module.nix index 6f568c0eb4f95..f3661d532b982 100644 --- a/pkgs/build-support/go/module.nix +++ b/pkgs/build-support/go/module.nix @@ -196,7 +196,12 @@ let runHook postConfigure ''); - buildPhase = args.buildPhase or ('' + buildPhase = args.buildPhase or ( + lib.warnIf (buildFlags != "" || buildFlagsArray != "") + "Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`" + lib.warnIf (builtins.elem "-buildid=" ldflags) + "`-buildid=` is set by default as ldflag by buildGoModule" + '' runHook preBuild exclude='\(/_\|examples\|Godeps\|testdata' @@ -313,9 +318,6 @@ let } // meta; }); in -lib.warnIf (buildFlags != "" || buildFlagsArray != "") - "Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`" -lib.warnIf (builtins.elem "-buildid=" ldflags) "`-buildid=` is set by default as ldflag by buildGoModule" lib.warnIf (builtins.elem "-trimpath" GOFLAGS) "`-trimpath` is added by default to GOFLAGS by buildGoModule when allowGoReference isn't set to true" lib.warnIf (lib.any (lib.hasPrefix "-mod=") GOFLAGS) "use `proxyVendor` to control Go module/vendor behavior instead of setting `-mod=` in GOFLAGS" package -- cgit 1.4.1 From 8d861e611873e55330fc2ef39bbf8591af0aef34 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Thu, 18 Apr 2024 15:13:01 +0000 Subject: buildGoModule: place GOFLAGS-related warnings around GOFLAGS specification Avoid "global" warnings that complicates fixed-point arguments support. --- pkgs/build-support/go/module.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/build-support/go/module.nix b/pkgs/build-support/go/module.nix index f3661d532b982..dce3ddb470909 100644 --- a/pkgs/build-support/go/module.nix +++ b/pkgs/build-support/go/module.nix @@ -163,8 +163,10 @@ let inherit (go) GOOS GOARCH; GOFLAGS = GOFLAGS - ++ lib.optional (!proxyVendor) "-mod=vendor" - ++ lib.optional (!allowGoReference) "-trimpath"; + ++ lib.warnIf (lib.any (lib.hasPrefix "-mod=") GOFLAGS) "use `proxyVendor` to control Go module/vendor behavior instead of setting `-mod=` in GOFLAGS" + (lib.optional (!proxyVendor) "-mod=vendor") + ++ lib.warnIf (builtins.elem "-trimpath" GOFLAGS) "`-trimpath` is added by default to GOFLAGS by buildGoModule when allowGoReference isn't set to true" + (lib.optional (!allowGoReference) "-trimpath"); inherit CGO_ENABLED enableParallelBuilding GO111MODULE GOTOOLCHAIN; # If not set to an explicit value, set the buildid empty for reproducibility. @@ -318,6 +320,4 @@ let } // meta; }); in -lib.warnIf (builtins.elem "-trimpath" GOFLAGS) "`-trimpath` is added by default to GOFLAGS by buildGoModule when allowGoReference isn't set to true" -lib.warnIf (lib.any (lib.hasPrefix "-mod=") GOFLAGS) "use `proxyVendor` to control Go module/vendor behavior instead of setting `-mod=` in GOFLAGS" - package +package -- cgit 1.4.1