From d782a29138efd022100e849346dcd2bae1836a32 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Wed, 20 Apr 2016 04:30:18 -0700 Subject: [PATCH] Make the build process a bit saner. --- Makefile | 46 +++++++++++++++++++++++++++++++--------------- tools/chain.js | 7 +++---- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 9174b6c3e..34fb57883 100644 --- a/Makefile +++ b/Makefile @@ -73,11 +73,13 @@ imports = \ $(if $(filter $(uses_tests_enabled),$1),.tests_enabled) \ $(imports_$1) -dests_platform = $(addprefix tmp/,$(subst /,-,$(subst src/,,$(subst platform,platform_$2,$(subst .coffee,.js,$1))))) +dests_platform = $(addprefix tmp/,$(subst /,-,$(patsubst src/%,%.js,$(subst platform,platform_$2,$1)))) dests_of = $(sort $(call dests_platform,$1,crx) $(call dests_platform,$1,userscript)) -dests = $(foreach s,$(sources),$(call dests_of,$(s))) +dests := $(foreach s,$(sources),$(call dests_of,$(s))) + +updates := $(subst tmp/,.events/,$(dests)) pieces = \ tmp/LICENSE \ @@ -117,7 +119,7 @@ ifneq "$(wildcard npm-shrinkwrap.json)" "" echo -> $@ node_modules/%/package.json : .events/npm - $(if $(wildcard $@),,npm install && echo -> $^) + $(if $(wildcard $@),,npm install && echo -> $<) else @@ -134,19 +136,32 @@ endif echo -> $@ tmp/declaration.js : .events/declare - $(if $(wildcard $@),,node tools/declare.js && echo -> $^) + $(if $(wildcard $@),,node tools/declare.js && echo -> $<) -define force_compile -$$(call dests_of,$1) : $1 $$(call imports,$1) $$(template_deps) $$(coffee_deps) tools/chain.js +define check_source +$$(subst tmp/,.events/,$(call dests_of,$1)) : $1 $$(call imports,$1) | .events echo -> $$(call QUOTE,$$@) endef -$(foreach s,$(sources),$(eval $(call force_compile,$(subst $$,$$$$,$(s))))) +$(foreach s,$(sources),$(eval $(call check_source,$(subst $$,$$$$,$(s))))) -.events/compile : $(dests) | .events - node tools/chain.js $(call QUOTE,$?) +.events/compile : $(updates) $(template_deps) $(coffee_deps) tools/chain.js + node tools/chain.js $(call QUOTE, \ + $(subst .events/,tmp/, \ + $(if $(filter-out $(updates),$?), \ + $(updates), \ + $(filter $(updates),$?) \ + ) \ + ) \ + ) echo -> $@ +$(dests) : .events/compile + $(if $(wildcard $@),, \ + node tools/chain.js $(filter-out $(wildcard $(dests)),$(dests)) \ + && echo -> $< \ + ) + tmp/eventPage.js : src/meta/eventPage.coffee $(coffee_deps) | tmp $(coffee) -o tmp src/meta/eventPage.coffee @@ -211,12 +226,13 @@ index.html : test.html tmp/.jshintrc : src/meta/jshint.json tmp/declaration.js src/globals/globals.js $(template_deps) | tmp $(template) $< $@ -.events/jshint.% : tmp/%.js tmp/.jshintrc node_modules/jshint/package.json | .events/compile - echo -> $(call QUOTE,$@) - -.events/jshint : $(patsubst tmp/%.js,.events/jshint.%,$(dests)) - $(BIN)jshint $(call QUOTE,$(patsubst .events/jshint.%,tmp/%.js,$?)) - echo - $(addprefix && echo -> ,$(call QUOTE,$?)) +.events/jshint : $(dests) tmp/.jshintrc node_modules/jshint/package.json + $(BIN)jshint $(call QUOTE, \ + $(if $(filter-out $(dests),$?), \ + $(dests), \ + $(filter $(dests),$?) \ + ) \ + ) echo -> $@ install.json : diff --git a/tools/chain.js b/tools/chain.js index e5c244680..504709ddb 100644 --- a/tools/chain.js +++ b/tools/chain.js @@ -4,13 +4,12 @@ var coffee = require('coffee-script'); for (var name of process.argv.slice(2)) { try { - var parts = name.match(/^tmp\/([^_]*)(?:_(.*))?-(.*)\.js$/); - var basename = fs.readdirSync(`src/${parts[1]}`).filter(x => (x === `${parts[3]}.coffee` || x === `${parts[3]}.js`))[0]; - var sourceName = `src/${parts[1]}/${basename}`; + var parts = name.match(/^tmp\/([^_]*)(?:_(.*))?-(.*)\.(.*)\.js$/); + var sourceName = `src/${parts[1]}/${parts[3]}.${parts[4]}`; var script = fs.readFileSync(sourceName, 'utf8'); script = script.replace(/\r\n/g, '\n'); script = template(script, {type: parts[2]}, sourceName); - if (/\.coffee$/.test(basename)) { + if (parts[4] === 'coffee') { script = coffee.compile(script); if (/^[$A-Z][$\w]*$/.test(parts[3])) { script = `${parts[3]} = ${script}`;