Message ID | 20211013101650.1810576-1-naush@raspberrypi.com |
---|---|
Headers | show |
Series |
|
Related | show |
On Wed, 13 Oct 2021 at 11:19, Naushir Patuck <naush@raspberrypi.com> wrote: > When distributions build and package libcamera libraries, they may not > necessarily run the build in the upstream source tree. In these cases, the > git > SHA1 versioning information will be lost. > > This change addresses that problem by requiring package managers to run > 'meson dist' to create a tarball of the source files and build from there. > On runing 'meson dist', the utils/run-dist.sh script will create a > version.gen > file in the release tarball with the version string generated from the > existing > utils/gen-version.sh script. > > The build system has been updated to check for the presence of this > version.gen > file and read the version string from it. If the file is not present, the > version string is generated by running utils/gen-version.sh as it currently > does. > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com> > --- > meson.build | 30 ++++++++++++++++++++---------- > src/libcamera/meson.build | 11 +++++------ > utils/run-dist.sh | 9 +++++++++ > 3 files changed, 34 insertions(+), 16 deletions(-) > create mode 100644 utils/run-dist.sh > > diff --git a/meson.build b/meson.build > index a49c484fe64e..f27bfd479a5c 100644 > --- a/meson.build > +++ b/meson.build > @@ -10,20 +10,30 @@ project('libcamera', 'c', 'cpp', > ], > license : 'LGPL 2.1+') > > -# Generate version information. The libcamera_git_version variable > contains the > -# full version with git patch count and SHA1 (e.g. 1.2.3+211-c94a24f4), > while > -# the libcamera_version variable contains the major.minor.patch (e.g. > 1.2.3) > -# only. If the source tree isn't under git control, or if it matches the > last > -# git version tag, the build metadata (e.g. +211-c94a24f4) is omitted from > -# libcamera_git_version. > -libcamera_git_version = run_command('utils/gen-version.sh', > - meson.build_root()).stdout().strip() > -if libcamera_git_version == '' > - libcamera_git_version = meson.project_version() > +fs_mod = import('fs') > +if not fs_mod.is_file('version.gen') > + # Generate version information. The libcamera_git_version variable > contains the > + # the full version with git patch count and SHA1 (e.g. > 1.2.3+211-c94a24f4), while > + # the libcamera_version variable contains the major.minor.patch (e.g. > 1.2.3) > + # only. If the source tree isn't under git control, or if it matches > the last > + # git version tag, the build metadata (e.g. +211-c94a24f4) is omitted > from > + # libcamera_git_version. > + libcamera_git_version = run_command('utils/gen-version.sh', > + > meson.build_root()).stdout().strip() > + if libcamera_git_version == '' > + libcamera_git_version = meson.project_version() > + endif > +else > + # Read the version information from the file generated by the > utils/run-dist.sh > + # script on a 'meson dist' command. > + libcamera_git_version = run_command(['cat', > 'version.gen']).stdout().strip() > endif > I've added an if clause here to check for the presence of the version file, but I could equally leave this as-is and check for the file in gen-version.sh. I don't have a strong preference either way. Naush > > libcamera_version = libcamera_git_version.split('+')[0] > > +# This script gererates the version.gen file on a 'meson dist' command. > +meson.add_dist_script('utils/run-dist.sh') > + > # Configure the build environment. > cc = meson.get_compiler('c') > cxx = meson.get_compiler('cpp') > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build > index 243dd3c180eb..360eaf80ecf1 100644 > --- a/src/libcamera/meson.build > +++ b/src/libcamera/meson.build > @@ -93,12 +93,11 @@ endforeach > > libcamera_sources += control_sources > > -gen_version = meson.source_root() / 'utils' / 'gen-version.sh' > - > -version_cpp = vcs_tag(command : [gen_version, meson.build_root()], > - input : 'version.cpp.in', > - output : 'version.cpp', > - fallback : meson.project_version()) > +version_data = configuration_data() > +version_data.set('VCS_TAG', libcamera_git_version) > +version_cpp = configure_file(input : 'version.cpp.in', > + output : 'version.cpp', > + configuration : version_data) > > libcamera_sources += version_cpp > > diff --git a/utils/run-dist.sh b/utils/run-dist.sh > new file mode 100644 > index 000000000000..1b2a6348c6bc > --- /dev/null > +++ b/utils/run-dist.sh > @@ -0,0 +1,9 @@ > +#!/bin/sh > + > +# SPDX-License-Identifier: GPL-2.0-or-later > +# > +# On a meson dist run, generate the version string and store it in a file. > +# This will late be picked up by the build system and used in place of > running > +# the utils/gen-version.sh script again since we may not be running in the > +# upstream git source tree, and so version information would be lost. > +"$MESON_DIST_ROOT"/utils/gen-version.sh > "$MESON_DIST_ROOT"/version.gen > -- > 2.25.1 > >
Hi Naush, Thank you for the patch. On Wed, Oct 13, 2021 at 11:20:53AM +0100, Naushir Patuck wrote: > On Wed, 13 Oct 2021 at 11:19, Naushir Patuck wrote: > > When distributions build and package libcamera libraries, they may not > > necessarily run the build in the upstream source tree. In these cases, the git > > SHA1 versioning information will be lost. > > > > This change addresses that problem by requiring package managers to run > > 'meson dist' to create a tarball of the source files and build from there. > > On runing 'meson dist', the utils/run-dist.sh script will create a version.gen > > file in the release tarball with the version string generated from the existing > > utils/gen-version.sh script. > > > > The build system has been updated to check for the presence of this version.gen > > file and read the version string from it. If the file is not present, the > > version string is generated by running utils/gen-version.sh as it currently > > does. > > > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com> > > --- > > meson.build | 30 ++++++++++++++++++++---------- > > src/libcamera/meson.build | 11 +++++------ > > utils/run-dist.sh | 9 +++++++++ > > 3 files changed, 34 insertions(+), 16 deletions(-) > > create mode 100644 utils/run-dist.sh > > > > diff --git a/meson.build b/meson.build > > index a49c484fe64e..f27bfd479a5c 100644 > > --- a/meson.build > > +++ b/meson.build > > @@ -10,20 +10,30 @@ project('libcamera', 'c', 'cpp', > > ], > > license : 'LGPL 2.1+') > > > > -# Generate version information. The libcamera_git_version variable contains the > > -# full version with git patch count and SHA1 (e.g. 1.2.3+211-c94a24f4), while > > -# the libcamera_version variable contains the major.minor.patch (e.g. 1.2.3) > > -# only. If the source tree isn't under git control, or if it matches the last > > -# git version tag, the build metadata (e.g. +211-c94a24f4) is omitted from > > -# libcamera_git_version. > > -libcamera_git_version = run_command('utils/gen-version.sh', > > - meson.build_root()).stdout().strip() > > -if libcamera_git_version == '' > > - libcamera_git_version = meson.project_version() > > +fs_mod = import('fs') > > +if not fs_mod.is_file('version.gen') > > + # Generate version information. The libcamera_git_version variable contains the > > + # the full version with git patch count and SHA1 (e.g. 1.2.3+211-c94a24f4), while > > + # the libcamera_version variable contains the major.minor.patch (e.g. 1.2.3) > > + # only. If the source tree isn't under git control, or if it matches the last > > + # git version tag, the build metadata (e.g. +211-c94a24f4) is omitted from > > + # libcamera_git_version. > > + libcamera_git_version = run_command('utils/gen-version.sh', > > + meson.build_root()).stdout().strip() > > + if libcamera_git_version == '' > > + libcamera_git_version = meson.project_version() > > + endif > > +else > > + # Read the version information from the file generated by the utils/run-dist.sh > > + # script on a 'meson dist' command. > > + libcamera_git_version = run_command(['cat', 'version.gen']).stdout().strip() > > endif > > I've added an if clause here to check for the presence of the version file, but I > could equally leave this as-is and check for the file in gen-version.sh. I don't have > a strong preference either way. I think I'd prefer handling this in gen-version.sh, as it will centralize all the version handling code in a single place. > > libcamera_version = libcamera_git_version.split('+')[0] > > > > +# This script gererates the version.gen file on a 'meson dist' command. > > +meson.add_dist_script('utils/run-dist.sh') > > + > > # Configure the build environment. > > cc = meson.get_compiler('c') > > cxx = meson.get_compiler('cpp') > > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build > > index 243dd3c180eb..360eaf80ecf1 100644 > > --- a/src/libcamera/meson.build > > +++ b/src/libcamera/meson.build > > @@ -93,12 +93,11 @@ endforeach > > > > libcamera_sources += control_sources > > > > -gen_version = meson.source_root() / 'utils' / 'gen-version.sh' > > - > > -version_cpp = vcs_tag(command : [gen_version, meson.build_root()], > > - input : 'version.cpp.in', > > - output : 'version.cpp', > > - fallback : meson.project_version()) > > +version_data = configuration_data() > > +version_data.set('VCS_TAG', libcamera_git_version) > > +version_cpp = configure_file(input : 'version.cpp.in', > > + output : 'version.cpp', > > + configuration : version_data) > > > > libcamera_sources += version_cpp > > > > diff --git a/utils/run-dist.sh b/utils/run-dist.sh > > new file mode 100644 > > index 000000000000..1b2a6348c6bc > > --- /dev/null > > +++ b/utils/run-dist.sh > > @@ -0,0 +1,9 @@ > > +#!/bin/sh > > + > > +# SPDX-License-Identifier: GPL-2.0-or-later > > +# > > +# On a meson dist run, generate the version string and store it in a file. > > +# This will late be picked up by the build system and used in place of running s/late/later/ > > +# the utils/gen-version.sh script again since we may not be running in the > > +# upstream git source tree, and so version information would be lost. A blank line here would be nice. > > +"$MESON_DIST_ROOT"/utils/gen-version.sh > "$MESON_DIST_ROOT"/version.gen Do we need to cd to MESON_SOURCE_ROOT first (or set GIT_DIR), or is there a guarantee that this script will always run from a subdirectory of MESON_SOURCE_ROOT ? To end with some nitpicking, I wonder if there's a standard name for files containing a version number (I initially thought about .version but have no evidence that it would be better than version.gen).
Hi Laurent, Thank you for your feedback. On Wed, 13 Oct 2021 at 11:38, Laurent Pinchart < laurent.pinchart@ideasonboard.com> wrote: > Hi Naush, > > Thank you for the patch. > > On Wed, Oct 13, 2021 at 11:20:53AM +0100, Naushir Patuck wrote: > > On Wed, 13 Oct 2021 at 11:19, Naushir Patuck wrote: > > > When distributions build and package libcamera libraries, they may not > > > necessarily run the build in the upstream source tree. In these cases, > the git > > > SHA1 versioning information will be lost. > > > > > > This change addresses that problem by requiring package managers to run > > > 'meson dist' to create a tarball of the source files and build from > there. > > > On runing 'meson dist', the utils/run-dist.sh script will create a > version.gen > > > file in the release tarball with the version string generated from the > existing > > > utils/gen-version.sh script. > > > > > > The build system has been updated to check for the presence of this > version.gen > > > file and read the version string from it. If the file is not present, > the > > > version string is generated by running utils/gen-version.sh as it > currently > > > does. > > > > > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com> > > > --- > > > meson.build | 30 ++++++++++++++++++++---------- > > > src/libcamera/meson.build | 11 +++++------ > > > utils/run-dist.sh | 9 +++++++++ > > > 3 files changed, 34 insertions(+), 16 deletions(-) > > > create mode 100644 utils/run-dist.sh > > > > > > diff --git a/meson.build b/meson.build > > > index a49c484fe64e..f27bfd479a5c 100644 > > > --- a/meson.build > > > +++ b/meson.build > > > @@ -10,20 +10,30 @@ project('libcamera', 'c', 'cpp', > > > ], > > > license : 'LGPL 2.1+') > > > > > > -# Generate version information. The libcamera_git_version variable > contains the > > > -# full version with git patch count and SHA1 (e.g. > 1.2.3+211-c94a24f4), while > > > -# the libcamera_version variable contains the major.minor.patch (e.g. > 1.2.3) > > > -# only. If the source tree isn't under git control, or if it matches > the last > > > -# git version tag, the build metadata (e.g. +211-c94a24f4) is omitted > from > > > -# libcamera_git_version. > > > -libcamera_git_version = run_command('utils/gen-version.sh', > > > - > meson.build_root()).stdout().strip() > > > -if libcamera_git_version == '' > > > - libcamera_git_version = meson.project_version() > > > +fs_mod = import('fs') > > > +if not fs_mod.is_file('version.gen') > > > + # Generate version information. The libcamera_git_version > variable contains the > > > + # the full version with git patch count and SHA1 (e.g. > 1.2.3+211-c94a24f4), while > > > + # the libcamera_version variable contains the major.minor.patch > (e.g. 1.2.3) > > > + # only. If the source tree isn't under git control, or if it > matches the last > > > + # git version tag, the build metadata (e.g. +211-c94a24f4) is > omitted from > > > + # libcamera_git_version. > > > + libcamera_git_version = run_command('utils/gen-version.sh', > > > + > meson.build_root()).stdout().strip() > > > + if libcamera_git_version == '' > > > + libcamera_git_version = meson.project_version() > > > + endif > > > +else > > > + # Read the version information from the file generated by the > utils/run-dist.sh > > > + # script on a 'meson dist' command. > > > + libcamera_git_version = run_command(['cat', > 'version.gen']).stdout().strip() > > > endif > > > > I've added an if clause here to check for the presence of the version > file, but I > > could equally leave this as-is and check for the file in gen-version.sh. > I don't have > > a strong preference either way. > > I think I'd prefer handling this in gen-version.sh, as it will > centralize all the version handling code in a single place. > Ok, will do. > > > > libcamera_version = libcamera_git_version.split('+')[0] > > > > > > +# This script gererates the version.gen file on a 'meson dist' > command. > > > +meson.add_dist_script('utils/run-dist.sh') > > > + > > > # Configure the build environment. > > > cc = meson.get_compiler('c') > > > cxx = meson.get_compiler('cpp') > > > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build > > > index 243dd3c180eb..360eaf80ecf1 100644 > > > --- a/src/libcamera/meson.build > > > +++ b/src/libcamera/meson.build > > > @@ -93,12 +93,11 @@ endforeach > > > > > > libcamera_sources += control_sources > > > > > > -gen_version = meson.source_root() / 'utils' / 'gen-version.sh' > > > - > > > -version_cpp = vcs_tag(command : [gen_version, meson.build_root()], > > > - input : 'version.cpp.in', > > > - output : 'version.cpp', > > > - fallback : meson.project_version()) > > > +version_data = configuration_data() > > > +version_data.set('VCS_TAG', libcamera_git_version) > > > +version_cpp = configure_file(input : 'version.cpp.in', > > > + output : 'version.cpp', > > > + configuration : version_data) > > > > > > libcamera_sources += version_cpp > > > > > > diff --git a/utils/run-dist.sh b/utils/run-dist.sh > > > new file mode 100644 > > > index 000000000000..1b2a6348c6bc > > > --- /dev/null > > > +++ b/utils/run-dist.sh > > > @@ -0,0 +1,9 @@ > > > +#!/bin/sh > > > + > > > +# SPDX-License-Identifier: GPL-2.0-or-later > > > +# > > > +# On a meson dist run, generate the version string and store it in a > file. > > > +# This will late be picked up by the build system and used in place > of running > > s/late/later/ > > > > +# the utils/gen-version.sh script again since we may not be running > in the > > > +# upstream git source tree, and so version information would be lost. > > A blank line here would be nice. > > > > +"$MESON_DIST_ROOT"/utils/gen-version.sh > > "$MESON_DIST_ROOT"/version.gen > > Do we need to cd to MESON_SOURCE_ROOT first (or set GIT_DIR), or is > there a guarantee that this script will always run from a subdirectory > of MESON_SOURCE_ROOT ? > From what I can tell, meson dist does not seem to allow the user to specify the dist output directory, it creates a 'meson-dist' direcotry under MESON_BUILD_ROOT. I had assumed the latter will will always be a subdirectly of MESON_SOURCE_ROOT, but perhaps that will not always be the case, so I could cd MESON_SOURCE_ROOT to be sure! > > To end with some nitpicking, I wonder if there's a standard name for > files containing a version number (I initially thought about .version > but have no evidence that it would be better than version.gen). > I don't know of any specific standard filename for this. I chose the .gen extension to loosely signify that this was an auto generated file. I can change to .version if you prefer? Regards, Naush > > -- > Regards, > > Laurent Pinchart >