diff --git a/pkg/sca/sca.go b/pkg/sca/sca.go index d38ae4a9c..b2726901e 100644 --- a/pkg/sca/sca.go +++ b/pkg/sca/sca.go @@ -587,23 +587,54 @@ func generateRubyDeps(ctx context.Context, hdl SCAHandle, generated *config.Depe return nil } -// Add man-db as a dep for any doc package +// For a documentation package add a dependency on man-db and / or texinfo as appropriate func generateDocDeps(ctx context.Context, hdl SCAHandle, generated *config.Dependencies) error { log := clog.FromContext(ctx) log.Infof("scanning for -doc package...") if !strings.HasSuffix(hdl.PackageName(), "-doc") { return nil } - // Do not add a man-db dependency if one already exists. - for _, dep := range hdl.BaseDependencies().Runtime { - if dep == "man-db" { - log.Warnf("%s: man-db dependency already specified, consider removing it in favor of SCA-generated dependency", hdl.PackageName()) - return nil - } + + fsys, err := hdl.Filesystem() + if err != nil { + return err } - log.Infof(" found -doc package, generating man-db dependency") - generated.Runtime = append(generated.Runtime, "man-db") + if err := fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + + if isInDir(path, []string{"usr/share/man"}) { + + // Do not add a man-db dependency if one already exists. + for _, dep := range hdl.BaseDependencies().Runtime { + if dep == "man-db" { + log.Warnf("%s: man-db dependency already specified, consider removing it in favor of SCA-generated dependency", hdl.PackageName()) + } + } + + log.Infof(" found files in /usr/share/man/ in package, generating man-db dependency") + generated.Runtime = append(generated.Runtime, "man-db") + } + + if isInDir(path, []string{"usr/share/info"}) { + + // Do not add a texinfo dependency if one already exists. + for _, dep := range hdl.BaseDependencies().Runtime { + if dep == "texinfo" { + log.Warnf("%s: texinfo dependency already specified, consider removing it in favor of SCA-generated dependency", hdl.PackageName()) + } + } + + log.Infof(" found files in /usr/share/info/ in package, generating texinfo dependency") + generated.Runtime = append(generated.Runtime, "texinfo") + } + return nil + + }); err != nil { + return err + } return nil } diff --git a/pkg/sca/sca_test.go b/pkg/sca/sca_test.go index 750a6009e..72938020b 100644 --- a/pkg/sca/sca_test.go +++ b/pkg/sca/sca_test.go @@ -222,8 +222,8 @@ func TestRubySca(t *testing.T) { func TestDocSca(t *testing.T) { ctx := slogtest.Context(t) // Generated by: - // wget https://packages.wolfi.dev/os/x86_64/xset-doc-1.2.5-r1.apk - th := handleFromApk(ctx, t, "xset-doc-1.2.5-r1.apk", "xset.yaml") + // wget https://packages.wolfi.dev/os/x86_64/bash-doc-5.2.37-r2.apk + th := handleFromApk(ctx, t, "bash-doc-5.2.37-r2.apk", "bash.yaml") defer th.exp.Close() got := config.Dependencies{} @@ -231,7 +231,7 @@ func TestDocSca(t *testing.T) { t.Fatal(err) } - want := config.Dependencies{Runtime: []string{"man-db"}} + want := config.Dependencies{Runtime: []string{"man-db", "texinfo"}} if diff := cmp.Diff(want, got); diff != "" { t.Errorf("Analyze(): (-want, +got):\n%s", diff) diff --git a/pkg/sca/testdata/bash-doc-5.2.37-r2.apk b/pkg/sca/testdata/bash-doc-5.2.37-r2.apk new file mode 100644 index 000000000..da6329666 Binary files /dev/null and b/pkg/sca/testdata/bash-doc-5.2.37-r2.apk differ diff --git a/pkg/sca/testdata/bash.yaml b/pkg/sca/testdata/bash.yaml new file mode 100644 index 000000000..4e7acb4bf --- /dev/null +++ b/pkg/sca/testdata/bash.yaml @@ -0,0 +1,106 @@ +package: + name: bash + version: 5.2.37 + epoch: 2 + description: "GNU bourne again shell" + copyright: + - license: GPL-3.0-or-later + +environment: + contents: + packages: + - build-base + - busybox + - ca-certificates-bundle + - ncurses-dev + - openssf-compiler-options + +pipeline: + - uses: fetch + with: + uri: https://ftp.fu-berlin.de/unix/gnu/bash/bash-${{package.version}}.tar.gz + expected-sha256: 9599b22ecd1d5787ad7d3b7bf0c59f312b3396d1e281175dd1f8a4014da621ff + + - runs: | + export CFLAGS="${CFLAGS} -DSYS_BASHRC='\"/etc/bash.bashrc\"' -DSYS_BASH_LOGOUT='\"/etc/bash.bash_logout\"'" + ./configure \ + --host=${{host.triplet.gnu}} \ + --target=${{host.triplet.gnu}} \ + --prefix=/usr \ + --bindir=/bin \ + --sysconfdir=/etc \ + --without-libidn \ + --with-ssl=openssl \ + --disable-nls \ + --enable-readline \ + --without-bash-malloc \ + --with-curses + + - uses: autoconf/make + + - uses: autoconf/make-install + + - uses: strip + +subpackages: + - name: bash-binsh + dependencies: + provider-priority: 60 + runtime: + - bash + pipeline: + - runs: | + mkdir -p "${{targets.subpkgdir}}"/bin + ln -s bash "${{targets.subpkgdir}}"/bin/sh + test: + pipeline: + - runs: | + [ /bin/sh -ef /bin/bash ] || { echo "/bin/sh is not same as /bin/bash"; exit 1; } + sh --version + sh --help + + - name: "bash-doc" + description: "bash documentation" + pipeline: + - uses: split/manpages + - uses: split/infodir + - runs: | + mkdir -p "${{targets.subpkgdir}}"/usr/share + mv "${{targets.destdir}}"/usr/share/doc "${{targets.subpkgdir}}"/usr/share/ + + - name: "bash-dev" + description: "bash development headers" + pipeline: + - uses: split/dev + - runs: | + mkdir -p "${{targets.subpkgdir}}"/bin + mv "${{targets.destdir}}"/bin/bashbug "${{targets.subpkgdir}}"/bin/ + test: + pipeline: + - runs: | + bashbug --version + bashbug --help + - uses: test/pkgconf + + - name: "bash-builtins" + description: "bash loadable builtins" + pipeline: + - runs: | + mkdir -p ${{targets.subpkgdir}}/usr/lib + mv "${{targets.destdir}}/usr/lib/bash" ${{targets.subpkgdir}}/usr/lib/ + +update: + enabled: true + release-monitor: + identifier: 166 + +test: + pipeline: + - runs: | + out=$(/bin/bash --version) + echo "$out" | grep "${{package.version}}" + bash --version + bash --help + - runs: | + out=$(/bin/bash -c "echo hello world") + [ "$out" = "hello world" ] diff --git a/pkg/sca/testdata/xset-doc-1.2.5-r1.apk b/pkg/sca/testdata/xset-doc-1.2.5-r1.apk deleted file mode 100644 index 7083da8a0..000000000 Binary files a/pkg/sca/testdata/xset-doc-1.2.5-r1.apk and /dev/null differ diff --git a/pkg/sca/testdata/xset.yaml b/pkg/sca/testdata/xset.yaml deleted file mode 100644 index 9c504a621..000000000 --- a/pkg/sca/testdata/xset.yaml +++ /dev/null @@ -1,45 +0,0 @@ -package: - name: xset - version: 1.2.5 - epoch: 2 - description: X.Org xset application - copyright: - - license: MIT - -environment: - contents: - packages: - - autoconf - - automake - - build-base - - busybox - - libx11-dev - - libxext-dev - - libxmu-dev - - openssf-compiler-options - - util-macros - -pipeline: - - uses: fetch - with: - expected-sha256: 9f692d55635b3862cd63633b1222a87680ec283c7a8e8ed6dd698a3147f75e2f - uri: https://www.x.org/releases/individual/app/xset-${{package.version}}.tar.xz - - - uses: autoconf/configure - - - uses: autoconf/make - - - uses: autoconf/make-install - - - uses: strip - -subpackages: - - name: xset-doc - description: xset documentation - pipeline: - - uses: split/manpages - -update: - enabled: true - release-monitor: - identifier: 14954