#40 Try again to fix failures with https://fedoraproject.org/wiki/Changes/SetBuildFlagsBuildCheck
Merged 5 months ago by gotmax23. Opened 5 months ago by tstellar.
tstellar/go-rpm-macros ld-flags-fix-v2  into  master

@@ -29,11 +29,7 @@ 

  #

  #    %make GOBUILDFLAGS="%gobuildflags"

  #

- 

- # Remove unsupported LDFLAGS

- %golang_filter_ldflags %(echo "$LDFLAGS" | sed -e 's/-Wl,-z,relro//')

- 

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

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

  

  # Turn off Go modules

  %gomodulesmode GO111MODULE=off
@@ -41,6 +37,10 @@ 

  # Define commands for building

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

  %gobuild(o:) %{expand:

+   # https://pagure.io/go-rpm-macros/pull-request/38

+   # Most of the default LDFLAGS for Fedora are not supported so we don't want

+   # LDFLAGS to be automatically initialized with the Fedora flags.

+   %undefine _auto_set_build_flags

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

    %global _dwz_low_mem_die_limit 0

    %{?gobuilddir:GOPATH="%{gobuilddir}:${GOPATH:+${GOPATH}:}%{?gopath}"} %{?gomodulesmode} \\
@@ -51,4 +51,7 @@ 

  # Define commands for testing

  %gotestflags      %{gocompilerflags}

  %gotestextldflags %__global_ldflags %{?__golang_extldflags}

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

+ %gotest() %{

+   %undefine _auto_set_build_flags

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

+ }

file modified
+1 -2
@@ -350,8 +350,7 @@ 

          zsuffix = "-z " .. suffix .. " "

    end

    print(rpm.expand('%goenv ' .. zsuffix        .. myenvflags   .. '\\n'               ..

-                    '%{?currentgoldflags:LDFLAGS="%{golang_filter_ldflags} '           ..

-                    '%{?currentgoldflags}" }'                                          ..

+                    '%{?currentgoldflags:LDFLAGS="${LDFLAGS} %{?currentgoldflags}" }'   ..

                     '%{?gotestflags:GO_TEST_FLAGS="%{gotestflags}" }'                  ..

                     '%{?gotestextldflags:GO_TEST_EXT_LD_FLAGS="%{gotestextldflags}" }' ..

                     'go-rpm-integration check ' .. mycheckflags .. '\\n'))

The original fix wasn't working correctly, because %golang_filter_ldflags was expanded before $LDFLAGS was set. This new fixes complete disables the new automatic %set_build_flag call in spec files that use %gobuild or %gotest.

This looks good to me. I tested it on copr and confirmed that it works properly.

Pull-Request has been merged by gotmax23

5 months ago

@gotmax23 @tstellar This is not working for me in %check:
https://copr.fedorainfracloud.org/coprs/eclipseo/gotests2/build/3259438/

I have:

go-rpm-macros x86_64 3.0.14-1.fc36 https_kojipkgs_fedoraproject_org_repos_f36_build_latest_basearch 34 k

But it still fails in %check:

Executing(%check): /bin/sh -e /var/tmp/rpm-tmp.2ahsVB
+ umask 022
+ cd /builddir/build/BUILD
+ CFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection'
+ export CFLAGS
+ CXXFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection'
+ export CXXFLAGS
+ FFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I/usr/lib64/gfortran/modules'
+ export FFLAGS
+ FCFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I/usr/lib64/gfortran/modules'
+ export FCFLAGS
+ LDFLAGS='-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/oras-go-1.1.0/.package_note-golang-oras-1.1.0-1.fc36.x86_64.ld'
+ export LDFLAGS
+ LT_SYS_LIBRARY_PATH=/usr/lib64:
+ export LT_SYS_LIBRARY_PATH
+ CC=gcc
+ export CC
+ CXX=g++
+ export CXX
+ '[' -f /usr/lib/rpm/generate-rpm-note.sh ']'
+ /usr/lib/rpm/generate-rpm-note.sh golang-oras 1.1.0-1.fc36 x86_64
+ cd oras-go-1.1.0
+ LDFLAGS='-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/oras-go-1.1.0/.package_note-golang-oras-1.1.0-1.fc36.x86_64.ld -X oras.land/oras-go/version=1.1.0'
+ GO_TEST_FLAGS='-buildmode pie -compiler gc'
+ GO_TEST_EXT_LD_FLAGS='-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/oras-go-1.1.0/.package_note-golang-oras-1.1.0-1.fc36.x86_64.ld '
+ go-rpm-integration check -i oras.land/oras-go -b /builddir/build/BUILD/oras-go-1.1.0/_build/bin -s /builddir/build/BUILD/oras-go-1.1.0/_build -V 1.1.0-1.fc36 -p /builddir/build/BUILDROOT/golang-oras-1.1.0-1.fc36.x86_64 -g /usr/share/gocode -r '.*example.*'
Testing    in: /builddir/build/BUILD/oras-go-1.1.0/_build/src
         PATH: /builddir/build/BUILD/oras-go-1.1.0/_build/bin:/builddir/.local/bin:/builddir/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
       GOPATH: /builddir/build/BUILD/oras-go-1.1.0/_build:/usr/share/gocode
  GO111MODULE: off
      command: go test -buildmode pie -compiler gc -ldflags "-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/oras-go-1.1.0/.package_note-golang-oras-1.1.0-1.fc36.x86_64.ld -X oras.land/oras-go/version=1.1.0 -extldflags '-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/oras-go-1.1.0/.package_note-golang-oras-1.1.0-1.fc36.x86_64.ld '"
      testing: oras.land/oras-go
oras.land/oras-go/pkg/artifact
?       oras.land/oras-go/pkg/artifact  [no test files]
oras.land/oras-go/pkg/auth
# oras.land/oras-go/pkg/auth.test
flag provided but not defined: -Wl,-z,relro

Are you sure that you're using the latest version of go-rpm-macros that I pushed to Rawhide in your copr? I did not see this problem.

Yes I have version 3.0.14-1.fc36 from the f36 repo: https_kojipkgs_fedoraproject_org_repos_f36_build_latest_basearch

Same here with a package that was imported 2 days ago that started to fail today:

https://koschei.fedoraproject.org/package/golang-github-sagikazarmark-crypt?collection=f36

And another package that also is failing:

https://koji.fedoraproject.org/koji/taskinfo?taskID=82103130

It seems that this is failing on packages that contain %gocheck but not %gobuild, because %undefine _auto_set_build_flags is included in the %gobuild definition but not the %gocheck definition. I apologize for the breakage I caused!

It seems that this is failing on packages that contain %gocheck but not %gobuild, because %undefine _auto_set_build_flags is included in the %gobuild definition but not the %gocheck definition. I apologize for the breakage I caused!

https://pagure.io/go-rpm-macros/pull-request/42 should fix the issue. Can you please take a look?