@@ -37,7 +37,12 @@ type Manifest2822Entry struct {
37
37
GitFetch string
38
38
GitCommit string
39
39
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())
41
46
42
47
Constraints []string `delim:"," strip:"\n\r\t "`
43
48
}
@@ -53,16 +58,34 @@ var (
53
58
}
54
59
)
55
60
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
+
56
69
func (entry Manifest2822Entry ) Clone () Manifest2822Entry {
57
70
// SLICES! grr
58
71
entry .Maintainers = append ([]string {}, entry .Maintainers ... )
59
72
entry .Tags = append ([]string {}, entry .Tags ... )
60
73
entry .SharedTags = append ([]string {}, entry .SharedTags ... )
61
74
entry .Architectures = append ([]string {}, entry .Architectures ... )
62
75
entry .Constraints = append ([]string {}, entry .Constraints ... )
76
+ // and MAPS, oh my
77
+ entry .ArchValues = deepCopyStringsMap (entry .ArchValues )
63
78
return entry
64
79
}
65
80
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
+
66
89
const StringSeparator2822 = ", "
67
90
68
91
func (entry Manifest2822Entry ) MaintainersString () string {
@@ -89,26 +112,23 @@ func (entry Manifest2822Entry) ConstraintsString() string {
89
112
func (a Manifest2822Entry ) SameBuildArtifacts (b Manifest2822Entry ) bool {
90
113
// check xxxarch-GitRepo, etc. fields for sameness first
91
114
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 ] {
93
116
return false
94
117
}
95
118
}
96
119
97
120
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 ()
98
121
}
99
122
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
-
104
123
// returns a list of architecture-specific fields in an Entry
105
124
func (entry Manifest2822Entry ) archFields () []string {
106
125
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 != "" {
109
128
ret = append (ret , key )
110
129
}
111
130
}
131
+ sort .Strings (ret )
112
132
return ret
113
133
}
114
134
@@ -140,8 +160,8 @@ func (entry Manifest2822Entry) ClearDefaults(defaults Manifest2822Entry) Manifes
140
160
entry .Directory = ""
141
161
}
142
162
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 )
145
165
}
146
166
}
147
167
if entry .ConstraintsString () == defaults .ConstraintsString () {
@@ -176,10 +196,8 @@ func (entry Manifest2822Entry) String() string {
176
196
if str := entry .Directory ; str != "" {
177
197
ret = append (ret , "Directory: " + str )
178
198
}
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 ])
183
201
}
184
202
if str := entry .ConstraintsString (); str != "" {
185
203
ret = append (ret , "Constraints: " + str )
@@ -203,42 +221,42 @@ func (manifest Manifest2822) String() string {
203
221
}
204
222
205
223
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 {}
208
226
}
209
- entry .Paragraph . Values [arch + "-GitRepo" ] = repo
227
+ entry .ArchValues [arch + "-GitRepo" ] = repo
210
228
}
211
229
212
230
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 != "" {
214
232
return val
215
233
}
216
234
return entry .GitRepo
217
235
}
218
236
219
237
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 != "" {
221
239
return val
222
240
}
223
241
return entry .GitFetch
224
242
}
225
243
226
244
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 {}
229
247
}
230
- entry .Paragraph . Values [arch + "-GitCommit" ] = commit
248
+ entry .ArchValues [arch + "-GitCommit" ] = commit
231
249
}
232
250
233
251
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 != "" {
235
253
return val
236
254
}
237
255
return entry .GitCommit
238
256
}
239
257
240
258
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 != "" {
242
260
return val
243
261
}
244
262
return entry .Directory
@@ -454,6 +472,9 @@ func (decoder *decoderWrapper) Decode(entry *Manifest2822Entry) error {
454
472
entry .Architectures = arches
455
473
}
456
474
475
+ // pull out any new architecture-specific values from Paragraph.Values
476
+ entry .SeedArchValues ()
477
+
457
478
return nil
458
479
}
459
480
}
0 commit comments