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

Commit 8f83dcd1 authored by Jihoon Kang's avatar Jihoon Kang
Browse files

Add droidstub modules for Soong java testing

Previously, only the essential java_api_library and
java_api_contribution modules were being added to the template bp file
for testing purpose. However, since the child change aosp/2640275
adds droidstubs that generates the java_api_contribution as the
dependency of the java_api_library modules, not adding the droidstubs
modules to the template bp file will lead to missing dependency errors
in Soong test cases that tests the from-text generation &
java_api_library functionality.

To prevent this, this change adds the droidstubs modules instead of the
auto generated java_api_contribution modules to the template bp file to
more closely align with the real life behavior.

Test: m nothing
Bug: 288624417
Change-Id: I6a25e2f6c5f1281e96eca15aa5eec7417635df3f
parent 0bf0865f
Loading
Loading
Loading
Loading
+72 −51
Original line number Original line Diff line number Diff line
@@ -73,10 +73,15 @@ var prepareForTestWithFrameworkDeps = android.GroupFixturePreparers(
		// Needed for various deps defined in GatherRequiredDepsForTest()
		// Needed for various deps defined in GatherRequiredDepsForTest()
		defaultJavaDir + "/a.java":                        nil,
		defaultJavaDir + "/a.java":                        nil,
		defaultJavaDir + "/api/current.txt":               nil,
		defaultJavaDir + "/api/current.txt":               nil,
		defaultJavaDir + "/api/removed.txt":               nil,
		defaultJavaDir + "/api/system-current.txt":        nil,
		defaultJavaDir + "/api/system-current.txt":        nil,
		defaultJavaDir + "/api/system-removed.txt":        nil,
		defaultJavaDir + "/api/test-current.txt":          nil,
		defaultJavaDir + "/api/test-current.txt":          nil,
		defaultJavaDir + "/api/test-removed.txt":          nil,
		defaultJavaDir + "/api/module-lib-current.txt":    nil,
		defaultJavaDir + "/api/module-lib-current.txt":    nil,
		defaultJavaDir + "/api/module-lib-removed.txt":    nil,
		defaultJavaDir + "/api/system-server-current.txt": nil,
		defaultJavaDir + "/api/system-server-current.txt": nil,
		defaultJavaDir + "/api/system-server-removed.txt": nil,


		// Needed for R8 rules on apps
		// Needed for R8 rules on apps
		"build/make/core/proguard.flags":             nil,
		"build/make/core/proguard.flags":             nil,
@@ -425,80 +430,96 @@ func gatherRequiredDepsForTest() string {
		`, extra)
		`, extra)
	}
	}


	type apiContributionStruct struct {
	type droidstubsStruct struct {
		name        string
		name        string
		apiSurface  string
		apiSurface  string
		apiFile     string
		apiFile     string
		removedFile string
	}
	}


	var publicApiContribution = apiContributionStruct{
	var publicDroidstubs = droidstubsStruct{
		name:       "api-stubs-docs-non-updatable.api.contribution",
		name:        "api-stubs-docs-non-updatable",
		apiSurface:  "public",
		apiSurface:  "public",
		apiFile:     "api/current.txt",
		apiFile:     "api/current.txt",
		removedFile: "api/removed.txt",
	}
	}
	var systemApiContribution = apiContributionStruct{
	var systemDroidstubs = droidstubsStruct{
		name:       "system-api-stubs-docs-non-updatable.api.contribution",
		name:        "system-api-stubs-docs-non-updatable",
		apiSurface:  "system",
		apiSurface:  "system",
		apiFile:     "api/system-current.txt",
		apiFile:     "api/system-current.txt",
		removedFile: "api/system-removed.txt",
	}
	}
	var testApiContribution = apiContributionStruct{
	var testDroidstubs = droidstubsStruct{
		name:       "test-api-stubs-docs-non-updatable.api.contribution",
		name:        "test-api-stubs-docs-non-updatable",
		apiSurface:  "test",
		apiSurface:  "test",
		apiFile:     "api/test-current.txt",
		apiFile:     "api/test-current.txt",
		removedFile: "api/test-removed.txt",
	}
	}
	var moduleLibApiContribution = apiContributionStruct{
	var moduleLibDroidstubs = droidstubsStruct{
		name:       "module-lib-api-stubs-docs-non-updatable.api.contribution",
		name:        "module-lib-api-stubs-docs-non-updatable",
		apiSurface:  "module-lib",
		apiSurface:  "module-lib",
		apiFile:     "api/module-lib-current.txt",
		apiFile:     "api/module-lib-current.txt",
		removedFile: "api/module-lib-removed.txt",
	}
	}
	var systemServerApiContribution = apiContributionStruct{
	var systemServerDroidstubs = droidstubsStruct{
		// This module does not exist but is named this way for consistency
		// This module does not exist but is named this way for consistency
		name:       "system-server-api-stubs-docs-non-updatable.api.contribution",
		name:        "system-server-api-stubs-docs-non-updatable",
		apiSurface:  "system-server",
		apiSurface:  "system-server",
		apiFile:     "api/system-server-current.txt",
		apiFile:     "api/system-server-current.txt",
	}
		removedFile: "api/system-server-removed.txt",
	var apiContributionStructs = []apiContributionStruct{
	}
		publicApiContribution,
	var droidstubsStructs = []droidstubsStruct{
		systemApiContribution,
		publicDroidstubs,
		testApiContribution,
		systemDroidstubs,
		moduleLibApiContribution,
		testDroidstubs,
		systemServerApiContribution,
		moduleLibDroidstubs,
	}
		systemServerDroidstubs,

	}
	extraApiLibraryModules := map[string]apiContributionStruct{

		"android_stubs_current.from-text":                  publicApiContribution,
	extraApiLibraryModules := map[string]droidstubsStruct{
		"android_system_stubs_current.from-text":           systemApiContribution,
		"android_stubs_current.from-text":                  publicDroidstubs,
		"android_test_stubs_current.from-text":             testApiContribution,
		"android_system_stubs_current.from-text":           systemDroidstubs,
		"android_module_lib_stubs_current.from-text":       moduleLibApiContribution,
		"android_test_stubs_current.from-text":             testDroidstubs,
		"android_module_lib_stubs_current_full.from-text":  moduleLibApiContribution,
		"android_module_lib_stubs_current.from-text":       moduleLibDroidstubs,
		"android_system_server_stubs_current.from-text":    systemServerApiContribution,
		"android_module_lib_stubs_current_full.from-text":  moduleLibDroidstubs,
		"core.current.stubs.from-text":                     publicApiContribution,
		"android_system_server_stubs_current.from-text":    systemServerDroidstubs,
		"legacy.core.platform.api.stubs.from-text":         publicApiContribution,
		"core.current.stubs.from-text":                     publicDroidstubs,
		"stable.core.platform.api.stubs.from-text":         publicApiContribution,
		"legacy.core.platform.api.stubs.from-text":         publicDroidstubs,
		"core-lambda-stubs.from-text":                      publicApiContribution,
		"stable.core.platform.api.stubs.from-text":         publicDroidstubs,
		"android-non-updatable.stubs.from-text":            publicApiContribution,
		"core-lambda-stubs.from-text":                      publicDroidstubs,
		"android-non-updatable.stubs.system.from-text":     systemApiContribution,
		"android-non-updatable.stubs.from-text":            publicDroidstubs,
		"android-non-updatable.stubs.test.from-text":       testApiContribution,
		"android-non-updatable.stubs.system.from-text":     systemDroidstubs,
		"android-non-updatable.stubs.module_lib.from-text": moduleLibApiContribution,
		"android-non-updatable.stubs.test.from-text":       testDroidstubs,
	}
		"android-non-updatable.stubs.module_lib.from-text": moduleLibDroidstubs,

	}
	for _, apiContribution := range apiContributionStructs {

	for _, droidstubs := range droidstubsStructs {
		bp += fmt.Sprintf(`
		bp += fmt.Sprintf(`
			java_api_contribution {
			droidstubs {
				name: "%s",
				name: "%s",
				api_surface: "%s",
				api_surface: "%s",
				check_api: {
					current: {
						api_file: "%s",
						api_file: "%s",
						removed_api_file: "%s",
					}
				}
				}
		`, apiContribution.name, apiContribution.apiSurface, apiContribution.apiFile)
			}
		`,
			droidstubs.name,
			droidstubs.apiSurface,
			droidstubs.apiFile,
			droidstubs.removedFile,
		)
	}
	}


	for libName, apiContribution := range extraApiLibraryModules {
	for libName, droidstubs := range extraApiLibraryModules {
		bp += fmt.Sprintf(`
		bp += fmt.Sprintf(`
            java_api_library {
            java_api_library {
                name: "%s",
                name: "%s",
                api_contributions: ["%s"],
                api_contributions: ["%s"],
            }
            }
        `, libName, apiContribution.name)
        `, libName, droidstubs.name+".api.contribution")
	}
	}


	bp += `
	bp += `