Permalink
Browse files

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)).
  • Loading branch information...
myitcv authored and hajimehoshi committed Apr 20, 2018
1 parent 27662f8 commit e1d10e7424f54589aa3caa8f87ce2934d1890e45
@@ -10,10 +10,13 @@ dependencies:
post:
- mv ./gopherjs $HOME/bin
- npm install --global node-gyp
- npm install # install our (dev) dependencies from package.json
- cd node-syscall && node-gyp rebuild && mkdir -p ~/.node_libraries/ && cp build/Release/syscall.node ~/.node_libraries/syscall.node
test:
override:
- go generate github.com/gopherjs/gopherjs/compiler/prelude
- diff -u <(echo -n) <(git status --porcelain)
- 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".
@@ -0,0 +1,63 @@
// +build ignore
package main
import (
"bytes"
"fmt"
"go/build"
"io/ioutil"
"log"
"os/exec"
"path/filepath"
"strings"
"github.com/gopherjs/gopherjs/compiler/prelude"
)
func main() {
if err := run(); err != nil {
log.Fatalln(err)
}
}
func run() error {
bpkg, err := build.Import("github.com/gopherjs/gopherjs", "", build.FindOnly)
if err != nil {
return fmt.Errorf("failed to locate path for github.com/gopherjs/gopherjs: %v", err)
}
preludeDir := filepath.Join(bpkg.Dir, "compiler", "prelude")
args := []string{
filepath.Join(bpkg.Dir, "node_modules", ".bin", "uglifyjs"),
"--config-file",
filepath.Join(preludeDir, "uglifyjs_options.json"),
}
stderr := new(bytes.Buffer)
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = strings.NewReader(prelude.Prelude)
cmd.Stderr = stderr
out, err := cmd.Output()
if err != nil {
return fmt.Errorf("failed to run %v: %v\n%s", strings.Join(args, " "), err, stderr.String())
}
fn := "prelude_min.go"
outStr := fmt.Sprintf(`// Code generated by genmin; DO NOT EDIT.
package prelude
// Minified is an uglifyjs-minified version of Prelude.
const Minified = %q
`, out)
if err := ioutil.WriteFile(fn, []byte(outStr), 0644); err != nil {
return fmt.Errorf("failed to write to %v: %v", fn, err)
}
return nil
}

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,98 @@
{
"compress": {
"arrows": true,
"booleans": true,
"collapse_vars": true,
"comparisons": true,
"computed_props": true,
"conditionals": true,
"dead_code": true,
"drop_console": false,
"drop_debugger": true,
"ecma": 5,
"evaluate": true,
"expression": false,
"global_defs": {},
"hoist_funs": false,
"hoist_props": true,
"hoist_vars": false,
"ie8": false,
"if_return": true,
"inline": true,
"join_vars": true,
"keep_classnames": false,
"keep_fargs": true,
"keep_fnames": false,
"keep_infinity": false,
"loops": true,
"negate_iife": true,
"passes": 1,
"properties": true,
"pure_funcs": null,
"pure_getters": "strict",
"reduce_funcs": true,
"reduce_vars": true,
"sequences": true,
"side_effects": true,
"switches": true,
"top_retain": null,
"toplevel": false,
"typeofs": true,
"unsafe": false,
"unsafe_Function": false,
"unsafe_arrows": false,
"unsafe_comps": false,
"unsafe_math": false,
"unsafe_methods": false,
"unsafe_proto": false,
"unsafe_regexp": false,
"unsafe_undefined": false,
"unused": true,
"warnings": false
},
"mangle": {
"eval": false,
"ie8": false,
"keep_classnames": false,
"keep_fnames": false,
"properties": false,
"reserved": [],
"safari10": false,
"toplevel": false
},
"output": {
"ascii_only": false,
"beautify": false,
"bracketize": false,
"comments": "/@license|@preserve|^!/",
"ecma": 5,
"ie8": false,
"indent_level": 4,
"indent_start": 0,
"inline_script": true,
"keep_quoted_props": false,
"max_line_len": false,
"preamble": null,
"preserve_line": false,
"quote_keys": false,
"quote_style": 0,
"safari10": false,
"semicolons": true,
"shebang": true,
"source_map": null,
"webkit": false,
"width": 80,
"wrap_iife": false
},
"parse": {
"bare_returns": false,
"ecma": 8,
"expression": false,
"filename": null,
"html5_comments": true,
"shebang": true,
"strict": false,
"toplevel": null
},
"wrap": false
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,6 @@
{
"name": "gopherjs",
"devDependencies": {
"uglify-es": "3.3.9"
}
}

0 comments on commit e1d10e7

Please sign in to comment.