| Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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 |
| 31 | import subprocess |
| Shubham Ajmera | 9c4b4f8 | 2017-03-09 10:15:49 -0800 | [diff] [blame] | 32 | import sys |
| Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 33 | |
| 34 | from target_config import target_config |
| 35 | import env |
| 36 | |
| 37 | parser = argparse.ArgumentParser() |
| Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 38 | parser.add_argument('-j', default='1', dest='n_threads') |
| Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 39 | # either -l/--list OR build-target is required (but not both). |
| 40 | group = parser.add_mutually_exclusive_group(required=True) |
| 41 | group.add_argument('build_target', nargs='?') |
| 42 | 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] | 43 | options = parser.parse_args() |
| 44 | |
| Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 45 | ########## |
| 46 | |
| 47 | if options.list: |
| 48 | print "List of all known build_target: " |
| 49 | for k in sorted(target_config.iterkeys()): |
| 50 | print " * " + k |
| 51 | # TODO: would be nice if this was the same order as the target config file. |
| 52 | sys.exit(1) |
| 53 | |
| 54 | if not target_config.get(options.build_target): |
| 55 | sys.stderr.write("error: invalid build_target, see -l/--list.\n") |
| 56 | sys.exit(1) |
| 57 | |
| Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 58 | target = target_config[options.build_target] |
| 59 | n_threads = options.n_threads |
| 60 | custom_env = target.get('env', {}) |
| 61 | custom_env['SOONG_ALLOW_MISSING_DEPENDENCIES'] = 'true' |
| 62 | print custom_env |
| 63 | os.environ.update(custom_env) |
| 64 | |
| Igor Murashkin | 01079c4 | 2017-04-21 13:04:27 -0700 | [diff] [blame] | 65 | if target.has_key('make'): |
| Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 66 | build_command = 'make' |
| Colin Cross | 91f55e6 | 2017-10-21 12:45:26 -0700 | [diff] [blame] | 67 | build_command += ' DX=' |
| Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 68 | build_command += ' -j' + str(n_threads) |
| 69 | build_command += ' -C ' + env.ANDROID_BUILD_TOP |
| Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 70 | build_command += ' ' + target.get('make') |
| Nicolas Geoffray | c461476 | 2017-03-27 10:06:14 +0100 | [diff] [blame] | 71 | # Add 'dist' to avoid Jack issues b/36169180. |
| 72 | build_command += ' dist' |
| Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 73 | sys.stdout.write(str(build_command) + '\n') |
| Shubham Ajmera | 3092c6e | 2017-03-24 16:19:48 -0700 | [diff] [blame] | 74 | sys.stdout.flush() |
| Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 75 | if subprocess.call(build_command.split()): |
| 76 | sys.exit(1) |
| 77 | |
| Igor Murashkin | 01079c4 | 2017-04-21 13:04:27 -0700 | [diff] [blame] | 78 | if target.has_key('golem'): |
| Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 79 | machine_type = target.get('golem') |
| 80 | # use art-opt-cc by default since it mimics the default preopt config. |
| 81 | default_golem_config = 'art-opt-cc' |
| 82 | |
| 83 | os.chdir(env.ANDROID_BUILD_TOP) |
| 84 | cmd = ['art/tools/golem/build-target.sh'] |
| 85 | cmd += ['-j' + str(n_threads)] |
| 86 | cmd += ['--showcommands'] |
| 87 | cmd += ['--machine-type=%s' %(machine_type)] |
| 88 | cmd += ['--golem=%s' %(default_golem_config)] |
| 89 | cmd += ['--tarball'] |
| 90 | sys.stdout.write(str(cmd) + '\n') |
| 91 | sys.stdout.flush() |
| 92 | |
| 93 | if subprocess.call(cmd): |
| 94 | sys.exit(1) |
| 95 | |
| Igor Murashkin | 01079c4 | 2017-04-21 13:04:27 -0700 | [diff] [blame] | 96 | if target.has_key('run-test'): |
| Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 97 | run_test_command = [os.path.join(env.ANDROID_BUILD_TOP, |
| 98 | 'art/test/testrunner/testrunner.py')] |
| Igor Murashkin | bab1506 | 2018-02-23 14:53:24 -0800 | [diff] [blame^] | 99 | test_flags = target.get('run-test', []) |
| 100 | run_test_command += test_flags |
| Shubham Ajmera | 93857f2 | 2017-10-09 13:47:35 -0700 | [diff] [blame] | 101 | # Let testrunner compute concurrency based on #cpus. |
| 102 | # b/65822340 |
| 103 | # run_test_command += ['-j', str(n_threads)] |
| Igor Murashkin | bab1506 | 2018-02-23 14:53:24 -0800 | [diff] [blame^] | 104 | |
| 105 | # In the config assume everything will run with --host and on ART. |
| 106 | # However for only [--jvm] this is undesirable, so don't pass in ART-specific flags. |
| 107 | if ['--jvm'] != test_flags: |
| 108 | run_test_command += ['--host'] |
| 109 | run_test_command += ['--dex2oat-jobs'] |
| 110 | run_test_command += ['4'] |
| Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 111 | run_test_command += ['-b'] |
| Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 112 | run_test_command += ['--verbose'] |
| 113 | |
| Igor Murashkin | 6228e9d | 2017-03-21 11:36:09 -0700 | [diff] [blame] | 114 | sys.stdout.write(str(run_test_command) + '\n') |
| Shubham Ajmera | 3092c6e | 2017-03-24 16:19:48 -0700 | [diff] [blame] | 115 | sys.stdout.flush() |
| Shubham Ajmera | e381ffe | 2017-03-08 11:03:22 -0800 | [diff] [blame] | 116 | if subprocess.call(run_test_command): |
| 117 | sys.exit(1) |
| 118 | |
| 119 | sys.exit(0) |