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(""" |
Colin Cross | 3b87d85 | 2021-10-08 17:53:52 -0700 | [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"], |
| 40 | srcs: ["*{shard}-*/**/*"], |
| 41 | defaults: ["art-run-test-data-defaults"], |
| 42 | cmd: "$(location run-test-build.py) --out $(out) --mode {mode} --shard {shard} " + |
| 43 | "--bootclasspath $(location :art-run-test-bootclasspath)", |
| 44 | }} |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 45 | |
| 46 | // Install in the output directory to make it accessible for tests. |
| 47 | prebuilt_etc_host {{ |
| 48 | name: "{name}", |
| 49 | defaults: ["art_module_source_build_prebuilt_defaults"], |
| 50 | src: ":{name}-tmp", |
| 51 | sub_dir: "art", |
| 52 | filename: "{name}.zip", |
| 53 | }} |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 54 | """.format(name=name, mode=mode, shard=shard))) |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 55 | |
David Srbecky | 720dcbc | 2022-10-27 11:27:45 +0100 | [diff] [blame] | 56 | name = "art-run-test-{mode}-data-merged".format(mode=mode) |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 57 | srcs = ("\n"+" "*8).join('":{}-tmp",'.format(n) for n in names) |
| 58 | deps = ("\n"+" "*8).join('"{}",'.format(n) for n in names) |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 59 | f.write(textwrap.dedent(""" |
Colin Cross | 3b87d85 | 2021-10-08 17:53:52 -0700 | [diff] [blame] | 60 | java_genrule {{ |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 61 | name: "{name}-tmp", |
Martin Stjernholm | 41e56c2 | 2021-10-14 00:28:12 +0100 | [diff] [blame] | 62 | defaults: ["art-run-test-data-defaults"], |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 63 | out: ["{name}.zip"], |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 64 | srcs: [ |
| 65 | {srcs} |
| 66 | ], |
| 67 | tools: ["merge_zips"], |
| 68 | cmd: "$(location merge_zips) $(out) $(in)", |
| 69 | }} |
David Srbecky | a6f7c74 | 2022-09-21 12:27:47 +0000 | [diff] [blame] | 70 | |
| 71 | // Install in the output directory to make it accessible for tests. |
| 72 | prebuilt_etc_host {{ |
| 73 | name: "{name}", |
| 74 | defaults: ["art_module_source_build_prebuilt_defaults"], |
| 75 | src: ":{name}-tmp", |
| 76 | required: [ |
| 77 | {deps} |
| 78 | ], |
| 79 | sub_dir: "art", |
| 80 | filename: "{name}.zip", |
| 81 | }} |
| 82 | """).format(name=name, srcs=srcs, deps=deps)) |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 83 | |
David Srbecky | 720dcbc | 2022-10-27 11:27:45 +0100 | [diff] [blame] | 84 | name = "art-run-test-{mode}-data".format(mode=mode) |
| 85 | srcs = ("\n"+" "*8).join('":{}-tmp",'.format(n) for n in names) |
| 86 | deps = ("\n"+" "*8).join('"{}",'.format(n) for n in names) |
| 87 | f.write(textwrap.dedent(""" |
| 88 | // Phony target used to build all shards |
| 89 | java_genrule {{ |
| 90 | name: "{name}-tmp", |
| 91 | defaults: ["art-run-test-data-defaults"], |
| 92 | out: ["{name}.txt"], |
| 93 | srcs: [ |
| 94 | {srcs} |
| 95 | ], |
| 96 | cmd: "echo $(in) > $(out)", |
| 97 | }} |
| 98 | |
| 99 | // Phony target used to install all shards |
| 100 | prebuilt_etc_host {{ |
| 101 | name: "{name}", |
| 102 | defaults: ["art_module_source_build_prebuilt_defaults"], |
| 103 | src: ":{name}-tmp", |
| 104 | required: [ |
| 105 | {deps} |
| 106 | ], |
| 107 | sub_dir: "art", |
| 108 | filename: "{name}.txt", |
| 109 | }} |
| 110 | """).format(name=name, srcs=srcs, deps=deps)) |
| 111 | |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 112 | if __name__ == "__main__": |
| 113 | main() |