-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform.go
More file actions
78 lines (66 loc) · 2.29 KB
/
platform.go
File metadata and controls
78 lines (66 loc) · 2.29 KB
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
// Package platforms translates platform identifier strings across package
// ecosystems. An ARM64 Mac is "darwin/arm64" to Go, "darwin-arm64" to Node,
// "aarch64-apple-darwin" to Rust, "arm64-darwin" to RubyGems, and
// "macosx_11_0_arm64" to Python. This package provides a shared mapping
// between all of them.
package platforms
import "sort"
// Ecosystem identifies a package ecosystem's platform naming convention.
type Ecosystem string
const (
Go Ecosystem = "go"
Node Ecosystem = "node"
Rust Ecosystem = "rust"
RubyGems Ecosystem = "rubygems"
Python Ecosystem = "python"
Debian Ecosystem = "debian"
LLVM Ecosystem = "llvm"
NuGet Ecosystem = "nuget"
Vcpkg Ecosystem = "vcpkg"
Conan Ecosystem = "conan"
Homebrew Ecosystem = "homebrew"
Swift Ecosystem = "swift"
Kotlin Ecosystem = "kotlin"
Maven Ecosystem = "maven"
)
var allEcosystems = []Ecosystem{Go, Node, Rust, RubyGems, Python, Debian, LLVM, NuGet, Vcpkg, Conan, Homebrew, Swift, Kotlin, Maven}
// Ecosystems returns all supported ecosystem identifiers in sorted order.
func Ecosystems() []Ecosystem {
out := make([]Ecosystem, len(allEcosystems))
copy(out, allEcosystems)
sort.Slice(out, func(i, j int) bool { return out[i] < out[j] })
return out
}
// Platform represents a canonical platform with architecture, OS, and
// optional vendor, ABI, OS version, and libc version fields.
type Platform struct {
Arch string
OS string
Vendor string
ABI string
OSVersion string
LibCVersion string
}
// ErrUnknownEcosystem is returned when an unrecognized ecosystem is provided.
type ErrUnknownEcosystem struct {
Ecosystem string
}
func (e *ErrUnknownEcosystem) Error() string {
return "unknown ecosystem: " + e.Ecosystem
}
// ErrUnknownPlatform is returned when a platform string cannot be parsed.
type ErrUnknownPlatform struct {
Ecosystem Ecosystem
Input string
}
func (e *ErrUnknownPlatform) Error() string {
return "unknown platform string for " + string(e.Ecosystem) + ": " + e.Input
}
// ErrNoMapping is returned when a platform cannot be formatted for an ecosystem.
type ErrNoMapping struct {
Ecosystem Ecosystem
Platform Platform
}
func (e *ErrNoMapping) Error() string {
return "no mapping for " + e.Platform.Arch + "/" + e.Platform.OS + " in " + string(e.Ecosystem)
}