Skip to content

Commit 7522980

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 7e9c7ba commit 7522980

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
@@ -84,6 +84,8 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
8484
}
8585

8686
switch path {
87+
case "os":
88+
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.
8789
case "runtime":
8890
pkg.GoFiles = []string{"error.go"}
8991
case "runtime/internal/sys":
@@ -121,6 +123,19 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
121123
return &PackageData{Package: pkg, JSFiles: jsFiles}, nil
122124
}
123125

126+
// stripExecutable strips all executable implementation .go files.
127+
// They have "executable_" prefix.
128+
func stripExecutable(goFiles []string) []string {
129+
var s []string
130+
for _, f := range goFiles {
131+
if strings.HasPrefix(f, "executable_") {
132+
continue
133+
}
134+
s = append(s, f)
135+
}
136+
return s
137+
}
138+
124139
// ImportDir is like Import but processes the Go package found in the named
125140
// directory.
126141
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)