forked from wailsapp/wails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprerequisites.go
100 lines (88 loc) · 2.89 KB
/
prerequisites.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
package cmd
import (
"fmt"
"runtime"
)
func newPrerequisite(name, help string) *Prerequisite {
return &Prerequisite{Name: name, Help: help}
}
// Prerequisites is a list of things required to use Wails
type Prerequisites []*Prerequisite
// Add given prereq object to list
func (p *Prerequisites) Add(prereq *Prerequisite) {
*p = append(*p, prereq)
}
// GetRequiredPrograms returns a list of programs required for the platform
func GetRequiredPrograms() (*Prerequisites, error) {
switch runtime.GOOS {
case "darwin":
return getRequiredProgramsOSX(), nil
case "linux":
return getRequiredProgramsLinux(), nil
case "windows":
return getRequiredProgramsWindows(), nil
default:
return nil, fmt.Errorf("platform '%s' not supported at this time", runtime.GOOS)
}
}
func getRequiredProgramsOSX() *Prerequisites {
result := &Prerequisites{}
result.Add(newPrerequisite("clang", "Please install with `xcode-select --install` and try again"))
result.Add(newPrerequisite("npm", "Please install from https://nodejs.org/en/download/ and try again"))
return result
}
func getRequiredProgramsLinux() *Prerequisites {
result := &Prerequisites{}
distroInfo := GetLinuxDistroInfo()
if distroInfo.Distribution != Unknown {
var linuxDB = NewLinuxDB()
distro := linuxDB.GetDistro(distroInfo.ID)
release := distro.GetRelease(distroInfo.Release)
for _, program := range release.Programs {
result.Add(program)
}
}
return result
}
// TODO: Test this on Windows
func getRequiredProgramsWindows() *Prerequisites {
result := &Prerequisites{}
result.Add(newPrerequisite("gcc", "Please install gcc from here and try again: http://tdm-gcc.tdragon.net/download. You will need to add the bin directory to your path, EG: C:\\TDM-GCC-64\\bin\\"))
result.Add(newPrerequisite("npm", "Please install node/npm from here and try again: https://nodejs.org/en/download/"))
return result
}
// GetRequiredLibraries returns a list of libraries (packages) required for the platform
func GetRequiredLibraries() (*Prerequisites, error) {
switch runtime.GOOS {
case "darwin":
return getRequiredLibrariesOSX()
case "linux":
return getRequiredLibrariesLinux()
case "windows":
return getRequiredLibrariesWindows()
default:
return nil, fmt.Errorf("platform '%s' not supported at this time", runtime.GOOS)
}
}
func getRequiredLibrariesOSX() (*Prerequisites, error) {
result := &Prerequisites{}
return result, nil
}
func getRequiredLibrariesLinux() (*Prerequisites, error) {
result := &Prerequisites{}
// The Linux Distribution DB
distroInfo := GetLinuxDistroInfo()
if distroInfo.Distribution != Unknown {
var linuxDB = NewLinuxDB()
distro := linuxDB.GetDistro(distroInfo.ID)
release := distro.GetRelease(distroInfo.Release)
for _, library := range release.Libraries {
result.Add(library)
}
}
return result, nil
}
func getRequiredLibrariesWindows() (*Prerequisites, error) {
result := &Prerequisites{}
return result, nil
}