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 | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 256 | func testMap(config android.Config) map[string][]string { |
| 257 | return config.Once("artTests", func() interface{} { |
| 258 | return make(map[string][]string) |
| 259 | }).(map[string][]string) |
| 260 | } |
| 261 | |
| 262 | func testInstall(ctx android.InstallHookContext) { |
| 263 | testMap := testMap(ctx.AConfig()) |
| 264 | |
| 265 | var name string |
| 266 | if ctx.Host() { |
| 267 | name = "host_" |
| 268 | } else { |
| 269 | name = "device_" |
| 270 | } |
| 271 | name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName() |
| 272 | |
| 273 | artTestMutex.Lock() |
| 274 | defer artTestMutex.Unlock() |
| 275 | |
| 276 | tests := testMap[name] |
| 277 | tests = append(tests, ctx.Path().RelPathString()) |
| 278 | testMap[name] = tests |
| 279 | } |
| 280 | |
| 281 | var artTestMutex sync.Mutex |
| 282 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 283 | func init() { |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 284 | android.RegisterModuleType("art_cc_library", artLibrary) |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 285 | android.RegisterModuleType("art_cc_static_library", artStaticLibrary) |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 286 | android.RegisterModuleType("art_cc_binary", artBinary) |
| 287 | android.RegisterModuleType("art_cc_test", artTest) |
| 288 | android.RegisterModuleType("art_cc_test_library", artTestLibrary) |
| 289 | android.RegisterModuleType("art_cc_defaults", artDefaultsFactory) |
Nicolas Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 290 | android.RegisterModuleType("libart_cc_defaults", libartDefaultsFactory) |
Andreas Gampe | ec5ed06 | 2018-01-26 16:20:02 -0800 | [diff] [blame] | 291 | android.RegisterModuleType("libart_static_cc_defaults", libartStaticDefaultsFactory) |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 292 | android.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory) |
| 293 | android.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory) |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 294 | |
| 295 | // TODO: This makes the module disable itself for host if HOST_PREFER_32_BIT is |
| 296 | // set. We need this because the multilib types of binaries listed in the apex |
| 297 | // rule must match the declared type. This is normally not difficult but HOST_PREFER_32_BIT |
| 298 | // changes this to 'prefer32' on all host binaries. Since HOST_PREFER_32_BIT is |
| 299 | // only used for testing we can just disable the module. |
| 300 | // See b/120617876 for more information. |
| 301 | android.RegisterModuleType("art_apex", artApexBundleFactory) |
| 302 | } |
| 303 | |
| 304 | func artApexBundleFactory() android.Module { |
| 305 | module := apex.ApexBundleFactory() |
| 306 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 307 | if envTrue(ctx, "HOST_PREFER_32_BIT") { |
| 308 | type props struct { |
| 309 | Target struct { |
| 310 | Host struct { |
| 311 | Enabled *bool |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | p := &props{} |
| 317 | p.Target.Host.Enabled = proptools.BoolPtr(false) |
| 318 | ctx.AppendProperties(p) |
| 319 | log.Print("Disabling host build of " + ctx.ModuleName() + " for HOST_PREFER_32_BIT=true") |
| 320 | } |
| 321 | }) |
| 322 | |
| 323 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 326 | func artGlobalDefaultsFactory() android.Module { |
| 327 | module := artDefaultsFactory() |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 328 | android.AddLoadHook(module, globalDefaults) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 329 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 330 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 333 | func artDebugDefaultsFactory() android.Module { |
| 334 | module := artDefaultsFactory() |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 335 | android.AddLoadHook(module, debugDefaults) |
| 336 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 337 | return module |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 340 | func artDefaultsFactory() android.Module { |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 341 | c := &codegenProperties{} |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 342 | module := cc.DefaultsFactory(c) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 343 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) }) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 344 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 345 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Nicolas Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 348 | func libartDefaultsFactory() android.Module { |
| 349 | c := &codegenProperties{} |
| 350 | module := cc.DefaultsFactory(c) |
| 351 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 352 | codegen(ctx, c, true) |
| 353 | |
| 354 | type props struct { |
Mathieu Chartier | 8d1a996 | 2016-08-17 16:39:45 -0700 | [diff] [blame] | 355 | Target struct { |
| 356 | Android struct { |
| 357 | Shared_libs []string |
| 358 | } |
| 359 | } |
Nicolas Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | p := &props{} |
| 363 | // TODO: express this in .bp instead b/79671158 |
| 364 | if !envTrue(ctx, "ART_TARGET_LINUX") { |
Mathieu Chartier | 8d1a996 | 2016-08-17 16:39:45 -0700 | [diff] [blame] | 365 | p.Target.Android.Shared_libs = []string{ |
| 366 | "libmetricslogger", |
| 367 | } |
Nicolas Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 368 | } |
| 369 | ctx.AppendProperties(p) |
| 370 | }) |
| 371 | |
| 372 | return module |
| 373 | } |
| 374 | |
Andreas Gampe | ec5ed06 | 2018-01-26 16:20:02 -0800 | [diff] [blame] | 375 | func libartStaticDefaultsFactory() android.Module { |
| 376 | c := &codegenProperties{} |
| 377 | module := cc.DefaultsFactory(c) |
| 378 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 379 | codegen(ctx, c, true) |
| 380 | |
| 381 | type props struct { |
| 382 | Target struct { |
| 383 | Android struct { |
| 384 | Static_libs []string |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | p := &props{} |
| 390 | // TODO: express this in .bp instead b/79671158 |
| 391 | if !envTrue(ctx, "ART_TARGET_LINUX") { |
| 392 | p.Target.Android.Static_libs = []string{ |
Howard Ro | 5c8d476 | 2018-10-23 00:42:09 +0000 | [diff] [blame] | 393 | "libmetricslogger", |
| 394 | "libstatssocket", |
Andreas Gampe | ec5ed06 | 2018-01-26 16:20:02 -0800 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | ctx.AppendProperties(p) |
| 398 | }) |
| 399 | |
| 400 | return module |
| 401 | } |
| 402 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 403 | func artLibrary() android.Module { |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 404 | m, _ := cc.NewLibrary(android.HostAndDeviceSupported) |
| 405 | module := m.Init() |
| 406 | |
| 407 | installCodegenCustomizer(module, true) |
| 408 | |
| 409 | return module |
| 410 | } |
| 411 | |
| 412 | func artStaticLibrary() android.Module { |
| 413 | m, library := cc.NewLibrary(android.HostAndDeviceSupported) |
| 414 | library.BuildOnlyStatic() |
| 415 | module := m.Init() |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 416 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 417 | installCodegenCustomizer(module, true) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 418 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 419 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 422 | func artBinary() android.Module { |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 423 | binary, _ := cc.NewBinary(android.HostAndDeviceSupported) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 424 | module := binary.Init() |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 425 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 426 | android.AddLoadHook(module, customLinker) |
| 427 | android.AddLoadHook(module, prefer32Bit) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 428 | return module |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 431 | func artTest() android.Module { |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 432 | test := cc.NewTest(android.HostAndDeviceSupported) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 433 | module := test.Init() |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 434 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 435 | installCodegenCustomizer(module, false) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 436 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 437 | android.AddLoadHook(module, customLinker) |
| 438 | android.AddLoadHook(module, prefer32Bit) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 439 | android.AddInstallHook(module, testInstall) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 440 | return module |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 443 | func artTestLibrary() android.Module { |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 444 | test := cc.NewTestLibrary(android.HostAndDeviceSupported) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 445 | module := test.Init() |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 446 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 447 | installCodegenCustomizer(module, false) |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 448 | |
| 449 | android.AddLoadHook(module, prefer32Bit) |
| 450 | android.AddInstallHook(module, testInstall) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 451 | return module |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 454 | func envDefault(ctx android.BaseContext, key string, defaultValue string) string { |
| 455 | ret := ctx.AConfig().Getenv(key) |
| 456 | if ret == "" { |
| 457 | return defaultValue |
| 458 | } |
| 459 | return ret |
| 460 | } |
| 461 | |
| 462 | func envTrue(ctx android.BaseContext, key string) bool { |
| 463 | return ctx.AConfig().Getenv(key) == "true" |
| 464 | } |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 465 | |
| 466 | func envFalse(ctx android.BaseContext, key string) bool { |
| 467 | return ctx.AConfig().Getenv(key) == "false" |
| 468 | } |
Alan Leung | 50173eb | 2017-12-20 13:33:21 -0800 | [diff] [blame] | 469 | |
| 470 | func envTrueOrDefault(ctx android.BaseContext, key string) bool { |
| 471 | return ctx.AConfig().Getenv(key) != "false" |
| 472 | } |