Skip to content

Commit 280b7f4

Browse files
author
Paul Whalen
committed
refactor: switch to standard Go vendoring for cross-distro packaging
Replace go-vendor-tools with standard Go module vendoring to support building on both Fedora and CentOS/RHEL with a single spec file. Changes: - Use `go mod vendor` + `tar` to create separate vendor tarball at release time via packit's create-archive action - Source0: project source from git archive (no vendor/) - Source1: vendor tarball created by `go mod vendor` - Remove go-vendor-tools dependency (EPEL-only package) - Remove %generate_buildrequires and %go_generate_buildrequires macros - Add vendor/ to .gitignore Signed-off-by: Paul Whalen <[email protected]>
1 parent 2d5efec commit 280b7f4

File tree

3 files changed

+19
-29
lines changed

3 files changed

+19
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ go.work.sum
66
go-fdo-client
77
go-fdo-client-*.tar.gz
88
rpmbuild
9+
vendor/

Makefile

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ PROJECT := go-fdo-client
66
SOURCEDIR := $(CURDIR)/build/package/rpm
77
SPEC_FILE_NAME := $(PROJECT).spec
88
SPEC_FILE := $(SOURCEDIR)/$(SPEC_FILE_NAME)
9-
GO_VENDOR_TOOLS_FILE := $(SOURCEDIR)/go-vendor-tools.toml
10-
GO_VENDOR_TOOLS_FILE_NAME := go-vendor-tools.toml
119

1210
SOURCE_TARBALL := $(SOURCEDIR)/$(PROJECT)-$(VERSION).tar.gz
1311
VENDOR_TARBALL := $(SOURCEDIR)/$(PROJECT)-$(VERSION)-vendor.tar.gz
@@ -37,20 +35,19 @@ test:
3735
vendor-tarball: $(VENDOR_TARBALL)
3836

3937
$(VENDOR_TARBALL):
38+
@echo "Creating vendor tarball..."
4039
rm -rf vendor; \
41-
command -v go_vendor_archive || sudo dnf install -y go-vendor-tools python3-tomlkit; \
42-
go_vendor_archive create --compression gz --config $(GO_VENDOR_TOOLS_FILE) --write-config --output $(VENDOR_TARBALL) .; \
43-
rm -rf vendor;
40+
go mod vendor; \
41+
tar -czf $(VENDOR_TARBALL) vendor/; \
42+
rm -rf vendor
4443

4544
packit-create-archive: $(SOURCE_TARBALL) $(VENDOR_TARBALL)
46-
@ls -1 "$(SOURCE_TARBALL)" | head -n1
45+
ls -1 $(SOURCE_TARBALL) $(VENDOR_TARBALL)
4746

4847
$(SOURCE_TARBALL):
48+
@echo "Creating source tarball..."
4949
mkdir -p "$(SOURCEDIR)"
50-
git archive --format=tar --prefix="$(PROJECT)-$(VERSION)/" HEAD | gzip > "$(SOURCE_TARBALL)"
51-
52-
vendor-licenses:
53-
go_vendor_license --config "$(GO_VENDOR_TOOLS_FILE)" .
50+
git archive --prefix=$(PROJECT)-$(VERSION)/ --format=tar.gz HEAD > $(SOURCE_TARBALL)
5451

5552
#
5653
# Building packages
@@ -76,7 +73,6 @@ RPMBUILD_SOURCES_DIR := $(RPMBUILD_TOP_DIR)/sources
7673
RPMBUILD_SRPMS_DIR := $(RPMBUILD_TOP_DIR)/srpms
7774
RPMBUILD_BUILDROOT_DIR := $(RPMBUILD_TOP_DIR)/buildroot
7875

79-
RPMBUILD_GOLANG_VENDOR_TOOLS_FILE := $(RPMBUILD_SOURCES_DIR)/$(GO_VENDOR_TOOLS_FILE_NAME)
8076
RPMBUILD_SPECFILE := $(RPMBUILD_SPECS_DIR)/$(PROJECT)-$(VERSION).spec
8177
RPMBUILD_TARBALL := $(RPMBUILD_SOURCES_DIR)/$(PROJECT)-$(VERSION).tar.gz
8278
RPMBUILD_VENDOR_TARBALL := $(RPMBUILD_SOURCES_DIR)/$(PROJECT)-$(VERSION)-vendor.tar.gz
@@ -95,14 +91,9 @@ $(RPMBUILD_TARBALL): $(SOURCE_TARBALL) $(VENDOR_TARBALL)
9591
cp -f $(SOURCE_TARBALL) $(RPMBUILD_TARBALL)
9692
cp -f $(VENDOR_TARBALL) $(RPMBUILD_VENDOR_TARBALL)
9793

