-
Notifications
You must be signed in to change notification settings - Fork 570
Support Go 1.13 and Go 1.14 both #964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6d6d029
7c96e2e
752b670
587694b
8a7356a
cfd313f
3e8fc9f
e230287
05591e7
ea61ac0
ad4d281
c6d6d64
254d3d2
afb4460
08185fa
07467f7
f1852a6
2452510
638a258
f40b392
e115225
8153f60
9a3412f
edca086
bb49db2
0f9071d
e3998bf
6879c3c
b836045
ff7a802
d15c989
24e88eb
8e608e5
363e3aa
499543d
4e9873f
a6745ae
d644f5c
3643fd9
cb53a78
b32521c
088e154
5a3dd28
5e486ea
f2cbc75
8f52a03
9785635
cc8eec7
a293d52
f12463c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/node-syscall/build | ||
/node_modules | ||
package-lock.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,17 @@ import ( | |
"strings" | ||
"time" | ||
|
||
"github.com/gopherjs/gopherjs/internal/goversion" | ||
|
||
"github.com/fsnotify/fsnotify" | ||
"github.com/gopherjs/gopherjs/compiler" | ||
"github.com/gopherjs/gopherjs/compiler/gopherjspkg" | ||
"github.com/gopherjs/gopherjs/compiler/natives" | ||
"github.com/neelance/sourcemap" | ||
"github.com/shurcooL/httpfs/vfsutil" | ||
"golang.org/x/tools/go/buildutil" | ||
|
||
"github.com/visualfc/fastmod" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a general observation, lack of comments makes understanding this PR considerably harder, in particular in the part that's related to modules support, the This, unfortunately, can be said about GopherJS codebase in general too :-( |
||
) | ||
|
||
type ImportCError struct { | ||
|
@@ -54,7 +58,7 @@ func NewBuildContext(installSuffix string, buildTags []string) *build.Context { | |
"netgo", // See https://godoc.org/net#hdr-Name_Resolution. | ||
"purego", // See https://golang.org/issues/23172. | ||
), | ||
ReleaseTags: build.Default.ReleaseTags, | ||
ReleaseTags: goversion.ReleaseTags(), | ||
CgoEnabled: true, // detect `import "C"` to throw proper error | ||
|
||
IsDir: func(path string) bool { | ||
|
@@ -125,10 +129,10 @@ func Import(path string, mode build.ImportMode, installSuffix string, buildTags | |
wd = "" | ||
} | ||
bctx := NewBuildContext(installSuffix, buildTags) | ||
return importWithSrcDir(*bctx, path, wd, mode, installSuffix) | ||
return importWithSrcDir(*bctx, path, wd, mode, installSuffix, nil) | ||
} | ||
|
||
func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build.ImportMode, installSuffix string) (*PackageData, error) { | ||
func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build.ImportMode, installSuffix string, mod *fastmod.Package) (*PackageData, error) { | ||
// bctx is passed by value, so it can be modified here. | ||
var isVirtual bool | ||
switch path { | ||
|
@@ -154,7 +158,24 @@ func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build | |
mode |= build.IgnoreVendor | ||
isVirtual = true | ||
} | ||
pkg, err := bctx.Import(path, srcDir, mode) | ||
var pkg *build.Package | ||
var err error | ||
if mod != nil && mod.IsValid() && !mod.IsStd() { | ||
if _, dir, typ := mod.Lookup(path); typ != fastmod.PkgTypeNil { | ||
srcDir = dir | ||
pkg, err = bctx.ImportDir(srcDir, mode) | ||
if err == nil { | ||
pkg.ImportPath = path | ||
} | ||
} | ||
} | ||
if pkg == nil { | ||
if filepath.IsAbs(path) { | ||
pkg, err = bctx.ImportDir(path, mode) | ||
} else { | ||
pkg, err = bctx.Import(path, srcDir, mode) | ||
} | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -276,11 +297,12 @@ func parseAndAugment(bctx *build.Context, pkg *build.Package, isTest bool, fileS | |
} | ||
|
||
nativesContext := &build.Context{ | ||
GOROOT: "/", | ||
GOOS: build.Default.GOOS, | ||
GOARCH: "js", | ||
Compiler: "gc", | ||
JoinPath: path.Join, | ||
GOROOT: "/", | ||
GOOS: build.Default.GOOS, | ||
GOARCH: "js", | ||
Compiler: "gc", | ||
ReleaseTags: goversion.ReleaseTags(), | ||
JoinPath: path.Join, | ||
SplitPathList: func(list string) []string { | ||
if list == "" { | ||
return nil | ||
|
@@ -443,6 +465,7 @@ type Options struct { | |
Minify bool | ||
Color bool | ||
BuildTags []string | ||
Rebuild bool | ||
} | ||
|
||
func (o *Options) PrintError(format string, a ...interface{}) { | ||
|
@@ -471,11 +494,23 @@ type PackageData struct { | |
type Session struct { | ||
options *Options | ||
bctx *build.Context | ||
mod *fastmod.Package | ||
Archives map[string]*compiler.Archive | ||
Types map[string]*types.Package | ||
Watcher *fsnotify.Watcher | ||
} | ||
|
||
func (s *Session) checkMod(pkg *PackageData) (err error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I commented on this on the other PR… Unless I'm misunderstanding the purpose of this function it facilitates passing some module-related information through a side channel, which is a generally problematic pattern (for all the same reasons why global variables are to be avoided). Aside from that, it creates a risk of hard to debug errors if there's a codepath in which this function is not called. |
||
s.mod.Clear() | ||
if pkg != nil && !pkg.Goroot { | ||
err := s.mod.LoadModule(pkg.Dir) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func NewSession(options *Options) *Session { | ||
if options.GOROOT == "" { | ||
options.GOROOT = build.Default.GOROOT | ||
|
@@ -490,6 +525,7 @@ func NewSession(options *Options) *Session { | |
Archives: make(map[string]*compiler.Archive), | ||
} | ||
s.bctx = NewBuildContext(s.InstallSuffix(), s.options.BuildTags) | ||
s.mod = fastmod.NewPackage(s.bctx) | ||
s.Types = make(map[string]*types.Package) | ||
if options.Watch { | ||
if out, err := exec.Command("ulimit", "-n").Output(); err == nil { | ||
|
@@ -531,7 +567,7 @@ func (s *Session) BuildDir(packagePath string, importPath string, pkgObj string) | |
return err | ||
} | ||
pkg.JSFiles = jsFiles | ||
archive, err := s.BuildPackage(pkg) | ||
archive, err := s.buildPackage(pkg) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -554,6 +590,10 @@ func (s *Session) BuildFiles(filenames []string, pkgObj string, packagePath stri | |
Dir: packagePath, | ||
}, | ||
} | ||
err := s.checkMod(pkg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, file := range filenames { | ||
if strings.HasSuffix(file, ".inc.js") { | ||
|
@@ -563,7 +603,7 @@ func (s *Session) BuildFiles(filenames []string, pkgObj string, packagePath stri | |
pkg.GoFiles = append(pkg.GoFiles, file) | ||
} | ||
|
||
archive, err := s.BuildPackage(pkg) | ||
archive, err := s.buildPackage(pkg) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -574,20 +614,28 @@ func (s *Session) BuildFiles(filenames []string, pkgObj string, packagePath stri | |
} | ||
|
||
func (s *Session) BuildImportPath(path string) (*compiler.Archive, error) { | ||
_, archive, err := s.buildImportPathWithSrcDir(path, "") | ||
_, archive, err := s.BuildImportPathWithPackage(path, nil) | ||
return archive, err | ||
} | ||
|
||
func (s *Session) buildImportPathWithSrcDir(path string, srcDir string) (*PackageData, *compiler.Archive, error) { | ||
pkg, err := importWithSrcDir(*s.bctx, path, srcDir, 0, s.InstallSuffix()) | ||
func (s *Session) BuildImportPathWithPackage(path string, pkgData *PackageData) (*PackageData, *compiler.Archive, error) { | ||
var srcDir string | ||
var mod *fastmod.Package | ||
if pkgData != nil { | ||
srcDir = pkgData.Dir | ||
if !pkgData.Goroot { | ||
mod = s.mod | ||
} | ||
} | ||
pkg, err := importWithSrcDir(*s.bctx, path, srcDir, 0, s.InstallSuffix(), mod) | ||
if s.Watcher != nil && pkg != nil { // add watch even on error | ||
s.Watcher.Add(pkg.Dir) | ||
} | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
archive, err := s.BuildPackage(pkg) | ||
archive, err := s.buildPackage(pkg) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
@@ -596,6 +644,14 @@ func (s *Session) buildImportPathWithSrcDir(path string, srcDir string) (*Packag | |
} | ||
|
||
func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) { | ||
err := s.checkMod(pkg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.buildPackage(pkg) | ||
} | ||
|
||
func (s *Session) buildPackage(pkg *PackageData) (*compiler.Archive, error) { | ||
if archive, ok := s.Archives[pkg.ImportPath]; ok { | ||
return archive, nil | ||
} | ||
|
@@ -634,7 +690,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) { | |
if importedPkgPath == "unsafe" || ignored { | ||
continue | ||
} | ||
importedPkg, _, err := s.buildImportPathWithSrcDir(importedPkgPath, pkg.Dir) | ||
importedPkg, _, err := s.BuildImportPathWithPackage(importedPkgPath, pkg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -655,7 +711,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) { | |
} | ||
|
||
pkgObjFileInfo, err := os.Stat(pkg.PkgObj) | ||
if err == nil && !pkg.SrcModTime.After(pkgObjFileInfo.ModTime()) { | ||
if !s.options.Rebuild && err == nil && !pkg.SrcModTime.After(pkgObjFileInfo.ModTime()) { | ||
// package object is up to date, load from disk if library | ||
pkg.UpToDate = true | ||
if pkg.IsCommand() { | ||
|
@@ -691,7 +747,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) { | |
if archive, ok := localImportPathCache[path]; ok { | ||
return archive, nil | ||
} | ||
_, archive, err := s.buildImportPathWithSrcDir(path, pkg.Dir) | ||
_, archive, err := s.BuildImportPathWithPackage(path, pkg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -715,7 +771,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) { | |
} | ||
|
||
if s.options.Verbose { | ||
fmt.Println(pkg.ImportPath) | ||
fmt.Println(pkg.Dir) | ||
} | ||
|
||
s.Archives[pkg.ImportPath] = archive | ||
|
@@ -784,7 +840,7 @@ func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string) | |
if archive, ok := s.Archives[path]; ok { | ||
return archive, nil | ||
} | ||
_, archive, err := s.buildImportPathWithSrcDir(path, "") | ||
_, archive, err := s.BuildImportPathWithPackage(path, nil) | ||
return archive, err | ||
}) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ import ( | |
|
||
var sizes32 = &types.StdSizes{WordSize: 4, MaxAlign: 8} | ||
var reservedKeywords = make(map[string]bool) | ||
var _ = ___GOPHERJS_REQUIRES_GO_VERSION_1_13___ // Compile error on other Go versions, because they're not supported. | ||
var _ = ___GOPHERJS_REQUIRES_GO_VERSION_1_12___ // Compile error on other Go versions, because they're not supported. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be |
||
|
||
func init() { | ||
for _, keyword := range []string{"abstract", "arguments", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "undefined", "var", "void", "volatile", "while", "with", "yield"} { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// +build go1.13 | ||
|
||
package compiler | ||
|
||
const ___GOPHERJS_REQUIRES_GO_VERSION_1_12___ = true | ||
|
||
// Version is the GopherJS compiler version string. | ||
const Version = "1.13-1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"net/http" | ||
"os" | ||
pathpkg "path" | ||
"path/filepath" | ||
|
||
"github.com/shurcooL/httpfs/filter" | ||
) | ||
|
@@ -23,6 +24,12 @@ var FS = filter.Keep( | |
) | ||
|
||
func importPathToDir(importPath string) string { | ||
for _, src := range build.Default.SrcDirs() { | ||
dir := filepath.Join(src, importPath) | ||
if _, err := os.Stat(dir); err == nil { | ||
return dir | ||
} | ||
} | ||
Comment on lines
+27
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? I'd expect build.Import() to find packages in standard locations. Same below. |
||
p, err := build.Import(importPath, "", build.FindOnly) | ||
if err != nil { | ||
log.Fatalln(err) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit strange. To my understanding, this list should only cover standard library, so seeing vendored packages is a bit unexpected.