summaryrefslogtreecommitdiff
path: root/java/base.go
diff options
context:
space:
mode:
author Yihan Dong <slotus@google.com> 2024-08-29 15:32:13 +0800
committer Yihan Dong <slotus@google.com> 2024-09-02 09:02:08 +0800
commit8be09c207544cfdee094494d57e819a5f924907b (patch)
tree3afed23148c680e6c6bc7be85f603d7cdc13a0d1 /java/base.go
parent88a8daf8cae89783450b349d2a4217e6ed0c4a94 (diff)
Apply apimapper instrument tool on android tests
Apimapper is a tool to instrument android tests to log potentail API calls at the run time. The real tool is developed internally. We use a placeholder binary in AOSP before the real tool is ready. The tool will only take affect when the enviroment var EMMA_API_MAPPER is set to true. Test: m cts Bug: 328699028 Change-Id: Iece53b8afdb9803334b7393527f4fa24e22f71a8
Diffstat (limited to 'java/base.go')
-rw-r--r--java/base.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/java/base.go b/java/base.go
index 4cd60215c..5ac965cad 100644
--- a/java/base.go
+++ b/java/base.go
@@ -233,6 +233,10 @@ type CommonProperties struct {
// Contributing api surface of the stub module. Is not visible to bp modules, and should
// only be set for stub submodules generated by the java_sdk_library
Stub_contributing_api *string `blueprint:"mutated"`
+
+ // If true, enable the "ApiMapper" tool on the output jar. "ApiMapper" is a tool to inject
+ // bytecode to log API calls.
+ ApiMapper bool `blueprint:"mutated"`
}
// Properties that are specific to device modules. Host module factories should not add these when
@@ -732,6 +736,10 @@ func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
ctx.DeviceConfig().JavaCoverageEnabledForPath(ctx.ModuleDir())
}
+func (j *Module) shouldApiMapper() bool {
+ return j.properties.ApiMapper
+}
+
func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
return j.properties.Supports_static_instrumentation &&
j.shouldInstrument(ctx) &&
@@ -760,6 +768,10 @@ func (j *Module) setInstrument(value bool) {
j.properties.Instrument = value
}
+func (j *Module) setApiMapper(value bool) {
+ j.properties.ApiMapper = value
+}
+
func (j *Module) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return android.SdkSpecFrom(ctx, String(j.deviceProperties.Sdk_version))
}
@@ -1591,6 +1603,18 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
outputFile = ravenizerOutput
}
+ if j.shouldApiMapper() {
+ inputFile := outputFile
+ apiMapperFile := android.PathForModuleOut(ctx, "apimapper", jarName)
+ ctx.Build(pctx, android.BuildParams{
+ Rule: apimapper,
+ Description: "apimapper",
+ Input: inputFile,
+ Output: apiMapperFile,
+ })
+ outputFile = apiMapperFile
+ }
+
// Check package restrictions if necessary.
if len(j.properties.Permitted_packages) > 0 {
// Time stamp file created by the package check rule.