|
| 1 | +# extract name from package.json |
| 2 | +PACKAGE_NAME := $(shell awk '/"name":/ {gsub(/[",]/, "", $$2); print $$2}' package.json) |
| 3 | +RPM_NAME := cockpit-$(PACKAGE_NAME) |
| 4 | +VERSION := $(shell T=$$(git describe 2>/dev/null) || T=1; echo $$T | tr '-' '.') |
| 5 | +ifeq ($(TEST_OS),) |
| 6 | +TEST_OS = centos-8-stream |
| 7 | +endif |
| 8 | +export TEST_OS |
| 9 | +TARFILE=$(RPM_NAME)-$(VERSION).tar.xz |
| 10 | +NODE_CACHE=$(RPM_NAME)-node-$(VERSION).tar.xz |
| 11 | +SPEC=$(RPM_NAME).spec |
| 12 | +APPSTREAMFILE=org.cockpit-project.$(PACKAGE_NAME).metainfo.xml |
| 13 | +VM_IMAGE=$(CURDIR)/test/images/$(TEST_OS) |
| 14 | +# stamp file to check if/when npm install ran |
| 15 | +NODE_MODULES_TEST=package-lock.json |
| 16 | +# one example file in dist/ from webpack to check if that already ran |
| 17 | +WEBPACK_TEST=dist/manifest.json |
| 18 | +# one example file in src/lib to check if it was already checked out |
| 19 | +LIB_TEST=src/lib/cockpit-po-plugin.js |
| 20 | +# common arguments for tar, mostly to make the generated tarballs reproducible |
| 21 | +TAR_ARGS = --sort=name --mtime "@$(shell git show --no-patch --format='%at')" --mode=go=rX,u+rw,a-s --numeric-owner --owner=0 --group=0 |
| 22 | + |
| 23 | +all: $(WEBPACK_TEST) |
| 24 | + |
| 25 | +# |
| 26 | +# i18n |
| 27 | +# |
| 28 | + |
| 29 | +LINGUAS=$(basename $(notdir $(wildcard po/*.po))) |
| 30 | + |
| 31 | +po/$(PACKAGE_NAME).js.pot: |
| 32 | + xgettext --default-domain=$(PACKAGE_NAME) --output=$@ --language=C --keyword= \ |
| 33 | + --keyword=_:1,1t --keyword=_:1c,2,2t --keyword=C_:1c,2 \ |
| 34 | + --keyword=N_ --keyword=NC_:1c,2 \ |
| 35 | + --keyword=gettext:1,1t --keyword=gettext:1c,2,2t \ |
| 36 | + --keyword=ngettext:1,2,3t --keyword=ngettext:1c,2,3,4t \ |
| 37 | + --keyword=gettextCatalog.getString:1,3c --keyword=gettextCatalog.getPlural:2,3,4c \ |
| 38 | + --from-code=UTF-8 $$(find src/ \( -name '*.js' -o -name '*.jsx' \) \! -path 'src/lib/*') |
| 39 | + |
| 40 | +po/$(PACKAGE_NAME).html.pot: $(NODE_MODULES_TEST) |
| 41 | + po/html2po -o $@ $$(find src -name '*.html' \! -path 'src/lib/*') |
| 42 | + |
| 43 | +po/$(PACKAGE_NAME).manifest.pot: $(NODE_MODULES_TEST) |
| 44 | + po/manifest2po src/manifest.json -o $@ |
| 45 | + |
| 46 | +po/$(PACKAGE_NAME).metainfo.pot: $(APPSTREAMFILE) |
| 47 | + xgettext --default-domain=$(PACKAGE_NAME) --output=$@ $< |
| 48 | + |
| 49 | +po/$(PACKAGE_NAME).pot: po/$(PACKAGE_NAME).html.pot po/$(PACKAGE_NAME).js.pot po/$(PACKAGE_NAME).manifest.pot po/$(PACKAGE_NAME).metainfo.pot |
| 50 | + msgcat --sort-output --output-file=$@ $^ |
| 51 | + |
| 52 | +po/LINGUAS: |
| 53 | + echo $(LINGUAS) | tr ' ' '\n' > $@ |
| 54 | + |
| 55 | +# Update translations against current PO template |
| 56 | +update-po: po/$(PACKAGE_NAME).pot |
| 57 | + for lang in $(LINGUAS); do \ |
| 58 | + msgmerge --output-file=po/$$lang.po po/$$lang.po $<; \ |
| 59 | + done |
| 60 | + |
| 61 | +# |
| 62 | +# Build/Install/dist |
| 63 | +# |
| 64 | + |
| 65 | +%.spec: packaging/%.spec.in |
| 66 | + sed -e 's/%{VERSION}/$(VERSION)/g' $< > $@ |
| 67 | + |
| 68 | +$(WEBPACK_TEST): $(NODE_MODULES_TEST) $(LIB_TEST) $(shell find src/ -type f) package.json webpack.config.js |
| 69 | + NODE_ENV=$(NODE_ENV) node_modules/.bin/webpack |
| 70 | + |
| 71 | +watch: |
| 72 | + NODE_ENV=$(NODE_ENV) node_modules/.bin/webpack --watch |
| 73 | + |
| 74 | +clean: |
| 75 | + rm -rf dist/ |
| 76 | + rm -f $(SPEC) |
| 77 | + rm -f po/LINGUAS |
| 78 | + |
| 79 | +install: $(WEBPACK_TEST) po/LINGUAS |
| 80 | + mkdir -p $(DESTDIR)/usr/share/cockpit/$(PACKAGE_NAME) |
| 81 | + cp -r dist/* $(DESTDIR)/usr/share/cockpit/$(PACKAGE_NAME) |
| 82 | + mkdir -p $(DESTDIR)/usr/share/metainfo/ |
| 83 | + msgfmt --xml -d po \ |
| 84 | + --template $(APPSTREAMFILE) \ |
| 85 | + -o $(DESTDIR)/usr/share/metainfo/$(APPSTREAMFILE) |
| 86 | + |
| 87 | +# this requires a built source tree and avoids having to install anything system-wide |
| 88 | +devel-install: $(WEBPACK_TEST) |
| 89 | + mkdir -p ~/.local/share/cockpit |
| 90 | + ln -s `pwd`/dist ~/.local/share/cockpit/$(PACKAGE_NAME) |
| 91 | + |
| 92 | +# assumes that there was symlink set up using the above devel-install target, |
| 93 | +# and removes it |
| 94 | +devel-uninstall: |
| 95 | + rm -f ~/.local/share/cockpit/$(PACKAGE_NAME) |
| 96 | + |
| 97 | +print-version: |
| 98 | + @echo "$(VERSION)" |
| 99 | + |
| 100 | +dist: $(TARFILE) |
| 101 | + @ls -1 $(TARFILE) |
| 102 | + |
| 103 | +# when building a distribution tarball, call webpack with a 'production' environment |
| 104 | +# we don't ship node_modules for license and compactness reasons; we ship a |
| 105 | +# pre-built dist/ (so it's not necessary) and ship packge-lock.json (so that |
| 106 | +# node_modules/ can be reconstructed if necessary) |
| 107 | +$(TARFILE): export NODE_ENV=production |
| 108 | +$(TARFILE): $(WEBPACK_TEST) $(SPEC) |
| 109 | + if type appstream-util >/dev/null 2>&1; then appstream-util validate-relax --nonet *.metainfo.xml; fi |
| 110 | + touch -r package.json $(NODE_MODULES_TEST) |
| 111 | + touch dist/* |
| 112 | + tar --xz $(TAR_ARGS) -cf $(TARFILE) --transform 's,^,$(RPM_NAME)/,' \ |
| 113 | + --exclude packaging/$(SPEC).in --exclude node_modules \ |
| 114 | + $$(git ls-files) src/lib package-lock.json $(SPEC) dist/ |
| 115 | + |
| 116 | +$(NODE_CACHE): $(NODE_MODULES_TEST) |
| 117 | + tar --xz $(TAR_ARGS) -cf $@ node_modules |
| 118 | + |
| 119 | +node-cache: $(NODE_CACHE) |
| 120 | + |
| 121 | +# convenience target for developers |
| 122 | +srpm: $(TARFILE) $(NODE_CACHE) $(SPEC) |
| 123 | + rpmbuild -bs \ |
| 124 | + --define "_sourcedir `pwd`" \ |
| 125 | + --define "_srcrpmdir `pwd`" \ |
| 126 | + $(SPEC) |
| 127 | + |
| 128 | +# convenience target for developers |
| 129 | +rpm: $(TARFILE) $(NODE_CACHE) $(SPEC) |
| 130 | + mkdir -p "`pwd`/output" |
| 131 | + mkdir -p "`pwd`/rpmbuild" |
| 132 | + rpmbuild -bb \ |
| 133 | + --define "_sourcedir `pwd`" \ |
| 134 | + --define "_specdir `pwd`" \ |
| 135 | + --define "_builddir `pwd`/rpmbuild" \ |
| 136 | + --define "_srcrpmdir `pwd`" \ |
| 137 | + --define "_rpmdir `pwd`/output" \ |
| 138 | + --define "_buildrootdir `pwd`/build" \ |
| 139 | + $(SPEC) |
| 140 | + find `pwd`/output -name '*.rpm' -printf '%f\n' -exec mv {} . \; |
| 141 | + rm -r "`pwd`/rpmbuild" |
| 142 | + rm -r "`pwd`/output" "`pwd`/build" |
| 143 | + |
| 144 | +# build a VM with locally built distro pkgs installed |
| 145 | +# disable networking, VM images have mock/pbuilder with the common build dependencies pre-installed |
| 146 | +$(VM_IMAGE): $(TARFILE) $(NODE_CACHE) bots test/vm.install |
| 147 | + bots/image-customize --no-network --fresh \ |
| 148 | + --upload $(NODE_CACHE):/var/tmp/ --build $(TARFILE) \ |
| 149 | + --script $(CURDIR)/test/vm.install $(TEST_OS) |
| 150 | + |
| 151 | +# convenience target for the above |
| 152 | +vm: $(VM_IMAGE) |
| 153 | + echo $(VM_IMAGE) |
| 154 | + |
| 155 | +# convenience target to print the filename of the test image |
| 156 | +print-vm: |
| 157 | + echo $(VM_IMAGE) |
| 158 | + |
| 159 | +# convenience target to setup all the bits needed for the integration tests |
| 160 | +# without actually running them |
| 161 | +prepare-check: $(NODE_MODULES_TEST) $(VM_IMAGE) test/common |
| 162 | + |
| 163 | +# run the browser integration tests; skip check for SELinux denials |
| 164 | +# this will run all tests/check-* and format them as TAP |
| 165 | +check: prepare-check |
| 166 | + TEST_AUDIT_NO_SELINUX=1 test/common/run-tests |
| 167 | + |
| 168 | +# checkout Cockpit's bots for standard test VM images and API to launch them |
| 169 | +# must be from main, as only that has current and existing images; but testvm.py API is stable |
| 170 | +# support CI testing against a bots change |
| 171 | +bots: |
| 172 | + git clone --quiet --reference-if-able $${XDG_CACHE_HOME:-$$HOME/.cache}/cockpit-project/bots https://github.com/cockpit-project/bots.git |
| 173 | + 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 |
| 174 | + @echo "checked out bots/ ref $$(git -C bots rev-parse HEAD)" |
| 175 | + |
| 176 | +# checkout Cockpit's test API; this has no API stability guarantee, so check out a stable tag |
| 177 | +# when you start a new project, use the latest release, and update it from time to time |
| 178 | +test/common: |
| 179 | + flock Makefile sh -ec '\ |
| 180 | + git fetch --depth=1 https://github.com/cockpit-project/cockpit.git 265; \ |
| 181 | + git checkout --force FETCH_HEAD -- test/common; \ |
| 182 | + git reset test/common' |
| 183 | + |
| 184 | +# checkout Cockpit's PF/React/build library; again this has no API stability guarantee, so check out a stable tag |
| 185 | +$(LIB_TEST): |
| 186 | + flock Makefile sh -ec '\ |
| 187 | + git fetch --depth=1 https://github.com/cockpit-project/cockpit.git 265; \ |
| 188 | + git checkout --force FETCH_HEAD -- ../pkg/lib; \ |
| 189 | + git reset -- ../pkg/lib' |
| 190 | + mv ../pkg/lib/cockpit-po-plugin.js ../pkg/lib/cockpit-rsync-plugin.js src/lib && rm -r ../pkg |
| 191 | + |
| 192 | +$(NODE_MODULES_TEST): package.json |
| 193 | + # if it exists already, npm install won't update it; force that so that we always get up-to-date packages |
| 194 | + rm -f package-lock.json |
| 195 | + # unset NODE_ENV, skips devDependencies otherwise |
| 196 | + env -u NODE_ENV npm install |
| 197 | + env -u NODE_ENV npm prune |
| 198 | + |
| 199 | +.PHONY: all clean install devel-install print-version dist node-cache rpm check vm update-po print-vm devel-uninstall |
0 commit comments