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

Commit cdc66f42 authored by Ronald Braunstein's avatar Ronald Braunstein
Browse files

Add "test-only" flag for java modules

As part of aosp/3022586 where we added the idea of "test-only" modules
and top_level_test_targets, this CL implements that for java modules.

We let users set "test-only" on java_library, but not on other modules
where the module kind is implicitly test-only, like java_test.
The implementation, not the user decides it is test-only.
We also exclude it from java_defaults.

	% gqui from  "flatten(~/aosp-main-with-phones/out/soong/ownership/all_teams.pb, teams)" proto team.proto:AllTeams 'select teams.kind, count(*) where teams.test_only = true and teams.kind not like "%cc_%" group by teams.kind'
	+--------------------------+----------+
	|        teams.kind        | count(*) |
	+--------------------------+----------+
	| android_test             |     1382 |
	| android_test_helper_app  |     1680 |
	| java_fuzz                |        5 |
	| java_test                |      774 |
	| java_test_helper_library |       29 |
	+--------------------------+----------+

	 % gqui from  "flatten(~/aosp-main-with-phones/out/soong/ownership/all_teams.pb, teams)" proto team.proto:AllTeams 'select teams.kind, count(*) where teams.top_level_target = true and teams.kind not like "%cc_%" group by teams.kind'
	+--------------+----------+
	|  teams.kind  | count(*) |
	+--------------+----------+
	| android_test |     1382 |
	| java_fuzz    |        5 |
	| java_test    |      774 |
	+--------------+----------+

Test: m nothing --no-skip-soong-tests
Test: go test ./java
Test: m all_teams

Bug: b/327280661
Change-Id: I9c3ad947dc3d68d6427abada27449526d69daa6b
parent fc5cdcbd
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -922,7 +922,8 @@ func AndroidLibraryFactory() android.Module {
	module.Module.addHostAndDeviceProperties()
	module.AddProperties(
		&module.aaptProperties,
		&module.androidLibraryProperties)
		&module.androidLibraryProperties,
		&module.sourceProperties)

	module.androidLibraryProperties.BuildAAR = true
	module.Module.linter.library = true
+16 −2
Original line number Diff line number Diff line
@@ -329,6 +329,10 @@ func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleCon
		a.aapt.manifestValues.applicationId = *applicationId
	}
	a.generateAndroidBuildActions(ctx)
	android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
		TestOnly: true,
	})

}

func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@@ -1191,7 +1195,8 @@ func AndroidAppFactory() android.Module {
	module.AddProperties(
		&module.aaptProperties,
		&module.appProperties,
		&module.overridableAppProperties)
		&module.overridableAppProperties,
		&module.Library.sourceProperties)

	module.usesLibrary.enforce = true

@@ -1340,6 +1345,11 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
		TestSuites:              a.testProperties.Test_suites,
		IsHost:                  false,
	})
	android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
		TestOnly:       true,
		TopLevelTarget: true,
	})

}

func (a *AndroidTest) FixTestConfig(ctx android.ModuleContext, testConfig android.Path) android.Path {
@@ -1532,9 +1542,13 @@ type OverrideAndroidTest struct {
	android.OverrideModuleBase
}

func (i *OverrideAndroidTest) GenerateAndroidBuildActions(_ android.ModuleContext) {
func (i *OverrideAndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	// All the overrides happen in the base module.
	// TODO(jungjw): Check the base module type.
	android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
		TestOnly:       true,
		TopLevelTarget: true,
	})
}

// override_android_test is used to create an android_app module based on another android_test by overriding
+38 −0
Original line number Diff line number Diff line
@@ -4432,6 +4432,44 @@ func TestNoDexpreoptOptionalUsesLibDoesNotHaveImpl(t *testing.T) {
	android.AssertBoolEquals(t, "dexpreopt should be disabled if optional_uses_libs does not have an implementation", true, dexpreopt == nil)
}

func TestTestOnlyApp(t *testing.T) {
	t.Parallel()
	ctx := android.GroupFixturePreparers(
		prepareForJavaTest,
	).RunTestWithBp(t, `
                // These should be test-only
                android_test {
                        name: "android-test",
                }
                android_test_helper_app {
                        name: "helper-app",
                }
                override_android_test {
                        name: "override-test",
                        base: "android-app",
                }
                // And these should not be
		android_app {
			name: "android-app",
                        srcs: ["b.java"],
			sdk_version: "current",
		}
	`)

	expectedTestOnly := []string{
		"android-test",
		"helper-app",
		"override-test",
	}

	expectedTopLevel := []string{
		"android-test",
		"override-test",
	}

	assertTestOnlyAndTopLevel(t, ctx, expectedTestOnly, expectedTopLevel)
}

func TestAppStem(t *testing.T) {
	ctx := testApp(t, `
				android_app {
+1 −0
Original line number Diff line number Diff line
@@ -435,6 +435,7 @@ type Module struct {
	deviceProperties DeviceProperties

	overridableProperties OverridableProperties
	sourceProperties      android.SourceProperties

	// jar file containing header classes including static library dependencies, suitable for
	// inserting into the bootclasspath/classpath of another compile
+2 −0
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ func JavaFuzzFactory() android.Module {
	module.Module.properties.Installable = proptools.BoolPtr(true)
	module.Module.dexpreopter.isTest = true
	module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
	module.Module.sourceProperties.Test_only = proptools.BoolPtr(true)
	module.Module.sourceProperties.Top_level_test_target = true

	android.AddLoadHook(module, func(ctx android.LoadHookContext) {
		disableLinuxBionic := struct {
Loading