From 00c9ee556b2b84471e650f3f45ebf109c099bd1f Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 7 Dec 2018 16:26:39 +0100 Subject: [PATCH] go.mod can be anywhere --- xgo.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/xgo.go b/xgo.go index 50ad697d..85106f21 100644 --- a/xgo.go +++ b/xgo.go @@ -238,17 +238,6 @@ func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string // Resolve the repository import path from the file path config.Repository = resolveImportPath(config.Repository) - // Check if the repo uses go 1.11 modules by determening if it has a go.mod file - if _, err := os.Stat(config.Repository + "/go.mod"); !os.IsNotExist(err) { - usesModules = true - - // Check if it has a vendor folder to use that when building with mod - vendorfolder, err := os.Stat(config.Repository + "/vendor") - if !os.IsNotExist(err) && vendorfolder.Mode().IsDir() { - // TODO: how to pass -mod=vendor to the build script? - } - } - // Iterate over all the local libs and export the mount points if os.Getenv("GOPATH") == "" && !usesModules { log.Fatalf("No $GOPATH is set or forwarded to xgo") @@ -278,6 +267,10 @@ func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string if filepath.HasPrefix(target, sources) { return nil } + // Check if the repo uses go 1.11 modules by determening if it has a go.mod file + if _, err := os.Stat(path + "/go.mod"); !os.IsNotExist(err) && !usesModules { + usesModules = true + } // Folder needs explicit mounting due to docker symlink security locals = append(locals, target) mounts = append(mounts, filepath.Join("/ext-go", strconv.Itoa(len(locals)), "src", strings.TrimPrefix(path, sources))) @@ -318,6 +311,12 @@ func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string if usesModules { args = append(args, []string{"-e", "GO111MODULE=on"}...) + + // Check if it has a vendor folder to use that when building with mod + vendorfolder, err := os.Stat(config.Repository + "/vendor") + if !os.IsNotExist(err) && vendorfolder.Mode().IsDir() { + // TODO: how to pass -mod=vendor to the build script? + } } args = append(args, []string{image, config.Repository}...)