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 19import os, textwrap 20 21def 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(""" 37 java_genrule {{ 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(""" 48 java_genrule {{ 49 name: "art-run-test-{mode}-data-merged", 50 defaults: ["art-run-test-data-defaults"], 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 60if __name__ == "__main__": 61 main() 62