David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (C) 2021 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 | |
| 17 | """ This script generates the Android.run-test.bp build file""" |
| 18 | |
| 19 | import os, textwrap |
| 20 | |
| 21 | def main(): |
| 22 | test_dir = os.path.dirname(__file__) |
| 23 | with open(os.path.join(test_dir, "Android.run-test.bp"), mode="wt") as f: |
| 24 | f.write(textwrap.dedent(""" |
| 25 | // This file was generated by {} |
| 26 | // It is not necessary to regenerate it when tests are added/removed/modified. |
| 27 | """.format(os.path.basename(__file__))).lstrip()) |
| 28 | for mode in ["host", "target", "jvm"]: |
| 29 | names = [] |
| 30 | # Group the tests into shards based on the last two digits of the test number. |
| 31 | # This keeps the number of generated genrules low so we don't overwhelm soong, |
| 32 | # but it still allows iterating on single test without recompiling all tests. |
| 33 | for shard in ["{:02}".format(i) for i in range(100)]: |
| 34 | name = "art-run-test-{mode}-data-shard{shard}".format(mode=mode, shard=shard) |
| 35 | names.append(name) |
| 36 | f.write(textwrap.dedent(""" |
David Srbecky | d050c33 | 2022-11-09 12:26:33 +0000 | [diff] [blame] | 37 | java_genrule {{ |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 38 | name: "{name}-tmp", |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 39 | out: ["{name}.zip"], |
David Srbecky | 3dccfb8 | 2022-11-03 11:43:47 +0000 | [diff] [blame] | 40 | srcs: ["?{shard}-*/**/*", "??{shard}-*/**/*"], |
| 41 | defaults: ["art-run-test-{mode}-data-defaults"], |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 42 | }} |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 43 | |
| 44 | // Install in the output directory to make it accessible for tests. |
| 45 | prebuilt_etc_host {{ |
| 46 | name: "{name}", |
| 47 | defaults: ["art_module_source_build_prebuilt_defaults"], |
| 48 | src: ":{name}-tmp", |
| 49 | sub_dir: "art", |
| 50 | filename: "{name}.zip", |
| 51 | }} |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 52 | """.format(name=name, mode=mode, shard=shard))) |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 53 | |
David Srbecky | c282bef | 2022-11-16 21:52:33 +0000 | [diff] [blame] | 54 | # Build all hiddenapi tests in their own shard. |
| 55 | # This removes the dependency on hiddenapi from all other shards, |
| 56 | # which in turn removes dependency on ART C++ source code. |
| 57 | name = "art-run-test-{mode}-data-shardHiddenApi".format(mode=mode) |
| 58 | names.append(name) |
| 59 | f.write(textwrap.dedent(""" |
| 60 | java_genrule {{ |
| 61 | name: "{name}-tmp", |
| 62 | out: ["{name}.zip"], |
| 63 | srcs: ["???-*hiddenapi*/**/*", "????-*hiddenapi*/**/*"], |
| 64 | defaults: ["art-run-test-{mode}-data-defaults"], |
| 65 | tools: ["hiddenapi"], |
| 66 | cmd: "$(location run_test_build.py) --out $(out) --mode {mode} " + |
| 67 | "--bootclasspath $(location :art-run-test-bootclasspath) " + |
| 68 | "--d8 $(location d8) " + |
| 69 | "--hiddenapi $(location hiddenapi) " + |
| 70 | "--jasmin $(location jasmin) " + |
| 71 | "--smali $(location smali) " + |
| 72 | "--soong_zip $(location soong_zip) " + |
| 73 | "--zipalign $(location zipalign) " + |
| 74 | "$(in)", |
| 75 | }} |
| 76 | |
| 77 | // Install in the output directory to make it accessible for tests. |
| 78 | prebuilt_etc_host {{ |
| 79 | name: "{name}", |
| 80 | defaults: ["art_module_source_build_prebuilt_defaults"], |
| 81 | src: ":{name}-tmp", |
| 82 | sub_dir: "art", |
| 83 | filename: "{name}.zip", |
| 84 | }} |
| 85 | """.format(name=name, mode=mode))) |
| 86 | |
David Srbecky | 3dccfb8 | 2022-11-03 11:43:47 +0000 | [diff] [blame] | 87 | f.write(textwrap.dedent(""" |
| 88 | genrule_defaults {{ |
| 89 | name: "art-run-test-{mode}-data-defaults", |
| 90 | defaults: [ |
| 91 | // Enable only in source builds, where com.android.art.testing is |
| 92 | // available. |
| 93 | "art_module_source_build_genrule_defaults", |
| 94 | ], |
| 95 | tool_files: [ |
| 96 | "run_test_build.py", |
| 97 | ":art-run-test-bootclasspath", |
| 98 | ], |
| 99 | tools: [ |
| 100 | "d8", |
David Srbecky | 3dccfb8 | 2022-11-03 11:43:47 +0000 | [diff] [blame] | 101 | "jasmin", |
| 102 | "smali", |
David Srbecky | 6bd1cd1 | 2022-11-05 18:54:19 +0000 | [diff] [blame] | 103 | "soong_zip", |
| 104 | "zipalign", |
David Srbecky | 3dccfb8 | 2022-11-03 11:43:47 +0000 | [diff] [blame] | 105 | ], |
| 106 | cmd: "$(location run_test_build.py) --out $(out) --mode {mode} " + |
David Srbecky | 6bd1cd1 | 2022-11-05 18:54:19 +0000 | [diff] [blame] | 107 | "--bootclasspath $(location :art-run-test-bootclasspath) " + |
| 108 | "--d8 $(location d8) " + |
David Srbecky | 6bd1cd1 | 2022-11-05 18:54:19 +0000 | [diff] [blame] | 109 | "--jasmin $(location jasmin) " + |
| 110 | "--smali $(location smali) " + |
| 111 | "--soong_zip $(location soong_zip) " + |
| 112 | "--zipalign $(location zipalign) " + |
| 113 | "$(in)", |
David Srbecky | 3dccfb8 | 2022-11-03 11:43:47 +0000 | [diff] [blame] | 114 | }} |
| 115 | """).format(mode=mode)) |
| 116 | |
David Srbecky | 720dcbc | 2022-10-27 11:27:45 +0100 | [diff] [blame] | 117 | name = "art-run-test-{mode}-data-merged".format(mode=mode) |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 118 | srcs = ("\n"+" "*8).join('":{}-tmp",'.format(n) for n in names) |
| 119 | deps = ("\n"+" "*8).join('"{}",'.format(n) for n in names) |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 120 | f.write(textwrap.dedent(""" |
David Srbecky | d050c33 | 2022-11-09 12:26:33 +0000 | [diff] [blame] | 121 | java_genrule {{ |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 122 | name: "{name}-tmp", |
David Srbecky | 3dccfb8 | 2022-11-03 11:43:47 +0000 | [diff] [blame] | 123 | defaults: ["art_module_source_build_genrule_defaults"], |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 124 | out: ["{name}.zip"], |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 125 | srcs: [ |
| 126 | {srcs} |
| 127 | ], |
| 128 | tools: ["merge_zips"], |
| 129 | cmd: "$(location merge_zips) $(out) $(in)", |
| 130 | }} |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 131 | |
| 132 | // Install in the output directory to make it accessible for tests. |
| 133 | prebuilt_etc_host {{ |
| 134 | name: "{name}", |
| 135 | defaults: ["art_module_source_build_prebuilt_defaults"], |
| 136 | src: ":{name}-tmp", |
| 137 | required: [ |
| 138 | {deps} |
| 139 | ], |
| 140 | sub_dir: "art", |
| 141 | filename: "{name}.zip", |
| 142 | }} |
| 143 | """).format(name=name, srcs=srcs, deps=deps)) |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 144 | |
David Srbecky | 720dcbc | 2022-10-27 11:27:45 +0100 | [diff] [blame] | 145 | name = "art-run-test-{mode}-data".format(mode=mode) |
| 146 | srcs = ("\n"+" "*8).join('":{}-tmp",'.format(n) for n in names) |
| 147 | deps = ("\n"+" "*8).join('"{}",'.format(n) for n in names) |
| 148 | f.write(textwrap.dedent(""" |
| 149 | // Phony target used to build all shards |
David Srbecky | d050c33 | 2022-11-09 12:26:33 +0000 | [diff] [blame] | 150 | java_genrule {{ |
David Srbecky | 720dcbc | 2022-10-27 11:27:45 +0100 | [diff] [blame] | 151 | name: "{name}-tmp", |
| 152 | defaults: ["art-run-test-data-defaults"], |
| 153 | out: ["{name}.txt"], |
| 154 | srcs: [ |
| 155 | {srcs} |
| 156 | ], |
| 157 | cmd: "echo $(in) > $(out)", |
| 158 | }} |
| 159 | |
| 160 | // Phony target used to install all shards |
| 161 | prebuilt_etc_host {{ |
| 162 | name: "{name}", |
| 163 | defaults: ["art_module_source_build_prebuilt_defaults"], |
| 164 | src: ":{name}-tmp", |
| 165 | required: [ |
| 166 | {deps} |
| 167 | ], |
| 168 | sub_dir: "art", |
| 169 | filename: "{name}.txt", |
| 170 | }} |
| 171 | """).format(name=name, srcs=srcs, deps=deps)) |
| 172 | |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 173 | if __name__ == "__main__": |
| 174 | main() |