#22 rpm/macros.d: Make disabling Go modules configurable for %gobuild and %gotest
Merged 2 months ago by ngompa. Opened 2 months ago by ngompa.
ngompa/go-rpm-macros add-gomodules-mode-configuration  into  master

@@ -31,12 +31,15 @@ 

  #

  %gobuildflags() %{expand:%{gocompilerflags} -tags=\\"rpm_crashtraceback \\" -ldflags \\"${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'\\" -a -v -x}

  

+ # Turn off Go modules

+ %gomodulesmode GO111MODULE=off

+ 

  # Define commands for building

  # BUILD_ID can be generated for golang build no matter of debuginfo

  %gobuild(o:) %{expand:

    # https://bugzilla.redhat.com/show_bug.cgi?id=995136#c12

    %global _dwz_low_mem_die_limit 0

-   %{?gobuilddir:GOPATH="%{gobuilddir}:${GOPATH:+${GOPATH}:}%{?gopath}"} GO111MODULE=off \\

+   %{?gobuilddir:GOPATH="%{gobuilddir}:${GOPATH:+${GOPATH}:}%{?gopath}"} %{?gomodulesmode} \\

    go build %{?gocompilerflags} -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x %{?**};

  }

  ${workroot}${GOPATH:+:${GOPATH}}

@@ -44,4 +47,4 @@ 

  # Define commands for testing

  %gotestflags      %{gocompilerflags}

  %gotestextldflags %__global_ldflags %{?__golang_extldflags}

- %gotest() GO111MODULE=off go test %{gotestflags} -ldflags "${LDFLAGS:-}%{?currentgoldflags} -extldflags '%{gotestextldflags}'" %{?**};

+ %gotest() %{?gomodulesmode} go test %{gotestflags} -ldflags "${LDFLAGS:-}%{?currentgoldflags} -extldflags '%{gotestextldflags}'" %{?**};

Having this unconditionally disabled without some way to change it
causes more heartache for downstream users than necessary.

It doesn't hurt to make it default to disable it while providing a
way for downstream users who need the Go module features (e.g. in COPR)
to be able to use them.

I know we have this flag set elsewhere in our macros, but I'm not sure how to make that a control everywhere. Moreover, I really only need it for %gobuild and %gotest...

rebased onto 57c7006

2 months ago

@ngompa: please stay coherent with the exising macros and do not use __ prefixing

Apart from that, why not, but enabling modules will break things right and left, so it’s a fire yourself in the foot setting

(go commands will start downloading right and left, go packahe naming resolution will fail because modules have special rules for versions in the import path, etc)

rebased onto df8452a

2 months ago

(go commands will start downloading right and left, go packahe naming resolution will fail because modules have special rules for versions in the import path, etc)

I'm aware of this, but if I'm only using %gobuild and %gotest in a package build that allows downloads and such (or has vendored modules), it should be fine.

@ngompa: please stay coherent with the exising macros and do not use __ prefixing

I dropped the prefix.

Pull-Request has been merged by ngompa

2 months ago
Metadata