aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/project/ci/dirs.py
blob: 9234df2ca80bb32d6ce58e726a2e7b8a4e62fb43 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 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.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.utils import env


class Dirs(abc.ABC):
    def __init__(self):
        pass

    @abc.abstractmethod
    def get_platform(self):
        pass

    @abc.abstractmethod
    def get_configuration(self):
        pass

    @abc.abstractmethod
    def get_src_dir(self):
        pass

    @abc.abstractmethod
    def get_build_dir(self):
        pass

    def get_boost_version(self):
        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(), 'build')

    @abc.abstractmethod
    def get_cmake_args(self):
        pass

    def get_boost_help(self):
        return f'''Download & build Boost on Travis/AppVeyor.

This is similar to running both project.boost.download & project.boost.build,
but auto-fills some parameters from environment variables.

Boost is built in {self.get_boost_dir()}.
'''

    def get_cmake_help(self):
        return f'''Build a CMake project on AppVeyor.

This is similar to running project.cmake.build, but auto-fills some parameters
from environment variables.

The project is built in {self.get_cmake_dir()}.
'''


class Travis(Dirs):
    def get_platform(self):
        return Platform.parse(env('platform'))

    def get_configuration(self):
        return Configuration.parse(env('configuration'))

    def get_src_dir(self):
        return env('TRAVIS_BUILD_DIR')

    def get_build_dir(self):
        return env('HOME')

    def get_cmake_args(self):
        return []


class AppVeyor(Dirs):
    def get_platform(self):
        return Platform.parse(env('PLATFORM'))

    def get_configuration(self):
        return Configuration.parse(env('CONFIGURATION'))

    def get_src_dir(self):
        return env('APPVEYOR_BUILD_FOLDER')

    def get_build_dir(self):
        return R'C:\projects'

    def get_cmake_args(self):
        return ['-G', str(Generator.from_image(Image.get()))]