From 1a8e96ac584dcb441434774bd57e5f1f40abb174 Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Mon, 25 Jan 2016 02:08:42 +0100 Subject: [PATCH 1/6] support for Go 1.6 (fixes #355) --- build/build.go | 4 ++- circle.yml | 2 +- compiler/compiler.go | 2 +- compiler/expressions.go | 14 +++++------ compiler/natives/io/io_test.go | 11 ++++++++ compiler/natives/math/math.go | 7 +++--- compiler/natives/net/net.go | 6 +++++ compiler/natives/reflect/reflect.go | 32 ++++++++++++++++++++---- compiler/natives/reflect/reflect_test.go | 4 +++ compiler/natives/runtime/runtime.go | 16 +++++++++--- compiler/version_check.go | 4 +-- tests/run.go | 1 + 12 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 compiler/natives/io/io_test.go diff --git a/build/build.go b/build/build.go index 2c25fe062..2eca239fb 100644 --- a/build/build.go +++ b/build/build.go @@ -78,7 +78,9 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install switch path { case "runtime": - pkg.GoFiles = []string{"error.go", fmt.Sprintf("zgoos_%s.go", buildContext.GOOS), "zversion.go"} + pkg.GoFiles = []string{"error.go"} + case "runtime/internal/sys": + pkg.GoFiles = []string{fmt.Sprintf("zgoos_%s.go", buildContext.GOOS), "zversion.go"} case "runtime/pprof": pkg.GoFiles = nil case "crypto/rand": diff --git a/circle.yml b/circle.yml index 120b7a2e9..11ba637d7 100644 --- a/circle.yml +++ b/circle.yml @@ -6,7 +6,7 @@ machine: dependencies: pre: - - cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath + - cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.6beta2.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath post: - mv ./gopherjs $HOME/bin - npm install --global node-gyp diff --git a/compiler/compiler.go b/compiler/compiler.go index fe527a5a3..bdbf2fc0f 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -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_5___ // compile error on earlier Go versions +var _ = ___GOPHERJS_REQUIRES_GO_VERSION_1_6___ // compile error on earlier Go versions 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"} { diff --git a/compiler/expressions.go b/compiler/expressions.go index d33b452a1..a5be71bae 100644 --- a/compiler/expressions.go +++ b/compiler/expressions.go @@ -42,19 +42,19 @@ func (c *funcContext) translateExpr(expr ast.Expr) *expression { case isInteger(basic): if is64Bit(basic) { if basic.Kind() == types.Int64 { - d, ok := constant.Int64Val(value) + d, ok := constant.Int64Val(constant.ToInt(value)) if !ok { panic("could not get exact uint") } return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatInt(d>>32, 10), strconv.FormatUint(uint64(d)&(1<<32-1), 10)) } - d, ok := constant.Uint64Val(value) + d, ok := constant.Uint64Val(constant.ToInt(value)) if !ok { panic("could not get exact uint") } return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatUint(d>>32, 10), strconv.FormatUint(d&(1<<32-1), 10)) } - d, ok := constant.Int64Val(value) + d, ok := constant.Int64Val(constant.ToInt(value)) if !ok { panic("could not get exact int") } @@ -110,7 +110,7 @@ func (c *funcContext) translateExpr(expr ast.Expr) *expression { zero := c.translateExpr(c.zeroValue(elementType)).String() for _, element := range e.Elts { if kve, isKve := element.(*ast.KeyValueExpr); isKve { - key, ok := constant.Int64Val(c.p.Types[kve.Key].Value) + key, ok := constant.Int64Val(constant.ToInt(c.p.Types[kve.Key].Value)) if !ok { panic("could not get exact int") } @@ -1313,7 +1313,7 @@ func (c *funcContext) formatExprInternal(format string, a []interface{}, parens case 'f': e := a[n].(ast.Expr) if val := c.p.Types[e].Value; val != nil { - d, _ := constant.Int64Val(val) + d, _ := constant.Int64Val(constant.ToInt(val)) out.WriteString(strconv.FormatInt(d, 10)) return } @@ -1327,7 +1327,7 @@ func (c *funcContext) formatExprInternal(format string, a []interface{}, parens case 'h': e := a[n].(ast.Expr) if val := c.p.Types[e].Value; val != nil { - d, _ := constant.Uint64Val(val) + d, _ := constant.Uint64Val(constant.ToInt(val)) if c.p.TypeOf(e).Underlying().(*types.Basic).Kind() == types.Int64 { out.WriteString(strconv.FormatInt(int64(d)>>32, 10)) return @@ -1338,7 +1338,7 @@ func (c *funcContext) formatExprInternal(format string, a []interface{}, parens writeExpr(".$high") case 'l': if val := c.p.Types[a[n].(ast.Expr)].Value; val != nil { - d, _ := constant.Uint64Val(val) + d, _ := constant.Uint64Val(constant.ToInt(val)) out.WriteString(strconv.FormatUint(d&(1<<32-1), 10)) return } diff --git a/compiler/natives/io/io_test.go b/compiler/natives/io/io_test.go new file mode 100644 index 000000000..2b9ea531c --- /dev/null +++ b/compiler/natives/io/io_test.go @@ -0,0 +1,11 @@ +// +build js + +package io_test + +import ( + "testing" +) + +func TestMultiWriter_WriteStringSingleAlloc(t *testing.T) { + t.Skip() +} diff --git a/compiler/natives/math/math.go b/compiler/natives/math/math.go index 8fa824780..df0fc96a5 100644 --- a/compiler/natives/math/math.go +++ b/compiler/natives/math/math.go @@ -12,10 +12,6 @@ var posInf = 1 / zero var negInf = -1 / zero var nan = 0 / zero -func Abs(x float64) float64 { - return abs(x) -} - func Acos(x float64) float64 { return math.Call("acos", x).Float() } @@ -146,6 +142,9 @@ func Modf(f float64) (float64, float64) { if f == posInf || f == negInf { return f, nan } + if 1/f == negInf { + return f, f + } frac := Mod(f, 1) return f - frac, frac } diff --git a/compiler/natives/net/net.go b/compiler/natives/net/net.go index 6235d04b5..eaa9b53d4 100644 --- a/compiler/natives/net/net.go +++ b/compiler/natives/net/net.go @@ -5,8 +5,14 @@ package net import ( "errors" "syscall" + + "github.com/gopherjs/gopherjs/js" ) +func byteIndex(s string, c byte) int { + return js.InternalObject(s).Call("indexOf", js.Global.Get("String").Call("fromCharCode", c)).Int() +} + func Listen(net, laddr string) (Listener, error) { panic(errors.New("network access is not supported by GopherJS")) } diff --git a/compiler/natives/reflect/reflect.go b/compiler/natives/reflect/reflect.go index 1cd0cfe0a..d396ea9c9 100644 --- a/compiler/natives/reflect/reflect.go +++ b/compiler/natives/reflect/reflect.go @@ -606,7 +606,7 @@ func (t *uncommonType) Method(i int) (m Method) { fl := flag(Func) if p.pkgPath != nil { m.PkgPath = *p.pkgPath - fl |= flagRO + fl |= flagStickyRO } mt := p.typ m.Type = mt @@ -812,11 +812,14 @@ func (v Value) Field(i int) Value { field := &tt.fields[i] typ := field.typ - fl := v.flag & (flagRO | flagIndir | flagAddr) + fl := v.flag&(flagStickyRO|flagIndir|flagAddr) | flag(typ.Kind()) if field.pkgPath != nil { - fl |= flagRO + if field.name == nil { + fl |= flagEmbedRO + } else { + fl |= flagStickyRO + } } - fl |= flag(typ.Kind()) if tag := tt.fields[i].tag; tag != nil && i != 0 { if jsTag := getJsTag(*tag); jsTag != "" { @@ -1024,6 +1027,23 @@ func (v Value) Set(x Value) { v.ptr = x.ptr } +func (v Value) SetBytes(x []byte) { + v.mustBeAssignable() + v.mustBe(Slice) + if v.typ.Elem().Kind() != Uint8 { + panic("reflect.Value.SetBytes of non-byte slice") + } + slice := js.InternalObject(x) + if v.typ.Name() != "" || v.typ.Elem().Name() != "" { + typedSlice := jsType(v.typ).New(slice.Get("$array")) + typedSlice.Set("$offset", slice.Get("$offset")) + typedSlice.Set("$length", slice.Get("$length")) + typedSlice.Set("$capacity", slice.Get("$capacity")) + slice = typedSlice + } + js.InternalObject(v.ptr).Call("$set", slice) +} + func (v Value) SetCap(n int) { v.mustBeAssignable() v.mustBe(Slice) @@ -1234,7 +1254,9 @@ func deepValueEqualJs(v1, v2 Value, visited [][2]unsafe.Pointer) bool { return false } for _, k := range keys { - if !deepValueEqualJs(v1.MapIndex(k), v2.MapIndex(k), visited) { + val1 := v1.MapIndex(k) + val2 := v2.MapIndex(k) + if !val1.IsValid() || !val2.IsValid() || !deepValueEqualJs(val1, val2, visited) { return false } } diff --git a/compiler/natives/reflect/reflect_test.go b/compiler/natives/reflect/reflect_test.go index e6bf8b2f7..30972eb7b 100644 --- a/compiler/natives/reflect/reflect_test.go +++ b/compiler/natives/reflect/reflect_test.go @@ -33,3 +33,7 @@ func TestTypelinksSorted(t *testing.T) { func TestGCBits(t *testing.T) { t.Skip() } + +func TestChanAlloc(t *testing.T) { + t.Skip() +} diff --git a/compiler/natives/runtime/runtime.go b/compiler/natives/runtime/runtime.go index 254fdfefd..29e7d4572 100644 --- a/compiler/natives/runtime/runtime.go +++ b/compiler/natives/runtime/runtime.go @@ -2,9 +2,13 @@ package runtime -import "github.com/gopherjs/gopherjs/js" +import ( + "runtime/internal/sys" -const GOOS = theGoos + "github.com/gopherjs/gopherjs/js" +) + +const GOOS = sys.TheGoos const GOARCH = "js" const Compiler = "gopherjs" @@ -37,7 +41,7 @@ func GOROOT() string { if goroot != js.Undefined { return goroot.String() } - return defaultGoroot + return sys.DefaultGoroot } func Breakpoint() { @@ -169,7 +173,7 @@ func LockOSThread() {} func UnlockOSThread() {} func Version() string { - return theVersion + return sys.TheVersion } func StartTrace() error { return nil } @@ -180,3 +184,7 @@ func ReadTrace() []byte func NumCgoCall() int64 { return 0 } + +func efaceOf(ep *interface{}) *eface { + panic("efaceOf: not supported") +} diff --git a/compiler/version_check.go b/compiler/version_check.go index 82882b008..ac5ee363d 100644 --- a/compiler/version_check.go +++ b/compiler/version_check.go @@ -1,5 +1,5 @@ -// +build go1.5 +// +build go1.6 package compiler -const ___GOPHERJS_REQUIRES_GO_VERSION_1_5___ = true +const ___GOPHERJS_REQUIRES_GO_VERSION_1_6___ = true diff --git a/tests/run.go b/tests/run.go index 7825159a3..e4b25670d 100644 --- a/tests/run.go +++ b/tests/run.go @@ -58,6 +58,7 @@ var knownFails = map[string]failReason{ "fixedbugs/bug433.go": {desc: "Error: [object Object]"}, "fixedbugs/issue10353.go": {desc: "incorrect output"}, "fixedbugs/issue11656.go": {desc: "Error: Native function not implemented: runtime/debug.setPanicOnFault"}, + "fixedbugs/issue13268.go": {desc: "os/exec.Command unsupported"}, "fixedbugs/issue4085b.go": {desc: "Error: got panic JavaScript error: Invalid typed array length, want len out of range"}, "fixedbugs/issue4316.go": {desc: "Error: runtime error: invalid memory address or nil pointer dereference"}, "fixedbugs/issue4388.go": {desc: "Error: expected :1 have anonymous function:0"}, From a618a1662704f3d7ab4492f47c581ef25a3d83b8 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Sun, 24 Jan 2016 19:14:45 -0800 Subject: [PATCH 2/6] Move issue13268 to os/exec.Command section. --- tests/run.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/run.go b/tests/run.go index e4b25670d..466a9bc52 100644 --- a/tests/run.go +++ b/tests/run.go @@ -58,7 +58,6 @@ var knownFails = map[string]failReason{ "fixedbugs/bug433.go": {desc: "Error: [object Object]"}, "fixedbugs/issue10353.go": {desc: "incorrect output"}, "fixedbugs/issue11656.go": {desc: "Error: Native function not implemented: runtime/debug.setPanicOnFault"}, - "fixedbugs/issue13268.go": {desc: "os/exec.Command unsupported"}, "fixedbugs/issue4085b.go": {desc: "Error: got panic JavaScript error: Invalid typed array length, want len out of range"}, "fixedbugs/issue4316.go": {desc: "Error: runtime error: invalid memory address or nil pointer dereference"}, "fixedbugs/issue4388.go": {desc: "Error: expected :1 have anonymous function:0"}, @@ -72,13 +71,14 @@ var knownFails = map[string]failReason{ "fixedbugs/issue8047b.go": {desc: "Error: [object Object]"}, // Failing due to use of os/exec.Command, which is unsupported. Now skipped via !nacl build tag. - /*"fixedbugs/bug248.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"}, - "fixedbugs/bug302.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"}, - "fixedbugs/bug345.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"}, - "fixedbugs/bug369.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"}, - "fixedbugs/bug429_run.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"}, - "fixedbugs/issue9862_run.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"},*/ - "fixedbugs/issue10607.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"}, + /*"fixedbugs/bug248.go": {desc: "os/exec.Command unsupported"}, + "fixedbugs/bug302.go": {desc: "os/exec.Command unsupported"}, + "fixedbugs/bug345.go": {desc: "os/exec.Command unsupported"}, + "fixedbugs/bug369.go": {desc: "os/exec.Command unsupported"}, + "fixedbugs/bug429_run.go": {desc: "os/exec.Command unsupported"}, + "fixedbugs/issue9862_run.go": {desc: "os/exec.Command unsupported"},*/ + "fixedbugs/issue10607.go": {desc: "os/exec.Command unsupported"}, + "fixedbugs/issue13268.go": {desc: "os/exec.Command unsupported"}, } type failCategory uint8 From eb4dd60edef67d116b65ed20a5a90e454ca30982 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Fri, 5 Feb 2016 17:05:53 -0800 Subject: [PATCH 3/6] third_party/importer: Disable go vet. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixing the vet issue (which appears to be relatively harmless/false-positive-y) is tricky. The package is a fork of a package that is meant to be used with Go 1.5, and likely isn’t actively maintained nor checked with more strict go vet of version 1.6. --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 11ba637d7..5d91821b5 100644 --- a/circle.yml +++ b/circle.yml @@ -16,6 +16,6 @@ test: override: - diff -u <(echo -n) <(gofmt -d .) - go tool vet *.go # Go package in root directory. - - for d in */; do echo $d; done | grep -v tests/ | xargs go tool vet # All subdirectories except "tests". + - for d in */; do echo $d; done | grep -v tests/ | grep -v third_party/ | xargs go tool vet # All subdirectories except "tests", "third_party". - gopherjs test --short --minify github.com/gopherjs/gopherjs/tests github.com/gopherjs/gopherjs/tests/main github.com/gopherjs/gopherjs/js archive/tar archive/zip bufio bytes compress/bzip2 compress/flate compress/gzip compress/lzw compress/zlib container/heap container/list container/ring crypto/aes crypto/cipher crypto/des crypto/dsa crypto/ecdsa crypto/elliptic crypto/hmac crypto/md5 crypto/rand crypto/rc4 crypto/rsa crypto/sha1 crypto/sha256 crypto/sha512 crypto/subtle crypto/x509 database/sql database/sql/driver debug/dwarf debug/elf debug/gosym debug/macho debug/pe encoding/ascii85 encoding/asn1 encoding/base32 encoding/base64 encoding/binary encoding/csv encoding/gob encoding/hex encoding/json encoding/pem encoding/xml errors expvar flag fmt go/ast go/constant go/doc go/format go/parser go/printer go/scanner go/token hash/adler32 hash/crc32 hash/crc64 hash/fnv html html/template image image/color image/draw image/gif image/jpeg image/png index/suffixarray io io/ioutil math math/big math/cmplx math/rand mime mime/multipart mime/quotedprintable net/http/cookiejar net/http/fcgi net/mail net/rpc/jsonrpc net/textproto net/url path path/filepath reflect regexp regexp/syntax sort strconv strings sync sync/atomic testing/quick text/scanner text/tabwriter text/template text/template/parse time unicode unicode/utf16 unicode/utf8 - go test -v -race ./... From 00ec4c68e19a139ee8a511d0b62615d6236af8a7 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Thu, 18 Feb 2016 00:15:43 -0800 Subject: [PATCH 4/6] circle: Use final release of Go 1.6. --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 5d91821b5..3c4bc7696 100644 --- a/circle.yml +++ b/circle.yml @@ -6,7 +6,7 @@ machine: dependencies: pre: - - cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.6beta2.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath + - cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath post: - mv ./gopherjs $HOME/bin - npm install --global node-gyp From ea172bf909a513346b2d1dcb58aa0a5c839407af Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Sat, 20 Feb 2016 18:37:46 +0100 Subject: [PATCH 5/6] tests of debug/gosym are not compatible with gopherjs --- circle.yml | 2 +- doc/packages.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index 3c4bc7696..bc6599c43 100644 --- a/circle.yml +++ b/circle.yml @@ -17,5 +17,5 @@ test: - diff -u <(echo -n) <(gofmt -d .) - go tool vet *.go # Go package in root directory. - for d in */; do echo $d; done | grep -v tests/ | grep -v third_party/ | xargs go tool vet # All subdirectories except "tests", "third_party". - - gopherjs test --short --minify github.com/gopherjs/gopherjs/tests github.com/gopherjs/gopherjs/tests/main github.com/gopherjs/gopherjs/js archive/tar archive/zip bufio bytes compress/bzip2 compress/flate compress/gzip compress/lzw compress/zlib container/heap container/list container/ring crypto/aes crypto/cipher crypto/des crypto/dsa crypto/ecdsa crypto/elliptic crypto/hmac crypto/md5 crypto/rand crypto/rc4 crypto/rsa crypto/sha1 crypto/sha256 crypto/sha512 crypto/subtle crypto/x509 database/sql database/sql/driver debug/dwarf debug/elf debug/gosym debug/macho debug/pe encoding/ascii85 encoding/asn1 encoding/base32 encoding/base64 encoding/binary encoding/csv encoding/gob encoding/hex encoding/json encoding/pem encoding/xml errors expvar flag fmt go/ast go/constant go/doc go/format go/parser go/printer go/scanner go/token hash/adler32 hash/crc32 hash/crc64 hash/fnv html html/template image image/color image/draw image/gif image/jpeg image/png index/suffixarray io io/ioutil math math/big math/cmplx math/rand mime mime/multipart mime/quotedprintable net/http/cookiejar net/http/fcgi net/mail net/rpc/jsonrpc net/textproto net/url path path/filepath reflect regexp regexp/syntax sort strconv strings sync sync/atomic testing/quick text/scanner text/tabwriter text/template text/template/parse time unicode unicode/utf16 unicode/utf8 + - gopherjs test --short --minify github.com/gopherjs/gopherjs/tests github.com/gopherjs/gopherjs/tests/main github.com/gopherjs/gopherjs/js archive/tar archive/zip bufio bytes compress/bzip2 compress/flate compress/gzip compress/lzw compress/zlib container/heap container/list container/ring crypto/aes crypto/cipher crypto/des crypto/dsa crypto/ecdsa crypto/elliptic crypto/hmac crypto/md5 crypto/rand crypto/rc4 crypto/rsa crypto/sha1 crypto/sha256 crypto/sha512 crypto/subtle crypto/x509 database/sql database/sql/driver debug/dwarf debug/elf debug/macho debug/pe encoding/ascii85 encoding/asn1 encoding/base32 encoding/base64 encoding/binary encoding/csv encoding/gob encoding/hex encoding/json encoding/pem encoding/xml errors expvar flag fmt go/ast go/constant go/doc go/format go/parser go/printer go/scanner go/token hash/adler32 hash/crc32 hash/crc64 hash/fnv html html/template image image/color image/draw image/gif image/jpeg image/png index/suffixarray io io/ioutil math math/big math/cmplx math/rand mime mime/multipart mime/quotedprintable net/http/cookiejar net/http/fcgi net/mail net/rpc/jsonrpc net/textproto net/url path path/filepath reflect regexp regexp/syntax sort strconv strings sync sync/atomic testing/quick text/scanner text/tabwriter text/template text/template/parse time unicode unicode/utf16 unicode/utf8 - go test -v -race ./... diff --git a/doc/packages.md b/doc/packages.md index 9ca1d0114..a88bf4f36 100644 --- a/doc/packages.md +++ b/doc/packages.md @@ -48,7 +48,7 @@ On each commit, Circle CI automatically compiles all supported packages with Gop | debug | | | | -- dwarf | yes | | | -- elf | yes | | -| -- gosym | yes | | +| -- gosym | partially | on binaries generated by gc | | -- macho | yes | | | -- pe | yes | | | encoding | | | From f8510c9aef19750ec5a1178b33932a7f9defd197 Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Sat, 20 Feb 2016 20:04:58 +0100 Subject: [PATCH 6/6] support for vendoring --- build/build.go | 2 +- compiler/package.go | 10 ++++++++-- tests/misc_test.go | 7 +++++++ tests/vendor/vendored/vendored.go | 3 +++ 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/vendor/vendored/vendored.go diff --git a/build/build.go b/build/build.go index 2eca239fb..612e2d189 100644 --- a/build/build.go +++ b/build/build.go @@ -318,7 +318,7 @@ func NewSession(options *Options) *Session { options: options, Packages: make(map[string]*PackageData), } - s.Types = map[string]*types.Package{"unsafe": types.Unsafe} + s.Types = make(map[string]*types.Package) if options.Watch { if out, err := exec.Command("ulimit", "-n").Output(); err == nil { if n, err := strconv.Atoi(strings.TrimSpace(string(out))); err == nil && n < 1024 { diff --git a/compiler/package.go b/compiler/package.go index d5109665a..9a31f2b59 100644 --- a/compiler/package.go +++ b/compiler/package.go @@ -101,14 +101,20 @@ type packageImporter struct { } func (pi packageImporter) Import(path string) (*types.Package, error) { - if _, err := pi.importContext.Import(path); err != nil { + if path == "unsafe" { + return types.Unsafe, nil + } + + a, err := pi.importContext.Import(path) + if err != nil { if *pi.importError == nil { // If import failed, show first error of import only (https://github.com/gopherjs/gopherjs/issues/119). *pi.importError = err } return nil, err } - return pi.importContext.Packages[path], nil + + return a.types, nil } func Compile(importPath string, files []*ast.File, fileSet *token.FileSet, importContext *ImportContext, minify bool) (*Archive, error) { diff --git a/tests/misc_test.go b/tests/misc_test.go index fa949e0aa..b617bdebc 100644 --- a/tests/misc_test.go +++ b/tests/misc_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" "time" + "vendored" "github.com/gopherjs/gopherjs/tests/otherpkg" ) @@ -502,3 +503,9 @@ func TestGoexit(t *testing.T) { runtime.Goexit() }() } + +func TestVendoring(t *testing.T) { + if vendored.Answer != 42 { + t.Fail() + } +} diff --git a/tests/vendor/vendored/vendored.go b/tests/vendor/vendored/vendored.go new file mode 100644 index 000000000..f1e32d227 --- /dev/null +++ b/tests/vendor/vendored/vendored.go @@ -0,0 +1,3 @@ +package vendored + +var Answer = 42