Igor Murashkin | 88c6809 | 2018-03-07 17:02:51 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 2 | # |
| 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 Ajmera | 9c4b4f8 | 2017-03-09 10:15:49 -0800 | [diff] [blame] | 17 | """Build and run go/ab/git_master-art-host target |
| 18 | |
Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 19 | This script is executed by the android build server and must not be moved, |
| 20 | or changed in an otherwise backwards-incompatible manner. |
| 21 | |
Shubham Ajmera | 9c4b4f8 | 2017-03-09 10:15:49 -0800 | [diff] [blame] | 22 | Provided with a target name, the script setup the environment for |
| 23 | building the test target by taking config information from |
| 24 | from target_config.py. |
| 25 | |
Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 26 | See target_config.py for the configuration syntax. |
Shubham Ajmera | 9c4b4f8 | 2017-03-09 10:15:49 -0800 | [diff] [blame] | 27 | """ |
| 28 | |
Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 29 | import argparse |
| 30 | import os |
Alex Light | e46d0fb | 2019-01-30 13:48:30 -0800 | [diff] [blame] | 31 | import pathlib |
Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 32 | import subprocess |
Shubham Ajmera | 9c4b4f8 | 2017-03-09 10:15:49 -0800 | [diff] [blame] | 33 | import sys |
Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 34 | |
| 35 | from target_config import target_config |
| 36 | import env |
| 37 | |
| 38 | parser = argparse.ArgumentParser() |
Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 39 | parser.add_argument('-j', default='1', dest='n_threads') |
Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 40 | # either -l/--list OR build-target is required (but not both). |
| 41 | group = parser.add_mutually_exclusive_group(required=True) |
| 42 | group.add_argument('build_target', nargs='?') |
| 43 | group.add_argument('-l', '--list', action='store_true', help='List all possible run-build targets.') |
Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 44 | options = parser.parse_args() |
| 45 | |
Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 46 | ########## |
| 47 | |
| 48 | if options.list: |
Igor Murashkin | 88c6809 | 2018-03-07 17:02:51 -0800 | [diff] [blame] | 49 | print("List of all known build_target: ") |
| 50 | for k in sorted(target_config.keys()): |
| 51 | print(" * " + k) |
Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 52 | # TODO: would be nice if this was the same order as the target config file. |
| 53 | sys.exit(1) |
| 54 | |
| 55 | if 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 Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 59 | target = target_config[options.build_target] |
| 60 | n_threads = options.n_threads |
| 61 | custom_env = target.get('env', {}) |
| 62 | custom_env['SOONG_ALLOW_MISSING_DEPENDENCIES'] = 'true' |
Martin Stjernholm | 6906910 | 2020-06-16 13:26:40 +0100 | [diff] [blame] | 63 | # Switch the build system to unbundled mode in the reduced manifest branch. |
Martin Stjernholm | 6906910 | 2020-06-16 13:26:40 +0100 | [diff] [blame] | 64 | if not os.path.isdir(env.ANDROID_BUILD_TOP + '/frameworks/base'): |
| 65 | custom_env['TARGET_BUILD_UNBUNDLED'] = 'true' |
Igor Murashkin | 88c6809 | 2018-03-07 17:02:51 -0800 | [diff] [blame] | 66 | print(custom_env) |
Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 67 | os.environ.update(custom_env) |
| 68 | |
David Srbecky | a9fed15 | 2021-04-16 15:00:47 +0100 | [diff] [blame] | 69 | # always run installclean first remove any old installed files from previous builds. |
| 70 | # this does not remove intermediate files, so it still avoids recompilation. |
| 71 | clean_command = 'build/soong/soong_ui.bash --make-mode installclean' |
| 72 | if env.DIST_DIR: |
| 73 | clean_command += ' dist' |
| 74 | sys.stdout.write(str(clean_command) + '\n') |
| 75 | sys.stdout.flush() |
| 76 | if subprocess.call(clean_command.split()): |
| 77 | sys.exit(1) |
| 78 | |
Alex Light | cbdca72 | 2018-11-13 14:03:02 -0800 | [diff] [blame] | 79 | # build is just a binary/script that is directly executed to build any artifacts needed for the |
| 80 | # test. |
| 81 | if 'build' in target: |
| 82 | build_command = target.get('build').format( |
| 83 | ANDROID_BUILD_TOP = env.ANDROID_BUILD_TOP, |
| 84 | MAKE_OPTIONS='DX= -j{threads}'.format(threads = n_threads)) |
| 85 | sys.stdout.write(str(build_command) + '\n') |
| 86 | sys.stdout.flush() |
| 87 | if subprocess.call(build_command.split()): |
| 88 | sys.exit(1) |
| 89 | |
| 90 | # make runs soong/kati to build the target listed in the entry. |
Igor Murashkin | 88c6809 | 2018-03-07 17:02:51 -0800 | [diff] [blame] | 91 | if 'make' in target: |
Dan Willemsen | 2e956ba | 2018-10-08 17:44:45 -0700 | [diff] [blame] | 92 | build_command = 'build/soong/soong_ui.bash --make-mode' |
Colin Cross | 91f55e6 | 2017-10-21 12:45:26 -0700 | [diff] [blame] | 93 | build_command += ' DX=' |
Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 94 | build_command += ' -j' + str(n_threads) |
Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 95 | build_command += ' ' + target.get('make') |
Dan Willemsen | db72e5e | 2018-10-02 14:09:21 -0700 | [diff] [blame] | 96 | if env.DIST_DIR: |
| 97 | build_command += ' dist' |
Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 98 | sys.stdout.write(str(build_command) + '\n') |
Shubham Ajmera | 3092c6e | 2017-03-24 16:19:48 -0700 | [diff] [blame] | 99 | sys.stdout.flush() |
Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 100 | if subprocess.call(build_command.split()): |
| 101 | sys.exit(1) |
| 102 | |
Igor Murashkin | 88c6809 | 2018-03-07 17:02:51 -0800 | [diff] [blame] | 103 | if 'golem' in target: |
Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 104 | machine_type = target.get('golem') |
| 105 | # use art-opt-cc by default since it mimics the default preopt config. |
| 106 | default_golem_config = 'art-opt-cc' |
| 107 | |
| 108 | os.chdir(env.ANDROID_BUILD_TOP) |
| 109 | cmd = ['art/tools/golem/build-target.sh'] |
| 110 | cmd += ['-j' + str(n_threads)] |
| 111 | cmd += ['--showcommands'] |
| 112 | cmd += ['--machine-type=%s' %(machine_type)] |
| 113 | cmd += ['--golem=%s' %(default_golem_config)] |
| 114 | cmd += ['--tarball'] |
| 115 | sys.stdout.write(str(cmd) + '\n') |
| 116 | sys.stdout.flush() |
| 117 | |
| 118 | if subprocess.call(cmd): |
| 119 | sys.exit(1) |
| 120 | |
Igor Murashkin | 88c6809 | 2018-03-07 17:02:51 -0800 | [diff] [blame] | 121 | if 'run-test' in target: |
Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 122 | run_test_command = [os.path.join(env.ANDROID_BUILD_TOP, |
| 123 | 'art/test/testrunner/testrunner.py')] |
Igor Murashkin | bab1506 | 2018-02-23 14:53:24 -0800 | [diff] [blame] | 124 | test_flags = target.get('run-test', []) |
Alex Light | e46d0fb | 2019-01-30 13:48:30 -0800 | [diff] [blame] | 125 | out_dir = pathlib.PurePath(env.SOONG_OUT_DIR) |
| 126 | if not out_dir.is_absolute(): |
| 127 | out_dir = pathlib.PurePath(env.ANDROID_BUILD_TOP).joinpath(out_dir) |
| 128 | run_test_command += list(map(lambda a: a.format(SOONG_OUT_DIR=str(out_dir)), test_flags)) |
Shubham Ajmera | 93857f2 | 2017-10-09 13:47:35 -0700 | [diff] [blame] | 129 | # Let testrunner compute concurrency based on #cpus. |
| 130 | # b/65822340 |
| 131 | # run_test_command += ['-j', str(n_threads)] |
Igor Murashkin | bab1506 | 2018-02-23 14:53:24 -0800 | [diff] [blame] | 132 | |
| 133 | # In the config assume everything will run with --host and on ART. |
| 134 | # However for only [--jvm] this is undesirable, so don't pass in ART-specific flags. |
| 135 | if ['--jvm'] != test_flags: |
| 136 | run_test_command += ['--host'] |
| 137 | run_test_command += ['--dex2oat-jobs'] |
| 138 | run_test_command += ['4'] |
Alex Light | cbdca72 | 2018-11-13 14:03:02 -0800 | [diff] [blame] | 139 | if '--no-build-dependencies' not in test_flags: |
| 140 | run_test_command += ['-b'] |
Roland Levillain | 93e4df7 | 2020-06-29 13:33:56 +0100 | [diff] [blame] | 141 | if env.DIST_DIR: |
| 142 | run_test_command += ['--dist'] |
Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 143 | run_test_command += ['--verbose'] |
| 144 | |
Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 145 | sys.stdout.write(str(run_test_command) + '\n') |
Shubham Ajmera | 3092c6e | 2017-03-24 16:19:48 -0700 | [diff] [blame] | 146 | sys.stdout.flush() |
Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 147 | if subprocess.call(run_test_command): |
| 148 | sys.exit(1) |
| 149 | |
| 150 | sys.exit(0) |