Skip to content

Commit 2c06401

Browse files
authored
Merge pull request #1111 from nevkontakte/syscall2
Standardize on a single GOOS/GOARCH and deprecate node-syscall module.
2 parents fcf8e05 + fe1dd62 commit 2c06401

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1615
-1903
lines changed

.std_test_pkg_exclusions

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,21 @@
1-
crypto/tls
2-
debug/gosym
31
embed/internal/embedtest
42
go/build
5-
go/importer
6-
go/internal/gccgoimporter
7-
go/internal/gcimporter
83
go/internal/srcimporter
94
go/types
105
internal/abi
11-
internal/syscall/unix
126
internal/syscall/windows
137
internal/syscall/windows/registry
148
internal/syscall/windows/sysdll
15-
internal/testenv
16-
internal/testlog
17-
internal/trace
189
internal/x/net/nettest
19-
log/syslog
20-
net
21-
net/http
22-
net/http/cgi
2310
net/http/httptest
24-
net/http/httptrace
2511
net/http/httputil
26-
net/http/internal
2712
net/http/pprof
28-
net/internal/socktest
2913
net/rpc
30-
net/smtp
31-
os
32-
os/exec
33-
os/signal
3414
os/signal/internal/pty
35-
plugin
3615
runtime
3716
runtime/cgo
3817
runtime/debug
3918
runtime/internal/atomic
40-
runtime/internal/math
41-
runtime/internal/sys
4219
runtime/pprof
4320
runtime/pprof/internal/profile
44-
runtime/race
4521
runtime/trace
46-
syscall
47-
testing/internal/testdeps
48-
unsafe

build/build.go

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ import (
2626
"github.com/gopherjs/gopherjs/compiler"
2727
"github.com/gopherjs/gopherjs/compiler/astutil"
2828
"github.com/gopherjs/gopherjs/compiler/gopherjspkg"
29-
"github.com/gopherjs/gopherjs/compiler/natives"
29+
3030
"github.com/neelance/sourcemap"
3131
"github.com/shurcooL/httpfs/vfsutil"
3232
"golang.org/x/tools/go/buildutil"
3333

3434
"github.com/gopherjs/gopherjs/build/cache"
35-
_ "github.com/gopherjs/gopherjs/build/versionhack" // go/build release tags hack.
3635
)
3736

3837
// DefaultGOROOT is the default GOROOT value for builds.
@@ -48,27 +47,20 @@ var DefaultGOROOT = func() string {
4847
return build.Default.GOROOT
4948
}()
5049

51-
// ImportCError is returned when GopherJS attempts to build a package that uses
52-
// CGo.
53-
type ImportCError struct {
54-
pkgPath string
55-
}
56-
57-
func (e *ImportCError) Error() string {
58-
return e.pkgPath + `: importing "C" is not supported by GopherJS`
59-
}
60-
6150
// NewBuildContext creates a build context for building Go packages
6251
// with GopherJS compiler.
6352
//
6453
// Core GopherJS packages (i.e., "github.com/gopherjs/gopherjs/js", "github.com/gopherjs/gopherjs/nosync")
6554
// are loaded from gopherjspkg.FS virtual filesystem if not present in GOPATH or
6655
// go.mod.
6756
func NewBuildContext(installSuffix string, buildTags []string) XContext {
68-
gopherjsRoot := filepath.Join(DefaultGOROOT, "src", "github.com", "gopherjs", "gopherjs")
57+
e := DefaultEnv()
58+
e.InstallSuffix = installSuffix
59+
e.BuildTags = buildTags
60+
realGOROOT := goCtx(e)
6961
return &chainedCtx{
70-
primary: goCtx(installSuffix, buildTags),
71-
secondary: embeddedCtx(&withPrefix{gopherjspkg.FS, gopherjsRoot}, installSuffix, buildTags),
62+
primary: realGOROOT,
63+
secondary: gopherjsCtx(e),
7264
}
7365
}
7466

@@ -103,7 +95,7 @@ func statFile(path string) (os.FileInfo, error) {
10395
func Import(path string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
10496
wd, err := os.Getwd()
10597
if err != nil {
106-
// Getwd may fail if we're in GOARCH=js mode. That's okay, handle
98+
// Getwd may fail if we're in GOOS=js mode. That's okay, handle
10799
// it by falling back to empty working directory. It just means
108100
// Import will not be able to resolve relative import paths.
109101
wd = ""
@@ -180,15 +172,7 @@ func parseAndAugment(xctx XContext, pkg *PackageData, isTest bool, fileSet *toke
180172
importPath = importPath[:len(importPath)-5]
181173
}
182174

183-
nativesContext := embeddedCtx(&withPrefix{fs: natives.FS, prefix: DefaultGOROOT}, "", nil)
184-
185-
if importPath == "syscall" {
186-
// Special handling for the syscall package, which uses OS native
187-
// GOOS/GOARCH pair. This will no longer be necessary after
188-
// https://github.com/gopherjs/gopherjs/issues/693.
189-
nativesContext.bctx.GOARCH = build.Default.GOARCH
190-
nativesContext.bctx.BuildTags = append(nativesContext.bctx.BuildTags, "js")
191-
}
175+
nativesContext := overlayCtx(xctx.Env())
192176

193177
if nativesPkg, err := nativesContext.Import(importPath, "", 0); err == nil {
194178
names := nativesPkg.GoFiles
@@ -321,8 +305,6 @@ func parseAndAugment(xctx XContext, pkg *PackageData, isTest bool, fileSet *toke
321305

322306
// Options controls build process behavior.
323307
type Options struct {
324-
GOROOT string
325-
GOPATH string
326308
Verbose bool
327309
Quiet bool
328310
Watch bool
@@ -366,6 +348,10 @@ type PackageData struct {
366348
bctx *build.Context // The original build context this package came from.
367349
}
368350

351+
func (p PackageData) String() string {
352+
return fmt.Sprintf("%s [is_test=%v]", p.ImportPath, p.IsTest)
353+
}
354+
369355
// InternalBuildContext returns the build context that produced the package.
370356
//
371357
// WARNING: This function is a part of internal API and will be removed in
@@ -439,30 +425,26 @@ type Session struct {
439425

440426
// NewSession creates a new GopherJS build session.
441427
func NewSession(options *Options) (*Session, error) {
442-
if options.GOROOT == "" {
443-
options.GOROOT = DefaultGOROOT
444-
}
445-
if options.GOPATH == "" {
446-
options.GOPATH = build.Default.GOPATH
447-
}
448428
options.Verbose = options.Verbose || options.Watch
449429

450-
// Go distribution version check.
451-
if err := compiler.CheckGoVersion(options.GOROOT); err != nil {
452-
return nil, err
453-
}
454-
455430
s := &Session{
456431
options: options,
457432
UpToDateArchives: make(map[string]*compiler.Archive),
458433
}
459434
s.xctx = NewBuildContext(s.InstallSuffix(), s.options.BuildTags)
435+
env := s.xctx.Env()
436+
437+
// Go distribution version check.
438+
if err := compiler.CheckGoVersion(env.GOROOT); err != nil {
439+
return nil, err
440+
}
441+
460442
s.buildCache = cache.BuildCache{
461-
GOOS: s.xctx.GOOS(),
462-
GOARCH: "js",
463-
GOROOT: options.GOROOT,
464-
GOPATH: options.GOPATH,
465-
BuildTags: options.BuildTags,
443+
GOOS: env.GOOS,
444+
GOARCH: env.GOARCH,
445+
GOROOT: env.GOROOT,
446+
GOPATH: env.GOPATH,
447+
BuildTags: append([]string{}, env.BuildTags...),
466448
Minify: options.Minify,
467449
TestedPackage: options.TestedPackage,
468450
}
@@ -496,7 +478,7 @@ func (s *Session) InstallSuffix() string {
496478

497479
// GoRelease returns Go release version this session is building with.
498480
func (s *Session) GoRelease() string {
499-
return compiler.GoRelease(s.options.GOROOT)
481+
return compiler.GoRelease(s.xctx.Env().GOROOT)
500482
}
501483

502484
// BuildFiles passed to the GopherJS tool as if they were a package.
@@ -513,7 +495,7 @@ func (s *Session) BuildFiles(filenames []string, pkgObj string, packagePath stri
513495
// This ephemeral package doesn't have a unique import path to be used as a
514496
// build cache key, so we never cache it.
515497
SrcModTime: time.Now().Add(time.Hour),
516-
bctx: &goCtx(s.InstallSuffix(), s.options.BuildTags).bctx,
498+
bctx: &goCtx(s.xctx.Env()).bctx,
517499
}
518500

519501
for _, file := range filenames {
@@ -667,6 +649,12 @@ func (s *Session) ImportResolverFor(pkg *PackageData) func(string) (*compiler.Ar
667649
}
668650
}
669651

652+
// SourceMappingCallback returns a call back for compiler.SourceMapFilter
653+
// configured for the current build session.
654+
func (s *Session) SourceMappingCallback(m *sourcemap.Map) func(generatedLine, generatedColumn int, originalPos token.Position) {
655+
return NewMappingCallback(m, s.xctx.Env().GOROOT, s.xctx.Env().GOPATH, s.options.MapToLocalDisk)
656+
}
657+
670658
// WriteCommandPackage writes the final JavaScript output file at pkgObj path.
671659
func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string) error {
672660
if err := os.MkdirAll(filepath.Dir(pkgObj), 0777); err != nil {
@@ -692,7 +680,7 @@ func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string)
692680
fmt.Fprintf(codeFile, "//# sourceMappingURL=%s.map\n", filepath.Base(pkgObj))
693681
}()
694682

695-
sourceMapFilter.MappingCallback = NewMappingCallback(m, s.options.GOROOT, s.options.GOPATH, s.options.MapToLocalDisk)
683+
sourceMapFilter.MappingCallback = s.SourceMappingCallback(m)
696684
}
697685

698686
deps, err := compiler.ImportDependencies(archive, func(path string) (*compiler.Archive, error) {

0 commit comments

Comments
 (0)