diff options
-rw-r--r-- | .github/workflows/ci_appveyor.yml | 4 | ||||
-rw-r--r-- | .github/workflows/ci_travis.yml | 4 | ||||
-rw-r--r-- | project/ci/boost.py | 9 | ||||
-rw-r--r-- | project/ci/cmake.py | 8 | ||||
-rw-r--r-- | project/ci/dirs.py | 30 |
5 files changed, 40 insertions, 15 deletions
diff --git a/.github/workflows/ci_appveyor.yml b/.github/workflows/ci_appveyor.yml index c9d34a1..80248d0 100644 --- a/.github/workflows/ci_appveyor.yml +++ b/.github/workflows/ci_appveyor.yml @@ -51,10 +51,10 @@ jobs: key: 'boost-${{ env.boost_version }}' - name: Build Boost - run: python -m project.ci.boost -- --with-filesystem + run: python -m project.ci.boost --hint AppVeyor -- --with-filesystem - name: Build example project - run: python -m project.ci.cmake --install + run: python -m project.ci.cmake --hint AppVeyor --install - name: Run example project run: | diff --git a/.github/workflows/ci_travis.yml b/.github/workflows/ci_travis.yml index d3e8bf3..3dc1da5 100644 --- a/.github/workflows/ci_travis.yml +++ b/.github/workflows/ci_travis.yml @@ -49,10 +49,10 @@ jobs: key: 'boost-${{ env.boost_version }}' - name: Build Boost - run: python -m project.ci.boost -- --with-filesystem + run: python -m project.ci.boost --hint Travis -- --with-filesystem - name: Build example project - run: python -m project.ci.cmake --install + run: python -m project.ci.cmake --hint Travis --install - name: Run example project run: | diff --git a/project/ci/boost.py b/project/ci/boost.py index 1b47710..b1bf8de 100644 --- a/project/ci/boost.py +++ b/project/ci/boost.py @@ -29,6 +29,13 @@ def _parse_args(argv=None): type=Linkage.parse, help='how the libraries link to the runtime') + # 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. + parser.add_argument('--hint', metavar='CI_NAME', + choices=Dirs.all_ci_names(), + help='CI system to use') + parser.add_argument('b2_args', metavar='B2_ARG', nargs='*', default=[], help='additional b2 arguments, to be passed verbatim') @@ -40,7 +47,7 @@ def build_ci(dirs, argv=None): args = _parse_args(argv) with setup_logging(): if dirs is None: - dirs = Dirs.detect() + dirs = Dirs.detect(args.hint) version = dirs.get_boost_version() build_dir = dirs.get_build_dir() diff --git a/project/ci/cmake.py b/project/ci/cmake.py index 83a80e8..1694a5e 100644 --- a/project/ci/cmake.py +++ b/project/ci/cmake.py @@ -21,6 +21,12 @@ def _parse_args(argv=None): description=Dirs.get_cmake_help(), formatter_class=argparse.RawDescriptionHelpFormatter) + # 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. + parser.add_argument('--hint', metavar='CI_NAME', + choices=Dirs.all_ci_names(), + help='CI system to use') parser.add_argument('--install', action='store_true', help='install the project') parser.add_argument('--boost', metavar='DIR', dest='boost_dir', @@ -36,7 +42,7 @@ def build_ci(dirs, argv=None): args = _parse_args(argv) with setup_logging(): if dirs is None: - dirs = Dirs.detect() + dirs = Dirs.detect(args.hint) src_dir = dirs.get_src_dir() if args.subdir: diff --git a/project/ci/dirs.py b/project/ci/dirs.py index f1b1c57..60fbdf8 100644 --- a/project/ci/dirs.py +++ b/project/ci/dirs.py @@ -17,14 +17,20 @@ from project.utils import env class Dirs(abc.ABC): @staticmethod - def detect(): + def detect(hint=None): matching = [ci for ci in _ALL_CI_LIST if ci.this_one()] if len(matching) == 0: raise RuntimeError('no CI system was detected') - if len(matching) > 1: - names = ', '.join(ci.get_name() for ci in matching) - raise RuntimeError(f"can't select a single CI system out of these: {names}") - return matching[0] + if len(matching) == 1: + return matching[0] + # The hint parameter is basically a workaround for when this is run + # on a CI, _but_ testing another CI is desired. + if hint is not None: + for ci in matching: + if ci.get_name() == hint: + return ci + names = ', '.join(ci.get_name() for ci in matching) + raise RuntimeError(f"can't select a single CI system out of these: {names}") def __init__(self): pass @@ -77,25 +83,31 @@ class Dirs(abc.ABC): pass @staticmethod + def all_ci_names(): + return [ci.get_name() for ci in _ALL_CI_LIST] + + @staticmethod + def join_ci_names(): + return ', '.join(Dirs.all_ci_names()) + + @staticmethod def get_boost_help(): - names = ', '.join(ci.get_name() for ci in _ALL_CI_LIST) return f'''Download & build Boost during a CI run. This is similar to running both project.boost.download & project.boost.build, but auto-fills some parameters from environment variables. -The supported CI systems are: {names}. +The supported CI systems are: {Dirs.join_ci_names()}. ''' @staticmethod def get_cmake_help(): - names = ', '.join(ci.get_name() for ci in _ALL_CI_LIST) return f'''Build a CMake project during a CI run. This is similar to running project.cmake.build, but auto-fills some parameters from environment variables. -The supported CI systems are: {names}. +The supported CI systems are: {Dirs.join_ci_names()}. ''' |