diff --git a/.gitignore b/.gitignore index 14f2922..2a1edc3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ SOURCES/go-rpm-macros-3.6.0.tar.gz +SOURCES/golist-0.10.4-vendor.tar.xz SOURCES/golist-0.10.4.tar.gz diff --git a/.go-rpm-macros.metadata b/.go-rpm-macros.metadata index f64db2c..2712a12 100644 --- a/.go-rpm-macros.metadata +++ b/.go-rpm-macros.metadata @@ -1,2 +1,3 @@ 9db262bd1b5acd1c3490d55b839819a878e6659c SOURCES/go-rpm-macros-3.6.0.tar.gz +d372835dbdb7c93e1c3ec0b7d1d4957dd860ac6c SOURCES/golist-0.10.4-vendor.tar.xz 4a105131658d029fe0b2d312b078a056748af2b4 SOURCES/golist-0.10.4.tar.gz diff --git a/SOURCES/golist-bootstrap-cli-no-vendor.patch b/SOURCES/golist-bootstrap-cli-no-vendor.patch deleted file mode 100644 index e8bc793..0000000 --- a/SOURCES/golist-bootstrap-cli-no-vendor.patch +++ /dev/null @@ -1,322 +0,0 @@ -diff --git a/cmd/golist/golist.go b/cmd/golist/golist.go -index ee028ae..e9c038d 100644 ---- a/cmd/golist/golist.go -+++ b/cmd/golist/golist.go -@@ -11,9 +11,8 @@ import ( - "strings" - "text/template" - -- "github.com/urfave/cli" -- - "pagure.io/golist/pkg/util" -+ "pagure.io/golist/pkg/cli" - ) - - var ( -@@ -100,7 +99,6 @@ func main() { - } - - app.Action = func(c *cli.Context) error { -- - if len(c.StringSlice("package-path")) == 0 { - return fmt.Errorf("--package-path is not set") - } -diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go -new file mode 100644 -index 0000000..ec91056 ---- /dev/null -+++ b/pkg/cli/cli.go -@@ -0,0 +1,293 @@ -+package cli -+ -+/* golist uses a very small portion of functionality -+ from github.com/urfave/cli. This module provides -+ minimal substitute API implementations for only the -+ core functionality used by golist, for the purpose of -+ bootstrapping golist without additional dependencies. -+*/ -+ -+import ( -+ "strings" -+ "fmt" -+ "os" -+) -+ -+type String string -+type StringSlice []string -+type Bool bool -+ -+type Flag interface { -+ name() string -+ usage() string -+} -+ -+type BoolFlag struct { -+ Name string -+ Usage string -+ Value bool -+} -+ -+type StringFlag struct { -+ Name string -+ Usage string -+ Value string -+} -+ -+type StringSliceFlag struct { -+ Name string -+ Usage string -+ Value *StringSlice -+} -+ -+type App struct { -+ Name string -+ Usage string -+ Version string -+ Flags []Flag -+ Action func(*Context) error -+ -+} -+ -+func NewApp() App { -+ var a App -+ return a -+} -+ -+func (a *App) Run(osArgs []string) error { -+ c, err := newContext(a.Flags, osArgs) -+ if err != nil { -+ return err -+ } -+ if c.Bool("help") { -+ a.PrintHelp() -+ os.Exit(0) -+ } -+ return a.Action(c) -+} -+ -+func (a *App) PrintHelp() { -+ maxNameLen := 0 -+ for _, flag := range a.Flags { -+ length := len(flag.name()) -+ if length > maxNameLen { -+ maxNameLen = length -+ } -+ } -+ fmtSpec := "%-" + fmt.Sprintf("%v", maxNameLen + 6) + "s\t%s\n" -+ fmt.Printf("%s - %s\n", a.Name, a.Usage) -+ fmt.Printf("Options:\n") -+ for _, flag := range a.Flags { -+ flagNameSlice := append([]string{canonicalName(flag)}, alternateNames(flag)...) -+ for i, _ := range flagNameSlice { -+ if len(flagNameSlice[i]) > 1 { -+ flagNameSlice[i] = fmt.Sprintf("--%s", flagNameSlice[i]) -+ } else { -+ flagNameSlice[i] = fmt.Sprintf("-%s", flagNameSlice[i]) -+ } -+ } -+ flagNameStr := strings.Join(flagNameSlice, ", ") -+ switch flag.(type) { -+ case StringFlag: -+ flagNameStr = fmt.Sprintf(" %s value", flagNameStr) -+ case StringSliceFlag: -+ flagNameStr = fmt.Sprintf(" %s value", flagNameStr) -+ case BoolFlag: -+ flagNameStr = fmt.Sprintf(" %s", flagNameStr) -+ } -+ fmt.Printf(fmtSpec, flagNameStr, flag.usage()) -+ } -+} -+ -+ -+type Context struct { -+ flagValues map[string]interface{} -+ flagDecls map[string]Flag -+ altFlags map[string]string -+ positionalArgs []string -+} -+ -+func (c *Context) Bool(flag string) bool { -+ iface, ok := c.flagDecls[flag] -+ if !ok { -+ panic("undefined flag" + flag) -+ } -+ switch iface.(type) { -+ case BoolFlag: -+ break -+ default: -+ panic("flag type mismatch - expected BoolFlag, got: " + flag) -+ } -+ val, ok := c.flagValues[flag] -+ if !ok { -+ return iface.(BoolFlag).Value -+ } -+ return val.(bool) -+} -+ -+func (c *Context) String(flag string) string { -+ iface, ok := c.flagDecls[flag] -+ if !ok { -+ panic("undefined flag" + flag) -+ } -+ switch iface.(type) { -+ case StringFlag: -+ break -+ default: -+ panic("flag type mismatch - expected StringFlag, got: " + flag) -+ } -+ val, ok:= c.flagValues[flag] -+ if !ok { -+ return iface.(StringFlag).Value -+ } -+ return val.(string) -+} -+ -+func (c *Context) StringSlice(flag string) []string { -+ iface, ok := c.flagDecls[flag]; -+ if !ok { -+ panic("undefined flag" + flag) -+ } -+ switch iface.(type) { -+ case StringSliceFlag: -+ break -+ default: -+ panic("flag type mismatch - expected StringSliceFlag, got: " + flag) -+ } -+ val, ok := c.flagValues[flag] -+ if !ok { -+ val = iface.(StringSliceFlag).Value -+ if val != nil { -+ return []string{} -+ } -+ } -+ return val.([]string) -+} -+ -+// Create a hash mapping from flag names to declarations -+// and alt names to flag names. -+func (c *Context) setupFlags(flagDecls []Flag) error { -+ helpFlag := BoolFlag { -+ Name: "help, h", -+ Usage: "Show help message", -+ } -+ flagDecls = append(flagDecls, helpFlag) -+ for _, flag := range flagDecls { -+ flagName := canonicalName(flag) -+ if _, ok:= c.flagDecls[flagName]; ok { -+ return fmt.Errorf("cannot redeclare flag: %s", flagName) -+ } -+ c.flagDecls[flagName] = flag -+ altFlagNames := alternateNames(flag) -+ for _, altName := range altFlagNames { -+ c.altFlags[altName] = flagName -+ } -+ } -+ return nil -+} -+ -+func (c *Context) parseArgs(osArgs []string) error { -+ // process command line arguments as a stream of tokens. -+ // operations consume the first token in the stream until -+ // the stream is empty. -+ argStream := osArgs -+ for len(argStream) > 0 { -+ arg := argStream[0] -+ if ! isFlag(arg) { -+ argStream = argStream[1:] -+ c.positionalArgs = append(c.positionalArgs, arg) -+ -+ } else { -+ arg = trimFlag(arg) -+ if _, ok:= c.altFlags[arg]; ok { -+ arg = c.altFlags[arg] -+ } -+ iface, ok := c.flagDecls[arg] -+ if !ok { -+ return fmt.Errorf("unexpected argument: %v", arg) -+ } -+ switch flag := iface.(type) { -+ case StringFlag: -+ argStream = argStream[1:] -+ if len(argStream) == 0 { -+ return fmt.Errorf("expected value for argument: %v", arg) -+ } -+ if isFlag(argStream[0]) { -+ return fmt.Errorf("unexpected flag: %v", arg) -+ } -+ c.flagValues[arg] = argStream[0] -+ case StringSliceFlag: -+ argStream = argStream[1:] -+ if len (argStream) == 0 { -+ return fmt.Errorf("expected value for argument: %v", arg) -+ } -+ if isFlag(argStream[0]) { -+ return fmt.Errorf("unexpected flag: %v", arg) -+ } -+ c.flagValues[arg] = make([]string, 0) -+ c.flagValues[arg] = append(c.flagValues[arg].([]string), argStream[0]) -+ argStream = argStream[1:] -+ for len(argStream) > 0 && ! isFlag(argStream[0]) { -+ c.flagValues[arg] = append(c.flagValues[arg].([]string), argStream[0]) -+ argStream = argStream[1:] -+ } -+ case BoolFlag: -+ argStream = argStream[1:] -+ c.flagValues[canonicalName(flag)] = true -+ default: -+ return fmt.Errorf("unexpected flag: %v", arg) -+ } -+ } -+ } -+ return nil -+} -+ -+func newContext(flags []Flag, osArgs []string) (*Context, error) { -+ var c Context -+ c.flagValues = make(map[string]interface{}) -+ c.flagDecls = make(map[string]Flag) -+ c.altFlags = make(map[string]string) -+ c.altFlags = make(map[string]string) -+ if err := c.setupFlags(flags); err != nil { -+ return nil, err -+ } -+ if err := c.parseArgs(osArgs); err != nil { -+ return nil, err -+ } -+ return &c, nil -+} -+ -+func (f StringFlag) name() string {return f.Name} -+func (f StringFlag) usage() string {return f.Usage} -+func (f BoolFlag) name() string {return f.Name} -+func (f BoolFlag) usage() string {return f.Usage} -+func (f StringSliceFlag) name() string {return f.Name} -+func (f StringSliceFlag) usage() string {return f.Usage} -+ -+// takes a Flag with a comma delimited string -+// of flag names and returns the first one -+func canonicalName(flag Flag) string { -+ flagNames := strings.Split(flag.name(), ",") -+ return strings.TrimSpace(flagNames[0]) -+} -+ -+// takes a Flag with a comma delimited string -+// of flag names and returns them as a string slice -+// with the canonical (first) flag ommitted -+func alternateNames(flag Flag) []string { -+ flagNames := strings.Split(flag.name(), ",") -+ altNames := flagNames[1:] -+ for i, _ := range altNames { -+ altNames[i] = strings.TrimSpace(altNames[i]) -+ } -+ return altNames -+} -+ -+func isFlag(arg string) bool { -+ return strings.HasPrefix(arg, "-") -+} -+ -+func trimFlag(arg string) string { -+ return strings.Trim(strings.Trim(arg, "-"), "-") -+} -+ diff --git a/SPECS/go-rpm-macros.spec b/SPECS/go-rpm-macros.spec index f9f2147..6d3b67e 100644 --- a/SPECS/go-rpm-macros.spec +++ b/SPECS/go-rpm-macros.spec @@ -18,25 +18,26 @@ Version: 3.6.0 # make Go devel packages archful %global gopath %{_datadir}/gocode -# whether to bundle golist or require it as a dependency %global bundle_golist 1 -%if 0%{?bundle_golist} -# do not create debuginfo packages when we add a build section -%global debug_package %{nil} %global golist_version 0.10.4 -%global golist_builddir %{_builddir}/golist-%{golist_version}/_build +%if 0%{?bundle_golist} +%global golist_builddir golist-%{golist_version} %global golist_goipath pagure.io/golist # where to bundle the golist executable -%global golist_execdir %{_libexecdir}/go-rpm-macros/ +%global golist_execdir %{_libexecdir}/go-rpm-macros # define gobuild to avoid this package requiring itself to build -%define gobuild(o:) GO111MODULE=off go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '" -a -v %{?**}; +%undefine _auto_set_build_flags +%global _dwz_low_mem_die_limit 0 +%define gobuild(o:) GO111MODULE=on go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${GO_BUILDTAGS-${BUILDTAGS-}}" -a -v -x -ldflags "${GO_LDFLAGS-${LDFLAGS-}} -B 0x$(echo "%{name}-%{version}-%{release}-${SOURCE_DATE_EPOCH:-}" | sha1sum | cut -d ' ' -f1) -compressdwarf=false -linkmode=external -extldflags '%{build_ldflags}'" %{?**}; +%else +%global debug_package %{nil} %endif ExclusiveArch: %{golang_arches} %{gccgo_arches} Name: go-rpm-macros -Release: 3%{?dist} +Release: 10%{?dist} Summary: Build-stage rpm automation for Go packages License: GPLv3+ @@ -44,6 +45,11 @@ URL: %{forgeurl} Source0: %{forgesource} %if 0%{?bundle_golist} Source1: https://pagure.io/golist/archive/v%{golist_version}/golist-%{golist_version}.tar.gz +# vendored dependency tarball, to create: +# tar xf golist-%%{golist_version}.tar.gz ; pushd golist-%%{golist_version} ; \ +# go mod init %%{golist_goipath} && go mod tidy && go mod vendor && \ +# tar Jcf ../golist-%%{golist_version}-vendor.tar.xz go.mod go.sum vendor/ ; popd +Source2: golist-%{golist_version}-vendor.tar.xz %endif Requires: go-srpm-macros = %{version}-%{release} @@ -51,6 +57,7 @@ Requires: go-filesystem = %{version}-%{release} %if 0%{?bundle_golist} BuildRequires: golang +Provides: bundled(golist) = %{golist_version} %else Requires: golist %endif @@ -69,10 +76,6 @@ Provides: compiler(go-compiler) = 1 Obsoletes: go-compilers-gcc-go-compiler < %{version}-%{release} %endif -# Replace golang-github-urfave-cli with a minimal -# command line parser backend to bootstrap golist -# without dependencies. -Patch1: golist-bootstrap-cli-no-vendor.patch # Add libexec to PATH in order to launch golist in every script Patch2: 0001-Add-libexec-to-path-for-EPEL9-golist.patch @@ -141,41 +144,35 @@ done # unpack golist and patch %if 0%{?bundle_golist} # Add libexec to PATH -%patch2 -p1 -pushd %{_builddir} -tar -xf %{_sourcedir}/golist-%{golist_version}.tar.gz -cd golist-%{golist_version} -%patch1 -p1 -cp %{_builddir}/golist-%{golist_version}/LICENSE %{_builddir}/go-rpm-macros-%{version}/LICENSE-golist +%patch -P 2 -p1 +tar -xf %{SOURCE1} +tar -C %{golist_builddir} -xf %{SOURCE2} +pushd %{golist_builddir} popd - -# create directory structure for a Go build -if [[ ! -e %{golist_builddir}/bin ]]; then - install -m 0755 -vd %{golist_builddir}/bin - export GOPATH=%{golist_builddir}:${GOPATH:+${GOPATH}:}/usr/share/gocode -fi -if [[ ! -e %{golist_builddir}/src/%{golist_goipath} ]]; then - install -m 0755 -vd %{golist_builddir}/src/pagure.io - ln -sf $(dirname %{golist_builddir}) %{golist_builddir}/src/%{golist_goipath} - -fi +cp %{golist_builddir}/LICENSE LICENSE-golist %endif -%patch3 -p1 -%patch4 -p1 +%patch -P 3 -p1 +%patch -P 4 -p1 %build # build golist %if 0%{?bundle_golist} -pushd %{golist_builddir}/src/%{golist_goipath} -export GOPATH=%{golist_builddir}:${GOPATH:+${GOPATH}:}/usr/share/gocode +pushd %{golist_builddir} for cmd in cmd/* ; do - %gobuild -o %{golist_builddir}/bin/$(basename $cmd) %{golist_goipath}/$cmd + %gobuild -o bin/$(basename $cmd) ./$cmd done popd %endif %install +install -m 0755 -vd %{buildroot}%{rpmmacrodir} + +install -m 0755 -vd %{buildroot}%{_rpmluadir}/fedora/srpm +install -m 0644 -vp rpm/lua/srpm/*lua \ + %{buildroot}%{_rpmluadir}/fedora/srpm + +%ifarch %{golang_arches} %{gccgo_arches} # Some of those probably do not work with gcc-go right now # This is not intentional, but mips is not a primary Fedora architecture # Patches and PRs are welcome @@ -184,20 +181,14 @@ install -m 0755 -vd %{buildroot}%{gopath}/src install -m 0755 -vd %{buildroot}%{_spectemplatedir} -if ls templates/rpm/*\.spec; then - install -m 0644 -vp templates/rpm/*spec \ - %{buildroot}%{_spectemplatedir} -fi +install -m 0644 -vp templates/rpm/*spec \ + %{buildroot}%{_spectemplatedir} install -m 0755 -vd %{buildroot}%{_bindir} install -m 0755 bin/* %{buildroot}%{_bindir} -install -m 0755 -vd %{buildroot}%{rpmmacrodir} -install -m 0644 -vp rpm/macros.d/macros.go-* \ +install -m 0644 -vp rpm/macros.d/macros.go-*rpm* \ %{buildroot}%{rpmmacrodir} -install -m 0755 -vd %{buildroot}%{_rpmluadir}/fedora/srpm -install -m 0644 -vp rpm/lua/srpm/*lua \ - %{buildroot}%{_rpmluadir}/fedora/srpm install -m 0755 -vd %{buildroot}%{_rpmluadir}/fedora/rpm install -m 0644 -vp rpm/lua/rpm/*lua \ %{buildroot}%{_rpmluadir}/fedora/rpm @@ -206,47 +197,50 @@ install -m 0644 -vp rpm/fileattrs/*.attr \ %{buildroot}%{_rpmconfigdir}/fileattrs/ install -m 0755 -vp rpm/*\.{prov,deps} \ %{buildroot}%{_rpmconfigdir}/ +%else +install -m 0644 -vp rpm/macros.d/macros.go-srpm \ + %{buildroot}%{rpmmacrodir} +%endif %ifarch %{golang_arches} -install -m 0644 -vp rpm/macros.d/macros.go-compilers-golang \ - %{buildroot}%{_rpmconfigdir}/macros.d/macros.go-compiler-golang +install -m 0644 -vp rpm/macros.d/macros.go-compilers-golang{,-pie} \ + %{buildroot}%{_rpmconfigdir}/macros.d/ %endif %ifarch %{gccgo_arches} install -m 0644 -vp rpm/macros.d/macros.go-compilers-gcc \ - %{buildroot}%{_rpmconfigdir}/macros.d/macros.go-compiler-gcc + %{buildroot}%{_rpmconfigdir}/macros.d/ %endif # install golist %if 0%{?bundle_golist} install -m 0755 -vd %{buildroot}%{golist_execdir} install -m 0755 -vp %{golist_builddir}/bin/* %{buildroot}%{golist_execdir}/ +sed -i "s,golist ,%{golist_execdir}/golist ,g" \ + %{buildroot}%{_bindir}/go-rpm-integration \ + %{buildroot}%{_rpmconfigdir}/gosymlink.deps \ + %{buildroot}%{_rpmmacrodir}/macros.go-rpm %endif +%ifarch %{golang_arches} %{gccgo_arches} %files -%license LICENSE.txt LICENSE-golist +%license LICENSE.txt +%if %{defined bundle_golist} +%license LICENSE-golist %{golist_builddir}/vendor/modules.txt +%endif %doc README.md %{_bindir}/* %{_rpmconfigdir}/fileattrs/*.attr %{_rpmconfigdir}/*.prov %{_rpmconfigdir}/*.deps -%{_rpmconfigdir}/macros.d/macros.go-rpm* -%{_rpmconfigdir}/macros.d/macros.go-compiler* +%{_rpmmacrodir}/macros.go-rpm* +%{_rpmmacrodir}/macros.go-compiler* %{_rpmluadir}/fedora/rpm/*.lua # package golist %if 0%{?bundle_golist} %{golist_execdir}/golist %endif -%files -n go-srpm-macros -%license LICENSE.txt -%doc README.md -%{_rpmconfigdir}/macros.d/macros.go-srpm -%{_rpmluadir}/fedora/srpm/*.lua - -%files -n go-filesystem -%dir %{gopath} -%dir %{gopath}/src %files -n go-rpm-templates %license LICENSE-templates.txt @@ -256,7 +250,41 @@ install -m 0755 -vp %{golist_builddir}/bin/* %{buildroot}%{golist_execdir}/ %dir %{_spectemplatedir} %{_spectemplatedir}/*.spec +%files -n go-filesystem +%dir %{gopath} +%dir %{gopath}/src +%endif + +# we only build go-srpm-macros on all architectures +%files -n go-srpm-macros +%license LICENSE.txt +%doc README.md +%{_rpmmacrodir}/macros.go-srpm +%{_rpmluadir}/fedora/srpm/*.lua + %changelog +* Fri Apr 11 2025 Alejandro Sáez - 3.6.0-10 +- Add full golist implementation +- Resolves: RHEL-86879 +- Resolves: RHEL-86880 + +* Wed Nov 13 2024 Alejandro Sáez +- Revert go-rpm-templates to noarch +- Resolves: RHEL-67300 +- Related: RHEL-52226 + +* Wed Nov 06 2024 Alejandro Sáez - 3.6.0-6 +- Add back again ExclusiveArch, it was removed by mistake. +- Resolves: RHEL-52226 + +* Mon Nov 04 2024 Alejandro Sáez - 3.6.0-5 +- Make golist non optional +- Resolves: RHEL-52226 + +* Thu Oct 31 2024 Alejandro Sáez - 3.6.0-4 +- Enable debuginfo package +- Resolves: RHEL-52226 + * Wed Jul 31 2024 Alejandro Sáez - 3.6.0-3 - Fix typo in add-gobuild-and-gotest.patch - Resolves: RHEL-7437