blob: d1e302772cf520938eeac17c79dc423694139737 [file] [log] [blame]
David Srbecky7cf6c582021-07-20 16:56:06 +01001#!/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("""
David Srbeckyd050c332022-11-09 12:26:33 +000037 java_genrule {{
David Srbeckya6f7c742022-09-21 12:27:47 +000038 name: "{name}-tmp",
David Srbecky7cf6c582021-07-20 16:56:06 +010039 out: ["{name}.zip"],
David Srbecky3dccfb82022-11-03 11:43:47 +000040 srcs: ["?{shard}-*/**/*", "??{shard}-*/**/*"],
41 defaults: ["art-run-test-{mode}-data-defaults"],
David Srbecky7cf6c582021-07-20 16:56:06 +010042 }}
David Srbeckya6f7c742022-09-21 12:27:47 +000043
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 Srbecky7cf6c582021-07-20 16:56:06 +010052 """.format(name=name, mode=mode, shard=shard)))
David Srbeckya6f7c742022-09-21 12:27:47 +000053
David Srbeckyc282bef2022-11-16 21:52:33 +000054 # 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 Srbecky3dccfb82022-11-03 11:43:47 +000087 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 Srbecky3dccfb82022-11-03 11:43:47 +0000101 "jasmin",
102 "smali",
David Srbecky6bd1cd12022-11-05 18:54:19 +0000103 "soong_zip",
104 "zipalign",
David Srbecky3dccfb82022-11-03 11:43:47 +0000105 ],
106 cmd: "$(location run_test_build.py) --out $(out) --mode {mode} " +
David Srbecky6bd1cd12022-11-05 18:54:19 +0000107 "--bootclasspath $(location :art-run-test-bootclasspath) " +
108 "--d8 $(location d8) " +
David Srbecky6bd1cd12022-11-05 18:54:19 +0000109 "--jasmin $(location jasmin) " +
110 "--smali $(location smali) " +
111 "--soong_zip $(location soong_zip) " +
112 "--zipalign $(location zipalign) " +
113 "$(in)",
David Srbecky3dccfb82022-11-03 11:43:47 +0000114 }}
115 """).format(mode=mode))
116
David Srbecky720dcbc2022-10-27 11:27:45 +0100117 name = "art-run-test-{mode}-data-merged".format(mode=mode)
David Srbeckya6f7c742022-09-21 12:27:47 +0000118 srcs = ("\n"+" "*8).join('":{}-tmp",'.format(n) for n in names)
119 deps = ("\n"+" "*8).join('"{}",'.format(n) for n in names)
David Srbecky7cf6c582021-07-20 16:56:06 +0100120 f.write(textwrap.dedent("""
David Srbeckyd050c332022-11-09 12:26:33 +0000121 java_genrule {{
David Srbeckya6f7c742022-09-21 12:27:47 +0000122 name: "{name}-tmp",
David Srbecky3dccfb82022-11-03 11:43:47 +0000123 defaults: ["art_module_source_build_genrule_defaults"],
David Srbeckya6f7c742022-09-21 12:27:47 +0000124 out: ["{name}.zip"],
David Srbecky7cf6c582021-07-20 16:56:06 +0100125 srcs: [
126 {srcs}
127 ],
128 tools: ["merge_zips"],
129 cmd: "$(location merge_zips) $(out) $(in)",
130 }}
David Srbeckya6f7c742022-09-21 12:27:47 +0000131
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 Srbecky7cf6c582021-07-20 16:56:06 +0100144
David Srbecky720dcbc2022-10-27 11:27:45 +0100145 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 Srbeckyd050c332022-11-09 12:26:33 +0000150 java_genrule {{
David Srbecky720dcbc2022-10-27 11:27:45 +0100151 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 Srbecky7cf6c582021-07-20 16:56:06 +0100173if __name__ == "__main__":
174 main()