diff --git a/cmd/linuxdb.go b/cmd/linuxdb.go index d3a92cb2..90e92548 100644 --- a/cmd/linuxdb.go +++ b/cmd/linuxdb.go @@ -7,15 +7,20 @@ import ( "gopkg.in/yaml.v3" ) +// LinuxDB is the database for linux distribution data. type LinuxDB struct { Distributions map[string]*Distribution `yaml:"distributions"` } +// Distribution holds the os-release ID and a map of releases. type Distribution struct { ID string `yaml:"id"` Releases map[string]*Release `yaml:"releases"` } +// GetRelease attempts to return the specific Release information +// for the given release name. If there is no specific match, the +// default release data is returned. func (d *Distribution) GetRelease(name string) *Release { result := d.Releases[name] if result == nil { @@ -24,18 +29,29 @@ func (d *Distribution) GetRelease(name string) *Release { return result } +// Release holds the name and version of the release as given by +// os-release. Programs is a slice of dependant programs required +// to be present on the local installation for Wails to function. +// Libraries is a slice of libraries that must be present for Wails +// applications to compile. type Release struct { - Name string `yaml:"name"` - Version string `yaml:"version"` - Programs []*Prerequisite `yaml:"programs"` - Libraries []*Prerequisite `yaml:"libraries"` + Name string `yaml:"name"` + Version string `yaml:"version"` + GccVersionCommand string `yaml:"gccversioncommand"` + Programs []*Prerequisite `yaml:"programs"` + Libraries []*Prerequisite `yaml:"libraries"` } +// Prerequisite is a simple struct containing a program/library name +// plus the distribution specific help text indicating how to install +// it. type Prerequisite struct { Name string `yaml:"name"` Help string `yaml:"help,omitempty"` } +// Load will load the given filename from disk and attempt to +// import the data into the LinuxDB. func (l *LinuxDB) Load(filename string) error { if fs.FileExists(filename) { data, err := fs.LoadAsBytes(filename) @@ -47,41 +63,21 @@ func (l *LinuxDB) Load(filename string) error { return nil } +// ImportData will unmarshal the given YAML formatted data +// into the LinuxDB func (l *LinuxDB) ImportData(data []byte) error { return yaml.Unmarshal(data, l) } +// GetDistro returns the Distribution information for the +// given distribution name. If the distribution is not supported, +// nil is returned. func (l *LinuxDB) GetDistro(name string) *Distribution { return l.Distributions[name] } -// func (l *LinuxDB) GetDistribution(name string) *Distribution { -// return l.Distributions[name] -// } - -// func (l *LinuxDB) Save() error { -// return fs.SaveAsJSON(l, l.filename) -// } - -// func (l *LinuxDB) GetPreRequisistes(name string, version string) ([]*DistributionPrerequisite, error) { -// distro := l.GetDistribution(name) -// if distro == nil { -// return nil, fmt.Errorf("distribution %s unsupported at this time", name) -// } - -// releaseInfo := distro.GetReleaseOrDefault(version) -// return releaseInfo.Prerequisites, nil - -// } - -// func (l *LinuxDBDistribution) GetReleaseOrDefault(release string) *DistributionRelease { -// result := l.Releases[release] -// if result == nil { -// result = l.Releases["default"] -// } -// return result -// } - +// NewLinuxDB creates a new LinuxDB instance from the bundled +// linuxdb.yaml file. func NewLinuxDB() *LinuxDB { data := mewn.Bytes("./linuxdb.yaml") result := LinuxDB{ diff --git a/cmd/linuxdb.yaml b/cmd/linuxdb.yaml index f72c5d46..573c8d01 100644 --- a/cmd/linuxdb.yaml +++ b/cmd/linuxdb.yaml @@ -6,6 +6,7 @@ distributions: default: name: Ubuntu version: default + gccversioncommand: &gccdumpfullversion -dumpfullversion programs: &ubuntudefaultprograms - name: gcc help: Please install with `sudo apt install build-essentials` and try again @@ -24,6 +25,7 @@ distributions: default: version: default name: Debian + gccversioncommand: &gccdumpversion -dumpversion programs: *ubuntudefaultprograms libraries: *ubuntudefaultlibraries parrot: @@ -32,6 +34,7 @@ distributions: default: version: default name: Parrot + gccversioncommand: *gccdumpversion programs: *ubuntudefaultprograms libraries: *ubuntudefaultlibraries zorin: @@ -40,6 +43,7 @@ distributions: default: version: default name: Zorin + gccversioncommand: *gccdumpversion programs: - name: gcc help: Please install with `sudo apt install build-essentials` and try again @@ -54,6 +58,7 @@ distributions: default: version: default name: CentOS + gccversioncommand: *gccdumpversion programs: - name: gcc help: Please install with `sudo yum install gcc-c++ make` and try again @@ -72,6 +77,7 @@ distributions: default: version: default name: Fedora + gccversioncommand: *gccdumpfullversion programs: - name: gcc help: Please install with `sudo yum install gcc-c++ make` and try again @@ -86,6 +92,7 @@ distributions: default: version: default name: Arch Linux + gccversioncommand: *gccdumpversion prerequisites: - name: gtk3 help: Please install with `sudo pacman -S gtk3` and try again @@ -103,6 +110,7 @@ distributions: default: version: default name: Gentoo + gccversioncommand: *gccdumpversion prerequisites: - name: gtk+:3 help: Please install with `sudo emerge gtk+:3` and try again diff --git a/cmd/wails/9_issue.go b/cmd/wails/9_issue.go index 24d7f64d..09bf5faa 100644 --- a/cmd/wails/9_issue.go +++ b/cmd/wails/9_issue.go @@ -58,24 +58,23 @@ To help you in this process, we will ask for some information, add Go/Wails deta case "linux": // for linux we have to collect // the distribution name - distro := cmd.GetLinuxDistroInfo() - // and use it as nested switch - switch distro.ID { - default: // most supported distros are printing the right result with just 'gcc -dumpversion' - gcc := program.FindProgram("gcc") - if gcc != nil { - stdout, _, _, _ := gcc.Run("-dumpversion") - gccVersion = strings.TrimSpace(stdout) - } - case "fedora", "ubuntu": // except fedora & ubuntu that require 'gcc -dumpfullversion' - gcc := program.FindProgram("gcc") - if gcc != nil { - stdout, _, _, _ := gcc.Run("-dumpfullversion") - gccVersion = strings.TrimSpace(stdout) - } - } + distroInfo := cmd.GetLinuxDistroInfo() + linuxDB := cmd.NewLinuxDB() + distro := linuxDB.GetDistro(distroInfo.ID) + release := distro.GetRelease(distroInfo.Release) + gccVersionCommand := release.GccVersionCommand - // TODO: windows support + gcc := program.FindProgram("gcc") + if gcc != nil { + stdout, _, _, _ := gcc.Run(gccVersionCommand) + gccVersion = strings.TrimSpace(stdout) + } + case "windows": + gcc := program.FindProgram("gcc") + if gcc != nil { + stdout, _, _, _ := gcc.Run("-dumpversion") + gccVersion = strings.TrimSpace(stdout) + } } npm := program.FindProgram("npm")