diff options
author | Erwin Jansen <jansene@google.com> | 2018-12-17 11:37:11 -0800 |
---|---|---|
committer | Erwin Jansen <jansene@google.com> | 2018-12-19 14:33:00 -0800 |
commit | d86c17b4f47804ed7ccc9be359f04ef7e8268f05 (patch) | |
tree | 3b061fa940c76d84f82ccb68d29abc19bea76a3e | |
parent | 065591efd65e005914424d1b8437025d4d023691 (diff) | |
download | buildSrc-d86c17b4f47804ed7ccc9be359f04ef7e8268f05.tar.gz |
Enable build scripts to be launched under python.
This will enable compilation on all platforms (Win/Lin/Darwin).
Newer GCE based build bots will now be able to target windows-msvc.
Windows based build bots should be able to launch the python build
script.
Change-Id: I5b8507abc1d80b87f6279845e16146a092f2c831
-rwxr-xr-x | servers/build.py | 147 | ||||
-rwxr-xr-x | servers/build_tools.sh | 21 | ||||
-rw-r--r-- | src/main/groovy/com/android/tools/internal/emulator/BuildEmulator.groovy | 27 |
3 files changed, 170 insertions, 25 deletions
diff --git a/servers/build.py b/servers/build.py new file mode 100755 index 0000000..4634468 --- /dev/null +++ b/servers/build.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python +# +# Copyright 2018 - The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the', help="License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an', help="AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import logging +import argparse +import os +import platform +import sys +import subprocess + +from enum import Enum +from Queue import Queue +from threading import Thread + + +AOSP_ROOT = os.path.abspath(os.path.join( + os.path.dirname(os.path.realpath(__file__)), '..', '..', '..')) +TOOLS = os.path.join(AOSP_ROOT, 'tools') + + +def _reader(pipe, queue): + try: + with pipe: + for line in iter(pipe.readline, b''): + queue.put((pipe, line[:-1])) + finally: + queue.put(None) + + +def log_std_out(proc): + """Logs the output of the given process.""" + q = Queue() + Thread(target=_reader, args=[proc.stdout, q]).start() + Thread(target=_reader, args=[proc.stderr, q]).start() + for _ in range(2): + for _, line in iter(q.get, None): + logging.info(line) + + +def run(cmd, env): + logging.info(' '.join(cmd)) + cmd_env = os.environ.copy() + cmd_env.update(env) + + proc = subprocess.Popen( + cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=cmd_env) + + log_std_out(proc) + proc.wait() + if proc.returncode != 0: + raise Exception('Failed to run %s - %s' % + (' '.join(cmd), proc.returncode)) + + +class Target(Enum): + """Supported targets.""" + windows = 'Windows' + darwin = 'Darwin' + linux = 'Linux' + mingw = 'Mingw' + + def __str__(self): + return self.name + + +def install_deps(): + run(['python', os.path.join(AOSP_ROOT, 'external', 'qemu', 'android', + 'build', 'python', 'setup.py'), 'develop', '--user'], {}) + + +def main(argv): + logging.basicConfig(format='%(message)s', level=logging.INFO) + parser = argparse.ArgumentParser( + description='Configures the android emulator cmake project so it can be build') + parser.add_argument("--out_dir", type=str, required=True, + help="The ouput directory") + parser.add_argument("--dist_dir", type=str, required=True, + help="The destination directory") + parser.add_argument("--build-id", type=str, default=[], required=True, + dest='build_id', help="The emulator build number") + parser.add_argument("--target", type=Target, default=platform.system(), + help="The build target, defaults to current os") + + args = parser.parse_args() + logging.info("Building on %s - %s", platform.system(), platform.uname()) + + ext = '' + if platform.system() == 'Windows': + ext = '.bat' + + + mingw = False + sdk = 'makeSdk' + if args.target == Target.windows: + sdk = 'makeWinSdk' + + if args.target == Target.mingw: + sdk = 'makeWinSdk' + mingw = True + + + + if not os.path.isabs(args.out_dir): + args.out_dir = os.path.join(AOSP_ROOT, args.out_dir) + + env = { + "OUT_DIR": args.out_dir, + "DIST_DIR": args.dist_dir, + "BUILD_NUMBER": args.build_id, + "MINGW" : "%s" % mingw + } + + gradle = os.path.join(TOOLS, 'gradlew%s' % ext) + build_gradle = os.path.join(TOOLS, 'build.gradle') + + # Make sure we have all the build dependencies + install_deps() + + + logging.info("Preparing gradle.") + run([gradle, '-b', build_gradle, '--no-daemon', '--info', 'publishLocal'], env) + + logging.info("Starting actual build.") + run([gradle, '-b', build_gradle, '--no-daemon', '--info', 'dist', sdk], env) + + +if __name__ == '__main__': + main(sys.argv) diff --git a/servers/build_tools.sh b/servers/build_tools.sh index f066d33..c2267ad 100755 --- a/servers/build_tools.sh +++ b/servers/build_tools.sh @@ -42,17 +42,12 @@ then popd fi -TARGET="dist makeSdk" -if [[ $CURRENT_OS == "linux" ]]; then - TARGET="$TARGET makeWinSdk" -fi - -cd "$PROG_DIR" +# Of course we are running on build bots that have old.. old.. stuff on them. +# So let's make sure we have enums available. +pip install enum34 --user +python $PROG_DIR/build.py --out_dir $OUT_DIR --dist_dir $DIST_DIR --build-id $BNUM -GRADLE_FLAGS="--no-daemon --info" - -( set -x ; OUT_DIR="$OUT_DIR" DIST_DIR="$DIST_DIR" BUILD_NUMBER="$BNUM" ../../gradlew -b ../../build.gradle $GRADLE_FLAGS publishLocal ) || exit $? - -# temp disable --parallel builds -#OUT_DIR="$OUT_DIR" DIST_DIR="$DIST_DIR" ../../gradlew -b ../../build.gradle --parallel-threads="${NUM_THREADS:-47}" $GRADLE_FLAGS makeSdk -( set -x ; OUT_DIR="$OUT_DIR" DIST_DIR="$DIST_DIR" BUILD_NUMBER="$BNUM" ../../gradlew -b ../../build.gradle $GRADLE_FLAGS $TARGET ) || exit $? +if [[ $CURRENT_OS == "linux" ]]; then + # Let's also build mingw. + python $PROG_DIR/build.py --out_dir $OUT_DIR --dist_dir $DIST_DIR --build-id $BNUM --target Mingw +fi
\ No newline at end of file diff --git a/src/main/groovy/com/android/tools/internal/emulator/BuildEmulator.groovy b/src/main/groovy/com/android/tools/internal/emulator/BuildEmulator.groovy index 2cfcdc3..bf5c922 100644 --- a/src/main/groovy/com/android/tools/internal/emulator/BuildEmulator.groovy +++ b/src/main/groovy/com/android/tools/internal/emulator/BuildEmulator.groovy @@ -84,6 +84,7 @@ class BuildEmulator extends DefaultTask { } boolean windows = false + boolean msvc = false // True if this is a full debug build which includes coverage. boolean debug = false @@ -96,21 +97,25 @@ class BuildEmulator extends DefaultTask { @TaskAction void build() { - String command = "$project.projectDir/android/rebuild.sh --verbose --out-dir=$output --sdk-revision=$revision --sdk-build-number=$build_number" + String command = "python $project.projectDir/android/build/python/cmake.py --noshowprefixforinfo --out $output --sdk_revision $revision --sdk_build_number $build_number" String prefix = "[" if (windows) { - command = command + " --mingw" - prefix = prefix + "win-" - - } + if ("True".equals(System.getenv("MINGW"))) { + command = command + " --target mingw" + prefix = prefix + "mingw-" + } else { + command = command + " --target windows" + prefix = prefix + "win-" + } + } if (debug) { - command = command + " --debug" + command = command + " --config debug" prefix = prefix + "dbg" } else { - command = command + " --symbols --crash-prod" + command = command + " --symbols --crash prod --symbol_dest prod" prefix = prefix + "rel" } prefix = prefix + "] " @@ -118,28 +123,26 @@ class BuildEmulator extends DefaultTask { LoggerWriter stdout = new LoggerWriter(logger, LogLevel.INFO, prefix) LoggerWriter stderr = new LoggerWriter(logger, LogLevel.ERROR, prefix) + logger.info("Running: " + command) Process p = command.execute() p.consumeProcessOutput(stdout, stderr) int result = p.waitFor() if (result != 0) { - throw new BuildException("Failed to run android/rebuild.sh command. See console output", null) + throw new BuildException("Failed to run android/buid/python/cmake.py command. See console output", null) } stdout.reset(); stderr.reset(); - if (!debug) { - uploadSymbols(stdout, stderr) - } } void uploadSymbols(LoggerWriter stdout, LoggerWriter stderr) { /** * Upload the symbols */ - String command = "$project.projectDir/android/scripts/upload-symbols.sh --crash-prod --symbol-dir=$output/build/symbols --verbose --verbose" + String command = "$project.projectDir/android/scripts/upload-symbols.py --crash-prod --symbol-dir=$output/build/symbols --verbose --verbose" Process p = command.execute() p.consumeProcessOutput(stdout, stderr) |