Skip to content

Commit 8a27199

Browse files
committed
Refactor the build tasks to be more foolproof, including the parser unless it’s explicitly excluded
1 parent c06a058 commit 8a27199

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

Cakefile

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,34 @@ header = """
2424
*/
2525
"""
2626

27-
# Used in folder names like docs/v1
27+
# Used in folder names like `docs/v1`.
2828
majorVersion = parseInt CoffeeScript.VERSION.split('.')[0], 10
2929

30+
3031
# Build the CoffeeScript language from source.
31-
build = (cb) ->
32+
buildParser = ->
33+
helpers.extend global, require 'util'
34+
require 'jison'
35+
parser = require('./lib/coffee-script/grammar').parser.generate()
36+
# Patch Jison’s output, until https://github.com/zaach/jison/pull/339 is accepted,
37+
# to ensure that require('fs') is only called where it exists.
38+
parser = parser.replace "var source = require('fs')", """
39+
var source = '';
40+
var fs = require('fs');
41+
if (typeof fs !== 'undefined' && fs !== null)
42+
source = fs"""
43+
fs.writeFileSync 'lib/coffee-script/parser.js', parser
44+
45+
buildExceptParser = (cb) ->
3246
files = fs.readdirSync 'src'
3347
files = ('src/' + file for file in files when file.match(/\.(lit)?coffee$/))
3448
run ['-c', '-o', 'lib/coffee-script'].concat(files), cb
3549

50+
build = (cb) ->
51+
buildParser()
52+
buildExceptParser cb
53+
54+
3655
# Run a CoffeeScript through our node/coffee interpreter.
3756
run = (args, cb) ->
3857
proc = spawn 'node', ['bin/coffee'].concat(args)
@@ -41,14 +60,19 @@ run = (args, cb) ->
4160
process.exit(1) if status isnt 0
4261
cb() if typeof cb is 'function'
4362

63+
4464
# Log a message with a color.
4565
log = (message, color, explanation) ->
4666
console.log color + message + reset + ' ' + (explanation or '')
4767

4868

49-
task 'build', 'build the CoffeeScript language from source', build
69+
task 'build', 'build the CoffeeScript compiler from source', build
70+
71+
task 'build:parser', 'build the Jison parser only', buildParser
72+
73+
task 'build:except-parser', 'build the CoffeeScript compiler, except for the Jison parser', buildExceptParser
5074

51-
task 'build:full', 'rebuild the source twice, and run the tests', ->
75+
task 'build:full', 'build the CoffeeScript compiler from source twice, and run the tests', ->
5276
build ->
5377
build ->
5478
csPath = './lib/coffee-script'
@@ -60,22 +84,7 @@ task 'build:full', 'rebuild the source twice, and run the tests', ->
6084
unless runTests require csPath
6185
process.exit 1
6286

63-
64-
task 'build:parser', 'rebuild the Jison parser (run build first)', ->
65-
helpers.extend global, require 'util'
66-
require 'jison'
67-
parser = require('./lib/coffee-script/grammar').parser.generate()
68-
# Patch Jison’s output, until https://github.com/zaach/jison/pull/339 is accepted,
69-
# to ensure that require('fs') is only called where it exists.
70-
parser = parser.replace "var source = require('fs')", """
71-
var source = '';
72-
var fs = require('fs');
73-
if (typeof fs !== 'undefined' && fs !== null)
74-
source = fs"""
75-
fs.writeFileSync 'lib/coffee-script/parser.js', parser
76-
77-
78-
task 'build:browser', 'rebuild the merged script for inclusion in the browser', ->
87+
task 'build:browser', 'build the merged script for inclusion in the browser', ->
7988
code = """
8089
require['../../package.json'] = (function() {
8190
return #{fs.readFileSync "./package.json"};

docs/v1/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,9 +2584,9 @@ <h2>Resources</h2><ul>
25842584
<li><p><a href="http://github.com/jashkenas/coffeescript/">Source Code</a><br>
25852585
Use <code>bin/coffee</code> to test your changes,<br>
25862586
<code>bin/cake test</code> to run the test suite,<br>
2587-
<code>bin/cake build</code> to rebuild the CoffeeScript compiler, and<br>
2588-
<code>bin/cake build:parser</code> to regenerate the Jison parser if you’re working on the grammar.</p>
2589-
<p><code>git checkout lib &amp;&amp; bin/cake build:full</code> 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.</p>
2587+
<code>bin/cake build</code> to rebuild the full CoffeeScript compiler, and<br>
2588+
<code>bin/cake build:except-parser</code> to recompile much faster if you’re not editing <code>grammar.coffee</code>.</p>
2589+
<p><code>git checkout lib &amp;&amp; bin/cake build:full</code> is a good command to run when you’re working on the core language. It’ll refresh the <code>lib</code> 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.</p>
25902590
</li>
25912591
<li><a href="v1/test.html">Browser Tests</a><br>
25922592
Run CoffeeScript’s test suite in your current browser.</li>

documentation/sections/resources.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* [Source Code](http://github.com/jashkenas/coffeescript/)<br>
44
Use `bin/coffee` to test your changes,<br>
55
`bin/cake test` to run the test suite,<br>
6-
`bin/cake build` to rebuild the CoffeeScript compiler, and<br>
7-
`bin/cake build:parser` to regenerate the Jison parser if you’re working on the grammar.
6+
`bin/cake build` to rebuild the full CoffeeScript compiler, and<br>
7+
`bin/cake build:except-parser` to recompile much faster if you’re not editing `grammar.coffee`.
88

9-
`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.
9+
`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.
1010
* [Browser Tests](v<%= majorVersion %>/test.html)<br>
1111
Run CoffeeScript’s test suite in your current browser.
1212
* [CoffeeScript Issues](http://github.com/jashkenas/coffeescript/issues)<br>

0 commit comments

Comments
 (0)