|
| 1 | +#!/usr/bin/env python |
| 2 | +# Copyright (C) 2017 LiveCode Ltd. |
| 3 | +# |
| 4 | +# This file is part of LiveCode. |
| 5 | +# |
| 6 | +# LiveCode is free software; you can redistribute it and/or modify it under |
| 7 | +# the terms of the GNU General Public License v3 as published by the Free |
| 8 | +# Software Foundation. |
| 9 | +# |
| 10 | +# LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 | +# WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | +# for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with LiveCode. If not see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +# This file contains rules used by the LiveCode Buildbot installation |
| 19 | +# at <https://vulcan.livecode.com/> |
| 20 | +# |
| 21 | +# Tasks that may be run on Windows workers must be implemented in this |
| 22 | +# file. Other tasks may be implemented in buildbot.mk, and this |
| 23 | +# script redirects to that Makefile. All buildbot operations should |
| 24 | +# occur via this script, so that buildbot does not invoke |
| 25 | +# platform-specific tools directly. |
| 26 | + |
| 27 | +import sys |
| 28 | +import subprocess |
| 29 | +import os |
| 30 | +import platform as _platform |
| 31 | +import shutil |
| 32 | +import tarfile |
| 33 | + |
| 34 | +# The set of platforms for which this branch supports automated builds |
| 35 | +BUILDBOT_PLATFORMS = ('linux-x86', 'linux-x86_64', 'android-armv6', 'mac', |
| 36 | + 'ios', 'win-x86', 'emscripten') |
| 37 | +# The set of build tasks that this branch supports |
| 38 | +BUILDBOT_TARGETS = ('config', 'compile', 'bin-archive', 'bin-extract', |
| 39 | + 'dist-notes', 'dist-docs', 'dist-server', 'dist-tools', 'dist-upload', |
| 40 | + 'distmac-archive', 'distmac-extract', 'distmac-disk') |
| 41 | + |
| 42 | +SKIP_EXIT_STATUS = 88 |
| 43 | + |
| 44 | +def usage(exit_status): |
| 45 | + print( |
| 46 | +"""Perform continuous integration and release build steps. |
| 47 | +
|
| 48 | +Usage: |
| 49 | + buildbot.py TARGET |
| 50 | +
|
| 51 | +Environment variables: |
| 52 | + BUILD_EDITION LiveCode edition name ("commercial" or "community") |
| 53 | + BUILD_PLATFORM The target platform for build (e.g. "ios") |
| 54 | + BUILD_SUBPLATFORM The target subplatform (e.g. "iphoneos10.2") |
| 55 | +
|
| 56 | +Many tasks are deferred to the "buildbot.mk" Makefile and the |
| 57 | +"config.py" configuration script. Refer to these for other |
| 58 | +environment variables that may affect the build. |
| 59 | +""") |
| 60 | + |
| 61 | + sys.exit(exit_status) |
| 62 | + |
| 63 | +def error(message): |
| 64 | + print("ERROR: " + message) |
| 65 | + sys.exit(1) |
| 66 | + |
| 67 | +def get_build_platform(): |
| 68 | + platform = (os.environ.get('BUILD_PLATFORM'), |
| 69 | + os.environ.get('BUILD_SUBPLATFORM')) |
| 70 | + if platform[0] is None: |
| 71 | + error('You must set $BUILD_PLATFORM') |
| 72 | + return platform |
| 73 | + |
| 74 | +def get_buildtype(): |
| 75 | + return os.environ.get('BUILDTYPE', 'Debug') |
| 76 | + |
| 77 | +def get_build_edition(): |
| 78 | + return os.environ.get('BUILD_EDITION', 'community') |
| 79 | + |
| 80 | +################################################################ |
| 81 | +# Defer to buildbot.mk |
| 82 | +################################################################ |
| 83 | + |
| 84 | +def exec_buildbot_make(target): |
| 85 | + args = ["make", "-f", "buildbot.mk", target] |
| 86 | + print(' '.join(args)) |
| 87 | + sys.exit(subprocess.call(args)) |
| 88 | + |
| 89 | +################################################################ |
| 90 | +# Configure with gyp |
| 91 | +################################################################ |
| 92 | + |
| 93 | +def exec_configure(args): |
| 94 | + import config |
| 95 | + print('config.py ' + ' '.join(args)) |
| 96 | + sys.exit(config.configure(args)) |
| 97 | + |
| 98 | +def do_configure(): |
| 99 | + platform, subplatform = get_build_platform() |
| 100 | + |
| 101 | + if platform == 'ios': |
| 102 | + if subplatform is None: |
| 103 | + error('You must set $BUILD_SUBPLATFORM for iOS builds') |
| 104 | + exec_configure(['--platform', 'ios', |
| 105 | + '--generator-output', |
| 106 | + 'build-{}-{}/livecode'.format(platform, subplatform), |
| 107 | + '-Dtarget_sdk=' + subplatform]) |
| 108 | + else: |
| 109 | + exec_configure(['--platform', platform]) |
| 110 | + return 0 |
| 111 | + |
| 112 | +################################################################ |
| 113 | +# Compile |
| 114 | +################################################################ |
| 115 | + |
| 116 | +def exec_make(target): |
| 117 | + args = ['make', target] |
| 118 | + print(' '.join(args)) |
| 119 | + sys.exit(subprocess.call(args)) |
| 120 | + |
| 121 | +def exec_msbuild(platform): |
| 122 | + # Run the make.cmd batch script; it's run using Wine if this is |
| 123 | + # not actually a Windows system. |
| 124 | + cwd = 'build-' + platform |
| 125 | + |
| 126 | + if _platform.system() == 'Windows': |
| 127 | + args = ['cmd', '/C', '..\\make.cmd'] |
| 128 | + print(' '.join(args)) |
| 129 | + sys.exit(subprocess.call(args, cwd=cwd)) |
| 130 | + |
| 131 | + else: |
| 132 | + args = ['wine', 'cmd', '/K', '..\\make.cmd'] |
| 133 | + print(' '.join(args)) |
| 134 | + exit_status = sys.exit(subprocess.call(args, cwd=cwd)) |
| 135 | + |
| 136 | + # Clean up any Wine processes that are still hanging around. |
| 137 | + # This is important in case the build fails. |
| 138 | + args = ['wineserver', '-k', '-w'] |
| 139 | + subprocess.call(args, cwd=cwd) |
| 140 | + |
| 141 | + sys.exit(exit_status) |
| 142 | + |
| 143 | +def do_compile(): |
| 144 | + platform, subplatform = get_build_platform() |
| 145 | + if platform.startswith('win-'): |
| 146 | + return exec_msbuild(platform) |
| 147 | + else: |
| 148 | + # Just defer to the top level Makefile |
| 149 | + if platform == 'ios': |
| 150 | + if subplatform is None: |
| 151 | + error('You must set $BUILD_SUBPLATFORM for iOS builds') |
| 152 | + target = 'compile-{}-{}'.format(platform, subplatform) |
| 153 | + else: |
| 154 | + target = 'compile-' + platform |
| 155 | + return exec_make(target) |
| 156 | + |
| 157 | +################################################################ |
| 158 | +# Archive / extract built binaries |
| 159 | +################################################################ |
| 160 | + |
| 161 | +def do_bin_archive(): |
| 162 | + platform, subplatform = get_build_platform() |
| 163 | + bindir = platform + '-bin' |
| 164 | + shutil.make_archive(bindir, 'bztar', '.', bindir) |
| 165 | + |
| 166 | +################################################################ |
| 167 | +# Main entry point |
| 168 | +################################################################ |
| 169 | + |
| 170 | +def buildbot_task(target): |
| 171 | + # Check that this branch can actually be built for the specified platform |
| 172 | + platform, subplatform = get_build_platform() |
| 173 | + if not platform in BUILDBOT_PLATFORMS: |
| 174 | + print('Buildbot build for "{}" platform is not supported'.format(platform)) |
| 175 | + sys.exit(SKIP_EXIT_STATUS) |
| 176 | + |
| 177 | + # Check that this branch supports performing the requested buildbot task |
| 178 | + if not target in BUILDBOT_TARGETS: |
| 179 | + print('Buildbot build step "{}" is not supported'.format(target)) |
| 180 | + sys.exit(SKIP_EXIT_STATUS) |
| 181 | + |
| 182 | + if target == 'config': |
| 183 | + return do_configure() |
| 184 | + elif target == 'compile': |
| 185 | + return do_compile() |
| 186 | + elif target == 'bin-archive': |
| 187 | + return do_bin_archive() |
| 188 | + else: |
| 189 | + return exec_buildbot_make(target) |
| 190 | + |
| 191 | +if __name__ == '__main__': |
| 192 | + if len(sys.argv) < 2: |
| 193 | + error("You must specify a buildbot target stage") |
| 194 | + sys.exit(buildbot_task(sys.argv[1])) |
0 commit comments