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 | "fmt" |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 19 | "log" |
David Srbecky | 1cf46a3 | 2020-06-22 15:39:00 +0100 | [diff] [blame] | 20 | "strings" |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 21 | "sync" |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 22 | |
| 23 | "github.com/google/blueprint/proptools" |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 24 | |
| 25 | "android/soong/android" |
| 26 | "android/soong/apex" |
| 27 | "android/soong/cc" |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 28 | ) |
| 29 | |
Vladimir Marko | be0d3cf | 2020-02-12 10:52:22 +0000 | [diff] [blame] | 30 | var supportedArches = []string{"arm", "arm64", "x86", "x86_64"} |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 31 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 32 | func globalFlags(ctx android.LoadHookContext) ([]string, []string) { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 33 | var cflags []string |
| 34 | var asflags []string |
| 35 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 36 | opt := ctx.Config().GetenvWithDefault("ART_NDEBUG_OPT_FLAG", "-O3") |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 37 | cflags = append(cflags, opt) |
| 38 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 39 | tlab := false |
| 40 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 41 | gcType := ctx.Config().GetenvWithDefault("ART_DEFAULT_GC_TYPE", "CMS") |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 42 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 43 | if ctx.Config().IsEnvTrue("ART_TEST_DEBUG_GC") { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 44 | gcType = "SS" |
| 45 | tlab = true |
| 46 | } |
| 47 | |
| 48 | cflags = append(cflags, "-DART_DEFAULT_GC_TYPE_IS_"+gcType) |
| 49 | if tlab { |
| 50 | cflags = append(cflags, "-DART_USE_TLAB=1") |
| 51 | } |
| 52 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 53 | if ctx.Config().IsEnvTrue("ART_HEAP_POISONING") { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 54 | cflags = append(cflags, "-DART_HEAP_POISONING=1") |
| 55 | asflags = append(asflags, "-DART_HEAP_POISONING=1") |
| 56 | } |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 57 | if ctx.Config().IsEnvTrue("ART_USE_CXX_INTERPRETER") { |
David Srbecky | 8ed45c8 | 2018-11-08 15:08:57 +0000 | [diff] [blame] | 58 | cflags = append(cflags, "-DART_USE_CXX_INTERPRETER=1") |
| 59 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 60 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 61 | if !ctx.Config().IsEnvFalse("ART_USE_READ_BARRIER") && ctx.Config().ArtUseReadBarrier() { |
Roland Levillain | b81e9e9 | 2017-04-20 17:35:32 +0100 | [diff] [blame] | 62 | // Used to change the read barrier type. Valid values are BAKER, BROOKS, |
| 63 | // TABLELOOKUP. The default is BAKER. |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 64 | barrierType := ctx.Config().GetenvWithDefault("ART_READ_BARRIER_TYPE", "BAKER") |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 65 | cflags = append(cflags, |
| 66 | "-DART_USE_READ_BARRIER=1", |
| 67 | "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1") |
| 68 | asflags = append(asflags, |
| 69 | "-DART_USE_READ_BARRIER=1", |
| 70 | "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1") |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 73 | if !ctx.Config().IsEnvFalse("ART_USE_GENERATIONAL_CC") { |
Mathieu Chartier | 8d1a996 | 2016-08-17 16:39:45 -0700 | [diff] [blame] | 74 | cflags = append(cflags, "-DART_USE_GENERATIONAL_CC=1") |
| 75 | } |
| 76 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 77 | cdexLevel := ctx.Config().GetenvWithDefault("ART_DEFAULT_COMPACT_DEX_LEVEL", "fast") |
Mathieu Chartier | 8d1a996 | 2016-08-17 16:39:45 -0700 | [diff] [blame] | 78 | cflags = append(cflags, "-DART_DEFAULT_COMPACT_DEX_LEVEL="+cdexLevel) |
Mathieu Chartier | a7f6b81 | 2017-12-11 13:34:29 -0800 | [diff] [blame] | 79 | |
Andreas Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 80 | // We need larger stack overflow guards for ASAN, as the compiled code will have |
| 81 | // larger frame sizes. For simplicity, just use global not-target-specific cflags. |
| 82 | // Note: We increase this for both debug and non-debug, as the overflow gap will |
| 83 | // be compiled into managed code. We always preopt (and build core images) with |
| 84 | // the debug version. So make the gap consistent (and adjust for the worst). |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 85 | if len(ctx.Config().SanitizeDevice()) > 0 || len(ctx.Config().SanitizeHost()) > 0 { |
Andreas Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 86 | cflags = append(cflags, |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 87 | "-DART_STACK_OVERFLOW_GAP_arm=8192", |
Evgenii Stepanov | 9e3954d | 2019-09-12 15:58:52 -0700 | [diff] [blame] | 88 | "-DART_STACK_OVERFLOW_GAP_arm64=16384", |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 89 | "-DART_STACK_OVERFLOW_GAP_x86=16384", |
| 90 | "-DART_STACK_OVERFLOW_GAP_x86_64=20480") |
Andreas Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 91 | } else { |
| 92 | cflags = append(cflags, |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 93 | "-DART_STACK_OVERFLOW_GAP_arm=8192", |
| 94 | "-DART_STACK_OVERFLOW_GAP_arm64=8192", |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 95 | "-DART_STACK_OVERFLOW_GAP_x86=8192", |
| 96 | "-DART_STACK_OVERFLOW_GAP_x86_64=8192") |
Andreas Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 97 | } |
Andreas Gampe | bc9f10c | 2017-05-19 08:28:06 -0700 | [diff] [blame] | 98 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 99 | if ctx.Config().IsEnvTrue("ART_ENABLE_ADDRESS_SANITIZER") { |
Andreas Gampe | dbf0e0f | 2017-07-11 08:34:48 -0700 | [diff] [blame] | 100 | // Used to enable full sanitization, i.e., user poisoning, under ASAN. |
| 101 | cflags = append(cflags, "-DART_ENABLE_ADDRESS_SANITIZER=1") |
| 102 | asflags = append(asflags, "-DART_ENABLE_ADDRESS_SANITIZER=1") |
| 103 | } |
| 104 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 105 | if !ctx.Config().IsEnvFalse("USE_D8_DESUGAR") { |
Alan Leung | 8f514ee | 2017-12-08 14:08:25 -0800 | [diff] [blame] | 106 | cflags = append(cflags, "-DUSE_D8_DESUGAR=1") |
| 107 | } |
| 108 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 109 | return cflags, asflags |
| 110 | } |
| 111 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 112 | func debugFlags(ctx android.LoadHookContext) []string { |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 113 | var cflags []string |
| 114 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 115 | opt := ctx.Config().GetenvWithDefault("ART_DEBUG_OPT_FLAG", "-O2") |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 116 | cflags = append(cflags, opt) |
| 117 | |
| 118 | return cflags |
| 119 | } |
| 120 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 121 | func deviceFlags(ctx android.LoadHookContext) []string { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 122 | var cflags []string |
| 123 | deviceFrameSizeLimit := 1736 |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 124 | if len(ctx.Config().SanitizeDevice()) > 0 { |
Vishwath Mohan | 1ecc4fe | 2016-09-26 09:22:42 -0700 | [diff] [blame] | 125 | deviceFrameSizeLimit = 7400 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 126 | } |
| 127 | cflags = append(cflags, |
| 128 | fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit), |
| 129 | fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit), |
| 130 | ) |
| 131 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 132 | cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.Config().LibartImgDeviceBaseAddress()) |
| 133 | if ctx.Config().IsEnvTrue("ART_TARGET_LINUX") { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 134 | cflags = append(cflags, "-DART_TARGET_LINUX") |
| 135 | } else { |
| 136 | cflags = append(cflags, "-DART_TARGET_ANDROID") |
| 137 | } |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 138 | minDelta := ctx.Config().GetenvWithDefault("LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000") |
| 139 | maxDelta := ctx.Config().GetenvWithDefault("LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000") |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 140 | cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta) |
| 141 | cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta) |
| 142 | |
| 143 | return cflags |
| 144 | } |
| 145 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 146 | func hostFlags(ctx android.LoadHookContext) []string { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 147 | var cflags []string |
| 148 | hostFrameSizeLimit := 1736 |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 149 | if len(ctx.Config().SanitizeHost()) > 0 { |
Colin Cross | 3174b68 | 2016-09-19 12:25:31 -0700 | [diff] [blame] | 150 | // art/test/137-cfi/cfi.cc |
| 151 | // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess' |
David Srbecky | 9cc67b1 | 2018-10-25 10:10:35 +0000 | [diff] [blame] | 152 | hostFrameSizeLimit = 6400 |
Colin Cross | 3174b68 | 2016-09-19 12:25:31 -0700 | [diff] [blame] | 153 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 154 | cflags = append(cflags, |
| 155 | fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit), |
| 156 | fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit), |
| 157 | ) |
| 158 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 159 | cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.Config().LibartImgHostBaseAddress()) |
| 160 | minDelta := ctx.Config().GetenvWithDefault("LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000") |
| 161 | maxDelta := ctx.Config().GetenvWithDefault("LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000") |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 162 | cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta) |
| 163 | cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta) |
| 164 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 165 | if len(ctx.Config().SanitizeHost()) > 0 && !ctx.Config().IsEnvFalse("ART_ENABLE_ADDRESS_SANITIZER") { |
Andreas Gampe | fcc7d67 | 2017-07-19 10:30:22 -0700 | [diff] [blame] | 166 | // We enable full sanitization on the host by default. |
| 167 | cflags = append(cflags, "-DART_ENABLE_ADDRESS_SANITIZER=1") |
| 168 | } |
| 169 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 170 | return cflags |
| 171 | } |
| 172 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 173 | func globalDefaults(ctx android.LoadHookContext) { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 174 | type props struct { |
| 175 | Target struct { |
| 176 | Android struct { |
| 177 | Cflags []string |
| 178 | } |
| 179 | Host struct { |
| 180 | Cflags []string |
| 181 | } |
| 182 | } |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 183 | Cflags []string |
| 184 | Asflags []string |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 185 | Sanitize struct { |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 186 | Recover []string |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 187 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 188 | } |
| 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 Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 194 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 195 | if ctx.Config().IsEnvTrue("ART_DEX_FILE_ACCESS_TRACKING") { |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 196 | p.Cflags = append(p.Cflags, "-DART_DEX_FILE_ACCESS_TRACKING") |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 197 | p.Sanitize.Recover = []string{ |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 198 | "address", |
| 199 | } |
| 200 | } |
| 201 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 202 | ctx.AppendProperties(p) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 203 | } |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 204 | |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 205 | func debugDefaults(ctx android.LoadHookContext) { |
| 206 | type props struct { |
| 207 | Cflags []string |
| 208 | } |
| 209 | |
| 210 | p := &props{} |
| 211 | p.Cflags = debugFlags(ctx) |
| 212 | ctx.AppendProperties(p) |
| 213 | } |
| 214 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 215 | func customLinker(ctx android.LoadHookContext) { |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 216 | linker := ctx.Config().Getenv("CUSTOM_TARGET_LINKER") |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 217 | type props struct { |
| 218 | DynamicLinker string |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 219 | } |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 220 | |
| 221 | p := &props{} |
| 222 | if linker != "" { |
| 223 | p.DynamicLinker = linker |
| 224 | } |
| 225 | |
| 226 | ctx.AppendProperties(p) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 229 | func prefer32Bit(ctx android.LoadHookContext) { |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 230 | type props struct { |
| 231 | Target struct { |
| 232 | Host struct { |
| 233 | Compile_multilib *string |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 236 | } |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 237 | |
| 238 | p := &props{} |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 239 | if ctx.Config().IsEnvTrue("HOST_PREFER_32_BIT") { |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 240 | p.Target.Host.Compile_multilib = proptools.StringPtr("prefer32") |
| 241 | } |
| 242 | |
Martin Stjernholm | e1a4451 | 2020-01-31 22:43:43 +0000 | [diff] [blame] | 243 | // Prepend to make it overridable in the blueprints. Note that it doesn't work |
| 244 | // to override the property in a cc_defaults module. |
| 245 | ctx.PrependProperties(p) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Colin Cross | b81d22d | 2019-02-06 12:42:54 -0800 | [diff] [blame] | 248 | var testMapKey = android.NewOnceKey("artTests") |
| 249 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 250 | func testMap(config android.Config) map[string][]string { |
Colin Cross | b81d22d | 2019-02-06 12:42:54 -0800 | [diff] [blame] | 251 | return config.Once(testMapKey, func() interface{} { |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 252 | return make(map[string][]string) |
| 253 | }).(map[string][]string) |
| 254 | } |
| 255 | |
| 256 | func testInstall(ctx android.InstallHookContext) { |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 257 | testMap := testMap(ctx.Config()) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 258 | |
| 259 | var name string |
| 260 | if ctx.Host() { |
| 261 | name = "host_" |
| 262 | } else { |
| 263 | name = "device_" |
| 264 | } |
| 265 | name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName() |
| 266 | |
| 267 | artTestMutex.Lock() |
| 268 | defer artTestMutex.Unlock() |
| 269 | |
| 270 | tests := testMap[name] |
Colin Cross | 8307206 | 2019-10-02 16:06:58 -0700 | [diff] [blame] | 271 | tests = append(tests, ctx.Path().ToMakePath().String()) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 272 | testMap[name] = tests |
| 273 | } |
| 274 | |
David Srbecky | 1cf46a3 | 2020-06-22 15:39:00 +0100 | [diff] [blame] | 275 | var testcasesContentKey = android.NewOnceKey("artTestcasesContent") |
| 276 | |
| 277 | func testcasesContent(config android.Config) map[string]string { |
| 278 | return config.Once(testcasesContentKey, func() interface{} { |
| 279 | return make(map[string]string) |
| 280 | }).(map[string]string) |
| 281 | } |
| 282 | |
| 283 | // Binaries and libraries also need to be copied in the testcases directory for |
| 284 | // running tests on host. This method adds module to the list of needed files. |
| 285 | // The 'key' is the file in testcases and 'value' is the path to copy it from. |
| 286 | // The actual copy will be done in make since soong does not do installations. |
| 287 | func addTestcasesFile(ctx android.InstallHookContext) { |
| 288 | testcasesContent := testcasesContent(ctx.Config()) |
| 289 | |
| 290 | artTestMutex.Lock() |
| 291 | defer artTestMutex.Unlock() |
| 292 | |
| 293 | if ctx.Os().Class == android.Host { |
David Srbecky | b0713ca | 2020-07-01 15:04:39 +0100 | [diff] [blame] | 294 | src := ctx.SrcPath().String() |
| 295 | path := strings.Split(ctx.Path().ToMakePath().String(), "/") |
| 296 | // Keep last two parts of the install path (e.g. bin/dex2oat). |
| 297 | dst := strings.Join(path[len(path)-2:], "/") |
| 298 | testcasesContent[dst] = src |
David Srbecky | 1cf46a3 | 2020-06-22 15:39:00 +0100 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 302 | var artTestMutex sync.Mutex |
| 303 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 304 | func init() { |
Paul Duffin | 0c89d57 | 2019-06-27 14:21:12 +0100 | [diff] [blame] | 305 | artModuleTypes := []string{ |
| 306 | "art_cc_library", |
| 307 | "art_cc_library_static", |
| 308 | "art_cc_binary", |
| 309 | "art_cc_test", |
| 310 | "art_cc_test_library", |
| 311 | "art_cc_defaults", |
| 312 | "libart_cc_defaults", |
| 313 | "libart_static_cc_defaults", |
| 314 | "art_global_defaults", |
| 315 | "art_debug_defaults", |
Roland Levillain | 4fb71cc | 2019-09-11 18:39:59 +0100 | [diff] [blame] | 316 | "art_apex_test_host", |
Paul Duffin | 0c89d57 | 2019-06-27 14:21:12 +0100 | [diff] [blame] | 317 | } |
| 318 | android.AddNeverAllowRules( |
| 319 | android.NeverAllow(). |
| 320 | NotIn("art", "external/vixl"). |
| 321 | ModuleType(artModuleTypes...)) |
| 322 | |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 323 | android.RegisterModuleType("art_cc_library", artLibrary) |
Steven Moreland | 73030ed | 2019-01-03 14:23:28 -0800 | [diff] [blame] | 324 | android.RegisterModuleType("art_cc_library_static", artStaticLibrary) |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 325 | android.RegisterModuleType("art_cc_binary", artBinary) |
| 326 | android.RegisterModuleType("art_cc_test", artTest) |
| 327 | android.RegisterModuleType("art_cc_test_library", artTestLibrary) |
| 328 | android.RegisterModuleType("art_cc_defaults", artDefaultsFactory) |
Nicolas Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 329 | android.RegisterModuleType("libart_cc_defaults", libartDefaultsFactory) |
Andreas Gampe | ec5ed06 | 2018-01-26 16:20:02 -0800 | [diff] [blame] | 330 | android.RegisterModuleType("libart_static_cc_defaults", libartStaticDefaultsFactory) |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 331 | android.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory) |
| 332 | android.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory) |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 333 | |
Ulyana Trafimovich | 7a20cbd | 2019-11-08 11:27:31 +0000 | [diff] [blame] | 334 | // ART apex is special because it must include dexpreopt files for bootclasspath jars. |
| 335 | android.RegisterModuleType("art_apex", artApexBundleFactory) |
| 336 | android.RegisterModuleType("art_apex_test", artTestApexBundleFactory) |
| 337 | |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 338 | // TODO: This makes the module disable itself for host if HOST_PREFER_32_BIT is |
| 339 | // set. We need this because the multilib types of binaries listed in the apex |
| 340 | // rule must match the declared type. This is normally not difficult but HOST_PREFER_32_BIT |
| 341 | // changes this to 'prefer32' on all host binaries. Since HOST_PREFER_32_BIT is |
| 342 | // only used for testing we can just disable the module. |
| 343 | // See b/120617876 for more information. |
Roland Levillain | 61f0716 | 2019-06-26 12:44:04 +0100 | [diff] [blame] | 344 | android.RegisterModuleType("art_apex_test_host", artHostTestApexBundleFactory) |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 345 | } |
| 346 | |
Ulyana Trafimovich | 7a20cbd | 2019-11-08 11:27:31 +0000 | [diff] [blame] | 347 | func artApexBundleFactory() android.Module { |
| 348 | return apex.ApexBundleFactory(false /*testApex*/, true /*artApex*/) |
| 349 | } |
| 350 | |
| 351 | func artTestApexBundleFactory() android.Module { |
| 352 | return apex.ApexBundleFactory(true /*testApex*/, true /*artApex*/) |
| 353 | } |
| 354 | |
Roland Levillain | 61f0716 | 2019-06-26 12:44:04 +0100 | [diff] [blame] | 355 | func artHostTestApexBundleFactory() android.Module { |
Ulyana Trafimovich | 7a20cbd | 2019-11-08 11:27:31 +0000 | [diff] [blame] | 356 | module := apex.ApexBundleFactory(true /*testApex*/, true /*artApex*/) |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 357 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 358 | if ctx.Config().IsEnvTrue("HOST_PREFER_32_BIT") { |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 359 | type props struct { |
| 360 | Target struct { |
| 361 | Host struct { |
| 362 | Enabled *bool |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | p := &props{} |
| 368 | p.Target.Host.Enabled = proptools.BoolPtr(false) |
| 369 | ctx.AppendProperties(p) |
| 370 | log.Print("Disabling host build of " + ctx.ModuleName() + " for HOST_PREFER_32_BIT=true") |
| 371 | } |
| 372 | }) |
| 373 | |
| 374 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 377 | func artGlobalDefaultsFactory() android.Module { |
| 378 | module := artDefaultsFactory() |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 379 | android.AddLoadHook(module, globalDefaults) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 380 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 381 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 384 | func artDebugDefaultsFactory() android.Module { |
| 385 | module := artDefaultsFactory() |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 386 | android.AddLoadHook(module, debugDefaults) |
| 387 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 388 | return module |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 391 | func artDefaultsFactory() android.Module { |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 392 | c := &codegenProperties{} |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 393 | module := cc.DefaultsFactory(c) |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 394 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, staticAndSharedLibrary) }) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 395 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 396 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Nicolas Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 399 | func libartDefaultsFactory() android.Module { |
| 400 | c := &codegenProperties{} |
| 401 | module := cc.DefaultsFactory(c) |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 402 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, staticAndSharedLibrary) }) |
Nicolas Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 403 | |
| 404 | return module |
| 405 | } |
| 406 | |
Andreas Gampe | ec5ed06 | 2018-01-26 16:20:02 -0800 | [diff] [blame] | 407 | func libartStaticDefaultsFactory() android.Module { |
| 408 | c := &codegenProperties{} |
| 409 | module := cc.DefaultsFactory(c) |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 410 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, staticLibrary) }) |
Andreas Gampe | ec5ed06 | 2018-01-26 16:20:02 -0800 | [diff] [blame] | 411 | |
| 412 | return module |
| 413 | } |
| 414 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 415 | func artLibrary() android.Module { |
Paul Duffin | e78b50e | 2020-02-18 12:25:40 +0000 | [diff] [blame] | 416 | module := cc.LibraryFactory() |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 417 | |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 418 | installCodegenCustomizer(module, staticAndSharedLibrary) |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 419 | |
David Srbecky | 1cf46a3 | 2020-06-22 15:39:00 +0100 | [diff] [blame] | 420 | android.AddInstallHook(module, addTestcasesFile) |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 421 | return module |
| 422 | } |
| 423 | |
| 424 | func artStaticLibrary() android.Module { |
Paul Duffin | e78b50e | 2020-02-18 12:25:40 +0000 | [diff] [blame] | 425 | module := cc.LibraryStaticFactory() |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 426 | |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 427 | installCodegenCustomizer(module, staticLibrary) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 428 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 429 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 432 | func artBinary() android.Module { |
Paul Duffin | e78b50e | 2020-02-18 12:25:40 +0000 | [diff] [blame] | 433 | module := cc.BinaryFactory() |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 434 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 435 | android.AddLoadHook(module, customLinker) |
| 436 | android.AddLoadHook(module, prefer32Bit) |
David Srbecky | 1cf46a3 | 2020-06-22 15:39:00 +0100 | [diff] [blame] | 437 | android.AddInstallHook(module, addTestcasesFile) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 438 | return module |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 441 | func artTest() android.Module { |
Paul Duffin | e78b50e | 2020-02-18 12:25:40 +0000 | [diff] [blame] | 442 | module := cc.TestFactory() |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 443 | |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 444 | installCodegenCustomizer(module, binary) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 445 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 446 | android.AddLoadHook(module, customLinker) |
| 447 | android.AddLoadHook(module, prefer32Bit) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 448 | android.AddInstallHook(module, testInstall) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 449 | return module |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 452 | func artTestLibrary() android.Module { |
Paul Duffin | e78b50e | 2020-02-18 12:25:40 +0000 | [diff] [blame] | 453 | module := cc.TestLibraryFactory() |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 454 | |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 455 | installCodegenCustomizer(module, staticAndSharedLibrary) |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 456 | |
| 457 | android.AddLoadHook(module, prefer32Bit) |
| 458 | android.AddInstallHook(module, testInstall) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 459 | return module |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 460 | } |