Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jammy: handle multi version constraint on package dep #417

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions frontend/deb/template_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,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 @@ -301,7 +301,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