diff --git a/java/sdk_library.go b/java/sdk_library.go index 0d29a3763..60924a662 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -589,6 +589,9 @@ type commonToSdkLibraryAndImportProperties struct { // An Android shared library is one that can be referenced in a element // in an AndroidManifest.xml. Shared_library *bool + + // Files containing information about supported java doc tags. + Doctag_files []string `android:"path"` } // Common code between sdk library and sdk library import @@ -601,6 +604,9 @@ type commonToSdkLibraryAndImport struct { commonSdkLibraryProperties commonToSdkLibraryAndImportProperties + // Paths to commonSdkLibraryProperties.Doctag_files + doctagPaths android.Paths + // Functionality related to this being used as a component of a java_sdk_library. EmbeddableSdkLibraryComponent } @@ -633,6 +639,10 @@ func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android return true } +func (c *commonToSdkLibraryAndImport) generateCommonBuildActions(ctx android.ModuleContext) { + c.doctagPaths = android.PathsForModuleSrc(ctx, c.commonSdkLibraryProperties.Doctag_files) +} + // Module name of the runtime implementation library func (c *commonToSdkLibraryAndImport) implLibraryModuleName() string { return c.moduleBase.BaseModuleName() + ".impl" @@ -732,6 +742,14 @@ func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Pat } } else { + switch tag { + case ".doctags": + if c.doctagPaths != nil { + return c.doctagPaths, nil + } else { + return nil, fmt.Errorf("no doctag_files specified on %s", c.moduleBase.BaseModuleName()) + } + } return nil, nil } } @@ -1014,6 +1032,8 @@ func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) { } func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { + module.generateCommonBuildActions(ctx) + // Only build an implementation library if required. if module.requiresRuntimeImplementationLibrary() { module.Library.GenerateAndroidBuildActions(ctx) @@ -1895,6 +1915,8 @@ func (module *SdkLibraryImport) OutputFiles(tag string) (android.Paths, error) { } func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { + module.generateCommonBuildActions(ctx) + // Record the paths to the prebuilt stubs library and stubs source. ctx.VisitDirectDeps(func(to android.Module) { tag := ctx.OtherModuleDependencyTag(to) @@ -2187,6 +2209,9 @@ type sdkLibrarySdkMemberProperties struct { // True if the java_sdk_library_import is for a shared library, false // otherwise. Shared_library *bool + + // The paths to the doctag files to add to the prebuilt. + Doctag_paths android.Paths } type scopeProperties struct { @@ -2226,6 +2251,7 @@ func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMembe s.Libs = sdk.properties.Libs s.Naming_scheme = sdk.commonSdkLibraryProperties.Naming_scheme s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary()) + s.Doctag_paths = sdk.doctagPaths } func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { @@ -2274,6 +2300,16 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo } } + if len(s.Doctag_paths) > 0 { + dests := []string{} + for _, p := range s.Doctag_paths { + dest := filepath.Join("doctags", p.Rel()) + ctx.SnapshotBuilder().CopyToSnapshot(p, dest) + dests = append(dests, dest) + } + propertySet.AddProperty("doctag_files", dests) + } + if len(s.Libs) > 0 { propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false)) } diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index a7ee8d12f..23ecb6d06 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -43,6 +43,7 @@ func testSdkWithJava(t *testing.T, bp string) *testSdkResult { "api/system-server-current.txt": nil, "api/system-server-removed.txt": nil, "build/soong/scripts/gen-java-current-api-files.sh": nil, + "docs/known_doctags": nil, } // for java_sdk_library tests @@ -1590,3 +1591,72 @@ sdk_snapshot { ), ) } + +func TestSnapshotWithJavaSdkLibrary_DoctagFiles(t *testing.T) { + result := testSdkWithJava(t, ` + sdk { + name: "mysdk", + java_sdk_libs: ["myjavalib"], + } + + java_sdk_library { + name: "myjavalib", + srcs: ["Test.java"], + sdk_version: "current", + public: { + enabled: true, + }, + doctag_files: ["docs/known_doctags"], + } + + filegroup { + name: "mygroup", + srcs: [":myjavalib{.doctags}"], + } + `) + + result.CheckSnapshot("mysdk", "", + checkAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +java_sdk_library_import { + name: "mysdk_myjavalib@current", + sdk_member_name: "myjavalib", + shared_library: true, + doctag_files: ["doctags/docs/known_doctags"], + 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", + sdk_version: "current", + }, +} + +java_sdk_library_import { + name: "myjavalib", + prefer: false, + shared_library: true, + doctag_files: ["doctags/docs/known_doctags"], + 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", + sdk_version: "current", + }, +} + +sdk_snapshot { + name: "mysdk@current", + java_sdk_libs: ["mysdk_myjavalib@current"], +} +`), + checkAllCopyRules(` +.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar +.intermediates/myjavalib.stubs.source/android_common/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt +.intermediates/myjavalib.stubs.source/android_common/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt +docs/known_doctags -> doctags/docs/known_doctags +`), + ) +} diff --git a/sdk/testing.go b/sdk/testing.go index ae1e44888..0b280efa3 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -94,6 +94,7 @@ func testSdkContext(bp string, fs map[string][]byte, extraOsTypes []android.OsTy // from android package android.RegisterPackageBuildComponents(ctx) + ctx.RegisterModuleType("filegroup", android.FileGroupFactory) ctx.PreArchMutators(android.RegisterVisibilityRuleChecker) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) ctx.PreArchMutators(android.RegisterComponentsMutator)