Skip to content

Commit

Permalink
Merge pull request #1705 from imjasonh/no-dedup
Browse files Browse the repository at this point in the history
remove unnecessary util.Dedup method
  • Loading branch information
imjasonh authored Dec 14, 2024
2 parents 42a9deb + 887bc2d commit 0e2b364
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 87 deletions.
4 changes: 3 additions & 1 deletion pkg/build/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ func (c *Compiled) compilePipeline(ctx context.Context, sm *SubstitutionMap, pip
}

if parent != nil {
with = util.RightJoinMap(parent, with)
m := maps.Clone(parent)
maps.Copy(m, with)
with = m
}

validated, err := validateWith(with, pipeline.Inputs)
Expand Down
8 changes: 4 additions & 4 deletions pkg/build/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"path/filepath"
"runtime"
"slices"
"strings"
"text/template"

Expand All @@ -36,7 +37,6 @@ import (

"chainguard.dev/melange/pkg/config"
"chainguard.dev/melange/pkg/sca"
"chainguard.dev/melange/pkg/util"

"chainguard.dev/apko/pkg/apk/tarball"
"github.com/chainguard-dev/clog"
Expand Down Expand Up @@ -342,15 +342,15 @@ func (pc *PackageBuild) GenerateDependencies(ctx context.Context, hdl sca.SCAHan
unvendored := removeSelfProvidedDeps(generated.Runtime, generated.Vendored)

newruntime := append(pc.Dependencies.Runtime, unvendored...)
pc.Dependencies.Runtime = util.Dedup(newruntime)
pc.Dependencies.Runtime = slices.Compact(slices.Sorted(slices.Values(newruntime)))

newprovides := append(pc.Dependencies.Provides, generated.Provides...)
pc.Dependencies.Provides = util.Dedup(newprovides)
pc.Dependencies.Provides = slices.Compact(slices.Sorted(slices.Values(newprovides)))

pc.Dependencies.Runtime = removeSelfProvidedDeps(pc.Dependencies.Runtime, pc.Dependencies.Provides)

// Sets .PKGINFO `# vendored = ...` comments; does not affect resolution.
pc.Dependencies.Vendored = util.Dedup(generated.Vendored)
pc.Dependencies.Vendored = slices.Compact(slices.Sorted(slices.Values(generated.Vendored)))

pc.Dependencies.Summarize(ctx)

Expand Down
5 changes: 4 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io/fs"
"iter"
"maps"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -1220,7 +1221,9 @@ func (p *Pipeline) propagateChildPipelines() {
p.Pipeline[idx].WorkDir = p.WorkDir
}

p.Pipeline[idx].Environment = util.RightJoinMap(p.Environment, p.Pipeline[idx].Environment)
m := maps.Clone(p.Environment)
maps.Copy(m, p.Pipeline[idx].Environment)
p.Pipeline[idx].Environment = m

p.Pipeline[idx].propagateChildPipelines()
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/sca/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"testing"

"chainguard.dev/melange/pkg/config"
"chainguard.dev/melange/pkg/util"
"github.com/chainguard-dev/clog/slogtest"
"github.com/google/go-cmp/cmp"
)
Expand All @@ -36,13 +35,13 @@ func TestGoFipsBinDeps(t *testing.T) {
t.Fatal(err)
}
want := config.Dependencies{
Runtime: util.Dedup([]string{
Runtime: []string{
"openssl-config-fipshardened",
"so:ld-linux-x86-64.so.2",
"so:libc.so.6",
"so:libcrypto.so.3",
"so:libssl.so.3",
}),
},
Provides: []string{"cmd:go-fips-bin=0.0.1-r0"},
}
if diff := cmp.Diff(want, got); diff != "" {
Expand Down
7 changes: 3 additions & 4 deletions pkg/sca/sca.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/chainguard-dev/go-pkgconfig"

"chainguard.dev/melange/pkg/config"
"chainguard.dev/melange/pkg/util"
)

var libDirs = []string{"lib/", "usr/lib/", "lib64/", "usr/lib64/"}
Expand Down Expand Up @@ -783,9 +782,9 @@ func Analyze(ctx context.Context, hdl SCAHandle, generated *config.Dependencies)
}
}

