blob: e606cb2ffc6fade4a5f50ce438036abbc77005ec [file] [log] [blame]
Colin Cross1f7f3bd2016-07-27 10:12:38 -07001// Copyright (C) 2016 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package art
16
17import (
Colin Cross1f7f3bd2016-07-27 10:12:38 -070018 "fmt"
Alex Lightda948ce2018-12-06 17:05:41 +000019 "log"
David Srbecky7400a542020-07-09 13:40:57 +010020 "path/filepath"
David Srbecky1cf46a32020-06-22 15:39:00 +010021 "strings"
Colin Cross6e95dd52016-09-12 15:37:10 -070022 "sync"
Colin Cross84b69332017-11-01 14:23:17 -070023
24 "github.com/google/blueprint/proptools"
Colin Crossdd3b7aa2019-07-31 13:47:39 -070025
26 "android/soong/android"
27 "android/soong/apex"
28 "android/soong/cc"
David Srbecky7400a542020-07-09 13:40:57 +010029 "android/soong/cc/config"
Colin Cross1f7f3bd2016-07-27 10:12:38 -070030)
31
Vladimir Markobe0d3cf2020-02-12 10:52:22 +000032var supportedArches = []string{"arm", "arm64", "x86", "x86_64"}
Colin Cross1f7f3bd2016-07-27 10:12:38 -070033
Colin Crossdd3b7aa2019-07-31 13:47:39 -070034func globalFlags(ctx android.LoadHookContext) ([]string, []string) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -070035 var cflags []string
36 var asflags []string
37
Colin Crossdd3b7aa2019-07-31 13:47:39 -070038 opt := ctx.Config().GetenvWithDefault("ART_NDEBUG_OPT_FLAG", "-O3")
Colin Crossbe332ed2016-09-21 13:23:53 -070039 cflags = append(cflags, opt)
40
Colin Cross1f7f3bd2016-07-27 10:12:38 -070041 tlab := false
42
Colin Crossdd3b7aa2019-07-31 13:47:39 -070043 gcType := ctx.Config().GetenvWithDefault("ART_DEFAULT_GC_TYPE", "CMS")
Colin Cross1f7f3bd2016-07-27 10:12:38 -070044
Colin Crossdd3b7aa2019-07-31 13:47:39 -070045 if ctx.Config().IsEnvTrue("ART_TEST_DEBUG_GC") {
Colin Cross1f7f3bd2016-07-27 10:12:38 -070046 gcType = "SS"
47 tlab = true
48 }
49
50 cflags = append(cflags, "-DART_DEFAULT_GC_TYPE_IS_"+gcType)
51 if tlab {
52 cflags = append(cflags, "-DART_USE_TLAB=1")
53 }
54
Colin Crossdd3b7aa2019-07-31 13:47:39 -070055 if ctx.Config().IsEnvTrue("ART_HEAP_POISONING") {
Colin Cross1f7f3bd2016-07-27 10:12:38 -070056 cflags = append(cflags, "-DART_HEAP_POISONING=1")
57 asflags = append(asflags, "-DART_HEAP_POISONING=1")
58 }
Colin Crossdd3b7aa2019-07-31 13:47:39 -070059 if ctx.Config().IsEnvTrue("ART_USE_CXX_INTERPRETER") {
David Srbecky8ed45c82018-11-08 15:08:57 +000060 cflags = append(cflags, "-DART_USE_CXX_INTERPRETER=1")
61 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -070062
Colin Crossdd3b7aa2019-07-31 13:47:39 -070063 if !ctx.Config().IsEnvFalse("ART_USE_READ_BARRIER") && ctx.Config().ArtUseReadBarrier() {
Roland Levillainb81e9e92017-04-20 17:35:32 +010064 // Used to change the read barrier type. Valid values are BAKER, BROOKS,
65 // TABLELOOKUP. The default is BAKER.
Colin Crossdd3b7aa2019-07-31 13:47:39 -070066 barrierType := ctx.Config().GetenvWithDefault("ART_READ_BARRIER_TYPE", "BAKER")
Colin Cross1f7f3bd2016-07-27 10:12:38 -070067 cflags = append(cflags,
68 "-DART_USE_READ_BARRIER=1",
69 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
70 asflags = append(asflags,
71 "-DART_USE_READ_BARRIER=1",
72 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
Colin Cross1f7f3bd2016-07-27 10:12:38 -070073 }
74
Colin Crossdd3b7aa2019-07-31 13:47:39 -070075 if !ctx.Config().IsEnvFalse("ART_USE_GENERATIONAL_CC") {
Mathieu Chartier8d1a9962016-08-17 16:39:45 -070076 cflags = append(cflags, "-DART_USE_GENERATIONAL_CC=1")
77 }
78
Colin Crossdd3b7aa2019-07-31 13:47:39 -070079 cdexLevel := ctx.Config().GetenvWithDefault("ART_DEFAULT_COMPACT_DEX_LEVEL", "fast")
Mathieu Chartier8d1a9962016-08-17 16:39:45 -070080 cflags = append(cflags, "-DART_DEFAULT_COMPACT_DEX_LEVEL="+cdexLevel)
Mathieu Chartiera7f6b812017-12-11 13:34:29 -080081
Andreas Gampe655c6fd2017-05-24 21:42:10 -070082 // We need larger stack overflow guards for ASAN, as the compiled code will have
83 // larger frame sizes. For simplicity, just use global not-target-specific cflags.
84 // Note: We increase this for both debug and non-debug, as the overflow gap will
85 // be compiled into managed code. We always preopt (and build core images) with
86 // the debug version. So make the gap consistent (and adjust for the worst).
Colin Crossdd3b7aa2019-07-31 13:47:39 -070087 if len(ctx.Config().SanitizeDevice()) > 0 || len(ctx.Config().SanitizeHost()) > 0 {
Andreas Gampe655c6fd2017-05-24 21:42:10 -070088 cflags = append(cflags,
Colin Cross2db58b62017-06-27 10:38:31 -070089 "-DART_STACK_OVERFLOW_GAP_arm=8192",
Evgenii Stepanov9e3954d2019-09-12 15:58:52 -070090 "-DART_STACK_OVERFLOW_GAP_arm64=16384",
Colin Cross2db58b62017-06-27 10:38:31 -070091 "-DART_STACK_OVERFLOW_GAP_x86=16384",
92 "-DART_STACK_OVERFLOW_GAP_x86_64=20480")
Andreas Gampe655c6fd2017-05-24 21:42:10 -070093 } else {
94 cflags = append(cflags,
Colin Cross2db58b62017-06-27 10:38:31 -070095 "-DART_STACK_OVERFLOW_GAP_arm=8192",
96 "-DART_STACK_OVERFLOW_GAP_arm64=8192",
Colin Cross2db58b62017-06-27 10:38:31 -070097 "-DART_STACK_OVERFLOW_GAP_x86=8192",
98 "-DART_STACK_OVERFLOW_GAP_x86_64=8192")
Andreas Gampe655c6fd2017-05-24 21:42:10 -070099 }
Andreas Gampebc9f10c2017-05-19 08:28:06 -0700100
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700101 if ctx.Config().IsEnvTrue("ART_ENABLE_ADDRESS_SANITIZER") {
Andreas Gampedbf0e0f2017-07-11 08:34:48 -0700102 // Used to enable full sanitization, i.e., user poisoning, under ASAN.
103 cflags = append(cflags, "-DART_ENABLE_ADDRESS_SANITIZER=1")
104 asflags = append(asflags, "-DART_ENABLE_ADDRESS_SANITIZER=1")
105 }
106
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700107 if !ctx.Config().IsEnvFalse("USE_D8_DESUGAR") {
Alan Leung8f514ee2017-12-08 14:08:25 -0800108 cflags = append(cflags, "-DUSE_D8_DESUGAR=1")
109 }
110
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700111 return cflags, asflags
112}
113
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700114func debugFlags(ctx android.LoadHookContext) []string {
Colin Crossbe332ed2016-09-21 13:23:53 -0700115 var cflags []string
116
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700117 opt := ctx.Config().GetenvWithDefault("ART_DEBUG_OPT_FLAG", "-O2")
Colin Crossbe332ed2016-09-21 13:23:53 -0700118 cflags = append(cflags, opt)
119
120 return cflags
121}
122
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700123func deviceFlags(ctx android.LoadHookContext) []string {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700124 var cflags []string
125 deviceFrameSizeLimit := 1736
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700126 if len(ctx.Config().SanitizeDevice()) > 0 {
Vishwath Mohan1ecc4fe2016-09-26 09:22:42 -0700127 deviceFrameSizeLimit = 7400
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700128 }
129 cflags = append(cflags,
130 fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit),
131 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit),
132 )
133
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700134 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.Config().LibartImgDeviceBaseAddress())
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700135 minDelta := ctx.Config().GetenvWithDefault("LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
136 maxDelta := ctx.Config().GetenvWithDefault("LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000")
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700137 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
138 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
139
140 return cflags
141}
142
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700143func hostFlags(ctx android.LoadHookContext) []string {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700144 var cflags []string
145 hostFrameSizeLimit := 1736
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700146 if len(ctx.Config().SanitizeHost()) > 0 {
Colin Cross3174b682016-09-19 12:25:31 -0700147 // art/test/137-cfi/cfi.cc
148 // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess'
David Srbecky9cc67b12018-10-25 10:10:35 +0000149 hostFrameSizeLimit = 6400
Colin Cross3174b682016-09-19 12:25:31 -0700150 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700151 cflags = append(cflags,
152 fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit),
153 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit),
154 )
155
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700156 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.Config().LibartImgHostBaseAddress())
157 minDelta := ctx.Config().GetenvWithDefault("LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
158 maxDelta := ctx.Config().GetenvWithDefault("LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000")
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700159 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
160 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
161
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700162 if len(ctx.Config().SanitizeHost()) > 0 && !ctx.Config().IsEnvFalse("ART_ENABLE_ADDRESS_SANITIZER") {
Andreas Gampefcc7d672017-07-19 10:30:22 -0700163 // We enable full sanitization on the host by default.
164 cflags = append(cflags, "-DART_ENABLE_ADDRESS_SANITIZER=1")
165 }
166
David Srbecky7400a542020-07-09 13:40:57 +0100167 clang_path := filepath.Join(config.ClangDefaultBase, ctx.Config().PrebuiltOS(), config.ClangDefaultVersion)
168 cflags = append(cflags, "-DART_CLANG_PATH=\""+clang_path+"\"")
169
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700170 return cflags
171}
172
Colin Cross6e511782016-09-13 13:41:03 -0700173func globalDefaults(ctx android.LoadHookContext) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700174 type props struct {
175 Target struct {
176 Android struct {
177 Cflags []string
178 }
179 Host struct {
180 Cflags []string
181 }
182 }
Colin Cross2db58b62017-06-27 10:38:31 -0700183 Cflags []string
184 Asflags []string
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -0700185 Sanitize struct {
Colin Cross2db58b62017-06-27 10:38:31 -0700186 Recover []string
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -0700187 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700188 }
189
190 p := &props{}
191 p.Cflags, p.Asflags = globalFlags(ctx)
192 p.Target.Android.Cflags = deviceFlags(ctx)
193 p.Target.Host.Cflags = hostFlags(ctx)
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -0700194
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700195 if ctx.Config().IsEnvTrue("ART_DEX_FILE_ACCESS_TRACKING") {
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -0700196 p.Cflags = append(p.Cflags, "-DART_DEX_FILE_ACCESS_TRACKING")
Colin Cross2db58b62017-06-27 10:38:31 -0700197 p.Sanitize.Recover = []string{
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -0700198 "address",
199 }
200 }
201
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700202 ctx.AppendProperties(p)
Colin Crossfe6064a2016-08-30 13:49:26 -0700203}
Colin Cross6326d1b2016-09-06 10:24:28 -0700204
Martin Stjernholmb3092402020-09-04 00:49:44 +0100205// Hook that adds flags that are implicit for all cc_art_* modules.
206func addImplicitFlags(ctx android.LoadHookContext) {
207 type props struct {
208 Target struct {
209 Android struct {
210 Cflags []string
211 }
212 }
213 }
214
215 p := &props{}
216 if ctx.Config().IsEnvTrue("ART_TARGET_LINUX") {
217 p.Target.Android.Cflags = []string{"-DART_TARGET", "-DART_TARGET_LINUX"}
218 } else {
219 p.Target.Android.Cflags = []string{"-DART_TARGET", "-DART_TARGET_ANDROID"}
220 }
221
222 ctx.AppendProperties(p)
223}
224
Colin Crossbe332ed2016-09-21 13:23:53 -0700225func debugDefaults(ctx android.LoadHookContext) {
226 type props struct {
227 Cflags []string
228 }
229
230 p := &props{}
231 p.Cflags = debugFlags(ctx)
232 ctx.AppendProperties(p)
233}
234
Colin Cross6e511782016-09-13 13:41:03 -0700235func customLinker(ctx android.LoadHookContext) {
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700236 linker := ctx.Config().Getenv("CUSTOM_TARGET_LINKER")
Colin Cross84b69332017-11-01 14:23:17 -0700237 type props struct {
238 DynamicLinker string
Colin Crossfe6064a2016-08-30 13:49:26 -0700239 }
Colin Cross84b69332017-11-01 14:23:17 -0700240
241 p := &props{}
242 if linker != "" {
243 p.DynamicLinker = linker
244 }
245
246 ctx.AppendProperties(p)
Colin Crossfe6064a2016-08-30 13:49:26 -0700247}
248
Colin Cross6e511782016-09-13 13:41:03 -0700249func prefer32Bit(ctx android.LoadHookContext) {
Colin Cross84b69332017-11-01 14:23:17 -0700250 type props struct {
251 Target struct {
252 Host struct {
253 Compile_multilib *string
Colin Cross6326d1b2016-09-06 10:24:28 -0700254 }
255 }
Colin Cross6326d1b2016-09-06 10:24:28 -0700256 }
Colin Cross84b69332017-11-01 14:23:17 -0700257
258 p := &props{}
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700259 if ctx.Config().IsEnvTrue("HOST_PREFER_32_BIT") {
Colin Cross84b69332017-11-01 14:23:17 -0700260 p.Target.Host.Compile_multilib = proptools.StringPtr("prefer32")
261 }
262
Martin Stjernholme1a44512020-01-31 22:43:43 +0000263 // Prepend to make it overridable in the blueprints. Note that it doesn't work
264 // to override the property in a cc_defaults module.
265 ctx.PrependProperties(p)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700266}
267
Colin Crossb81d22d2019-02-06 12:42:54 -0800268var testMapKey = android.NewOnceKey("artTests")
269
Colin Cross6e95dd52016-09-12 15:37:10 -0700270func testMap(config android.Config) map[string][]string {
Colin Crossb81d22d2019-02-06 12:42:54 -0800271 return config.Once(testMapKey, func() interface{} {
Colin Cross6e95dd52016-09-12 15:37:10 -0700272 return make(map[string][]string)
273 }).(map[string][]string)
274}
275
276func testInstall(ctx android.InstallHookContext) {
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700277 testMap := testMap(ctx.Config())
Colin Cross6e95dd52016-09-12 15:37:10 -0700278
279 var name string
280 if ctx.Host() {
281 name = "host_"
282 } else {
283 name = "device_"
284 }
285 name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName()
286
287 artTestMutex.Lock()
288 defer artTestMutex.Unlock()
289
290 tests := testMap[name]
Colin Cross83072062019-10-02 16:06:58 -0700291 tests = append(tests, ctx.Path().ToMakePath().String())
Colin Cross6e95dd52016-09-12 15:37:10 -0700292 testMap[name] = tests
293}
294
David Srbecky1cf46a32020-06-22 15:39:00 +0100295var testcasesContentKey = android.NewOnceKey("artTestcasesContent")
296
297func testcasesContent(config android.Config) map[string]string {
298 return config.Once(testcasesContentKey, func() interface{} {
299 return make(map[string]string)
300 }).(map[string]string)
301}
302
303// Binaries and libraries also need to be copied in the testcases directory for
304// running tests on host. This method adds module to the list of needed files.
305// The 'key' is the file in testcases and 'value' is the path to copy it from.
306// The actual copy will be done in make since soong does not do installations.
307func addTestcasesFile(ctx android.InstallHookContext) {
Colin Cross71f76332021-07-20 11:57:48 -0700308 if ctx.Os() != ctx.Config().BuildOS || ctx.Module().IsSkipInstall() {
Martin Stjernholma3a828d2020-12-23 03:29:10 +0000309 return
310 }
311
David Srbecky1cf46a32020-06-22 15:39:00 +0100312 testcasesContent := testcasesContent(ctx.Config())
313
314 artTestMutex.Lock()
315 defer artTestMutex.Unlock()
316
Martin Stjernholma3a828d2020-12-23 03:29:10 +0000317 src := ctx.SrcPath().String()
318 path := strings.Split(ctx.Path().ToMakePath().String(), "/")
319 // Keep last two parts of the install path (e.g. bin/dex2oat).
320 dst := strings.Join(path[len(path)-2:], "/")
321 if oldSrc, ok := testcasesContent[dst]; ok {
322 ctx.ModuleErrorf("Conflicting sources for %s: %s and %s", dst, oldSrc, src)
David Srbecky1cf46a32020-06-22 15:39:00 +0100323 }
Martin Stjernholma3a828d2020-12-23 03:29:10 +0000324 testcasesContent[dst] = src
David Srbecky1cf46a32020-06-22 15:39:00 +0100325}
326
Colin Cross6e95dd52016-09-12 15:37:10 -0700327var artTestMutex sync.Mutex
328
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700329func init() {
Paul Duffin0c89d572019-06-27 14:21:12 +0100330 artModuleTypes := []string{
331 "art_cc_library",
332 "art_cc_library_static",
333 "art_cc_binary",
334 "art_cc_test",
335 "art_cc_test_library",
336 "art_cc_defaults",
337 "libart_cc_defaults",
338 "libart_static_cc_defaults",
339 "art_global_defaults",
340 "art_debug_defaults",
Roland Levillain4fb71cc2019-09-11 18:39:59 +0100341 "art_apex_test_host",
Paul Duffin0c89d572019-06-27 14:21:12 +0100342 }
343 android.AddNeverAllowRules(
344 android.NeverAllow().
345 NotIn("art", "external/vixl").
346 ModuleType(artModuleTypes...))
347
Colin Cross96548c92016-10-12 14:26:55 -0700348 android.RegisterModuleType("art_cc_library", artLibrary)
Steven Moreland73030ed2019-01-03 14:23:28 -0800349 android.RegisterModuleType("art_cc_library_static", artStaticLibrary)
Colin Cross96548c92016-10-12 14:26:55 -0700350 android.RegisterModuleType("art_cc_binary", artBinary)
351 android.RegisterModuleType("art_cc_test", artTest)
352 android.RegisterModuleType("art_cc_test_library", artTestLibrary)
353 android.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
Nicolas Geoffray8a229072018-05-10 16:34:14 +0100354 android.RegisterModuleType("libart_cc_defaults", libartDefaultsFactory)
Andreas Gampeec5ed062018-01-26 16:20:02 -0800355 android.RegisterModuleType("libart_static_cc_defaults", libartStaticDefaultsFactory)
Colin Cross96548c92016-10-12 14:26:55 -0700356 android.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
357 android.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory)
Alex Lightda948ce2018-12-06 17:05:41 +0000358
Ulyana Trafimovich7a20cbd2019-11-08 11:27:31 +0000359 // ART apex is special because it must include dexpreopt files for bootclasspath jars.
360 android.RegisterModuleType("art_apex", artApexBundleFactory)
361 android.RegisterModuleType("art_apex_test", artTestApexBundleFactory)
362
Alex Lightda948ce2018-12-06 17:05:41 +0000363 // TODO: This makes the module disable itself for host if HOST_PREFER_32_BIT is
364 // set. We need this because the multilib types of binaries listed in the apex
365 // rule must match the declared type. This is normally not difficult but HOST_PREFER_32_BIT
366 // changes this to 'prefer32' on all host binaries. Since HOST_PREFER_32_BIT is
367 // only used for testing we can just disable the module.
368 // See b/120617876 for more information.
Roland Levillain61f07162019-06-26 12:44:04 +0100369 android.RegisterModuleType("art_apex_test_host", artHostTestApexBundleFactory)
Alex Lightda948ce2018-12-06 17:05:41 +0000370}
371
Ulyana Trafimovich7a20cbd2019-11-08 11:27:31 +0000372func artApexBundleFactory() android.Module {
373 return apex.ApexBundleFactory(false /*testApex*/, true /*artApex*/)
374}
375
376func artTestApexBundleFactory() android.Module {
377 return apex.ApexBundleFactory(true /*testApex*/, true /*artApex*/)
378}
379
Roland Levillain61f07162019-06-26 12:44:04 +0100380func artHostTestApexBundleFactory() android.Module {
Ulyana Trafimovich7a20cbd2019-11-08 11:27:31 +0000381 module := apex.ApexBundleFactory(true /*testApex*/, true /*artApex*/)
Alex Lightda948ce2018-12-06 17:05:41 +0000382 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
Colin Crossdd3b7aa2019-07-31 13:47:39 -0700383 if ctx.Config().IsEnvTrue("HOST_PREFER_32_BIT") {
Alex Lightda948ce2018-12-06 17:05:41 +0000384 type props struct {
385 Target struct {
386 Host struct {
387 Enabled *bool
388 }
389 }
390 }
391
392 p := &props{}
393 p.Target.Host.Enabled = proptools.BoolPtr(false)
394 ctx.AppendProperties(p)
395 log.Print("Disabling host build of " + ctx.ModuleName() + " for HOST_PREFER_32_BIT=true")
396 }
397 })
398
399 return module
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700400}
401
Colin Crossca06ea32017-06-27 10:38:55 -0700402func artGlobalDefaultsFactory() android.Module {
403 module := artDefaultsFactory()
Martin Stjernholmb3092402020-09-04 00:49:44 +0100404 android.AddLoadHook(module, addImplicitFlags)
Colin Cross6e511782016-09-13 13:41:03 -0700405 android.AddLoadHook(module, globalDefaults)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700406
Colin Crossca06ea32017-06-27 10:38:55 -0700407 return module
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700408}
409
Colin Crossca06ea32017-06-27 10:38:55 -0700410func artDebugDefaultsFactory() android.Module {
411 module := artDefaultsFactory()
Colin Crossbe332ed2016-09-21 13:23:53 -0700412 android.AddLoadHook(module, debugDefaults)
413
Colin Crossca06ea32017-06-27 10:38:55 -0700414 return module
Colin Crossbe332ed2016-09-21 13:23:53 -0700415}
416
Colin Crossca06ea32017-06-27 10:38:55 -0700417func artDefaultsFactory() android.Module {
Colin Cross6e511782016-09-13 13:41:03 -0700418 c := &codegenProperties{}
Colin Crossca06ea32017-06-27 10:38:55 -0700419 module := cc.DefaultsFactory(c)
Colin Crossf383ed82019-09-24 15:02:23 -0700420 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, staticAndSharedLibrary) })
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700421
Colin Crossca06ea32017-06-27 10:38:55 -0700422 return module
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700423}
424
Nicolas Geoffray8a229072018-05-10 16:34:14 +0100425func libartDefaultsFactory() android.Module {
426 c := &codegenProperties{}
427 module := cc.DefaultsFactory(c)
Colin Crossf383ed82019-09-24 15:02:23 -0700428 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, staticAndSharedLibrary) })
Nicolas Geoffray8a229072018-05-10 16:34:14 +0100429
430 return module
431}
432
Andreas Gampeec5ed062018-01-26 16:20:02 -0800433func libartStaticDefaultsFactory() android.Module {
434 c := &codegenProperties{}
435 module := cc.DefaultsFactory(c)
Colin Crossf383ed82019-09-24 15:02:23 -0700436 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, staticLibrary) })
Andreas Gampeec5ed062018-01-26 16:20:02 -0800437
438 return module
439}
440
Colin Crossca06ea32017-06-27 10:38:55 -0700441func artLibrary() android.Module {
Paul Duffine78b50e2020-02-18 12:25:40 +0000442 module := cc.LibraryFactory()
Vladimir Marko74527972016-11-29 15:57:32 +0000443
Colin Crossf383ed82019-09-24 15:02:23 -0700444 installCodegenCustomizer(module, staticAndSharedLibrary)
Vladimir Marko74527972016-11-29 15:57:32 +0000445
Martin Stjernholmb3092402020-09-04 00:49:44 +0100446 android.AddLoadHook(module, addImplicitFlags)
David Srbecky1cf46a32020-06-22 15:39:00 +0100447 android.AddInstallHook(module, addTestcasesFile)
Vladimir Marko74527972016-11-29 15:57:32 +0000448 return module
449}
450
451func artStaticLibrary() android.Module {
Paul Duffine78b50e2020-02-18 12:25:40 +0000452 module := cc.LibraryStaticFactory()
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700453
Colin Crossf383ed82019-09-24 15:02:23 -0700454 installCodegenCustomizer(module, staticLibrary)
Colin Crossfe6064a2016-08-30 13:49:26 -0700455
Martin Stjernholmb3092402020-09-04 00:49:44 +0100456 android.AddLoadHook(module, addImplicitFlags)
Colin Crossca06ea32017-06-27 10:38:55 -0700457 return module
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700458}
459
Colin Crossca06ea32017-06-27 10:38:55 -0700460func artBinary() android.Module {
Paul Duffine78b50e2020-02-18 12:25:40 +0000461 module := cc.BinaryFactory()
Colin Cross123989f2016-09-07 14:12:50 -0700462
Martin Stjernholmb3092402020-09-04 00:49:44 +0100463 android.AddLoadHook(module, addImplicitFlags)
Colin Cross6e511782016-09-13 13:41:03 -0700464 android.AddLoadHook(module, customLinker)
465 android.AddLoadHook(module, prefer32Bit)
David Srbecky1cf46a32020-06-22 15:39:00 +0100466 android.AddInstallHook(module, addTestcasesFile)
Colin Crossca06ea32017-06-27 10:38:55 -0700467 return module
Colin Cross123989f2016-09-07 14:12:50 -0700468}
469
Colin Crossca06ea32017-06-27 10:38:55 -0700470func artTest() android.Module {
Paul Duffine78b50e2020-02-18 12:25:40 +0000471 module := cc.TestFactory()
Colin Crossc7376e02016-09-08 12:52:18 -0700472
Colin Crossf383ed82019-09-24 15:02:23 -0700473 installCodegenCustomizer(module, binary)
Colin Cross6e95dd52016-09-12 15:37:10 -0700474
Martin Stjernholmb3092402020-09-04 00:49:44 +0100475 android.AddLoadHook(module, addImplicitFlags)
Colin Cross6e511782016-09-13 13:41:03 -0700476 android.AddLoadHook(module, customLinker)
477 android.AddLoadHook(module, prefer32Bit)
Colin Cross6e95dd52016-09-12 15:37:10 -0700478 android.AddInstallHook(module, testInstall)
Colin Crossca06ea32017-06-27 10:38:55 -0700479 return module
Colin Crossc7376e02016-09-08 12:52:18 -0700480}
481
Colin Crossca06ea32017-06-27 10:38:55 -0700482func artTestLibrary() android.Module {
Paul Duffine78b50e2020-02-18 12:25:40 +0000483 module := cc.TestLibraryFactory()
Colin Crossafd3c9e2016-09-16 13:47:21 -0700484
Colin Crossf383ed82019-09-24 15:02:23 -0700485 installCodegenCustomizer(module, staticAndSharedLibrary)
Colin Crossafd3c9e2016-09-16 13:47:21 -0700486
Martin Stjernholmb3092402020-09-04 00:49:44 +0100487 android.AddLoadHook(module, addImplicitFlags)
Colin Crossafd3c9e2016-09-16 13:47:21 -0700488 android.AddLoadHook(module, prefer32Bit)
489 android.AddInstallHook(module, testInstall)
Colin Crossca06ea32017-06-27 10:38:55 -0700490 return module
Colin Crossafd3c9e2016-09-16 13:47:21 -0700491}