forked from cockpit-project/cockpit-ostree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
170 lines (139 loc) · 6.34 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# extract name from package.json
PACKAGE_NAME := $(shell awk '/"name":/ {gsub(/[",]/, "", $$2); print $$2}' package.json)
VERSION := $(shell T=$$(git describe 2>/dev/null) || T=1; echo $$T | tr '-' '.')
ifeq ($(TEST_OS),)
TEST_OS = fedora-coreos
endif
export TEST_OS
TARFILE=$(PACKAGE_NAME)-$(VERSION).tar.xz
NODE_CACHE=$(PACKAGE_NAME)-node-$(VERSION).tar.xz
RPMFILE=$(shell rpmspec -D"VERSION $(VERSION)" -q $(PACKAGE_NAME).spec.in).rpm
SRPMFILE=$(subst noarch,src,$(RPMFILE))
PREFIX ?= /usr/local
VM_IMAGE=$(CURDIR)/test/images/$(TEST_OS)
# stamp file to check if/when npm install ran
NODE_MODULES_TEST=package-lock.json
# one example file in dist/ from webpack to check if that already ran
WEBPACK_TEST=dist/manifest.json
# one example file in src/lib to check if it was already checked out
LIB_TEST=src/lib/cockpit-po-plugin.js
all: $(WEBPACK_TEST)
#
# i18n
#
po/$(PACKAGE_NAME).js.pot:
xgettext --default-domain=cockpit --output=$@ --language=C --keyword= \
--keyword=_:1,1t --keyword=_:1c,2,2t --keyword=C_:1c,2 \
--keyword=N_ --keyword=NC_:1c,2 \
--keyword=gettext:1,1t --keyword=gettext:1c,2,2t \
--keyword=ngettext:1,2,3t --keyword=ngettext:1c,2,3,4t \
--keyword=gettextCatalog.getString:1,3c --keyword=gettextCatalog.getPlural:2,3,4c \
--from-code=UTF-8 $$(find src/ -name '*.js' -o -name '*.jsx')
po/$(PACKAGE_NAME).html.pot: $(NODE_MODULES_TEST)
po/html2po -o $@ $$(find src -name '*.html')
po/$(PACKAGE_NAME).manifest.pot: $(NODE_MODULES_TEST)
po/manifest2po src/manifest.json -o $@
po/$(PACKAGE_NAME).pot: po/$(PACKAGE_NAME).html.pot po/$(PACKAGE_NAME).js.pot po/$(PACKAGE_NAME).manifest.pot
msgcat --sort-output --output-file=$@ $^
#
# Build/Install/dist
#
%.spec: %.spec.in
sed -e 's/%{VERSION}/$(VERSION)/g' $< > $@
$(WEBPACK_TEST): $(NODE_MODULES_TEST) $(LIB_TEST) $(shell find src/ -type f) package.json webpack.config.js
NODE_ENV=$(NODE_ENV) node_modules/.bin/webpack
watch:
NODE_ENV=$(NODE_ENV) node_modules/.bin/webpack --watch
clean:
rm -rf dist/
[ ! -e $(PACKAGE_NAME).spec.in ] || rm -f $(PACKAGE_NAME).spec
install: $(WEBPACK_TEST)
mkdir -p $(DESTDIR)$(PREFIX)/share/cockpit/$(PACKAGE_NAME)
cp -r dist/* $(DESTDIR)$(PREFIX)/share/cockpit/$(PACKAGE_NAME)
# this requires a built source tree and avoids having to install anything system-wide
devel-install: $(WEBPACK_TEST)
mkdir -p ~/.local/share/cockpit
ln -s `pwd`/dist ~/.local/share/cockpit/$(PACKAGE_NAME)
dist: $(TARFILE)
@ls -1 $(TARFILE)
# when building a distribution tarball, call webpack with a 'production' environment
# we don't ship node_modules for license and compactness reasons; we ship a
# pre-built dist/ (so it's not necessary) and ship packge-lock.json (so that
# node_modules/ can be reconstructed if necessary)
$(TARFILE): NODE_ENV=production
$(TARFILE): $(WEBPACK_TEST) $(PACKAGE_NAME).spec
touch -r package.json $(NODE_MODULES_TEST)
touch dist/*
tar --xz -cf $(TARFILE) --transform 's,^,$(PACKAGE_NAME)/,' \
--exclude $(PACKAGE_NAME).spec.in --exclude node_modules --exclude test/reference \
$$(git ls-files) src/lib package-lock.json $(PACKAGE_NAME).spec dist/
$(NODE_CACHE): $(NODE_MODULES_TEST)
tar --xz -cf $@ node_modules
node-cache: $(NODE_CACHE)
srpm: $(SRPMFILE)
$(SRPMFILE): $(TARFILE) $(PACKAGE_NAME).spec
rpmbuild -bs \
--define "_sourcedir `pwd`" \
--define "_srcrpmdir `pwd`" \
$(PACKAGE_NAME).spec
rpm: $(RPMFILE)
# this is a noarch build, so local rpm build works fine for recent OSes; but
# RHEL/CentOS Atomic don't get along with rpms built on Fedora ≥ 31
$(RPMFILE): $(SRPMFILE) bots
set -e; srpm=`ls *.src.rpm | head -n1`; \
if [ "$${TEST_OS%-atomic}" != "$$TEST_OS" ]; then \
bots/image-download centos-7; \
test/rpmbuild-vm "$$srpm" centos-7; \
else \
test/rpmbuild-local "$$srpm"; \
fi
# build a VM with locally built rpm installed, cockpit/ws container, and local
# ostree for testing
$(VM_IMAGE): rpm bots
rm -f $(VM_IMAGE) $(VM_IMAGE).qcow2
bots/image-customize -v --upload $$(ls $(PACKAGE_NAME)-*.noarch.rpm):/tmp/ \
--no-network \
--run-command 'rpm -q cockpit-ostree && rpm-ostree --cache-only override replace /tmp/*.rpm || rpm-ostree --cache-only install /tmp/*.rpm' \
$(TEST_OS)
# building the local tree needs the modified tree from above booted already
bots/image-customize -v --no-network --script $(CURDIR)/test/vm.install $(TEST_OS)
# convenience target for the above
vm: $(VM_IMAGE)
echo $(VM_IMAGE)
# run the QUnit tests
check-unit: $(NODE_MODULES_TEST)
npm run test
# run the browser integration tests; skip check for SELinux denials
# this will run all tests/check-* and format them as TAP
check: $(NODE_MODULES_TEST) $(VM_IMAGE) test/common test/reference check-unit
TEST_AUDIT_NO_SELINUX=1 test/common/run-tests ${RUN_TESTS_OPTIONS}
# checkout Cockpit's bots for standard test VM images and API to launch them
# must be from main, as only that has current and existing images; but testvm.py API is stable
# support CI testing against a bots change
bots:
git clone --quiet --reference-if-able $${XDG_CACHE_HOME:-$$HOME/.cache}/cockpit-project/bots https://github.com/cockpit-project/bots.git
if [ -n "$$COCKPIT_BOTS_REF" ]; then git -C bots fetch --quiet --depth=1 origin "$$COCKPIT_BOTS_REF"; git -C bots checkout --quiet FETCH_HEAD; fi
@echo "checked out bots/ ref $$(git -C bots rev-parse HEAD)"
# checkout Cockpit's test API; this has no API stability guarantee, so check out a stable tag
# when you start a new project, use the latest release, and update it from time to time
test/common:
flock Makefile sh -ec '\
git fetch --depth=1 https://github.com/cockpit-project/cockpit.git 267; \
git checkout --force FETCH_HEAD -- test/common; \
git reset test/common'
test/reference: test/common
test/common/pixel-tests pull
# checkout Cockpit's PF/React/build library; again this has no API stability guarantee, so check out a stable tag
$(LIB_TEST):
flock Makefile sh -ec '\
git fetch --depth=1 https://github.com/cockpit-project/cockpit.git 261; \
git checkout --force FETCH_HEAD -- pkg/lib; \
git reset -- pkg/lib'
mv pkg/lib src/ && rmdir -p pkg
$(NODE_MODULES_TEST): package.json
# if it exists already, npm install won't update it; force that so that we always get up-to-date packages
rm -f package-lock.json
# unset NODE_ENV, skips devDependencies otherwise
env -u NODE_ENV npm install
env -u NODE_ENV npm prune
.PHONY: all clean install devel-install dist node-cache srpm rpm check check-unit vm