Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43c0eb17 authored by Sam Delmerico's avatar Sam Delmerico Committed by Gerrit Code Review
Browse files

Merge "add jacocoagent by default to Java modules"

parents c0cca3f4 1e3f78f8
Loading
Loading
Loading
Loading
+1 −13
Original line number Original line Diff line number Diff line
@@ -8843,19 +8843,7 @@ func TestApexJavaCoverage(t *testing.T) {
		android.FixtureWithRootAndroidBp(bp),
		android.FixtureWithRootAndroidBp(bp),
		dexpreopt.FixtureSetApexBootJars("myapex:mybootclasspathlib"),
		dexpreopt.FixtureSetApexBootJars("myapex:mybootclasspathlib"),
		dexpreopt.FixtureSetApexSystemServerJars("myapex:mysystemserverclasspathlib"),
		dexpreopt.FixtureSetApexSystemServerJars("myapex:mysystemserverclasspathlib"),
		android.FixtureMergeEnv(map[string]string{
		java.PrepareForTestWithJacocoInstrumentation,
			"EMMA_INSTRUMENT": "true",
		}),
		// need to mock jacocoagent here to satisfy dependency added for
		// instrumented libraries at build time
		android.FixtureAddFile("jacocoagent/Android.bp", []byte(`
			java_library {
				name: "jacocoagent",
				srcs: ["Test.java"],
				system_modules: "none",
				sdk_version: "none",
			}
		`)),
	).RunTest(t)
	).RunTest(t)


	// Make sure jacoco ran on both mylib and mybootclasspathlib
	// Make sure jacoco ran on both mylib and mybootclasspathlib
+4 −7
Original line number Original line Diff line number Diff line
@@ -650,6 +650,10 @@ func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool {
	return false
	return false
}
}


func (j *Module) setInstrument(value bool) {
	j.properties.Instrument = value
}

func (j *Module) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
func (j *Module) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
	return android.SdkSpecFrom(ctx, String(j.deviceProperties.Sdk_version))
	return android.SdkSpecFrom(ctx, String(j.deviceProperties.Sdk_version))
}
}
@@ -789,9 +793,6 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
	} else if j.shouldInstrumentStatic(ctx) {
	} else if j.shouldInstrumentStatic(ctx) {
		ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
		ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
	}
	}
	if j.shouldInstrument(ctx) {
		ctx.AddVariationDependencies(nil, libTag, "jacocoagent")
	}


	if j.useCompose() {
	if j.useCompose() {
		ctx.AddVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), kotlinPluginTag,
		ctx.AddVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), kotlinPluginTag,
@@ -1435,10 +1436,6 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
		j.headerJarFile = j.implementationJarFile
		j.headerJarFile = j.implementationJarFile
	}
	}


	if j.shouldInstrumentInApex(ctx) {
		j.properties.Instrument = true
	}

	// enforce syntax check to jacoco filters for any build (http://b/183622051)
	// enforce syntax check to jacoco filters for any build (http://b/183622051)
	specs := j.jacocoModuleToZipCommand(ctx)
	specs := j.jacocoModuleToZipCommand(ctx)
	if ctx.Failed() {
	if ctx.Failed() {
+1 −18
Original line number Original line Diff line number Diff line
@@ -96,23 +96,6 @@ func TestBootclasspathFragmentInconsistentArtConfiguration_ApexMixture(t *testin
}
}


func TestBootclasspathFragment_Coverage(t *testing.T) {
func TestBootclasspathFragment_Coverage(t *testing.T) {
	prepareForTestWithFrameworkCoverage := android.GroupFixturePreparers(
		android.FixtureMergeEnv(map[string]string{
			"EMMA_INSTRUMENT":           "true",
			"EMMA_INSTRUMENT_FRAMEWORK": "true",
		}),
		// need to mock jacocoagent here to satisfy dependency added for
		// instrumented libraries at build time
		android.FixtureAddFile("jacocoagent/Android.bp", []byte(`
			java_library {
				name: "jacocoagent",
				srcs: ["Test.java"],
				system_modules: "none",
				sdk_version: "none",
			}
		`)),
	)

	prepareWithBp := android.FixtureWithRootAndroidBp(`
	prepareWithBp := android.FixtureWithRootAndroidBp(`
		bootclasspath_fragment {
		bootclasspath_fragment {
			name: "myfragment",
			name: "myfragment",
@@ -191,7 +174,7 @@ func TestBootclasspathFragment_Coverage(t *testing.T) {


	t.Run("with coverage", func(t *testing.T) {
	t.Run("with coverage", func(t *testing.T) {
		result := android.GroupFixturePreparers(
		result := android.GroupFixturePreparers(
			prepareForTestWithFrameworkCoverage,
			prepareForTestWithFrameworkJacocoInstrumentation,
			preparer,
			preparer,
		).RunTest(t)
		).RunTest(t)
		checkContents(t, result, "mybootlib", "coveragelib")
		checkContents(t, result, "mybootlib", "coveragelib")
+28 −0
Original line number Original line Diff line number Diff line
@@ -47,6 +47,34 @@ var (
		"strippedJar", "stripSpec", "tmpDir", "tmpJar")
		"strippedJar", "stripSpec", "tmpDir", "tmpJar")
)
)


func jacocoDepsMutator(ctx android.BottomUpMutatorContext) {
	type instrumentable interface {
		shouldInstrument(ctx android.BaseModuleContext) bool
		shouldInstrumentInApex(ctx android.BaseModuleContext) bool
		setInstrument(value bool)
	}

	j, ok := ctx.Module().(instrumentable)
	if !ctx.Module().Enabled() || !ok {
		return
	}

	if j.shouldInstrumentInApex(ctx) {
		j.setInstrument(true)
	}

	if j.shouldInstrument(ctx) && ctx.ModuleName() != "jacocoagent" {
		// We can use AddFarVariationDependencies here because, since this dep
		// is added as libs only (i.e. a compiletime CLASSPATH entry only),
		// the first variant of jacocoagent is sufficient to prevent
		// compile time errors.
		// At this stage in the build, AddVariationDependencies is not always
		// able to procure a variant of jacocoagent that matches the calling
		// module.
		ctx.AddFarVariationDependencies(ctx.Module().Target().Variations(), libTag, "jacocoagent")
	}
}

// Instruments a jar using the Jacoco command line interface.  Uses stripSpec to extract a subset
// Instruments a jar using the Jacoco command line interface.  Uses stripSpec to extract a subset
// of the classes in inputJar into strippedJar, instruments strippedJar into tmpJar, and then
// of the classes in inputJar into strippedJar, instruments strippedJar into tmpJar, and then
// combines the classes in tmpJar with inputJar (preferring the instrumented classes in tmpJar)
// combines the classes in tmpJar with inputJar (preferring the instrumented classes in tmpJar)
+2 −0
Original line number Original line Diff line number Diff line
@@ -66,6 +66,8 @@ func registerJavaBuildComponents(ctx android.RegistrationContext) {
	// to support the checks in dexpreoptDisabled().
	// to support the checks in dexpreoptDisabled().
	ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
	ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
		ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel()
		ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel()
		// needs access to ApexInfoProvider which is available after variant creation
		ctx.BottomUp("jacoco_deps", jacocoDepsMutator).Parallel()
	})
	})


	ctx.RegisterSingletonType("logtags", LogtagsSingleton)
	ctx.RegisterSingletonType("logtags", LogtagsSingleton)
Loading