Skip to content

Commit 76cdafa

Browse files
committed
Add arch-specific fields
1 parent 61055e4 commit 76cdafa

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

manifest/rfc2822.go

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type Manifest2822Entry struct {
3030
Tags []string `delim:"," strip:"\n\r\t "`
3131
SharedTags []string `delim:"," strip:"\n\r\t "`
3232

33+
Architectures []string `delim:"," strip:"\n\r\t "`
34+
3335
GitRepo string
3436
GitFetch string
3537
GitCommit string
@@ -70,9 +72,28 @@ func (entry Manifest2822Entry) ConstraintsString() string {
7072
return strings.Join(entry.Constraints, StringSeparator2822)
7173
}
7274

75+
func (entry Manifest2822Entry) ArchitecturesString() string {
76+
return strings.Join(entry.Architectures, StringSeparator2822)
77+
}
78+
7379
// if this method returns "true", then a.Tags and b.Tags can safely be combined (for the purposes of building)
7480
func (a Manifest2822Entry) SameBuildArtifacts(b Manifest2822Entry) bool {
75-
return a.GitRepo == b.GitRepo && a.GitFetch == b.GitFetch && a.GitCommit == b.GitCommit && a.Directory == b.Directory && a.ConstraintsString() == b.ConstraintsString()
81+
for key,val := range a.Paragraph.Values {
82+
if isArchField(key) && val != b.Paragraph.Values[key] {
83+
return false
84+
}
85+
}
86+
for key,val := range b.Paragraph.Values {
87+
if isArchField(key) && val != a.Paragraph.Values[key] {
88+
return false
89+
}
90+
}
91+
92+
return a.GitRepo == b.GitRepo && a.GitFetch == b.GitFetch && a.GitCommit == b.GitCommit && a.Directory == b.Directory && a.ConstraintsString() == b.ConstraintsString() && a.ArchitecturesString() == b.ArchitecturesString()
93+
}
94+
95+
func isArchField(field string) bool {
96+
return strings.HasSuffix(field, "-GitRepo") || strings.HasSuffix(field, "-GitFetch") || strings.HasSuffix(field, "-GitCommit") || strings.HasSuffix(field, "-Directory")
7697
}
7798

7899
// returns a new Entry with any of the values that are equal to the values in "defaults" cleared
@@ -101,6 +122,14 @@ func (entry Manifest2822Entry) ClearDefaults(defaults Manifest2822Entry) Manifes
101122
if entry.ConstraintsString() == defaults.ConstraintsString() {
102123
entry.Constraints = nil
103124
}
125+
if entry.ArchitecturesString() == defaults.ArchitecturesString() {
126+
entry.Architectures = nil
127+
}
128+
for key,val := range defaults.Paragraph.Values {
129+
if isArchField(key) && val == entry.Paragraph.Values[key] {
130+
delete(entry.Paragraph.Values, key)
131+
}
132+
}
104133
return entry
105134
}
106135

@@ -130,6 +159,14 @@ func (entry Manifest2822Entry) String() string {
130159
if str := entry.ConstraintsString(); str != "" {
131160
ret = append(ret, "Constraints: "+str)
132161
}
162+
if str := entry.ArchitecturesString(); str != "" {
163+
ret = append(ret, "Architectures: "+str)
164+
}
165+
for key,val := range entry.Paragraph.Values {
166+
if isArchField(key) {
167+
ret = append(ret, key+": "+val)
168+
}
169+
}
133170
return strings.Join(ret, "\n")
134171
}
135172

@@ -148,6 +185,34 @@ func (manifest Manifest2822) String() string {
148185
return strings.Join(ret, "\n\n")
149186
}
150187

188+
func (entry Manifest2822Entry) ArchGitRepo(arch string) string {
189+
if val,ok := entry.Paragraph.Values[arch+"-GitRepo"]; ok {
190+
return val
191+
}
192+
return entry.GitRepo
193+
}
194+
195+
func (entry Manifest2822Entry) ArchGitFetch(arch string) string {
196+
if val,ok := entry.Paragraph.Values[arch+"-GitFetch"]; ok {
197+
return val
198+
}
199+
return entry.GitFetch
200+
}
201+
202+
func (entry Manifest2822Entry) ArchGitCommit(arch string) string {
203+
if val,ok := entry.Paragraph.Values[arch+"-GitCommit"]; ok {
204+
return val
205+
}
206+
return entry.GitCommit
207+
}
208+
209+
func (entry Manifest2822Entry) ArchDirectory(arch string) string {
210+
if val,ok := entry.Paragraph.Values[arch+"-Directory"]; ok {
211+
return val
212+
}
213+
return entry.Directory
214+
}
215+
151216
func (entry Manifest2822Entry) HasTag(tag string) bool {
152217
for _, existingTag := range entry.Tags {
153218
if tag == existingTag {

0 commit comments

Comments
 (0)