Skip to content

Commit

Permalink
Merge pull request #1654 from murraybd/add-info-or-man
Browse files Browse the repository at this point in the history
add a dependency on texinfo or man-db as appropriate
  • Loading branch information
murraybd authored Nov 19, 2024
2 parents 5decd5c + 02aa6ad commit 9b14cd2
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 57 deletions.
49 changes: 40 additions & 9 deletions pkg/sca/sca.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/sca/sca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,16 @@ 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{}
if err := Analyze(ctx, th, &got); err != nil {
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)
Expand Down
Binary file added pkg/sca/testdata/bash-doc-5.2.37-r2.apk
Binary file not shown.
106 changes: 106 additions & 0 deletions pkg/sca/testdata/bash.yaml
Original file line number Diff line number Diff line change
@@ -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" ]
Binary file removed pkg/sca/testdata/xset-doc-1.2.5-r1.apk
Binary file not shown.
45 changes: 0 additions & 45 deletions pkg/sca/testdata/xset.yaml

This file was deleted.

0 comments on commit 9b14cd2

Please sign in to comment.