From 8a271995c7d663a6e21e61637bfdbac799c69c57 Mon Sep 17 00:00:00 2001 From: Geoffrey Date: Mon, 13 Feb 2017 21:05:12 -0800 Subject: [PATCH] =?UTF-8?q?Refactor=20the=20build=20tasks=20to=20be=20more?= =?UTF-8?q?=20foolproof,=20including=20the=20parser=20unless=20it=E2=80=99?= =?UTF-8?q?s=20explicitly=20excluded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cakefile | 81 ++++++++++++++++------------- docs/v1/index.html | 6 +-- documentation/sections/resources.md | 6 +-- 3 files changed, 51 insertions(+), 42 deletions(-) diff --git a/Cakefile b/Cakefile index da176a8d..be742734 100644 --- a/Cakefile +++ b/Cakefile @@ -24,44 +24,12 @@ header = """ */ """ -# Used in folder names like docs/v1 +# Used in folder names like `docs/v1`. majorVersion = parseInt CoffeeScript.VERSION.split('.')[0], 10 + # Build the CoffeeScript language from source. -build = (cb) -> - files = fs.readdirSync 'src' - files = ('src/' + file for file in files when file.match(/\.(lit)?coffee$/)) - run ['-c', '-o', 'lib/coffee-script'].concat(files), cb - -# Run a CoffeeScript through our node/coffee interpreter. -run = (args, cb) -> - proc = spawn 'node', ['bin/coffee'].concat(args) - proc.stderr.on 'data', (buffer) -> console.log buffer.toString() - proc.on 'exit', (status) -> - process.exit(1) if status isnt 0 - cb() if typeof cb is 'function' - -# Log a message with a color. -log = (message, color, explanation) -> - console.log color + message + reset + ' ' + (explanation or '') - - -task 'build', 'build the CoffeeScript language from source', build - -task 'build:full', 'rebuild the source twice, and run the tests', -> - build -> - build -> - csPath = './lib/coffee-script' - csDir = path.dirname require.resolve csPath - - for mod of require.cache when csDir is mod[0 ... csDir.length] - delete require.cache[mod] - - unless runTests require csPath - process.exit 1 - - -task 'build:parser', 'rebuild the Jison parser (run build first)', -> +buildParser = -> helpers.extend global, require 'util' require 'jison' parser = require('./lib/coffee-script/grammar').parser.generate() @@ -74,8 +42,49 @@ task 'build:parser', 'rebuild the Jison parser (run build first)', -> source = fs""" fs.writeFileSync 'lib/coffee-script/parser.js', parser +buildExceptParser = (cb) -> + files = fs.readdirSync 'src' + files = ('src/' + file for file in files when file.match(/\.(lit)?coffee$/)) + run ['-c', '-o', 'lib/coffee-script'].concat(files), cb -task 'build:browser', 'rebuild the merged script for inclusion in the browser', -> +build = (cb) -> + buildParser() + buildExceptParser cb + + +# Run a CoffeeScript through our node/coffee interpreter. +run = (args, cb) -> + proc = spawn 'node', ['bin/coffee'].concat(args) + proc.stderr.on 'data', (buffer) -> console.log buffer.toString() + proc.on 'exit', (status) -> + process.exit(1) if status isnt 0 + cb() if typeof cb is 'function' + + +# Log a message with a color. +log = (message, color, explanation) -> + console.log color + message + reset + ' ' + (explanation or '') + + +task 'build', 'build the CoffeeScript compiler from source', build + +task 'build:parser', 'build the Jison parser only', buildParser + +task 'build:except-parser', 'build the CoffeeScript compiler, except for the Jison parser', buildExceptParser + +task 'build:full', 'build the CoffeeScript compiler from source twice, and run the tests', -> + build -> + build -> + csPath = './lib/coffee-script' + csDir = path.dirname require.resolve csPath + + for mod of require.cache when csDir is mod[0 ... csDir.length] + delete require.cache[mod] + + unless runTests require csPath + process.exit 1 + +task 'build:browser', 'build the merged script for inclusion in the browser', -> code = """ require['../../package.json'] = (function() { return #{fs.readFileSync "./package.json"}; diff --git a/docs/v1/index.html b/docs/v1/index.html index c108e6d0..0cd03d54 100644 --- a/docs/v1/index.html +++ b/docs/v1/index.html @@ -2584,9 +2584,9 @@ task('build:parser', 'rebuild t
  • Source Code
    Use bin/coffee to test your changes,
    bin/cake test to run the test suite,
    -bin/cake build to rebuild the CoffeeScript compiler, and
    -bin/cake build:parser to regenerate the Jison parser if you’re working on the grammar.

    -

    git checkout lib && bin/cake build:full is a good command to run when you’re working on the core language. It’ll refresh the lib directory (in case you broke something), build your altered compiler, use that to rebuild itself (a good sanity test) and then run all of the tests. If they pass, there’s a good chance you’ve made a successful change.

    +bin/cake build to rebuild the full CoffeeScript compiler, and
    +bin/cake build:except-parser to recompile much faster if you’re not editing grammar.coffee.

    +

    git checkout lib && bin/cake build:full is a good command to run when you’re working on the core language. It’ll refresh the lib folder (in case you broke something), build your altered compiler, use that to rebuild itself (a good sanity test) and then run all of the tests. If they pass, there’s a good chance you’ve made a successful change.

  • Browser Tests
    Run CoffeeScript’s test suite in your current browser.
  • diff --git a/documentation/sections/resources.md b/documentation/sections/resources.md index 9e1e2927..bac559e4 100644 --- a/documentation/sections/resources.md +++ b/documentation/sections/resources.md @@ -3,10 +3,10 @@ * [Source Code](http://github.com/jashkenas/coffeescript/)
    Use `bin/coffee` to test your changes,
    `bin/cake test` to run the test suite,
    - `bin/cake build` to rebuild the CoffeeScript compiler, and
    - `bin/cake build:parser` to regenerate the Jison parser if you’re working on the grammar. + `bin/cake build` to rebuild the full CoffeeScript compiler, and
    + `bin/cake build:except-parser` to recompile much faster if you’re not editing `grammar.coffee`. - `git checkout lib && bin/cake build:full` is a good command to run when you’re working on the core language. It’ll refresh the lib directory (in case you broke something), build your altered compiler, use that to rebuild itself (a good sanity test) and then run all of the tests. If they pass, there’s a good chance you’ve made a successful change. + `git checkout lib && bin/cake build:full` is a good command to run when you’re working on the core language. It’ll refresh the `lib` folder (in case you broke something), build your altered compiler, use that to rebuild itself (a good sanity test) and then run all of the tests. If they pass, there’s a good chance you’ve made a successful change. * [Browser Tests](v<%= majorVersion %>/test.html)
    Run CoffeeScript’s test suite in your current browser. * [CoffeeScript Issues](http://github.com/jashkenas/coffeescript/issues)