Permalink
Browse files

Switch to Go1.7

vendoring: update gopherjs to rev
45518c130e5bd1525f20110830a4986365a153de

Patch on upstream to remove fsnotify dep added (for reference) as:
vendor/github.com/gopherjs/gopherjs/nofsnotify.diff

make.go: make Go1.7 the required version

Fixes #838

Change-Id: I2013ee4832a26f8be3a8b42f02e40a347674ec9a
1 parent 64ca2c4 commit 5bc0864f811c09a25aaa78176928a87ad39312cc @mpl mpl committed Aug 30, 2016
Showing with 2,112 additions and 249 deletions.
  1. +1 −1 make.go
  2. +2 −0 vendor/github.com/gopherjs/gopherjs/.gitignore
  3. +1 −1 vendor/github.com/gopherjs/gopherjs/README.md
  4. +64 −6 vendor/github.com/gopherjs/gopherjs/build/build.go
  5. +199 −0 vendor/github.com/gopherjs/gopherjs/build/build_test.go
  6. +111 −3 vendor/github.com/gopherjs/gopherjs/circle.yml
  7. +1 −1 vendor/github.com/gopherjs/gopherjs/compiler/compiler.go
  8. +6 −5 vendor/github.com/gopherjs/gopherjs/compiler/expressions.go
  9. +8 −0 vendor/github.com/gopherjs/gopherjs/compiler/natives/doc.go
  10. +29 −0 vendor/github.com/gopherjs/gopherjs/compiler/natives/fs.go
  11. +733 −0 vendor/github.com/gopherjs/gopherjs/compiler/natives/fs_vfsdata.go
  12. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/bytes/bytes.go
  13. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/bytes/bytes_test.go
  14. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/crypto/rand/rand.go
  15. +2 −1 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/crypto/x509/x509.go
  16. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/crypto/x509/x509_test.go
  17. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/debug/elf/elf_test.go
  18. 0 ...com/gopherjs/gopherjs/compiler/natives/{encoding/json/json.go → src/encoding/json/stream_test.go}
  19. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/fmt/fmt_test.go
  20. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/go/token/token_test.go
  21. +4 −0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/io/io_test.go
  22. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/math/big/big.go
  23. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/math/big/big_test.go
  24. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/math/math.go
  25. +4 −0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/math/rand/rand_test.go
  26. +144 −0 vendor/github.com/gopherjs/gopherjs/compiler/natives/src/net/http/fetch.go
  27. +20 −6 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/net/http/http.go
  28. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/net/net.go
  29. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/os/os.go
  30. +225 −80 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/reflect/reflect.go
  31. +36 −0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/reflect/reflect_test.go
  32. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/regexp/regexp_test.go
  33. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/runtime/debug/debug.go
  34. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/runtime/pprof/pprof.go
  35. +10 −4 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/runtime/runtime.go
  36. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/strings/strings.go
  37. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/sync/atomic/atomic.go
  38. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/sync/atomic/atomic_test.go
  39. +5 −7 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/sync/cond.go
  40. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/sync/pool.go
  41. +2 −0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/sync/sync.go
  42. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/sync/sync_test.go
  43. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/sync/waitgroup.go
  44. +11 −2 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/syscall/syscall.go
  45. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/syscall/syscall_unix.go
  46. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/syscall/syscall_windows.go
  47. +3 −0 vendor/github.com/gopherjs/gopherjs/compiler/natives/src/text/template/template.go
  48. +7 −3 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/time/time.go
  49. 0 vendor/github.com/gopherjs/gopherjs/compiler/natives/{ → src}/unicode/unicode.go
  50. +4 −4 vendor/github.com/gopherjs/gopherjs/compiler/package.go
  51. +6 −4 vendor/github.com/gopherjs/gopherjs/compiler/prelude/goroutines.go
  52. +1 −1 vendor/github.com/gopherjs/gopherjs/compiler/prelude/jsmapping.go
  53. +1 −1 vendor/github.com/gopherjs/gopherjs/compiler/prelude/prelude.go
  54. +37 −35 vendor/github.com/gopherjs/gopherjs/compiler/prelude/types.go
  55. +5 −2 vendor/github.com/gopherjs/gopherjs/compiler/typesutil/typesutil.go
  56. +24 −0 vendor/github.com/gopherjs/gopherjs/compiler/vendor/github.com/neelance/astrewrite/LICENSE
  57. +65 −8 vendor/github.com/gopherjs/gopherjs/compiler/vendor/github.com/neelance/astrewrite/simplify.go
  58. +3 −4 vendor/github.com/gopherjs/gopherjs/compiler/vendor/vendor.json
  59. +6 −2 vendor/github.com/gopherjs/gopherjs/compiler/version_check.go
  60. +2 −2 vendor/github.com/gopherjs/gopherjs/doc/packages.md
  61. +2 −2 vendor/github.com/gopherjs/gopherjs/js/js.go
  62. +14 −8 vendor/github.com/gopherjs/gopherjs/js/js_test.go
  63. +157 −0 vendor/github.com/gopherjs/gopherjs/nofsnotify.diff
  64. +9 −0 vendor/github.com/gopherjs/gopherjs/tests/goroutine_test.go
  65. +9 −0 vendor/github.com/gopherjs/gopherjs/tests/run.go
  66. +139 −56 vendor/github.com/gopherjs/gopherjs/tool.go
