From 69f4218c4feaeca953237cd9e76a9a8cc423d3e3 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Wed, 29 Mar 2023 16:25:16 +0000 Subject: [PATCH 1/2] Rename JavaLibraryNameFromText function The "FromText" suffix is an implementation detail. Having this suffix in the name can be also confusing because in certain settings (e.g. when not run with --build-stub-from-text) it returns the name of the stub module generated from source files Test: go build ./java Change-Id: I68678ddfaa3d68c8e1a945632e7512b5de33d9af --- android/sdk_version.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/sdk_version.go b/android/sdk_version.go index 5bb1e5a2c..1f01dc64f 100644 --- a/android/sdk_version.go +++ b/android/sdk_version.go @@ -87,13 +87,13 @@ func (k SdkKind) String() string { // JavaLibraryName returns the soong module containing the Java APIs of that API surface. func (k SdkKind) JavaLibraryName(c Config) string { name := k.defaultJavaLibraryName() - return JavaLibraryNameFromText(c, name) + return JavaApiLibraryName(c, name) } -// JavaLibraryNameFromText returns the name of .txt equivalent of a java_library, but does +// JavaApiLibraryName returns the name of .txt equivalent of a java_library, but does // not check if either module exists. // TODO: Return .txt (single-tree or multi-tree equivalents) based on config -func JavaLibraryNameFromText(c Config, name string) string { +func JavaApiLibraryName(c Config, name string) string { if c.BuildFromTextStub() { return name + ".from-text" } From 877f39d535edfb58d75eac843a818234d1c56657 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Wed, 29 Mar 2023 16:19:51 +0000 Subject: [PATCH 2/2] Use stubs from .txt files for hiddenapi Hiddenapi processing uses the stub libraries to determine the api surface boundaries. Use JavaLibraryName function to redirect the usage of stubs from .txt files based on config. This should be a no-op for now. Bug: 271443071 Test: go test ./java Change-Id: I1ed3ab2485c903bc57f627dc1acf1a3fbc0a3c4d --- java/bootclasspath_fragment.go | 2 ++ java/sdk_library.go | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index c07a94a0b..f69256347 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -499,6 +499,8 @@ func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorCon for _, apiScope := range hiddenAPISdkLibrarySupportedScopes { // Add a dependency onto a possibly scope specific stub library. scopeSpecificDependency := apiScope.scopeSpecificStubModule(ctx, additionalStubModule) + // Use JavaApiLibraryName function to be redirected to stubs generated from .txt if applicable + scopeSpecificDependency = android.JavaApiLibraryName(ctx.Config(), scopeSpecificDependency) tag := hiddenAPIStubsDependencyTag{apiScope: apiScope, fromAdditionalDependency: true} ctx.AddVariationDependencies(nil, tag, scopeSpecificDependency) } diff --git a/java/sdk_library.go b/java/sdk_library.go index 5477ed664..103f1ace7 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1267,7 +1267,10 @@ var implLibraryTag = sdkLibraryComponentTag{name: "impl-library"} func (module *SdkLibrary) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { for _, apiScope := range module.getGeneratedApiScopes(ctx) { // Add dependencies to the stubs library - ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope)) + stubModuleName := module.stubsLibraryModuleName(apiScope) + // Use JavaApiLibraryName function to be redirected to stubs generated from .txt if applicable + stubModuleName = android.JavaApiLibraryName(ctx.Config(), stubModuleName) + ctx.AddVariationDependencies(nil, apiScope.stubsTag, stubModuleName) // Add a dependency on the stubs source in order to access both stubs source and api information. ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope))