Skip to content

Commit 2d17f70

Browse files
committed
WIP: Use cmd/go with GopherJS support.
Very alpha, much unfinished. Dragons be here. It won't work on your computer yet, unless you're me. But that will be fixed soon, up next. TODO: Split into logical commits, document and explain changes. Update. https://github.com/gopherjs/go/commit/524b8a70b6b558603ceca9144d36e7113f0d37b9 Use own go/build replacement. Update. https://github.com/gopherjs/go/commit/4254365d55f5a069526e73d904ba1b04f4e52709 WIP: Use embedded js, nosync packages. For now, try to use pre-built js.a and nosync.a until we can figure out a good way to build them in a normal way. Try to do this in order to make progress in CI and see what next steps need to be taken. Don't use own go/build replacement for importgraph. It's needed for GopherJS compiler, but we can't use it for importgraph package since they're 3rd party and rely on "go/build".Package. WIP: Try a fix for issue 10332. WIP: Work on disabling cgo, filling custom files during test package builds.
1 parent 45518c1 commit 2d17f70

File tree

14 files changed

+28355
-645
lines changed

14 files changed

+28355
-645
lines changed

build/build.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package build
33
import (
44
"fmt"
55
"go/ast"
6-
"go/build"
76
"go/parser"
87
"go/scanner"
98
"go/token"
@@ -21,6 +20,7 @@ import (
2120
"github.com/fsnotify/fsnotify"
2221
"github.com/gopherjs/gopherjs/compiler"
2322
"github.com/gopherjs/gopherjs/compiler/natives"
23+
"github.com/gopherjs/gopherjs/go/build"
2424
"github.com/kardianos/osext"
2525
"github.com/neelance/sourcemap"
2626
)
@@ -135,6 +135,11 @@ func ImportDir(dir string, mode build.ImportMode) (*PackageData, error) {
135135
return &PackageData{Package: pkg, JSFiles: jsFiles}, nil
136136
}
137137

138+
// Parse ...
139+
func Parse(pkg *build.Package, isTest bool, fileSet *token.FileSet) ([]*ast.File, error) {
140+
return parseAndAugment(pkg, isTest, fileSet)
141+
}
142+
138143
// parseAndAugment parses and returns all .go files of given pkg.
139144
// Standard Go library packages are augmented with files in compiler/natives folder.
140145
// If isTest is true and pkg.ImportPath has no _test suffix, package is built for running internal tests.
@@ -547,7 +552,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
547552
}
548553
defer objFile.Close()
549554

550-
archive, err := compiler.ReadArchive(pkg.PkgObj, pkg.ImportPath, objFile, s.Types)
555+
archive, err := compiler.ReadArchive(pkg.ImportPath, objFile, s.Types)
551556
if err != nil {
552557
return nil, err
553558
}

build/build_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99
"testing"
1010

11+
"github.com/gopherjs/gopherjs/go/build"
1112
"github.com/kisielk/gotool"
1213
"github.com/shurcooL/go/importgraphutil"
1314
)
@@ -68,9 +69,9 @@ func TestNativesDontImportExtraPackages(t *testing.T) {
6869
// Normal package.
6970
{
7071
// Import the real normal package, and populate its real import set.
71-
bpkg, err := gobuild.Import(pkg, "", gobuild.ImportComment)
72+
bpkg, err := build.Import(pkg, "", build.ImportComment)
7273
if err != nil {
73-
t.Fatalf("gobuild.Import: %v", err)
74+
t.Fatalf("build.Import: %v", err)
7475
}
7576
realImports := make(stringSet)
7677
populateImportSet(bpkg.Imports, &realImports)
@@ -107,9 +108,9 @@ func TestNativesDontImportExtraPackages(t *testing.T) {
107108
// Test package.
108109
{
109110
// Import the real test package, and populate its real import set.
110-
bpkg, err := gobuild.Import(pkg, "", gobuild.ImportComment)
111+
bpkg, err := build.Import(pkg, "", build.ImportComment)
111112
if err != nil {
112-
t.Fatalf("gobuild.Import: %v", err)
113+
t.Fatalf("build.Import: %v", err)
113114
}
114115
realTestImports := make(stringSet)
115116
populateImportSet(bpkg.TestImports, &realTestImports)
@@ -146,9 +147,9 @@ func TestNativesDontImportExtraPackages(t *testing.T) {
146147
// External test package.
147148
{
148149
// Import the real external test package, and populate its real import set.
149-
bpkg, err := gobuild.Import(pkg, "", gobuild.ImportComment)
150+
bpkg, err := build.Import(pkg, "", build.ImportComment)
150151
if err != nil {
151-
t.Fatalf("gobuild.Import: %v", err)
152+
t.Fatalf("build.Import: %v", err)
152153
}
153154
realXTestImports := make(stringSet)
154155
populateImportSet(bpkg.XTestImports, &realXTestImports)

cmd/go/doc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Go is a tool for managing Go source code.
2+
//
3+
// This is a feature branch of the official cmd/go command with
4+
// GopherJS compiler support added (via -compiler=gopherjs flag).
5+
package main

0 commit comments

Comments
 (0)