Compiler uses runtime.GOOS instead of conditional compilation
This commit is contained in:
parent
e574b248e5
commit
eccb2e9a5b
|
@ -1,10 +1,55 @@
|
|||
// Package native provides OS native parameters for the compilation process.
|
||||
package native
|
||||
|
||||
import "os"
|
||||
import "errors"
|
||||
import "runtime"
|
||||
import "path/filepath"
|
||||
import "git.tebibyte.media/fspl/fspl/compiler"
|
||||
|
||||
// NativeResolver returns a resolver that resolves paths native to the operating
|
||||
// system.
|
||||
func NativeResolver () (*compiler.Resolver, error) {
|
||||
return nativeResolver()
|
||||
switch runtime.GOOS {
|
||||
case "windows": return windowsNativeResolver()
|
||||
default: return unixNativeResolver()
|
||||
}
|
||||
}
|
||||
|
||||
func unixNativeResolver () (*compiler.Resolver, error) {
|
||||
resolver := compiler.NewResolver (
|
||||
"/usr/local/src/fspl",
|
||||
"/usr/src/fspl",
|
||||
"/usr/local/incude/fspl",
|
||||
"/usr/include/fspl")
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil { return nil, err }
|
||||
resolver.AddPathFront (
|
||||
filepath.Join(homeDir, ".local/src/fspl"),
|
||||
filepath.Join(homeDir, ".local/include/fspl"))
|
||||
return resolver, nil
|
||||
}
|
||||
|
||||
func windowsNativeResolver () (*compiler.Resolver, error) {
|
||||
localAppData := os.Getenv("LOCALAPPDATA")
|
||||
if localAppData == "" {
|
||||
return nil, errors.New("could not get %LOCALAPPDATA%")
|
||||
}
|
||||
allUsersProfile := os.Getenv("ALLUSERSPROFILE")
|
||||
if allUsersProfile == "" {
|
||||
return nil, errors.New("could not get %ALLUSERSPROFILE%")
|
||||
}
|
||||
programFiles := os.Getenv("ProgramFiles")
|
||||
if programFiles == "" {
|
||||
return nil, errors.New("could not get %ProgramFiles%")
|
||||
}
|
||||
|
||||
resolver := compiler.NewResolver (
|
||||
filepath.Join(localAppData, "fspl\\src"),
|
||||
filepath.Join(localAppData, "fspl\\include"),
|
||||
filepath.Join(allUsersProfile, "fspl\\src"),
|
||||
filepath.Join(allUsersProfile, "fspl\\include"),
|
||||
filepath.Join(programFiles, "fspl\\src"),
|
||||
filepath.Join(programFiles, "fspl\\include"))
|
||||
return resolver, nil
|
||||
}
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package native
|
||||
|
||||
import "os"
|
||||
import "path/filepath"
|
||||
import "git.tebibyte.media/fspl/fspl/compiler"
|
||||
|
||||
func nativeResolver () (*compiler.Resolver, error) {
|
||||
resolver := compiler.NewResolver (
|
||||
"/usr/local/src/fspl",
|
||||
"/usr/src/fspl",
|
||||
"/usr/local/incude/fspl",
|
||||
"/usr/include/fspl")
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil { return nil, err }
|
||||
resolver.AddPathFront (
|
||||
filepath.Join(homeDir, ".local/src/fspl"),
|
||||
filepath.Join(homeDir, ".local/include/fspl"))
|
||||
return resolver, nil
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package native
|
||||
|
||||
import "os"
|
||||
import "errors"
|
||||
import "path/filepath"
|
||||
import "git.tebibyte.media/fspl/fspl/compiler"
|
||||
|
||||
func nativeResolver () (*compiler.Resolver, error) {
|
||||
localAppData := os.Getenv("LOCALAPPDATA")
|
||||
if localAppData == "" {
|
||||
return nil, errors.New("could not get %LOCALAPPDATA%")
|
||||
}
|
||||
allUsersProfile := os.Getenv("ALLUSERSPROFILE")
|
||||
if allUsersProfile == "" {
|
||||
return nil, errors.New("could not get %ALLUSERSPROFILE%")
|
||||
}
|
||||
programFiles := os.Getenv("ProgramFiles")
|
||||
if programFiles == "" {
|
||||
return nil, errors.New("could not get %ProgramFiles%")
|
||||
}
|
||||
|
||||
resolver := compiler.NewResolver (
|
||||
filepath.Join(localAppData, "fspl\\src"),
|
||||
filepath.Join(localAppData, "fspl\\include"),
|
||||
filepath.Join(allUsersProfile, "fspl\\src"),
|
||||
filepath.Join(allUsersProfile, "fspl\\include"),
|
||||
filepath.Join(programFiles, "fspl\\src"),
|
||||
filepath.Join(programFiles, "fspl\\include"))
|
||||
return resolver, nil
|
||||
}
|
Loading…
Reference in New Issue