Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package art |
| 16 | |
| 17 | import ( |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 18 | "android/soong/android" |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 19 | "android/soong/apex" |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 20 | "android/soong/cc" |
| 21 | "fmt" |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 22 | "log" |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 23 | "sync" |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 24 | |
| 25 | "github.com/google/blueprint/proptools" |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | var supportedArches = []string{"arm", "arm64", "mips", "mips64", "x86", "x86_64"} |
| 29 | |
| 30 | func globalFlags(ctx android.BaseContext) ([]string, []string) { |
| 31 | var cflags []string |
| 32 | var asflags []string |
| 33 | |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 34 | opt := envDefault(ctx, "ART_NDEBUG_OPT_FLAG", "-O3") |
| 35 | cflags = append(cflags, opt) |
| 36 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 37 | 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 Srbecky | 8ed45c8 | 2018-11-08 15:08:57 +0000 | [diff] [blame] | 58 | if envTrue(ctx, "ART_USE_CXX_INTERPRETER") { |
| 59 | cflags = append(cflags, "-DART_USE_CXX_INTERPRETER=1") |
| 60 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 61 | |
Hiroshi Yamauchi | da75ad7 | 2017-01-24 11:06:47 -0800 | [diff] [blame] | 62 | if !envFalse(ctx, "ART_USE_READ_BARRIER") && ctx.AConfig().ArtUseReadBarrier() { |
Roland Levillain | b81e9e9 | 2017-04-20 17:35:32 +0100 | [diff] [blame] | 63 | // Used to change the read barrier type. Valid values are BAKER, BROOKS, |
| 64 | // TABLELOOKUP. The default is BAKER. |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 65 | 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 Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Roland Levillain | 95fb31e | 2018-08-29 13:08:11 +0100 | [diff] [blame] | 74 | if !envFalse(ctx, "ART_USE_GENERATIONAL_CC") { |
Mathieu Chartier | 8d1a996 | 2016-08-17 16:39:45 -0700 | [diff] [blame] | 75 | 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 Chartier | a7f6b81 | 2017-12-11 13:34:29 -0800 | [diff] [blame] | 80 | |
Andreas Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 81 | // 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 Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 88 | "-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 Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 94 | } else { |
| 95 | cflags = append(cflags, |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 96 | "-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 Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 102 | } |
Andreas Gampe | bc9f10c | 2017-05-19 08:28:06 -0700 | [diff] [blame] | 103 | |
Andreas Gampe | dbf0e0f | 2017-07-11 08:34:48 -0700 | [diff] [blame] | 104 | 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 Larsen | 715f43e | 2017-10-23 11:00:32 -0700 | [diff] [blame] | 110 | 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 Leung | 50173eb | 2017-12-20 13:33:21 -0800 | [diff] [blame] | 115 | if envTrueOrDefault(ctx, "USE_D8_DESUGAR") { |
Alan Leung | 8f514ee | 2017-12-08 14:08:25 -0800 | [diff] [blame] | 116 | cflags = append(cflags, "-DUSE_D8_DESUGAR=1") |
| 117 | } |
| 118 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 119 | return cflags, asflags |
| 120 | } |
| 121 | |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 122 | func 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 Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 131 | func deviceFlags(ctx android.BaseContext) []string { |
| 132 | var cflags []string |
| 133 | deviceFrameSizeLimit := 1736 |
| 134 | if len(ctx.AConfig().SanitizeDevice()) > 0 { |
Vishwath Mohan | 1ecc4fe | 2016-09-26 09:22:42 -0700 | [diff] [blame] | 135 | deviceFrameSizeLimit = 7400 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 136 | } |
| 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 | |
| 156 | func hostFlags(ctx android.BaseContext) []string { |
| 157 | var cflags []string |
| 158 | hostFrameSizeLimit := 1736 |
Colin Cross | 3174b68 | 2016-09-19 12:25:31 -0700 | [diff] [blame] | 159 | 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 Srbecky | 9cc67b1 | 2018-10-25 10:10:35 +0000 | [diff] [blame] | 162 | hostFrameSizeLimit = 6400 |
Colin Cross | 3174b68 | 2016-09-19 12:25:31 -0700 | [diff] [blame] | 163 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 164 | 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 Gampe | fcc7d67 | 2017-07-19 10:30:22 -0700 | [diff] [blame] | 175 | 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 Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 180 | return cflags |
| 181 | } |
| 182 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 183 | func globalDefaults(ctx android.LoadHookContext) { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 184 | type props struct { |
| 185 | Target struct { |
| 186 | Android struct { |
| 187 | Cflags []string |
| 188 | } |
| 189 | Host struct { |
| 190 | Cflags []string |
| 191 | } |
| 192 | } |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 193 | Cflags []string |
| 194 | Asflags []string |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 195 | Sanitize struct { |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 196 | Recover []string |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 197 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 198 | } |
| 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 Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 204 | |
| 205 | if envTrue(ctx, "ART_DEX_FILE_ACCESS_TRACKING") { |
| 206 | p.Cflags = append(p.Cflags, "-DART_DEX_FILE_ACCESS_TRACKING") |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 207 | p.Sanitize.Recover = []string{ |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 208 | "address", |
| 209 | } |
| 210 | } |
| 211 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 212 | ctx.AppendProperties(p) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 213 | } |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 214 | |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 215 | func 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 Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 225 | func customLinker(ctx android.LoadHookContext) { |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 226 | linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "") |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 227 | type props struct { |
| 228 | DynamicLinker string |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 229 | } |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 230 | |
| 231 | p := &props{} |
| 232 | if linker != "" { |
| 233 | p.DynamicLinker = linker |
| 234 | } |
| 235 | |
| 236 | ctx.AppendProperties(p) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 239 | func prefer32Bit(ctx android.LoadHookContext) { |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 240 | type props struct { |
| 241 | Target struct { |
| 242 | Host struct { |
| 243 | Compile_multilib *string |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 246 | } |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 247 | |
| 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 Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Colin Cross | b81d22d | 2019-02-06 12:42:54 -0800 | [diff] [blame] | 256 | var testMapKey = android.NewOnceKey("artTests") |
| 257 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 258 | func testMap(config android.Config) map[string][]string { |
Colin Cross | b81d22d | 2019-02-06 12:42:54 -0800 | [diff] [blame] | 259 | return config.Once(testMapKey, func() interface{} { |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 260 | return make(map[string][]string) |
| 261 | }).(map[string][]string) |
| 262 | } |
| 263 | |
| 264 | func 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 | |
| 283 | var artTestMutex sync.Mutex |
| 284 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 285 | func init() { |
Paul Duffin | 0c89d57 | 2019-06-27 14:21:12 +0100 | [diff] [blame] | 286 | 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 Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 304 | android.RegisterModuleType("art_cc_library", artLibrary) |
Steven Moreland | 73030ed | 2019-01-03 14:23:28 -0800 | [diff] [blame] | 305 | android.RegisterModuleType("art_cc_library_static", artStaticLibrary) |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 306 | 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 Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 310 | android.RegisterModuleType("libart_cc_defaults", libartDefaultsFactory) |
Andreas Gampe | ec5ed06 | 2018-01-26 16:20:02 -0800 | [diff] [blame] | 311 | android.RegisterModuleType("libart_static_cc_defaults", libartStaticDefaultsFactory) |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 312 | android.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory) |
| 313 | android.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory) |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 314 | |
| 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 Levillain | 61f0716 | 2019-06-26 12:44:04 +0100 | [diff] [blame] | 321 | android.RegisterModuleType("art_apex_test_host", artHostTestApexBundleFactory) |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Roland Levillain | 61f0716 | 2019-06-26 12:44:04 +0100 | [diff] [blame] | 324 | func artHostTestApexBundleFactory() android.Module { |
Alex Light | 0239f2f | 2019-02-07 13:38:50 -0800 | [diff] [blame] | 325 | module := apex.ApexBundleFactory( /*testApex*/ true) |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 326 | 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 Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 346 | func artGlobalDefaultsFactory() android.Module { |
| 347 | module := artDefaultsFactory() |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 348 | android.AddLoadHook(module, globalDefaults) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 349 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 350 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 353 | func artDebugDefaultsFactory() android.Module { |
| 354 | module := artDefaultsFactory() |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 355 | android.AddLoadHook(module, debugDefaults) |
| 356 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 357 | return module |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 360 | func artDefaultsFactory() android.Module { |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 361 | c := &codegenProperties{} |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 362 | module := cc.DefaultsFactory(c) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 363 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) }) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 364 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 365 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Nicolas Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 368 | func libartDefaultsFactory() android.Module { |
| 369 | c := &codegenProperties{} |
| 370 | module := cc.DefaultsFactory(c) |
Orion Hodson | b4113e3 | 2019-01-30 09:36:39 +0000 | [diff] [blame] | 371 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) }) |
Nicolas Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 372 | |
| 373 | return module |
| 374 | } |
| 375 | |
Andreas Gampe | ec5ed06 | 2018-01-26 16:20:02 -0800 | [diff] [blame] | 376 | func libartStaticDefaultsFactory() android.Module { |
| 377 | c := &codegenProperties{} |
| 378 | module := cc.DefaultsFactory(c) |
Alex Light | 0239f2f | 2019-02-07 13:38:50 -0800 | [diff] [blame] | 379 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) }) |
Andreas Gampe | ec5ed06 | 2018-01-26 16:20:02 -0800 | [diff] [blame] | 380 | |
| 381 | return module |
| 382 | } |
| 383 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 384 | func artLibrary() android.Module { |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 385 | m, _ := cc.NewLibrary(android.HostAndDeviceSupported) |
| 386 | module := m.Init() |
| 387 | |
| 388 | installCodegenCustomizer(module, true) |
| 389 | |
| 390 | return module |
| 391 | } |
| 392 | |
| 393 | func artStaticLibrary() android.Module { |
| 394 | m, library := cc.NewLibrary(android.HostAndDeviceSupported) |
| 395 | library.BuildOnlyStatic() |
| 396 | module := m.Init() |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 397 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 398 | installCodegenCustomizer(module, true) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 399 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 400 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 403 | func artBinary() android.Module { |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 404 | binary, _ := cc.NewBinary(android.HostAndDeviceSupported) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 405 | module := binary.Init() |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 406 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 407 | android.AddLoadHook(module, customLinker) |
| 408 | android.AddLoadHook(module, prefer32Bit) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 409 | return module |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 412 | func artTest() android.Module { |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 413 | test := cc.NewTest(android.HostAndDeviceSupported) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 414 | module := test.Init() |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 415 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 416 | installCodegenCustomizer(module, false) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 417 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 418 | android.AddLoadHook(module, customLinker) |
| 419 | android.AddLoadHook(module, prefer32Bit) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 420 | android.AddInstallHook(module, testInstall) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 421 | return module |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 424 | func artTestLibrary() android.Module { |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 425 | test := cc.NewTestLibrary(android.HostAndDeviceSupported) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 426 | module := test.Init() |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 427 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 428 | installCodegenCustomizer(module, false) |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 429 | |
| 430 | android.AddLoadHook(module, prefer32Bit) |
| 431 | android.AddInstallHook(module, testInstall) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 432 | return module |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 435 | func 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 | |
| 443 | func envTrue(ctx android.BaseContext, key string) bool { |
| 444 | return ctx.AConfig().Getenv(key) == "true" |
| 445 | } |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 446 | |
| 447 | func envFalse(ctx android.BaseContext, key string) bool { |
| 448 | return ctx.AConfig().Getenv(key) == "false" |
| 449 | } |
Alan Leung | 50173eb | 2017-12-20 13:33:21 -0800 | [diff] [blame] | 450 | |
| 451 | func envTrueOrDefault(ctx android.BaseContext, key string) bool { |
| 452 | return ctx.AConfig().Getenv(key) != "false" |
| 453 | } |