From: Ben Crocker <bcrocker@xxxxxxxxxx> ⢠Makefile: Create new dist-dump-variables target for dynamically deriving variables from Makefile.common and dumping them. Create new dist-clean-scripts target to clean up generated scripts. Create new dist-self-test target and hook up the BATS self tests. Check for the presence of /usr/bin/bats (via 'test -x') and complain if it is not installed. Add a description of the new dist-self-test target to dist-full-help. ⢠Makefile.common: make HEAD an overridable variable. Change GITID:= $(shell $(GIT) log --max-count=1 --pretty=format:%H) to GITID:= $(shell $(GIT) log --max-count=1 --pretty=format:%H $(HEAD)) making the argument to 'git log' explicit and allowing it to be overridden by, e.g., self-tests. ⢠self-test/egit.sh: Initial commit This is a sample script providing a thin layer over the git command. It is meant to substitute in redhat/Makefile and Makefile.common via the GIT macro defined in Makefile. Each git subcommand currently used by Makefile and Makefile.common can be broken out into its own case. At the moment, the output of 'git describe' can be overridden by means of an environment variable, EGIT_OVERRIDE_DESCRIBE. Use case: self test with test values for 'git describe'. Other git subcommands are simply passed through. Usage: GIT=<path to egit.sh> EGIT_OVERRIDE_DESCRIBE=v5.9-rc8 DIST=.elrdy make dist-srpm ⢠self-test/1005-dist-dump-variables.bats: initial commit The four tests in 1005-dist-dump-variables.bats test the RPM version generation, name generation, and snapshot designation for several previously chosen tags/commits. The tags/commits chosen are: a) v5.8 b) v5.8-rc7 c) v5.8-9-g565674d613d7 d) v5.8-rc5-99-g25ccd24ffd91 and the expected results are: a) RPMVERSION = 5.8.0, no rc b) RPMVERSION = 5.8.0, .rc7 c) RPMVERSION = 5.9.0, .rc0, snapshot d) RPMVERSION = 5.8.0, .rc5, snapshot Signed-off-by: Ben Crocker <bcrocker@xxxxxxxxxx> --- redhat/Makefile | 20 ++++++- redhat/Makefile.common | 13 +++-- .../self-test/1005-dist-dump-variables.bats | 55 +++++++++++++++++++ redhat/self-test/egit.sh | 18 ++++++ 4 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 redhat/self-test/1005-dist-dump-variables.bats create mode 100755 redhat/self-test/egit.sh diff --git a/redhat/Makefile b/redhat/Makefile index 115ffc172960..84950bf876af 100644 --- a/redhat/Makefile +++ b/redhat/Makefile @@ -166,7 +166,10 @@ dist-clean-rpmdirs: rm -rf $$i; \ done; -dist-clean: dist-clean-sources dist-clean-configs dist-clean-rpmdirs +dist-clean-scripts: + @if [ -f dist-dump-variables.sh ]; then rm dist-dump-variables.sh; fi + +dist-clean: dist-clean-sources dist-clean-configs dist-clean-rpmdirs dist-clean-scripts dist-stub-key: @echo "Copying pre-generated keys"; @@ -382,6 +385,20 @@ dist-get-latest: dist-os-version: @echo "OSVERSION: $(RHEL_MAJOR).$(RHEL_MINOR)" +.EXPORT_ALL_VARIABLES: +.PHONY: dist-dump-variables +dist-dump-variables: + grep "^[ ]*[a-zA-Z_][a-zA-Z_0-9]*[ ]*[:?]*=" $(REDHAT)/Makefile.common | sed -e 's/[ ]*\([a-zA-Z_][a-zA-Z_0-9]*\).*/echo "\1=$$\1"/' | sort | uniq > dist-dump-variables.sh + chmod +x $(REDHAT)/dist-dump-variables.sh + @$(REDHAT)/dist-dump-variables.sh + +dist-self-test: + @if test -x /usr/bin/bats; then \ + bats $(REDHAT)/self-test/*.bats ; \ + else \ + echo "dist-self-test: The bats package is not installed" ; \ + fi + dist-help: @echo 'Cleaning targets:' @echo ' dist-clean - Clean redhat/configs/ and redhat/rpm/ directories.' @@ -499,4 +516,5 @@ dist-full-help: @echo ' development tag.' @echo ' dist-os-version - Displays the current Red Hat Enterprise Linux versioni' @echo ' target used by the current branch/tree.' + @echo ' dist-self-test - Runs self-tests from the redhat/self-test directory' @echo '' diff --git a/redhat/Makefile.common b/redhat/Makefile.common index 80c3b8dfccd4..cdffa9fb3d3d 100644 --- a/redhat/Makefile.common +++ b/redhat/Makefile.common @@ -6,11 +6,12 @@ RPMBUILD := $(shell if [ -x "/usr/bin/rpmbuild" ]; then echo rpmbuild; \ else echo rpm; fi) MACH := $(shell uname -m) -RPMKVERSION:=$(shell $(GIT) show HEAD:Makefile | sed -ne '/^VERSION\ =\ /{s///;p;q}') -RPMKPATCHLEVEL:=$(shell $(GIT) show HEAD:Makefile | sed -ne '/^PATCHLEVEL\ =\ /{s///;p;q}') -RPMKSUBLEVEL:=$(shell $(GIT) show HEAD:Makefile | sed -ne '/^SUBLEVEL\ =\ /{s///;p;q}') -RPMKEXTRAVERSION:=$(shell $(GIT) show HEAD:Makefile | sed -ne '/^EXTRAVERSION\ =\ /{s///;p;q}') -GITID:= $(shell $(GIT) log --max-count=1 --pretty=format:%H) +HEAD ?= HEAD +RPMKVERSION:=$(shell $(GIT) show $(HEAD):Makefile | sed -ne '/^VERSION\ =\ /{s///;p;q}') +RPMKPATCHLEVEL:=$(shell $(GIT) show $(HEAD):Makefile | sed -ne '/^PATCHLEVEL\ =\ /{s///;p;q}') +RPMKSUBLEVEL:=$(shell $(GIT) show $(HEAD):Makefile | sed -ne '/^SUBLEVEL\ =\ /{s///;p;q}') +RPMKEXTRAVERSION:=$(shell $(GIT) show $(HEAD):Makefile | sed -ne '/^EXTRAVERSION\ =\ /{s///;p;q}') +GITID:= $(shell $(GIT) log --max-count=1 --pretty=format:%H $(HEAD)) # marker is git tag which we base off of for exporting patches # Make sure marker uses RPMKPATCHLEVEL and RPMKEXTRAVERSION from the kernel # makefile as opposed to any adjusted version for snapshotting. @@ -42,7 +43,7 @@ else endif ifeq ($(VERSION_ON_UPSTREAM),1) # master is expected to track mainline. - MERGE_BASE:=$(shell $(GIT) merge-base HEAD master) + MERGE_BASE:=$(shell $(GIT) merge-base $(HEAD) master) _TAG:=$(shell $(GIT) describe $(MERGE_BASE)) # a snapshot off of a tagged git is of the form [tag]-[cnt]-g[hash] SNAPSHOT:=$(shell echo $(_TAG) | grep -c '\-g') diff --git a/redhat/self-test/1005-dist-dump-variables.bats b/redhat/self-test/1005-dist-dump-variables.bats new file mode 100644 index 000000000000..9251ca4636d5 --- /dev/null +++ b/redhat/self-test/1005-dist-dump-variables.bats @@ -0,0 +1,55 @@ +#!/usr/bin/env bats + +function prologue() +{ + tag=$1 + ofile=$BATS_TMPDIR/$tag.out + # Have to unset environment variables that may be inherited from supra-make: + grep "^[ ]*[a-zA-Z_][a-zA-Z_0-9]*[ ]*[:?]*=" \ + $BATS_TEST_DIRNAME/../Makefile.common | \ + sed -e 's/[ ]*\([a-zA-Z_][a-zA-Z_0-9]*\).*/unset \1/' | \ + sort | uniq > $BATS_TMPDIR/unset-vars.sh + source $BATS_TMPDIR/unset-vars.sh + GIT=$BATS_TEST_DIRNAME/egit.sh HEAD=$tag EGIT_OVERRIDE_DESCRIBE=$tag DIST=.fc33 make dist-dump-variables > $ofile +} + +function checkversion() +{ + status=1 + if grep -x "_TAG=$1" $ofile && \ + grep -x "RPMKVERSION=$2" $ofile && grep -x "RPMKPATCHLEVEL=$3" $ofile && \ + grep -x "RPMKSUBLEVEL=$4" $ofile && grep -x "RPMKEXTRAVERSION=$5" $ofile && \ + grep -x "KEXTRAVERSION=$6" $ofile && \ + grep -x "SNAPSHOT=$7" $ofile + then + status=$? + fi +} + +@test "dist-dump-variables v5.8" { + tag=v5.8 + prologue $tag + checkversion $tag "5" "8" "0" "" "" "0" + [ "$status" = 0 ] +} + +@test "dist-dump-variables v5.8-rc7" { + tag=v5.8-rc7 + prologue $tag + checkversion $tag "5" "8" "0" "-rc7" ".rc7" "0" + [ "$status" = 0 ] +} + +@test "dist-dump-variables v5.8-9-g565674d613d7" { + tag=v5.8-9-g565674d613d7 + prologue $tag + checkversion $tag "5" "9" "0" "" ".rc0" "1" + [ "$status" = 0 ] +} + +@test "dist-dump-variables v5.8-rc5-99-g25ccd24ffd91" { + tag=v5.8-rc5-99-g25ccd24ffd91 + prologue $tag + checkversion $tag "5" "8" "0" "-rc5" ".rc5" "1" + [ "$status" = 0 ] +} diff --git a/redhat/self-test/egit.sh b/redhat/self-test/egit.sh new file mode 100755 index 000000000000..f26921cc2aca --- /dev/null +++ b/redhat/self-test/egit.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +arg=$1 +shift +case $arg in + describe ) + if [ -n "$EGIT_OVERRIDE_DESCRIBE" ] + then + # Should be a version, e.g. v5.9-rc8 or v5.9-rc7-1449-g57b6fb86b0ac + echo "$EGIT_OVERRIDE_DESCRIBE" + else + git describe "$@" + fi + ;; + * ) + git "$arg" "$@" + ;; +esac -- GitLab _______________________________________________ kernel mailing list -- kernel@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to kernel-leave@xxxxxxxxxxxxxxxxxxxxxxx Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/kernel@xxxxxxxxxxxxxxxxxxxxxxx