Skip to content

Commit ce6f973

Browse files
committed
Add new functions to ensure global arch-specific values are inherited properly
1 parent 663a091 commit ce6f973

File tree

1 file changed

+45
-24
lines changed

1 file changed

+45
-24
lines changed

manifest/rfc2822.go

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ type Manifest2822Entry struct {
3737
GitFetch string
3838
GitCommit string
3939
Directory string
40-
// architecture-specific versions of the above fields are in Paragraph.Values as ARCH-Field, ala s390x-Directory
40+
41+
// architecture-specific versions of the above fields
42+
ArchValues map[string]string
43+
// "ARCH-FIELD: VALUE"
44+
// ala, "s390x-GitCommit: deadbeef"
45+
// (sourced from Paragraph.Values via .SeedArchValues())
4146

4247
Constraints []string `delim:"," strip:"\n\r\t "`
4348
}
@@ -53,16 +58,34 @@ var (
5358
}
5459
)
5560

61+
func deepCopyStringsMap(a map[string]string) map[string]string {
62+
b := map[string]string{}
63+
for k, v := range a {
64+
b[k] = v
65+
}
66+
return b
67+
}
68+
5669
func (entry Manifest2822Entry) Clone() Manifest2822Entry {
5770
// SLICES! grr
5871
entry.Maintainers = append([]string{}, entry.Maintainers...)
5972
entry.Tags = append([]string{}, entry.Tags...)
6073
entry.SharedTags = append([]string{}, entry.SharedTags...)
6174
entry.Architectures = append([]string{}, entry.Architectures...)
6275
entry.Constraints = append([]string{}, entry.Constraints...)
76+
// and MAPS, oh my
77+
entry.ArchValues = deepCopyStringsMap(entry.ArchValues)
6378
return entry
6479
}
6580

81+
func (entry *Manifest2822Entry) SeedArchValues() {
82+
for field, val := range entry.Paragraph.Values {
83+
if strings.HasSuffix(field, "-GitRepo") || strings.HasSuffix(field, "-GitFetch") || strings.HasSuffix(field, "-GitCommit") || strings.HasSuffix(field, "-Directory") {
84+
entry.ArchValues[field] = val
85+
}
86+
}
87+
}
88+
6689
const StringSeparator2822 = ", "
6790

