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

Commit 58cfc9af authored by Paul Duffin's avatar Paul Duffin
Browse files

Pass API surface specific extension jars to Metalava

Previously, it would only pass `public` extension jars. This change
fixes that so it passes the jars for the API surface being generated.

Bug: 336993217
Test: m out/target/common/obj/PACKAGING/api_versions_public_generated-api-versions.xml \
        out/target/common/obj/PACKAGING/api_versions_system_generated-api-versions.xml
      # Compare the following files to make sure that they include public extension
      # APIs and system extension APIs respectively.
      diff \
          out/soong/.intermediates/frameworks/base/api/api_versions_public/android_common/*/metalava_exportable.sbox.textproto \
          out/soong/.intermediates/frameworks/base/api/api_versions_system/android_common/*/metalava_exportable.sbox.textproto
Change-Id: I02e2ec3c8176cfbc3cbd8ac56fb78d12b765eedb
parent b39c877a
Loading
Loading
Loading
Loading
+26 −21
Original line number Diff line number Diff line
@@ -614,11 +614,36 @@ func (d *Droidstubs) apiLevelsGenerationFlags(ctx android.ModuleContext, cmd *an

	filename := proptools.StringDefault(d.properties.Api_levels_jar_filename, "android.jar")

	// TODO: Avoid the duplication of API surfaces, reuse apiScope.
	// Add all relevant --android-jar-pattern patterns for Metalava.
	// When parsing a stub jar for a specific version, Metalava picks the first pattern that defines
	// an actual file present on disk (in the order the patterns were passed). For system APIs for
	// privileged apps that are only defined since API level 21 (Lollipop), fallback to public stubs
	// for older releases. Similarly, module-lib falls back to system API.
	var sdkDirs []string
	switch proptools.StringDefault(d.properties.Api_levels_sdk_type, "public") {
	case "system-server":
		sdkDirs = []string{"system-server", "module-lib", "system", "public"}
	case "module-lib":
		sdkDirs = []string{"module-lib", "system", "public"}
	case "system":
		sdkDirs = []string{"system", "public"}
	case "public":
		sdkDirs = []string{"public"}
	default:
		ctx.PropertyErrorf("api_levels_sdk_type", "needs to be one of %v", allowedApiLevelSdkTypes)
		return
	}

	// Use the first item in the sdkDirs array as that is the sdk type for the target API levels
	// being generated but has the advantage over `Api_levels_sdk_type` as it has been validated.
	extensionsPattern := fmt.Sprintf(`/extensions/[0-9]+/%s/.*\.jar`, sdkDirs[0])

	var dirs []string
	var extensions_dir string
	ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
		if t, ok := m.(*ExportedDroiddocDir); ok {
			extRegex := regexp.MustCompile(t.dir.String() + `/extensions/[0-9]+/public/.*\.jar`)
			extRegex := regexp.MustCompile(t.dir.String() + extensionsPattern)

			// Grab the first extensions_dir and we find while scanning ExportedDroiddocDir.deps;
			// ideally this should be read from prebuiltApis.properties.Extensions_*
@@ -650,26 +675,6 @@ func (d *Droidstubs) apiLevelsGenerationFlags(ctx android.ModuleContext, cmd *an
		}
	})

	// Add all relevant --android-jar-pattern patterns for Metalava.
	// When parsing a stub jar for a specific version, Metalava picks the first pattern that defines
	// an actual file present on disk (in the order the patterns were passed). For system APIs for
	// privileged apps that are only defined since API level 21 (Lollipop), fallback to public stubs
	// for older releases. Similarly, module-lib falls back to system API.
	var sdkDirs []string
	switch proptools.StringDefault(d.properties.Api_levels_sdk_type, "public") {
	case "system-server":
		sdkDirs = []string{"system-server", "module-lib", "system", "public"}
	case "module-lib":
		sdkDirs = []string{"module-lib", "system", "public"}
	case "system":
		sdkDirs = []string{"system", "public"}
	case "public":
		sdkDirs = []string{"public"}
	default:
		ctx.PropertyErrorf("api_levels_sdk_type", "needs to be one of %v", allowedApiLevelSdkTypes)
		return
	}

	for _, sdkDir := range sdkDirs {
		for _, dir := range dirs {
			cmd.FlagWithArg("--android-jar-pattern ", fmt.Sprintf("%s/%%/%s/%s", dir, sdkDir, filename))