Skip to content

Commit

Permalink
Support partial rebuilds. #833
Browse files Browse the repository at this point in the history
  • Loading branch information
ccd0 committed Apr 12, 2016
1 parent 0df9bfe commit 18f0b77
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 27 deletions.
87 changes: 62 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ cat := node tools/cat.js
cat_deps := tools/cat.js
jshint_deps := .jshintrc node_modules/jshint/package.json

sources := \
groups := 0 1 2 3 4 5 6 7 8 9 10 11 12 13

sources0 := \
src/General/Config.coffee \
src/General/Globals.coffee \
src/General/Globals.coffee
sources1 := \
src/General/$$.coffee \
src/General/CrossOrigin.coffee \
src/General/CrossOrigin.coffee
sources2 := \
src/classes/Callbacks.coffee \
src/classes/Board.coffee \
src/classes/Thread.coffee \
Expand All @@ -39,31 +43,44 @@ sources := \
src/classes/SimpleDict.coffee \
src/classes/ShimSet.coffee \
src/classes/Connection.coffee \
src/classes/Fetcher.coffee \
src/classes/Fetcher.coffee
sources3 := \
src/General/Polyfill.coffee \
src/General/Header.coffee \
src/General/Index.coffee \
src/General/Build.coffee \
src/General/Get.coffee \
src/General/UI.coffee \
src/General/BuildTest.coffee \
$(sort $(wildcard src/Filtering/*.coffee)) \
$(sort $(wildcard src/Quotelinks/*.coffee)) \
src/General/BuildTest.coffee
sources4 := \
$(sort $(wildcard src/Filtering/*.coffee))
sources5 := \
$(sort $(wildcard src/Quotelinks/*.coffee))
sources6 := \
src/Posting/QR.coffee \
src/Posting/Captcha.coffee \
$(sort $(wildcard src/Posting/Captcha.*.coffee)) \
src/Posting/PassLink.coffee \
src/Posting/PostSuccessful.coffee \
$(sort $(wildcard src/Posting/QR.*.coffee)) \
$(sort $(wildcard src/Images/*.coffee)) \
$(sort $(wildcard src/Linkification/*.coffee)) \
$(sort $(wildcard src/Menu/*.coffee)) \
$(sort $(wildcard src/Monitoring/*.coffee)) \
$(sort $(wildcard src/Archive/*.coffee)) \
$(sort $(wildcard src/Miscellaneous/*.coffee)) \
$(sort $(wildcard src/Posting/QR.*.coffee))
sources7 := \
$(sort $(wildcard src/Images/*.coffee))
sources8 := \
$(sort $(wildcard src/Linkification/*.coffee))
sources9 := \
$(sort $(wildcard src/Menu/*.coffee))
sources10 := \
$(sort $(wildcard src/Monitoring/*.coffee))
sources11 := \
$(sort $(wildcard src/Archive/*.coffee))
sources12 := \
$(sort $(wildcard src/Miscellaneous/*.coffee))
sources13 := \
src/General/Settings.coffee \
src/General/Main.coffee

sources := $(foreach i,$(groups),$(sources$(i)))

imports := \
node_modules/font-awesome/package.json \
$(wildcard src/Linkification/icons/*.png) \
Expand Down Expand Up @@ -91,11 +108,13 @@ testbds := $(foreach f,$(subst .crx,.crx.zip,$(bds)),test$(f))

jshint := $(foreach f,script-crx eventPage script-userscript,.events/jshint.$(f))

jshint_parts := $(foreach t,crx userscript,$(foreach i,$(parts),.events/jshint.script$(i)-$(t))) .events/jshint.eventPage

default : install

all : bds install

.events tmp testbuilds builds :
.events tmp tmp/parts testbuilds builds :
$(MKDIR)

.events/npm : npm-shrinkwrap.json | .events
Expand All @@ -108,14 +127,23 @@ node_modules/%/package.json : .events/npm
.tests_enabled :
echo false> .tests_enabled

tmp/script.coffee : $(sources) $(cat_deps) | tmp
$(cat) $(sources) $@
define rules_group

tmp/parts/script$1.coffee : $$(sources$1) $(cat_deps) | tmp/parts
$(cat) $$(sources$1) $$@

tmp/script-%.coffee : tmp/script.coffee $(imports) $(template_deps)
$(template) $< $@ type=$*
tmp/parts/script$1-%.coffee : tmp/parts/script$1.coffee $(imports) $(template_deps)
$(template) $$< $$@ type=$$*

tmp/parts/script$1-%.js : tmp/parts/script$1-%.coffee $(coffee_deps)
$(coffee) $$<

endef

tmp/script-%.js : tmp/script-%.coffee $(coffee_deps)
$(coffee) $<
$(foreach i,$(groups),$(eval $(call rules_group,$(i))))

tmp/script-%.js : $(foreach i,$(groups),tmp/parts/script$(i)-%.js) tools/cat-coffee.js
node tools/cat-coffee.js $(foreach i,$(groups),tmp/parts/script$(i)-$*.js) $@

tmp/eventPage.js : src/General/eventPage.coffee $(coffee_deps) | tmp
$(coffee) -o tmp src/General/eventPage.coffee
Expand Down Expand Up @@ -169,23 +197,30 @@ builds/% : testbuilds/% $(jshint) | builds
test.html : README.md template.jst tools/markdown.js node_modules/marked/package.json node_modules/lodash/package.json
node tools/markdown.js

tmp/parts/.jshintrc : src/meta/jshint.json $(template_deps) | tmp/parts
$(template) $< $@ stage=parts

.jshintrc : src/meta/jshint.json $(template_deps)
$(template) $< .jshintrc
$(template) $< $@ stage=full

.events/jshint.% : tmp/%.js .jshintrc node_modules/jshint/package.json | .events
$(BIN)jshint $<
echo -> $@

.events/jshint.% : tmp/%.js $(jshint_deps) | .events
.events/jshint_parts.% : tmp/parts/%.js tmp/parts/.jshintrc node_modules/jshint/package.json | .events
$(BIN)jshint $<
echo -> $@

install.json :
echo {}> $@

.events/install : $(testbds) $(jshint) install.json tools/install.js | .events
.events/install : $(testbds) $(jshint_parts) install.json tools/install.js | .events
node tools/install.js
echo -> $@

.SECONDARY :

.PHONY: default all clean cleanall testbds bds jshint install
.PHONY: default all clean cleanall testbds bds jshint jshint_parts install

clean :
$(RMDIR) tmp testbuilds .events
Expand All @@ -200,4 +235,6 @@ bds : $(bds)

jshint : $(jshint)

jshint_parts : $(jshint_parts)

install : .events/install
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
"GM_openInTab",
"GM_xmlhttpRequest"
],
"globals": [
"$$",
"c",
"Conf",
"d",
"doc",
"E",
"g"
],
"min": {
"chrome": "33",
"firefox": "26",
Expand Down
14 changes: 12 additions & 2 deletions src/meta/jshint.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@
"cloneInto": true,
"unsafeWindow": true,
"chrome": true<%=
readJSON('package.json').meta.grants.map(x => `,\n "${x}": true`).join('')
%>
meta.grants.map(x => `,\n "${x}": true`
).join('')
%><% if (stage === 'parts') { %>
meta.globals.map(x => `,\n "${x}": true`
<% } %><% if (stage === 'parts') { %>
fs.readdirSync('src')
.map(x => fs.readdirSync(`src/${x}`))
.reduce((x,y) => x.concat(y))
.filter(x => /^[$A-Z]\w*\.coffee/.test(x))
.map(x => x.split('.')[0])
.map(x => `,\n "${x}": true`
<% } %>
}
}
56 changes: 56 additions & 0 deletions tools/cat-coffee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var fs = require('fs');

var inputFiles = process.argv.slice(2, -1);

var allVars = [];
var allHelperNames = [];
var allHelperValues = {};
var allBodies = [];

for (var file of inputFiles) {
var inputText = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n');

var parts = inputText.match(/^\(function\(\) {\n var ([\w$]+(?:, [\w$]+)*)((?:,\n [\w$]+ = .*)*);\n\n([^]*)\n\n}\)\.call\(this\);\n$/);
if (!parts) throw new Error(`${file}: unexpected format`);

var vars = parts[1].split(', ');
for (var v of vars) {
if (allVars.indexOf(v) >= 0) {
throw new Error(`${file}: reused variable name ${v}`);
}
if (allHelperNames.indexOf(v) >= 0) {
throw new Error(`${file}: variable clashes with helper ${v}`);
}
allVars.push(v);
}

var helpers = parts[2].split(',\n ').slice(1);
for (var h of helpers) {
var hparts = h.match(/^([\w$]+) = (.*)$/);
var hn = hparts[1];
var hv = hparts[2];
if (allVars.indexOf(hn) >= 0) {
throw new Error(`${file}: helper clashes with variable ${v}`);
}
if (allHelperNames.indexOf(hn) >= 0) {
if (allHelperValues[hn] !== hv) {
throw new Error(`${file}: redefined helper ${hn}`);
}
} else {
allHelperNames.push(hn);
allHelperValues[hn] = hv;
}
}

var body = parts[3];
allBodies.push(body);
}

var varText = allVars.sort().join(', ');
var helperText = allHelperNames.map(hn => `,\n ${hn} = ${allHelperValues[hn]}`).join('');
var bodyText = allBodies.join('\n\n');

var outputText = `(function() {\n var ${varText}${helperText};\n\n${bodyText}\n\n}).call(this);\n`;

var outputName = process.argv[process.argv.length - 1];
fs.writeFileSync(outputName, outputText);

0 comments on commit 18f0b77

Please # to comment.