Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

Enabled usage of go modules #144

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion xgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,24 @@ func pullDockerImage(image string) error {
func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string) error {
// If a local build was requested, find the import path and mount all GOPATH sources
locals, mounts, paths := []string{}, []string{}, []string{}
var usesModules bool
if strings.HasPrefix(config.Repository, string(filepath.Separator)) || strings.HasPrefix(config.Repository, ".") {
// 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) {
kolaente marked this conversation as resolved.
Show resolved Hide resolved
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") == "" {
if os.Getenv("GOPATH") == "" && !usesModules {
log.Fatalf("No $GOPATH is set or forwarded to xgo")
}
for _, gopath := range strings.Split(os.Getenv("GOPATH"), string(os.PathListSeparator)) {
Expand Down Expand Up @@ -304,6 +316,10 @@ func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string
}
args = append(args, []string{"-e", "EXT_GOPATH=" + strings.Join(paths, ":")}...)

if usesModules {
args = append(args, []string{"-e", "GO111MODULE=on"}...)
}

args = append(args, []string{image, config.Repository}...)
return run(exec.Command("docker", args...))
}
Expand Down