Skip to content

Commit f8510c9

Browse files
committed
support for vendoring
1 parent ea172bf commit f8510c9

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

build/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func NewSession(options *Options) *Session {
318318
options: options,
319319
Packages: make(map[string]*PackageData),
320320
}
321-
s.Types = map[string]*types.Package{"unsafe": types.Unsafe}
321+
s.Types = make(map[string]*types.Package)
322322
if options.Watch {
323323
if out, err := exec.Command("ulimit", "-n").Output(); err == nil {
324324
if n, err := strconv.Atoi(strings.TrimSpace(string(out))); err == nil && n < 1024 {

compiler/package.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,20 @@ type packageImporter struct {
101101
}
102102

103103
func (pi packageImporter) Import(path string) (*types.Package, error) {
104-
if _, err := pi.importContext.Import(path); err != nil {
104+
if path == "unsafe" {
105+
return types.Unsafe, nil
106+
}
107+
108+
a, err := pi.importContext.Import(path)
109+
if err != nil {
105110
if *pi.importError == nil {
106111
// If import failed, show first error of import only (https://github.com/gopherjs/gopherjs/issues/119).
107112
*pi.importError = err
108113
}
109114
return nil, err
110115
}
111-
return pi.importContext.Packages[path], nil
116+
117+
return a.types, nil
112118
}
113119

114120
func Compile(importPath string, files []*ast.File, fileSet *token.FileSet, importContext *ImportContext, minify bool) (*Archive, error) {

tests/misc_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88
"testing"
99
"time"
10+
"vendored"
1011

1112
"github.com/gopherjs/gopherjs/tests/otherpkg"
1213
)
@@ -502,3 +503,9 @@ func TestGoexit(t *testing.T) {
502503
runtime.Goexit()
503504
}()
504505
}
506+
507+
func TestVendoring(t *testing.T) {
508+
if vendored.Answer != 42 {
509+
t.Fail()
510+
}
511+
}

tests/vendor/vendored/vendored.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package vendored
2+
3+
var Answer = 42

0 commit comments

Comments
 (0)