Skip to content

Commit

Permalink
fix rpath issue on linux again + more fixes for go modules
Browse files Browse the repository at this point in the history
  • Loading branch information
therecipe committed Jan 18, 2019
1 parent 38b504f commit df49a97
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 33 deletions.
3 changes: 1 addition & 2 deletions internal/binding/parser/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package parser
import (
"bytes"
"fmt"
"os/exec"
"runtime"
"sort"
"strings"
Expand Down Expand Up @@ -443,7 +442,7 @@ func GetCustomLibs(target, tags string) map[string]string {
getCustomLibsCacheMutex.Unlock()

if !ok {
cmd := exec.Command("go", "list", "-e", "-f", "{{.ImportPath}}", fmt.Sprintf("-tags=\"%v\"", tags))
cmd := utils.GoList("{{.ImportPath}}", fmt.Sprintf("-tags=\"%v\"", tags))
cmd.Dir = c.Pkg

/*TODO: cycle dep of cmd.BuildEnv
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func InitEnv(target string) {
}

if !utils.ExistsDir(utils.QT_DIR()) {
qt_dir := strings.TrimSpace(utils.RunCmd(exec.Command("go", "list", "-f", "{{.Dir}}", "github.com/therecipe/env_"+runtime.GOOS+"_amd64_"+strconv.Itoa(utils.QT_VERSION_NUM())[:3]), "get env dir"))
qt_dir := strings.TrimSpace(utils.RunCmd(utils.GoList("{{.Dir}}", "github.com/therecipe/env_"+runtime.GOOS+"_amd64_"+strconv.Itoa(utils.QT_VERSION_NUM())[:3]), "get env dir"))

switch runtime.GOOS {
case "linux", "darwin", "windows":
Expand Down Expand Up @@ -642,7 +642,7 @@ func BuildEnv(target, name, depPath string) (map[string]string, []string, []stri
}

if target == "linux" {
env["CGO_LDFLAGS"] = "-Wl,-rpath,./lib -Wl,--disable-new-dtags"
env["CGO_LDFLAGS"] = "-Wl,-rpath,$ORIGIN/lib -Wl,--disable-new-dtags"
}

case "rpi1", "rpi2", "rpi3":
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deploy/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ func bundle(mode, target, path, name, depPath string, tagsCustom string, fast bo
if tagsCustom != "" {
tags = append(tags, strings.Split(tagsCustom, " ")...)
}
lcmd := exec.Command("go", "list", "-e", "-f", "{{ join .Deps \"|\" }}", fmt.Sprintf("-tags=\"%v\"", strings.Join(tags, "\" \"")))
lcmd := utils.GoList("{{ join .Deps \"|\" }}", fmt.Sprintf("-tags=\"%v\"", strings.Join(tags, "\" \"")))
lcmd.Dir = path
for k, v := range env {
lcmd.Env = append(lcmd.Env, fmt.Sprintf("%v=%v", k, v))
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deploy/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func run(target, name, depPath, device string) {
utils.Log.WithError(err).Errorf("failed to run %v for %v", name, target)
}

case "js", "wasm": //TODO: REVIEW
case "js", "wasm": //TODO: REVIEW and use emscripten wrapper instead
if runtime.GOOS == "darwin" {
exec.Command("/Applications/Firefox Nightly.app/Contents/MacOS/firefox", filepath.Join(depPath, "index.html")).Start()
}
Expand Down
4 changes: 1 addition & 3 deletions internal/cmd/minimal/minimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Minimal(path, target, tags string) {
}

env, tagsEnv, _, _ := cmd.BuildEnv(target, "", "")
scmd := exec.Command("go", "list")
scmd := utils.GoList("'{{.Stale}}':'{{.StaleReason}}'")
scmd.Dir = path

tagsEnv = append(tagsEnv, "minimal")
Expand All @@ -47,8 +47,6 @@ func Minimal(path, target, tags string) {
scmd.Env = append(scmd.Env, fmt.Sprintf("%v=%v", key, value))
}

scmd.Args = append(scmd.Args, "-f", "'{{.Stale}}':'{{.StaleReason}}'")

if out := utils.RunCmdOptional(scmd, fmt.Sprintf("go check stale for %v on %v", target, runtime.GOOS)); strings.Contains(out, "but available in build cache") || strings.Contains(out, "false") {
utils.Log.WithField("path", path).Debug("skipping already cached minimal")
return
Expand Down
16 changes: 6 additions & 10 deletions internal/cmd/moc/moc.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func moc(path, target, tags string, fast, slow, root bool, l int, dirty bool) {

if !dirty {
env, tagsEnv, _, _ := cmd.BuildEnv(target, "", "")
scmd := exec.Command("go", "list")
scmd := utils.GoList("'{{.Stale}}':'{{.StaleReason}}'")
scmd.Dir = path

if !fast && !utils.QT_FAT() {
Expand All @@ -86,8 +86,6 @@ func moc(path, target, tags string, fast, slow, root bool, l int, dirty bool) {
scmd.Env = append(scmd.Env, fmt.Sprintf("%v=%v", key, value))
}

scmd.Args = append(scmd.Args, "-f", "'{{.Stale}}':'{{.StaleReason}}'")

if out := utils.RunCmdOptional(scmd, fmt.Sprintf("go check stale for %v on %v", target, runtime.GOOS)); strings.Contains(out, "but available in build cache") || strings.Contains(out, "false") {
utils.Log.WithField("path", path).Debug("skipping already cached moc")
return
Expand Down Expand Up @@ -334,7 +332,7 @@ func moc(path, target, tags string, fast, slow, root bool, l int, dirty bool) {
ResourceNamesMutex.Unlock()

env, tagsEnv, _, _ := cmd.BuildEnv(target, "", "")
scmd := exec.Command("go", "list")
scmd := utils.GoList("'{{.Stale}}':'{{.StaleReason}}'")
scmd.Dir = path

if !fast && !utils.QT_FAT() {
Expand All @@ -353,8 +351,6 @@ func moc(path, target, tags string, fast, slow, root bool, l int, dirty bool) {
scmd.Env = append(scmd.Env, fmt.Sprintf("%v=%v", key, value))
}

scmd.Args = append(scmd.Args, "-f", "'{{.Stale}}':'{{.StaleReason}}'")

if out := utils.RunCmdOptional(scmd, fmt.Sprintf("go check stale for %v on %v", target, runtime.GOOS)); strings.Contains(out, "but available in build cache") || strings.Contains(out, "false") {
utils.Log.WithField("path", path).Debug("skipping already cached moc")
} else {
Expand Down Expand Up @@ -540,7 +536,7 @@ func parse(path string) ([]*parser.Class, string, error) {
if n, ok := goNameCache[imp.Path.Value]; ok {
name = n
} else {
name = strings.TrimSpace(utils.RunCmd(exec.Command("go", "list", "-e", "-f", "{{.Name}}", strings.Replace(imp.Path.Value, "\"", "", -1)), "get import name"))
name = strings.TrimSpace(utils.RunCmd(utils.GoList("{{.Name}}", strings.Replace(imp.Path.Value, "\"", "", -1)), "get import name"))
goNameCache[imp.Path.Value] = name
}
goNameCacheMutex.Unlock()
Expand All @@ -550,7 +546,7 @@ func parse(path string) ([]*parser.Class, string, error) {
if d, ok := goDirCache[imp.Path.Value]; ok {
dir = d
} else {
dir = strings.TrimSpace(utils.RunCmd(exec.Command("go", "list", "-e", "-f", "{{.Dir}}", strings.Replace(imp.Path.Value, "\"", "", -1)), "get import dir"))
dir = strings.TrimSpace(utils.RunCmd(utils.GoList("{{.Dir}}", strings.Replace(imp.Path.Value, "\"", "", -1)), "get import dir"))
goDirCache[imp.Path.Value] = dir
}
goDirCacheMutex.Unlock()
Expand Down Expand Up @@ -580,7 +576,7 @@ func parse(path string) ([]*parser.Class, string, error) {
if n, ok := goNameCache[imp.Path.Value]; ok {
name = n
} else {
name = strings.TrimSpace(utils.RunCmd(exec.Command("go", "list", "-e", "-f", "{{.Name}}", strings.Replace(imp.Path.Value, "\"", "", -1)), "get import name"))
name = strings.TrimSpace(utils.RunCmd(utils.GoList("{{.Name}}", strings.Replace(imp.Path.Value, "\"", "", -1)), "get import name"))
goNameCache[imp.Path.Value] = name
}
goNameCacheMutex.Unlock()
Expand All @@ -594,7 +590,7 @@ func parse(path string) ([]*parser.Class, string, error) {
if d, ok := goDirCache[imp.Path.Value]; ok {
dir = d
} else {
dir = strings.TrimSpace(utils.RunCmd(exec.Command("go", "list", "-e", "-f", "{{.Dir}}", strings.Replace(imp.Path.Value, "\"", "", -1)), "get import dir"))
dir = strings.TrimSpace(utils.RunCmd(utils.GoList("{{.Dir}}", strings.Replace(imp.Path.Value, "\"", "", -1)), "get import dir"))
goDirCache[imp.Path.Value] = dir
}
goDirCacheMutex.Unlock()
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/rcc/rcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func rcc(path, target, tagsCustom, output_dir string, root bool) {
tags = append(tags, strings.Split(tagsCustom, " ")...)
}

pkgCmd := exec.Command("go", "list", "-e", "-f", "{{.Name}}", fmt.Sprintf("-tags=\"%v\"", strings.Join(tags, "\" \"")))
pkgCmd := utils.GoList("{{.Name}}", fmt.Sprintf("-tags=\"%v\"", strings.Join(tags, "\" \"")))
pkgCmd.Dir = path
for k, v := range env {
pkgCmd.Env = append(pkgCmd.Env, fmt.Sprintf("%v=%v", k, v))
Expand Down Expand Up @@ -129,7 +129,7 @@ func rcc(path, target, tagsCustom, output_dir string, root bool) {
}
}

nameCmd := exec.Command("go", "list", "-e", "-f", "{{.ImportPath}}", fmt.Sprintf("-tags=\"%v\"", strings.Join(tags, "\" \"")))
nameCmd := utils.GoList("{{.ImportPath}}", fmt.Sprintf("-tags=\"%v\"", strings.Join(tags, "\" \"")))
nameCmd.Dir = path
for k, v := range env {
nameCmd.Env = append(nameCmd.Env, fmt.Sprintf("%v=%v", k, v))
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func GetImports(path, target, tagsCustom string, level int, onlyDirect, moc bool
}

//TODO: cache
cmd := exec.Command("go", "list", "-e", "-f", "'{{ join .TestImports \"|\" }}':'{{ join .XTestImports \"|\" }}':'{{ join ."+imp+" \"|\" }}'", fmt.Sprintf("-tags=\"%v\"", strings.Join(tags, "\" \"")))
cmd := utils.GoList("'{{ join .TestImports \"|\" }}':'{{ join .XTestImports \"|\" }}':'{{ join ."+imp+" \"|\" }}'", fmt.Sprintf("-tags=\"%v\"", strings.Join(tags, "\" \"")))
cmd.Dir = path
for k, v := range env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%v=%v", k, v))
Expand Down Expand Up @@ -106,7 +106,7 @@ func GetImports(path, target, tagsCustom string, level int, onlyDirect, moc bool
return
}

cmd := exec.Command("go", "list", "-e", "-f", "{{.Dir}}", fmt.Sprintf("-tags=\"%v\"", strings.Join(tags, "\" \"")), l)
cmd := utils.GoList("{{.Dir}}", fmt.Sprintf("-tags=\"%v\"", strings.Join(tags, "\" \"")), l)
for k, v := range env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%v=%v", k, v))
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func GetGoFiles(path, target, tagsCustom string) []string {
}

//TODO: cache
cmd := exec.Command("go", "list", "-e", "-f", "'{{ join .GoFiles \"|\" }}':'{{ join .CgoFiles \"|\" }}':'{{ join .TestGoFiles \"|\" }}':'{{ join .XTestGoFiles \"|\" }}'", fmt.Sprintf("-tags=\"%v\"", strings.Join(tags, "\" \"")))
cmd := utils.GoList("'{{ join .GoFiles \"|\" }}':'{{ join .CgoFiles \"|\" }}':'{{ join .TestGoFiles \"|\" }}':'{{ join .XTestGoFiles \"|\" }}'", fmt.Sprintf("-tags=\"%v\"", strings.Join(tags, "\" \"")))
cmd.Dir = path
for k, v := range env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%v=%v", k, v))
Expand Down
14 changes: 13 additions & 1 deletion internal/utils/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func GOFLAGS() string {
if flags, ok := os.LookupEnv("GOFLAGS"); ok {
return flags
}
if (strings.Contains(runtime.Version(), "1.11") || strings.Contains(runtime.Version(), "devel")) && UseGOMOD("") {
if UseGOMOD("") {
return "-mod=vendor"
}
return ""
Expand Down Expand Up @@ -289,3 +289,15 @@ func UseGOMOD(path string) (r bool) {
func QT_GEN_OPENGL() bool {
return os.Getenv("QT_GEN_OPENGL") == "true"
}

func GoList(args ...string) *exec.Cmd {
cmd := exec.Command("go", "list")
if UseGOMOD("") {
if !strings.Contains(strings.Join(args, "|"), "github.com/therecipe/env_"+runtime.GOOS+"_amd64") {
cmd.Args = append(cmd.Args, GOFLAGS())
}
}
cmd.Args = append(cmd.Args, "-e", "-f")
cmd.Args = append(cmd.Args, args...)
return cmd
}
3 changes: 1 addition & 2 deletions internal/utils/gopath.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package utils

import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
Expand All @@ -27,7 +26,7 @@ func GOBIN() string {
func MustGoPath() string {
mustGoPathMutex.Lock()
if len(mustGoPath) == 0 {
mustGoPath = strings.TrimSpace(RunCmd(exec.Command("go", "list", "-f", "{{.Root}}", "github.com/therecipe/qt"), "get list gopath"))
mustGoPath = strings.TrimSpace(RunCmd(GoList("{{.Root}}", "github.com/therecipe/qt"), "get list gopath"))
if len(mustGoPath) == 0 {
mustGoPath = GOPATH()
}
Expand Down
7 changes: 1 addition & 6 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ var (
func GoQtPkgPath(s ...string) (r string) {
goQtPkgPathMutex.Lock()
if len(goQtPkgPath) == 0 {
cmd := exec.Command("go", "list")
if UseGOMOD("") {
cmd.Args = append(cmd.Args, GOFLAGS())
}
cmd.Args = append(cmd.Args, "-f", "{{.Dir}}", packageName)
goQtPkgPath = strings.TrimSpace(RunCmd(cmd, "utils.GoQtPkgPath"))
goQtPkgPath = strings.TrimSpace(RunCmd(GoList("{{.Dir}}", packageName), "utils.GoQtPkgPath"))
}
r = goQtPkgPath
goQtPkgPathMutex.Unlock()
Expand Down

0 comments on commit df49a97

Please sign in to comment.