-
Notifications
You must be signed in to change notification settings - Fork 54
fix: handle default arch in Select #256
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
Changes from 8 commits
a080409
2fb3c32
53fe075
c80bc7b
4ce1609
7796bfc
842070c
f1ffee3
9b8ace6
79e047d
2b506e8
032536a
1863441
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -369,7 +369,7 @@ func order(pkgs map[string]*Package, keys []SliceKey, arch string) ([]SliceKey, | |
| fqslice := slice.String() | ||
| predecessors := successors[fqslice] | ||
| for req, info := range slice.Essential { | ||
| if len(info.Arch) > 0 && !slices.Contains(info.Arch, arch) { | ||
| if len(info.Arch) > 0 && arch != "" && !slices.Contains(info.Arch, arch) { | ||
| continue | ||
| } | ||
| fqreq := req.String() | ||
|
|
@@ -465,6 +465,10 @@ func stripBase(baseDir, path string) string { | |
| func Select(release *Release, slices []SliceKey, arch string) (*Selection, error) { | ||
| logf("Selecting slices...") | ||
|
|
||
| if arch == "" { | ||
| return nil, fmt.Errorf(`cannot select slices: "arch" is unset`) | ||
|
||
| } | ||
|
|
||
| selection := &Selection{ | ||
| Release: release, | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3548,6 +3548,44 @@ var setupTests = []setupTest{{ | |
| `, | ||
| }, | ||
| relerror: `package "mypkg" repeats mypkg_myslice2 in essential fields`, | ||
| }, { | ||
| summary: "Cycles are detected with 'v3-essential'", | ||
| input: map[string]string{ | ||
| "slices/mydir/mypkg1.yaml": ` | ||
| package: mypkg1 | ||
| slices: | ||
| myslice: | ||
| v3-essential: | ||
| mypkg2_myslice: {arch: [amd64, i386]} | ||
| `, | ||
| "slices/mydir/mypkg2.yaml": ` | ||
| package: mypkg2 | ||
| slices: | ||
| myslice: | ||
| v3-essential: | ||
| mypkg1_myslice: {arch: [amd64, i386]} | ||
| `, | ||
| }, | ||
| relerror: "essential loop detected: mypkg1_myslice, mypkg2_myslice", | ||
| }, { | ||
| summary: "Cycles are detected with 'v3-essential' without architecture", | ||
| input: map[string]string{ | ||
| "slices/mydir/mypkg1.yaml": ` | ||
| package: mypkg1 | ||
| slices: | ||
| myslice: | ||
| v3-essential: | ||
| mypkg2_myslice: | ||
| `, | ||
| "slices/mydir/mypkg2.yaml": ` | ||
| package: mypkg2 | ||
| slices: | ||
| myslice: | ||
| v3-essential: | ||
| mypkg1_myslice: {arch: [amd64, i386]} | ||
| `, | ||
| }, | ||
| relerror: "essential loop detected: mypkg1_myslice, mypkg2_myslice", | ||
| }} | ||
|
|
||
| func (s *S) TestParseRelease(c *C) { | ||
|
|
@@ -3625,7 +3663,7 @@ func runParseReleaseTests(c *C, tests []setupTest) { | |
| } | ||
|
|
||
| if test.selslices != nil { | ||
| selection, err := setup.Select(release, test.selslices, "") | ||
| selection, err := setup.Select(release, test.selslices, "amd64") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. magic value. should be a constant imo. these are tests, so its maybe less important here, but nonetheless it does introduce a notion of a default architecture. maybe we should define that and the return it here:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think it introduces the notion of a default architecture from the point of view of The behavior of falling back to inferring the arch is consistent with how the release is inferred in |
||
| if test.selerror != "" { | ||
| c.Assert(err, ErrorMatches, test.selerror) | ||
| continue | ||
|
|
@@ -3850,3 +3888,8 @@ func (s *S) TestYAMLPathGenerate(c *C) { | |
| c.Assert(result, Equals, test.result) | ||
| } | ||
| } | ||
|
|
||
| func (s *S) TestSelectEmptyArch(c *C) { | ||
| _, err := setup.Select(nil, nil, "") | ||
| c.Assert(err, ErrorMatches, `cannot select slices: "arch" is unset`) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2078,6 +2078,10 @@ func runSlicerTests(s *S, c *C, tests []slicerTest) { | |
| Slice: "manifest", | ||
| }) | ||
|
|
||
| if test.arch == "" { | ||
| test.arch = "amd64" | ||
|
||
| } | ||
|
|
||
| selection, err := setup.Select(release, testSlices, test.arch) | ||
| c.Assert(err, IsNil) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: this is returning the
debArchfield ofarchPairis that the correct one to use? maybe in the future we should do an internal refactor forgoArchanddebArchto be enums to make it clear which one we're using where.. 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
debArchis then used as a filter for values defined inpathso this is the one we want. The purpose ofdeb.InferArch()is to return the current runtimedebarchitecture. The fact it is inferred from the GOARCH is an implementation details I think.What do you think if the source of confusion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, just when reading the code there is both
goArchanddebArch, which are both strings so its not explicit which one should go where, and the name ofInferArchdoes not say which one it returns, so i could imagine someone making a mistake of thinking it returns the other one -- something which would not be caught by the compiler