Merge "Add annotations.zip support to java_sdk_library" am: 86da9c6a3d am: 52b99b10f5 am: 40ef0e9141 am: 9ef920bcb1 am: ee9ab003bb

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1832255

Change-Id: I10e4e4c5188f0a0297ee2baa1b5cf4a1b0f234a9
This commit is contained in:
Anton Hansson
2021-09-23 10:41:47 +00:00
committed by Automerger Merge Worker
5 changed files with 112 additions and 5 deletions

View File

@@ -533,6 +533,9 @@ type scopePaths struct {
// The stubs source jar.
stubsSrcJar android.OptionalPath
// Extracted annotations.
annotationsZip android.OptionalPath
}
func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error {
@@ -568,6 +571,7 @@ func (paths *scopePaths) treatDepAsApiStubsSrcProvider(dep android.Module, actio
}
func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider) {
paths.annotationsZip = android.OptionalPathForPath(provider.AnnotationsZip())
paths.currentApiFilePath = android.OptionalPathForPath(provider.ApiFilePath())
paths.removedApiFilePath = android.OptionalPathForPath(provider.RemovedApiFilePath())
}
@@ -749,6 +753,8 @@ const (
apiTxtComponentName = "api.txt"
removedApiTxtComponentName = "removed-api.txt"
annotationsComponentName = "annotations.zip"
)
// A regular expression to match tags that reference a specific stubs component.
@@ -767,7 +773,7 @@ var tagSplitter = func() *regexp.Regexp {
scopesRegexp := choice(allScopeNames...)
// Regular expression to match one of the components.
componentsRegexp := choice(stubsSourceComponentName, apiTxtComponentName, removedApiTxtComponentName)
componentsRegexp := choice(stubsSourceComponentName, apiTxtComponentName, removedApiTxtComponentName, annotationsComponentName)
// Regular expression to match any combination of one scope and one component.
return regexp.MustCompile(fmt.Sprintf(`^\.(%s)\.(%s)$`, scopesRegexp, componentsRegexp))
@@ -775,9 +781,7 @@ var tagSplitter = func() *regexp.Regexp {
// For OutputFileProducer interface
//
// .<scope>.stubs.source
// .<scope>.api.txt
// .<scope>.removed-api.txt
// .<scope>.<component name>, for all ComponentNames (for example: .public.removed-api.txt)
func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Paths, error) {
if groups := tagSplitter.FindStringSubmatch(tag); groups != nil {
scopeName := groups[1]
@@ -804,6 +808,11 @@ func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Pat
if paths.removedApiFilePath.Valid() {
return android.Paths{paths.removedApiFilePath.Path()}, nil
}
case annotationsComponentName:
if paths.annotationsZip.Valid() {
return android.Paths{paths.annotationsZip.Path()}, nil
}
}
return nil, fmt.Errorf("%s not available for api scope %s", component, scopeName)
@@ -1906,6 +1915,9 @@ type sdkLibraryScopeProperties struct {
// The removed.txt
Removed_api *string `android:"path"`
// Annotation zip
Annotations *string `android:"path"`
}
type sdkLibraryImportProperties struct {
@@ -2219,6 +2231,7 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo
}
paths := module.getScopePathsCreateIfNeeded(apiScope)
paths.annotationsZip = android.OptionalPathForModuleSrc(ctx, scopeProperties.Annotations)
paths.currentApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Current_api)
paths.removedApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Removed_api)
}
@@ -2683,6 +2696,7 @@ type scopeProperties struct {
StubsSrcJar android.Path
CurrentApiFile android.Path
RemovedApiFile android.Path
AnnotationsZip android.Path
SdkVersion string
}
@@ -2708,6 +2722,10 @@ func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMembe
if paths.removedApiFilePath.Valid() {
properties.RemovedApiFile = paths.removedApiFilePath.Path()
}
// The annotations zip is only available for modules that set annotations_enabled: true.
if paths.annotationsZip.Valid() {
properties.AnnotationsZip = paths.annotationsZip.Path()
}
s.Scopes[apiScope] = properties
}
}
@@ -2776,6 +2794,12 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo
scopeSet.AddProperty("removed_api", removedApiSnapshotPath)
}
if properties.AnnotationsZip != nil {
annotationsSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"_annotations.zip")
ctx.SnapshotBuilder().CopyToSnapshot(properties.AnnotationsZip, annotationsSnapshotPath)
scopeSet.AddProperty("annotations", annotationsSnapshotPath)
}
if properties.SdkVersion != "" {
scopeSet.AddProperty("sdk_version", properties.SdkVersion)
}