diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-07-05 10:36:19 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-07-09 12:34:10 +0300 |
commit | c4281ba3bb02f883a9c0980128cfbf3c445e9d89 (patch) | |
tree | 862471f099398b67138c8d7e877dd240bbaedfff /utils/gen-version.sh | |
parent | 0de1a9f318ecf9f3d069b8a4a4a02ef0391cfb04 (diff) |
libcamera: Rework automatic version generation to avoid rebuilds
Commit b817bcec6b53 ("libcamera: Auto generate version information")
generates version information in order to automatically include it
various locations (Sphinx and Doxygen documentation, libcamera::version
variable available at runtime, and version.h available at compile time).
Unfortunately this causes lots of unnecessary rebuilds when modifying
the git tree state, which hinders development.
The problem is caused by the generated version.h being listed as a
dependency for the whole libcamera. This is required as meson (to the
best of my knowledge) doesn't provide a way to explicitly specify the
dependency of a single object file (camera_manager.o in this case, as
camera_manager.cpp is the only consumer of the generated version string)
on the custom target used to generate version.h. The dependency can't be
automatically detected at build time, like dependencies on normal
headers that are generated by parsing the source, because the version.h
header may not exist yet. The build could then fail in a racy way.
This change attempts at solving the issue by generating a version.cpp
instead of a version.h to set the git-based version. This minimises the
number of files that need to be rebuild when then git tree state
changes, while retaining the main purpose of the original automatic
version generation, the ability to access the git-based version string
at runtime. We however lose the ability to access git-based version
information at build time in an application building against libcamera,
but there is no expected use case for this.
The version string is moved from the libcamera namespace to the
CameraManager class in order to avoid including version.h inside
libcamera (in version.cpp and in camera_manager.cpp), which would create
dependencies causing more rebuild steps, as described above.
On the other hand, major, minor and patch level version numbers are
useful at build time. This commit changes the generation of version.h in
order to add three macros named LIBCAMERA_VERSION_MAJOR,
LIBCAMERA_VERSION_MINOR and LIBCAMERA_VERSION_PATCH for this purpose.
version.h is not included by any other libcamera header or source file,
and thus doesn't force a rebuild of the library.
The Sphinx and Doxygen documentation keep their git-based version
information, which is set during the configuration of the build and then
doesn't track git commits. We may want to investigate how to improve
this, but given that git-based version for the documentation has very
few use cases outside of tagging nightly builds, this isn't considered
an issue at the moment.
The documentation install directory now uses the base version string, in
order to avoid increasing the number of documentation directories
needlessly. This shouldn't cause any issue as the API should not change
without a change to the version number.
The version number generation and handling code now also standardises
the version variables to not start with a 'v' prefix in meson, in order
to simplify their handling. The prefix is added when generating the
relevant files.
Note that we go back to specifying the fallback version in the main
meson.build, in the call to the project() function. For the time being I
believe this should be a good compromise to avoid unnecessary
recompilation, and moving the fallback version to a different file for
tarball releases can be built on top of this.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'utils/gen-version.sh')
-rwxr-xr-x | utils/gen-version.sh | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/utils/gen-version.sh b/utils/gen-version.sh index b3003d7a..708c01d3 100755 --- a/utils/gen-version.sh +++ b/utils/gen-version.sh @@ -8,6 +8,9 @@ then cd "$1" 2>/dev/null || exit 1 fi +# Bail out if the directory isn't under git control +git rev-parse --git-dir >/dev/null 2>&1 || exit 1 + # Get a short description from the tree. version=$(git describe --abbrev=8 --match "v[0-9]*" 2>/dev/null) @@ -16,22 +19,16 @@ then # Handle an un-tagged repository sha=$(git describe --abbrev=8 --always 2>/dev/null) commits=$(git log --oneline | wc -l 2>/dev/null) - version=v0.0.$commits.$sha + version="v0.0.0-$commits-g$sha" fi -# Prevent changed timestamps causing -dirty labels +# Append a '-dirty' suffix if the working tree is dirty. Prevent false +# positives due to changed timestamps by running git update-index. git update-index --refresh > /dev/null 2>&1 -dirty=$(git diff-index --name-only HEAD 2>/dev/null) || dirty= - -# Strip the 'g', and replace the preceeding '-' with a '+' to denote a label -version=$(echo "$version" | sed -e 's/-g/+/g') - -# Fix the '-' (the patch count) to a '.' as a version increment. -version=$(echo "$version" | sed -e 's/-/./g') +git diff-index --quiet HEAD || version="$version-dirty" -if [ -n "$dirty" ] -then - version=$version-dirty -fi +# Replace first '-' with a '+' to denote build metadata, strip the 'g' in from +# of the git SHA1 and remove the initial 'v'. +version=$(echo "$version" | sed -e 's/-/+/' | sed -e 's/-g/-/' | cut -c 2-) echo "$version" |