Welcome to mirror list, hosted at ThFree Co, Russian Federation.

buildbot_utils.py « buildbot « build_files - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e8adf5ba8100b949684d115475225906e4872994 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>

import argparse
import os
import re
import subprocess
import sys

def is_tool(name):
    """Check whether `name` is on PATH and marked as executable."""

    # from whichcraft import which
    from shutil import which

    return which(name) is not None

class Builder:
    def __init__(self, name, branch):
        self.name = name
        self.branch = branch
        self.is_release_branch = re.match("^blender-v(.*)-release$", branch) is not None

        # Buildbot runs from build/ directory
        self.blender_dir = os.path.abspath(os.path.join('..', 'blender.git'))
        self.build_dir = os.path.abspath(os.path.join('..', 'build'))
        self.install_dir = os.path.abspath(os.path.join('..', 'install'))
        self.upload_dir = os.path.abspath(os.path.join('..', 'install'))

        # Detect platform
        if name.startswith('mac'):
            self.platform = 'mac'
            self.command_prefix =  []
        elif name.startswith('linux'):
            self.platform = 'linux'
            if is_tool('scl'):
                self.command_prefix =  ['scl', 'enable', 'devtoolset-9', '--']
            else:
                self.command_prefix =  []
        elif name.startswith('win'):
            self.platform = 'win'
            self.command_prefix =  []
        else:
            raise ValueError('Unkonw platform for builder ' + self.platform)

        # Always 64 bit now
        self.bits = 64

def create_builder_from_arguments():
    parser = argparse.ArgumentParser()
    parser.add_argument('builder_name')
    parser.add_argument('branch', default='master', nargs='?')
    args = parser.parse_args()
    return Builder(args.builder_name, args.branch)


class VersionInfo:
    def __init__(self, builder):
        # Get version information
        buildinfo_h = os.path.join(builder.build_dir, "source", "creator", "buildinfo.h")
        blender_h = os.path.join(builder.blender_dir, "source", "blender", "blenkernel", "BKE_blender_version.h")

        version_number = int(self._parse_header_file(blender_h, 'BLENDER_VERSION'))
        version_number_patch = int(self._parse_header_file(blender_h, 'BLENDER_VERSION_PATCH'))
        version_numbers = (version_number // 100, version_number % 100, version_number_patch)
        self.short_version = "%d.%02d" % (version_numbers[0], version_numbers[1])
        self.version = "%d.%02d.%d" % version_numbers
        self.version_cycle = self._parse_header_file(blender_h, 'BLENDER_VERSION_CYCLE')
        self.version_cycle_number = self._parse_header_file(blender_h, 'BLENDER_VERSION_CYCLE_NUMBER')
        self.hash = self._parse_header_file(buildinfo_h, 'BUILD_HASH')[1:-1]

        if self.version_cycle == "release":
            # Final release
            self.full_version = self.version
            self.is_development_build = False
        elif self.version_cycle == "rc":
            # Release candidate
            version_cycle = self.version_cycle + self.version_cycle_number
            self.full_version = self.version + version_cycle
            self.is_development_build = False
        else:
            # Development build
            self.full_version = self.version + '-' + self.hash
            self.is_development_build = True

    def _parse_header_file(self, filename, define):
        import re
        regex = re.compile("^#\s*define\s+%s\s+(.*)" % define)
        with open(filename, "r") as file:
            for l in file:
                match = regex.match(l)
                if match:
                    return match.group(1)
        return None


def call(cmd, env=None, exit_on_error=True):
    print(' '.join(cmd))

    # Flush to ensure correct order output on Windows.
    sys.stdout.flush()
    sys.stderr.flush()

    retcode = subprocess.call(cmd, env=env)
    if exit_on_error and retcode != 0:
        sys.exit(retcode)
    return retcode