From b0637e8470aa027965309d1513534cd714edb9c7 Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Thu, 3 Apr 2025 13:37:00 +0100 Subject: [PATCH] sbom-utility: Fix version, add shell completions --- pkgs/by-name/sb/sbom-utility/name.patch | 13 +++++ pkgs/by-name/sb/sbom-utility/package.nix | 41 +++++++++++++- pkgs/by-name/sb/sbom-utility/stderr.patch | 67 +++++++++++++++++++++++ 3 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 pkgs/by-name/sb/sbom-utility/name.patch create mode 100644 pkgs/by-name/sb/sbom-utility/stderr.patch diff --git a/pkgs/by-name/sb/sbom-utility/name.patch b/pkgs/by-name/sb/sbom-utility/name.patch new file mode 100644 index 000000000000..0edbb05706d4 --- /dev/null +++ b/pkgs/by-name/sb/sbom-utility/name.patch @@ -0,0 +1,13 @@ +diff --git a/cmd/root.go b/cmd/root.go +index 5ef5d46..e99b245 100644 +--- a/cmd/root.go ++++ b/cmd/root.go +@@ -139,7 +139,7 @@ const ( + ) + + var rootCmd = &cobra.Command{ +- Use: fmt.Sprintf("%s [command] [flags]", utils.GlobalFlags.Project), ++ Use: fmt.Sprintf("sbom-utility [command] [flags]"), + SilenceErrors: false, + SilenceUsage: false, + Short: MSG_APP_NAME, diff --git a/pkgs/by-name/sb/sbom-utility/package.nix b/pkgs/by-name/sb/sbom-utility/package.nix index e6f4ac7a5701..6ebfbcbfe73d 100644 --- a/pkgs/by-name/sb/sbom-utility/package.nix +++ b/pkgs/by-name/sb/sbom-utility/package.nix @@ -2,11 +2,18 @@ lib, buildGoModule, fetchFromGitHub, + fetchpatch, + versionCheckHook, + installShellFiles, + stdenv, }: -buildGoModule rec { - pname = "sbom-utility"; +let version = "0.17.0"; +in +buildGoModule { + pname = "sbom-utility"; + inherit version; src = fetchFromGitHub { owner = "CycloneDX"; @@ -17,10 +24,40 @@ buildGoModule rec { vendorHash = "sha256-vyYSir5u6d5nv+2ScrHpasQGER4VFSoLb1FDUDIrtDM="; + patches = [ + # work around https://github.com/CycloneDX/sbom-utility/issues/121, which otherwise + # breaks shell completions + ./name.patch + # Output logs to stderr rather than stdout. + # Patch of https://github.com/CycloneDX/sbom-utility/pull/122, adapted to apply + # against v0.17.0 + ./stderr.patch + ]; + + ldflags = [ + "-X main.Version=${version}" + ]; + + nativeBuildInputs = [ + installShellFiles + ]; + + nativeInstallCheckInputs = [ + versionCheckHook + ]; + doInstallCheck = true; + preCheck = '' cd test ''; + postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' + for shell in bash fish zsh; do + installShellCompletion --cmd sbom-utility \ + --$shell <($out/bin/sbom-utility -q completion $shell) + done + ''; + meta = with lib; { description = "Utility that provides an API platform for validating, querying and managing BOM data"; homepage = "https://github.com/CycloneDX/sbom-utility"; diff --git a/pkgs/by-name/sb/sbom-utility/stderr.patch b/pkgs/by-name/sb/sbom-utility/stderr.patch new file mode 100644 index 000000000000..779c53d624d9 --- /dev/null +++ b/pkgs/by-name/sb/sbom-utility/stderr.patch @@ -0,0 +1,67 @@ +diff --git a/log/log.go b/log/log.go +index 2615f0a..c82b6c5 100644 +--- a/log/log.go ++++ b/log/log.go +@@ -104,7 +104,7 @@ func NewDefaultLogger() *MiniLogger { + tagEnter: DEFAULT_ENTER_TAG, + tagExit: DEFAULT_EXIT_TAG, + tagColor: color.New(color.FgMagenta), +- outputFile: os.Stdout, ++ outputFile: os.Stderr, + maxStrLength: 64, + } + +@@ -361,7 +361,7 @@ func (log MiniLogger) dumpInterface(lvl Level, tag string, value interface{}, sk + } + + // TODO: use a general output writer (set to stdout, stderr, or file stream) +- fmt.Println(sb.String()) ++ fmt.Fprintln(log.outputFile, sb.String()) + } else { + os.Stderr.WriteString("Error: Unable to retrieve call stack. Exiting...") + os.Exit(-2) +@@ -370,7 +370,7 @@ func (log MiniLogger) dumpInterface(lvl Level, tag string, value interface{}, sk + } + + func (log MiniLogger) DumpString(value string) { +- fmt.Print(value) ++ fmt.Fprint(log.outputFile, value) + } + + func (log MiniLogger) DumpStruct(structName string, field interface{}) error { +@@ -389,7 +389,7 @@ func (log MiniLogger) DumpStruct(structName string, field interface{}) error { + } + + // TODO: print to output stream +- fmt.Println(sb.String()) ++ fmt.Fprintln(log.outputFile, sb.String()) + + return nil + } +@@ -398,8 +398,8 @@ func (log MiniLogger) DumpArgs() { + args := os.Args + for i, a := range args { + // TODO: print to output stream +- fmt.Print(log.indentRunes) +- fmt.Printf("os.Arg[%d]: `%v`\n", i, a) ++ fmt.Fprint(log.outputFile, log.indentRunes) ++ fmt.Fprintf(log.outputFile, "os.Arg[%d]: `%v`\n", i, a) + } + } + +@@ -409,7 +409,7 @@ func (log MiniLogger) DumpSeparator(sep byte, repeat int) (string, error) { + for i := 0; i < repeat; i++ { + sb.WriteByte(sep) + } +- fmt.Println(sb.String()) ++ fmt.Fprintln(log.outputFile, sb.String()) + return sb.String(), nil + } else { + return "", errors.New("invalid repeat length (>80)") +@@ -417,5 +417,5 @@ func (log MiniLogger) DumpSeparator(sep byte, repeat int) (string, error) { + } + + func (log *MiniLogger) DumpStackTrace() { +- fmt.Println(string(debug.Stack())) ++ fmt.Fprintln(log.outputFile, string(debug.Stack())) + }