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 | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 38 | name: "{name}", |
| 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 | }} |
| 45 | """.format(name=name, mode=mode, shard=shard))) |
| 46 | srcs = ("\n"+" "*8).join('":{}",'.format(n) for n in names) |
| 47 | f.write(textwrap.dedent(""" |
Colin Cross | 3b87d85 | 2021-10-08 17:53:52 -0700 | [diff] [blame] | 48 | java_genrule {{ |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 49 | name: "art-run-test-{mode}-data-merged", |
Martin Stjernholm | 41e56c2 | 2021-10-14 00:28:12 +0100 | [diff] [blame] | 50 | defaults: ["art-run-test-data-defaults"], |
David Srbecky | 7cf6c58 | 2021-07-20 16:56:06 +0100 | [diff] [blame] | 51 | out: ["art-run-test-{mode}-data-merged.zip"], |
| 52 | srcs: [ |
| 53 | {srcs} |
| 54 | ], |
| 55 | tools: ["merge_zips"], |
| 56 | cmd: "$(location merge_zips) $(out) $(in)", |
| 57 | }} |
| 58 | """).format(mode=mode, srcs=srcs)) |
| 59 | |
| 60 | if __name__ == "__main__": |
| 61 | main() |