Merge "Add coverage specific properties to bootclasspath_fragment"
This commit is contained in:
@@ -69,16 +69,23 @@ func IsBootclasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
|
|||||||
return tag == bootclasspathFragmentContentDepTag
|
return tag == bootclasspathFragmentContentDepTag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Properties that can be different when coverage is enabled.
|
||||||
|
type BootclasspathFragmentCoverageAffectedProperties struct {
|
||||||
|
// The contents of this bootclasspath_fragment, could be either java_library, or java_sdk_library.
|
||||||
|
//
|
||||||
|
// The order of this list matters as it is the order that is used in the bootclasspath.
|
||||||
|
Contents []string
|
||||||
|
}
|
||||||
|
|
||||||
type bootclasspathFragmentProperties struct {
|
type bootclasspathFragmentProperties struct {
|
||||||
// The name of the image this represents.
|
// The name of the image this represents.
|
||||||
//
|
//
|
||||||
// If specified then it must be one of "art" or "boot".
|
// If specified then it must be one of "art" or "boot".
|
||||||
Image_name *string
|
Image_name *string
|
||||||
|
|
||||||
// The contents of this bootclasspath_fragment, could be either java_library, java_sdk_library, or boot_image.
|
// Properties whose values need to differ with and without coverage.
|
||||||
//
|
BootclasspathFragmentCoverageAffectedProperties
|
||||||
// The order of this list matters as it is the order that is used in the bootclasspath.
|
Coverage BootclasspathFragmentCoverageAffectedProperties
|
||||||
Contents []string
|
|
||||||
|
|
||||||
Hidden_api HiddenAPIFlagFileProperties
|
Hidden_api HiddenAPIFlagFileProperties
|
||||||
}
|
}
|
||||||
@@ -97,8 +104,18 @@ func bootclasspathFragmentFactory() android.Module {
|
|||||||
android.InitSdkAwareModule(m)
|
android.InitSdkAwareModule(m)
|
||||||
android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
|
android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
|
||||||
|
|
||||||
// Initialize the contents property from the image_name.
|
|
||||||
android.AddLoadHook(m, func(ctx android.LoadHookContext) {
|
android.AddLoadHook(m, func(ctx android.LoadHookContext) {
|
||||||
|
// If code coverage has been enabled for the framework then append the properties with
|
||||||
|
// coverage specific properties.
|
||||||
|
if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
|
||||||
|
err := proptools.AppendProperties(&m.properties.BootclasspathFragmentCoverageAffectedProperties, &m.properties.Coverage, nil)
|
||||||
|
if err != nil {
|
||||||
|
ctx.PropertyErrorf("coverage", "error trying to append coverage specific properties: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the contents property from the image_name.
|
||||||
bootclasspathFragmentInitContentsFromImage(ctx, m)
|
bootclasspathFragmentInitContentsFromImage(ctx, m)
|
||||||
})
|
})
|
||||||
return m
|
return m
|
||||||
|
@@ -125,3 +125,62 @@ func TestBootclasspathFragmentWithImageNameAndContents(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBootclasspathFragment_Coverage(t *testing.T) {
|
||||||
|
prepareForTestWithFrameworkCoverage := android.FixtureMergeEnv(map[string]string{
|
||||||
|
"EMMA_INSTRUMENT": "true",
|
||||||
|
"EMMA_INSTRUMENT_FRAMEWORK": "true",
|
||||||
|
})
|
||||||
|
|
||||||
|
prepareWithBp := android.FixtureWithRootAndroidBp(`
|
||||||
|
bootclasspath_fragment {
|
||||||
|
name: "myfragment",
|
||||||
|
contents: [
|
||||||
|
"mybootlib",
|
||||||
|
],
|
||||||
|
coverage: {
|
||||||
|
contents: [
|
||||||
|
"coveragelib",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
java_library {
|
||||||
|
name: "mybootlib",
|
||||||
|
srcs: ["Test.java"],
|
||||||
|
system_modules: "none",
|
||||||
|
sdk_version: "none",
|
||||||
|
compile_dex: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
java_library {
|
||||||
|
name: "coveragelib",
|
||||||
|
srcs: ["Test.java"],
|
||||||
|
system_modules: "none",
|
||||||
|
sdk_version: "none",
|
||||||
|
compile_dex: true,
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
checkContents := func(t *testing.T, result *android.TestResult, expected ...string) {
|
||||||
|
module := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule)
|
||||||
|
android.AssertArrayString(t, "contents property", expected, module.properties.Contents)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("without coverage", func(t *testing.T) {
|
||||||
|
result := android.GroupFixturePreparers(
|
||||||
|
prepareForTestWithBootclasspathFragment,
|
||||||
|
prepareWithBp,
|
||||||
|
).RunTest(t)
|
||||||
|
checkContents(t, result, "mybootlib")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("with coverage", func(t *testing.T) {
|
||||||
|
result := android.GroupFixturePreparers(
|
||||||
|
prepareForTestWithBootclasspathFragment,
|
||||||
|
prepareForTestWithFrameworkCoverage,
|
||||||
|
prepareWithBp,
|
||||||
|
).RunTest(t)
|
||||||
|
checkContents(t, result, "mybootlib", "coveragelib")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user