diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-03 22:31:15 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-03 22:32:44 +0200 |
commit | be0b69971a4d8447d86f77b3d09b3820e8c9cb67 (patch) | |
tree | da1e2075e9145186f92e28fea6061802d0842fca /project/ci | |
parent | project.ci.cmake -> project.ci.build (diff) | |
download | cmake-common-be0b69971a4d8447d86f77b3d09b3820e8c9cb67.tar.gz cmake-common-be0b69971a4d8447d86f77b3d09b3820e8c9cb67.zip |
remove project.ci
The weird magic going on in the ci-{boost,build} scripts is honestly too
weird. With hindsight, it seems to me that it's much better to just
build a project with the same command during a CI run as when developing
locally.
Plus, I haven't really used either Travis or AppVeyor in quite some
time, so this code was mostly untested really.
Diffstat (limited to 'project/ci')
-rw-r--r-- | project/ci/__init__.py | 0 | ||||
-rw-r--r-- | project/ci/appveyor/__init__.py | 0 | ||||
-rw-r--r-- | project/ci/appveyor/generator.py | 64 | ||||
-rw-r--r-- | project/ci/boost.py | 75 | ||||
-rw-r--r-- | project/ci/build.py | 79 | ||||
-rw-r--r-- | project/ci/dirs.py | 176 |
6 files changed, 0 insertions, 394 deletions
diff --git a/project/ci/__init__.py b/project/ci/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/project/ci/__init__.py +++ /dev/null diff --git a/project/ci/appveyor/__init__.py b/project/ci/appveyor/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/project/ci/appveyor/__init__.py +++ /dev/null diff --git a/project/ci/appveyor/generator.py b/project/ci/appveyor/generator.py deleted file mode 100644 index 454bd4a..0000000 --- a/project/ci/appveyor/generator.py +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com> -# This file is part of the "cmake-common" project. -# For details, see https://github.com/egor-tensin/cmake-common. -# Distributed under the MIT License. - -from enum import Enum - -from project.utils import env - - -class Image(Enum): - VS_2013 = 'Visual Studio 2013' - VS_2015 = 'Visual Studio 2015' - VS_2017 = 'Visual Studio 2017' - VS_2019 = 'Visual Studio 2019' - - def __str__(self): - return str(self.value) - - @staticmethod - def parse(s): - try: - return Image(s) - except ValueError as e: - raise ValueError(f'unsupported AppVeyor image: {s}') from e - - @staticmethod - def get(): - return Image.parse(env('APPVEYOR_BUILD_WORKER_IMAGE')) - - def get_prebuilt_boost_dir(self): - # As of 2021-01-25, these are the latest pre-built Boost distributions: - # https://www.appveyor.com/docs/windows-images-software/#boost - if self is Image.VS_2013: - return 'C:\\Libraries\\boost_1_58_0' - if self is Image.VS_2015: - return 'C:\\Libraries\\boost_1_69_0' - if self is Image.VS_2017: - return 'C:\\Libraries\\boost_1_69_0' - if self is Image.VS_2019: - return 'C:\\Libraries\\boost_1_73_0' - raise NotImplementedError(f'unsupported AppVeyor image: {self}') - - -class Generator(Enum): - VS_2013 = 'Visual Studio 12 2013' - VS_2015 = 'Visual Studio 14 2015' - VS_2017 = 'Visual Studio 15 2017' - VS_2019 = 'Visual Studio 16 2019' - - def __str__(self): - return str(self.value) - - @staticmethod - def from_image(image): - if image is Image.VS_2013: - return Generator.VS_2013 - if image is Image.VS_2015: - return Generator.VS_2015 - if image is Image.VS_2017: - return Generator.VS_2017 - if image is Image.VS_2019: - return Generator.VS_2019 - raise RuntimeError(f"don't know which generator to use for image: {image}") diff --git a/project/ci/boost.py b/project/ci/boost.py deleted file mode 100644 index 65f4da0..0000000 --- a/project/ci/boost.py +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com> -# This file is part of the "cmake-common" project. -# For details, see https://github.com/egor-tensin/cmake-common. -# Distributed under the MIT License. - -import argparse -import sys - -from project.boost.build import BuildParameters, build -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): - if argv is None: - argv = sys.argv[1:] - - parser = argparse.ArgumentParser( - 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') - parser.add_argument('--runtime-link', metavar='LINKAGE', - 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=argparse.SUPPRESS) - - parser.add_argument('b2_args', metavar='B2_ARG', - nargs='*', default=[], - help='additional b2 arguments, to be passed verbatim') - - return parser.parse_args(argv) - - -def build_ci(dirs, argv=None): - args = _parse_args(argv) - with setup_logging(): - if dirs is None: - dirs = Dirs.detect(args.hint) - - version = dirs.get_boost_version() - build_dir = dirs.get_build_dir() - boost_dir = dirs.get_boost_dir() - params = Download(version, cache_dir=build_dir, dest_path=boost_dir) - download(params) - - params = BuildParameters(boost_dir, - platforms=(dirs.get_platform(),), - configurations=(dirs.get_configuration(),), - link=args.link, - runtime_link=args.runtime_link, - toolset_version=dirs.get_toolset(), - b2_args=args.b2_args) - build(params) - - -def main(argv=None): - build_ci(None, argv) - - -if __name__ == '__main__': - main() diff --git a/project/ci/build.py b/project/ci/build.py deleted file mode 100644 index 24fe34c..0000000 --- a/project/ci/build.py +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com> -# This file is part of the "cmake-common" project. -# For details, see https://github.com/egor-tensin/cmake-common. -# Distributed under the MIT License. - -import argparse -import os.path -import sys - -from project.ci.dirs import Dirs -from project.build import BuildParameters, build -from project.utils import setup_logging -import project.version - - -def _parse_args(argv=None): - if argv is None: - argv = sys.argv[1:] - - parser = argparse.ArgumentParser( - 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. - parser.add_argument('--hint', metavar='CI_NAME', - choices=Dirs.all_ci_names(), - help=argparse.SUPPRESS) - parser.add_argument('--install', action='store_true', - help='install the project') - parser.add_argument('--boost', metavar='DIR', dest='boost_dir', - help='set Boost directory path') - parser.add_argument('--subdir', metavar='DIR', - help='relative project directory path') - parser.add_argument('cmake_args', nargs='*', metavar='CMAKE_ARG', default=[], - help='additional CMake arguments, to be passed verbatim') - return parser.parse_args(argv) - - -def build_ci(dirs, argv=None): - args = _parse_args(argv) - with setup_logging(): - if dirs is None: - dirs = Dirs.detect(args.hint) - - src_dir = dirs.get_src_dir() - if args.subdir: - src_dir = os.path.join(src_dir, args.subdir) - install_dir = dirs.get_install_dir() if args.install else None - - boost_dir = args.boost_dir - if not boost_dir: - # If we've built Boost using project.ci.boost already, use that. - # Otherwise, try to use the latest pre-built Boost provided by the CI - # system. - boost_dir = dirs.get_boost_dir() - if not os.path.isdir(boost_dir): - boost_dir = dirs.get_prebuilt_boost_dir() - - params = BuildParameters(src_dir, - build_dir=dirs.get_cmake_dir(), - install_dir=install_dir, - platform=dirs.get_platform(), - configuration=dirs.get_configuration(), - boost_dir=boost_dir, - toolset_version=dirs.get_toolset(), - cmake_args=dirs.get_cmake_args() + args.cmake_args) - build(params) - - -def main(argv=None): - build_ci(None, argv) - - -if __name__ == '__main__': - main() diff --git a/project/ci/dirs.py b/project/ci/dirs.py deleted file mode 100644 index 6de9509..0000000 --- a/project/ci/dirs.py +++ /dev/null @@ -1,176 +0,0 @@ -# Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com> -# This file is part of the "cmake-common" project. -# For details, see https://github.com/egor-tensin/cmake-common. -# Distributed under the MIT License. - -import abc -import os -import os.path - -from project.boost.version import Version -from project.ci.appveyor.generator import Generator, Image -from project.configuration import Configuration -from project.platform import Platform -from project.toolset import ToolsetVersion -from project.utils import env - - -class Dirs(abc.ABC): - @staticmethod - 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: - 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 - - @staticmethod - @abc.abstractmethod - def get_name(): - pass - - @abc.abstractmethod - def this_one(self): - pass - - @staticmethod - def get_toolset(): - if 'TOOLSET' in os.environ: - return ToolsetVersion.parse(os.environ['TOOLSET']) - return None - - @staticmethod - def get_platform(): - return Platform.parse(env('PLATFORM')) - - @staticmethod - def get_configuration(): - return Configuration.parse(env('CONFIGURATION')) - - @abc.abstractmethod - def get_src_dir(self): - pass - - def get_build_dir(self): - return os.path.join(os.path.dirname(self.get_src_dir()), 'build') - - @abc.abstractmethod - def get_prebuilt_boost_dir(self): - pass - - @staticmethod - def get_boost_version(): - return Version.from_string(env('BOOST_VERSION')) - - def get_boost_dir(self): - return os.path.join(self.get_build_dir(), 'boost') - - def get_cmake_dir(self): - return os.path.join(self.get_build_dir(), 'cmake') - - def get_install_dir(self): - return os.path.join(self.get_build_dir(), 'install') - - @abc.abstractmethod - def get_cmake_args(self): - 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(): - 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: {Dirs.join_ci_names()}. -''' - - @staticmethod - def get_cmake_help(): - return f'''Build a CMake project during a CI run. - -This is similar to running project.build, but auto-fills some parameters -from environment variables. - -The supported CI systems are: {Dirs.join_ci_names()}. -''' - - -class Travis(Dirs): - @staticmethod - def get_name(): - return 'Travis' - - def this_one(self): - return 'TRAVIS' in os.environ - - def get_src_dir(self): - return env('TRAVIS_BUILD_DIR') - - def get_prebuilt_boost_dir(self): - # Travis doesn't have pre-built Boost (available for installation from - # the official Ubuntu repositories though). - return None - - def get_cmake_args(self): - return [] - - -class AppVeyor(Dirs): - @staticmethod - def get_name(): - return 'AppVeyor' - - def this_one(self): - return 'APPVEYOR' in os.environ - - def get_src_dir(self): - return env('APPVEYOR_BUILD_FOLDER') - - def get_prebuilt_boost_dir(self): - return Image.get().get_prebuilt_boost_dir() - - def get_cmake_args(self): - return ['-G', str(Generator.from_image(Image.get()))] - - -class GitHub(Dirs): - @staticmethod - def get_name(): - return 'GitHub Actions' - - def this_one(self): - return 'GITHUB_ACTIONS' in os.environ - - def get_src_dir(self): - return env('GITHUB_WORKSPACE') - - def get_prebuilt_boost_dir(self): - # Used to have 1.72.0 pre-built binaries, but not anymore: - # https://github.com/actions/virtual-environments/issues/2667 - return None - - def get_cmake_args(self): - return [] - - -_ALL_CI_LIST = (Travis(), AppVeyor(), GitHub()) |