From a92a4b7726ff70a2cbdec31aef24a895c04829fc Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 10 May 2022 12:35:39 +0200 Subject: [PATCH] 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. --- .gitignore | 1 + Makefile | 13 +++++++++++-- packaging/cockpit-starter-kit.spec.in | 2 ++ packit.yaml | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index aa13142..5792da1 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ POTFILES* tmp/ /po/LINGUAS /tools +/nodejs_provides.list diff --git a/Makefile b/Makefile index 46b1391..e66c87b 100644 --- a/Makefile +++ b/Makefile @@ -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("-(?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 \ diff --git a/packaging/cockpit-starter-kit.spec.in b/packaging/cockpit-starter-kit.spec.in index 156bd5e..3b31d45 100644 --- a/packaging/cockpit-starter-kit.spec.in +++ b/packaging/cockpit-starter-kit.spec.in @@ -21,6 +21,8 @@ BuildRequires: libappstream-glib-devel Requires: cockpit-bridge +%{NODEJS_PROVIDES} + %description Cockpit Starter Kit Example Module diff --git a/packit.yaml b/packit.yaml index 3fd4283..98e836d 100644 --- a/packit.yaml +++ b/packit.yaml @@ -7,6 +7,7 @@ specfile_path: cockpit-starter-kit.spec copy_upstream_release_description: true srpm_build_deps: + - jq - make - npm