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

Commit 1e4ac1d6 authored by Jihoon Kang's avatar Jihoon Kang
Browse files

Create java_defaults in api.go

combined_apis.bootclasspath lists java_sdk_library modules that
contribute to API surfaces. The api_contribution modules generated from
these sdk_library modules (more specifically, from droidstubs module
created from the sdk_library module) are used to generate full api
surface java_api_library modules. Currently, the java_defaults modules
are hardcoded, but this leads to a duplicate source of truth, adding
difficulty in scaling the api domains that contributes to api surfaces.

Generating the java_defaults dynamically in combined_apis instead of
hardcoding resolves this problem, as well as the discrepancy in the list
of api contributions in aosp and internal master.

Test: m android_<API_SURFACE_NAME>_stubs_current.from-text
Bug: 277378670
Change-Id: I987c2c1d89535d2347cf14d084c9c9a47e1db5e0
parent fdbe2583
Loading
Loading
Loading
Loading
+45 −10
Original line number Diff line number Diff line
@@ -15,7 +15,9 @@
package api

import (
	"fmt"
	"sort"
	"strings"

	"github.com/google/blueprint/proptools"

@@ -102,6 +104,13 @@ type fgProps struct {
	Visibility []string
}

type defaultsProps struct {
	Name                *string
	Api_surface         *string
	Api_contributions   []string
	Defaults_visibility []string
}

type Bazel_module struct {
	Bp2build_available *bool
}
@@ -329,6 +338,30 @@ func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_
	}
}

func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) {
	defaultsSdkKinds := []android.SdkKind{
		android.SdkPublic, android.SdkSystem, android.SdkModule,
	}
	for _, sdkKind := range defaultsSdkKinds {
		props := defaultsProps{}
		props.Name = proptools.StringPtr(
			sdkKind.DefaultJavaLibraryName() + "_contributions")
		if sdkKind == android.SdkModule {
			props.Name = proptools.StringPtr(
				sdkKind.DefaultJavaLibraryName() + "_contributions_full")
		}
		props.Api_surface = proptools.StringPtr(sdkKind.String())
		apiSuffix := ""
		if sdkKind != android.SdkPublic {
			apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_")
		}
		props.Api_contributions = transformArray(
			modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix))
		props.Defaults_visibility = []string{"//visibility:public"}
		ctx.CreateModule(java.DefaultsFactory, &props)
	}
}

func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
	bootclasspath := a.properties.Bootclasspath
	system_server_classpath := a.properties.System_server_classpath
@@ -347,6 +380,8 @@ func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
	createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)

	createPublicStubsSourceFilegroup(ctx, bootclasspath)

	createApiContributionDefaults(ctx, bootclasspath)
}

func combinedApisModuleFactory() android.Module {