6891
func (entry Manifest2822Entry) MaintainersString() string {
@@ -89,26 +112,23 @@ func (entry Manifest2822Entry) ConstraintsString() string {
89112
func (a Manifest2822Entry) SameBuildArtifacts(b Manifest2822Entry) bool {
90113
// check xxxarch-GitRepo, etc. fields for sameness first
91114
for _, key := range append(a.archFields(), b.archFields()...) {
92-
if a.Paragraph.Values[key] != b.Paragraph.Values[key] {
115+
if a.ArchValues[key] != b.ArchValues[key] {
93116
return false
94117
}
95118
}
96119

97120
return a.ArchitecturesString() == b.ArchitecturesString() && a.GitRepo == b.GitRepo && a.GitFetch == b.GitFetch && a.GitCommit == b.GitCommit && a.Directory == b.Directory && a.ConstraintsString() == b.ConstraintsString()
98121
}
99122

100-
func isArchField(field string) bool {
101-
return strings.HasSuffix(field, "-GitRepo") || strings.HasSuffix(field, "-GitFetch") || strings.HasSuffix(field, "-GitCommit") || strings.HasSuffix(field, "-Directory")
102-
}
103-
104123
// returns a list of architecture-specific fields in an Entry
105124
func (entry Manifest2822Entry) archFields() []string {
106125
ret := []string{}
107-
for key, val := range entry.Paragraph.Values {
108-
if isArchField(key) && val != "" {
126+
for key, val := range entry.ArchValues {
127+
if val != "" {
109128
ret = append(ret, key)
110129
}
111130
}
131+
sort.Strings(ret)
112132
return ret
113133
}
114134

@@ -140,8 +160,8 @@ func (entry Manifest2822Entry) ClearDefaults(defaults Manifest2822Entry) Manifes
140160
entry.Directory = ""
141161
}
142162
for _, key := range defaults.archFields() {
143-
if defaults.Paragraph.Values[key] == entry.Paragraph.Values[key] {
144-
delete(entry.Paragraph.Values, key)
163+
if defaults.ArchValues[key] == entry.ArchValues[key] {
164+
delete(entry.ArchValues, key)
145165
}
146166
}
147167
if entry.ConstraintsString() == defaults.ConstraintsString() {
@@ -176,10 +196,8 @@ func (entry Manifest2822Entry) String() string {
176196
if str := entry.Directory; str != "" {
177197
ret = append(ret, "Directory: "+str)
178198
}
179-
archFields := entry.archFields()
180-
sort.Strings(archFields) // consistent ordering
181-
for _, key := range archFields {
182-
ret = append(ret, key+": "+entry.Paragraph.Values[key])
199+
for _, key := range entry.archFields() {
200+
ret = append(ret, key+": "+entry.ArchValues[key])
183201
}
184202
if str := entry.ConstraintsString(); str != "" {
185203
ret = append(ret, "Constraints: "+str)
@@ -203,42 +221,42 @@ func (manifest Manifest2822) String() string {
203221
}
204222

205223
func (entry *Manifest2822Entry) SetGitRepo(arch string, repo string) {
206-
if entry.Paragraph.Values == nil {
207-
entry.Paragraph.Values = map[string]string{}
224+
if entry.ArchValues == nil {
225+
entry.ArchValues = map[string]string{}
208226
}
209-
entry.Paragraph.Values[arch+"-GitRepo"] = repo
227+
entry.ArchValues[arch+"-GitRepo"] = repo
210228
}
211229

212230
func (entry Manifest2822Entry) ArchGitRepo(arch string) string {
213-
if val, ok := entry.Paragraph.Values[arch+"-GitRepo"]; ok && val != "" {
231+
if val, ok := entry.ArchValues[arch+"-GitRepo"]; ok && val != "" {
214232
return val
215233
}
216234
return entry.GitRepo
217235
}
218236

219237
func (entry Manifest2822Entry) ArchGitFetch(arch string) string {
220-
if val, ok := entry.Paragraph.Values[arch+"-GitFetch"]; ok && val != "" {
238+
if val, ok := entry.ArchValues[arch+"-GitFetch"]; ok && val != "" {
221239
return val
222240
}
223241
return entry.GitFetch
224242
}
225243

226244
func (entry *Manifest2822Entry) SetGitCommit(arch string, commit string) {
227-
if entry.Paragraph.Values == nil {
228-
entry.Paragraph.Values = map[string]string{}
245+
if entry.ArchValues == nil {
246+
entry.ArchValues = map[string]string{}
229247
}
230-
entry.Paragraph.Values[arch+"-GitCommit"] = commit
248+
entry.ArchValues[arch+"-GitCommit"] = commit
231249
}
232250

233251
func (entry Manifest2822Entry) ArchGitCommit(arch string) string {
234-
if val, ok := entry.Paragraph.Values[arch+"-GitCommit"]; ok && val != "" {
252+
if val, ok := entry.ArchValues[arch+"-GitCommit"]; ok && val != "" {
235253
return val
236254
}
237255
return entry.GitCommit
238256
}
239257

240258
func (entry Manifest2822Entry) ArchDirectory(arch string) string {
241-
if val, ok := entry.Paragraph.Values[arch+"-Directory"]; ok && val != "" {
259+
if val, ok := entry.ArchValues[arch+"-Directory"]; ok && val != "" {
242260
return val
243261
}
244262
return entry.Directory
@@ -454,6 +472,9 @@ func (decoder *decoderWrapper) Decode(entry *Manifest2822Entry) error {
454472
entry.Architectures = arches
455473
}
456474

475+
// pull out any new architecture-specific values from Paragraph.Values
476+
entry.SeedArchValues()
477+
457478
return nil
458479
}
459480
}

0 commit comments

Comments
 (0)