Skip to content

Commit 34f3a8e

Browse files
gomod fixes for go1.16 (#121)
* gomod fixes for go1.16 patch from: #109 (comment) * Update test_pr.yml * Update test_pr.yml * kludge * re-enable eth smoke * Update xgo.bats * apply feedback from Z
1 parent de44cf5 commit 34f3a8e

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

.github/workflows/test_pr.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,7 @@ jobs:
7171
bats-version: 1.2.1
7272
- name: run BATS tests
7373
run: |
74+
mkdir -p .xgo-cache
75+
mkdir -p ~/go/src
7476
bats xgo.bats
75-
77+

xgo.bats

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bats
22

33
@test "embedded c" {
4+
export GO111MODULE=auto
45
run go run xgo.go ./tests/embedded_c
56
echo "$output"
67
[ "$status" -eq 0 ]
@@ -33,8 +34,9 @@
3334
}
3435

3536
@test "eth smoke" {
36-
skip "remotes are temporarily disabled due to gomod"
37-
run go run xgo.go --remote github.com/ethereum/go-ethereum --targets "linux/amd64" github.com/ethereum/go-ethereum/cmd/geth
37+
# skip "remotes are temporarily disabled due to gomod"
38+
git clone https://github.com/ethereum/go-ethereum.git /tmp/eth
39+
run go run xgo.go --targets "linux/amd64" /tmp/eth/cmd/geth
3840
echo "$output"
3941
[ "$status" -eq 0 ]
4042
}

xgo.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,17 @@ func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string
258258
locals, mounts, paths := []string{}, []string{}, []string{}
259259
var usesModules bool
260260
if strings.HasPrefix(config.Repository, string(filepath.Separator)) || strings.HasPrefix(config.Repository, ".") {
261-
// Resolve the repository import path from the file path
262-
config.Repository = resolveImportPath(config.Repository)
261+
if _, err := os.Stat(config.Repository + "/go.mod"); err == nil {
262+
usesModules = true
263+
}
264+
if !usesModules {
265+
// Resolve the repository import path from the file path
266+
config.Repository = resolveImportPath(config.Repository)
263267

264-
// Determine if this is a module-based repository
265-
var modFile = config.Repository + "/go.mod"
266-
_, err := os.Stat(modFile)
267-
usesModules = !os.IsNotExist(err)
268+
if _, err := os.Stat(config.Repository + "/go.mod"); err == nil {
269+
usesModules = true
270+
}
271+
}
268272

269273
gopathEnv := os.Getenv("GOPATH")
270274
if gopathEnv == "" && !usesModules {
@@ -277,6 +281,7 @@ func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string
277281
log.Fatalf("No $GOPATH is set or forwarded to xgo")
278282
}
279283
if !usesModules {
284+
280285
for _, gopath := range strings.Split(gopathEnv, string(os.PathListSeparator)) {
281286
// Since docker sandboxes volumes, resolve any symlinks manually
282287
sources := filepath.Join(gopath, "src")

0 commit comments

Comments
 (0)