diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-03 20:41:10 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-03 21:26:12 +0200 |
commit | b3c440a0e582b58bdfd984041e031cf061690648 (patch) | |
tree | 2ce44a3022f912213d5ddbbf9e1117b8b2b49f9b | |
parent | fix PyLint warnings (diff) | |
download | cmake-common-b3c440a0e582b58bdfd984041e031cf061690648.tar.gz cmake-common-b3c440a0e582b58bdfd984041e031cf061690648.zip |
project.cmake: require the build dir argument
It doesn't make a lot of sense for the build dir argument to be
optional. There's still a placeholder you can use to build in a
temporary directory.
Diffstat (limited to '')
-rw-r--r-- | .github/actions/build-example/action.yml | 2 | ||||
-rw-r--r-- | .github/workflows/basic.yml | 12 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | docs/ci.md | 3 | ||||
-rw-r--r-- | project/cmake/build.py | 28 |
5 files changed, 26 insertions, 21 deletions
diff --git a/.github/actions/build-example/action.yml b/.github/actions/build-example/action.yml index 60ca2e8..ba7b43f 100644 --- a/.github/actions/build-example/action.yml +++ b/.github/actions/build-example/action.yml @@ -63,7 +63,7 @@ runs: $args += '--boost',$boost_dir } - $args += '--',$src_dir + $args += '--',$src_dir,'TMP' $env:VERBOSE = 1 & $python -m project.cmake.build $args shell: pwsh diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index 1b0f42a..d5db93d 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -48,12 +48,12 @@ jobs: key: 'boost_${{ matrix.boost-version }}' - name: Build Boost run: | - python -m project.boost.download --cache . '${{ matrix.boost-version }}' boost - python -m project.boost.build -- boost --with-filesystem + python -m project.boost.download --cache . '${{ matrix.boost-version }}' boost/ + python -m project.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 + python -m project.cmake.build --boost boost/ --install install/ -- $src_dir build/ - name: Run example project run: ./.ci/run_foo.ps1 (Join-Path (Get-Location).Path install bin foo) @@ -93,12 +93,12 @@ jobs: cmake-build --version - name: Build Boost run: | - boost-download --cache . '${{ matrix.boost-version }}' boost - 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 - cmake-build --boost boost --install install -- $src_dir + cmake-build --boost boost/ --install install/ -- $src_dir build/ - name: Run example project run: ./.ci/run_foo.ps1 (Join-Path (Get-Location).Path install bin foo) @@ -78,7 +78,7 @@ Pass the `--help` flag to view detailed usage information. Build (and optionally, install) a CMake project. - $ cmake-build --configuration Release --install path/to/somewhere --boost path/to/boost -- examples/simple + $ cmake-build --configuration Release --install path/to/somewhere --boost path/to/boost -- examples/simple build/ ... $ ./path/to/somewhere/bin/foo @@ -44,7 +44,8 @@ for configuration in Debug Release; do --build "$TRAVIS_BUILD_DIR/../build/cmake" \ --install "$TRAVIS_BUILD_DIR/../build/install" \ -- \ - "$TRAVIS_BUILD_DIR" + "$TRAVIS_BUILD_DIR" \ + TMP done ``` diff --git a/project/cmake/build.py b/project/cmake/build.py index 9c98ba3..ef4de1a 100644 --- a/project/cmake/build.py +++ b/project/cmake/build.py @@ -12,7 +12,7 @@ but written in bash and PowerShell, respectively). A simple usage example: - $ cmake-build --configuration Release --install path/to/somewhere -- examples/simple + $ cmake-build --configuration Release --install path/to/somewhere -- examples/simple build/ ... $ ./path/to/somewhere/bin/foo @@ -136,13 +136,14 @@ class BuildPhase: class BuildParameters: - def __init__(self, src_dir, build_dir=None, install_dir=None, + BUILD_DIR_TMP_PLACEHOLDER = 'TMP' + + def __init__(self, src_dir, build_dir, install_dir=None, platform=None, configuration=None, boost_dir=None, toolset_version=None, cmake_args=None): src_dir = normalize_path(src_dir) - if build_dir is not None: - build_dir = normalize_path(build_dir) + build_dir = self.normalize_build_dir(build_dir) if install_dir is not None: install_dir = normalize_path(install_dir) platform = platform or DEFAULT_PLATFORM @@ -167,9 +168,15 @@ class BuildParameters: args.pop('help_toolsets', None) return BuildParameters(**args) + @staticmethod + def normalize_build_dir(build_dir): + if build_dir == BuildParameters.BUILD_DIR_TMP_PLACEHOLDER: + return build_dir + return normalize_path(build_dir) + @contextmanager def create_build_dir(self): - if self.build_dir is not None: + if self.build_dir != BuildParameters.BUILD_DIR_TMP_PLACEHOLDER: logging.info('Build directory: %s', self.build_dir) mkdir_parent(self.build_dir) yield self.build_dir @@ -214,9 +221,6 @@ def _parse_args(argv=None): 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)') parser.add_argument('--install', metavar='DIR', dest='install_dir', type=normalize_path, help='install directory') @@ -241,11 +245,11 @@ def _parse_args(argv=None): parser.add_argument('--help-toolsets', action='store_true', help='show detailed info about supported toolsets') - parser.add_argument('src_dir', metavar='DIR', - type=normalize_path, + parser.add_argument('src_dir', type=normalize_path, help='source directory') - parser.add_argument('cmake_args', metavar='CMAKE_ARG', - nargs='*', default=[], + parser.add_argument('build_dir', type=BuildParameters.normalize_build_dir, + help=f"build directory ('{BuildParameters.BUILD_DIR_TMP_PLACEHOLDER}' to use a temporary directory)") + parser.add_argument('cmake_args', nargs='*', default=[], help='additional CMake arguments, to be passed verbatim') return parser.parse_args(argv) |