generated.Runtime = util.Dedup(generated.Runtime)
generated.Provides = util.Dedup(generated.Provides)
generated.Vendored = util.Dedup(generated.Vendored)
generated.Runtime = slices.Compact(slices.Sorted(slices.Values(generated.Runtime)))
generated.Provides = slices.Compact(slices.Sorted(slices.Values(generated.Provides)))
generated.Vendored = slices.Compact(slices.Sorted(slices.Values(generated.Vendored)))

if hdl.Options().NoCommands {
generated.Provides = slices.DeleteFunc(generated.Provides, func(s string) bool {
Expand Down
33 changes: 18 additions & 15 deletions pkg/sca/sca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"chainguard.dev/apko/pkg/apk/apk"
"chainguard.dev/apko/pkg/apk/expandapk"
"chainguard.dev/melange/pkg/config"
"chainguard.dev/melange/pkg/util"
"github.com/chainguard-dev/clog/slogtest"
"github.com/google/go-cmp/cmp"
"gopkg.in/ini.v1"
Expand Down Expand Up @@ -151,16 +150,16 @@ func TestExecableSharedObjects(t *testing.T) {
}

want := config.Dependencies{
Runtime: util.Dedup([]string{
Runtime: []string{
"so:ld-linux-aarch64.so.1",
"so:libc.so.6",
"so:libcap.so.2",
"so:libpsx.so.2",
}),
Provides: util.Dedup([]string{
},
Provides: []string{
"so:libcap.so.2=2",
"so:libpsx.so.2=2",
}),
},
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("Analyze(): (-want, +got):\n%s", diff)
Expand All @@ -181,18 +180,22 @@ func TestVendoredPkgConfig(t *testing.T) {
}

want := config.Dependencies{
Runtime: util.Dedup([]string{
Runtime: []string{
// We only include libecpg_compat.so.3 to test that "libexec" isn't treated as a library directory.
// These are dependencies of libecpg_compat.so.3, but if we had the whole neon APK it would look different.
"so:libecpg.so.6", "so:libpgtypes.so.3", "so:libpq.so.5", "so:libc.so.6", "so:ld-linux-aarch64.so.1",
}),
Vendored: util.Dedup([]string{
"so:libecpg_compat.so.3=3",
"so:ld-linux-aarch64.so.1",
"so:libc.so.6",
"so:libecpg.so.6",
"so:libpgtypes.so.3",
"so:libpq.so.5",
},
Vendored: []string{
"pc:libecpg=4604-r0",
"pc:libecpg_compat=4604-r0",
"pc:libpgtypes=4604-r0",
"pc:libpq=4604-r0",
}),
"so:libecpg_compat.so.3=3",
},
}

if diff := cmp.Diff(want, got); diff != "" {
Expand Down Expand Up @@ -252,7 +255,7 @@ func TestUnstableSonames(t *testing.T) {
}

want := config.Dependencies{
Runtime: util.Dedup([]string{
Runtime: []string{
"so:ld-linux-aarch64.so.1",
"so:libaws-c-auth.so.1.0.0",
"so:libaws-c-cal.so.1.0.0",
Expand All @@ -262,7 +265,7 @@ func TestUnstableSonames(t *testing.T) {
"so:libaws-c-s3.so.0unstable",
"so:libaws-checksums.so.1.0.0",
"so:libc.so.6",
}),
},
Provides: []string{"so:libaws-c-s3.so.0unstable=0"},
}

Expand All @@ -278,13 +281,13 @@ func TestShbangDeps(t *testing.T) {
defer th.exp.Close()

want := config.Dependencies{
Runtime: util.Dedup([]string{
Runtime: []string{
"cmd:bash",
"cmd:envDashSCmd",
"cmd:python3.12",
"so:ld-linux-x86-64.so.2",
"so:libc.so.6",
}),
},
Provides: nil,
}

Expand Down
45 changes: 0 additions & 45 deletions pkg/util/util.go

This file was deleted.

14 changes: 0 additions & 14 deletions pkg/util/util_test.go

This file was deleted.

0 comments on commit 0e2b364

Please sign in to comment.