cutego/internal/utils/env.go

120 lines
2.9 KiB
Go
Raw Normal View History

2016-10-28 05:00:58 +03:00
package utils
import (
"os"
"path/filepath"
"runtime"
"strings"
)
2016-12-30 23:40:48 +03:00
func QT_VERSION() string {
if version := os.Getenv("QT_VERSION"); version != "" {
return version
}
return "5.8.0"
2016-12-30 23:40:48 +03:00
}
func QT_VERSION_MAJOR() string {
return strings.Join(strings.Split(QT_VERSION(), ".")[:2], ".")
}
2016-10-28 05:00:58 +03:00
func QT_DIR() string {
if dir := os.Getenv("QT_DIR"); dir != "" {
return filepath.Clean(dir)
}
if runtime.GOOS == "windows" {
2016-12-30 23:40:48 +03:00
return "C:\\Qt\\Qt" + QT_VERSION()
2016-10-28 05:00:58 +03:00
}
2016-12-30 23:40:48 +03:00
return filepath.Join(os.Getenv("HOME"), "Qt"+QT_VERSION())
2016-10-28 05:00:58 +03:00
}
func QT_STUB() bool {
2017-01-02 23:26:38 +03:00
return strings.ToLower(os.Getenv("QT_STUB")) == "true" || UseMsys2()
2016-10-28 05:00:58 +03:00
}
func QT_DEBUG() bool {
return strings.ToLower(os.Getenv("QT_DEBUG")) == "true"
}
func CheckBuildTarget(buildTarget string) {
switch buildTarget {
case "desktop", "android", "ios", "ios-simulator",
"sailfish", "sailfish-emulator", "rpi1", "rpi2", "rpi3", "windows", "darwin", "linux",
"linux-docker", "windows-docker", "android-docker":
{
var buildDocker = strings.HasSuffix(buildTarget, "-docker")
switch buildTarget {
case "windows":
{
if runtime.GOOS == "windows" && !buildDocker {
} else if runtime.GOOS == "linux" || buildDocker {
} else {
Log.Fatalf("%v is currently not supported as a deploy target on %v", buildTarget, runtime.GOOS)
}
}
case "darwin", "ios", "ios-simulator":
{
if runtime.GOOS == "darwin" && !buildDocker {
} else {
Log.Fatalf("%v is currently not supported as a deploy target on %v (not even with docker)", buildTarget, runtime.GOOS)
}
}
case "linux":
{
if runtime.GOOS == "linux" && !buildDocker {
} else if buildDocker {
} else {
Log.Fatalf("%v is currently not supported as a deploy target on %v", buildTarget, runtime.GOOS)
}
}
}
}
default:
{
Log.Panicf("failed to recognize build target %v", buildTarget)
}
}
if buildTarget == "android" || strings.HasPrefix(buildTarget, "ios") {
switch {
case UseMsys2():
{
Log.Fatalf("%v is not supported as a deploy target on %v with MSYS2 -> install the official Qt version instead and try again", buildTarget, runtime.GOOS)
}
case UseHomeBrew():
{
Log.Fatalf("%v is not supported as a deploy target on %v with HomeBrew -> install the official Qt version instead and try again", buildTarget, runtime.GOOS)
}
case UsePkgConfig():
{
Log.Fatalf("%v is not supported as a deploy target on %v with PkgConfig -> install the official Qt version instead and try again", buildTarget, runtime.GOOS)
}
}
}
}
2017-02-01 18:38:51 +03:00
func IsCI() bool {
return strings.ToLower(os.Getenv("CI")) == "true"
}
func QT_QMAKE_DIR() string {
2017-02-27 03:23:27 +03:00
if dir := os.Getenv("QT_QMAKE_DIR"); dir != "" {
return filepath.Clean(dir)
}
return ""
}
func QT_QMAKE_CGO() bool {
return strings.ToLower(os.Getenv("QT_QMAKE_CGO")) == "true"
}
2017-02-28 21:27:55 +03:00
func QT_DOCKER() bool {
return strings.ToLower(os.Getenv("QT_DOCKER")) == "true"
}