View
@@ -814,7 +814,7 @@ func verifyCamlistoreRoot(dir string) {
}
func verifyGoVersion() {
- const neededMinor = '6'
+ const neededMinor = '7'
_, err := exec.LookPath("go")
if err != nil {
log.Fatalf("Go doesn't appear to be installed ('go' isn't in your PATH). Install Go 1.%c or newer.", neededMinor)
@@ -0,0 +1,2 @@
+/node-syscall/build
+/node_modules
@@ -6,7 +6,7 @@ GopherJS - A compiler from Go to JavaScript
GopherJS compiles Go code ([golang.org](https://golang.org/)) to pure JavaScript code. Its main purpose is to give you the opportunity to write front-end code in Go which will still run in all browsers. Give GopherJS a try on the [GopherJS Playground](http://gopherjs.github.io/playground/).
### What is supported?
-Nearly everything, including Goroutines ([compatibility table](https://github.com/gopherjs/gopherjs/blob/master/doc/packages.md)). Performance is quite good in most cases, see [HTML5 game engine benchmark](http://ajhager.github.io/enj/).
+Nearly everything, including Goroutines ([compatibility table](https://github.com/gopherjs/gopherjs/blob/master/doc/packages.md)). Performance is quite good in most cases, see [HTML5 game engine benchmark](https://ajhager.github.io/engi/demos/botmark.html).
### Installation and Usage
Get or update GopherJS and dependencies with:
@@ -8,14 +8,17 @@ import (
"go/scanner"
"go/token"
"go/types"
+ "io"
"io/ioutil"
"os"
+ "path"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/gopherjs/gopherjs/compiler"
+ "github.com/gopherjs/gopherjs/compiler/natives"
"github.com/kardianos/osext"
"github.com/neelance/sourcemap"
)
@@ -130,10 +133,18 @@ func ImportDir(dir string, mode build.ImportMode) (*PackageData, error) {
return &PackageData{Package: pkg, JSFiles: jsFiles}, nil
}
-// parse parses and returns all .go files of given pkg.
+// parseAndAugment parses and returns all .go files of given pkg.
// Standard Go library packages are augmented with files in compiler/natives folder.
-// isTest is true when package is being built for running tests.
-func parse(pkg *build.Package, isTest bool, fileSet *token.FileSet) ([]*ast.File, error) {
+// If isTest is true and pkg.ImportPath has no _test suffix, package is built for running internal tests.
+// If isTest is true and pkg.ImportPath has _test suffix, package is built for running external tests.
+//
+// The native packages are augmented by the contents of natives.FS in the following way.
+// The file names do not matter except the usual `_test` suffix. The files for
+// native overrides get added to the package (even if they have the same name
+// as an existing file from the standard library). For all identifiers that exist
+// in the original AND the overrides, the original identifier in the AST gets
+// replaced by `_`. New identifiers that don't exist in original package get added.
+func parseAndAugment(pkg *build.Package, isTest bool, fileSet *token.FileSet) ([]*ast.File, error) {
var files []*ast.File
replacedDeclNames := make(map[string]bool)
funcName := func(d *ast.FuncDecl) string {
@@ -151,7 +162,48 @@ func parse(pkg *build.Package, isTest bool, fileSet *token.FileSet) ([]*ast.File
if isXTest {
importPath = importPath[:len(importPath)-5]
}
- if nativesPkg, err := Import("github.com/gopherjs/gopherjs/compiler/natives/"+importPath, 0, "", nil); err == nil {
+
+ nativesContext := &build.Context{
+ GOROOT: "/",
+ GOOS: build.Default.GOOS,
+ GOARCH: "js",
+ Compiler: "gc",
+ JoinPath: path.Join,
+ SplitPathList: func(list string) []string {
+ if list == "" {
+ return nil
+ }
+ return strings.Split(list, "/")
+ },
+ IsAbsPath: path.IsAbs,
+ IsDir: func(name string) bool {
+ dir, err := natives.FS.Open(name)
+ if err != nil {
+ return false
+ }
+ defer dir.Close()
+ info, err := dir.Stat()
+ if err != nil {
+ return false
+ }
+ return info.IsDir()
+ },
+ HasSubdir: func(root, name string) (rel string, ok bool) {
+ panic("not implemented")
+ },
+ ReadDir: func(name string) (fi []os.FileInfo, err error) {
+ dir, err := natives.FS.Open(name)
+ if err != nil {
+ return nil, err
+ }
+ defer dir.Close()
+ return dir.Readdir(0)
+ },
+ OpenFile: func(name string) (r io.ReadCloser, err error) {
+ return natives.FS.Open(name)
+ },
+ }
+ if nativesPkg, err := nativesContext.Import(importPath, "", 0); err == nil {
names := nativesPkg.GoFiles
if isTest {
names = append(names, nativesPkg.TestGoFiles...)
@@ -160,10 +212,16 @@ func parse(pkg *build.Package, isTest bool, fileSet *token.FileSet) ([]*ast.File
names = nativesPkg.XTestGoFiles
}
for _, name := range names {
- file, err := parser.ParseFile(fileSet, filepath.Join(nativesPkg.Dir, name), nil, parser.ParseComments)
+ fullPath := path.Join(nativesPkg.Dir, name)
+ r, err := nativesContext.OpenFile(fullPath)
+ if err != nil {
+ panic(err)
+ }
+ file, err := parser.ParseFile(fileSet, fullPath, r, parser.ParseComments)
if err != nil {
panic(err)
}
+ r.Close()
for _, decl := range file.Decls {
switch d := decl.(type) {
case *ast.FuncDecl:
@@ -478,7 +536,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
}
fileSet := token.NewFileSet()
- files, err := parse(pkg.Package, pkg.IsTest, fileSet)
+ files, err := parseAndAugment(pkg.Package, pkg.IsTest, fileSet)
if err != nil {
return nil, err
}
@@ -0,0 +1,199 @@
+package build
+
+import (
+ "fmt"
+ gobuild "go/build"
+ "go/token"
+ "strconv"
+ "strings"
+ "testing"
+
+ "github.com/kisielk/gotool"
+ "github.com/shurcooL/go/importgraphutil"
+)
+
+// Natives augment the standard library with GopherJS-specific changes.
+// This test ensures that none of the standard library packages are modified
+// in a way that adds imports which the original upstream standard library package
+// does not already import. Doing that can increase generated output size or cause
+// other unexpected issues (since the cmd/go tool does not know about these extra imports),
+// so it's best to avoid it.
+//
+// It checks all standard library packages. Each package is considered as a normal
+// package, as a test package, and as an external test package.
+func TestNativesDontImportExtraPackages(t *testing.T) {
+ // Calculate the forward import graph for all standard library packages.
+ // It's needed for populateImportSet.
+ stdOnly := gobuild.Default
+ stdOnly.GOPATH = "" // We only care about standard library, so skip all GOPATH packages.
+ forward, _, err := importgraphutil.BuildNoTests(&stdOnly)
+ if err != nil {
+ t.Fatalf("importgraphutil.BuildNoTests: %v", err)
+ }
+
+ // populateImportSet takes a slice of imports, and populates set with those
+ // imports, as well as their transitive dependencies. That way, the set can
+ // be quickly queried to check if a package is in the import graph of imports.
+ //
+ // Note, this does not include transitive imports of test/xtest packages,
+ // which could cause some false positives. It currently doesn't, but if it does,
+ // then support for that should be added here.
+ populateImportSet := func(imports []string, set *stringSet) {
+ for _, p := range imports {
+ (*set)[p] = struct{}{}
+ switch p {
+ case "sync":
+ (*set)["github.com/gopherjs/gopherjs/nosync"] = struct{}{}
+ }
+ transitiveImports := forward.Search(p)
+ for p := range transitiveImports {
+ (*set)[p] = struct{}{}
+ }
+ }
+ }
+
+ // Check all standard library packages.
+ //
+ // The general strategy is to first import each standard library package using the
+ // normal build.Import, which returns a *build.Package. That contains Imports, TestImports,
+ // and XTestImports values that are considered the "real imports".
+ //
+ // That list of direct imports is then expanded to the transitive closure by populateImportSet,
+ // meaning all packages that are indirectly imported are also added to the set.
+ //
+ // Then, github.com/gopherjs/gopherjs/build.parseAndAugment(*build.Package) returns []*ast.File.
+ // Those augmented parsed Go files of the package are checked, one file at at time, one import
+ // at a time. Each import is verified to belong in the set of allowed real imports.
+ for _, pkg := range gotool.ImportPaths([]string{"std"}) {
+ // Normal package.
+ {
+ // Import the real normal package, and populate its real import set.
+ bpkg, err := gobuild.Import(pkg, "", gobuild.ImportComment)
+ if err != nil {
+ t.Fatalf("gobuild.Import: %v", err)
+ }
+ realImports := make(stringSet)
+ populateImportSet(bpkg.Imports, &realImports)
+
+ // Use parseAndAugment to get a list of augmented AST files.
+ fset := token.NewFileSet()
+ files, err := parseAndAugment(bpkg, false, fset)
+ if err != nil {
+ t.Fatalf("github.com/gopherjs/gopherjs/build.parseAndAugment: %v", err)
+ }
+
+ // Verify imports of normal augmented AST files.
+ for _, f := range files {
+ fileName := fset.File(f.Pos()).Name()
+ normalFile := !strings.HasSuffix(fileName, "_test.go")
+ if !normalFile {
+ continue
+ }
+ for _, imp := range f.Imports {
+ importPath, err := strconv.Unquote(imp.Path.Value)
+ if err != nil {
+ t.Fatalf("strconv.Unquote(%v): %v", imp.Path.Value, err)
+ }
+ if importPath == "github.com/gopherjs/gopherjs/js" {
+ continue
+ }
+ if _, ok := realImports[importPath]; !ok {
+ t.Errorf("augmented normal package %q imports %q in file %v, but real %q doesn't:\nrealImports = %v", bpkg.ImportPath, importPath, fileName, bpkg.ImportPath, realImports)
+ }
+ }
+ }
+ }
+
+ // Test package.
+ {
+ // Import the real test package, and populate its real import set.
+ bpkg, err := gobuild.Import(pkg, "", gobuild.ImportComment)
+ if err != nil {
+ t.Fatalf("gobuild.Import: %v", err)
+ }
+ realTestImports := make(stringSet)
+ populateImportSet(bpkg.TestImports, &realTestImports)
+
+ // Use parseAndAugment to get a list of augmented AST files.
+ fset := token.NewFileSet()
+ files, err := parseAndAugment(bpkg, true, fset)
+ if err != nil {
+ t.Fatalf("github.com/gopherjs/gopherjs/build.parseAndAugment: %v", err)
+ }
+
+ // Verify imports of test augmented AST files.
+ for _, f := range files {
+ fileName, pkgName := fset.File(f.Pos()).Name(), f.Name.String()
+ testFile := strings.HasSuffix(fileName, "_test.go") && !strings.HasSuffix(pkgName, "_test")
+ if !testFile {
+ continue
+ }
+ for _, imp := range f.Imports {
+ importPath, err := strconv.Unquote(imp.Path.Value)
+ if err != nil {
+ t.Fatalf("strconv.Unquote(%v): %v", imp.Path.Value, err)
+ }
+ if importPath == "github.com/gopherjs/gopherjs/js" {
+ continue
+ }
+ if _, ok := realTestImports[importPath]; !ok {
+ t.Errorf("augmented test package %q imports %q in file %v, but real %q doesn't:\nrealTestImports = %v", bpkg.ImportPath, importPath, fileName, bpkg.ImportPath, realTestImports)
+ }
+ }
+ }
+ }
+
+ // External test package.
+ {
+ // Import the real external test package, and populate its real import set.
+ bpkg, err := gobuild.Import(pkg, "", gobuild.ImportComment)
+ if err != nil {
+ t.Fatalf("gobuild.Import: %v", err)
+ }
+ realXTestImports := make(stringSet)
+ populateImportSet(bpkg.XTestImports, &realXTestImports)
+
+ // Add _test suffix to import path to cause parseAndAugment to use external test mode.
+ bpkg.ImportPath += "_test"
+
+ // Use parseAndAugment to get a list of augmented AST files, then check only the external test files.
+ fset := token.NewFileSet()
+ files, err := parseAndAugment(bpkg, true, fset)
+ if err != nil {
+ t.Fatalf("github.com/gopherjs/gopherjs/build.parseAndAugment: %v", err)
+ }
+
+ // Verify imports of external test augmented AST files.
+ for _, f := range files {
+ fileName, pkgName := fset.File(f.Pos()).Name(), f.Name.String()
+ xTestFile := strings.HasSuffix(fileName, "_test.go") && strings.HasSuffix(pkgName, "_test")
+ if !xTestFile {
+ continue
+ }
+ for _, imp := range f.Imports {
+ importPath, err := strconv.Unquote(imp.Path.Value)
+ if err != nil {
+ t.Fatalf("strconv.Unquote(%v): %v", imp.Path.Value, err)
+ }
+ if importPath == "github.com/gopherjs/gopherjs/js" {
+ continue
+ }
+ if _, ok := realXTestImports[importPath]; !ok {
+ t.Errorf("augmented external test package %q imports %q in file %v, but real %q doesn't:\nrealXTestImports = %v", bpkg.ImportPath, importPath, fileName, bpkg.ImportPath, realXTestImports)
+ }
+ }
+ }
+ }
+ }
+}
+
+// stringSet is used to print a set of strings in a more readable way.
+type stringSet map[string]struct{}
+
+func (m stringSet) String() string {
+ s := make([]string, 0, len(m))
+ for v := range m {
+ s = append(s, v)
+ }
+ return fmt.Sprintf("%q", s)
+}
Oops, something went wrong.

0 comments on commit 5bc0864

Please sign in to comment.