blob: e6157b43fbf75553d0a777a043e849008cdb1dd3 [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 "android/soong/android"
Alex Lightda948ce2018-12-06 17:05:41 +000019 "android/soong/apex"
Colin Cross1f7f3bd2016-07-27 10:12:38 -070020 "android/soong/cc"
21 "fmt"
Alex Lightda948ce2018-12-06 17:05:41 +000022 "log"
Colin Cross6e95dd52016-09-12 15:37:10 -070023 "sync"
Colin Cross84b69332017-11-01 14:23:17 -070024
25 "github.com/google/blueprint/proptools"
Colin Cross1f7f3bd2016-07-27 10:12:38 -070026)
27
28var supportedArches = []string{"arm", "arm64", "mips", "mips64", "x86", "x86_64"}
29
30func globalFlags(ctx android.BaseContext) ([]string, []string) {
31 var cflags []string
32 var asflags []string
33
Colin Crossbe332ed2016-09-21 13:23:53 -070034 opt := envDefault(ctx, "ART_NDEBUG_OPT_FLAG", "-O3")
35 cflags = append(cflags, opt)
36
Colin Cross1f7f3bd2016-07-27 10:12:38 -070037 tlab := false
38
39 gcType := envDefault(ctx, "ART_DEFAULT_GC_TYPE", "CMS")
40
41 if envTrue(ctx, "ART_TEST_DEBUG_GC") {
42 gcType = "SS"
43 tlab = true
44 }
45
46 cflags = append(cflags, "-DART_DEFAULT_GC_TYPE_IS_"+gcType)
47 if tlab {
48 cflags = append(cflags, "-DART_USE_TLAB=1")
49 }
50
51 imtSize := envDefault(ctx, "ART_IMT_SIZE", "43")
52 cflags = append(cflags, "-DIMT_SIZE="+imtSize)
53
54 if envTrue(ctx, "ART_HEAP_POISONING") {
55 cflags = append(cflags, "-DART_HEAP_POISONING=1")
56 asflags = append(asflags, "-DART_HEAP_POISONING=1")
57 }
David Srbecky8ed45c82018-11-08 15:08:57 +000058 if envTrue(ctx, "ART_USE_CXX_INTERPRETER") {
59 cflags = append(cflags, "-DART_USE_CXX_INTERPRETER=1")
60 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -070061
Hiroshi Yamauchida75ad72017-01-24 11:06:47 -080062 if !envFalse(ctx, "ART_USE_READ_BARRIER") && ctx.AConfig().ArtUseReadBarrier() {
Roland Levillainb81e9e92017-04-20 17:35:32 +010063 // Used to change the read barrier type. Valid values are BAKER, BROOKS,
64 // TABLELOOKUP. The default is BAKER.
Colin Cross1f7f3bd2016-07-27 10:12:38 -070065 barrierType := envDefault(ctx, "ART_READ_BARRIER_TYPE", "BAKER")
66 cflags = append(cflags,
67 "-DART_USE_READ_BARRIER=1",
68 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
69 asflags = append(asflags,
70 "-DART_USE_READ_BARRIER=1",
71 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
Colin Cross1f7f3bd2016-07-27 10:12:38 -070072 }
73
Roland Levillain95fb31e2018-08-29 13:08:11 +010074 if !envFalse(ctx, "ART_USE_GENERATIONAL_CC") {
Mathieu Chartier8d1a9962016-08-17 16:39:45 -070075 cflags = append(cflags, "-DART_USE_GENERATIONAL_CC=1")
76 }
77
78 cdexLevel := envDefault(ctx, "ART_DEFAULT_COMPACT_DEX_LEVEL", "fast")
79 cflags = append(cflags, "-DART_DEFAULT_COMPACT_DEX_LEVEL="+cdexLevel)
Mathieu Chartiera7f6b812017-12-11 13:34:29 -080080
Andreas Gampe655c6fd2017-05-24 21:42:10 -070081 // We need larger stack overflow guards for ASAN, as the compiled code will have
82 // larger frame sizes. For simplicity, just use global not-target-specific cflags.
83 // Note: We increase this for both debug and non-debug, as the overflow gap will
84 // be compiled into managed code. We always preopt (and build core images) with
85 // the debug version. So make the gap consistent (and adjust for the worst).
86 if len(ctx.AConfig().SanitizeDevice()) > 0 || len(ctx.AConfig().SanitizeHost()) > 0 {
87 cflags = append(cflags,
Colin Cross2db58b62017-06-27 10:38:31 -070088 "-DART_STACK_OVERFLOW_GAP_arm=8192",
89 "-DART_STACK_OVERFLOW_GAP_arm64=8192",
90 "-DART_STACK_OVERFLOW_GAP_mips=16384",
91 "-DART_STACK_OVERFLOW_GAP_mips64=16384",
92 "-DART_STACK_OVERFLOW_GAP_x86=16384",
93 "-DART_STACK_OVERFLOW_GAP_x86_64=20480")
Andreas Gampe655c6fd2017-05-24 21:42:10 -070094 } else {
95 cflags = append(cflags,
Colin Cross2db58b62017-06-27 10:38:31 -070096 "-DART_STACK_OVERFLOW_GAP_arm=8192",
97 "-DART_STACK_OVERFLOW_GAP_arm64=8192",
98 "-DART_STACK_OVERFLOW_GAP_mips=16384",
99 "-DART_STACK_OVERFLOW_GAP_mips64=16384",
100 "-DART_STACK_OVERFLOW_GAP_x86=8192",
101 "-DART_STACK_OVERFLOW_GAP_x86_64=8192")
Andreas Gampe655c6fd2017-05-24 21:42:10 -0700102 }
Andreas Gampebc9f10c2017-05-19 08:28:06 -0700103
Andreas Gampedbf0e0f2017-07-11 08:34:48 -0700104 if envTrue(ctx, "ART_ENABLE_ADDRESS_SANITIZER") {
105 // Used to enable full sanitization, i.e., user poisoning, under ASAN.
106 cflags = append(cflags, "-DART_ENABLE_ADDRESS_SANITIZER=1")
107 asflags = append(asflags, "-DART_ENABLE_ADDRESS_SANITIZER=1")
108 }
109
Chris Larsen715f43e2017-10-23 11:00:32 -0700110 if envTrue(ctx, "ART_MIPS32_CHECK_ALIGNMENT") {
111 // Enable the use of MIPS32 CHECK_ALIGNMENT macro for debugging purposes
112 asflags = append(asflags, "-DART_MIPS32_CHECK_ALIGNMENT")
113 }
114
Alan Leung50173eb2017-12-20 13:33:21 -0800115 if envTrueOrDefault(ctx, "USE_D8_DESUGAR") {
Alan Leung8f514ee2017-12-08 14:08:25 -0800116 cflags = append(cflags, "-DUSE_D8_DESUGAR=1")
117 }
118
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700119 return cflags, asflags
120}
121
Colin Crossbe332ed2016-09-21 13:23:53 -0700122func debugFlags(ctx android.BaseContext) []string {
123 var cflags []string
124
125 opt := envDefault(ctx, "ART_DEBUG_OPT_FLAG", "-O2")
126 cflags = append(cflags, opt)
127
128 return cflags
129}
130
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700131func deviceFlags(ctx android.BaseContext) []string {
132 var cflags []string
133 deviceFrameSizeLimit := 1736
134 if len(ctx.AConfig().SanitizeDevice()) > 0 {
Vishwath Mohan1ecc4fe2016-09-26 09:22:42 -0700135 deviceFrameSizeLimit = 7400
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700136 }
137 cflags = append(cflags,
138 fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit),
139 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit),
140 )
141
142 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgDeviceBaseAddress())
143 if envTrue(ctx, "ART_TARGET_LINUX") {
144 cflags = append(cflags, "-DART_TARGET_LINUX")
145 } else {
146 cflags = append(cflags, "-DART_TARGET_ANDROID")
147 }
148 minDelta := envDefault(ctx, "LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
149 maxDelta := envDefault(ctx, "LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000")
150 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
151 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
152
153 return cflags
154}
155
156func hostFlags(ctx android.BaseContext) []string {
157 var cflags []string
158 hostFrameSizeLimit := 1736
Colin Cross3174b682016-09-19 12:25:31 -0700159 if len(ctx.AConfig().SanitizeHost()) > 0 {
160 // art/test/137-cfi/cfi.cc
161 // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess'
David Srbecky9cc67b12018-10-25 10:10:35 +0000162 hostFrameSizeLimit = 6400
Colin Cross3174b682016-09-19 12:25:31 -0700163 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700164 cflags = append(cflags,
165 fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit),
166 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit),
167 )
168
169 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgHostBaseAddress())
170 minDelta := envDefault(ctx, "LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
171 maxDelta := envDefault(ctx, "LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000")
172 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
173 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
174
Andreas Gampefcc7d672017-07-19 10:30:22 -0700175 if len(ctx.AConfig().SanitizeHost()) > 0 && !envFalse(ctx, "ART_ENABLE_ADDRESS_SANITIZER") {
176 // We enable full sanitization on the host by default.
177 cflags = append(cflags, "-DART_ENABLE_ADDRESS_SANITIZER=1")
178 }
179
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700180 return cflags
181}
182
Colin Cross6e511782016-09-13 13:41:03 -0700183func globalDefaults(ctx android.LoadHookContext) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700184 type props struct {
185 Target struct {
186 Android struct {
187 Cflags []string
188 }
189 Host struct {
190 Cflags []string
191 }
192 }
Colin Cross2db58b62017-06-27 10:38:31 -0700193 Cflags []string
194 Asflags []string
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -0700195 Sanitize struct {
Colin Cross2db58b62017-06-27 10:38:31 -0700196 Recover []string
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -0700197 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700198 }
199
200 p := &props{}
201 p.Cflags, p.Asflags = globalFlags(ctx)
202 p.Target.Android.Cflags = deviceFlags(ctx)
203 p.Target.Host.Cflags = hostFlags(ctx)
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -0700204
205 if envTrue(ctx, "ART_DEX_FILE_ACCESS_TRACKING") {
206 p.Cflags = append(p.Cflags, "-DART_DEX_FILE_ACCESS_TRACKING")
Colin Cross2db58b62017-06-27 10:38:31 -0700207 p.Sanitize.Recover = []string{
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -0700208 "address",
209 }
210 }
211
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700212 ctx.AppendProperties(p)
Colin Crossfe6064a2016-08-30 13:49:26 -0700213}
Colin Cross6326d1b2016-09-06 10:24:28 -0700214
Colin Crossbe332ed2016-09-21 13:23:53 -0700215func debugDefaults(ctx android.LoadHookContext) {
216 type props struct {
217 Cflags []string
218 }
219
220 p := &props{}
221 p.Cflags = debugFlags(ctx)
222 ctx.AppendProperties(p)
223}
224
Colin Cross6e511782016-09-13 13:41:03 -0700225func customLinker(ctx android.LoadHookContext) {
Colin Crossfe6064a2016-08-30 13:49:26 -0700226 linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
Colin Cross84b69332017-11-01 14:23:17 -0700227 type props struct {
228 DynamicLinker string
Colin Crossfe6064a2016-08-30 13:49:26 -0700229 }
Colin Cross84b69332017-11-01 14:23:17 -0700230
231 p := &props{}
232 if linker != "" {
233 p.DynamicLinker = linker
234 }
235
236 ctx.AppendProperties(p)
Colin Crossfe6064a2016-08-30 13:49:26 -0700237}
238
Colin Cross6e511782016-09-13 13:41:03 -0700239func prefer32Bit(ctx android.LoadHookContext) {
Colin Cross84b69332017-11-01 14:23:17 -0700240 type props struct {
241 Target struct {
242 Host struct {
243 Compile_multilib *string
Colin Cross6326d1b2016-09-06 10:24:28 -0700244 }
245 }
Colin Cross6326d1b2016-09-06 10:24:28 -0700246 }
Colin Cross84b69332017-11-01 14:23:17 -0700247
248 p := &props{}
249 if envTrue(ctx, "HOST_PREFER_32_BIT") {
250 p.Target.Host.Compile_multilib = proptools.StringPtr("prefer32")
251 }
252
253 ctx.AppendProperties(p)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700254}
255
Colin Crossb81d22d2019-02-06 12:42:54 -0800256var testMapKey = android.NewOnceKey("artTests")
257
Colin Cross6e95dd52016-09-12 15:37:10 -0700258func testMap(config android.Config) map[string][]string {
Colin Crossb81d22d2019-02-06 12:42:54 -0800259 return config.Once(testMapKey, func() interface{} {
Colin Cross6e95dd52016-09-12 15:37:10 -0700260 return make(map[string][]string)
261 }).(map[string][]string)
262}
263
264func testInstall(ctx android.InstallHookContext) {
265 testMap := testMap(ctx.AConfig())
266
267 var name string
268 if ctx.Host() {
269 name = "host_"
270 } else {
271 name = "device_"
272 }
273 name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName()
274
275 artTestMutex.Lock()
276 defer artTestMutex.Unlock()
277
278 tests := testMap[name]
279 tests = append(tests, ctx.Path().RelPathString())
280 testMap[name] = tests
281}
282
283var artTestMutex sync.Mutex
284
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700285func init() {
Paul Duffin0c89d572019-06-27 14:21:12 +0100286 artModuleTypes := []string{
287 "art_cc_library",
288 "art_cc_library_static",
289 "art_cc_binary",
290 "art_cc_test",
291 "art_cc_test_library",
292 "art_cc_defaults",
293 "libart_cc_defaults",
294 "libart_static_cc_defaults",
295 "art_global_defaults",
296 "art_debug_defaults",
297 "art_apex_test",
298 }
299 android.AddNeverAllowRules(
300 android.NeverAllow().
301 NotIn("art", "external/vixl").
302 ModuleType(artModuleTypes...))
303
Colin Cross96548c92016-10-12 14:26:55 -0700304 android.RegisterModuleType("art_cc_library", artLibrary)
Steven Moreland73030ed2019-01-03 14:23:28 -0800305 android.RegisterModuleType("art_cc_library_static", artStaticLibrary)
Colin Cross96548c92016-10-12 14:26:55 -0700306 android.RegisterModuleType("art_cc_binary", artBinary)
307 android.RegisterModuleType("art_cc_test", artTest)
308 android.RegisterModuleType("art_cc_test_library", artTestLibrary)
309 android.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
Nicolas Geoffray8a229072018-05-10 16:34:14 +0100310 android.RegisterModuleType("libart_cc_defaults", libartDefaultsFactory)
Andreas Gampeec5ed062018-01-26 16:20:02 -0800311 android.RegisterModuleType("libart_static_cc_defaults", libartStaticDefaultsFactory)
Colin Cross96548c92016-10-12 14:26:55 -0700312 android.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
313 android.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory)
Alex Lightda948ce2018-12-06 17:05:41 +0000314
315 // TODO: This makes the module disable itself for host if HOST_PREFER_32_BIT is
316 // set. We need this because the multilib types of binaries listed in the apex
317 // rule must match the declared type. This is normally not difficult but HOST_PREFER_32_BIT
318 // changes this to 'prefer32' on all host binaries. Since HOST_PREFER_32_BIT is
319 // only used for testing we can just disable the module.
320 // See b/120617876 for more information.
Roland Levillain61f07162019-06-26 12:44:04 +0100321 android.RegisterModuleType("art_apex_test_host", artHostTestApexBundleFactory)
Alex Lightda948ce2018-12-06 17:05:41 +0000322}
323
Roland Levillain61f07162019-06-26 12:44:04 +0100324func artHostTestApexBundleFactory() android.Module {
Alex Light0239f2f2019-02-07 13:38:50 -0800325 module := apex.ApexBundleFactory( /*testApex*/ true)
Alex Lightda948ce2018-12-06 17:05:41 +0000326 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
327 if envTrue(ctx, "HOST_PREFER_32_BIT") {
328 type props struct {
329 Target struct {
330 Host struct {
331 Enabled *bool
332 }
333 }
334 }
335
336 p := &props{}
337 p.Target.Host.Enabled = proptools.BoolPtr(false)
338 ctx.AppendProperties(p)
339 log.Print("Disabling host build of " + ctx.ModuleName() + " for HOST_PREFER_32_BIT=true")
340 }
341 })
342
343 return module
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700344}
345
Colin Crossca06ea32017-06-27 10:38:55 -0700346func artGlobalDefaultsFactory() android.Module {
347 module := artDefaultsFactory()
Colin Cross6e511782016-09-13 13:41:03 -0700348 android.AddLoadHook(module, globalDefaults)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700349
Colin Crossca06ea32017-06-27 10:38:55 -0700350 return module
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700351}
352
Colin Crossca06ea32017-06-27 10:38:55 -0700353func artDebugDefaultsFactory() android.Module {
354 module := artDefaultsFactory()
Colin Crossbe332ed2016-09-21 13:23:53 -0700355 android.AddLoadHook(module, debugDefaults)
356
Colin Crossca06ea32017-06-27 10:38:55 -0700357 return module
Colin Crossbe332ed2016-09-21 13:23:53 -0700358}
359
Colin Crossca06ea32017-06-27 10:38:55 -0700360func artDefaultsFactory() android.Module {
Colin Cross6e511782016-09-13 13:41:03 -0700361 c := &codegenProperties{}
Colin Crossca06ea32017-06-27 10:38:55 -0700362 module := cc.DefaultsFactory(c)
Colin Cross6e95dd52016-09-12 15:37:10 -0700363 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) })
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700364
Colin Crossca06ea32017-06-27 10:38:55 -0700365 return module
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700366}
367
Nicolas Geoffray8a229072018-05-10 16:34:14 +0100368func libartDefaultsFactory() android.Module {
369 c := &codegenProperties{}
370 module := cc.DefaultsFactory(c)
Orion Hodsonb4113e32019-01-30 09:36:39 +0000371 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) })
Nicolas Geoffray8a229072018-05-10 16:34:14 +0100372
373 return module
374}
375
Andreas Gampeec5ed062018-01-26 16:20:02 -0800376func libartStaticDefaultsFactory() android.Module {
377 c := &codegenProperties{}
378 module := cc.DefaultsFactory(c)
Alex Light0239f2f2019-02-07 13:38:50 -0800379 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) })
Andreas Gampeec5ed062018-01-26 16:20:02 -0800380
381 return module
382}
383
Colin Crossca06ea32017-06-27 10:38:55 -0700384func artLibrary() android.Module {
Vladimir Marko74527972016-11-29 15:57:32 +0000385 m, _ := cc.NewLibrary(android.HostAndDeviceSupported)
386 module := m.Init()
387
388 installCodegenCustomizer(module, true)
389
390 return module
391}
392
393func artStaticLibrary() android.Module {
394 m, library := cc.NewLibrary(android.HostAndDeviceSupported)
395 library.BuildOnlyStatic()
396 module := m.Init()
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700397
Colin Crossca06ea32017-06-27 10:38:55 -0700398 installCodegenCustomizer(module, true)
Colin Crossfe6064a2016-08-30 13:49:26 -0700399
Colin Crossca06ea32017-06-27 10:38:55 -0700400 return module
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700401}
402
Colin Crossca06ea32017-06-27 10:38:55 -0700403func artBinary() android.Module {
Colin Cross123989f2016-09-07 14:12:50 -0700404 binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
Colin Crossca06ea32017-06-27 10:38:55 -0700405 module := binary.Init()
Colin Cross123989f2016-09-07 14:12:50 -0700406
Colin Cross6e511782016-09-13 13:41:03 -0700407 android.AddLoadHook(module, customLinker)
408 android.AddLoadHook(module, prefer32Bit)
Colin Crossca06ea32017-06-27 10:38:55 -0700409 return module
Colin Cross123989f2016-09-07 14:12:50 -0700410}
411
Colin Crossca06ea32017-06-27 10:38:55 -0700412func artTest() android.Module {
Colin Crossc7376e02016-09-08 12:52:18 -0700413 test := cc.NewTest(android.HostAndDeviceSupported)
Colin Crossca06ea32017-06-27 10:38:55 -0700414 module := test.Init()
Colin Crossc7376e02016-09-08 12:52:18 -0700415
Colin Crossca06ea32017-06-27 10:38:55 -0700416 installCodegenCustomizer(module, false)
Colin Cross6e95dd52016-09-12 15:37:10 -0700417
Colin Cross6e511782016-09-13 13:41:03 -0700418 android.AddLoadHook(module, customLinker)
419 android.AddLoadHook(module, prefer32Bit)
Colin Cross6e95dd52016-09-12 15:37:10 -0700420 android.AddInstallHook(module, testInstall)
Colin Crossca06ea32017-06-27 10:38:55 -0700421 return module
Colin Crossc7376e02016-09-08 12:52:18 -0700422}
423
Colin Crossca06ea32017-06-27 10:38:55 -0700424func artTestLibrary() android.Module {
Colin Crossafd3c9e2016-09-16 13:47:21 -0700425 test := cc.NewTestLibrary(android.HostAndDeviceSupported)
Colin Crossca06ea32017-06-27 10:38:55 -0700426 module := test.Init()
Colin Crossafd3c9e2016-09-16 13:47:21 -0700427
Colin Crossca06ea32017-06-27 10:38:55 -0700428 installCodegenCustomizer(module, false)
Colin Crossafd3c9e2016-09-16 13:47:21 -0700429
430 android.AddLoadHook(module, prefer32Bit)
431 android.AddInstallHook(module, testInstall)
Colin Crossca06ea32017-06-27 10:38:55 -0700432 return module
Colin Crossafd3c9e2016-09-16 13:47:21 -0700433}
434
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700435func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
436 ret := ctx.AConfig().Getenv(key)
437 if ret == "" {
438 return defaultValue
439 }
440 return ret
441}
442
443func envTrue(ctx android.BaseContext, key string) bool {
444 return ctx.AConfig().Getenv(key) == "true"
445}
David Brazdil7b49e6c2016-09-01 11:06:18 +0100446
447func envFalse(ctx android.BaseContext, key string) bool {
448 return ctx.AConfig().Getenv(key) == "false"
449}
Alan Leung50173eb2017-12-20 13:33:21 -0800450
451func envTrueOrDefault(ctx android.BaseContext, key string) bool {
452 return ctx.AConfig().Getenv(key) != "false"
453}