spec: automatic Provides generation from node_modules

One of the requirements of Fedora packages that contain the result of
nodejs modules is to list them as Provides. Listing them manually in the
spec file would be a manual job, too error prone.

As solution, create the static list of nodejs modules as RPM Provides,
and include it in the spec file so it is used when building the RPM
package. This is done by querying npm for the list of locally installed
modules, and using jq to output that as Provides. There are manglings
done:
- the '@' in the name of a module is removed, and '/' replaced with '-'
- e.g. "-alpha" or "-beta-" in the version of a module are turned into
  "~something", as "-" is not accepted as version by RPM (whereas the
  tilde is the compliant way for pre-releases in versioning guidelines)

Sadly this static inclusion is the only possible way at the moment,
as a in-package dependency generator is not possible, nor any other form
of dynamic filling of package relationships only at build/install time.
This commit is contained in:
Pino Toscano 2022-05-10 12:35:39 +02:00
parent b54f4aa607
commit a92a4b7726
4 changed files with 15 additions and 2 deletions

1
.gitignore vendored
View file

@ -17,3 +17,4 @@ POTFILES*
tmp/
/po/LINGUAS
/tools
/nodejs_provides.list

View file

@ -9,6 +9,7 @@ export TEST_OS
TARFILE=$(RPM_NAME)-$(VERSION).tar.xz
NODE_CACHE=$(RPM_NAME)-node-$(VERSION).tar.xz
SPEC=$(RPM_NAME).spec
SPEC_LIST=nodejs_provides.list
PREFIX ?= /usr/local
APPSTREAMFILE=org.cockpit-project.$(PACKAGE_NAME).metainfo.xml
VM_IMAGE=$(CURDIR)/test/images/$(TEST_OS)
@ -77,8 +78,10 @@ po/LINGUAS:
# Build/Install/dist
#
%.spec: packaging/%.spec.in
sed -e 's/%{VERSION}/$(VERSION)/g' $< > $@
%.spec: packaging/%.spec.in $(SPEC_LIST)
sed -e 's/%{VERSION}/$(VERSION)/g' \
-e '/%{NODEJS_PROVIDES}/{r $(SPEC_LIST)' -e 'd}' \
$< > $@
$(DIST_TEST): $(NODE_MODULES_TEST) $(COCKPIT_REPO_STAMP) $(shell find src/ -type f) package.json webpack.config.js
NODE_ENV=$(NODE_ENV) node_modules/.bin/webpack
@ -90,6 +93,7 @@ clean:
rm -rf dist/
rm -f $(SPEC)
rm -f po/LINGUAS
rm -f $(SPEC_LIST)
install: $(DIST_TEST) po/LINGUAS
mkdir -p $(DESTDIR)$(PREFIX)/share/cockpit/$(PACKAGE_NAME)
@ -131,6 +135,11 @@ $(NODE_CACHE): $(NODE_MODULES_TEST)
node-cache: $(NODE_CACHE)
$(SPEC_LIST): $(NODE_MODULES_TEST)
npm ls --json | \
jq -r 'def fn: gsub("@"; "") | gsub("/"; "-"); def fv: gsub("-(?<a>alpha|beta|rc)-?"; "~\(.a)"); .dependencies | to_entries[] | "Provides: bundled(nodejs-\(.key | fn)) = \(.value.version | fv)"' \
> $@
# convenience target for developers
srpm: $(TARFILE) $(NODE_CACHE) $(SPEC)
rpmbuild -bs \

View file

@ -21,6 +21,8 @@ BuildRequires: libappstream-glib-devel
Requires: cockpit-bridge
%{NODEJS_PROVIDES}
%description
Cockpit Starter Kit Example Module

View file

@ -7,6 +7,7 @@ specfile_path: cockpit-starter-kit.spec
copy_upstream_release_description: true
srpm_build_deps:
- jq
- make
- npm