Thomas Heijligen has uploaded this change for review.
meson make: use VERSION file
To create a distribution package with meson you run
`meson dist -C <your_build_dir>`
This will collect all git tracked files and pack them into an archive.
There is no way to collect version information for that.
So now the base version stands in the VERSION file. To relase a flashrom
version you change that file and tag the changing commit.
When building from git the git version is embedded in the flashrom
binary. E.g.:
flashrom 1.4-devel (git:v1.2-1172-g7f186838) on Linux 6.1.3 (x86_64)
Change-Id: Idc17eadb397b3c579bddfbf9ae6bf1b171f5dfb7
Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com>
---
M Makefile
A VERSION
M meson.build
D util/getrevision.sh
D util/getversion.sh
5 files changed, 42 insertions(+), 320 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/57/72657/1
diff --git a/Makefile b/Makefile
index 08de553..70f7d94 100644
--- a/Makefile
+++ b/Makefile
@@ -397,13 +397,11 @@
CLI_OBJS = cli_classic.o cli_output.o cli_common.o print.o
-# versioninfo.inc stores metadata required to build a packaged flashrom. It is generated by the export rule and
-# imported below. If versioninfo.inc is not found and the variables are not defined by the user, the info will
-# be obtained using util/getrevision.sh, which is the common case during development.
--include versioninfo.inc
-VERSION ?= $(shell ./util/getrevision.sh --revision)
-
-SCMDEF := -D'FLASHROM_VERSION="$(VERSION)"'
+VERSION ?= $(shell cat ./VERSION)
+VERSION_GIT ?= $(shell git describe 2>/dev/null)
+ifdef VERSION_GIT
+ VERSION := "$(VERSION) (git:$(VERSION_GIT))"
+endif
# No spaces in release names unless set explicitly
RELEASENAME ?= $(shell echo "$(VERSION)" | sed -e 's/ /_/')
@@ -1000,7 +998,7 @@
fi
%.o: %.c | config
- $(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FLASHROM_CFLAGS) $(FEATURE_FLAGS) $(SCMDEF) -o $@ -c $<
+ $(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FLASHROM_CFLAGS) $(FEATURE_FLAGS) -D'FLASHROM_VERSION=$(VERSION)' -o $@ -c $<
$(PROGRAM)$(EXEC_SUFFIX): $(CLI_OBJS) libflashrom.a
$(CC) -o $@ $^ $(LDFLAGS)
@@ -1080,7 +1078,7 @@
make CC="CC=i386-elf-gcc lpgcc" AR=i386-elf-ar RANLIB=i386-elf-ranlib
gitconfig:
- ./util/getrevision.sh -c 2>/dev/null && ./util/git-hooks/install.sh
+ git rev-parse 2>/dev/null && ./util/git-hooks/install.sh
.PHONY: all install clean distclean config _export export tarball libpayload
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..25b3ed9
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+1.4-devel
diff --git a/meson.build b/meson.build
index 42695c7..d066142 100644
--- a/meson.build
+++ b/meson.build
@@ -1,5 +1,5 @@
project('flashromutils', 'c',
- version : run_command('util/getversion.sh', '--version', check : true).stdout().strip(),
+ version : files('VERSION'),
license : 'GPL-2.0',
meson_version : '>=0.57.0',
default_options : [
@@ -13,7 +13,17 @@
config = configuration_data()
-config.set_quoted('FLASHROM_VERSION', meson.project_version())
+version = meson.project_version()
+git = find_program('git', native : true, required : false)
+if git.found()
+ version_git = run_command('git', 'describe', check : false)
+ if version_git.returncode() == 0
+ version += ' (git:@0@)'.format(version_git.stdout().strip())
+ endif
+endif
+
+config.set_quoted('FLASHROM_VERSION', version)
+
config.set('FLASHROM_LIBVERSION', '1.0.0')
subdir('doc')
diff --git a/util/getrevision.sh b/util/getrevision.sh
deleted file mode 100755
index f7d6bf3..0000000
--- a/util/getrevision.sh
+++ /dev/null
@@ -1,238 +0,0 @@
-#!/bin/sh
-# NB: Supposed to be POSIX compatible but at least the usage of 'local' is not.
-#
-# This file is part of the flashrom project.
-#
-# Copyright (C) 2005 coresystems GmbH <stepan@coresystems.de>
-# Copyright (C) 2009,2010 Carl-Daniel Hailfinger
-# Copyright (C) 2010 Chromium OS Authors
-# Copyright (C) 2013-2016 Stefan Tauner
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-
-EXIT_SUCCESS=0
-EXIT_FAILURE=1
-
-# Make sure we don't get translated output
-export LC_ALL=C
-# nor local times or dates
-export TZ=UTC0
-
-# Helper functions
-# First argument is the path to inspect (usually optional; without
-# it the whole repository will be considered)
-git_has_local_changes() {
- git update-index -q --refresh >/dev/null
- ! git diff-index --quiet HEAD -- "$1"
-}
-
-git_last_commit() {
- # git rev-parse --short HEAD would suffice if repository as a whole is of interest (no $1)
- git log --pretty=format:"%h" -1 -- "$1"
-}
-
-git_is_file_tracked() {
- git ls-files --error-unmatch -- "$1" >/dev/null 2>&1
-}
-
-is_file_tracked() {
- git_is_file_tracked "$1"
-}
-
-# Tries to find a remote source for the changes committed locally.
-# This includes the URL of the remote repository including the last commit and a suitable branch name.
-# Takes one optional argument: the path to inspect
-git_url() {
- last_commit=$(git_last_commit "$1")
- # get all remote branches containing the last commit (excluding origin/HEAD)
- branches=$(git branch -r --contains $last_commit | sed '/\//!d;/.*->.*/d;s/[\t ]*//')
- if [ -z "$branches" ] ; then
- echo "No remote branch contains a suitable commit">&2
- return
- fi
-
- # find "nearest" branch
- local mindiff=9000
- local target=
- for branch in $branches ; do
- curdiff=$(git rev-list --count $last_commit..$branch)
- if [ $curdiff -ge $mindiff ] ; then
- continue
- fi
- mindiff=$curdiff
- target=$branch
- done
-
- echo "$(git ls-remote --exit-code --get-url ${target%/*}) ${target#*/}"
-}
-
-# Returns a string indicating where others can get the current source code (excluding uncommitted changes).
-# Takes one optional argument: the path to inspect
-scm_url() {
- local url=
-
- if git_is_file_tracked "$1" ; then
- url="$(git_url "$1")"
- else
- return ${EXIT_FAILURE}
- fi
-
- echo "${url}"
-}
-
-# Retrieve timestamp since last modification. If the sources are pristine,
-# then the timestamp will match that of the SCM's most recent modification
-# date.
-timestamp() {
- local t
-
- # date syntaxes are manifold:
- # gnu date [-d input]... [+FORMAT]
- # netbsd date [-ajnu] [-d date] [-r seconds] [+format] [[[[[[CC]yy]mm]dd]HH]MM[.SS]]
- # freebsd date [-jnu] [-d dst] [-r seconds] [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format] [...]
- # dragonflybsd date [-jnu] [-d dst] [-r seconds] [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format] [...]
- # openbsd date [-aju] [-d dst] [-r seconds] [+format] [[[[[[cc]yy]mm]dd]HH]MM[.SS]] [...]
- if git_is_file_tracked "$2" ; then
- # are there local changes?
- if git_has_local_changes "$2" ; then
- t=$(date -u "${1}")
- else
- # No local changes, get date of the last commit
- case $(uname) in
- # Most BSD dates do not support parsing date values from user input with -d but all of
- # them support parsing epoch seconds with -r. Thanks to git we can easily use that:
- NetBSD|OpenBSD|DragonFly|FreeBSD)
- t=$(date -u -r "$(git log --pretty=format:%ct -1 -- $2)" "$1" 2>/dev/null);;
- *)
- t=$(date -d "$(git log --pretty=format:%cD -1 -- $2)" -u "$1" 2>/dev/null);;
- esac
- fi
- else
- t=$(date -u "$1")
- fi
-
- if [ -z "$t" ]; then
- echo "Warning: Could not determine timestamp." 2>/dev/null
- fi
- echo "${t}"
-}
-
-revision() {
- local r
- if git_is_file_tracked "$1" ; then
- r=$(git describe --always $(git_last_commit "$1"))
- if git_has_local_changes "$1" ; then
- r="$r-dirty"
- fi
- else
- r="unknown"
- fi
-
- echo "${r}"
-}
-
-is_tracked() {
- is_file_tracked "$1"
-}
-
-show_help() {
- echo "Usage:
- ${0} <command> [path]
-
-Commands
- -h or --help
- this message
- -c or --check
- test if path is under version control at all
- -r or --revision
- return unique revision information including an indicator for
- uncommitted changes
- -U or --url
- URL associated with the latest commit
- -d or --date
- date of most recent modification
- -t or --timestamp
- timestamp of most recent modification
-"
- return
-}
-
-check_action() {
- if [ -n "$action" ]; then
- echo "Error: Multiple actions given.">&2
- exit ${EXIT_FAILURE}
- fi
-}
-
-main() {
- local query_path=
- local action=
-
- # Argument parser loop
- while [ $# -gt 0 ];
- do
- case ${1} in
- -h|--help)
- action=show_help;
- shift;;
- -U|--url)
- check_action $1
- action=scm_url
- shift;;
- -d|--date)
- check_action $1
- action="timestamp +%Y-%m-%d" # refrain from suffixing 'Z' to indicate it's UTC
- shift;;
- -r|--revision)
- check_action $1
- action=revision
- shift;;
- -t|--timestamp)
- check_action $1
- action="timestamp +%Y-%m-%dT%H:%M:%SZ" # There is only one valid time format! ISO 8601
- shift;;
- -c|--check)
- check_action $1
- action=is_tracked
- shift;;
- -*)
- show_help;
- echo "Error: Invalid option: ${1}"
- exit ${EXIT_FAILURE};;
- *)
- if [ -z "$query_path" ] ; then
- if [ ! -e "$1" ] ; then
- echo "Error: Path \"${1}\" does not exist.">&2
- exit ${EXIT_FAILURE}
- fi
- query_path=$1
- else
- echo "Warning: Ignoring overabundant parameter: \"${1}\"">&2
- fi
- shift;;
- esac;
- done
-
- # default to current directory (usually equals the whole repository)
- if [ -z "$query_path" ] ; then
- query_path=.
- fi
- if [ -z "$action" ] ; then
- show_help
- echo "Error: No actions specified"
- exit ${EXIT_FAILURE}
- fi
-
- $action "$query_path"
-}
-
-main $@
diff --git a/util/getversion.sh b/util/getversion.sh
deleted file mode 100755
index d3810d2..0000000
--- a/util/getversion.sh
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/bin/sh
-#
-# This file is part of the flashrom project.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-
-version() {
- if [ -r versioninfo.inc ]; then
- v=$(sed -n 's/^VERSION = //p' versioninfo.inc)
- else
- v=$($(dirname ${0})/getrevision.sh --revision)
- if [ $? -ne 0 ]; then
- v='unknown'
- fi
- fi
-
- echo ${v}
-}
-
-mandate() {
- if [ -r versioninfo.inc ]; then
- d=$(sed -n 's/^MAN_DATE = //p' versioninfo.inc)
- else
- d=$($(dirname ${0})/getrevision.sh --date flashrom.8.tmpl)
- if [ $? -ne 0 ]; then
- d='unknown'
- fi
- fi
-
- echo ${d}
-}
-
-show_help() {
- echo "Usage:
- ${0} <command>
-
-Commands
- -h or --help
- this message
- -v or --version
- return current/release flashrom version
- -m or --man-date
- return current/release date of the manual page
-"
-}
-
-if [ $# -ne 1 ]; then
- show_help
- echo "Error: Only exactly one command allowed.">&2
- exit 1
-fi
-
-case $1 in
- -h|--help) show_help;;
- -m|--man-date) mandate;;
- -v|--version) version;;
- *)
- show_help
- echo "Error: Invalid option: $1"
- exit 1
- ;;
-esac
To view, visit change 72657. To unsubscribe, or for help writing mail filters, visit settings.