Skip to content

Commit

Permalink
save dev state
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Jan 19, 2024
1 parent 42c1d92 commit f8af821
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 26 deletions.
6 changes: 6 additions & 0 deletions lpm-builder/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,9 @@ func Utf8FriendlyJsonMarshal(i interface{}) ([]byte, error) {
err := encoder.Encode(i)
return bytes.TrimRight(buffer.Bytes(), "\n"), err
}

func Assert(condition bool, message string) {
if !condition {
panic(fmt.Sprintf("assertion failed at %s", message))
}
}
79 changes: 53 additions & 26 deletions lpm-builder/pkg/template/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@ package template
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
common "lpm_builder/pkg/common"
"net/url"
"regexp"
)

type Template struct {
Name string `json:"name"`
Description string `json:"description"`
Maintainer string `json:"maintainer"`
SourceRepository string `json:"source_repository"`
Homepage string `json:"homepage"`
Arch string `json:"arch"`
Kind string `json:"kind"`
Name string `json:"name"`
Description string `json:"description"`
Maintainer string `json:"maintainer"`
SourceRepository string `json:"source_repository"`
Homepage string `json:"homepage"`
Arch string `json:"arch"`
Kind string `json:"kind"`
Tags []string `json:"tags"`
License string `json:"license"`
Builds map[string]Build `json:"builds"`
}

type Build struct {
FileChecksumAlgo string `json:"file_checksum_algo"`
Tags []string `json:"tags"`
Version common.Version `json:"version"`
License string `json:"license"`
MandatoryDependencies Dependencies `json:"mandatory_dependencies"`
SuggestedDependencies Dependencies `json:"suggested_dependencies"`
}
Expand Down Expand Up @@ -78,16 +83,29 @@ func (template *Template) validate() error {

}

// File checksum algorithm
// Builds
{
var supportedAlgorithms []string = []string{
"md5",
"sha256",
"sha512",
}

if !common.Contains(supportedAlgorithms, template.FileChecksumAlgo) {
return errors.New("Unsupported checksum algorithm.")
for build_name, build := range template.Builds {
var supportedAlgorithms []string = []string{
"md5",
"sha256",
"sha512",
}

common.Assert(common.Contains(supportedAlgorithms, build.FileChecksumAlgo), fmt.Sprintf("Unsupported checksum algorithm used for '%s' build. Supported algorithms: %v", build_name, supportedAlgorithms))

var supportedBuilds []string = []string{
"amd64",
"source",
"noarch",
}

common.Assert(common.Contains(supportedBuilds, build_name), fmt.Sprintf("Unsupported build '%s'. Supported builds (please contact with maintainers to support more builds): %v", supportedBuilds))

if build_name == "source" {
common.Assert(len(build.MandatoryDependencies.Build) == 0, "source packages can not contain build time dependencies")
common.Assert(len(build.SuggestedDependencies.Build) == 0, "source packages can not contain build time dependencies")
}
}
}

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

var template = Template{
MandatoryDependencies: Dependencies{
Build: []common.Dependency{},
Runtime: []common.Dependency{},
},
SuggestedDependencies: Dependencies{
Build: []common.Dependency{},
Runtime: []common.Dependency{},
},
// TODO
// MandatoryDependencies: Dependencies{
// Build: []common.Dependency{},
// Runtime: []common.Dependency{},
// },
// SuggestedDependencies: Dependencies{
// Build: []common.Dependency{},
// Runtime: []common.Dependency{},
// },
}

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

// TODO
for build_name, _ := range template.Builds {
if build_name == "" {
} else if build_name == "" {
} else {
}
}

for i := range template.MandatoryDependencies.Runtime {
if len(template.MandatoryDependencies.Runtime[i].Version.Condition) == 0 {
template.MandatoryDependencies.Runtime[i].Version.Condition = ">="
Expand Down

0 comments on commit f8af821

Please sign in to comment.