Skip to content

Commit f8af821

Browse files
committed
save dev state
Signed-off-by: onur-ozkan <[email protected]>
1 parent 42c1d92 commit f8af821

File tree

2 files changed

+59
-26
lines changed

2 files changed

+59
-26
lines changed

lpm-builder/pkg/common/common.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,9 @@ func Utf8FriendlyJsonMarshal(i interface{}) ([]byte, error) {
116116
err := encoder.Encode(i)
117117
return bytes.TrimRight(buffer.Bytes(), "\n"), err
118118
}
119+
120+
func Assert(condition bool, message string) {
121+
if !condition {
122+
panic(fmt.Sprintf("assertion failed at %s", message))
123+
}
124+
}

lpm-builder/pkg/template/structs.go

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,29 @@ package template
33
import (
44
"encoding/json"
55
"errors"
6+
"fmt"
67
"io/ioutil"
78
common "lpm_builder/pkg/common"
89
"net/url"
910
"regexp"
1011
)
1112

1213
type Template struct {
13-
Name string `json:"name"`
14-
Description string `json:"description"`
15-
Maintainer string `json:"maintainer"`
16-
SourceRepository string `json:"source_repository"`
17-
Homepage string `json:"homepage"`
18-
Arch string `json:"arch"`
19-
Kind string `json:"kind"`
14+
Name string `json:"name"`
15+
Description string `json:"description"`
16+
Maintainer string `json:"maintainer"`
17+
SourceRepository string `json:"source_repository"`
18+
Homepage string `json:"homepage"`
19+
Arch string `json:"arch"`
20+
Kind string `json:"kind"`
21+
Tags []string `json:"tags"`
22+
License string `json:"license"`
23+
Builds map[string]Build `json:"builds"`
24+
}
25+
26+
type Build struct {
2027
FileChecksumAlgo string `json:"file_checksum_algo"`
21-
Tags []string `json:"tags"`
2228
Version common.Version `json:"version"`
23-
License string `json:"license"`
2429
MandatoryDependencies Dependencies `json:"mandatory_dependencies"`
2530
SuggestedDependencies Dependencies `json:"suggested_dependencies"`
2631
}
@@ -78,16 +83,29 @@ func (template *Template) validate() error {
7883

7984
}
8085

81-
// File checksum algorithm
86+
// Builds
8287
{
83-
var supportedAlgorithms []string = []string{
84-
"md5",
85-
"sha256",
86-
"sha512",
87-
}
88-
89-
if !common.Contains(supportedAlgorithms, template.FileChecksumAlgo) {
90-
return errors.New("Unsupported checksum algorithm.")
88+
for build_name, build := range template.Builds {
89+
var supportedAlgorithms []string = []string{
90+
"md5",
91+
"sha256",
92+
"sha512",
93+
}
94+
95+
common.Assert(common.Contains(supportedAlgorithms, build.FileChecksumAlgo), fmt.Sprintf("Unsupported checksum algorithm used for '%s' build. Supported algorithms: %v", build_name, supportedAlgorithms))
96+
97+
var supportedBuilds []string = []string{
98+
"amd64",
99+
"source",
100+
"noarch",
101+
}
102+
103+
common.Assert(common.Contains(supportedBuilds, build_name), fmt.Sprintf("Unsupported build '%s'. Supported builds (please contact with maintainers to support more builds): %v", supportedBuilds))
104+
105+
if build_name == "source" {
106+
common.Assert(len(build.MandatoryDependencies.Build) == 0, "source packages can not contain build time dependencies")
107+
common.Assert(len(build.SuggestedDependencies.Build) == 0, "source packages can not contain build time dependencies")
108+
}
91109
}
92110
}
93111

@@ -111,14 +129,15 @@ func DeserializeTemplate(templateDirPath string) Template {
111129
const templateLeafPath = "/template"
112130

113131
var template = Template{
114-
MandatoryDependencies: Dependencies{
115-
Build: []common.Dependency{},
116-
Runtime: []common.Dependency{},
117-
},
118-
SuggestedDependencies: Dependencies{
119-
Build: []common.Dependency{},
120-
Runtime: []common.Dependency{},
121-
},
132+
// TODO
133+
// MandatoryDependencies: Dependencies{
134+
// Build: []common.Dependency{},
135+
// Runtime: []common.Dependency{},
136+
// },
137+
// SuggestedDependencies: Dependencies{
138+
// Build: []common.Dependency{},
139+
// Runtime: []common.Dependency{},
140+
// },
122141
}
123142

124143
template_json_content, err := ioutil.ReadFile(templateDirPath + templateLeafPath)
@@ -130,6 +149,14 @@ func DeserializeTemplate(templateDirPath string) Template {
130149
err = template.validate()
131150
common.FailOnError(err)
132151

152+
// TODO
153+
for build_name, _ := range template.Builds {
154+
if build_name == "" {
155+
} else if build_name == "" {
156+
} else {
157+
}
158+
}
159+
133160
for i := range template.MandatoryDependencies.Runtime {
134161
if len(template.MandatoryDependencies.Runtime[i].Version.Condition) == 0 {
135162
template.MandatoryDependencies.Runtime[i].Version.Condition = ">="

0 commit comments

Comments
 (0)