Permalink
Browse files

build, compiler/natives/src/os: Remove syscalling os.Executable imple…

…mentation.

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.
  • Loading branch information...
1 parent 0c82c68 commit b36bf3827456dfce2567767299621cb6c49efe08 @shurcooL shurcooL committed Feb 16, 2017
Showing with 21 additions and 0 deletions.
  1. +15 −0 build/build.go
  2. +6 −0 compiler/natives/src/os/os.go
View
@@ -84,6 +84,8 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
}
switch path {
+ case "os":
+ 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.
case "runtime":
pkg.GoFiles = []string{"error.go"}
case "runtime/internal/sys":
@@ -121,6 +123,19 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
return &PackageData{Package: pkg, JSFiles: jsFiles}, nil
}
+// stripExecutable strips all executable implementation .go files.
+// They have "executable_" prefix.
+func stripExecutable(goFiles []string) []string {
+ var s []string
+ for _, f := range goFiles {
+ if strings.HasPrefix(f, "executable_") {
+ continue
+ }
+ s = append(s, f)
+ }
+ return s
+}
+
// ImportDir is like Import but processes the Go package found in the named
// directory.
func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
@@ -3,6 +3,8 @@
package os
import (
+ "errors"
+
"github.com/gopherjs/gopherjs/js"
)
@@ -24,3 +26,7 @@ func init() {
}
func runtime_beforeExit() {}
+
+func executable() (string, error) {
+ return "", errors.New("Executable not implemented for GOARCH=js")
+}

0 comments on commit b36bf38

Please sign in to comment.