98-
# Also copy the vendor tools TOML so macros can read it if needed
99-
$(RPMBUILD_GOLANG_VENDOR_TOOLS_FILE):
100-
mkdir -p $(RPMBUILD_SOURCES_DIR)
101-
cp -f $(GO_VENDOR_TOOLS_FILE) $(RPMBUILD_GOLANG_VENDOR_TOOLS_FILE)
102-
10394
# Build SRPM locally (outputs under ./rpmbuild)
10495
.PHONY: srpm
105-
srpm: $(RPMBUILD_SPECFILE) $(RPMBUILD_TARBALL) $(RPMBUILD_GOLANG_VENDOR_TOOLS_FILE)
96+
srpm: $(RPMBUILD_SPECFILE) $(RPMBUILD_TARBALL)
10697
command -v rpmbuild >/dev/null || { echo "rpmbuild missing"; exit 1; }
10798
rpmbuild -bs \
10899
--define "_topdir $(RPMBUILD_TOP_DIR)" \
@@ -116,7 +107,7 @@ srpm: $(RPMBUILD_SPECFILE) $(RPMBUILD_TARBALL) $(RPMBUILD_GOLANG_VENDOR_TOOLS_FI
116107

117108
# Build binary RPM locally (optional)
118109
.PHONY: rpm
119-
rpm: $(RPMBUILD_SPECFILE) $(RPMBUILD_TARBALL) $(RPMBUILD_GOLANG_VENDOR_TOOLS_FILE)
110+
rpm: $(RPMBUILD_SPECFILE) $(RPMBUILD_TARBALL)
120111
command -v rpmbuild >/dev/null || { echo "rpmbuild missing"; exit 1; }
121112
# Uncomment to auto-install build deps on your host:
122113
# sudo dnf builddep -y $(RPMBUILD_SPECFILE)
@@ -129,3 +120,9 @@ rpm: $(RPMBUILD_SPECFILE) $(RPMBUILD_TARBALL) $(RPMBUILD_GOLANG_VENDOR_TOOLS_FIL
129120
--define "_builddir $(RPMBUILD_BUILD_DIR)" \
130121
--define "_buildrootdir $(RPMBUILD_BUILDROOT_DIR)" \
131122
$(RPMBUILD_SPECFILE)
123+
124+
.PHONY: clean
125+
clean:
126+
rm -rf $(RPMBUILD_TOP_DIR)
127+
rm -rf $(SOURCEDIR)/$(PROJECT)-*.tar.gz
128+
rm -rf vendor

build/package/rpm/go-fdo-client.spec

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ Version: 0
1616
Release: %autorelease -p
1717
Summary: FIDO FDO compliant device on-boarding tool
1818

19-
# Generated by go-vendor-tools
2019
License: Apache-2.0 AND BSD-3-Clause AND MIT
2120
URL: %{gourl}
2221
Source0: %{archivename}.tar.gz
2322
Source1: %{archivename}-vendor.tar.gz
24-
Source2: go-vendor-tools.toml
2523

26-
BuildRequires: go-vendor-tools
24+
BuildRequires: golang >= 1.23
2725
BuildRequires: go-rpm-macros
28-
BuildRequires: golang
2926

3027
%gometa -L -f
3128

@@ -35,26 +32,21 @@ BuildRequires: golang
3532
%autosetup -n %{archivename} -a1
3633
# %autopatch -p1
3734

38-
%generate_buildrequires
39-
%go_vendor_license_buildrequires -c %{S:2}
40-
4135
%build
4236
%global gomodulesmode GO111MODULE=on
4337
%gobuild -o %{gobuilddir}/bin/go-fdo-client %{goipath}
4438

4539
%install
46-
%go_vendor_license_install -c %{S:2}
4740
install -m 0755 -vd %{buildroot}%{_bindir}
4841
install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/
4942

5043
%check
51-
%go_vendor_license_check -c %{S:2}
5244
%if %{with check}
5345
%gotest ./...
5446
%endif
5547

56-
%files -f %{go_vendor_license_filelist}
57-
%license vendor/modules.txt
48+
%files
49+
%license LICENSE vendor/modules.txt
5850
%doc README.md
5951
%{_bindir}/go-fdo-client
6052

0 commit comments

Comments
 (0)