Skip to content

Commit e1d10e7

Browse files
myitcvhajimehoshi
authored andcommitted
compiler: automate regeneration of prelude (#784)
This is a rebase of #765. Whilst rebasing #669 I fell into a similar trap to #775 (#775 (comment)), by forgetting to commit the manually minified prelude. Then going through the manual process of manually minifying the prelude I wasted a whole load of time installing goexec, missing something the first time etc, issues that this PR addresses by automating the process, as previously discussed (#765 (comment)).
1 parent 27662f8 commit e1d10e7

File tree

7 files changed

+208
-4
lines changed

7 files changed

+208
-4
lines changed

circle.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ dependencies:
1010
post:
1111
- mv ./gopherjs $HOME/bin
1212
- npm install --global node-gyp
13+
- npm install # install our (dev) dependencies from package.json
1314
- cd node-syscall && node-gyp rebuild && mkdir -p ~/.node_libraries/ && cp build/Release/syscall.node ~/.node_libraries/syscall.node
1415

1516
test:
1617
override:
18+
- go generate github.com/gopherjs/gopherjs/compiler/prelude
19+
- diff -u <(echo -n) <(git status --porcelain)
1720
- diff -u <(echo -n) <(gofmt -d .)
1821
- go tool vet *.go # Go package in root directory.
1922
- for d in */; do echo $d; done | grep -v tests/ | grep -v third_party/ | xargs go tool vet # All subdirectories except "tests", "third_party".

compiler/prelude/genmin.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// +build ignore
2+
3+
package main
4+
5+
import (
6+
"bytes"
7+
"fmt"
8+
"go/build"
9+
"io/ioutil"
10+
"log"
11+
"os/exec"
12+
"path/filepath"
13+
"strings"
14+
15+
"github.com/gopherjs/gopherjs/compiler/prelude"
16+
)
17+
18+
func main() {
19+
if err := run(); err != nil {
20+
log.Fatalln(err)
21+
}
22+
}
23+
24+
func run() error {
25+
bpkg, err := build.Import("github.com/gopherjs/gopherjs", "", build.FindOnly)
26+
if err != nil {
27+
return fmt.Errorf("failed to locate path for github.com/gopherjs/gopherjs: %v", err)
28+
}
29+
30+
preludeDir := filepath.Join(bpkg.Dir, "compiler", "prelude")
31+
32+
args := []string{
33+
filepath.Join(bpkg.Dir, "node_modules", ".bin", "uglifyjs"),
34+
"--config-file",
35+
filepath.Join(preludeDir, "uglifyjs_options.json"),
36+
}
37+
38+
stderr := new(bytes.Buffer)
39+
cmd := exec.Command(args[0], args[1:]...)
40+
cmd.Stdin = strings.NewReader(prelude.Prelude)
41+
cmd.Stderr = stderr
42+
43+
out, err := cmd.Output()
44+
if err != nil {
45+
return fmt.Errorf("failed to run %v: %v\n%s", strings.Join(args, " "), err, stderr.String())
46+
}
47+
48+
fn := "prelude_min.go"
49+
50+
outStr := fmt.Sprintf(`// Code generated by genmin; DO NOT EDIT.
51+
52+
package prelude
53+
54+
// Minified is an uglifyjs-minified version of Prelude.
55+
const Minified = %q
56+
`, out)
57+
58+
if err := ioutil.WriteFile(fn, []byte(outStr), 0644); err != nil {
59+
return fmt.Errorf("failed to write to %v: %v", fn, err)
60+
}
61+
62+
return nil
63+
}

compiler/prelude/prelude.go

Lines changed: 3 additions & 4 deletions
Large diffs are not rendered by default.

compiler/prelude/prelude_min.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"compress": {
3+
"arrows": true,
4+
"booleans": true,
5+
"collapse_vars": true,
6+
"comparisons": true,
7+
"computed_props": true,
8+
"conditionals": true,
9+
"dead_code": true,
10+
"drop_console": false,
11+
"drop_debugger": true,
12+
"ecma": 5,
13+
"evaluate": true,
14+
"expression": false,
15+
"global_defs": {},
16+
"hoist_funs": false,
17+
"hoist_props": true,
18+
"hoist_vars": false,
19+
"ie8": false,
20+
"if_return": true,
21+
"inline": true,
22+
"join_vars": true,
23+
"keep_classnames": false,
24+
"keep_fargs": true,
25+
"keep_fnames": false,
26+
"keep_infinity": false,
27+
"loops": true,
28+
"negate_iife": true,
29+
"passes": 1,
30+
"properties": true,
31+
"pure_funcs": null,
32+
"pure_getters": "strict",
33+
"reduce_funcs": true,
34+
"reduce_vars": true,
35+
"sequences": true,
36+
"side_effects": true,
37+
"switches": true,
38+
"top_retain": null,
39+
"toplevel": false,
40+
"typeofs": true,
41+
"unsafe": false,
42+
"unsafe_Function": false,
43+
"unsafe_arrows": false,
44+
"unsafe_comps": false,
45+
"unsafe_math": false,
46+
"unsafe_methods": false,
47+
"unsafe_proto": false,
48+
"unsafe_regexp": false,
49+
"unsafe_undefined": false,
50+
"unused": true,
51+
"warnings": false
52+
},
53+
"mangle": {
54+
"eval": false,
55+
"ie8": false,
56+
"keep_classnames": false,
57+
"keep_fnames": false,
58+
"properties": false,
59+
"reserved": [],
60+
"safari10": false,
61+
"toplevel": false
62+
},
63+
"output": {
64+
"ascii_only": false,
65+
"beautify": false,
66+
"bracketize": false,
67+
"comments": "/@license|@preserve|^!/",
68+
"ecma": 5,
69+
"ie8": false,
70+
"indent_level": 4,
71+
"indent_start": 0,
72+
"inline_script": true,
73+
"keep_quoted_props": false,
74+
"max_line_len": false,
75+
"preamble": null,
76+
"preserve_line": false,
77+
"quote_keys": false,
78+
"quote_style": 0,
79+
"safari10": false,
80+
"semicolons": true,
81+
"shebang": true,
82+
"source_map": null,
83+
"webkit": false,
84+
"width": 80,
85+
"wrap_iife": false
86+
},
87+
"parse": {
88+
"bare_returns": false,
89+
"ecma": 8,
90+
"expression": false,
91+
"filename": null,
92+
"html5_comments": true,
93+
"shebang": true,
94+
"strict": false,
95+
"toplevel": null
96+
},
97+
"wrap": false
98+
}

package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "gopherjs",
3+
"devDependencies": {
4+
"uglify-es": "3.3.9"
5+
}
6+
}

0 commit comments

Comments
 (0)