Check platform for module config
This commit is contained in:
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
@@ -14,7 +14,8 @@
|
||||
"type": "delve",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/src",
|
||||
"args": ["link", "test_module", "-d"],
|
||||
"args1": ["link", "test_module", "-d"],
|
||||
"args": ["info"],
|
||||
"dlvCwd": "${workspaceFolder}/src"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"alma/helpers"
|
||||
"cmp"
|
||||
"encoding/json"
|
||||
"io"
|
||||
@@ -36,8 +37,9 @@ func LoadModuleConfiguration(moduleConfigPath string) *ModuleConfiguration {
|
||||
platformKeys := make([]string, 0, len(moduleConfigurationRoot))
|
||||
|
||||
for key := range moduleConfigurationRoot {
|
||||
if key != "default" {
|
||||
if key != "default" && helpers.IsOnPlatform(key) {
|
||||
platformKeys = append(platformKeys, key)
|
||||
println("Adding platform '" + key + "'")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +53,7 @@ func LoadModuleConfiguration(moduleConfigPath string) *ModuleConfiguration {
|
||||
}
|
||||
|
||||
for _, platformKey := range platformKeys {
|
||||
// TODO: apply only the platform-specific configuration
|
||||
println("Merging platform '" + platformKey + "'")
|
||||
moduleConfiguration.Merge(moduleConfigurationRoot[platformKey])
|
||||
}
|
||||
|
||||
|
||||
62
src/helpers/osinfo.go
Normal file
62
src/helpers/osinfo.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const OsIdentifierDefault = "default"
|
||||
const OsIdentifierLinux = "linux"
|
||||
const OsIdentifierMac = "macos"
|
||||
const OsIdentifierWindows = "windows"
|
||||
|
||||
const osReleasePathLinux = "/etc/os-release"
|
||||
|
||||
func GetOsIdentifier() string {
|
||||
baseIdentifier := getBaseOsIdentifier()
|
||||
|
||||
return baseIdentifier + "-" + getNormalizedArch()
|
||||
}
|
||||
|
||||
func IsOnPlatform(platform string) bool {
|
||||
return strings.Index(GetOsIdentifier(), platform) == 0
|
||||
}
|
||||
|
||||
func getBaseOsIdentifier() string {
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
return OsIdentifierWindows
|
||||
case "darwin":
|
||||
return OsIdentifierMac
|
||||
case "linux":
|
||||
file, err := os.Open(osReleasePathLinux)
|
||||
|
||||
if err != nil {
|
||||
return OsIdentifierLinux
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
line := strings.ToLower(scanner.Text())
|
||||
if strings.HasPrefix(line, "id=") {
|
||||
return OsIdentifierLinux + "-" + strings.Trim(line[3:], "\"")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return runtime.GOOS
|
||||
}
|
||||
|
||||
func getNormalizedArch() string {
|
||||
switch runtime.GOARCH {
|
||||
case "amd64":
|
||||
return "x64"
|
||||
case "386":
|
||||
return "x86"
|
||||
}
|
||||
|
||||
return runtime.GOARCH
|
||||
}
|
||||
@@ -5,5 +5,13 @@
|
||||
"test_folder": "test_folder",
|
||||
"test_folder2": "test_folder3"
|
||||
}
|
||||
},
|
||||
"win": {
|
||||
},
|
||||
"linux": {
|
||||
},
|
||||
"linux-fedora-x64": {
|
||||
},
|
||||
"linux-fedora": {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user