blob: 19f03c31653aa1fcc3fc7eb7ee19e54f871cedad [file] [log] [blame]
Igor Murashkin88c68092018-03-07 17:02:51 -08001#!/usr/bin/env python3
Shubham Ajmerae381ffe2017-03-08 11:03:22 -08002#
3# Copyright 2017, The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Shubham Ajmera9c4b4f82017-03-09 10:15:49 -080017"""Build and run go/ab/git_master-art-host target
18
Igor Murashkin6228e9d2017-03-21 11:36:09 -070019This script is executed by the android build server and must not be moved,
20or changed in an otherwise backwards-incompatible manner.
21
Shubham Ajmera9c4b4f82017-03-09 10:15:49 -080022Provided with a target name, the script setup the environment for
23building the test target by taking config information from
24from target_config.py.
25
Igor Murashkin6228e9d2017-03-21 11:36:09 -070026See target_config.py for the configuration syntax.
Shubham Ajmera9c4b4f82017-03-09 10:15:49 -080027"""
28
Shubham Ajmerae381ffe2017-03-08 11:03:22 -080029import argparse
30import os
Alex Lighte46d0fb2019-01-30 13:48:30 -080031import pathlib
Shubham Ajmerae381ffe2017-03-08 11:03:22 -080032import subprocess
Shubham Ajmera9c4b4f82017-03-09 10:15:49 -080033import sys
Shubham Ajmerae381ffe2017-03-08 11:03:22 -080034
35from target_config import target_config
36import env
37
38parser = argparse.ArgumentParser()
Shubham Ajmerae381ffe2017-03-08 11:03:22 -080039parser.add_argument('-j', default='1', dest='n_threads')
Igor Murashkin6228e9d2017-03-21 11:36:09 -070040# either -l/--list OR build-target is required (but not both).
41group = parser.add_mutually_exclusive_group(required=True)
42group.add_argument('build_target', nargs='?')
43group.add_argument('-l', '--list', action='store_true', help='List all possible run-build targets.')
Shubham Ajmerae381ffe2017-03-08 11:03:22 -080044options = parser.parse_args()
45
Igor Murashkin6228e9d2017-03-21 11:36:09 -070046##########
47
48if options.list:
Igor Murashkin88c68092018-03-07 17:02:51 -080049 print("List of all known build_target: ")
50 for k in sorted(target_config.keys()):
51 print(" * " + k)
Igor Murashkin6228e9d2017-03-21 11:36:09 -070052 # TODO: would be nice if this was the same order as the target config file.
53 sys.exit(1)
54
55if not target_config.get(options.build_target):
56 sys.stderr.write("error: invalid build_target, see -l/--list.\n")
57 sys.exit(1)
58
Shubham Ajmerae381ffe2017-03-08 11:03:22 -080059target = target_config[options.build_target]
60n_threads = options.n_threads
61custom_env = target.get('env', {})
62custom_env['SOONG_ALLOW_MISSING_DEPENDENCIES'] = 'true'
Igor Murashkin88c68092018-03-07 17:02:51 -080063print(custom_env)
Shubham Ajmerae381ffe2017-03-08 11:03:22 -080064os.environ.update(custom_env)
65
Alex Lightcbdca722018-11-13 14:03:02 -080066# build is just a binary/script that is directly executed to build any artifacts needed for the
67# test.
68if 'build' in target:
69 build_command = target.get('build').format(
70 ANDROID_BUILD_TOP = env.ANDROID_BUILD_TOP,
71 MAKE_OPTIONS='DX= -j{threads}'.format(threads = n_threads))
72 sys.stdout.write(str(build_command) + '\n')
73 sys.stdout.flush()
74 if subprocess.call(build_command.split()):
75 sys.exit(1)
76
77# make runs soong/kati to build the target listed in the entry.
Igor Murashkin88c68092018-03-07 17:02:51 -080078if 'make' in target:
Dan Willemsen2e956ba2018-10-08 17:44:45 -070079 build_command = 'build/soong/soong_ui.bash --make-mode'
Colin Cross91f55e62017-10-21 12:45:26 -070080 build_command += ' DX='
Shubham Ajmerae381ffe2017-03-08 11:03:22 -080081 build_command += ' -j' + str(n_threads)
Igor Murashkin6228e9d2017-03-21 11:36:09 -070082 build_command += ' ' + target.get('make')
Dan Willemsendb72e5e2018-10-02 14:09:21 -070083 if env.DIST_DIR:
84 build_command += ' dist'
Igor Murashkin6228e9d2017-03-21 11:36:09 -070085 sys.stdout.write(str(build_command) + '\n')
Shubham Ajmera3092c6e2017-03-24 16:19:48 -070086 sys.stdout.flush()
Shubham Ajmerae381ffe2017-03-08 11:03:22 -080087 if subprocess.call(build_command.split()):
88 sys.exit(1)
89
Igor Murashkin88c68092018-03-07 17:02:51 -080090if 'golem' in target:
Igor Murashkin6228e9d2017-03-21 11:36:09 -070091 machine_type = target.get('golem')
92 # use art-opt-cc by default since it mimics the default preopt config.
93 default_golem_config = 'art-opt-cc'
94
95 os.chdir(env.ANDROID_BUILD_TOP)
96 cmd = ['art/tools/golem/build-target.sh']
97 cmd += ['-j' + str(n_threads)]
98 cmd += ['--showcommands']
99 cmd += ['--machine-type=%s' %(machine_type)]
100 cmd += ['--golem=%s' %(default_golem_config)]
101 cmd += ['--tarball']
102 sys.stdout.write(str(cmd) + '\n')
103 sys.stdout.flush()
104
105 if subprocess.call(cmd):
106 sys.exit(1)
107
Igor Murashkin88c68092018-03-07 17:02:51 -0800108if 'run-test' in target:
Shubham Ajmerae381ffe2017-03-08 11:03:22 -0800109 run_test_command = [os.path.join(env.ANDROID_BUILD_TOP,
110 'art/test/testrunner/testrunner.py')]
Igor Murashkinbab15062018-02-23 14:53:24 -0800111 test_flags = target.get('run-test', [])
Alex Lighte46d0fb2019-01-30 13:48:30 -0800112 out_dir = pathlib.PurePath(env.SOONG_OUT_DIR)
113 if not out_dir.is_absolute():
114 out_dir = pathlib.PurePath(env.ANDROID_BUILD_TOP).joinpath(out_dir)
115 run_test_command += list(map(lambda a: a.format(SOONG_OUT_DIR=str(out_dir)), test_flags))
Shubham Ajmera93857f22017-10-09 13:47:35 -0700116 # Let testrunner compute concurrency based on #cpus.
117 # b/65822340
118 # run_test_command += ['-j', str(n_threads)]
Igor Murashkinbab15062018-02-23 14:53:24 -0800119
120 # In the config assume everything will run with --host and on ART.
121 # However for only [--jvm] this is undesirable, so don't pass in ART-specific flags.
122 if ['--jvm'] != test_flags:
123 run_test_command += ['--host']
124 run_test_command += ['--dex2oat-jobs']
125 run_test_command += ['4']
Alex Lightcbdca722018-11-13 14:03:02 -0800126 if '--no-build-dependencies' not in test_flags:
127 run_test_command += ['-b']
Shubham Ajmerae381ffe2017-03-08 11:03:22 -0800128 run_test_command += ['--verbose']
129
Igor Murashkin6228e9d2017-03-21 11:36:09 -0700130 sys.stdout.write(str(run_test_command) + '\n')
Shubham Ajmera3092c6e2017-03-24 16:19:48 -0700131 sys.stdout.flush()
Shubham Ajmerae381ffe2017-03-08 11:03:22 -0800132 if subprocess.call(run_test_command):
133 sys.exit(1)
134
135sys.exit(0)