openSUSE / golang-packaging

golang packaging tool for openSUSE
GNU General Public License v3.0
6 stars 13 forks source link

gobuild expand issue #36

Open alexandrevicenzi opened 3 years ago

alexandrevicenzi commented 3 years ago

I noticed something that does not seem right. %gobuild seems to get lost and expands to something that is broken.

The following code:

%gobuild -ldflags "-X %{goipath}/pkg/version.Version=$VERSION -X %{goipath}/pkg/version.GitCommit=$COMMIT"`

Expands to:

go install -v -p 4 -x -buildmode=pie -ldflags github.com/rancher/k3s/-X github.com/rancher/k3s/pkg/version.Version=1.21.3 -X github.com/rancher/k3s/pkg/version.GitCommit=v1.21.3+k3s1

Note that for some reason -ldflags is wrong, the project name was injected into the middle of the variable. Since -ldflags is now invalid, the build will fail.

The following code:

%gobuild -ldflags "-X %{goipath}/pkg/version.Version=$VERSION -X %{goipath}/pkg/version.GitCommit=$COMMIT" cmd/k3s

Expands to:

go install -v -p 4 -x -buildmode=pie -ldflags '-X github.com/rancher/k3s/pkg/version.Version=1.21.3 -X github.com/rancher/k3s/pkg/version.GitCommit=v1.21.3+k3s1' github.com/rancher/k3s/cmd/k3s

Note that this works, it injects the project name after -ldflags values.

skazi0 commented 2 years ago

If you pass any arguments to %gobuild, the last one is interpreted as "importpath modifier". There were some nice examples included in macros.go but they were "refactored out". Check last version here: https://github.com/openSUSE/golang-packaging/blob/3229c62bb83d710c0994661f6c98099924fcc39a/macros.go#L61