From 282225416b42ec72434002b950221a0e5be517cf Mon Sep 17 00:00:00 2001 From: Paul M Furley Date: Mon, 18 Aug 2014 15:47:57 +0100 Subject: [PATCH 1/8] Replace make-templates.sh with Makefile Beginnings of a Makefile which provides the following: ``` make app/js/templates.js make all make clean make assert_templates_js_up_to_date ``` Note that I preserved the principle of generating a temporary file with handlebars then moving it into place (which I presume was for atomicity). However the tempfile is now generated by `mktemp` which is safer than using the PID to derive a name. Starts #227 --- Makefile | 35 +++++++++++++++++++++++++++++++++++ make-templates.sh | 15 --------------- run-tests.sh | 5 +++-- sendAppToRouter | 2 +- 4 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 Makefile delete mode 100755 make-templates.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9c9ac44 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ + +TEMPLATES_JS=app/js/templates.js +HANDLEBARS_FILES=app/templates/*.handlebars # Used to generate templates.js + +.PHONY: all +all: $(TEMPLATES_JS) + +.PHONY: clean +clean: + rm -f $(TEMPLATES_JS) + + +$(TEMPLATES_JS): $(HANDLEBARS_FILES) + $(eval TEMPFILE=$(shell mktemp --suffix _templates.js)) + + ./node_modules/handlebars/bin/handlebars -f $(TEMPFILE) $(HANDLEBARS_FILES) + mv -f $(TEMPFILE) $(TEMPLATES_JS) + + +# NOTE: assert_templates_js_up_to_date is a temporary workaround to confirm +# that templates.js is up-to-date with the handlebars templates used to +# generate it. Both are checked in to source control because the build server +# currently does not have handlebars installed so relies on the repo version of +# templates.js +# +# TODO: once the build server has handlebars installed: +# - remove apps/js/templates.js from source control (https://github.com/EFForg/OpenWireless/pull/234) +# - always build templates.js from apps/templates/* +# - remove this make target. + +.PHONY: assert_templates_js_up_to_date +assert_templates_js_up_to_date: + $(eval TEMPFILE=$(shell mktemp --suffix _templates.js)) + ./node_modules/handlebars/bin/handlebars -f $(TEMPFILE) $(HANDLEBARS_FILES) + diff --brief $(TEMPFILE) $(TEMPLATES_JS) # exit=1 if different diff --git a/make-templates.sh b/make-templates.sh deleted file mode 100755 index 667eb38..0000000 --- a/make-templates.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -cd $(dirname $0) -JS=app/js/templates.js -TEMPLATES=app/templates -TMP=/tmp/template.$$.js -./node_modules/handlebars/bin/handlebars -f $TMP $TEMPLATES/*.handlebars -if [ "$1" = "--is-updated" ] ; then - # Return true if templates.js is up-to-date. - diff -q $JS $TMP > /dev/null - RESULT=$? - rm -f $TMP - exit $RESULT -else - mv -f $TMP $JS -fi diff --git a/run-tests.sh b/run-tests.sh index 1ac4bce..4f40582 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -16,10 +16,11 @@ else pip install -qr requirements.txt fi -if ! ./make-templates.sh --is-updated ; then - echo "Error: templates.js out-of-date. Run ./make-templates.sh" +if ! make assert_templates_js_up_to_date ; then + echo 'Error: templates.js out-of-date. Run `make app/js/templates.js`' exit 1 fi + /usr/bin/env python2.7 -m unittest discover -s test/ -p '*_test.py' if which nodejs ; then NODEJS=nodejs diff --git a/sendAppToRouter b/sendAppToRouter index 8b383ed..059efde 100755 --- a/sendAppToRouter +++ b/sendAppToRouter @@ -3,7 +3,7 @@ cd $(dirname $0) TARGET=root@gw.home.lan sync() { - ./make-templates.sh && \ + make app/js/templates.js && \ rsync -au --no-owner --no-group app/ $TARGET:/www/ && \ rsync -au --no-owner --no-group routerapi/ $TARGET:/www/cgi-bin/routerapi/ && \ rsync -au --no-owner --no-group etc/lighttpd/lighttpd.conf $TARGET:/etc/lighttpd/lighttpd.conf && \ From e10bbb0fb3b6ba2d53faf093c2b08086bbf31b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Manchado=20Vel=C3=A1zquez?= Date: Wed, 27 Aug 2014 20:50:52 +0200 Subject: [PATCH 2/8] No need to specify Makefile target in sendAppToRouter --- sendAppToRouter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendAppToRouter b/sendAppToRouter index 059efde..a8f82de 100755 --- a/sendAppToRouter +++ b/sendAppToRouter @@ -3,7 +3,7 @@ cd $(dirname $0) TARGET=root@gw.home.lan sync() { - make app/js/templates.js && \ + make && \ rsync -au --no-owner --no-group app/ $TARGET:/www/ && \ rsync -au --no-owner --no-group routerapi/ $TARGET:/www/cgi-bin/routerapi/ && \ rsync -au --no-owner --no-group etc/lighttpd/lighttpd.conf $TARGET:/etc/lighttpd/lighttpd.conf && \ From 75ad1621828cf9f2b1c8c66edeeec21f2eb27f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Manchado=20Vel=C3=A1zquez?= Date: Wed, 27 Aug 2014 21:33:05 +0200 Subject: [PATCH 3/8] Use common.get_etc() as configuration directory (not /etc) --- routerapi/dashboard | 3 ++- routerapi/set_timezone | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/routerapi/dashboard b/routerapi/dashboard index 1e42f39..7fb5e7d 100755 --- a/routerapi/dashboard +++ b/routerapi/dashboard @@ -9,6 +9,7 @@ import common import ip_address_retriever import run import uci +import os.path def get_dashboard(): """Render JSON dashboard data response.""" @@ -47,7 +48,7 @@ def get_dashboard(): openwireless_use = get_openwireless_use() - [last_check_date,avail] = open("/etc/last_update_check").read().split() + [last_check_date,avail] = open(os.path.join(common.get_etc(), "last_update_check")).read().split() if (avail=="Y"): update_available = True diff --git a/routerapi/set_timezone b/routerapi/set_timezone index 866cf59..4cbe845 100755 --- a/routerapi/set_timezone +++ b/routerapi/set_timezone @@ -1,11 +1,12 @@ #!/usr/bin/env python2.7 import json import os +import os.path import sys import common -TZ_PATH = "/etc/TZ" +TZ_PATH = os.path.join(common.get_etc(), "TZ") def jsonrpc_set_timezone(tz_path=TZ_PATH): """Accept a POSIX-style set timezone, with parameters like so: From 37ca35e424778c7804580cfc7c0d152bd0f846c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Manchado=20Vel=C3=A1zquez?= Date: Wed, 27 Aug 2014 22:54:59 +0200 Subject: [PATCH 4/8] Revert "Use common.get_etc() as configuration directory (not /etc)" This reverts commit 75ad1621828cf9f2b1c8c66edeeec21f2eb27f8c. --- routerapi/dashboard | 3 +-- routerapi/set_timezone | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/routerapi/dashboard b/routerapi/dashboard index 7fb5e7d..1e42f39 100755 --- a/routerapi/dashboard +++ b/routerapi/dashboard @@ -9,7 +9,6 @@ import common import ip_address_retriever import run import uci -import os.path def get_dashboard(): """Render JSON dashboard data response.""" @@ -48,7 +47,7 @@ def get_dashboard(): openwireless_use = get_openwireless_use() - [last_check_date,avail] = open(os.path.join(common.get_etc(), "last_update_check")).read().split() + [last_check_date,avail] = open("/etc/last_update_check").read().split() if (avail=="Y"): update_available = True diff --git a/routerapi/set_timezone b/routerapi/set_timezone index 4cbe845..866cf59 100755 --- a/routerapi/set_timezone +++ b/routerapi/set_timezone @@ -1,12 +1,11 @@ #!/usr/bin/env python2.7 import json import os -import os.path import sys import common -TZ_PATH = os.path.join(common.get_etc(), "TZ") +TZ_PATH = "/etc/TZ" def jsonrpc_set_timezone(tz_path=TZ_PATH): """Accept a POSIX-style set timezone, with parameters like so: From e9d9aa431de1452792e14d96707edb2bc777bbd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Manchado=20Vel=C3=A1zquez?= Date: Sun, 31 Aug 2014 23:21:19 +0200 Subject: [PATCH 5/8] Turn test scripts into Makefile targets (#227) Keep the actual scripts for now as almost-empty shells that just call Makefile with the right target. --- Makefile | 22 +++++++++++++++++++++- run-selenium-tests.sh | 4 +++- run-tests.sh | 25 +++---------------------- 3 files changed, 27 insertions(+), 24 deletions(-) mode change 100644 => 100755 run-selenium-tests.sh diff --git a/Makefile b/Makefile index 9c9ac44..9c2b6ea 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +NODEJS=$(if $(shell which nodejs),nodejs,node) +PIP_USER_SWITCH=$(if $(VIRTUAL_ENV),--user,) TEMPLATES_JS=app/js/templates.js HANDLEBARS_FILES=app/templates/*.handlebars # Used to generate templates.js @@ -16,6 +18,21 @@ $(TEMPLATES_JS): $(HANDLEBARS_FILES) ./node_modules/handlebars/bin/handlebars -f $(TEMPFILE) $(HANDLEBARS_FILES) mv -f $(TEMPFILE) $(TEMPLATES_JS) +.PHONY: deps +deps: + npm install + pip install $(PIP_USER_SWITCH) -qr requirements.txt + +# This should depend on "all" instead. See note below for assert_templates_js_up_to_date +.PHONY: test +test: assert_templates_js_up_to_date deps + /usr/bin/env python2.7 -m unittest discover -s test/ -p '*_test.py' + $(NODEJS) -e "require('grunt').tasks(['test']);" + +.PHONY: test-selenium +test-selenium: + python -m unittest discover -s selenium/ -p '*_test.py' + # NOTE: assert_templates_js_up_to_date is a temporary workaround to confirm # that templates.js is up-to-date with the handlebars templates used to @@ -32,4 +49,7 @@ $(TEMPLATES_JS): $(HANDLEBARS_FILES) assert_templates_js_up_to_date: $(eval TEMPFILE=$(shell mktemp --suffix _templates.js)) ./node_modules/handlebars/bin/handlebars -f $(TEMPFILE) $(HANDLEBARS_FILES) - diff --brief $(TEMPFILE) $(TEMPLATES_JS) # exit=1 if different + if ! diff --brief $(TEMPFILE) $(TEMPLATES_JS); then \ + echo 'Error: templates.js out-of-date. Run `make app/js/templates.js`' 2>&1; \ + exit 1; \ + fi diff --git a/run-selenium-tests.sh b/run-selenium-tests.sh old mode 100644 new mode 100755 index 45857c8..1b65c8c --- a/run-selenium-tests.sh +++ b/run-selenium-tests.sh @@ -1,3 +1,5 @@ #!/bin/bash -e -python -m unittest discover -s selenium/ -p '*_test.py' +# NOTE: Once all machines have been updated to use the Makefile +# directly, remove this script. +make test-selenium diff --git a/run-tests.sh b/run-tests.sh index 8a517d6..16181c1 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -6,25 +6,6 @@ # ln -s ../../run-tests.sh .git/hooks/pre-push # -# Install required packages -npm install -if [ -z "$VIRTUAL_ENV" ] ; then - USER=--user -else - USER= -fi -pip install $USER -qr requirements.txt - -if ! make assert_templates_js_up_to_date ; then - echo 'Error: templates.js out-of-date. Run `make app/js/templates.js`' - exit 1 -fi - -/usr/bin/env python2.7 -m unittest discover -s test/ -p '*_test.py' -if which nodejs ; then - NODEJS=nodejs -else - NODEJS=node -fi - -$NODEJS -e "require('grunt').tasks(['test']);" +# NOTE: Once all machines have been updated to use the Makefile +# directly, remove this script. +make test From 78b2bdc7bf11580a5085bb74403e05a3f91f144b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Manchado=20Vel=C3=A1zquez?= Date: Mon, 1 Sep 2014 01:40:27 +0200 Subject: [PATCH 6/8] Turn build.sh into a Makefile target (#227) --- Makefile | 25 ++++++++++++++++++++++++- build.sh | 47 +---------------------------------------------- sendAppToRouter | 2 +- 3 files changed, 26 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index 9c2b6ea..2df36a0 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,32 @@ PIP_USER_SWITCH=$(if $(VIRTUAL_ENV),--user,) TEMPLATES_JS=app/js/templates.js HANDLEBARS_FILES=app/templates/*.handlebars # Used to generate templates.js +IMAGE=cerowrt/releases/openwireless-openwrt-squashfs-sysupgrade.bin .PHONY: all -all: $(TEMPLATES_JS) +all: templates image + +.PHONY: templates +templates: $(TEMPLATES_JS) + +.PHONY: image +image: + git submodule update --init + cp OWrt/config-OWrt cerowrt/.config + if ! grep '^src-git cero' cerowrt/feeds.conf.default; then \ + echo 'src-git cero https://github.com/dtaht/ceropackages-3.10' >> cerowrt/feeds.conf.default; \ + fi + ./cerowrt/scripts/feeds update + cp -r ow-python/python-mini-eff ./cerowrt/feeds/oldpackages/lang/ + ./cerowrt/scripts/feeds update -a + ./sendToBuild + make -C cerowrt + mkdir -p cerowrt/releases + cp cerowrt/bin/ar71xx/openwrt-ar71xx-generic-wndr3800-squashfs-sysupgrade.bin $(IMAGE) + @if [ ! -f $(IMAGE) ]; then \ + echo "ERROR: For some reason $IMAGE failed to generate!"; \ + exit 1; \ + fi .PHONY: clean clean: diff --git a/build.sh b/build.sh index 160ee20..d63b667 100755 --- a/build.sh +++ b/build.sh @@ -1,48 +1,3 @@ #!/bin/bash - - IMAGE="releases/openwireless-openwrt-squashfs-sysupgrade.bin" - - git submodule init - git submodule update - - #build router image - echo "building openwireless" - - #copy the config (kernel + packages) - cp OWrt/config-OWrt cerowrt/.config - - #setup the package building system - cd cerowrt - - echo 'src-git cero https://github.com/dtaht/ceropackages-3.10' >> feeds.conf.default - - ./scripts/feeds update - #copy over python package - cp -r ../ow-python/python-mini-eff ./feeds/oldpackages/lang/ - ./scripts/feeds update -a - #./scripts/feeds install libnettle - #./scripts/feeds install python-mini-eff - #./scripts/feeds install gnupg - #./scripts/feeds install tor - - - - #customize the file system - cd .. - ./sendToBuild - cd cerowrt - - echo "building cerowrt" - make - - cd .. - - mkdir -p releases - cp cerowrt/bin/ar71xx/openwrt-ar71xx-generic-wndr3800-squashfs-sysupgrade.bin $IMAGE - - if ! [ -f $IMAGE ]; then - echo "ERROR: For some reason $IMAGE failed to generate!" - exit 1 - fi - +make image diff --git a/sendAppToRouter b/sendAppToRouter index a8f82de..9469c26 100755 --- a/sendAppToRouter +++ b/sendAppToRouter @@ -3,7 +3,7 @@ cd $(dirname $0) TARGET=root@gw.home.lan sync() { - make && \ + make templates && \ rsync -au --no-owner --no-group app/ $TARGET:/www/ && \ rsync -au --no-owner --no-group routerapi/ $TARGET:/www/cgi-bin/routerapi/ && \ rsync -au --no-owner --no-group etc/lighttpd/lighttpd.conf $TARGET:/etc/lighttpd/lighttpd.conf && \ From 63a294b0dd1b4101ed6fd936c6073f03b6abea07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Manchado=20Vel=C3=A1zquez?= Date: Mon, 1 Sep 2014 22:09:46 +0200 Subject: [PATCH 7/8] Improve "clean" target in Makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 2df36a0..467a296 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,9 @@ image: .PHONY: clean clean: rm -f $(TEMPLATES_JS) + rm -rf cerowrt/releases/ + grep -v '^src-git cero' cerowrt/feeds.conf.default >feeds.conf.tmp + mv feeds.conf.tmp cerowrt/feeds.conf.default $(TEMPLATES_JS): $(HANDLEBARS_FILES) From 35b6b827aa4da30ea360f182266771e44420a0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Manchado=20Vel=C3=A1zquez?= Date: Fri, 7 Nov 2014 21:19:41 +0100 Subject: [PATCH 8/8] Fix tests (patch by c0ff3m4kr) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 467a296..aabaece 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ NODEJS=$(if $(shell which nodejs),nodejs,node) -PIP_USER_SWITCH=$(if $(VIRTUAL_ENV),--user,) +PIP_USER_SWITCH=$(if $(VIRTUAL_ENV),,--user) TEMPLATES_JS=app/js/templates.js HANDLEBARS_FILES=app/templates/*.handlebars # Used to generate templates.js