Skip to content
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
2 changes: 1 addition & 1 deletion cmd/chisel/cmd_cut.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (cmd *cmdCut) Execute(args []string) error {
}
}

selection, err := setup.Select(release, sliceKeys)
selection, err := setup.Select(release, sliceKeys, cmd.Arch)
if err != nil {
return err
}
Expand Down
22 changes: 11 additions & 11 deletions cmd/chisel/cmd_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ var infoTests = []infoTest{{
contents:
/dir/file: {}
myslice2:
essential:
- mypkg1_myslice1
- mypkg2_myslice
v3-essential:
mypkg1_myslice1: {}
mypkg2_myslice: {arch: amd64}
`,
}, {
summary: "Packages and slices",
Expand All @@ -67,9 +67,9 @@ var infoTests = []infoTest{{
contents:
/dir/file: {}
myslice2:
essential:
- mypkg1_myslice1
- mypkg2_myslice
v3-essential:
mypkg1_myslice1: {}
mypkg2_myslice: {arch: amd64}
---
package: mypkg2
slices:
Expand All @@ -88,9 +88,9 @@ var infoTests = []infoTest{{
contents:
/dir/file: {}
myslice2:
essential:
- mypkg1_myslice1
- mypkg2_myslice
v3-essential:
mypkg1_myslice1: {}
mypkg2_myslice: {arch: amd64}
`,
}, {
summary: "Same slice appearing multiple times",
Expand Down Expand Up @@ -148,8 +148,8 @@ var infoRelease = map[string]string{
contents:
/dir/file:
myslice2:
essential:
- mypkg2_myslice
v3-essential:
mypkg2_myslice: {arch: amd64}
`,
"slices/mypkg2.yaml": `
package: mypkg2
Expand Down
31 changes: 24 additions & 7 deletions internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ type Package struct {
type Slice struct {
Package string
Name string
Essential []SliceKey
Essential map[SliceKey]EssentialInfo
Contents map[string]PathInfo
Scripts SliceScripts
}

type EssentialInfo struct {
Arch []string
}

type SliceScripts struct {
Mutate string
}
Expand Down Expand Up @@ -298,7 +302,12 @@ func (r *Release) validate() error {
}

// Check for cycles.
_, err = order(r.Packages, keys)
// Note: For release validation an essential with a specific arch is the
// same as an essential with all archs, i.e. Chisel does not use arch to
// partition the dependency set. If we were to use arch, we would allow
// combinations of dependencies which are overly complex and brittle, that
// is why it is better to be more strict here.
_, err = order(r.Packages, keys, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -328,7 +337,12 @@ func (r *Release) validate() error {
return nil
}

func order(pkgs map[string]*Package, keys []SliceKey) ([]SliceKey, error) {
// order will use TarjanSort to get an ordering of the essential(s). It will
// return an error if there are cycles.
//
// If arch is supplied, essential(s) not specific to that arch are not
// considered.
func order(pkgs map[string]*Package, keys []SliceKey, arch string) ([]SliceKey, error) {

// Preprocess the list to improve error messages.
for _, key := range keys {
Expand All @@ -354,15 +368,18 @@ func order(pkgs map[string]*Package, keys []SliceKey) ([]SliceKey, error) {
slice := pkg.Slices[key.Slice]
fqslice := slice.String()
predecessors := successors[fqslice]
for _, req := range slice.Essential {
for req, info := range slice.Essential {
if len(info.Arch) > 0 && !slices.Contains(info.Arch, arch) {
continue
}
fqreq := req.String()
if reqpkg, ok := pkgs[req.Package]; !ok || reqpkg.Slices[req.Slice] == nil {
return nil, fmt.Errorf("%s requires %s, but slice is missing", fqslice, fqreq)
}
predecessors = append(predecessors, fqreq)
pending = append(pending, req)
}
successors[fqslice] = predecessors
pending = append(pending, slice.Essential...)
}

// Sort them up.
Expand Down Expand Up @@ -445,14 +462,14 @@ func stripBase(baseDir, path string) string {
return strings.TrimPrefix(path, baseDir+string(filepath.Separator))
}

func Select(release *Release, slices []SliceKey) (*Selection, error) {
func Select(release *Release, slices []SliceKey, arch string) (*Selection, error) {
logf("Selecting slices...")

selection := &Selection{
Release: release,
}

sorted, err := order(release.Packages, slices)
sorted, err := order(release.Packages, slices, arch)
if err != nil {
return nil, err
}
Expand Down
Loading