| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. | 
|  | 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 cc | 
|  | 16 |  | 
|  | 17 | import ( | 
| Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 18 | "strconv" | 
|  | 19 |  | 
| Pirama Arumuga Nainar | 82fe59b | 2019-07-02 14:55:35 -0700 | [diff] [blame] | 20 | "github.com/google/blueprint" | 
|  | 21 |  | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 22 | "android/soong/android" | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 23 | ) | 
|  | 24 |  | 
| Pirama Arumuga Nainar | f45e152 | 2020-08-05 10:08:30 -0700 | [diff] [blame] | 25 | const profileInstrFlag = "-fprofile-instr-generate=/data/misc/trace/clang-%p-%m.profraw" | 
|  | 26 |  | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 27 | type CoverageProperties struct { | 
|  | 28 | Native_coverage *bool | 
|  | 29 |  | 
| Pirama Arumuga Nainar | ee30d5e | 2019-03-20 11:31:56 -0700 | [diff] [blame] | 30 | NeedCoverageVariant bool `blueprint:"mutated"` | 
|  | 31 | NeedCoverageBuild   bool `blueprint:"mutated"` | 
|  | 32 |  | 
| Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 33 | CoverageEnabled   bool `blueprint:"mutated"` | 
|  | 34 | IsCoverageVariant bool `blueprint:"mutated"` | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 35 | } | 
|  | 36 |  | 
|  | 37 | type coverage struct { | 
|  | 38 | Properties CoverageProperties | 
|  | 39 |  | 
|  | 40 | // Whether binaries containing this module need --coverage added to their ldflags | 
|  | 41 | linkCoverage bool | 
|  | 42 | } | 
|  | 43 |  | 
|  | 44 | func (cov *coverage) props() []interface{} { | 
|  | 45 | return []interface{}{&cov.Properties} | 
|  | 46 | } | 
|  | 47 |  | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 48 | func getGcovProfileLibraryName(ctx ModuleContextIntf) string { | 
| Pirama Arumuga Nainar | 82fe59b | 2019-07-02 14:55:35 -0700 | [diff] [blame] | 49 | // This function should only ever be called for a cc.Module, so the | 
|  | 50 | // following statement should always succeed. | 
| Liz Kammer | 3847f21 | 2023-07-14 15:24:35 -0400 | [diff] [blame] | 51 | // LINT.IfChange | 
| Pirama Arumuga Nainar | 82fe59b | 2019-07-02 14:55:35 -0700 | [diff] [blame] | 52 | if ctx.useSdk() { | 
|  | 53 | return "libprofile-extras_ndk" | 
|  | 54 | } else { | 
|  | 55 | return "libprofile-extras" | 
|  | 56 | } | 
|  | 57 | } | 
|  | 58 |  | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 59 | func getClangProfileLibraryName(ctx ModuleContextIntf) string { | 
|  | 60 | if ctx.useSdk() { | 
|  | 61 | return "libprofile-clang-extras_ndk" | 
| Cindy Zhou | 5d5cfc1 | 2021-01-09 08:25:22 -0800 | [diff] [blame] | 62 | } else if ctx.isCfiAssemblySupportEnabled() { | 
|  | 63 | return "libprofile-clang-extras_cfi_support" | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 64 | } else { | 
|  | 65 | return "libprofile-clang-extras" | 
|  | 66 | } | 
| Liz Kammer | 3847f21 | 2023-07-14 15:24:35 -0400 | [diff] [blame] | 67 | // LINT.ThenChange(library.go) | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 68 | } | 
|  | 69 |  | 
| Pirama Arumuga Nainar | 82fe59b | 2019-07-02 14:55:35 -0700 | [diff] [blame] | 70 | func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps { | 
|  | 71 | if cov.Properties.NeedCoverageVariant { | 
|  | 72 | ctx.AddVariationDependencies([]blueprint.Variation{ | 
|  | 73 | {Mutator: "link", Variation: "static"}, | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 74 | }, CoverageDepTag, getGcovProfileLibraryName(ctx)) | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 75 | ctx.AddVariationDependencies([]blueprint.Variation{ | 
|  | 76 | {Mutator: "link", Variation: "static"}, | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 77 | }, CoverageDepTag, getClangProfileLibraryName(ctx)) | 
| Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 78 | } | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 79 | return deps | 
|  | 80 | } | 
|  | 81 |  | 
| Pirama Arumuga Nainar | b37ae58 | 2022-01-26 22:14:32 -0800 | [diff] [blame] | 82 | func EnableContinuousCoverage(ctx android.BaseModuleContext) bool { | 
|  | 83 | return ctx.DeviceConfig().ClangCoverageContinuousMode() | 
|  | 84 | } | 
|  | 85 |  | 
| Pirama Arumuga Nainar | 82fe59b | 2019-07-02 14:55:35 -0700 | [diff] [blame] | 86 | func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) { | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 87 | clangCoverage := ctx.DeviceConfig().ClangCoverageEnabled() | 
| Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 88 | gcovCoverage := ctx.DeviceConfig().GcovCoverageEnabled() | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 89 |  | 
|  | 90 | if !gcovCoverage && !clangCoverage { | 
| Pirama Arumuga Nainar | 82fe59b | 2019-07-02 14:55:35 -0700 | [diff] [blame] | 91 | return flags, deps | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 92 | } | 
|  | 93 |  | 
|  | 94 | if cov.Properties.CoverageEnabled { | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 95 | cov.linkCoverage = true | 
| Pirama Arumuga Nainar | c7679de | 2019-02-18 22:23:42 -0800 | [diff] [blame] | 96 |  | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 97 | if gcovCoverage { | 
| Oliver Nguyen | 0452678 | 2020-04-21 12:40:27 -0700 | [diff] [blame] | 98 | flags.GcovCoverage = true | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 99 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, "--coverage", "-O0") | 
|  | 100 |  | 
|  | 101 | // Override -Wframe-larger-than and non-default optimization | 
|  | 102 | // flags that the module may use. | 
|  | 103 | flags.Local.CFlags = append(flags.Local.CFlags, "-Wno-frame-larger-than=", "-O0") | 
|  | 104 | } else if clangCoverage { | 
| Pirama Arumuga Nainar | 551b06d | 2021-04-27 15:47:43 -0700 | [diff] [blame] | 105 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, profileInstrFlag, | 
|  | 106 | "-fcoverage-mapping", "-Wno-pass-failed", "-D__ANDROID_CLANG_COVERAGE__") | 
| Pirama Arumuga Nainar | f776c8c | 2022-01-27 10:46:26 -0800 | [diff] [blame] | 107 | // Override -Wframe-larger-than.  We can expect frame size increase after | 
|  | 108 | // coverage instrumentation. | 
|  | 109 | flags.Local.CFlags = append(flags.Local.CFlags, "-Wno-frame-larger-than=") | 
| Pirama Arumuga Nainar | b37ae58 | 2022-01-26 22:14:32 -0800 | [diff] [blame] | 110 | if EnableContinuousCoverage(ctx) { | 
|  | 111 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-mllvm", "-runtime-counter-relocation") | 
|  | 112 | } | 
| Pirama Arumuga Nainar | 2bcdf5e | 2022-10-04 23:52:48 +0000 | [diff] [blame] | 113 |  | 
|  | 114 | // http://b/248022906, http://b/247941801  enabling coverage and hwasan-globals | 
|  | 115 | // instrumentation together causes duplicate-symbol errors for __llvm_profile_filename. | 
|  | 116 | if c, ok := ctx.Module().(*Module); ok && c.sanitize.isSanitizerEnabled(Hwasan) { | 
|  | 117 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-mllvm", "-hwasan-globals=0") | 
|  | 118 | } | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 119 | } | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 120 | } | 
|  | 121 |  | 
|  | 122 | // Even if we don't have coverage enabled, if any of our object files were compiled | 
|  | 123 | // with coverage, then we need to add --coverage to our ldflags. | 
|  | 124 | if !cov.linkCoverage { | 
|  | 125 | if ctx.static() && !ctx.staticBinary() { | 
|  | 126 | // For static libraries, the only thing that changes our object files | 
|  | 127 | // are included whole static libraries, so check to see if any of | 
|  | 128 | // those have coverage enabled. | 
| Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 129 | ctx.VisitDirectDeps(func(m android.Module) { | 
|  | 130 | if depTag, ok := ctx.OtherModuleDependencyTag(m).(libraryDependencyTag); ok { | 
|  | 131 | if depTag.static() && depTag.wholeStatic { | 
|  | 132 | if cc, ok := m.(*Module); ok && cc.coverage != nil { | 
|  | 133 | if cc.coverage.linkCoverage { | 
|  | 134 | cov.linkCoverage = true | 
|  | 135 | } | 
|  | 136 | } | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 137 | } | 
|  | 138 | } | 
|  | 139 | }) | 
|  | 140 | } else { | 
|  | 141 | // For executables and shared libraries, we need to check all of | 
|  | 142 | // our static dependencies. | 
| Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 143 | ctx.VisitDirectDeps(func(m android.Module) { | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 144 | cc, ok := m.(*Module) | 
|  | 145 | if !ok || cc.coverage == nil { | 
|  | 146 | return | 
|  | 147 | } | 
|  | 148 |  | 
|  | 149 | if static, ok := cc.linker.(libraryInterface); !ok || !static.static() { | 
|  | 150 | return | 
|  | 151 | } | 
|  | 152 |  | 
|  | 153 | if cc.coverage.linkCoverage { | 
|  | 154 | cov.linkCoverage = true | 
|  | 155 | } | 
|  | 156 | }) | 
|  | 157 | } | 
|  | 158 | } | 
|  | 159 |  | 
|  | 160 | if cov.linkCoverage { | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 161 | if gcovCoverage { | 
|  | 162 | flags.Local.LdFlags = append(flags.Local.LdFlags, "--coverage") | 
| Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 163 |  | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 164 | coverage := ctx.GetDirectDepWithTag(getGcovProfileLibraryName(ctx), CoverageDepTag).(*Module) | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 165 | deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path()) | 
| Pirama Arumuga Nainar | 100bbdc | 2019-07-02 23:47:35 -0700 | [diff] [blame] | 166 |  | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 167 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--wrap,getenv") | 
|  | 168 | } else if clangCoverage { | 
| Pirama Arumuga Nainar | f45e152 | 2020-08-05 10:08:30 -0700 | [diff] [blame] | 169 | flags.Local.LdFlags = append(flags.Local.LdFlags, profileInstrFlag) | 
| Pirama Arumuga Nainar | b37ae58 | 2022-01-26 22:14:32 -0800 | [diff] [blame] | 170 | if EnableContinuousCoverage(ctx) { | 
|  | 171 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-mllvm=-runtime-counter-relocation") | 
|  | 172 | } | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 173 |  | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 174 | coverage := ctx.GetDirectDepWithTag(getClangProfileLibraryName(ctx), CoverageDepTag).(*Module) | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 175 | deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path()) | 
| Pirama Arumuga Nainar | 9464b6c | 2020-12-10 10:45:33 -0800 | [diff] [blame] | 176 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--wrap,open") | 
| Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 177 | } | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 178 | } | 
|  | 179 |  | 
| Pirama Arumuga Nainar | 82fe59b | 2019-07-02 14:55:35 -0700 | [diff] [blame] | 180 | return flags, deps | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 181 | } | 
|  | 182 |  | 
| Pirama Arumuga Nainar | ee30d5e | 2019-03-20 11:31:56 -0700 | [diff] [blame] | 183 | func (cov *coverage) begin(ctx BaseModuleContext) { | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 184 | if ctx.Host() { | 
|  | 185 | // TODO(dwillemsen): because of -nodefaultlibs, we must depend on libclang_rt.profile-*.a | 
|  | 186 | // Just turn off for now. | 
|  | 187 | } else { | 
|  | 188 | cov.Properties = SetCoverageProperties(ctx, cov.Properties, ctx.nativeCoverage(), ctx.useSdk(), ctx.sdkVersion()) | 
|  | 189 | } | 
|  | 190 | } | 
|  | 191 |  | 
|  | 192 | func SetCoverageProperties(ctx android.BaseModuleContext, properties CoverageProperties, moduleTypeHasCoverage bool, | 
|  | 193 | useSdk bool, sdkVersion string) CoverageProperties { | 
| Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 194 | // Coverage is disabled globally | 
| Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 195 | if !ctx.DeviceConfig().NativeCoverageEnabled() { | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 196 | return properties | 
| Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 197 | } | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 198 |  | 
| Pirama Arumuga Nainar | ee30d5e | 2019-03-20 11:31:56 -0700 | [diff] [blame] | 199 | var needCoverageVariant bool | 
|  | 200 | var needCoverageBuild bool | 
| Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 201 |  | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 202 | if moduleTypeHasCoverage { | 
| Pirama Arumuga Nainar | ee30d5e | 2019-03-20 11:31:56 -0700 | [diff] [blame] | 203 | // Check if Native_coverage is set to false.  This property defaults to true. | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 204 | needCoverageVariant = BoolDefault(properties.Native_coverage, true) | 
|  | 205 | if useSdk && sdkVersion != "current" { | 
| Pirama Arumuga Nainar | ee30d5e | 2019-03-20 11:31:56 -0700 | [diff] [blame] | 206 | // Native coverage is not supported for SDK versions < 23 | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 207 | if fromApi, err := strconv.Atoi(sdkVersion); err == nil && fromApi < 23 { | 
| Pirama Arumuga Nainar | ee30d5e | 2019-03-20 11:31:56 -0700 | [diff] [blame] | 208 | needCoverageVariant = false | 
| Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 209 | } | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 210 | } | 
|  | 211 |  | 
| Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 212 | if needCoverageVariant { | 
| Pirama Arumuga Nainar | ee30d5e | 2019-03-20 11:31:56 -0700 | [diff] [blame] | 213 | // Coverage variant is actually built with coverage if enabled for its module path | 
| Roland Levillain | 4f5297b | 2020-06-09 12:44:06 +0100 | [diff] [blame] | 214 | needCoverageBuild = ctx.DeviceConfig().NativeCoverageEnabledForPath(ctx.ModuleDir()) | 
| Pirama Arumuga Nainar | ee30d5e | 2019-03-20 11:31:56 -0700 | [diff] [blame] | 215 | } | 
|  | 216 | } | 
|  | 217 |  | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 218 | properties.NeedCoverageBuild = needCoverageBuild | 
|  | 219 | properties.NeedCoverageVariant = needCoverageVariant | 
|  | 220 |  | 
|  | 221 | return properties | 
| Pirama Arumuga Nainar | ee30d5e | 2019-03-20 11:31:56 -0700 | [diff] [blame] | 222 | } | 
|  | 223 |  | 
| Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 224 | type UseCoverage interface { | 
| Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 225 | android.Module | 
|  | 226 | IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool | 
| Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 227 | } | 
|  | 228 |  | 
|  | 229 | // Coverage is an interface for non-CC modules to implement to be mutated for coverage | 
|  | 230 | type Coverage interface { | 
|  | 231 | UseCoverage | 
| Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 232 | SetPreventInstall() | 
| Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 233 | HideFromMake() | 
| Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 234 | MarkAsCoverageVariant(bool) | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 235 | EnableCoverageIfNeeded() | 
| Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 236 | } | 
|  | 237 |  | 
| Pirama Arumuga Nainar | ee30d5e | 2019-03-20 11:31:56 -0700 | [diff] [blame] | 238 | func coverageMutator(mctx android.BottomUpMutatorContext) { | 
|  | 239 | if c, ok := mctx.Module().(*Module); ok && c.coverage != nil { | 
|  | 240 | needCoverageVariant := c.coverage.Properties.NeedCoverageVariant | 
|  | 241 | needCoverageBuild := c.coverage.Properties.NeedCoverageBuild | 
|  | 242 | if needCoverageVariant { | 
| Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 243 | m := mctx.CreateVariations("", "cov") | 
|  | 244 |  | 
|  | 245 | // Setup the non-coverage version and set HideFromMake and | 
|  | 246 | // PreventInstall to true. | 
|  | 247 | m[0].(*Module).coverage.Properties.CoverageEnabled = false | 
|  | 248 | m[0].(*Module).coverage.Properties.IsCoverageVariant = false | 
|  | 249 | m[0].(*Module).Properties.HideFromMake = true | 
|  | 250 | m[0].(*Module).Properties.PreventInstall = true | 
|  | 251 |  | 
|  | 252 | // The coverage-enabled version inherits HideFromMake, | 
|  | 253 | // PreventInstall from the original module. | 
|  | 254 | m[1].(*Module).coverage.Properties.CoverageEnabled = needCoverageBuild | 
|  | 255 | m[1].(*Module).coverage.Properties.IsCoverageVariant = true | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 256 | } | 
| Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 257 | } else if cov, ok := mctx.Module().(Coverage); ok && cov.IsNativeCoverageNeeded(mctx) { | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 258 | // APEX and Rust modules fall here | 
| Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 259 |  | 
|  | 260 | // Note: variant "" is also created because an APEX can be depended on by another | 
|  | 261 | // module which are split into "" and "cov" variants. e.g. when cc_test refers | 
|  | 262 | // to an APEX via 'data' property. | 
|  | 263 | m := mctx.CreateVariations("", "cov") | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 264 | m[0].(Coverage).MarkAsCoverageVariant(false) | 
| Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 265 | m[0].(Coverage).SetPreventInstall() | 
| Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 266 | m[0].(Coverage).HideFromMake() | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 267 |  | 
|  | 268 | m[1].(Coverage).MarkAsCoverageVariant(true) | 
|  | 269 | m[1].(Coverage).EnableCoverageIfNeeded() | 
| Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 270 | } else if cov, ok := mctx.Module().(UseCoverage); ok && cov.IsNativeCoverageNeeded(mctx) { | 
|  | 271 | // Module itself doesn't have to have "cov" variant, but it should use "cov" variants of | 
|  | 272 | // deps. | 
|  | 273 | mctx.CreateVariations("cov") | 
|  | 274 | mctx.AliasVariation("cov") | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 275 | } | 
|  | 276 | } | 
| sophiez | 4c4f803 | 2021-08-16 22:54:00 -0700 | [diff] [blame] | 277 |  | 
|  | 278 | func parseSymbolFileForAPICoverage(ctx ModuleContext, symbolFile string) android.ModuleOutPath { | 
|  | 279 | apiLevelsJson := android.GetApiLevelsJson(ctx) | 
|  | 280 | symbolFilePath := android.PathForModuleSrc(ctx, symbolFile) | 
|  | 281 | outputFile := ctx.baseModuleName() + ".xml" | 
|  | 282 | parsedApiCoveragePath := android.PathForModuleOut(ctx, outputFile) | 
|  | 283 | rule := android.NewRuleBuilder(pctx, ctx) | 
|  | 284 | rule.Command(). | 
|  | 285 | BuiltTool("ndk_api_coverage_parser"). | 
|  | 286 | Input(symbolFilePath). | 
|  | 287 | Output(parsedApiCoveragePath). | 
|  | 288 | Implicit(apiLevelsJson). | 
|  | 289 | FlagWithArg("--api-map ", apiLevelsJson.String()) | 
|  | 290 | rule.Build("native_library_api_list", "Generate native API list based on symbol files for coverage measurement") | 
|  | 291 | return parsedApiCoveragePath | 
|  | 292 | } |