blob: 72d99026bee781905df54324c09f13bd0ad148b8 [file] [log] [blame]
SHELL := /bin/bash -euo pipefail
export PATH := node_modules/.bin:clients/shell/bin:$(PATH)
export GOPATH := $(shell pwd)/clients/shell:$(GOPATH)
export VDLPATH := $(GOPATH)
# Don't use V23_ROOT if NO_V23_ROOT is set.
# This is equivalent to "V23_ROOT= make ..."
ifdef NO_V23_ROOT
V23_ROOT :=
endif
# If V23_ROOT is defined, we should compile/build our clients against the
# code there. This allows us to test our clients againts the current code, and
# simplifies debugging. In order to make this work, we must change our PATHs
# and go compiler depending on whether V23_ROOT is set.
ifdef V23_ROOT
# Use "v23" go compiler wrapper.
GO := v23 go
# v23 puts binaries in $(V23_ROOT)/release/go/bin, so add that to the PATH.
PATH := $(V23_ROOT)/release/go/bin:$(PATH)
# Add location of node and npm from environment repo.
export PATH := $(V23_ROOT)/environment/cout/node/bin:$(PATH)
else
# Use standard go compiler.
GO := go
# The vdl tool needs either V23_ROOT or VDLROOT, so set VDLROOT.
export VDLROOT := $(shell pwd)/clients/shell/src/v.io/v23/vdlroot
endif
# This target causes any target files to be deleted if the target task fails.
# This is especially useful for browserify, which creates files even if it
# fails.
.DELETE_ON_ERROR:
# Default browserify options: use sourcemaps.
BROWSERIFY_OPTS := --debug
# Names that should not be mangled by minification.
RESERVED_NAMES := 'context,ctx,callback,cb,$$stream'
# Don't mangle RESERVED_NAMES, and screw ie8.
MANGLE_OPTS := --mangle [--except $(RESERVED_NAMES) --screw_ie8 ]
# Don't remove unused variables from function arguments, which could mess up signatures.
# Also don't evaulate constant expressions, since we rely on them to conditionally require modules only in node.
COMPRESS_OPTS := --compress [ --no-unused --no-evaluate ]
# Browserify and extract sourcemap, but do not minify.
define BROWSERIFY
mkdir -p $(dir $2)
browserify $1 $(BROWSERIFY_OPTS) | exorcist $2.map > $2
endef
# Browserify, minify, and extract sourcemap.
define BROWSERIFY-MIN
mkdir -p $(dir $2)
browserify $1 $(BROWSERIFY_OPTS) --g [ uglifyify $(MANGLE_OPTS) $(COMPRESS_OPTS) ] | exorcist $2.map > $2
endef
UNAME := $(shell uname)
# When running browser tests on non-Darwin machines, set the --headless flag.
# This uses Xvfb underneath the hood (inside prova => browser-launcher =>
# headless), which is not supported on OS X.
# See: https://github.com/kesla/node-headless/
ifndef NOHEADLESS
ifneq ($(UNAME),Darwin)
HEADLESS := --headless
endif
endif
ifdef STOPONFAIL
STOPONFAIL := --stopOnFirstFailure
endif
ifndef NOTAP
TAP := --tap
endif
ifndef NOQUIT
QUIT := --quit
endif
ifdef XUNIT
TAP := --tap # TAP must be set for xunit to work
OUTPUT_TRANSFORM := tap-xunit
endif
ifdef BROWSER_OUTPUT
BROWSER_OUTPUT_LOCAL = $(BROWSER_OUTPUT)
ifdef OUTPUT_TRANSFORM
BROWSER_OUTPUT_LOCAL := >($(OUTPUT_TRANSFORM) --package=javascript.browser > $(BROWSER_OUTPUT_LOCAL))
endif
BROWSER_OUTPUT_LOCAL := | tee $(BROWSER_OUTPUT_LOCAL)
endif
PROVA_OPTS := --includeFilenameAsPackage $(TAP) $(QUIT) $(STOPONFAIL)
BROWSER_OPTS := --browser --launch chrome $(HEADLESS) --log=./tmp/chrome.log
.DEFAULT_GOAL := all
.PHONY: all
all: build-shell build-web
.PHONY: deploy-staging
deploy-staging: build-web-assets
git rev-parse --verify HEAD >> build/version
gcloud config set project vanadium-staging
gsutil -m rsync -d -r build gs://chat.staging.v.io
node_modules: package.json
npm prune
npm install
ifdef V23_ROOT
# If V23_ROOT is defined, link vanadium from it.
rm -rf ./node_modules/vanadium
cd "$(V23_ROOT)/release/javascript/core" && npm link
npm link vanadium
else
# If V23_ROOT is not defined, install veyron.js from github.
npm install git+ssh://git@github.com:veyron/veyron.js.git
endif
touch node_modules
# TODO(sadovsky): Make it so we only run "go install" when binaries are out of
# date.
vanadium-binaries: clients/shell/src/v.io
$(GO) install \
v.io/x/ref/services/mounttable/mounttabled \
v.io/x/ref/services/proxy/proxyd \
v.io/x/ref/cmd/{principal,servicerunner,vdl}
gen-vdl: vanadium-binaries
vdl generate --lang=go chat/vdl
vdl generate --lang=javascript --js-out-dir=clients/web/js chat/vdl
clients/shell/src/github.com/fatih/color:
$(GO) get github.com/fatih/color
clients/shell/src/github.com/kr/text:
$(GO) get github.com/kr/text
clients/shell/src/github.com/nlacasse/gocui:
$(GO) get github.com/nlacasse/gocui
clients/shell/src/v.io:
# Only go get v.io go repo if V23_ROOT is not defined.
ifndef V23_ROOT
$(GO) get v.io/x/ref/...
endif
clients/shell/bin/chat: vanadium-binaries gen-vdl
clients/shell/bin/chat: clients/shell/src/github.com/fatih/color
clients/shell/bin/chat: clients/shell/src/github.com/kr/text
clients/shell/bin/chat: clients/shell/src/github.com/nlacasse/gocui
clients/shell/bin/chat: $(shell find clients/shell/src -name "*.go")
$(GO) install chat
build-shell: vanadium-binaries clients/shell/bin/chat
mkdir-build:
@mkdir -p build
build/bundle.css: clients/web/css/index.css $(shell find clients/web/css -name "*.css") mkdir-build node_modules
node tools/rework-css.js $< 1> $@
# https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
# Note, on OS X you'll likely need to run "ulimit -S -n 1024" for the browserify
# command to succeed. (Run "ulimit -S -a" and "ulimit -H -a" to see all soft and
# hard limits respectively.)
# Also see: https://github.com/substack/node-browserify/issues/899
build/bundle.js: clients/web/js/index.js $(shell find clients/web/js -name "*.js") gen-vdl mkdir-build node_modules vanadium-binaries
ifndef NOMINIFY
$(call BROWSERIFY,$<,$@)
else
$(call BROWSERIFY-MIN,$<,$@)
endif
build/index.html: clients/web/public/index.html mkdir-build
cp $< $@
build/markdown-preview.css: markdown/markdown-preview.css mkdir-build
cp $< $@
# This task has the minimal set of dependencies to build the web client assets,
# so that it can be run on a GCE instance during the deploy process.
# In particular, it does not depend on a vanadium environment or golang.
build-web-assets: mkdir-build node_modules build/bundle.css build/bundle.js build/index.html build/markdown-preview.css README.md
node tools/render-md.js
# TODO(sadovsky): For some reason, browserify and friends get triggered on each
# build-web invocation, even if their inputs haven't changed.
build-web: build-web-assets vanadium-binaries
serve-web: build-web-assets
node server.js
test: test-shell test-web
test-shell: build-shell
# We must pass --v23.tcp.address=localhost:0, otherwise the chat server
# will listen on the external IP address of the gce instance, and our
# firewall rules prevent connections on unknown ports unless coming from
# localhost.
$(GO) test chat/... --v23.tcp.address=localhost:0
# We use the same test runner as vanadium.js. It handles starting and stopping
# all required services (proxy, wspr, mounntabled), and runs tests in chrome
# with prova.
# TODO(sadovsky): Some of the deps in our package.json are needed solely for
# runner.js. We should restructure things so that runner.js is its own npm
# package with its own deps.
test-web: lint build-web
ifndef V23_ROOT
# The js tests needs the extension built into a folder so that it can be
# loaded with chrome on startup. The extension build process currently
# depends on v23, the Vanadium "web" profile, and V23_ROOT.
#
# TODO(nlacasse): Either make the extension build process have less
# dependencies, or distribute a version of the extension that can be
# unpacked into a directory and used in tests by other projects like chat.
@echo "The test-web make task requires V23_ROOT to be set."
exit 1
else
node ./node_modules/vanadium/test/integration/runner.js -- \
make test-web-runner
endif
# Note: runner.js sets the V23_NAMESPACE and PROXY_ADDR env vars for the
# spawned test subprocess; we specify "make test-web-runner" as the test
# command so that we can then reference these vars in the Vanadium extension
# and our prova command.
test-web-runner: APP_FRAME := "./build/index.html?mtname=$(V23_NAMESPACE)"
test-web-runner: VANADIUM_JS := $(V23_ROOT)/release/javascript/core
test-web-runner: BROWSER_OPTS := --options="--load-extension=$(VANADIUM_JS)/extension/build-test/,--ignore-certificate-errors,--enable-logging=stderr" $(BROWSER_OPTS)
test-web-runner:
$(MAKE) -C $(VANADIUM_JS)/extension clean
$(MAKE) -C $(VANADIUM_JS)/extension build-test
prova clients/web/test/test-*.js -f $(APP_FRAME) $(PROVA_OPTS) $(BROWSER_OPTS) $(BROWSER_OUTPUT_LOCAL)
clean:
rm -rf node_modules
rm -rf clients/shell/{bin,pkg,src/code.google.com,src/github.com,src/golang.org,src/v.io}
rm -rf build
rm -rf vanadium.js
lint: node_modules
jshint .
.PHONY: all vanadium-binaries go-deps gen-vdl
.PHONY: build-shell build-web-assets build-web serve-web
.PHONY: test test-shell test-web clean lint
.NOTPARALLEL: test