From bc3c7c7190c5acaeb03ef82dc41cc716aaff76c6 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 2 Mar 2023 22:56:06 +0100 Subject: add runtime version information --- .github/workflows/basic.yml | 17 ++++++++++++++--- project/boost/build.py | 3 +++ project/boost/download.py | 3 +++ project/ci/boost.py | 3 +++ project/ci/cmake.py | 3 +++ project/cmake/build.py | 3 +++ project/version.py | 15 +++++++++++++++ pyproject.toml | 10 ++++++++-- 8 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 project/version.py diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index c5cbeb0..7621e52 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -72,6 +72,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v4 with: @@ -81,14 +83,21 @@ jobs: with: path: boost_*.tar.gz key: 'boost_${{ matrix.boost-version }}' + - name: 'Install package & dependencies' + run: pip install -q -e . + - name: Check that scripts are runnable + run: | + boost-download --version + boost-build --version + cmake-build --version - name: Build Boost run: | - python -m project.boost.download --cache . '${{ matrix.boost-version }}' boost - python -m project.boost.build -- boost --with-filesystem + boost-download --cache . '${{ matrix.boost-version }}' boost + boost-build -- boost --with-filesystem - name: Build example project run: | $src_dir = Join-Path examples boost - python -m project.cmake.build --boost boost --install install -- $src_dir + cmake-build --boost boost --install install -- $src_dir - name: Run example project run: ./.ci/run_foo.ps1 (Join-Path (Get-Location).Path install bin foo) @@ -101,6 +110,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v4 with: diff --git a/project/boost/build.py b/project/boost/build.py index fd73b6e..bd4fd6b 100644 --- a/project/boost/build.py +++ b/project/boost/build.py @@ -37,6 +37,7 @@ from project.os import on_linux_like from project.platform import Platform from project.toolset import Toolset, ToolsetVersion from project.utils import normalize_path, setup_logging +import project.version DEFAULT_PLATFORMS = (Platform.AUTO,) @@ -150,6 +151,8 @@ def _parse_args(argv=None): description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + project.version.add_to_arg_parser(parser) + platform_options = '/'.join(map(str, Platform.all())) configuration_options = '/'.join(map(str, Configuration.all())) # These are used to put the built libraries into proper stage/ diff --git a/project/boost/download.py b/project/boost/download.py index 3f1366e..b5bf684 100644 --- a/project/boost/download.py +++ b/project/boost/download.py @@ -27,6 +27,7 @@ import urllib.request from project.boost.archive import Archive, PermanentStorage, TemporaryStorage from project.boost.version import Version from project.utils import normalize_path, mkdir_parent, retry, setup_logging +import project.version class Download: @@ -127,6 +128,8 @@ def _parse_args(argv=None): description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + project.version.add_to_arg_parser(parser) + parser.add_argument('--unpack', metavar='DIR', dest='unpack_dir', type=normalize_path, help='directory to unpack the archive to') diff --git a/project/ci/boost.py b/project/ci/boost.py index 0d89b75..65f4da0 100644 --- a/project/ci/boost.py +++ b/project/ci/boost.py @@ -11,6 +11,7 @@ from project.boost.download import Download, download from project.ci.dirs import Dirs from project.linkage import Linkage from project.utils import setup_logging +import project.version def _parse_args(argv=None): @@ -21,6 +22,8 @@ def _parse_args(argv=None): description=Dirs.get_boost_help(), formatter_class=argparse.RawDescriptionHelpFormatter) + project.version.add_to_arg_parser(parser) + parser.add_argument('--link', metavar='LINKAGE', nargs='*', type=Linkage.parse, help='how the libraries are linked') diff --git a/project/ci/cmake.py b/project/ci/cmake.py index 1f49f78..13929f7 100644 --- a/project/ci/cmake.py +++ b/project/ci/cmake.py @@ -10,6 +10,7 @@ import sys from project.ci.dirs import Dirs from project.cmake.build import BuildParameters, build from project.utils import setup_logging +import project.version def _parse_args(argv=None): @@ -20,6 +21,8 @@ def _parse_args(argv=None): description=Dirs.get_cmake_help(), formatter_class=argparse.RawDescriptionHelpFormatter) + project.version.add_to_arg_parser(parser) + # The hint parameter is basically a workaround for when this is run on a # CI, _but_ testing another CI is desired. This shouldn't be used in a # real CI workflow. diff --git a/project/cmake/build.py b/project/cmake/build.py index 3c4853d..9c98ba3 100644 --- a/project/cmake/build.py +++ b/project/cmake/build.py @@ -30,6 +30,7 @@ from project.configuration import Configuration from project.platform import Platform from project.toolset import Toolset, ToolsetVersion from project.utils import normalize_path, mkdir_parent, run, setup_logging +import project.version DEFAULT_PLATFORM = Platform.AUTO @@ -211,6 +212,8 @@ def _parse_args(argv=None): description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + project.version.add_to_arg_parser(parser) + parser.add_argument('--build', metavar='DIR', dest='build_dir', type=normalize_path, help='build directory (temporary directory unless specified)') diff --git a/project/version.py b/project/version.py new file mode 100644 index 0000000..8cff333 --- /dev/null +++ b/project/version.py @@ -0,0 +1,15 @@ +try: + import importlib.metadata as metadata +except ImportError: + import importlib_metadata as metadata + + +try: + __version__ = metadata.version('cmake_common') +except Exception: + __version__ = 'unknown' + + +def add_to_arg_parser(parser): + parser.add_argument('--version', '-V', action='version', + version=f'%(prog)s {__version__}') diff --git a/pyproject.toml b/pyproject.toml index f1052b4..6ee788c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,16 +1,20 @@ [build-system] -requires = ["setuptools>=61.0"] +requires = ["setuptools>=61.0", "setuptools-scm"] build-backend = "setuptools.build_meta" [project] name = "cmake_common" description = "Utilities to help develop C++/CMake projects" license = {text = "MIT"} -version = "3.4.1" +dynamic = ["version"] authors = [{name = "Egor Tensin", email = "Egor.Tensin@gmail.com"}] readme = "README.md" requires-python = ">=3.6" +dependencies = [ + 'importlib-metadata ~= 4.0 ; python_version < "3.8"', +] + classifiers = [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", @@ -38,3 +42,5 @@ script-files = [ [tool.setuptools.data-files] "share/cmake" = ["common.cmake"] + +[tool.setuptools_scm] -- cgit v1.2.3