From 3dd5fb88e5caa585991fd98071b87b8162cd0cfd Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 18 Apr 2014 08:39:49 -0600 Subject: [PATCH] Allow configuration of JVM arguments in build --- package.json | 2 +- tasks/build.js | 17 +++++++++++++---- tasks/readme.md | 6 ++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 73e1b6a59b..1fe77d0590 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "url": "https://github.com/openlayers/ol3/issues" }, "devDependencies": { - "closure-util": "~0.10.0", + "closure-util": "~0.11.0", "async": "~0.2.10", "htmlparser2": "~3.7.1", "jshint": "~2.4.4", diff --git a/tasks/build.js b/tasks/build.js index 626e81274c..7fd85f0666 100644 --- a/tasks/build.js +++ b/tasks/build.js @@ -30,6 +30,10 @@ function assertValidConfig(config, callback) { callback(new Error('Config missing "compile" object')); return; } + if (config.jvm && !Array.isArray(config.jvm)) { + callback(new Error('Config "jvm" must be an array')); + return; + } if (config.src && !Array.isArray(config.src)) { callback(new Error('Config "src" must be an array')); return; @@ -88,15 +92,20 @@ function getDependencies(src, callback) { /** * Run the compiler. - * @param {Object} options Options for Closure Compiler. + * @param {Object} config Build configuration object. * @param {Array.} paths List of paths to source files. * @param {function(Error, string)} callback Called with the compiled output or * any error. */ -function build(options, paths, callback) { +function build(config, paths, callback) { log.info('ol', 'Compiling ' + paths.length + ' sources'); + var options = config.compile; options.js = paths.concat(options.js || []); - closure.compile(options, callback); + if (config.jvm) { + closure.compile(options, config.jvm, callback); + } else { + closure.compile(options, callback); + } } @@ -112,7 +121,7 @@ function main(config, callback) { assertValidConfig.bind(null, config), generateExports.bind(null, config.exports), getDependencies.bind(null, config.src), - build.bind(null, config.compile) + build.bind(null, config) ], callback); } diff --git a/tasks/readme.md b/tasks/readme.md index a6647dc834..5710e143c9 100644 --- a/tasks/readme.md +++ b/tasks/readme.md @@ -13,12 +13,18 @@ Builds the library based on a configuration file. See the `--help` option for m Build configuration files are JSON files that are used to determine what should be exported from the library and what options should be passed to the compiler. +**Required configuration properties** + * **exports** - `Array.` An array of symbol names or patterns to be exported (names that are used in your application). For example, including `"ol.Map"` will export the map constructor. Method names are prefixed with `#`. So `"ol.Map#getView"` will export the map's `getView` method. You can use a `*` at the end to match multiple names. The pattern `"ol.Map#*"` will export all map methods. * **compile** - `Object` An object whose properties are [Closure Compiler options](https://github.com/openlayers/closure-util/blob/master/compiler-options.txt). Property names match the option names without the `--` prefix (e.g. `"compilation_level": "ADVANCED_OPTIMIZATIONS"` would set the `--compilation_level` option). Where an option can be specified multiple times, use an array for the value (e.g. `"externs": ["one.js", "two.js"]`). Where an option is used as a flag, use a boolean value (e.g. `"use_types_for_optimization": true`). +**Optional configuration properties** + * **src** - `Array.` Optional array of [path patterns](https://github.com/isaacs/minimatch/blob/master/README.md) for source files. This defaults to `["src/**/*.js"]` which will match all `.js` files in the `src` directory. To include a different set of source files, provide an array of path patterns. Note that these patterns are `/` delimited even on Windows. + * **jvm** - `Array.` Optional array of [command line options](https://code.google.com/p/closure-compiler/wiki/FAQ#What_are_the_recommended_Java_VM_command-line_options?) for the compiler. By default, the Compiler is run with `['-server', '-XX:+TieredCompilation']`. + The build task generates a list of source files sorted in dependency order and passes these to the compiler. This takes the place of the `--js` options that you would use when calling the compiler directly. If you want to add additional source files, typically you would use the `src` array described above. This works with sources that have `goog.require` and/or `goog.provide` calls (which are used to sort dependencies). If you want to force the inclusion of files that don't use `goog.require` or `goog.provide`, you can use the `js` property of the `compile` object. Paths in the `js` array will be passed to the compiler **after** all other source files. Paths in your config file should be relative to the current working directory (when you call `node tasks/build.js`). Note that this means paths are not necessarily relative to the config file itself.