-
Notifications
You must be signed in to change notification settings - Fork 570
Embed core GopherJS packages into build system; enable vendoring of GopherJS. #787
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
f681903
a4af087
c121b3d
b90dbcb
b24e356
d0d69c0
c8e5f7c
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Package gopherjspkg provides core GopherJS packages via a virtual filesystem. | ||
// | ||
// Core GopherJS packages are packages that are critical for GopherJS compiler | ||
// operation. They are needed to build the Go standard library with GopherJS. | ||
// Currently, they include: | ||
// | ||
// github.com/gopherjs/gopherjs/js | ||
// github.com/gopherjs/gopherjs/nosync | ||
// | ||
package gopherjspkg | ||
|
||
//go:generate vfsgendev -source="github.com/gopherjs/gopherjs/compiler/gopherjspkg".FS -tag=gopherjsdev | ||
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. Where does 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. 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. Please can we make this 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. That's out of scope for this PR. This 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. Good point. This would be better solved in any case by golang/go#22726 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// +build gopherjsdev | ||
|
||
package gopherjspkg | ||
|
||
import ( | ||
"go/build" | ||
"log" | ||
"net/http" | ||
"os" | ||
pathpkg "path" | ||
|
||
"github.com/shurcooL/httpfs/filter" | ||
) | ||
|
||
// FS is a virtual filesystem that contains core GopherJS packages. | ||
var FS = filter.Keep( | ||
http.Dir(importPathToDir("github.com/gopherjs/gopherjs")), | ||
func(path string, fi os.FileInfo) bool { | ||
return path == "/" || | ||
path == "/js" || (pathpkg.Dir(path) == "/js" && !fi.IsDir()) || | ||
path == "/nosync" || (pathpkg.Dir(path) == "/nosync" && !fi.IsDir()) | ||
}, | ||
) | ||
|
||
func importPathToDir(importPath string) string { | ||
p, err := build.Import(importPath, "", build.FindOnly) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
return p.Dir | ||
} |
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.
Isn't it ok to check in the above way like
strings.HasPrefix(path, gopherJSRoot+string(filepath.Separator)
for consistency?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.
No, because this needs to be those 2 packages only. We don't want
github.com/gopherjs/gopherjs/compiler
or others to be included.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.
OK, thanks. I feel like this set is duplicated with
FS
definition infs.go
. Would it be possible to unify these sets into one?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.
The "core" GopherJS packages are enumerated and documented in the package comment of
./compiler/gopherjspkg
package (seecompiler/gopherjspkg/doc.go
file).Here, the
./build
package implements that. It uses import paths.In
gopherjspkg.FS
, the code picks up those packages via relative directory paths.I don't think anything more needs to be done, this is very simple, and trying to make it more DRY isn't worth the effort (I'm usually all for it, but it needs to be worthwhile).