This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spackEnv.go
106 lines (90 loc) · 2.59 KB
/
spackEnv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package repo
import (
"io/ioutil"
"strings"
"gopkg.in/yaml.v2"
)
type SpackEnv struct {
Spack Spack `yaml:"spack"`
}
type Spack struct {
Specs []string `yaml:"specs,omitempty"`
View bool `yaml:"view"`
Packages map[string]SpackPackages `yaml:"packages,omitempty"`
Config SpackConfig `yaml:"config"`
Container SpackContainer `yaml:"container"`
Mirrors map[string]string `yaml:"mirrors,omitempty"`
}
type SpackPackages struct {
Target []string `yaml:"target,omitempty"`
}
type SpackConfig struct {
Concretizer string `yaml:"concretizer,omitempty"`
Compiler SpackConfigCompiler `yaml:"compiler,omitempty"`
InstallMissingCompilers bool `yaml:"install_missing_compilers"`
InstallTree SpackConfigInstallTree `yaml:"install_tree,omitempty"`
}
type SpackConfigInstallTree struct {
Root string `yaml:"root,omitempty"`
PaddedLength int `yaml:"padded_length,omitempty"`
}
type SpackConfigCompiler struct {
Target string `yaml:"target,omitempty"`
}
type SpackContainer struct {
OSPackages SpackContainerPackages `yaml:"os_packages,omitempty"`
Images SpackContainerImages `yaml:"images,omitempty"`
Strip bool `yaml:"strip"`
}
type SpackContainerImages struct {
Build string `yaml:"build,omitempty"`
Final string `yaml:"final,omitempty"`
}
type SpackContainerPackages struct {
Build []string `yaml:"build,omitempty"`
Final []string `yaml:"final,omitempty"`
}
func defaultEnv(defaultPath string) (output SpackEnv, err error) {
input, err := ioutil.ReadFile(defaultPath)
if err != nil {
return output, err
}
err = yaml.Unmarshal(input, &output)
return output, err
}
// ParseSpackEnv parses a spack environment into a go struct.
func ParseSpackEnv(defaultPath, containerPath string) (result SpackEnv, err error) {
result, err = defaultEnv(defaultPath)
if err != nil {
return
}
input, err := ioutil.ReadFile(containerPath)
if err != nil {
return
}
err = yaml.Unmarshal(input, &result)
if err != nil {
return
}
// Clean specs from varient/version information.
specs := []string{}
for _, spec := range result.Spack.Specs {
i := strings.IndexFunc(spec, versend)
if i > 0 {
specs = append(specs, spec[:i])
} else {
specs = append(specs, spec)
}
}
result.Spack.Specs = specs
return result, nil
}
// versend returns true at the end of the name of a dependency
func versend(input rune) bool {
for _, c := range []rune{'@', '~', '+', '%'} {
if input == c {
return true
}
}
return false
}