Skip to content

Commit

Permalink
jammy: handle multi version constraint on package dep
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBrito committed Oct 25, 2024
1 parent c63436e commit 696cc7a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 5 deletions.
16 changes: 12 additions & 4 deletions frontend/deb/template_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,27 @@ func appendConstraints(deps map[string]dalec.PackageConstraints) []string {

for i, dep := range out {
constraints := deps[dep]
s := dep
var versionConstraints []string
// Format is specified in https://www.debian.org/doc/debian-policy/ch-relationships.html#syntax-of-relationship-fields
if len(constraints.Version) > 0 {
ls := constraints.Version
slices.Sort(ls)
s = fmt.Sprintf("%s (%s)", s, strings.Join(ls, ", "))
for _, v := range ls {
versionConstraints = append(versionConstraints, fmt.Sprintf("%s (%s)", dep, v))
}
} else {
versionConstraints = append(versionConstraints, dep)
}

if len(constraints.Arch) > 0 {
ls := constraints.Arch
slices.Sort(ls)
s = fmt.Sprintf("%s [%s]", s, strings.Join(ls, ", "))
for j, vc := range versionConstraints {
versionConstraints[j] = fmt.Sprintf("%s [%s]", vc, strings.Join(ls, " "))
}
}
out[i] = s

out[i] = strings.Join(versionConstraints, " | ")
}

return out
Expand Down
71 changes: 71 additions & 0 deletions frontend/deb/template_control_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package deb

import (
"reflect"
"testing"

"github.com/Azure/dalec"
)

func TestAppendConstraints(t *testing.T) {
tests := []struct {
name string
deps map[string]dalec.PackageConstraints
want []string
}{
{
name: "nil dependencies",
deps: nil,
want: nil,
},
{
name: "empty dependencies",
deps: map[string]dalec.PackageConstraints{},
want: []string{},
},
{
name: "single dependency without constraints",
deps: map[string]dalec.PackageConstraints{
"packageA": {},
},
want: []string{"packageA"},
},
{
name: "single dependency with version constraints",
deps: map[string]dalec.PackageConstraints{
"packageA": {Version: []string{">= 1.0", "< 2.0"}},
},
want: []string{"packageA (< 2.0) | packageA (>= 1.0)"},
},
{
name: "single dependency with architecture constraints",
deps: map[string]dalec.PackageConstraints{
"packageA": {Arch: []string{"amd64", "arm64"}},
},
want: []string{"packageA [amd64 arm64]"},
},
{
name: "single dependency with version and architecture constraints",
deps: map[string]dalec.PackageConstraints{
"packageA": {Version: []string{">= 1.0", "< 2.0"}, Arch: []string{"amd64", "arm64"}},
},
want: []string{"packageA (< 2.0) [amd64 arm64] | packageA (>= 1.0) [amd64 arm64]"},
},
{
name: "multiple dependencies with constraints",
deps: map[string]dalec.PackageConstraints{
"packageB": {Version: []string{"= 1.0"}},
"packageA": {Arch: []string{"amd64"}},
},
want: []string{"packageA [amd64]", "packageB (= 1.0)"},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := appendConstraints(tt.deps); !reflect.DeepEqual(got, tt.want) {
t.Errorf("appendConstraints() = %v, want %v", got, tt.want)
}
})
}
}
2 changes: 1 addition & 1 deletion frontend/jammy/handle_deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func buildDepends(worker llb.State, sOpt dalec.SourceOpts, spec *dalec.Spec, tar

pg := dalec.ProgressGroup("Install build dependencies")
opts = append(opts, pg)
pkg, err := deb.BuildDeb(worker, depsSpec, sOpt, targetKey, "", append(opts, dalec.ProgressGroup("Create intermediate deb for build dependnencies"))...)
pkg, err := deb.BuildDeb(worker, depsSpec, sOpt, targetKey, "", append(opts, dalec.ProgressGroup("Create intermediate deb for build dependencies"))...)
if err != nil {
return nil, errors.Wrap(err, "error creating intermediate package for installing build dependencies")
}
Expand Down

0 comments on commit 696cc7a

Please sign in to comment.