-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
79 lines (67 loc) · 3.36 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
SHELL=/bin/bash
ALL=$(shell pushd formats/$(VERSION); find . -name "*.jsonnet" \
| sed -e "s/\.\//output\/$(VERSION)\//" -e "s/.jsonnet//g" )
TESTS=$(shell find . -type f -a -name "*_test.jsonnet" \
| grep -v jsonnetunit \
| sed -e "s/\.\///" -e "s/.jsonnet//g" )
DEPS=sites.jsonnet retired.jsonnet sites/_default.jsonnet lib/site.jsonnet experiments.jsonnet
OUTDIR=output
ARCHDIR:=$(shell date +%Y/%m/%d/%H:%M:%S )
SJSONNET_JAR=/usr/bin/sjsonnet.jar
# NOTE: It's possible to execute the sjsonnet.jar directly, however that uses
# the default heap size of 64M which is not always enough for our large outputs.
# So, run sjsonnet the hard way and provide maximum heap.
SJSONNET=java -Xmx2G -cp $(SJSONNET_JAR) sjsonnet.SjsonnetMain
.PHONY: output
all: output $(ALL) $(OUTDIR)/$(VERSION)/index.html
mkdir -p $(OUTDIR)/configs/$(VERSION)/sites/$(ARCHDIR)
cp $(OUTDIR)/$(VERSION)/sites/* $(OUTDIR)/configs/$(VERSION)/sites/$(ARCHDIR)/
mkdir -p $(OUTDIR)/configs/$(VERSION)/retired/$(ARCHDIR)
cp $(OUTDIR)/$(VERSION)/retired/* $(OUTDIR)/configs/$(VERSION)/retired/$(ARCHDIR)/
mkdir -p $(OUTDIR)/configs/$(VERSION)/zones/$(ARCHDIR)
cp $(OUTDIR)/$(VERSION)/zones/* $(OUTDIR)/configs/$(VERSION)/zones/$(ARCHDIR)/
mkdir -p $(OUTDIR)/configs/$(VERSION)/adhoc/$(ARCHDIR)
cp $(OUTDIR)/$(VERSION)/adhoc/* $(OUTDIR)/configs/$(VERSION)/adhoc/$(ARCHDIR)/
test: $(TESTS)
output:
mkdir -p $(OUTDIR)/$(VERSION)/zones
mkdir -p $(OUTDIR)/$(VERSION)/sites
mkdir -p $(OUTDIR)/$(VERSION)/retired
mkdir -p $(OUTDIR)/$(VERSION)/adhoc
clean:
rm -f *.json *.zone
rm -rf output
$(OUTDIR)/$(VERSION)/sites/%.json: formats/$(VERSION)/sites/%.json.jsonnet $(DEPS)
time $(SJSONNET) -J . --ext-str version=$(VERSION) --ext-code retired=false $< > $@
$(OUTDIR)/$(VERSION)/retired/%.json: formats/$(VERSION)/retired/%.json.jsonnet $(DEPS)
time $(SJSONNET) -J . --ext-str version=$(VERSION) --ext-code retired=true $< > $@
$(OUTDIR)/$(VERSION)/adhoc/%.json: formats/$(VERSION)/adhoc/%.json.jsonnet $(DEPS)
# NOTE: we must use jsonnet to support the two-argument form of std.sort().
time jsonnet -J . $< > $@
%_test: %_test.jsonnet $(DEPS)
time $(SJSONNET) -J . -J jsonnetunit --ext-str version=$(VERSION) $<
# NOTE: sjsonnet.jar does not support the --string option. And, jsonnet alone
# takes over 6min to process the zone file. So, this two step operation saves
# _considerable_ time.
$(OUTDIR)/$(VERSION)/zones/%.zone: formats/$(VERSION)/zones/%.zone.jsonnet $(DEPS)
time $(SJSONNET) -J . \
--ext-str project=$(strip $(PROJECT)) \
--ext-str version=$(strip $(VERSION)) \
--ext-str zone=$(shell basename $@) $< \
| jsonnet --string - > $@
$(eval ZONE_FILE := $(shell echo $@ | sed -e "s/projects_/$(PROJECT)./"))
if [[ $@ != ${ZONE_FILE} ]] ; then mv $@ ${ZONE_FILE} ; fi
./zonediff.sh ${ZONE_FILE}
$(OUTDIR)/$(VERSION)/%.html: %.html.jsonnet $(DEPS)
cd $(OUTDIR)/$(VERSION) && find . -type f | grep -v 'index.html' | sort > ../files.list
time jsonnet -J . \
--ext-str latest=$(strip $(shell date +%Y-%m-%dT%H:%M:%S )) \
--ext-str version=$(strip $(VERSION)) \
--string $< > $@
# NOTE: this target only works with the C++ implementation of jsonnet.
fmt:
@find . -name '*.jsonnet' -print0 | while read -d $$'\0' f; do \
jsonnetfmt --indent 2 --max-blank-lines 2 --sort-imports \
--string-style s --comment-style s $$f | diff $$f - ; \
jsonnetfmt --in-place $$f ; \
done