Skip to content

Commit 65da89e

Browse files
committed
build, compiler/natives/src/os: Remove syscalling os.Executable implementation.
Replace it with a not-implemented-erroring one. This fixes the issue #583 where on darwin a call to os.Getwd is made, which makes syscalls, and causes a warning to be printed to console: warning: system calls not available, see https://github.com/gopherjs/gopherjs/blob/master/doc/syscalls.md os.Executable is documented to be unsupported on nacl: // Executable is not supported on nacl or OpenBSD (unless procfs is // mounted.) GOARCH=js is similar to nacl in many ways, so it's pretty expected os.Executable wouldn't be supported here either. Use https://github.com/golang/go/blob/990124da2a6ca5a54b38733b51018e2f8758cfae/src/os/executable_procfs.go#L21 as template for error message. Fixes #583.
1 parent d48e93b commit 65da89e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

build/build.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
7979
}
8080

8181
switch path {
82+
case "os":
83+
pkg.GoFiles = stripExecutable(pkg.GoFiles) // Need to strip executable implementation files, because some of them contain package scope variables that perform (indirectly) syscalls on init.
8284
case "runtime":
8385
pkg.GoFiles = []string{"error.go"}
8486
case "runtime/internal/sys":
@@ -116,6 +118,19 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
116118
return &PackageData{Package: pkg, JSFiles: jsFiles}, nil
117119
}
118120

121+
// stripExecutable strips all executable implementation .go files.
122+
// They have "executable_" prefix.
123+
func stripExecutable(goFiles []string) []string {
124+
var s []string
125+
for _, f := range goFiles {
126+
if strings.HasPrefix(f, "executable_") {
127+
continue
128+
}
129+
s = append(s, f)
130+
}
131+
return s
132+
}
133+
119134
// ImportDir is like Import but processes the Go package found in the named
120135
// directory.
121136
func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {

compiler/natives/src/os/os.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
package os
44

55
import (
6+
"errors"
7+
68
"github.com/gopherjs/gopherjs/js"
79
)
810

@@ -24,3 +26,7 @@ func init() {
2426
}
2527

2628
func runtime_beforeExit() {}
29+
30+
func executable() (string, error) {
31+
return "", errors.New("Executable not implemented for GOARCH=js")
32+
}

0 commit comments

Comments
 (0)