From 1262e20783b71a32348de33b1ec728b6c80ce3bf Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Fri, 7 Feb 2025 22:46:09 +0000 Subject: Convert api.xml dist rules to Soong ...from make to support dist'ing *-api.xml files in soong-only builds. Test: m droid dist --soong-only && ls out/dist/api.xml Bug: 395162087 Bug: 394365683 Change-Id: I98e92423a107d24b04e6f6f0f96c23c24de01fa5 --- java/java.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index c204476b1..2db7b1edc 100644 --- a/java/java.go +++ b/java/java.go @@ -828,6 +828,8 @@ type Library struct { combinedExportedProguardFlagsFile android.Path InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.InstallPaths) + + apiXmlFile android.WritablePath } var _ android.ApexModule = (*Library)(nil) @@ -1155,6 +1157,8 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.javaLibraryModuleInfoJSON(ctx) buildComplianceMetadata(ctx) + + j.createApiXmlFile(ctx) } func (j *Library) javaLibraryModuleInfoJSON(ctx android.ModuleContext) *android.ModuleInfoJSON { @@ -1259,6 +1263,35 @@ func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { } } +var apiXMLGeneratingApiSurfaces = []android.SdkKind{ + android.SdkPublic, + android.SdkSystem, + android.SdkModule, + android.SdkSystemServer, + android.SdkTest, +} + +func (j *Library) createApiXmlFile(ctx android.ModuleContext) { + if kind, ok := android.JavaLibraryNameToSdkKind(ctx.ModuleName()); ok && android.InList(kind, apiXMLGeneratingApiSurfaces) { + scopePrefix := AllApiScopes.matchingScopeFromSdkKind(kind).apiFilePrefix + j.apiXmlFile = android.PathForModuleOut(ctx, fmt.Sprintf("%sapi.xml", scopePrefix)) + ctx.Build(pctx, android.BuildParams{ + Rule: generateApiXMLRule, + // LOCAL_SOONG_CLASSES_JAR + Input: j.implementationAndResourcesJar, + Output: j.apiXmlFile, + }) + } +} + +var _ android.ModuleMakeVarsProvider = (*Library)(nil) + +func (j *Library) MakeVars(ctx android.MakeVarsModuleContext) { + if j.apiXmlFile != nil { + ctx.DistForGoal("dist_files", j.apiXmlFile) + } +} + const ( aidlIncludeDir = "aidl" javaDir = "java" -- cgit v1.2.3-59-g8ed1b