Merge "Add annotations.zip support to java_sdk_library" am: 86da9c6a3d
am: 52b99b10f5
am: 40ef0e9141
am: 9ef920bcb1
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1832255 Change-Id: I53d92cb62e9fcbe1eaac08cf0fc64dd2c7a941d3
This commit is contained in:
@@ -156,6 +156,7 @@ type ApiStubsSrcProvider interface {
|
|||||||
|
|
||||||
// Provider of information about API stubs, used by java_sdk_library.
|
// Provider of information about API stubs, used by java_sdk_library.
|
||||||
type ApiStubsProvider interface {
|
type ApiStubsProvider interface {
|
||||||
|
AnnotationsZip() android.Path
|
||||||
ApiFilePath
|
ApiFilePath
|
||||||
RemovedApiFilePath() android.Path
|
RemovedApiFilePath() android.Path
|
||||||
|
|
||||||
@@ -210,6 +211,10 @@ func (d *Droidstubs) OutputFiles(tag string) (android.Paths, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Droidstubs) AnnotationsZip() android.Path {
|
||||||
|
return d.annotationsZip
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Droidstubs) ApiFilePath() android.Path {
|
func (d *Droidstubs) ApiFilePath() android.Path {
|
||||||
return d.apiFilePath
|
return d.apiFilePath
|
||||||
}
|
}
|
||||||
|
@@ -550,6 +550,9 @@ type scopePaths struct {
|
|||||||
|
|
||||||
// The stubs source jar.
|
// The stubs source jar.
|
||||||
stubsSrcJar android.OptionalPath
|
stubsSrcJar android.OptionalPath
|
||||||
|
|
||||||
|
// Extracted annotations.
|
||||||
|
annotationsZip android.OptionalPath
|
||||||
}
|
}
|
||||||
|
|
||||||
func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error {
|
func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error {
|
||||||
@@ -585,6 +588,7 @@ func (paths *scopePaths) treatDepAsApiStubsSrcProvider(dep android.Module, actio
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider) {
|
func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider) {
|
||||||
|
paths.annotationsZip = android.OptionalPathForPath(provider.AnnotationsZip())
|
||||||
paths.currentApiFilePath = android.OptionalPathForPath(provider.ApiFilePath())
|
paths.currentApiFilePath = android.OptionalPathForPath(provider.ApiFilePath())
|
||||||
paths.removedApiFilePath = android.OptionalPathForPath(provider.RemovedApiFilePath())
|
paths.removedApiFilePath = android.OptionalPathForPath(provider.RemovedApiFilePath())
|
||||||
}
|
}
|
||||||
@@ -739,6 +743,8 @@ const (
|
|||||||
apiTxtComponentName = "api.txt"
|
apiTxtComponentName = "api.txt"
|
||||||
|
|
||||||
removedApiTxtComponentName = "removed-api.txt"
|
removedApiTxtComponentName = "removed-api.txt"
|
||||||
|
|
||||||
|
annotationsComponentName = "annotations.zip"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A regular expression to match tags that reference a specific stubs component.
|
// A regular expression to match tags that reference a specific stubs component.
|
||||||
@@ -757,7 +763,7 @@ var tagSplitter = func() *regexp.Regexp {
|
|||||||
scopesRegexp := choice(allScopeNames...)
|
scopesRegexp := choice(allScopeNames...)
|
||||||
|
|
||||||
// Regular expression to match one of the components.
|
// 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.
|
// Regular expression to match any combination of one scope and one component.
|
||||||
return regexp.MustCompile(fmt.Sprintf(`^\.(%s)\.(%s)$`, scopesRegexp, componentsRegexp))
|
return regexp.MustCompile(fmt.Sprintf(`^\.(%s)\.(%s)$`, scopesRegexp, componentsRegexp))
|
||||||
@@ -765,9 +771,7 @@ var tagSplitter = func() *regexp.Regexp {
|
|||||||
|
|
||||||
// For OutputFileProducer interface
|
// For OutputFileProducer interface
|
||||||
//
|
//
|
||||||
// .<scope>.stubs.source
|
// .<scope>.<component name>, for all ComponentNames (for example: .public.removed-api.txt)
|
||||||
// .<scope>.api.txt
|
|
||||||
// .<scope>.removed-api.txt
|
|
||||||
func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Paths, error) {
|
func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Paths, error) {
|
||||||
if groups := tagSplitter.FindStringSubmatch(tag); groups != nil {
|
if groups := tagSplitter.FindStringSubmatch(tag); groups != nil {
|
||||||
scopeName := groups[1]
|
scopeName := groups[1]
|
||||||
@@ -794,6 +798,11 @@ func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Pat
|
|||||||
if paths.removedApiFilePath.Valid() {
|
if paths.removedApiFilePath.Valid() {
|
||||||
return android.Paths{paths.removedApiFilePath.Path()}, nil
|
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)
|
return nil, fmt.Errorf("%s not available for api scope %s", component, scopeName)
|
||||||
@@ -1888,6 +1897,9 @@ type sdkLibraryScopeProperties struct {
|
|||||||
|
|
||||||
// The removed.txt
|
// The removed.txt
|
||||||
Removed_api *string `android:"path"`
|
Removed_api *string `android:"path"`
|
||||||
|
|
||||||
|
// Annotation zip
|
||||||
|
Annotations *string `android:"path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type sdkLibraryImportProperties struct {
|
type sdkLibraryImportProperties struct {
|
||||||
@@ -2201,6 +2213,7 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
paths := module.getScopePathsCreateIfNeeded(apiScope)
|
paths := module.getScopePathsCreateIfNeeded(apiScope)
|
||||||
|
paths.annotationsZip = android.OptionalPathForModuleSrc(ctx, scopeProperties.Annotations)
|
||||||
paths.currentApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Current_api)
|
paths.currentApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Current_api)
|
||||||
paths.removedApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Removed_api)
|
paths.removedApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Removed_api)
|
||||||
}
|
}
|
||||||
@@ -2551,6 +2564,7 @@ type scopeProperties struct {
|
|||||||
StubsSrcJar android.Path
|
StubsSrcJar android.Path
|
||||||
CurrentApiFile android.Path
|
CurrentApiFile android.Path
|
||||||
RemovedApiFile android.Path
|
RemovedApiFile android.Path
|
||||||
|
AnnotationsZip android.Path
|
||||||
SdkVersion string
|
SdkVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2576,6 +2590,10 @@ func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMembe
|
|||||||
if paths.removedApiFilePath.Valid() {
|
if paths.removedApiFilePath.Valid() {
|
||||||
properties.RemovedApiFile = paths.removedApiFilePath.Path()
|
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
|
s.Scopes[apiScope] = properties
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2640,6 +2658,12 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo
|
|||||||
scopeSet.AddProperty("removed_api", removedApiSnapshotPath)
|
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 != "" {
|
if properties.SdkVersion != "" {
|
||||||
scopeSet.AddProperty("sdk_version", properties.SdkVersion)
|
scopeSet.AddProperty("sdk_version", properties.SdkVersion)
|
||||||
}
|
}
|
||||||
|
@@ -248,12 +248,37 @@ func TestJavaSdkLibrary_DoNotAccessImplWhenItIsNotBuilt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJavaSdkLibrary_UseSourcesFromAnotherSdkLibrary(t *testing.T) {
|
func TestJavaSdkLibrary_AccessOutputFiles(t *testing.T) {
|
||||||
android.GroupFixturePreparers(
|
android.GroupFixturePreparers(
|
||||||
prepareForJavaTest,
|
prepareForJavaTest,
|
||||||
PrepareForTestWithJavaSdkLibraryFiles,
|
PrepareForTestWithJavaSdkLibraryFiles,
|
||||||
FixtureWithLastReleaseApis("foo"),
|
FixtureWithLastReleaseApis("foo"),
|
||||||
).RunTestWithBp(t, `
|
).RunTestWithBp(t, `
|
||||||
|
java_sdk_library {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
api_packages: ["foo"],
|
||||||
|
annotations_enabled: true,
|
||||||
|
public: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
java_library {
|
||||||
|
name: "bar",
|
||||||
|
srcs: ["b.java", ":foo{.public.stubs.source}"],
|
||||||
|
java_resources: [":foo{.public.annotations.zip}"],
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJavaSdkLibrary_AccessOutputFiles_NoAnnotations(t *testing.T) {
|
||||||
|
android.GroupFixturePreparers(
|
||||||
|
prepareForJavaTest,
|
||||||
|
PrepareForTestWithJavaSdkLibraryFiles,
|
||||||
|
FixtureWithLastReleaseApis("foo"),
|
||||||
|
).
|
||||||
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "bar" variant "android_common": path dependency ":foo{.public.annotations.zip}": annotations.zip not available for api scope public`)).
|
||||||
|
RunTestWithBp(t, `
|
||||||
java_sdk_library {
|
java_sdk_library {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
@@ -266,6 +291,7 @@ func TestJavaSdkLibrary_UseSourcesFromAnotherSdkLibrary(t *testing.T) {
|
|||||||
java_library {
|
java_library {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
srcs: ["b.java", ":foo{.public.stubs.source}"],
|
srcs: ["b.java", ":foo{.public.stubs.source}"],
|
||||||
|
java_resources: [":foo{.public.annotations.zip}"],
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
@@ -329,6 +355,7 @@ func TestJavaSdkLibraryImport_AccessOutputFiles(t *testing.T) {
|
|||||||
stub_srcs: ["a.java"],
|
stub_srcs: ["a.java"],
|
||||||
current_api: "api/current.txt",
|
current_api: "api/current.txt",
|
||||||
removed_api: "api/removed.txt",
|
removed_api: "api/removed.txt",
|
||||||
|
annotations: "x/annotations.zip",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,6 +365,7 @@ func TestJavaSdkLibraryImport_AccessOutputFiles(t *testing.T) {
|
|||||||
java_resources: [
|
java_resources: [
|
||||||
":foo{.public.api.txt}",
|
":foo{.public.api.txt}",
|
||||||
":foo{.public.removed-api.txt}",
|
":foo{.public.removed-api.txt}",
|
||||||
|
":foo{.public.annotations.zip}",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
@@ -300,6 +300,7 @@ func gatherRequiredDepsForTest() string {
|
|||||||
"kotlin-stdlib-jdk7",
|
"kotlin-stdlib-jdk7",
|
||||||
"kotlin-stdlib-jdk8",
|
"kotlin-stdlib-jdk8",
|
||||||
"kotlin-annotations",
|
"kotlin-annotations",
|
||||||
|
"stub-annotations",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, extra := range extraModules {
|
for _, extra := range extraModules {
|
||||||
|
@@ -1205,6 +1205,55 @@ java_sdk_library_import {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSnapshotWithJavaSdkLibrary_AnnotationsZip(t *testing.T) {
|
||||||
|
result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
|
||||||
|
sdk {
|
||||||
|
name: "mysdk",
|
||||||
|
java_sdk_libs: ["myjavalib"],
|
||||||
|
}
|
||||||
|
|
||||||
|
java_sdk_library {
|
||||||
|
name: "myjavalib",
|
||||||
|
srcs: ["Test.java"],
|
||||||
|
sdk_version: "current",
|
||||||
|
shared_library: false,
|
||||||
|
annotations_enabled: true,
|
||||||
|
public: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
CheckSnapshot(t, result, "mysdk", "",
|
||||||
|
checkUnversionedAndroidBpContents(`
|
||||||
|
// This is auto-generated. DO NOT EDIT.
|
||||||
|
|
||||||
|
java_sdk_library_import {
|
||||||
|
name: "myjavalib",
|
||||||
|
prefer: false,
|
||||||
|
visibility: ["//visibility:public"],
|
||||||
|
apex_available: ["//apex_available:platform"],
|
||||||
|
shared_library: false,
|
||||||
|
public: {
|
||||||
|
jars: ["sdk_library/public/myjavalib-stubs.jar"],
|
||||||
|
stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
|
||||||
|
current_api: "sdk_library/public/myjavalib.txt",
|
||||||
|
removed_api: "sdk_library/public/myjavalib-removed.txt",
|
||||||
|
annotations: "sdk_library/public/myjavalib_annotations.zip",
|
||||||
|
sdk_version: "current",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`),
|
||||||
|
checkAllCopyRules(`
|
||||||
|
.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
|
||||||
|
.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
|
||||||
|
.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
|
||||||
|
.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_annotations.zip -> sdk_library/public/myjavalib_annotations.zip
|
||||||
|
`),
|
||||||
|
checkMergeZips(".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func TestSnapshotWithJavaSdkLibrary_CompileDex(t *testing.T) {
|
func TestSnapshotWithJavaSdkLibrary_CompileDex(t *testing.T) {
|
||||||
result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
|
result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
|
||||||
sdk {
|
sdk {
|
||||||
|
Reference in New Issue
Block a user