q/src/build/config/init.go

59 lines
849 B
Go

package config
import (
"os"
"path"
"path/filepath"
"runtime/debug"
)
var (
Executable string
Root string
Library string
WorkingDirectory string
)
func init() {
debug.SetGCPercent(-1)
var err error
Executable, err = os.Executable()
if err != nil {
panic(err)
}
WorkingDirectory, err = os.Getwd()
if err != nil {
panic(err)
}
Root = filepath.Dir(Executable)
Library = filepath.Join(Root, "lib")
stat, err := os.Stat(Library)
if os.IsNotExist(err) || stat == nil || !stat.IsDir() {
findLibrary()
}
}
func findLibrary() {
dir := WorkingDirectory
for {
Library = path.Join(dir, "lib")
stat, err := os.Stat(Library)
if !os.IsNotExist(err) && stat != nil && stat.IsDir() {
return
}
if dir == "/" {
panic("standard library not found")
}
dir = filepath.Dir(dir)
}
}