2018-04-10 06:07:10 +02:00
// Copyright 2018 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package java
import (
2024-01-23 01:16:41 +01:00
"errors"
2018-04-10 06:07:10 +02:00
"fmt"
"path"
2018-10-19 06:46:09 +02:00
"path/filepath"
2020-04-07 20:27:04 +02:00
"reflect"
2020-05-14 16:39:10 +02:00
"regexp"
2018-04-23 14:41:26 +02:00
"sort"
2018-04-10 06:07:10 +02:00
"strings"
2018-04-23 14:41:26 +02:00
"sync"
2018-04-10 06:07:10 +02:00
2020-01-22 12:57:20 +01:00
"github.com/google/blueprint"
2018-04-10 06:07:10 +02:00
"github.com/google/blueprint/proptools"
2020-04-07 20:27:04 +02:00
"android/soong/android"
2020-12-17 13:07:54 +01:00
"android/soong/dexpreopt"
2018-04-10 06:07:10 +02:00
)
2019-12-18 07:34:32 +01:00
const (
2021-09-07 19:21:59 +02:00
sdkXmlFileSuffix = ".xml"
2018-04-10 06:07:10 +02:00
)
2020-01-22 12:57:20 +01:00
// A tag to associated a dependency with a specific api scope.
type scopeDependencyTag struct {
blueprint . BaseDependencyTag
name string
apiScope * apiScope
2020-04-29 21:45:27 +02:00
// Function for extracting appropriate path information from the dependency.
2021-02-01 22:59:03 +01:00
depInfoExtractor func ( paths * scopePaths , ctx android . ModuleContext , dep android . Module ) error
2020-04-29 21:45:27 +02:00
}
// Extract tag specific information from the dependency.
func ( tag scopeDependencyTag ) extractDepInfo ( ctx android . ModuleContext , dep android . Module , paths * scopePaths ) {
2021-02-01 22:59:03 +01:00
err := tag . depInfoExtractor ( paths , ctx , dep )
2020-04-29 21:45:27 +02:00
if err != nil {
ctx . ModuleErrorf ( "has an invalid {scopeDependencyTag: %s} dependency on module %s: %s" , tag . name , ctx . OtherModuleName ( dep ) , err . Error ( ) )
}
2020-01-22 12:57:20 +01:00
}
2018-04-27 09:29:21 +02:00
2020-06-26 23:08:43 +02:00
var _ android . ReplaceSourceWithPrebuilt = ( * scopeDependencyTag ) ( nil )
func ( tag scopeDependencyTag ) ReplaceSourceWithPrebuilt ( ) bool {
return false
}
2020-01-22 12:57:20 +01:00
// Provides information about an api scope, e.g. public, system, test.
type apiScope struct {
// The name of the api scope, e.g. public, system, test
name string
2018-04-27 09:29:21 +02:00
2020-05-05 15:40:52 +02:00
// The api scope that this scope extends.
Allow sdk_version: "system_server_current" modules to access module-lib APIs
Previously, a java module with sdk_version: "system_server_current",
would only be able to access the system server or public API of a
java_sdk_library. This change allows it to access the system server,
module lib, system and public APIs in that order.
The apiScope structs define the characteristics of each of the
different API scopes used as required by the java_sdk_library. They are
organized into a hierarchy which is used for two different purposes.
The first purpose is to define an extension hierachy. If scope X
extends Y then X provides a superset of all API elements (classes,
fields, methods, etc) provided by Y. That is reflected in the fact that
the .txt file for X would be a delta on the .txt file for Y. So, system
extends public and so system_current.txt only contains additional API
elements to add to current.txt.
The second purpose is when a java_sdk_library/import is asked to
provide a specific API scope. e.g. a library that has:
sdk_version: "module_current"
will ask each of the SDK libraries it depends upon for a module-lib
API. However, not all of them will provide an API for that scope. In
that case it will find the closest suitable API scope.
Previously, it did that by traversing up the API extension until it
found an API scope that it did provide and return that. As
system_server_current extended the public API that meant that a library
which has:
sdk_version: "system_server_current"
would provide a system server API if available, and if not fall
straight back to public. That meant that the library could not access
system or module-lib APIs even though it is running in the system
server which should be able to access all APIs.
One way to fix this would have been to just have system server API
scope extend module-lib but that would have had a number of nasty
side effects:
* It would have created a significant overhead as every module that
provides a system server API would also have to provide a module-lib
and system API, along with their corresponding .txt files.
* Each existing java_sdk_library that provided a system server API
would need those .txt files created.
* Generating sdk snapshots for older releases would have been more
complicated.
* It would have confused developers.
All of that would be unnecessary because the system server API scope is
intended to be provided by libraries that are used solely by the system
server so there is no point in them providing anything other than a
system server API.
So, instead a separate access hierarchy was added which is the same as
the extension hierarchy for all existing scopes except for the
system server scope, which instead of just being able to access the
public API will be able to access the module-lib scope, which can in
turn access system and it can in turn access public.
That achieves what we want which is a library that is loaded into the
system server to be able to access all API scopes.
Bug: 204176972
Test: m nothing
Change-Id: I854df63fcaeba32afbc1eb0d1a501238022673d0
2022-09-30 19:11:41 +02:00
//
// This organizes the scopes into an extension hierarchy.
//
// If set this means that the API provided by this scope includes the API provided by the scope
// set in this field.
2020-05-05 15:40:52 +02:00
extends * apiScope
Allow sdk_version: "system_server_current" modules to access module-lib APIs
Previously, a java module with sdk_version: "system_server_current",
would only be able to access the system server or public API of a
java_sdk_library. This change allows it to access the system server,
module lib, system and public APIs in that order.
The apiScope structs define the characteristics of each of the
different API scopes used as required by the java_sdk_library. They are
organized into a hierarchy which is used for two different purposes.
The first purpose is to define an extension hierachy. If scope X
extends Y then X provides a superset of all API elements (classes,
fields, methods, etc) provided by Y. That is reflected in the fact that
the .txt file for X would be a delta on the .txt file for Y. So, system
extends public and so system_current.txt only contains additional API
elements to add to current.txt.
The second purpose is when a java_sdk_library/import is asked to
provide a specific API scope. e.g. a library that has:
sdk_version: "module_current"
will ask each of the SDK libraries it depends upon for a module-lib
API. However, not all of them will provide an API for that scope. In
that case it will find the closest suitable API scope.
Previously, it did that by traversing up the API extension until it
found an API scope that it did provide and return that. As
system_server_current extended the public API that meant that a library
which has:
sdk_version: "system_server_current"
would provide a system server API if available, and if not fall
straight back to public. That meant that the library could not access
system or module-lib APIs even though it is running in the system
server which should be able to access all APIs.
One way to fix this would have been to just have system server API
scope extend module-lib but that would have had a number of nasty
side effects:
* It would have created a significant overhead as every module that
provides a system server API would also have to provide a module-lib
and system API, along with their corresponding .txt files.
* Each existing java_sdk_library that provided a system server API
would need those .txt files created.
* Generating sdk snapshots for older releases would have been more
complicated.
* It would have confused developers.
All of that would be unnecessary because the system server API scope is
intended to be provided by libraries that are used solely by the system
server so there is no point in them providing anything other than a
system server API.
So, instead a separate access hierarchy was added which is the same as
the extension hierarchy for all existing scopes except for the
system server scope, which instead of just being able to access the
public API will be able to access the module-lib scope, which can in
turn access system and it can in turn access public.
That achieves what we want which is a library that is loaded into the
system server to be able to access all API scopes.
Bug: 204176972
Test: m nothing
Change-Id: I854df63fcaeba32afbc1eb0d1a501238022673d0
2022-09-30 19:11:41 +02:00
// The next api scope that a library that uses this scope can access.
//
// This organizes the scopes into an access hierarchy.
//
// If set this means that a library that can access this API can also access the API provided by
// the scope set in this field.
//
// A module that sets sdk_version: "<scope>_current" should have access to the <scope> API of
// every java_sdk_library that it depends on. If the library does not provide an API for <scope>
// then it will traverse up this access hierarchy to find an API that it does provide.
//
// If this is not set then it defaults to the scope set in extends.
canAccess * apiScope
2020-04-28 11:44:03 +02:00
// The legacy enabled status for a specific scope can be dependent on other
// properties that have been specified on the library so it is provided by
// a function that can determine the status by examining those properties.
legacyEnabledStatus func ( module * SdkLibrary ) bool
// The default enabled status for non-legacy behavior, which is triggered by
// explicitly enabling at least one api scope.
defaultEnabledStatus bool
// Gets a pointer to the scope specific properties.
scopeSpecificProperties func ( module * SdkLibrary ) * ApiScopeProperties
2020-04-07 20:27:04 +02:00
// The name of the field in the dynamically created structure.
fieldName string
2020-05-13 20:19:49 +02:00
// The name of the property in the java_sdk_library_import
propertyName string
2024-01-22 20:40:08 +01:00
// The tag to use to depend on the prebuilt stubs library module
prebuiltStubsTag scopeDependencyTag
2020-01-22 12:57:20 +01:00
2023-12-26 20:08:01 +01:00
// The tag to use to depend on the everything stubs library module.
everythingStubsTag scopeDependencyTag
// The tag to use to depend on the exportable stubs library module.
exportableStubsTag scopeDependencyTag
2020-04-29 14:30:54 +02:00
// The tag to use to depend on the stubs source module (if separate from the API module).
stubsSourceTag scopeDependencyTag
// The tag to use to depend on the API file generating module (if separate from the stubs source module).
apiFileTag scopeDependencyTag
2020-04-29 21:45:27 +02:00
// The tag to use to depend on the stubs source and API module.
stubsSourceAndApiTag scopeDependencyTag
2020-01-22 12:57:20 +01:00
2022-05-16 15:10:47 +02:00
// The tag to use to depend on the module that provides the latest version of the API .txt file.
latestApiModuleTag scopeDependencyTag
// The tag to use to depend on the module that provides the latest version of the API removed.txt
// file.
latestRemovedApiModuleTag scopeDependencyTag
2020-01-22 12:57:20 +01:00
// The scope specific prefix to add to the api file base of "current.txt" or "removed.txt".
apiFilePrefix string
Allow sdk_version: "system_server_current" modules to access module-lib APIs
Previously, a java module with sdk_version: "system_server_current",
would only be able to access the system server or public API of a
java_sdk_library. This change allows it to access the system server,
module lib, system and public APIs in that order.
The apiScope structs define the characteristics of each of the
different API scopes used as required by the java_sdk_library. They are
organized into a hierarchy which is used for two different purposes.
The first purpose is to define an extension hierachy. If scope X
extends Y then X provides a superset of all API elements (classes,
fields, methods, etc) provided by Y. That is reflected in the fact that
the .txt file for X would be a delta on the .txt file for Y. So, system
extends public and so system_current.txt only contains additional API
elements to add to current.txt.
The second purpose is when a java_sdk_library/import is asked to
provide a specific API scope. e.g. a library that has:
sdk_version: "module_current"
will ask each of the SDK libraries it depends upon for a module-lib
API. However, not all of them will provide an API for that scope. In
that case it will find the closest suitable API scope.
Previously, it did that by traversing up the API extension until it
found an API scope that it did provide and return that. As
system_server_current extended the public API that meant that a library
which has:
sdk_version: "system_server_current"
would provide a system server API if available, and if not fall
straight back to public. That meant that the library could not access
system or module-lib APIs even though it is running in the system
server which should be able to access all APIs.
One way to fix this would have been to just have system server API
scope extend module-lib but that would have had a number of nasty
side effects:
* It would have created a significant overhead as every module that
provides a system server API would also have to provide a module-lib
and system API, along with their corresponding .txt files.
* Each existing java_sdk_library that provided a system server API
would need those .txt files created.
* Generating sdk snapshots for older releases would have been more
complicated.
* It would have confused developers.
All of that would be unnecessary because the system server API scope is
intended to be provided by libraries that are used solely by the system
server so there is no point in them providing anything other than a
system server API.
So, instead a separate access hierarchy was added which is the same as
the extension hierarchy for all existing scopes except for the
system server scope, which instead of just being able to access the
public API will be able to access the module-lib scope, which can in
turn access system and it can in turn access public.
That achieves what we want which is a library that is loaded into the
system server to be able to access all API scopes.
Bug: 204176972
Test: m nothing
Change-Id: I854df63fcaeba32afbc1eb0d1a501238022673d0
2022-09-30 19:11:41 +02:00
// The scope specific suffix to add to the sdk library module name to construct a scope specific
2020-01-22 12:57:20 +01:00
// module name.
moduleSuffix string
// SDK version that the stubs library is built against. Note that this is always
// *current. Older stubs library built with a numbered SDK version is created from
// the prebuilt jar.
sdkVersion string
2020-04-07 19:50:10 +02:00
2020-07-20 19:04:44 +02:00
// The annotation that identifies this API level, empty for the public API scope.
annotation string
2020-05-02 12:19:36 +02:00
2020-07-20 19:04:44 +02:00
// Extra arguments to pass to droidstubs for this scope.
2020-04-29 14:30:54 +02:00
//
2020-07-20 19:04:44 +02:00
// This is not used directly but is used to construct the droidstubsArgs.
extraArgs [ ] string
2020-04-29 14:30:54 +02:00
2020-07-20 19:04:44 +02:00
// The args that must be passed to droidstubs to generate the API and stubs source
// for this scope, constructed dynamically by initApiScope().
2020-04-29 14:30:54 +02:00
//
// The API only includes the additional members that this scope adds over the scope
// that it extends.
2020-07-20 19:04:44 +02:00
//
// The stubs source must include the definitions of everything that is in this
// api scope and all the scopes that this one extends.
droidstubsArgs [ ] string
2020-04-29 14:30:54 +02:00
2020-05-02 12:19:36 +02:00
// Whether the api scope can be treated as unstable, and should skip compat checks.
unstable bool
2023-03-23 18:44:51 +01:00
// Represents the SDK kind of this scope.
kind android . SdkKind
2020-01-22 12:57:20 +01:00
}
// Initialize a scope, creating and adding appropriate dependency tags
func initApiScope ( scope * apiScope ) * apiScope {
2020-04-29 21:45:27 +02:00
name := scope . name
2020-05-14 16:39:10 +02:00
scopeByName [ name ] = scope
allScopeNames = append ( allScopeNames , name )
2020-05-13 20:19:49 +02:00
scope . propertyName = strings . ReplaceAll ( name , "-" , "_" )
scope . fieldName = proptools . FieldNameForProperty ( scope . propertyName )
2024-01-22 20:40:08 +01:00
scope . prebuiltStubsTag = scopeDependencyTag {
2020-04-29 21:45:27 +02:00
name : name + "-stubs" ,
apiScope : scope ,
depInfoExtractor : ( * scopePaths ) . extractStubsLibraryInfoFromDependency ,
2020-01-22 12:57:20 +01:00
}
2023-12-26 20:08:01 +01:00
scope . everythingStubsTag = scopeDependencyTag {
name : name + "-stubs-everything" ,
apiScope : scope ,
depInfoExtractor : ( * scopePaths ) . extractEverythingStubsLibraryInfoFromDependency ,
}
scope . exportableStubsTag = scopeDependencyTag {
name : name + "-stubs-exportable" ,
apiScope : scope ,
depInfoExtractor : ( * scopePaths ) . extractExportableStubsLibraryInfoFromDependency ,
}
2020-04-29 14:30:54 +02:00
scope . stubsSourceTag = scopeDependencyTag {
name : name + "-stubs-source" ,
apiScope : scope ,
depInfoExtractor : ( * scopePaths ) . extractStubsSourceInfoFromDep ,
}
scope . apiFileTag = scopeDependencyTag {
name : name + "-api" ,
apiScope : scope ,
depInfoExtractor : ( * scopePaths ) . extractApiInfoFromDep ,
}
2020-04-29 21:45:27 +02:00
scope . stubsSourceAndApiTag = scopeDependencyTag {
name : name + "-stubs-source-and-api" ,
apiScope : scope ,
depInfoExtractor : ( * scopePaths ) . extractStubsSourceAndApiInfoFromApiStubsProvider ,
2020-01-22 12:57:20 +01:00
}
2022-05-16 15:10:47 +02:00
scope . latestApiModuleTag = scopeDependencyTag {
name : name + "-latest-api" ,
apiScope : scope ,
depInfoExtractor : ( * scopePaths ) . extractLatestApiPath ,
}
scope . latestRemovedApiModuleTag = scopeDependencyTag {
name : name + "-latest-removed-api" ,
apiScope : scope ,
depInfoExtractor : ( * scopePaths ) . extractLatestRemovedApiPath ,
}
2020-04-29 14:30:54 +02:00
// To get the args needed to generate the stubs source append all the args from
// this scope and all the scopes it extends as each set of args adds additional
// members to the stubs.
2020-07-20 19:04:44 +02:00
var scopeSpecificArgs [ ] string
if scope . annotation != "" {
scopeSpecificArgs = [ ] string { "--show-annotation" , scope . annotation }
2020-04-29 14:30:54 +02:00
}
2020-07-20 19:04:44 +02:00
for s := scope ; s != nil ; s = s . extends {
scopeSpecificArgs = append ( scopeSpecificArgs , s . extraArgs ... )
2020-04-29 14:30:54 +02:00
2020-07-20 19:04:44 +02:00
// Ensure that the generated stubs includes all the API elements from the API scope
// that this scope extends.
if s != scope && s . annotation != "" {
scopeSpecificArgs = append ( scopeSpecificArgs , "--show-for-stub-purposes-annotation" , s . annotation )
}
}
2020-04-29 14:30:54 +02:00
Allow sdk_version: "system_server_current" modules to access module-lib APIs
Previously, a java module with sdk_version: "system_server_current",
would only be able to access the system server or public API of a
java_sdk_library. This change allows it to access the system server,
module lib, system and public APIs in that order.
The apiScope structs define the characteristics of each of the
different API scopes used as required by the java_sdk_library. They are
organized into a hierarchy which is used for two different purposes.
The first purpose is to define an extension hierachy. If scope X
extends Y then X provides a superset of all API elements (classes,
fields, methods, etc) provided by Y. That is reflected in the fact that
the .txt file for X would be a delta on the .txt file for Y. So, system
extends public and so system_current.txt only contains additional API
elements to add to current.txt.
The second purpose is when a java_sdk_library/import is asked to
provide a specific API scope. e.g. a library that has:
sdk_version: "module_current"
will ask each of the SDK libraries it depends upon for a module-lib
API. However, not all of them will provide an API for that scope. In
that case it will find the closest suitable API scope.
Previously, it did that by traversing up the API extension until it
found an API scope that it did provide and return that. As
system_server_current extended the public API that meant that a library
which has:
sdk_version: "system_server_current"
would provide a system server API if available, and if not fall
straight back to public. That meant that the library could not access
system or module-lib APIs even though it is running in the system
server which should be able to access all APIs.
One way to fix this would have been to just have system server API
scope extend module-lib but that would have had a number of nasty
side effects:
* It would have created a significant overhead as every module that
provides a system server API would also have to provide a module-lib
and system API, along with their corresponding .txt files.
* Each existing java_sdk_library that provided a system server API
would need those .txt files created.
* Generating sdk snapshots for older releases would have been more
complicated.
* It would have confused developers.
All of that would be unnecessary because the system server API scope is
intended to be provided by libraries that are used solely by the system
server so there is no point in them providing anything other than a
system server API.
So, instead a separate access hierarchy was added which is the same as
the extension hierarchy for all existing scopes except for the
system server scope, which instead of just being able to access the
public API will be able to access the module-lib scope, which can in
turn access system and it can in turn access public.
That achieves what we want which is a library that is loaded into the
system server to be able to access all API scopes.
Bug: 204176972
Test: m nothing
Change-Id: I854df63fcaeba32afbc1eb0d1a501238022673d0
2022-09-30 19:11:41 +02:00
// By default, a library that can access a scope can also access the scope it extends.
if scope . canAccess == nil {
scope . canAccess = scope . extends
}
2020-07-20 19:04:44 +02:00
// Escape any special characters in the arguments. This is needed because droidstubs
// passes these directly to the shell command.
scope . droidstubsArgs = proptools . ShellEscapeList ( scopeSpecificArgs )
2020-04-29 14:30:54 +02:00
2020-01-22 12:57:20 +01:00
return scope
}
2021-04-07 16:32:19 +02:00
func ( scope * apiScope ) stubsLibraryModuleNameSuffix ( ) string {
return ".stubs" + scope . moduleSuffix
}
2023-12-20 03:53:38 +01:00
func ( scope * apiScope ) exportableStubsLibraryModuleNameSuffix ( ) string {
return ".stubs.exportable" + scope . moduleSuffix
}
2023-03-23 18:44:51 +01:00
func ( scope * apiScope ) apiLibraryModuleName ( baseName string ) string {
return scope . stubsLibraryModuleName ( baseName ) + ".from-text"
}
2023-06-09 01:25:57 +02:00
func ( scope * apiScope ) sourceStubLibraryModuleName ( baseName string ) string {
return scope . stubsLibraryModuleName ( baseName ) + ".from-source"
}
2023-12-20 03:53:38 +01:00
func ( scope * apiScope ) exportableSourceStubsLibraryModuleName ( baseName string ) string {
return scope . exportableStubsLibraryModuleName ( baseName ) + ".from-source"
}
2020-05-08 15:16:20 +02:00
func ( scope * apiScope ) stubsLibraryModuleName ( baseName string ) string {
2021-04-07 16:32:19 +02:00
return baseName + scope . stubsLibraryModuleNameSuffix ( )
2020-01-22 12:57:20 +01:00
}
2023-12-20 03:53:38 +01:00
func ( scope * apiScope ) exportableStubsLibraryModuleName ( baseName string ) string {
return baseName + scope . exportableStubsLibraryModuleNameSuffix ( )
}
2020-04-29 21:45:27 +02:00
func ( scope * apiScope ) stubsSourceModuleName ( baseName string ) string {
2020-05-08 16:52:37 +02:00
return baseName + ".stubs.source" + scope . moduleSuffix
2020-01-22 12:57:20 +01:00
}
2020-04-29 14:30:54 +02:00
func ( scope * apiScope ) apiModuleName ( baseName string ) string {
2020-05-08 16:52:37 +02:00
return baseName + ".api" + scope . moduleSuffix
2020-04-29 14:30:54 +02:00
}
2020-04-28 11:44:03 +02:00
func ( scope * apiScope ) String ( ) string {
return scope . name
}
2022-05-16 15:10:47 +02:00
// snapshotRelativeDir returns the snapshot directory into which the files related to scopes will
// be stored.
func ( scope * apiScope ) snapshotRelativeDir ( ) string {
return filepath . Join ( "sdk_library" , scope . name )
}
// snapshotRelativeCurrentApiTxtPath returns the snapshot path to the API .txt file for the named
// library.
func ( scope * apiScope ) snapshotRelativeCurrentApiTxtPath ( name string ) string {
return filepath . Join ( scope . snapshotRelativeDir ( ) , name + ".txt" )
}
// snapshotRelativeRemovedApiTxtPath returns the snapshot path to the removed API .txt file for the
// named library.
func ( scope * apiScope ) snapshotRelativeRemovedApiTxtPath ( name string ) string {
return filepath . Join ( scope . snapshotRelativeDir ( ) , name + "-removed.txt" )
}
2020-01-22 12:57:20 +01:00
type apiScopes [ ] * apiScope
func ( scopes apiScopes ) Strings ( accessor func ( * apiScope ) string ) [ ] string {
var list [ ] string
for _ , scope := range scopes {
list = append ( list , accessor ( scope ) )
}
return list
}
2023-09-21 01:43:32 +02:00
// Method that maps the apiScopes properties to the index of each apiScopes elements.
// apiScopes property to be used as the key can be specified with the input accessor.
// Only a string property of apiScope can be used as the key of the map.
func ( scopes apiScopes ) MapToIndex ( accessor func ( * apiScope ) string ) map [ string ] int {
ret := make ( map [ string ] int )
for i , scope := range scopes {
ret [ accessor ( scope ) ] = i
}
return ret
}
2020-01-22 12:57:20 +01:00
var (
2020-05-14 16:39:10 +02:00
scopeByName = make ( map [ string ] * apiScope )
allScopeNames [ ] string
2020-01-22 12:57:20 +01:00
apiScopePublic = initApiScope ( & apiScope {
2020-04-28 11:44:03 +02:00
name : "public" ,
// Public scope is enabled by default for both legacy and non-legacy modes.
legacyEnabledStatus : func ( module * SdkLibrary ) bool {
return true
} ,
defaultEnabledStatus : true ,
scopeSpecificProperties : func ( module * SdkLibrary ) * ApiScopeProperties {
return & module . sdkLibraryProperties . Public
} ,
2020-01-22 12:57:20 +01:00
sdkVersion : "current" ,
2023-03-23 18:44:51 +01:00
kind : android . SdkPublic ,
2020-01-22 12:57:20 +01:00
} )
apiScopeSystem = initApiScope ( & apiScope {
2020-04-28 11:44:03 +02:00
name : "system" ,
extends : apiScopePublic ,
legacyEnabledStatus : ( * SdkLibrary ) . generateTestAndSystemScopesByDefault ,
scopeSpecificProperties : func ( module * SdkLibrary ) * ApiScopeProperties {
return & module . sdkLibraryProperties . System
} ,
2020-07-20 19:04:44 +02:00
apiFilePrefix : "system-" ,
moduleSuffix : ".system" ,
sdkVersion : "system_current" ,
annotation : "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.PRIVILEGED_APPS)" ,
2023-03-23 18:44:51 +01:00
kind : android . SdkSystem ,
2020-01-22 12:57:20 +01:00
} )
apiScopeTest = initApiScope ( & apiScope {
2020-04-28 11:44:03 +02:00
name : "test" ,
2020-10-09 11:16:49 +02:00
extends : apiScopeSystem ,
2020-04-28 11:44:03 +02:00
legacyEnabledStatus : ( * SdkLibrary ) . generateTestAndSystemScopesByDefault ,
scopeSpecificProperties : func ( module * SdkLibrary ) * ApiScopeProperties {
return & module . sdkLibraryProperties . Test
} ,
2020-07-20 19:04:44 +02:00
apiFilePrefix : "test-" ,
moduleSuffix : ".test" ,
sdkVersion : "test_current" ,
annotation : "android.annotation.TestApi" ,
unstable : true ,
2023-03-23 18:44:51 +01:00
kind : android . SdkTest ,
2020-01-22 12:57:20 +01:00
} )
2020-04-28 15:13:56 +02:00
apiScopeModuleLib = initApiScope ( & apiScope {
2020-05-13 20:19:49 +02:00
name : "module-lib" ,
2020-04-28 15:13:56 +02:00
extends : apiScopeSystem ,
2020-06-02 14:00:08 +02:00
// The module-lib scope is disabled by default in legacy mode.
2020-04-28 15:13:56 +02:00
//
// Enabling this would break existing usages.
legacyEnabledStatus : func ( module * SdkLibrary ) bool {
return false
} ,
scopeSpecificProperties : func ( module * SdkLibrary ) * ApiScopeProperties {
return & module . sdkLibraryProperties . Module_lib
} ,
apiFilePrefix : "module-lib-" ,
moduleSuffix : ".module_lib" ,
sdkVersion : "module_current" ,
2020-07-20 19:04:44 +02:00
annotation : "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES)" ,
2023-03-23 18:44:51 +01:00
kind : android . SdkModule ,
2020-04-28 15:13:56 +02:00
} )
2020-06-02 14:00:08 +02:00
apiScopeSystemServer = initApiScope ( & apiScope {
name : "system-server" ,
extends : apiScopePublic ,
Allow sdk_version: "system_server_current" modules to access module-lib APIs
Previously, a java module with sdk_version: "system_server_current",
would only be able to access the system server or public API of a
java_sdk_library. This change allows it to access the system server,
module lib, system and public APIs in that order.
The apiScope structs define the characteristics of each of the
different API scopes used as required by the java_sdk_library. They are
organized into a hierarchy which is used for two different purposes.
The first purpose is to define an extension hierachy. If scope X
extends Y then X provides a superset of all API elements (classes,
fields, methods, etc) provided by Y. That is reflected in the fact that
the .txt file for X would be a delta on the .txt file for Y. So, system
extends public and so system_current.txt only contains additional API
elements to add to current.txt.
The second purpose is when a java_sdk_library/import is asked to
provide a specific API scope. e.g. a library that has:
sdk_version: "module_current"
will ask each of the SDK libraries it depends upon for a module-lib
API. However, not all of them will provide an API for that scope. In
that case it will find the closest suitable API scope.
Previously, it did that by traversing up the API extension until it
found an API scope that it did provide and return that. As
system_server_current extended the public API that meant that a library
which has:
sdk_version: "system_server_current"
would provide a system server API if available, and if not fall
straight back to public. That meant that the library could not access
system or module-lib APIs even though it is running in the system
server which should be able to access all APIs.
One way to fix this would have been to just have system server API
scope extend module-lib but that would have had a number of nasty
side effects:
* It would have created a significant overhead as every module that
provides a system server API would also have to provide a module-lib
and system API, along with their corresponding .txt files.
* Each existing java_sdk_library that provided a system server API
would need those .txt files created.
* Generating sdk snapshots for older releases would have been more
complicated.
* It would have confused developers.
All of that would be unnecessary because the system server API scope is
intended to be provided by libraries that are used solely by the system
server so there is no point in them providing anything other than a
system server API.
So, instead a separate access hierarchy was added which is the same as
the extension hierarchy for all existing scopes except for the
system server scope, which instead of just being able to access the
public API will be able to access the module-lib scope, which can in
turn access system and it can in turn access public.
That achieves what we want which is a library that is loaded into the
system server to be able to access all API scopes.
Bug: 204176972
Test: m nothing
Change-Id: I854df63fcaeba32afbc1eb0d1a501238022673d0
2022-09-30 19:11:41 +02:00
// The system-server scope can access the module-lib scope.
//
// A module that provides a system-server API is appended to the standard bootclasspath that is
// used by the system server. So, it should be able to access module-lib APIs provided by
// libraries on the bootclasspath.
canAccess : apiScopeModuleLib ,
2020-06-02 14:00:08 +02:00
// The system-server scope is disabled by default in legacy mode.
//
// Enabling this would break existing usages.
legacyEnabledStatus : func ( module * SdkLibrary ) bool {
return false
} ,
scopeSpecificProperties : func ( module * SdkLibrary ) * ApiScopeProperties {
return & module . sdkLibraryProperties . System_server
} ,
apiFilePrefix : "system-server-" ,
moduleSuffix : ".system_server" ,
sdkVersion : "system_server_current" ,
2020-07-20 19:04:44 +02:00
annotation : "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.SYSTEM_SERVER)" ,
extraArgs : [ ] string {
"--hide-annotation" , "android.annotation.Hide" ,
2020-06-02 14:00:08 +02:00
// com.android.* classes are okay in this interface"
2020-07-20 19:04:44 +02:00
"--hide" , "InternalClasses" ,
2020-06-02 14:00:08 +02:00
} ,
2023-03-23 18:44:51 +01:00
kind : android . SdkSystemServer ,
2020-06-02 14:00:08 +02:00
} )
2020-01-22 12:57:20 +01:00
allApiScopes = apiScopes {
apiScopePublic ,
apiScopeSystem ,
apiScopeTest ,
2020-04-28 15:13:56 +02:00
apiScopeModuleLib ,
2020-06-02 14:00:08 +02:00
apiScopeSystemServer ,
2020-01-22 12:57:20 +01:00
}
2023-08-02 08:44:57 +02:00
apiLibraryAdditionalProperties = map [ string ] struct {
FullApiSurfaceStubLib string
AdditionalApiContribution string
} {
"legacy.i18n.module.platform.api" : {
FullApiSurfaceStubLib : "legacy.core.platform.api.stubs" ,
AdditionalApiContribution : "i18n.module.public.api.stubs.source.api.contribution" ,
} ,
"stable.i18n.module.platform.api" : {
FullApiSurfaceStubLib : "stable.core.platform.api.stubs" ,
AdditionalApiContribution : "i18n.module.public.api.stubs.source.api.contribution" ,
} ,
"conscrypt.module.platform.api" : {
FullApiSurfaceStubLib : "stable.core.platform.api.stubs" ,
AdditionalApiContribution : "conscrypt.module.public.api.stubs.source.api.contribution" ,
} ,
}
2018-04-10 06:07:10 +02:00
)
2018-04-23 14:41:26 +02:00
var (
javaSdkLibrariesLock sync . Mutex
)
2018-04-10 06:07:10 +02:00
// TODO: these are big features that are currently missing
2018-05-28 11:02:19 +02:00
// 1) disallowing linking to the runtime shared lib
// 2) HTML generation
2018-04-10 06:07:10 +02:00
func init ( ) {
2019-12-19 12:18:54 +01:00
RegisterSdkLibraryBuildComponents ( android . InitRegistrationContext )
2018-04-10 06:07:10 +02:00
2018-04-23 14:41:26 +02:00
android . RegisterMakeVarsProvider ( pctx , func ( ctx android . MakeVarsContext ) {
javaSdkLibraries := javaSdkLibraries ( ctx . Config ( ) )
sort . Strings ( * javaSdkLibraries )
ctx . Strict ( "JAVA_SDK_LIBRARIES" , strings . Join ( * javaSdkLibraries , " " ) )
} )
2020-02-10 14:37:10 +01:00
// Register sdk member types.
2021-04-28 00:20:26 +02:00
android . RegisterSdkMemberType ( javaSdkLibrarySdkMemberType )
2018-04-10 06:07:10 +02:00
}
2019-12-19 12:18:54 +01:00
func RegisterSdkLibraryBuildComponents ( ctx android . RegistrationContext ) {
ctx . RegisterModuleType ( "java_sdk_library" , SdkLibraryFactory )
ctx . RegisterModuleType ( "java_sdk_library_import" , sdkLibraryImportFactory )
}
2020-04-28 11:44:03 +02:00
// Properties associated with each api scope.
type ApiScopeProperties struct {
// Indicates whether the api surface is generated.
//
// If this is set for any scope then all scopes must explicitly specify if they
// are enabled. This is to prevent new usages from depending on legacy behavior.
//
// Otherwise, if this is not set for any scope then the default behavior is
// scope specific so please refer to the scope specific property documentation.
Enabled * bool
2020-05-12 12:50:28 +02:00
// The sdk_version to use for building the stubs.
//
// If not specified then it will use an sdk_version determined as follows:
2021-11-04 15:25:39 +01:00
//
2020-05-12 12:50:28 +02:00
// 1) If the sdk_version specified on the java_sdk_library is none then this
2021-11-04 15:25:39 +01:00
// will be none. This is used for java_sdk_library instances that are used
// to create stubs that contribute to the core_current sdk version.
// 2) Otherwise, it is assumed that this library extends but does not
// contribute directly to a specific sdk_version and so this uses the
// sdk_version appropriate for the api scope. e.g. public will use
// sdk_version: current, system will use sdk_version: system_current, etc.
2020-05-12 12:50:28 +02:00
//
// This does not affect the sdk_version used for either generating the stubs source
// or the API file. They both have to use the same sdk_version as is used for
// compiling the implementation library.
Sdk_version * string
2023-08-10 02:07:03 +02:00
// Extra libs used when compiling stubs for this scope.
Libs [ ] string
2020-04-28 11:44:03 +02:00
}
2018-04-10 06:07:10 +02:00
type sdkLibraryProperties struct {
2021-09-16 15:24:13 +02:00
// List of source files that are needed to compile the API, but are not part of runtime library.
Api_srcs [ ] string ` android:"arch_variant" `
2020-05-16 16:52:12 +02:00
// Visibility for impl library module. If not specified then defaults to the
// visibility property.
Impl_library_visibility [ ] string
2020-04-30 00:35:13 +02:00
// Visibility for stubs library modules. If not specified then defaults to the
// visibility property.
Stubs_library_visibility [ ] string
// Visibility for stubs source modules. If not specified then defaults to the
// visibility property.
Stubs_source_visibility [ ] string
2020-10-08 15:47:23 +02:00
// List of Java libraries that will be in the classpath when building the implementation lib
Impl_only_libs [ ] string ` android:"arch_variant" `
2022-04-28 16:13:30 +02:00
// List of Java libraries that will included in the implementation lib.
Impl_only_static_libs [ ] string ` android:"arch_variant" `
2018-06-25 09:04:37 +02:00
// List of Java libraries that will be in the classpath when building stubs
Stub_only_libs [ ] string ` android:"arch_variant" `
2021-04-21 17:30:10 +02:00
// List of Java libraries that will included in stub libraries
Stub_only_static_libs [ ] string ` android:"arch_variant" `
2019-12-30 18:09:34 +01:00
// list of package names that will be documented and publicized as API.
// This allows the API to be restricted to a subset of the source files provided.
// If this is unspecified then all the source files will be treated as being part
// of the API.
2018-04-10 06:07:10 +02:00
Api_packages [ ] string
2018-05-01 15:25:41 +02:00
// list of package names that must be hidden from the API
Hidden_api_packages [ ] string
2019-12-30 18:23:46 +01:00
// the relative path to the directory containing the api specification files.
// Defaults to "api".
Api_dir * string
2020-05-15 21:37:11 +02:00
// Determines whether a runtime implementation library is built; defaults to false.
//
// If true then it also prevents the module from being used as a shared module, i.e.
2022-05-25 16:27:11 +02:00
// it is as if shared_library: false, was set.
2019-12-30 18:35:49 +01:00
Api_only * bool
2019-02-11 16:55:17 +01:00
// local files that are used within user customized droiddoc options.
Droiddoc_option_files [ ] string
2021-07-29 20:26:39 +02:00
// additional droiddoc options.
2019-02-11 16:55:17 +01:00
// Available variables for substitution:
//
// $(location <label>): the path to the droiddoc_option_files with name <label>
2018-07-31 10:19:11 +02:00
Droiddoc_options [ ] string
2020-05-20 20:35:27 +02:00
// is set to true, Metalava will allow framework SDK to contain annotations.
Annotations_enabled * bool
2018-10-19 06:46:09 +02:00
// a list of top-level directories containing files to merge qualifier annotations
// (i.e. those intended to be included in the stubs written) from.
Merge_annotations_dirs [ ] string
// a list of top-level directories containing Java stub files to merge show/hide annotations from.
Merge_inclusion_annotations_dirs [ ] string
2020-11-19 15:53:43 +01:00
// If set to true then don't create dist rules.
No_dist * bool
2019-05-13 08:02:50 +02:00
2020-11-20 22:26:20 +01:00
// The stem for the artifacts that are copied to the dist, if not specified
// then defaults to the base module name.
//
// For each scope the following artifacts are copied to the apistubs/<scope>
// directory in the dist.
// * stubs impl jar -> <dist-stem>.jar
// * API specification file -> api/<dist-stem>.txt
// * Removed API specification file -> api/<dist-stem>-removed.txt
//
// Also used to construct the name of the filegroup (created by prebuilt_apis)
// that references the latest released API and remove API specification files.
// * API specification filegroup -> <dist-stem>.api.<scope>.latest
// * Removed API specification filegroup -> <dist-stem>-removed.api.<scope>.latest
2021-03-09 22:25:02 +01:00
// * API incompatibilities baseline filegroup -> <dist-stem>-incompatibilities.api.<scope>.latest
2020-11-20 22:26:20 +01:00
Dist_stem * string
2021-06-01 22:13:40 +02:00
// The subdirectory for the artifacts that are copied to the dist directory. If not specified
2021-06-01 23:05:09 +02:00
// then defaults to "unknown". Should be set to "android" for anything that should be published
2021-06-01 22:13:40 +02:00
// in the public Android SDK.
Dist_group * string
2020-12-21 18:10:01 +01:00
// A compatibility mode that allows historical API-tracking files to not exist.
// Do not use.
Unsafe_ignore_missing_latest_api bool
2020-04-28 11:44:03 +02:00
// indicates whether system and test apis should be generated.
Generate_system_and_test_apis bool ` blueprint:"mutated" `
// The properties specific to the public api scope
//
// Unless explicitly specified by using public.enabled the public api scope is
// enabled by default in both legacy and non-legacy mode.
Public ApiScopeProperties
// The properties specific to the system api scope
//
// In legacy mode the system api scope is enabled by default when sdk_version
// is set to something other than "none".
//
// In non-legacy mode the system api scope is disabled by default.
System ApiScopeProperties
// The properties specific to the test api scope
//
// In legacy mode the test api scope is enabled by default when sdk_version
// is set to something other than "none".
//
// In non-legacy mode the test api scope is disabled by default.
Test ApiScopeProperties
2019-12-30 18:20:10 +01:00
2020-06-02 14:00:08 +02:00
// The properties specific to the module-lib api scope
2020-04-28 15:13:56 +02:00
//
2023-02-01 00:53:30 +01:00
// Unless explicitly specified by using module_lib.enabled the module_lib api
// scope is disabled by default.
2020-04-28 15:13:56 +02:00
Module_lib ApiScopeProperties
2020-06-02 14:00:08 +02:00
// The properties specific to the system-server api scope
//
2023-02-01 00:53:30 +01:00
// Unless explicitly specified by using system_server.enabled the
// system_server api scope is disabled by default.
2020-06-02 14:00:08 +02:00
System_server ApiScopeProperties
2020-05-27 17:19:53 +02:00
// Determines if the stubs are preferred over the implementation library
// for linking, even when the client doesn't specify sdk_version. When this
// is set to true, such clients are provided with the widest API surface that
// this lib provides. Note however that this option doesn't affect the clients
// that are in the same APEX as this library. In that case, the clients are
// always linked with the implementation library. Default is false.
Default_to_stubs * bool
2020-05-10 20:32:20 +02:00
// Properties related to api linting.
Api_lint struct {
// Enable api linting.
Enabled * bool
2023-11-02 16:18:09 +01:00
// If API lint is enabled, this flag controls whether a set of legitimate lint errors
// are turned off. The default is true.
Legacy_errors_allowed * bool
2020-05-10 20:32:20 +02:00
}
2023-11-15 20:22:14 +01:00
// Determines if the module contributes to any api surfaces.
// This property should be set to true only if the module is listed under
// frameworks-base-api.bootclasspath in frameworks/base/api/Android.bp.
// Otherwise, this property should be set to false.
// Defaults to false.
Contribute_to_android_api * bool
2023-12-19 02:13:16 +01:00
// a list of aconfig_declarations module names that the stubs generated in this module
// depend on.
Aconfig_declarations [ ] string
2018-04-10 06:07:10 +02:00
// TODO: determines whether to create HTML doc or not
2022-09-22 17:24:46 +02:00
// Html_doc *bool
2018-04-10 06:07:10 +02:00
}
2020-05-20 17:18:00 +02:00
// Paths to outputs from java_sdk_library and java_sdk_library_import.
//
// Fields that are android.Paths are always set (during GenerateAndroidBuildActions).
// OptionalPaths are always set by java_sdk_library but may not be set by
// java_sdk_library_import as not all instances provide that information.
2020-01-22 12:57:20 +01:00
type scopePaths struct {
2020-05-20 17:18:00 +02:00
// The path (represented as Paths for convenience when returning) to the stubs header jar.
//
// That is the jar that is created by turbine.
stubsHeaderPath android . Paths
// The path (represented as Paths for convenience when returning) to the stubs implementation jar.
//
// This is not the implementation jar, it still only contains stubs.
stubsImplPath android . Paths
2021-04-16 18:21:36 +02:00
// The dex jar for the stubs.
//
// This is not the implementation jar, it still only contains stubs.
2021-09-15 04:34:04 +02:00
stubsDexJarPath OptionalDexJarPath
2021-04-16 18:21:36 +02:00
2023-12-26 20:08:01 +01:00
// The exportable dex jar for the stubs.
// This is not the implementation jar, it still only contains stubs.
// Includes unflagged apis and flagged apis enabled by release configurations.
exportableStubsDexJarPath OptionalDexJarPath
2020-05-20 17:18:00 +02:00
// The API specification file, e.g. system_current.txt.
currentApiFilePath android . OptionalPath
// The specification of API elements removed since the last release.
removedApiFilePath android . OptionalPath
// The stubs source jar.
stubsSrcJar android . OptionalPath
2021-09-21 16:25:12 +02:00
// Extracted annotations.
annotationsZip android . OptionalPath
2022-05-16 15:10:47 +02:00
// The path to the latest API file.
latestApiPath android . OptionalPath
// The path to the latest removed API file.
latestRemovedApiPath android . OptionalPath
2020-01-22 12:57:20 +01:00
}
2021-02-01 22:59:03 +01:00
func ( paths * scopePaths ) extractStubsLibraryInfoFromDependency ( ctx android . ModuleContext , dep android . Module ) error {
2023-12-13 22:47:44 +01:00
if lib , ok := android . OtherModuleProvider ( ctx , dep , JavaInfoProvider ) ; ok {
2021-02-01 22:59:03 +01:00
paths . stubsHeaderPath = lib . HeaderJars
paths . stubsImplPath = lib . ImplementationJars
2021-04-16 18:21:36 +02:00
libDep := dep . ( UsesLibraryDependency )
2024-01-09 22:35:56 +01:00
paths . stubsDexJarPath = libDep . DexJarBuildPath ( ctx )
2023-12-26 20:08:01 +01:00
paths . exportableStubsDexJarPath = libDep . DexJarBuildPath ( ctx )
return nil
} else {
return fmt . Errorf ( "expected module that has JavaInfoProvider, e.g. java_library" )
}
}
func ( paths * scopePaths ) extractEverythingStubsLibraryInfoFromDependency ( ctx android . ModuleContext , dep android . Module ) error {
if lib , ok := android . OtherModuleProvider ( ctx , dep , JavaInfoProvider ) ; ok {
paths . stubsHeaderPath = lib . HeaderJars
2024-01-08 09:56:20 +01:00
if ! ctx . Config ( ) . ReleaseHiddenApiExportableStubs ( ) {
paths . stubsImplPath = lib . ImplementationJars
}
2023-12-26 20:08:01 +01:00
libDep := dep . ( UsesLibraryDependency )
paths . stubsDexJarPath = libDep . DexJarBuildPath ( ctx )
return nil
} else {
return fmt . Errorf ( "expected module that has JavaInfoProvider, e.g. java_library" )
}
}
func ( paths * scopePaths ) extractExportableStubsLibraryInfoFromDependency ( ctx android . ModuleContext , dep android . Module ) error {
2024-01-08 09:56:20 +01:00
if lib , ok := android . OtherModuleProvider ( ctx , dep , JavaInfoProvider ) ; ok {
if ctx . Config ( ) . ReleaseHiddenApiExportableStubs ( ) {
paths . stubsImplPath = lib . ImplementationJars
}
2023-12-26 20:08:01 +01:00
libDep := dep . ( UsesLibraryDependency )
paths . exportableStubsDexJarPath = libDep . DexJarBuildPath ( ctx )
2020-04-29 21:45:27 +02:00
return nil
} else {
2021-02-01 22:59:03 +01:00
return fmt . Errorf ( "expected module that has JavaInfoProvider, e.g. java_library" )
2020-04-29 21:45:27 +02:00
}
}
2024-01-23 01:16:41 +01:00
func ( paths * scopePaths ) treatDepAsApiStubsProvider ( dep android . Module , action func ( provider ApiStubsProvider ) error ) error {
2020-04-29 14:30:54 +02:00
if apiStubsProvider , ok := dep . ( ApiStubsProvider ) ; ok {
2024-01-23 01:16:41 +01:00
err := action ( apiStubsProvider )
if err != nil {
return err
}
2024-01-08 09:56:20 +01:00
return nil
} else {
return fmt . Errorf ( "expected module that implements ExportableApiStubsSrcProvider, e.g. droidstubs" )
}
}
2024-01-23 01:16:41 +01:00
func ( paths * scopePaths ) treatDepAsApiStubsSrcProvider ( dep android . Module , action func ( provider ApiStubsSrcProvider ) error ) error {
2020-05-20 17:18:00 +02:00
if apiStubsProvider , ok := dep . ( ApiStubsSrcProvider ) ; ok {
2024-01-23 01:16:41 +01:00
err := action ( apiStubsProvider )
if err != nil {
return err
}
2020-05-20 17:18:00 +02:00
return nil
} else {
return fmt . Errorf ( "expected module that implements ApiStubsSrcProvider, e.g. droidstubs" )
}
}
2024-01-23 01:16:41 +01:00
func ( paths * scopePaths ) extractApiInfoFromApiStubsProvider ( provider ApiStubsProvider , stubsType StubsType ) error {
var annotationsZip , currentApiFilePath , removedApiFilePath android . Path
annotationsZip , annotationsZipErr := provider . AnnotationsZip ( stubsType )
currentApiFilePath , currentApiFilePathErr := provider . ApiFilePath ( stubsType )
removedApiFilePath , removedApiFilePathErr := provider . RemovedApiFilePath ( stubsType )
combinedError := errors . Join ( annotationsZipErr , currentApiFilePathErr , removedApiFilePathErr )
2020-04-29 14:30:54 +02:00
2024-01-23 01:16:41 +01:00
if combinedError == nil {
paths . annotationsZip = android . OptionalPathForPath ( annotationsZip )
paths . currentApiFilePath = android . OptionalPathForPath ( currentApiFilePath )
paths . removedApiFilePath = android . OptionalPathForPath ( removedApiFilePath )
}
return combinedError
2024-01-08 09:56:20 +01:00
}
2021-02-01 22:59:03 +01:00
func ( paths * scopePaths ) extractApiInfoFromDep ( ctx android . ModuleContext , dep android . Module ) error {
2024-01-23 01:16:41 +01:00
return paths . treatDepAsApiStubsProvider ( dep , func ( provider ApiStubsProvider ) error {
return paths . extractApiInfoFromApiStubsProvider ( provider , Everything )
2020-04-29 14:30:54 +02:00
} )
}
2024-01-23 01:16:41 +01:00
func ( paths * scopePaths ) extractStubsSourceInfoFromApiStubsProviders ( provider ApiStubsSrcProvider , stubsType StubsType ) error {
stubsSrcJar , err := provider . StubsSrcJar ( stubsType )
if err == nil {
paths . stubsSrcJar = android . OptionalPathForPath ( stubsSrcJar )
}
return err
2024-01-08 09:56:20 +01:00
}
2021-02-01 22:59:03 +01:00
func ( paths * scopePaths ) extractStubsSourceInfoFromDep ( ctx android . ModuleContext , dep android . Module ) error {
2024-01-23 01:16:41 +01:00
return paths . treatDepAsApiStubsSrcProvider ( dep , func ( provider ApiStubsSrcProvider ) error {
return paths . extractStubsSourceInfoFromApiStubsProviders ( provider , Everything )
2020-04-29 14:30:54 +02:00
} )
}
2021-02-01 22:59:03 +01:00
func ( paths * scopePaths ) extractStubsSourceAndApiInfoFromApiStubsProvider ( ctx android . ModuleContext , dep android . Module ) error {
2024-01-08 09:56:20 +01:00
if ctx . Config ( ) . ReleaseHiddenApiExportableStubs ( ) {
2024-01-23 01:16:41 +01:00
return paths . treatDepAsApiStubsProvider ( dep , func ( provider ApiStubsProvider ) error {
extractApiInfoErr := paths . extractApiInfoFromApiStubsProvider ( provider , Exportable )
extractStubsSourceInfoErr := paths . extractStubsSourceInfoFromApiStubsProviders ( provider , Exportable )
return errors . Join ( extractApiInfoErr , extractStubsSourceInfoErr )
2024-01-08 09:56:20 +01:00
} )
}
2024-01-23 01:16:41 +01:00
return paths . treatDepAsApiStubsProvider ( dep , func ( provider ApiStubsProvider ) error {
extractApiInfoErr := paths . extractApiInfoFromApiStubsProvider ( provider , Everything )
extractStubsSourceInfoErr := paths . extractStubsSourceInfoFromApiStubsProviders ( provider , Everything )
return errors . Join ( extractApiInfoErr , extractStubsSourceInfoErr )
2020-04-29 14:30:54 +02:00
} )
}
2022-05-16 15:10:47 +02:00
func extractSingleOptionalOutputPath ( dep android . Module ) ( android . OptionalPath , error ) {
var paths android . Paths
if sourceFileProducer , ok := dep . ( android . SourceFileProducer ) ; ok {
paths = sourceFileProducer . Srcs ( )
} else {
return android . OptionalPath { } , fmt . Errorf ( "module %q does not produce source files" , dep )
}
if len ( paths ) != 1 {
return android . OptionalPath { } , fmt . Errorf ( "expected one path from %q, got %q" , dep , paths )
}
return android . OptionalPathForPath ( paths [ 0 ] ) , nil
}
func ( paths * scopePaths ) extractLatestApiPath ( ctx android . ModuleContext , dep android . Module ) error {
outputPath , err := extractSingleOptionalOutputPath ( dep )
paths . latestApiPath = outputPath
return err
}
func ( paths * scopePaths ) extractLatestRemovedApiPath ( ctx android . ModuleContext , dep android . Module ) error {
outputPath , err := extractSingleOptionalOutputPath ( dep )
paths . latestRemovedApiPath = outputPath
return err
}
2020-04-29 14:30:54 +02:00
type commonToSdkLibraryAndImportProperties struct {
2020-05-08 14:44:43 +02:00
// The naming scheme to use for the components that this module creates.
//
2020-09-11 14:04:05 +02:00
// If not specified then it defaults to "default".
2020-05-08 14:44:43 +02:00
//
// This is a temporary mechanism to simplify conversion from separate modules for each
// component that follow a different naming pattern to the default one.
//
// TODO(b/155480189) - Remove once naming inconsistencies have been resolved.
2020-04-29 14:30:54 +02:00
Naming_scheme * string
2020-05-15 21:37:11 +02:00
// Specifies whether this module can be used as an Android shared library; defaults
// to true.
//
// An Android shared library is one that can be referenced in a <uses-library> element
// in an AndroidManifest.xml.
Shared_library * bool
2020-09-11 12:55:00 +02:00
// Files containing information about supported java doc tags.
Doctag_files [ ] string ` android:"path" `
2021-09-07 19:21:59 +02:00
// Signals that this shared library is part of the bootclasspath starting
// on the version indicated in this attribute.
//
// This will make platforms at this level and above to ignore
// <uses-library> tags with this library name because the library is already
// available
On_bootclasspath_since * string
// Signals that this shared library was part of the bootclasspath before
// (but not including) the version indicated in this attribute.
//
// The system will automatically add a <uses-library> tag with this library to
// apps that target any SDK less than the version indicated in this attribute.
On_bootclasspath_before * string
// Indicates that PackageManager should ignore this shared library if the
// platform is below the version indicated in this attribute.
//
// This means that the device won't recognise this library as installed.
Min_device_sdk * string
// Indicates that PackageManager should ignore this shared library if the
// platform is above the version indicated in this attribute.
//
// This means that the device won't recognise this library as installed.
Max_device_sdk * string
2020-04-29 14:30:54 +02:00
}
2021-06-23 12:39:47 +02:00
// commonSdkLibraryAndImportModule defines the interface that must be provided by a module that
// embeds the commonToSdkLibraryAndImport struct.
type commonSdkLibraryAndImportModule interface {
2022-11-24 00:06:05 +01:00
android . Module
2021-06-23 12:39:47 +02:00
2024-01-19 01:22:22 +01:00
// Returns the name of the root java_sdk_library that creates the child stub libraries
// This is the `name` as it appears in Android.bp, and not the name in Soong's build graph
// (with the prebuilt_ prefix)
//
// e.g. in the following java_sdk_library_import
// java_sdk_library_import {
// name: "framework-foo.v1",
// source_module_name: "framework-foo",
// }
// the values returned by
// 1. Name(): prebuilt_framework-foo.v1 # unique
// 2. BaseModuleName(): framework-foo # the source
// 3. RootLibraryName: framework-foo.v1 # the undecordated `name` from Android.bp
RootLibraryName ( ) string
}
func ( m * SdkLibrary ) RootLibraryName ( ) string {
return m . BaseModuleName ( )
}
func ( m * SdkLibraryImport ) RootLibraryName ( ) string {
// m.BaseModuleName refers to the source of the import
// use moduleBase.Name to get the name of the module as it appears in the .bp file
return m . ModuleBase . Name ( )
2021-06-23 12:39:47 +02:00
}
2020-01-31 14:36:25 +01:00
// Common code between sdk library and sdk library import
type commonToSdkLibraryAndImport struct {
2021-06-23 12:39:47 +02:00
module commonSdkLibraryAndImportModule
2020-05-08 15:16:20 +02:00
2020-01-31 14:36:25 +01:00
scopePaths map [ * apiScope ] * scopePaths
2020-05-08 14:44:43 +02:00
namingScheme sdkLibraryComponentNamingScheme
2020-05-15 21:37:11 +02:00
commonSdkLibraryProperties commonToSdkLibraryAndImportProperties
2020-05-15 11:20:31 +02:00
2020-09-11 12:55:00 +02:00
// Paths to commonSdkLibraryProperties.Doctag_files
doctagPaths android . Paths
2020-05-15 11:20:31 +02:00
// Functionality related to this being used as a component of a java_sdk_library.
EmbeddableSdkLibraryComponent
2020-01-31 14:36:25 +01:00
}
2021-06-23 12:39:47 +02:00
func ( c * commonToSdkLibraryAndImport ) initCommon ( module commonSdkLibraryAndImportModule ) {
c . module = module
2020-05-08 14:44:43 +02:00
2021-06-23 12:39:47 +02:00
module . AddProperties ( & c . commonSdkLibraryProperties )
2020-05-15 11:20:31 +02:00
// Initialize this as an sdk library component.
2021-06-23 12:39:47 +02:00
c . initSdkLibraryComponent ( module )
2020-05-08 14:44:43 +02:00
}
func ( c * commonToSdkLibraryAndImport ) initCommonAfterDefaultsApplied ( ctx android . DefaultableHookContext ) bool {
2020-05-15 21:37:11 +02:00
schemeProperty := proptools . StringDefault ( c . commonSdkLibraryProperties . Naming_scheme , "default" )
2020-05-08 14:44:43 +02:00
switch schemeProperty {
case "default" :
c . namingScheme = & defaultNamingScheme { }
default :
ctx . PropertyErrorf ( "naming_scheme" , "expected 'default' but was %q" , schemeProperty )
return false
}
2024-01-19 01:22:22 +01:00
namePtr := proptools . StringPtr ( c . module . RootLibraryName ( ) )
2021-06-30 19:25:36 +02:00
c . sdkLibraryComponentProperties . SdkLibraryName = namePtr
2020-05-15 21:37:11 +02:00
// Only track this sdk library if this can be used as a shared library.
if c . sharedLibrary ( ) {
// Use the name specified in the module definition as the owner.
2021-06-30 19:25:36 +02:00
c . sdkLibraryComponentProperties . SdkLibraryToImplicitlyTrack = namePtr
2020-05-15 21:37:11 +02:00
}
2020-05-15 11:20:31 +02:00
2020-05-08 14:44:43 +02:00
return true
2020-05-08 15:16:20 +02:00
}
2021-06-24 14:25:57 +02:00
// uniqueApexVariations provides common implementation of the ApexModule.UniqueApexVariations
// method.
func ( c * commonToSdkLibraryAndImport ) uniqueApexVariations ( ) bool {
// A java_sdk_library that is a shared library produces an XML file that makes the shared library
// usable from an AndroidManifest.xml's <uses-library> entry. That XML file contains the name of
// the APEX and so it needs a unique variation per APEX.
return c . sharedLibrary ( )
}
2020-09-11 12:55:00 +02:00
func ( c * commonToSdkLibraryAndImport ) generateCommonBuildActions ( ctx android . ModuleContext ) {
c . doctagPaths = android . PathsForModuleSrc ( ctx , c . commonSdkLibraryProperties . Doctag_files )
}
2020-06-12 18:46:39 +02:00
// Module name of the runtime implementation library
func ( c * commonToSdkLibraryAndImport ) implLibraryModuleName ( ) string {
2024-01-19 01:22:22 +01:00
return c . module . RootLibraryName ( ) + ".impl"
2020-06-12 18:46:39 +02:00
}
// Module name of the XML file for the lib
func ( c * commonToSdkLibraryAndImport ) xmlPermissionsModuleName ( ) string {
2024-01-19 01:22:22 +01:00
return c . module . RootLibraryName ( ) + sdkXmlFileSuffix
2020-06-12 18:46:39 +02:00
}
2020-05-08 15:16:20 +02:00
// Name of the java_library module that compiles the stubs source.
func ( c * commonToSdkLibraryAndImport ) stubsLibraryModuleName ( apiScope * apiScope ) string {
2024-01-19 01:22:22 +01:00
baseName := c . module . RootLibraryName ( )
2022-11-25 13:48:20 +01:00
return c . namingScheme . stubsLibraryModuleName ( apiScope , baseName )
2020-05-08 15:16:20 +02:00
}
2023-12-20 03:53:38 +01:00
// Name of the java_library module that compiles the exportable stubs source.
func ( c * commonToSdkLibraryAndImport ) exportableStubsLibraryModuleName ( apiScope * apiScope ) string {
2024-01-19 01:22:22 +01:00
baseName := c . module . RootLibraryName ( )
2023-12-20 03:53:38 +01:00
return c . namingScheme . exportableStubsLibraryModuleName ( apiScope , baseName )
}
2020-05-08 15:16:20 +02:00
// Name of the droidstubs module that generates the stubs source and may also
// generate/check the API.
func ( c * commonToSdkLibraryAndImport ) stubsSourceModuleName ( apiScope * apiScope ) string {
2024-01-19 01:22:22 +01:00
baseName := c . module . RootLibraryName ( )
2022-11-25 13:48:20 +01:00
return c . namingScheme . stubsSourceModuleName ( apiScope , baseName )
2020-05-08 15:16:20 +02:00
}
2023-03-23 18:44:51 +01:00
// Name of the java_api_library module that generates the from-text stubs source
// and compiles to a jar file.
func ( c * commonToSdkLibraryAndImport ) apiLibraryModuleName ( apiScope * apiScope ) string {
2024-01-19 01:22:22 +01:00
baseName := c . module . RootLibraryName ( )
2023-03-23 18:44:51 +01:00
return c . namingScheme . apiLibraryModuleName ( apiScope , baseName )
}
2023-06-09 01:25:57 +02:00
// Name of the java_library module that compiles the stubs
// generated from source Java files.
2023-12-20 03:53:38 +01:00
func ( c * commonToSdkLibraryAndImport ) sourceStubsLibraryModuleName ( apiScope * apiScope ) string {
2024-01-19 01:22:22 +01:00
baseName := c . module . RootLibraryName ( )
2023-12-20 03:53:38 +01:00
return c . namingScheme . sourceStubsLibraryModuleName ( apiScope , baseName )
}
// Name of the java_library module that compiles the exportable stubs
// generated from source Java files.
func ( c * commonToSdkLibraryAndImport ) exportableSourceStubsLibraryModuleName ( apiScope * apiScope ) string {
2024-01-19 01:22:22 +01:00
baseName := c . module . RootLibraryName ( )
2023-12-20 03:53:38 +01:00
return c . namingScheme . exportableSourceStubsLibraryModuleName ( apiScope , baseName )
2023-06-09 01:25:57 +02:00
}
2020-05-14 16:39:10 +02:00
// The component names for different outputs of the java_sdk_library.
//
// They are similar to the names used for the child modules it creates
const (
stubsSourceComponentName = "stubs.source"
apiTxtComponentName = "api.txt"
removedApiTxtComponentName = "removed-api.txt"
2021-09-21 16:25:12 +02:00
annotationsComponentName = "annotations.zip"
2020-05-14 16:39:10 +02:00
)
// A regular expression to match tags that reference a specific stubs component.
//
// It will only match if given a valid scope and a valid component. It is verfy strict
// to ensure it does not accidentally match a similar looking tag that should be processed
// by the embedded Library.
var tagSplitter = func ( ) * regexp . Regexp {
// Given a list of literal string items returns a regular expression that will
// match any one of the items.
choice := func ( items ... string ) string {
return ` \Q ` + strings . Join ( items , ` \E|\Q ` ) + ` \E `
}
// Regular expression to match one of the scopes.
scopesRegexp := choice ( allScopeNames ... )
// Regular expression to match one of the components.
2021-09-21 16:25:12 +02:00
componentsRegexp := choice ( stubsSourceComponentName , apiTxtComponentName , removedApiTxtComponentName , annotationsComponentName )
2020-05-14 16:39:10 +02:00
// Regular expression to match any combination of one scope and one component.
return regexp . MustCompile ( fmt . Sprintf ( ` ^\.(%s)\.(%s)$ ` , scopesRegexp , componentsRegexp ) )
} ( )
// For OutputFileProducer interface
//
2021-09-21 16:25:12 +02:00
// .<scope>.<component name>, for all ComponentNames (for example: .public.removed-api.txt)
2020-05-14 16:39:10 +02:00
func ( c * commonToSdkLibraryAndImport ) commonOutputFiles ( tag string ) ( android . Paths , error ) {
if groups := tagSplitter . FindStringSubmatch ( tag ) ; groups != nil {
scopeName := groups [ 1 ]
component := groups [ 2 ]
if scope , ok := scopeByName [ scopeName ] ; ok {
paths := c . findScopePaths ( scope )
if paths == nil {
2024-01-19 01:22:22 +01:00
return nil , fmt . Errorf ( "%q does not provide api scope %s" , c . module . RootLibraryName ( ) , scopeName )
2020-05-14 16:39:10 +02:00
}
switch component {
case stubsSourceComponentName :
if paths . stubsSrcJar . Valid ( ) {
return android . Paths { paths . stubsSrcJar . Path ( ) } , nil
}
case apiTxtComponentName :
if paths . currentApiFilePath . Valid ( ) {
return android . Paths { paths . currentApiFilePath . Path ( ) } , nil
}
case removedApiTxtComponentName :
if paths . removedApiFilePath . Valid ( ) {
return android . Paths { paths . removedApiFilePath . Path ( ) } , nil
}
2021-09-21 16:25:12 +02:00
case annotationsComponentName :
if paths . annotationsZip . Valid ( ) {
return android . Paths { paths . annotationsZip . Path ( ) } , nil
}
2020-05-14 16:39:10 +02:00
}
return nil , fmt . Errorf ( "%s not available for api scope %s" , component , scopeName )
} else {
return nil , fmt . Errorf ( "unknown scope %s in %s" , scope , tag )
}
} else {
2020-09-11 12:55:00 +02:00
switch tag {
case ".doctags" :
if c . doctagPaths != nil {
return c . doctagPaths , nil
} else {
2024-01-19 01:22:22 +01:00
return nil , fmt . Errorf ( "no doctag_files specified on %s" , c . module . RootLibraryName ( ) )
2020-09-11 12:55:00 +02:00
}
}
2020-05-14 16:39:10 +02:00
return nil , nil
}
}
2020-05-20 12:52:25 +02:00
func ( c * commonToSdkLibraryAndImport ) getScopePathsCreateIfNeeded ( scope * apiScope ) * scopePaths {
2020-01-31 14:36:25 +01:00
if c . scopePaths == nil {
c . scopePaths = make ( map [ * apiScope ] * scopePaths )
}
paths := c . scopePaths [ scope ]
if paths == nil {
paths = & scopePaths { }
c . scopePaths [ scope ] = paths
}
return paths
}
2020-05-20 12:52:25 +02:00
func ( c * commonToSdkLibraryAndImport ) findScopePaths ( scope * apiScope ) * scopePaths {
if c . scopePaths == nil {
return nil
}
return c . scopePaths [ scope ]
}
// If this does not support the requested api scope then find the closest available
// scope it does support. Returns nil if no such scope is available.
func ( c * commonToSdkLibraryAndImport ) findClosestScopePath ( scope * apiScope ) * scopePaths {
Allow sdk_version: "system_server_current" modules to access module-lib APIs
Previously, a java module with sdk_version: "system_server_current",
would only be able to access the system server or public API of a
java_sdk_library. This change allows it to access the system server,
module lib, system and public APIs in that order.
The apiScope structs define the characteristics of each of the
different API scopes used as required by the java_sdk_library. They are
organized into a hierarchy which is used for two different purposes.
The first purpose is to define an extension hierachy. If scope X
extends Y then X provides a superset of all API elements (classes,
fields, methods, etc) provided by Y. That is reflected in the fact that
the .txt file for X would be a delta on the .txt file for Y. So, system
extends public and so system_current.txt only contains additional API
elements to add to current.txt.
The second purpose is when a java_sdk_library/import is asked to
provide a specific API scope. e.g. a library that has:
sdk_version: "module_current"
will ask each of the SDK libraries it depends upon for a module-lib
API. However, not all of them will provide an API for that scope. In
that case it will find the closest suitable API scope.
Previously, it did that by traversing up the API extension until it
found an API scope that it did provide and return that. As
system_server_current extended the public API that meant that a library
which has:
sdk_version: "system_server_current"
would provide a system server API if available, and if not fall
straight back to public. That meant that the library could not access
system or module-lib APIs even though it is running in the system
server which should be able to access all APIs.
One way to fix this would have been to just have system server API
scope extend module-lib but that would have had a number of nasty
side effects:
* It would have created a significant overhead as every module that
provides a system server API would also have to provide a module-lib
and system API, along with their corresponding .txt files.
* Each existing java_sdk_library that provided a system server API
would need those .txt files created.
* Generating sdk snapshots for older releases would have been more
complicated.
* It would have confused developers.
All of that would be unnecessary because the system server API scope is
intended to be provided by libraries that are used solely by the system
server so there is no point in them providing anything other than a
system server API.
So, instead a separate access hierarchy was added which is the same as
the extension hierarchy for all existing scopes except for the
system server scope, which instead of just being able to access the
public API will be able to access the module-lib scope, which can in
turn access system and it can in turn access public.
That achieves what we want which is a library that is loaded into the
system server to be able to access all API scopes.
Bug: 204176972
Test: m nothing
Change-Id: I854df63fcaeba32afbc1eb0d1a501238022673d0
2022-09-30 19:11:41 +02:00
for s := scope ; s != nil ; s = s . canAccess {
2020-05-20 12:52:25 +02:00
if paths := c . findScopePaths ( s ) ; paths != nil {
return paths
}
}
// This should never happen outside tests as public should be the base scope for every
// scope and is enabled by default.
return nil
}
2021-03-29 13:11:58 +02:00
func ( c * commonToSdkLibraryAndImport ) selectHeaderJarsForSdkVersion ( ctx android . BaseModuleContext , sdkVersion android . SdkSpec ) android . Paths {
2020-05-20 13:19:10 +02:00
// If a specific numeric version has been requested then use prebuilt versions of the sdk.
2021-03-31 11:17:53 +02:00
if ! sdkVersion . ApiLevel . IsPreview ( ) {
2024-01-19 01:22:22 +01:00
return PrebuiltJars ( ctx , c . module . RootLibraryName ( ) , sdkVersion )
2020-05-20 13:19:10 +02:00
}
2021-04-16 18:21:36 +02:00
paths := c . selectScopePaths ( ctx , sdkVersion . Kind )
if paths == nil {
return nil
}
return paths . stubsHeaderPath
}
// selectScopePaths returns the *scopePaths appropriate for the specific kind.
//
// If the module does not support the specific kind then it will return the *scopePaths for the
// closest kind which is a subset of the requested kind. e.g. if requesting android.SdkModule then
// it will return *scopePaths for android.SdkSystem if available or android.SdkPublic of not.
func ( c * commonToSdkLibraryAndImport ) selectScopePaths ( ctx android . BaseModuleContext , kind android . SdkKind ) * scopePaths {
2021-05-18 17:32:50 +02:00
apiScope := sdkKindToApiScope ( kind )
2020-05-20 13:19:10 +02:00
2020-05-20 12:52:25 +02:00
paths := c . findClosestScopePath ( apiScope )
if paths == nil {
var scopes [ ] string
for _ , s := range allApiScopes {
if c . findScopePaths ( s ) != nil {
scopes = append ( scopes , s . name )
}
}
2024-01-19 01:22:22 +01:00
ctx . ModuleErrorf ( "requires api scope %s from %s but it only has %q available" , apiScope . name , c . module . RootLibraryName ( ) , scopes )
2020-05-20 12:52:25 +02:00
return nil
}
2021-04-16 18:21:36 +02:00
return paths
}
2021-05-18 17:32:50 +02:00
// sdkKindToApiScope maps from android.SdkKind to apiScope.
func sdkKindToApiScope ( kind android . SdkKind ) * apiScope {
var apiScope * apiScope
switch kind {
case android . SdkSystem :
apiScope = apiScopeSystem
case android . SdkModule :
apiScope = apiScopeModuleLib
case android . SdkTest :
apiScope = apiScopeTest
case android . SdkSystemServer :
apiScope = apiScopeSystemServer
default :
apiScope = apiScopePublic
}
return apiScope
}
2021-04-16 18:21:36 +02:00
// to satisfy SdkLibraryDependency interface
2021-09-15 04:34:04 +02:00
func ( c * commonToSdkLibraryAndImport ) SdkApiStubDexJar ( ctx android . BaseModuleContext , kind android . SdkKind ) OptionalDexJarPath {
2021-04-16 18:21:36 +02:00
paths := c . selectScopePaths ( ctx , kind )
if paths == nil {
2021-09-15 04:34:04 +02:00
return makeUnsetDexJarPath ( )
2021-04-16 18:21:36 +02:00
}
return paths . stubsDexJarPath
2020-05-20 13:19:10 +02:00
}
2023-12-26 20:08:01 +01:00
// to satisfy SdkLibraryDependency interface
func ( c * commonToSdkLibraryAndImport ) SdkApiExportableStubDexJar ( ctx android . BaseModuleContext , kind android . SdkKind ) OptionalDexJarPath {
paths := c . selectScopePaths ( ctx , kind )
if paths == nil {
return makeUnsetDexJarPath ( )
}
return paths . exportableStubsDexJarPath
}
2021-05-18 17:32:50 +02:00
// to satisfy SdkLibraryDependency interface
func ( c * commonToSdkLibraryAndImport ) SdkRemovedTxtFile ( ctx android . BaseModuleContext , kind android . SdkKind ) android . OptionalPath {
apiScope := sdkKindToApiScope ( kind )
paths := c . findScopePaths ( apiScope )
if paths == nil {
return android . OptionalPath { }
}
return paths . removedApiFilePath
}
2020-05-15 11:20:31 +02:00
func ( c * commonToSdkLibraryAndImport ) sdkComponentPropertiesForChildLibrary ( ) interface { } {
componentProps := & struct {
2021-06-30 19:25:36 +02:00
SdkLibraryName * string
2020-05-15 11:20:31 +02:00
SdkLibraryToImplicitlyTrack * string
2020-05-15 21:37:11 +02:00
} { }
2024-01-19 01:22:22 +01:00
namePtr := proptools . StringPtr ( c . module . RootLibraryName ( ) )
2021-06-30 19:25:36 +02:00
componentProps . SdkLibraryName = namePtr
2020-05-15 21:37:11 +02:00
if c . sharedLibrary ( ) {
2020-05-15 11:20:31 +02:00
// Mark the stubs library as being components of this java_sdk_library so that
// any app that includes code which depends (directly or indirectly) on the stubs
// library will have the appropriate <uses-library> invocation inserted into its
// manifest if necessary.
2021-06-30 19:25:36 +02:00
componentProps . SdkLibraryToImplicitlyTrack = namePtr
2020-05-15 11:20:31 +02:00
}
return componentProps
}
2020-05-15 21:37:11 +02:00
func ( c * commonToSdkLibraryAndImport ) sharedLibrary ( ) bool {
return proptools . BoolDefault ( c . commonSdkLibraryProperties . Shared_library , true )
}
2021-05-13 23:34:45 +02:00
// Check if the stub libraries should be compiled for dex
func ( c * commonToSdkLibraryAndImport ) stubLibrariesCompiledForDex ( ) bool {
// Always compile the dex file files for the stub libraries if they will be used on the
// bootclasspath.
return ! c . sharedLibrary ( )
}
2020-05-15 11:20:31 +02:00
// Properties related to the use of a module as an component of a java_sdk_library.
type SdkLibraryComponentProperties struct {
2021-06-30 19:25:36 +02:00
// The name of the java_sdk_library/_import module.
SdkLibraryName * string ` blueprint:"mutated" `
2020-05-15 11:20:31 +02:00
// The name of the java_sdk_library/_import to add to a <uses-library> entry
// in the AndroidManifest.xml of any Android app that includes code that references
// this module. If not set then no java_sdk_library/_import is tracked.
SdkLibraryToImplicitlyTrack * string ` blueprint:"mutated" `
}
// Structure to be embedded in a module struct that needs to support the
// SdkLibraryComponentDependency interface.
type EmbeddableSdkLibraryComponent struct {
sdkLibraryComponentProperties SdkLibraryComponentProperties
}
2021-06-23 12:39:47 +02:00
func ( e * EmbeddableSdkLibraryComponent ) initSdkLibraryComponent ( module android . Module ) {
module . AddProperties ( & e . sdkLibraryComponentProperties )
2020-05-15 11:20:31 +02:00
}
2021-06-30 19:25:36 +02:00
// to satisfy SdkLibraryComponentDependency
func ( e * EmbeddableSdkLibraryComponent ) SdkLibraryName ( ) * string {
return e . sdkLibraryComponentProperties . SdkLibraryName
}
2020-09-23 17:42:35 +02:00
// to satisfy SdkLibraryComponentDependency
func ( e * EmbeddableSdkLibraryComponent ) OptionalSdkLibraryImplementation ( ) * string {
2021-07-16 16:29:25 +02:00
// For shared libraries, this is the same as the SDK library name. If a Java library or app
// depends on a component library (e.g. a stub library) it still needs to know the name of the
// run-time library and the corresponding module that provides the implementation. This name is
// passed to manifest_fixer (to be added to AndroidManifest.xml) and added to CLC (to be used
// in dexpreopt).
//
// For non-shared SDK (component or not) libraries this returns `nil`, as they are not
// <uses-library> and should not be added to the manifest or to CLC.
2020-09-23 17:42:35 +02:00
return e . sdkLibraryComponentProperties . SdkLibraryToImplicitlyTrack
}
2020-05-15 11:20:31 +02:00
// Implemented by modules that are (or possibly could be) a component of a java_sdk_library
// (including the java_sdk_library) itself.
type SdkLibraryComponentDependency interface {
2020-08-14 18:32:16 +02:00
UsesLibraryDependency
2021-06-30 19:25:36 +02:00
// SdkLibraryName returns the name of the java_sdk_library/_import module.
SdkLibraryName ( ) * string
2020-09-23 17:42:35 +02:00
// The name of the implementation library for the optional SDK library or nil, if there isn't one.
OptionalSdkLibraryImplementation ( ) * string
2020-05-15 11:20:31 +02:00
}
// Make sure that all the module types that are components of java_sdk_library/_import
// and which can be referenced (directly or indirectly) from an android app implement
// the SdkLibraryComponentDependency interface.
var _ SdkLibraryComponentDependency = ( * Library ) ( nil )
var _ SdkLibraryComponentDependency = ( * Import ) ( nil )
var _ SdkLibraryComponentDependency = ( * SdkLibrary ) ( nil )
2020-06-12 18:46:39 +02:00
var _ SdkLibraryComponentDependency = ( * SdkLibraryImport ) ( nil )
2020-05-15 11:20:31 +02:00
2021-05-18 17:32:50 +02:00
// Provides access to sdk_version related files, e.g. header and implementation jars.
2020-05-15 11:20:31 +02:00
type SdkLibraryDependency interface {
SdkLibraryComponentDependency
// Get the header jars appropriate for the supplied sdk_version.
//
// These are turbine generated jars so they only change if the externals of the
// class changes but it does not contain and implementation or JavaDoc.
2021-03-29 13:11:58 +02:00
SdkHeaderJars ( ctx android . BaseModuleContext , sdkVersion android . SdkSpec ) android . Paths
2020-05-15 11:20:31 +02:00
// Get the implementation jars appropriate for the supplied sdk version.
//
// These are either the implementation jar for the whole sdk library or the implementation
// jars for the stubs. The latter should only be needed when generating JavaDoc as otherwise
// they are identical to the corresponding header jars.
2021-03-29 13:11:58 +02:00
SdkImplementationJars ( ctx android . BaseModuleContext , sdkVersion android . SdkSpec ) android . Paths
2021-04-16 18:21:36 +02:00
2023-12-26 20:08:01 +01:00
// SdkApiStubDexJar returns the dex jar for the stubs for the prebuilt
// java_sdk_library_import module. It is needed by the hiddenapi processing tool which
// processes dex files.
2021-09-15 04:34:04 +02:00
SdkApiStubDexJar ( ctx android . BaseModuleContext , kind android . SdkKind ) OptionalDexJarPath
2021-05-13 23:34:45 +02:00
2023-12-26 20:08:01 +01:00
// SdkApiExportableStubDexJar returns the exportable dex jar for the stubs for
// java_sdk_library module. It is needed by the hiddenapi processing tool which processes
// dex files.
SdkApiExportableStubDexJar ( ctx android . BaseModuleContext , kind android . SdkKind ) OptionalDexJarPath
2021-05-18 17:32:50 +02:00
// SdkRemovedTxtFile returns the optional path to the removed.txt file for the specified sdk kind.
SdkRemovedTxtFile ( ctx android . BaseModuleContext , kind android . SdkKind ) android . OptionalPath
2021-05-13 23:34:45 +02:00
// sharedLibrary returns true if this can be used as a shared library.
sharedLibrary ( ) bool
2020-05-15 11:20:31 +02:00
}
2019-02-08 13:00:45 +01:00
type SdkLibrary struct {
2018-10-19 06:46:09 +02:00
Library
2018-04-10 06:07:10 +02:00
2018-10-19 06:46:09 +02:00
sdkLibraryProperties sdkLibraryProperties
2018-04-10 06:07:10 +02:00
2020-04-28 11:44:03 +02:00
// Map from api scope to the scope specific property structure.
scopeToProperties map [ * apiScope ] * ApiScopeProperties
2020-01-31 14:36:25 +01:00
commonToSdkLibraryAndImport
2018-04-10 06:07:10 +02:00
}
2019-02-08 13:00:45 +01:00
var _ SdkLibraryDependency = ( * SdkLibrary ) ( nil )
2019-02-11 23:03:51 +01:00
2020-04-28 11:44:03 +02:00
func ( module * SdkLibrary ) generateTestAndSystemScopesByDefault ( ) bool {
return module . sdkLibraryProperties . Generate_system_and_test_apis
}
func ( module * SdkLibrary ) getGeneratedApiScopes ( ctx android . EarlyModuleContext ) apiScopes {
// Check to see if any scopes have been explicitly enabled. If any have then all
// must be.
anyScopesExplicitlyEnabled := false
for _ , scope := range allApiScopes {
scopeProperties := module . scopeToProperties [ scope ]
if scopeProperties . Enabled != nil {
anyScopesExplicitlyEnabled = true
break
}
2019-07-15 08:31:16 +02:00
}
2020-04-28 11:44:03 +02:00
var generatedScopes apiScopes
enabledScopes := make ( map [ * apiScope ] struct { } )
for _ , scope := range allApiScopes {
scopeProperties := module . scopeToProperties [ scope ]
// If any scopes are explicitly enabled then ignore the legacy enabled status.
// This is to ensure that any new usages of this module type do not rely on legacy
// behaviour.
defaultEnabledStatus := false
if anyScopesExplicitlyEnabled {
defaultEnabledStatus = scope . defaultEnabledStatus
} else {
defaultEnabledStatus = scope . legacyEnabledStatus ( module )
}
enabled := proptools . BoolDefault ( scopeProperties . Enabled , defaultEnabledStatus )
if enabled {
enabledScopes [ scope ] = struct { } { }
generatedScopes = append ( generatedScopes , scope )
}
}
// Now check to make sure that any scope that is extended by an enabled scope is also
// enabled.
for _ , scope := range allApiScopes {
if _ , ok := enabledScopes [ scope ] ; ok {
extends := scope . extends
if extends != nil {
if _ , ok := enabledScopes [ extends ] ; ! ok {
ctx . ModuleErrorf ( "enabled api scope %q depends on disabled scope %q" , scope , extends )
}
}
}
}
return generatedScopes
2020-01-22 12:57:20 +01:00
}
2018-10-19 06:46:09 +02:00
2021-12-06 12:42:40 +01:00
var _ android . ModuleWithMinSdkVersionCheck = ( * SdkLibrary ) ( nil )
2021-12-06 12:40:46 +01:00
func ( module * SdkLibrary ) CheckMinSdkVersion ( ctx android . ModuleContext ) {
2023-03-03 22:20:36 +01:00
android . CheckMinSdkVersion ( ctx , module . MinSdkVersion ( ctx ) , func ( c android . ModuleContext , do android . PayloadDepsCallback ) {
2021-12-06 12:40:46 +01:00
ctx . WalkDeps ( func ( child android . Module , parent android . Module ) bool {
isExternal := ! module . depIsInSameApex ( ctx , child )
if am , ok := child . ( android . ApexModule ) ; ok {
if ! do ( ctx , parent , am , isExternal ) {
return false
}
}
return ! isExternal
} )
} )
}
2020-06-12 18:46:39 +02:00
type sdkLibraryComponentTag struct {
blueprint . BaseDependencyTag
name string
}
// Mark this tag so dependencies that use it are excluded from visibility enforcement.
func ( t sdkLibraryComponentTag ) ExcludeFromVisibilityEnforcement ( ) { }
var xmlPermissionsFileTag = sdkLibraryComponentTag { name : "xml-permissions-file" }
2020-02-06 14:51:46 +01:00
2020-02-17 09:28:10 +01:00
func IsXmlPermissionsFileDepTag ( depTag blueprint . DependencyTag ) bool {
2020-06-12 18:46:39 +02:00
if dt , ok := depTag . ( sdkLibraryComponentTag ) ; ok {
2020-02-17 09:28:10 +01:00
return dt == xmlPermissionsFileTag
}
return false
}
2020-06-12 18:46:39 +02:00
var implLibraryTag = sdkLibraryComponentTag { name : "impl-library" }
2020-05-16 16:52:12 +02:00
2020-06-26 21:17:02 +02:00
// Add the dependencies on the child modules in the component deps mutator.
func ( module * SdkLibrary ) ComponentDepsMutator ( ctx android . BottomUpMutatorContext ) {
2020-04-28 11:44:03 +02:00
for _ , apiScope := range module . getGeneratedApiScopes ( ctx ) {
2020-01-22 12:57:20 +01:00
// Add dependencies to the stubs library
2023-03-29 18:19:51 +02:00
stubModuleName := module . stubsLibraryModuleName ( apiScope )
2023-12-26 20:08:01 +01:00
ctx . AddVariationDependencies ( nil , apiScope . everythingStubsTag , stubModuleName )
2023-06-09 01:25:57 +02:00
2023-12-26 20:08:01 +01:00
exportableStubModuleName := module . exportableStubsLibraryModuleName ( apiScope )
ctx . AddVariationDependencies ( nil , apiScope . exportableStubsTag , exportableStubModuleName )
2020-01-22 12:57:20 +01:00
2020-07-20 19:04:44 +02:00
// 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 ) )
2022-05-16 15:10:47 +02:00
if module . compareAgainstLatestApi ( apiScope ) {
// Add dependencies on the latest finalized version of the API .txt file.
latestApiModuleName := module . latestApiModuleName ( apiScope )
ctx . AddDependency ( module , apiScope . latestApiModuleTag , latestApiModuleName )
// Add dependencies on the latest finalized version of the remove API .txt file.
latestRemovedApiModuleName := module . latestRemovedApiModuleName ( apiScope )
ctx . AddDependency ( module , apiScope . latestRemovedApiModuleTag , latestRemovedApiModuleName )
}
2018-10-19 06:46:09 +02:00
}
2020-05-15 21:37:11 +02:00
if module . requiresRuntimeImplementationLibrary ( ) {
2020-05-16 16:52:12 +02:00
// Add dependency to the rule for generating the implementation library.
ctx . AddDependency ( module , implLibraryTag , module . implLibraryModuleName ( ) )
2020-05-15 21:37:11 +02:00
if module . sharedLibrary ( ) {
// Add dependency to the rule for generating the xml permissions file
2020-06-12 18:46:39 +02:00
ctx . AddDependency ( module , xmlPermissionsFileTag , module . xmlPermissionsModuleName ( ) )
2020-05-15 21:37:11 +02:00
}
2020-06-26 21:17:02 +02:00
}
}
2020-02-06 14:51:46 +01:00
2020-06-26 21:17:02 +02:00
// Add other dependencies as normal.
func ( module * SdkLibrary ) DepsMutator ( ctx android . BottomUpMutatorContext ) {
2021-01-20 17:52:41 +01:00
var missingApiModules [ ] string
for _ , apiScope := range module . getGeneratedApiScopes ( ctx ) {
if apiScope . unstable {
continue
}
2022-05-16 15:10:47 +02:00
if m := module . latestApiModuleName ( apiScope ) ; ! ctx . OtherModuleExists ( m ) {
2021-01-20 17:52:41 +01:00
missingApiModules = append ( missingApiModules , m )
}
2022-05-16 15:10:47 +02:00
if m := module . latestRemovedApiModuleName ( apiScope ) ; ! ctx . OtherModuleExists ( m ) {
2021-01-20 17:52:41 +01:00
missingApiModules = append ( missingApiModules , m )
}
2022-05-16 15:10:47 +02:00
if m := module . latestIncompatibilitiesModuleName ( apiScope ) ; ! ctx . OtherModuleExists ( m ) {
2021-03-09 22:25:02 +01:00
missingApiModules = append ( missingApiModules , m )
}
2021-01-20 17:52:41 +01:00
}
if len ( missingApiModules ) != 0 && ! module . sdkLibraryProperties . Unsafe_ignore_missing_latest_api {
m := module . Name ( ) + " is missing tracking files for previously released library versions.\n"
m += "You need to do one of the following:\n"
m += "- Add `unsafe_ignore_missing_latest_api: true` to your blueprint (to disable compat tracking)\n"
m += "- Add a set of prebuilt txt files representing the last released version of this library for compat checking.\n"
m += " (the current set of API files can be used as a seed for this compatibility tracking\n"
m += "\n"
m += "The following filegroup modules are missing:\n "
m += strings . Join ( missingApiModules , "\n " ) + "\n"
m += "Please see the documentation of the prebuilt_apis module type (and a usage example in prebuilts/sdk) for a convenient way to generate these."
ctx . ModuleErrorf ( m )
}
2020-06-26 21:17:02 +02:00
if module . requiresRuntimeImplementationLibrary ( ) {
2020-05-15 21:37:11 +02:00
// Only add the deps for the library if it is actually going to be built.
module . Library . deps ( ctx )
}
2018-04-10 06:07:10 +02:00
}
2020-05-14 16:39:10 +02:00
func ( module * SdkLibrary ) OutputFiles ( tag string ) ( android . Paths , error ) {
paths , err := module . commonOutputFiles ( tag )
2021-12-11 00:05:02 +01:00
if paths != nil || err != nil {
2021-12-10 23:52:43 +01:00
return paths , err
2021-11-08 20:52:49 +01:00
}
2021-12-11 00:05:02 +01:00
if module . requiresRuntimeImplementationLibrary ( ) {
return module . Library . OutputFiles ( tag )
}
if tag == "" {
return nil , nil
}
return nil , fmt . Errorf ( "unsupported module reference tag %q" , tag )
2020-05-14 16:39:10 +02:00
}
2019-02-08 13:00:45 +01:00
func ( module * SdkLibrary ) GenerateAndroidBuildActions ( ctx android . ModuleContext ) {
2021-12-06 12:40:46 +01:00
if proptools . String ( module . deviceProperties . Min_sdk_version ) != "" {
module . CheckMinSdkVersion ( ctx )
}
2020-09-11 12:55:00 +02:00
module . generateCommonBuildActions ( ctx )
2020-05-15 21:37:11 +02:00
// Only build an implementation library if required.
if module . requiresRuntimeImplementationLibrary ( ) {
2024-02-12 23:49:21 +01:00
// stubsLinkType must be set before calling Library.GenerateAndroidBuildActions
module . Library . stubsLinkType = Unknown
2019-12-30 18:35:49 +01:00
module . Library . GenerateAndroidBuildActions ( ctx )
}
2018-10-19 06:46:09 +02:00
Remove duplicate component from sdk snapshot
Previously, an sdk snapshot could contain the following:
* A java_sdk_library_import module, e.g. "foo" which creates component
modules "foo.stubs", etc.
* A corresponding versioned module, e.g. "sdk_foo@current" which
created component modules "sdk_foo@current.stubs", etc.
* An internal (to the sdk snapshot) java_import for one of "foo"'s
components, e.g. "sdk_foo.stubs"
* A corresponding versioned module, e.g. "sdk_foo.stubs@current".
That causes a few problems:
1. The "foo.stubs" is duplicated.
2. The names of the components created by the versioned
java_sdk_library_import are invalid, as they append the component's
suffix to the version and not the name before the version.
The latter causes problems when building against prebuilts and fixing
that causes the generated snapshot to be invalid because it contains
duplicate definitions of the "sdk_foo.stubs@current" module. One
explicitly in the Android.bp file and one created by the
"sdk_foo@current" module.
Removing the duplicates from the snapshot causes errors as the name
generated by the snapshot for the component module, i.e.
"sdk_foo.stubs@current" does not match the name generated by the
"sdk_foo@current", i.e. "sdk_foo@current.stubs".
This change fixes them together.
Bug: 179354495
Test: m nothing
Merged-In: I515f235fe21755b5275af12366e96c24c94c0273
Change-Id: I515f235fe21755b5275af12366e96c24c94c0273
(cherry picked from commit a1aa7387f74a49c8c974ba2198def0e081488624)
2021-04-29 22:50:40 +02:00
// Collate the components exported by this module. All scope specific modules are exported but
// the impl and xml component modules are not.
exportedComponents := map [ string ] struct { } { }
2018-07-06 04:20:23 +02:00
// Record the paths to the header jars of the library (stubs and impl).
2020-01-22 12:57:20 +01:00
// When this java_sdk_library is depended upon from others via "libs" property,
2018-04-10 06:07:10 +02:00
// the recorded paths will be returned depending on the link type of the caller.
ctx . VisitDirectDeps ( func ( to android . Module ) {
tag := ctx . OtherModuleDependencyTag ( to )
2020-04-29 21:45:27 +02:00
// Extract information from any of the scope specific dependencies.
if scopeTag , ok := tag . ( scopeDependencyTag ) ; ok {
apiScope := scopeTag . apiScope
2020-05-20 12:52:25 +02:00
scopePaths := module . getScopePathsCreateIfNeeded ( apiScope )
2020-04-29 21:45:27 +02:00
// Extract information from the dependency. The exact information extracted
// is determined by the nature of the dependency which is determined by the tag.
scopeTag . extractDepInfo ( ctx , to , scopePaths )
Remove duplicate component from sdk snapshot
Previously, an sdk snapshot could contain the following:
* A java_sdk_library_import module, e.g. "foo" which creates component
modules "foo.stubs", etc.
* A corresponding versioned module, e.g. "sdk_foo@current" which
created component modules "sdk_foo@current.stubs", etc.
* An internal (to the sdk snapshot) java_import for one of "foo"'s
components, e.g. "sdk_foo.stubs"
* A corresponding versioned module, e.g. "sdk_foo.stubs@current".
That causes a few problems:
1. The "foo.stubs" is duplicated.
2. The names of the components created by the versioned
java_sdk_library_import are invalid, as they append the component's
suffix to the version and not the name before the version.
The latter causes problems when building against prebuilts and fixing
that causes the generated snapshot to be invalid because it contains
duplicate definitions of the "sdk_foo.stubs@current" module. One
explicitly in the Android.bp file and one created by the
"sdk_foo@current" module.
Removing the duplicates from the snapshot causes errors as the name
generated by the snapshot for the component module, i.e.
"sdk_foo.stubs@current" does not match the name generated by the
"sdk_foo@current", i.e. "sdk_foo@current.stubs".
This change fixes them together.
Bug: 179354495
Test: m nothing
Merged-In: I515f235fe21755b5275af12366e96c24c94c0273
Change-Id: I515f235fe21755b5275af12366e96c24c94c0273
(cherry picked from commit a1aa7387f74a49c8c974ba2198def0e081488624)
2021-04-29 22:50:40 +02:00
exportedComponents [ ctx . OtherModuleName ( to ) ] = struct { } { }
2018-07-24 04:19:26 +02:00
}
2018-04-10 06:07:10 +02:00
} )
Remove duplicate component from sdk snapshot
Previously, an sdk snapshot could contain the following:
* A java_sdk_library_import module, e.g. "foo" which creates component
modules "foo.stubs", etc.
* A corresponding versioned module, e.g. "sdk_foo@current" which
created component modules "sdk_foo@current.stubs", etc.
* An internal (to the sdk snapshot) java_import for one of "foo"'s
components, e.g. "sdk_foo.stubs"
* A corresponding versioned module, e.g. "sdk_foo.stubs@current".
That causes a few problems:
1. The "foo.stubs" is duplicated.
2. The names of the components created by the versioned
java_sdk_library_import are invalid, as they append the component's
suffix to the version and not the name before the version.
The latter causes problems when building against prebuilts and fixing
that causes the generated snapshot to be invalid because it contains
duplicate definitions of the "sdk_foo.stubs@current" module. One
explicitly in the Android.bp file and one created by the
"sdk_foo@current" module.
Removing the duplicates from the snapshot causes errors as the name
generated by the snapshot for the component module, i.e.
"sdk_foo.stubs@current" does not match the name generated by the
"sdk_foo@current", i.e. "sdk_foo@current.stubs".
This change fixes them together.
Bug: 179354495
Test: m nothing
Merged-In: I515f235fe21755b5275af12366e96c24c94c0273
Change-Id: I515f235fe21755b5275af12366e96c24c94c0273
(cherry picked from commit a1aa7387f74a49c8c974ba2198def0e081488624)
2021-04-29 22:50:40 +02:00
// Make the set of components exported by this module available for use elsewhere.
2023-03-01 01:02:16 +01:00
exportedComponentInfo := android . ExportedComponentsInfo { Components : android . SortedKeys ( exportedComponents ) }
2023-12-14 00:19:49 +01:00
android . SetProvider ( ctx , android . ExportedComponentsInfoProvider , exportedComponentInfo )
2022-05-16 15:10:47 +02:00
// Provide additional information for inclusion in an sdk's generated .info file.
additionalSdkInfo := map [ string ] interface { } { }
additionalSdkInfo [ "dist_stem" ] = module . distStem ( )
2022-09-22 17:24:46 +02:00
baseModuleName := module . distStem ( )
2022-05-16 15:10:47 +02:00
scopes := map [ string ] interface { } { }
additionalSdkInfo [ "scopes" ] = scopes
for scope , scopePaths := range module . scopePaths {
scopeInfo := map [ string ] interface { } { }
scopes [ scope . name ] = scopeInfo
scopeInfo [ "current_api" ] = scope . snapshotRelativeCurrentApiTxtPath ( baseModuleName )
scopeInfo [ "removed_api" ] = scope . snapshotRelativeRemovedApiTxtPath ( baseModuleName )
if p := scopePaths . latestApiPath ; p . Valid ( ) {
scopeInfo [ "latest_api" ] = p . Path ( ) . String ( )
}
if p := scopePaths . latestRemovedApiPath ; p . Valid ( ) {
scopeInfo [ "latest_removed_api" ] = p . Path ( ) . String ( )
}
}
2023-12-14 00:19:49 +01:00
android . SetProvider ( ctx , android . AdditionalSdkInfoProvider , android . AdditionalSdkInfo { additionalSdkInfo } )
2018-04-10 06:07:10 +02:00
}
2019-12-03 05:24:29 +01:00
func ( module * SdkLibrary ) AndroidMkEntries ( ) [ ] android . AndroidMkEntries {
2020-05-15 21:37:11 +02:00
if ! module . requiresRuntimeImplementationLibrary ( ) {
2019-12-30 18:35:49 +01:00
return nil
}
2019-12-03 05:24:29 +01:00
entriesList := module . Library . AndroidMkEntries ( )
2020-06-05 11:43:19 +02:00
if module . sharedLibrary ( ) {
entries := & entriesList [ 0 ]
entries . Required = append ( entries . Required , module . xmlPermissionsModuleName ( ) )
}
2019-12-03 05:24:29 +01:00
return entriesList
2018-04-23 14:41:26 +02:00
}
2020-03-27 20:43:19 +01:00
// The dist path of the stub artifacts
func ( module * SdkLibrary ) apiDistPath ( apiScope * apiScope ) string {
2021-06-02 22:02:23 +02:00
return path . Join ( "apistubs" , module . distGroup ( ) , apiScope . name )
2020-03-27 20:43:19 +01:00
}
2019-12-24 21:31:31 +01:00
// Get the sdk version for use when compiling the stubs library.
2020-05-12 16:52:55 +02:00
func ( module * SdkLibrary ) sdkVersionForStubsLibrary ( mctx android . EarlyModuleContext , apiScope * apiScope ) string {
2020-05-12 12:50:28 +02:00
scopeProperties := module . scopeToProperties [ apiScope ]
if scopeProperties . Sdk_version != nil {
return proptools . String ( scopeProperties . Sdk_version )
}
2021-03-29 13:11:58 +02:00
sdkDep := decodeSdkDep ( mctx , android . SdkContext ( & module . Library ) )
2019-12-24 21:31:31 +01:00
if sdkDep . hasStandardLibs ( ) {
// If building against a standard sdk then use the sdk version appropriate for the scope.
2020-01-22 12:57:20 +01:00
return apiScope . sdkVersion
2019-12-24 21:31:31 +01:00
} else {
// Otherwise, use no system module.
return "none"
}
}
2020-11-20 22:26:20 +01:00
func ( module * SdkLibrary ) distStem ( ) string {
return proptools . StringDefault ( module . sdkLibraryProperties . Dist_stem , module . BaseModuleName ( ) )
}
2021-06-01 22:13:40 +02:00
// distGroup returns the subdirectory of the dist path of the stub artifacts.
func ( module * SdkLibrary ) distGroup ( ) string {
2021-06-01 23:07:56 +02:00
return proptools . StringDefault ( module . sdkLibraryProperties . Dist_group , "unknown" )
2021-06-01 22:13:40 +02:00
}
2022-05-16 15:10:47 +02:00
func latestPrebuiltApiModuleName ( name string , apiScope * apiScope ) string {
return PrebuiltApiModuleName ( name , apiScope . name , "latest" )
}
2020-01-22 12:57:20 +01:00
func ( module * SdkLibrary ) latestApiFilegroupName ( apiScope * apiScope ) string {
2022-05-16 15:10:47 +02:00
return ":" + module . latestApiModuleName ( apiScope )
}
func ( module * SdkLibrary ) latestApiModuleName ( apiScope * apiScope ) string {
return latestPrebuiltApiModuleName ( module . distStem ( ) , apiScope )
2018-05-12 15:29:12 +02:00
}
2018-04-10 06:07:10 +02:00
2020-01-22 12:57:20 +01:00
func ( module * SdkLibrary ) latestRemovedApiFilegroupName ( apiScope * apiScope ) string {
2022-05-16 15:10:47 +02:00
return ":" + module . latestRemovedApiModuleName ( apiScope )
}
func ( module * SdkLibrary ) latestRemovedApiModuleName ( apiScope * apiScope ) string {
return latestPrebuiltApiModuleName ( module . distStem ( ) + "-removed" , apiScope )
2018-04-10 06:07:10 +02:00
}
2021-03-09 22:25:02 +01:00
func ( module * SdkLibrary ) latestIncompatibilitiesFilegroupName ( apiScope * apiScope ) string {
2022-05-16 15:10:47 +02:00
return ":" + module . latestIncompatibilitiesModuleName ( apiScope )
}
func ( module * SdkLibrary ) latestIncompatibilitiesModuleName ( apiScope * apiScope ) string {
return latestPrebuiltApiModuleName ( module . distStem ( ) + "-incompatibilities" , apiScope )
2021-03-09 22:25:02 +01:00
}
2023-03-23 18:44:51 +01:00
func ( module * SdkLibrary ) contributesToApiSurface ( c android . Config ) bool {
_ , exists := c . GetApiLibraries ( ) [ module . Name ( ) ]
return exists
}
2023-08-02 08:44:57 +02:00
// The listed modules are the special java_sdk_libraries where apiScope.kind do not match the
// api surface that the module contribute to. For example, the public droidstubs and java_library
// do not contribute to the public api surface, but contributes to the core platform api surface.
// This method returns the full api surface stub lib that
// the generated java_api_library should depend on.
func ( module * SdkLibrary ) alternativeFullApiSurfaceStubLib ( ) string {
if val , ok := apiLibraryAdditionalProperties [ module . Name ( ) ] ; ok {
return val . FullApiSurfaceStubLib
}
return ""
}
// The listed modules' stubs contents do not match the corresponding txt files,
// but require additional api contributions to generate the full stubs.
// This method returns the name of the additional api contribution module
// for corresponding sdk_library modules.
func ( module * SdkLibrary ) apiLibraryAdditionalApiContribution ( ) string {
if val , ok := apiLibraryAdditionalProperties [ module . Name ( ) ] ; ok {
return val . AdditionalApiContribution
}
return ""
}
2020-08-19 12:40:22 +02:00
func childModuleVisibility ( childVisibility [ ] string ) [ ] string {
if childVisibility == nil {
// No child visibility set. The child will use the visibility of the sdk_library.
return nil
}
// Prepend an override to ignore the sdk_library's visibility, and rely on the child visibility.
var visibility [ ] string
visibility = append ( visibility , "//visibility:override" )
visibility = append ( visibility , childVisibility ... )
return visibility
}
2020-05-16 16:52:12 +02:00
// Creates the implementation java library
func ( module * SdkLibrary ) createImplLibrary ( mctx android . DefaultableHookContext ) {
2020-08-19 12:40:22 +02:00
visibility := childModuleVisibility ( module . sdkLibraryProperties . Impl_library_visibility )
2020-05-16 16:52:12 +02:00
props := struct {
2022-04-28 16:13:30 +02:00
Name * string
Visibility [ ] string
Instrument bool
Libs [ ] string
Static_libs [ ] string
Apex_available [ ] string
2020-05-16 16:52:12 +02:00
} {
Name : proptools . StringPtr ( module . implLibraryModuleName ( ) ) ,
2020-08-19 12:40:22 +02:00
Visibility : visibility ,
2020-06-18 22:09:55 +02:00
// Set the instrument property to ensure it is instrumented when instrumentation is required.
Instrument : true ,
2020-10-08 15:47:23 +02:00
// Set the impl_only libs. Note that the module's "Libs" get appended as well, via the
// addition of &module.properties below.
Libs : module . sdkLibraryProperties . Impl_only_libs ,
2022-04-28 16:13:30 +02:00
// Set the impl_only static libs. Note that the module's "static_libs" get appended as well, via the
// addition of &module.properties below.
Static_libs : module . sdkLibraryProperties . Impl_only_static_libs ,
// Pass the apex_available settings down so that the impl library can be statically
// embedded within a library that is added to an APEX. Needed for updatable-media.
Apex_available : module . ApexAvailable ( ) ,
2020-05-16 16:52:12 +02:00
}
properties := [ ] interface { } {
& module . properties ,
& module . protoProperties ,
& module . deviceProperties ,
2020-07-10 00:16:41 +02:00
& module . dexProperties ,
2020-05-16 16:52:12 +02:00
& module . dexpreoptProperties ,
2020-06-03 05:09:13 +02:00
& module . linter . properties ,
2020-05-16 16:52:12 +02:00
& props ,
module . sdkComponentPropertiesForChildLibrary ( ) ,
}
mctx . CreateModule ( LibraryFactory , properties ... )
}
2023-12-20 03:53:38 +01:00
type libraryProperties struct {
Name * string
Visibility [ ] string
Srcs [ ] string
Installable * bool
Sdk_version * string
System_modules * string
Patch_module * string
Libs [ ] string
Static_libs [ ] string
Compile_dex * bool
Java_version * string
Openjdk9 struct {
Srcs [ ] string
Javacflags [ ] string
}
Dist struct {
Targets [ ] string
Dest * string
Dir * string
Tag * string
}
2024-02-12 23:49:21 +01:00
Is_stubs_module * bool
2023-12-20 03:53:38 +01:00
}
func ( module * SdkLibrary ) stubsLibraryProps ( mctx android . DefaultableHookContext , apiScope * apiScope ) libraryProperties {
props := libraryProperties { }
2023-09-07 03:18:31 +02:00
props . Visibility = [ ] string { "//visibility:override" , "//visibility:private" }
2018-04-10 06:07:10 +02:00
// sources are generated from the droiddoc
2019-12-24 21:31:31 +01:00
sdkVersion := module . sdkVersionForStubsLibrary ( mctx , apiScope )
2019-06-11 13:31:14 +02:00
props . Sdk_version = proptools . StringPtr ( sdkVersion )
2020-05-16 19:54:24 +02:00
props . System_modules = module . deviceProperties . System_modules
props . Patch_module = module . properties . Patch_module
2019-12-23 20:40:36 +01:00
props . Installable = proptools . BoolPtr ( false )
2018-10-19 06:46:09 +02:00
props . Libs = module . sdkLibraryProperties . Stub_only_libs
2023-08-10 02:07:03 +02:00
props . Libs = append ( props . Libs , module . scopeToProperties [ apiScope ] . Libs ... )
2021-04-21 17:30:10 +02:00
props . Static_libs = module . sdkLibraryProperties . Stub_only_static_libs
2020-05-20 20:35:27 +02:00
// The stub-annotations library contains special versions of the annotations
// with CLASS retention policy, so that they're kept.
if proptools . Bool ( module . sdkLibraryProperties . Annotations_enabled ) {
props . Libs = append ( props . Libs , "stub-annotations" )
}
2020-05-16 19:54:24 +02:00
props . Openjdk9 . Srcs = module . properties . Openjdk9 . Srcs
props . Openjdk9 . Javacflags = module . properties . Openjdk9 . Javacflags
2020-05-21 10:21:57 +02:00
// We compile the stubs for 1.8 in line with the main android.jar stubs, and potential
// interop with older developer tools that don't support 1.9.
props . Java_version = proptools . StringPtr ( "1.8" )
2024-02-12 23:49:21 +01:00
props . Is_stubs_module = proptools . BoolPtr ( true )
2021-05-13 23:34:45 +02:00
2023-12-20 03:53:38 +01:00
return props
}
// Creates a static java library that has API stubs
func ( module * SdkLibrary ) createStubsLibrary ( mctx android . DefaultableHookContext , apiScope * apiScope ) {
props := module . stubsLibraryProps ( mctx , apiScope )
props . Name = proptools . StringPtr ( module . sourceStubsLibraryModuleName ( apiScope ) )
props . Srcs = [ ] string { ":" + module . stubsSourceModuleName ( apiScope ) }
mctx . CreateModule ( LibraryFactory , & props , module . sdkComponentPropertiesForChildLibrary ( ) )
}
// Create a static java library that compiles the "exportable" stubs
func ( module * SdkLibrary ) createExportableStubsLibrary ( mctx android . DefaultableHookContext , apiScope * apiScope ) {
props := module . stubsLibraryProps ( mctx , apiScope )
props . Name = proptools . StringPtr ( module . exportableSourceStubsLibraryModuleName ( apiScope ) )
props . Srcs = [ ] string { ":" + module . stubsSourceModuleName ( apiScope ) + "{.exportable}" }
2020-05-15 11:20:31 +02:00
mctx . CreateModule ( LibraryFactory , & props , module . sdkComponentPropertiesForChildLibrary ( ) )
2018-04-10 06:07:10 +02:00
}
2020-04-07 19:49:53 +02:00
// Creates a droidstubs module that creates stubs source files from the given full source
2020-04-29 21:45:27 +02:00
// files and also updates and checks the API specification files.
2020-07-20 19:04:44 +02:00
func ( module * SdkLibrary ) createStubsSourcesAndApi ( mctx android . DefaultableHookContext , apiScope * apiScope , name string , scopeSpecificDroidstubsArgs [ ] string ) {
2018-04-10 06:07:10 +02:00
props := struct {
2018-10-19 06:46:09 +02:00
Name * string
2020-04-30 00:35:13 +02:00
Visibility [ ] string
2018-10-19 06:46:09 +02:00
Srcs [ ] string
Installable * bool
2019-06-11 13:31:14 +02:00
Sdk_version * string
2023-01-26 09:08:52 +01:00
Api_surface * string
2019-12-24 21:31:31 +01:00
System_modules * string
2018-10-19 06:46:09 +02:00
Libs [ ] string
2020-09-25 20:59:14 +02:00
Output_javadoc_comments * bool
2019-02-11 16:55:17 +01:00
Arg_files [ ] string
2018-10-19 06:46:09 +02:00
Args * string
Java_version * string
2020-05-20 20:35:27 +02:00
Annotations_enabled * bool
2018-10-19 06:46:09 +02:00
Merge_annotations_dirs [ ] string
Merge_inclusion_annotations_dirs [ ] string
2020-04-29 14:30:54 +02:00
Generate_stubs * bool
2020-12-21 16:29:34 +01:00
Previous_api * string
2023-12-19 02:13:16 +01:00
Aconfig_declarations [ ] string
2018-10-19 06:46:09 +02:00
Check_api struct {
2020-12-31 11:37:27 +01:00
Current ApiToCheck
Last_released ApiToCheck
2020-05-10 20:32:20 +02:00
Api_lint struct {
Enabled * bool
New_since * string
Baseline_file * string
}
2018-05-12 15:29:12 +02:00
}
2018-05-29 04:35:17 +02:00
Aidl struct {
Include_dirs [ ] string
Local_include_dirs [ ] string
}
2020-11-23 18:41:36 +01:00
Dists [ ] android . Dist
2018-04-10 06:07:10 +02:00
} { }
2020-04-28 15:08:32 +02:00
// The stubs source processing uses the same compile time classpath when extracting the
// API from the implementation library as it does when compiling it. i.e. the same
// * sdk version
// * system_modules
// * libs (static_libs/libs)
2019-06-07 11:44:37 +02:00
2020-04-29 14:30:54 +02:00
props . Name = proptools . StringPtr ( name )
2020-08-19 12:40:22 +02:00
props . Visibility = childModuleVisibility ( module . sdkLibraryProperties . Stubs_source_visibility )
2020-05-16 19:54:24 +02:00
props . Srcs = append ( props . Srcs , module . properties . Srcs ... )
2021-09-16 15:24:13 +02:00
props . Srcs = append ( props . Srcs , module . sdkLibraryProperties . Api_srcs ... )
2020-05-16 19:54:24 +02:00
props . Sdk_version = module . deviceProperties . Sdk_version
2023-01-26 09:08:52 +01:00
props . Api_surface = & apiScope . name
2020-05-16 19:54:24 +02:00
props . System_modules = module . deviceProperties . System_modules
2018-04-10 06:07:10 +02:00
props . Installable = proptools . BoolPtr ( false )
2018-06-05 09:46:14 +02:00
// A droiddoc module has only one Libs property and doesn't distinguish between
// shared libs and static libs. So we need to add both of these libs to Libs property.
2020-05-16 19:54:24 +02:00
props . Libs = module . properties . Libs
props . Libs = append ( props . Libs , module . properties . Static_libs ... )
2022-11-21 13:38:25 +01:00
props . Libs = append ( props . Libs , module . sdkLibraryProperties . Stub_only_libs ... )
2023-08-10 02:07:03 +02:00
props . Libs = append ( props . Libs , module . scopeToProperties [ apiScope ] . Libs ... )
2020-05-16 19:54:24 +02:00
props . Aidl . Include_dirs = module . deviceProperties . Aidl . Include_dirs
props . Aidl . Local_include_dirs = module . deviceProperties . Aidl . Local_include_dirs
props . Java_version = module . properties . Java_version
2018-10-19 06:46:09 +02:00
2020-05-20 20:35:27 +02:00
props . Annotations_enabled = module . sdkLibraryProperties . Annotations_enabled
2018-10-19 06:46:09 +02:00
props . Merge_annotations_dirs = module . sdkLibraryProperties . Merge_annotations_dirs
props . Merge_inclusion_annotations_dirs = module . sdkLibraryProperties . Merge_inclusion_annotations_dirs
2023-12-19 02:13:16 +01:00
props . Aconfig_declarations = module . sdkLibraryProperties . Aconfig_declarations
2018-10-19 06:46:09 +02:00
2020-04-07 19:49:53 +02:00
droidstubsArgs := [ ] string { }
2019-12-24 11:41:30 +01:00
if len ( module . sdkLibraryProperties . Api_packages ) != 0 {
2020-04-07 19:49:53 +02:00
droidstubsArgs = append ( droidstubsArgs , "--stub-packages " + strings . Join ( module . sdkLibraryProperties . Api_packages , ":" ) )
2019-12-24 11:41:30 +01:00
}
if len ( module . sdkLibraryProperties . Hidden_api_packages ) != 0 {
2020-04-07 19:49:53 +02:00
droidstubsArgs = append ( droidstubsArgs ,
2019-12-24 11:41:30 +01:00
android . JoinWithPrefix ( module . sdkLibraryProperties . Hidden_api_packages , " --hide-package " ) )
}
2020-04-07 19:49:53 +02:00
droidstubsArgs = append ( droidstubsArgs , module . sdkLibraryProperties . Droiddoc_options ... )
2023-11-02 16:18:09 +01:00
disabledWarnings := [ ] string { "HiddenSuperclass" }
if proptools . BoolDefault ( module . sdkLibraryProperties . Api_lint . Legacy_errors_allowed , true ) {
disabledWarnings = append ( disabledWarnings ,
"BroadcastBehavior" ,
"DeprecationMismatch" ,
"MissingPermission" ,
"SdkConstant" ,
"Todo" ,
)
2019-12-24 11:41:30 +01:00
}
2020-04-07 19:49:53 +02:00
droidstubsArgs = append ( droidstubsArgs , android . JoinWithPrefix ( disabledWarnings , "--hide " ) )
2018-09-17 06:23:09 +02:00
2020-09-25 20:59:14 +02:00
// Output Javadoc comments for public scope.
if apiScope == apiScopePublic {
props . Output_javadoc_comments = proptools . BoolPtr ( true )
}
2020-04-07 19:50:10 +02:00
// Add in scope specific arguments.
2020-04-29 14:30:54 +02:00
droidstubsArgs = append ( droidstubsArgs , scopeSpecificDroidstubsArgs ... )
2019-02-11 16:55:17 +01:00
props . Arg_files = module . sdkLibraryProperties . Droiddoc_option_files
2020-04-07 19:49:53 +02:00
props . Args = proptools . StringPtr ( strings . Join ( droidstubsArgs , " " ) )
2018-04-10 06:07:10 +02:00
2020-07-20 19:04:44 +02:00
// List of APIs identified from the provided source files are created. They are later
// compared against to the not-yet-released (a.k.a current) list of APIs and to the
// last-released (a.k.a numbered) list of API.
currentApiFileName := apiScope . apiFilePrefix + "current.txt"
removedApiFileName := apiScope . apiFilePrefix + "removed.txt"
apiDir := module . getApiDir ( )
currentApiFileName = path . Join ( apiDir , currentApiFileName )
removedApiFileName = path . Join ( apiDir , removedApiFileName )
// check against the not-yet-release API
props . Check_api . Current . Api_file = proptools . StringPtr ( currentApiFileName )
props . Check_api . Current . Removed_api_file = proptools . StringPtr ( removedApiFileName )
2022-05-16 15:10:47 +02:00
if module . compareAgainstLatestApi ( apiScope ) {
2020-07-20 19:04:44 +02:00
// check against the latest released API
latestApiFilegroupName := proptools . StringPtr ( module . latestApiFilegroupName ( apiScope ) )
2020-12-21 16:29:34 +01:00
props . Previous_api = latestApiFilegroupName
2020-07-20 19:04:44 +02:00
props . Check_api . Last_released . Api_file = latestApiFilegroupName
props . Check_api . Last_released . Removed_api_file = proptools . StringPtr (
module . latestRemovedApiFilegroupName ( apiScope ) )
2021-03-09 22:25:02 +01:00
props . Check_api . Last_released . Baseline_file = proptools . StringPtr (
module . latestIncompatibilitiesFilegroupName ( apiScope ) )
2020-07-20 19:04:44 +02:00
if proptools . Bool ( module . sdkLibraryProperties . Api_lint . Enabled ) {
// Enable api lint.
props . Check_api . Api_lint . Enabled = proptools . BoolPtr ( true )
props . Check_api . Api_lint . New_since = latestApiFilegroupName
// If it exists then pass a lint-baseline.txt through to droidstubs.
baselinePath := path . Join ( apiDir , apiScope . apiFilePrefix + "lint-baseline.txt" )
baselinePathRelativeToRoot := path . Join ( mctx . ModuleDir ( ) , baselinePath )
paths , err := mctx . GlobWithDeps ( baselinePathRelativeToRoot , nil )
if err != nil {
mctx . ModuleErrorf ( "error checking for presence of %s: %s" , baselinePathRelativeToRoot , err )
}
if len ( paths ) == 1 {
props . Check_api . Api_lint . Baseline_file = proptools . StringPtr ( baselinePath )
} else if len ( paths ) != 0 {
mctx . ModuleErrorf ( "error checking for presence of %s: expected one path, found: %v" , baselinePathRelativeToRoot , paths )
2020-05-10 20:32:20 +02:00
}
}
2020-07-20 19:04:44 +02:00
}
2018-04-10 06:07:10 +02:00
2020-07-20 19:04:44 +02:00
if ! Bool ( module . sdkLibraryProperties . No_dist ) {
2020-11-23 18:41:36 +01:00
// Dist the api txt and removed api txt artifacts for sdk builds.
distDir := proptools . StringPtr ( path . Join ( module . apiDistPath ( apiScope ) , "api" ) )
for _ , p := range [ ] struct {
tag string
pattern string
} {
2024-02-21 00:01:38 +01:00
// "exportable" api files are copied to the dist directory instead of the
// "everything" api files.
{ tag : ".exportable.api.txt" , pattern : "%s.txt" } ,
{ tag : ".exportable.removed-api.txt" , pattern : "%s-removed.txt" } ,
2020-11-23 18:41:36 +01:00
} {
props . Dists = append ( props . Dists , android . Dist {
Targets : [ ] string { "sdk" , "win_sdk" } ,
Dir : distDir ,
Dest : proptools . StringPtr ( fmt . Sprintf ( p . pattern , module . distStem ( ) ) ) ,
Tag : proptools . StringPtr ( p . tag ) ,
} )
}
2020-03-27 20:43:19 +01:00
}
2023-10-27 19:21:52 +02:00
mctx . CreateModule ( DroidstubsFactory , & props , module . sdkComponentPropertiesForChildLibrary ( ) ) . ( * Droidstubs ) . CallHookIfAvailable ( mctx )
2018-04-10 06:07:10 +02:00
}
2023-08-02 08:44:57 +02:00
func ( module * SdkLibrary ) createApiLibrary ( mctx android . DefaultableHookContext , apiScope * apiScope , alternativeFullApiSurfaceStub string ) {
2023-03-23 18:44:51 +01:00
props := struct {
2023-06-23 01:13:51 +02:00
Name * string
Visibility [ ] string
Api_contributions [ ] string
Libs [ ] string
Static_libs [ ] string
Full_api_surface_stub * string
2023-10-05 19:26:09 +02:00
System_modules * string
2023-06-28 03:16:23 +02:00
Enable_validation * bool
2023-03-23 18:44:51 +01:00
} { }
props . Name = proptools . StringPtr ( module . apiLibraryModuleName ( apiScope ) )
2023-09-07 03:18:31 +02:00
props . Visibility = [ ] string { "//visibility:override" , "//visibility:private" }
2023-03-23 18:44:51 +01:00
apiContributions := [ ] string { }
// Api surfaces are not independent of each other, but have subset relationships,
// and so does the api files. To generate from-text stubs for api surfaces other than public,
// all subset api domains' api_contriubtions must be added as well.
scope := apiScope
for scope != nil {
apiContributions = append ( apiContributions , module . stubsSourceModuleName ( scope ) + ".api.contribution" )
scope = scope . extends
}
2023-08-02 08:44:57 +02:00
if apiScope == apiScopePublic {
additionalApiContribution := module . apiLibraryAdditionalApiContribution ( )
if additionalApiContribution != "" {
apiContributions = append ( apiContributions , additionalApiContribution )
}
}
2023-03-23 18:44:51 +01:00
props . Api_contributions = apiContributions
props . Libs = module . properties . Libs
props . Libs = append ( props . Libs , module . sdkLibraryProperties . Stub_only_libs ... )
2023-08-10 02:07:03 +02:00
props . Libs = append ( props . Libs , module . scopeToProperties [ apiScope ] . Libs ... )
2023-03-23 18:44:51 +01:00
props . Libs = append ( props . Libs , "stub-annotations" )
props . Static_libs = module . sdkLibraryProperties . Stub_only_static_libs
2023-07-25 07:51:46 +02:00
props . Full_api_surface_stub = proptools . StringPtr ( apiScope . kind . DefaultJavaLibraryName ( ) )
2023-08-02 08:44:57 +02:00
if alternativeFullApiSurfaceStub != "" {
props . Full_api_surface_stub = proptools . StringPtr ( alternativeFullApiSurfaceStub )
}
2023-03-23 18:44:51 +01:00
// android_module_lib_stubs_current.from-text only comprises api contributions from art, conscrypt and i18n.
// Thus, replace with android_module_lib_stubs_current_full.from-text, which comprises every api domains.
if apiScope . kind == android . SdkModule {
2023-06-23 01:13:51 +02:00
props . Full_api_surface_stub = proptools . StringPtr ( apiScope . kind . DefaultJavaLibraryName ( ) + "_full.from-text" )
2023-03-23 18:44:51 +01:00
}
2023-10-09 20:00:17 +02:00
// java_sdk_library modules that set sdk_version as none does not depend on other api
// domains. Therefore, java_api_library created from such modules should not depend on
// full_api_surface_stubs but create and compile stubs by the java_api_library module
// itself.
if module . SdkVersion ( mctx ) . Kind == android . SdkNone {
props . Full_api_surface_stub = nil
}
2023-10-05 19:26:09 +02:00
props . System_modules = module . deviceProperties . System_modules
2023-06-28 03:16:23 +02:00
props . Enable_validation = proptools . BoolPtr ( true )
2023-10-05 19:26:09 +02:00
2023-10-27 19:21:52 +02:00
mctx . CreateModule ( ApiLibraryFactory , & props , module . sdkComponentPropertiesForChildLibrary ( ) )
2023-03-23 18:44:51 +01:00
}
2023-12-20 03:53:38 +01:00
func ( module * SdkLibrary ) topLevelStubsLibraryProps ( mctx android . DefaultableHookContext , apiScope * apiScope ) libraryProperties {
props := libraryProperties { }
2023-06-09 01:25:57 +02:00
props . Visibility = childModuleVisibility ( module . sdkLibraryProperties . Stubs_library_visibility )
sdkVersion := module . sdkVersionForStubsLibrary ( mctx , apiScope )
props . Sdk_version = proptools . StringPtr ( sdkVersion )
2023-12-20 03:53:38 +01:00
props . System_modules = module . deviceProperties . System_modules
// The imports need to be compiled to dex if the java_sdk_library requests it.
compileDex := module . dexProperties . Compile_dex
if module . stubLibrariesCompiledForDex ( ) {
compileDex = proptools . BoolPtr ( true )
}
props . Compile_dex = compileDex
return props
}
func ( module * SdkLibrary ) createTopLevelStubsLibrary (
mctx android . DefaultableHookContext , apiScope * apiScope , contributesToApiSurface bool ) {
props := module . topLevelStubsLibraryProps ( mctx , apiScope )
props . Name = proptools . StringPtr ( module . stubsLibraryModuleName ( apiScope ) )
2023-06-09 01:25:57 +02:00
// Add the stub compiling java_library/java_api_library as static lib based on build config
2023-12-20 03:53:38 +01:00
staticLib := module . sourceStubsLibraryModuleName ( apiScope )
2023-06-09 01:25:57 +02:00
if mctx . Config ( ) . BuildFromTextStub ( ) && contributesToApiSurface {
staticLib = module . apiLibraryModuleName ( apiScope )
}
props . Static_libs = append ( props . Static_libs , staticLib )
2023-12-20 03:53:38 +01:00
mctx . CreateModule ( LibraryFactory , & props , module . sdkComponentPropertiesForChildLibrary ( ) )
}
func ( module * SdkLibrary ) createTopLevelExportableStubsLibrary (
mctx android . DefaultableHookContext , apiScope * apiScope ) {
props := module . topLevelStubsLibraryProps ( mctx , apiScope )
props . Name = proptools . StringPtr ( module . exportableStubsLibraryModuleName ( apiScope ) )
2023-06-09 01:25:57 +02:00
// Dist the class jar artifact for sdk builds.
2023-12-20 03:53:38 +01:00
// "exportable" stubs are copied to dist for sdk builds instead of the "everything" stubs.
2023-06-09 01:25:57 +02:00
if ! Bool ( module . sdkLibraryProperties . No_dist ) {
props . Dist . Targets = [ ] string { "sdk" , "win_sdk" }
props . Dist . Dest = proptools . StringPtr ( fmt . Sprintf ( "%v.jar" , module . distStem ( ) ) )
props . Dist . Dir = proptools . StringPtr ( module . apiDistPath ( apiScope ) )
props . Dist . Tag = proptools . StringPtr ( ".jar" )
}
2023-12-20 03:53:38 +01:00
staticLib := module . exportableSourceStubsLibraryModuleName ( apiScope )
props . Static_libs = append ( props . Static_libs , staticLib )
2023-06-09 01:25:57 +02:00
mctx . CreateModule ( LibraryFactory , & props , module . sdkComponentPropertiesForChildLibrary ( ) )
}
2022-05-16 15:10:47 +02:00
func ( module * SdkLibrary ) compareAgainstLatestApi ( apiScope * apiScope ) bool {
return ! ( apiScope . unstable || module . sdkLibraryProperties . Unsafe_ignore_missing_latest_api )
}
2021-06-24 14:25:57 +02:00
// Implements android.ApexModule
2020-03-09 22:23:13 +01:00
func ( module * SdkLibrary ) DepIsInSameApex ( mctx android . BaseModuleContext , dep android . Module ) bool {
depTag := mctx . OtherModuleDependencyTag ( dep )
if depTag == xmlPermissionsFileTag {
return true
}
return module . Library . DepIsInSameApex ( mctx , dep )
}
2021-06-24 14:25:57 +02:00
// Implements android.ApexModule
func ( module * SdkLibrary ) UniqueApexVariations ( ) bool {
return module . uniqueApexVariations ( )
}
2023-11-15 20:22:14 +01:00
func ( module * SdkLibrary ) ContributeToApi ( ) bool {
return proptools . BoolDefault ( module . sdkLibraryProperties . Contribute_to_android_api , false )
}
2018-04-10 06:07:10 +02:00
// Creates the xml file that publicizes the runtime library
2020-04-29 17:47:28 +02:00
func ( module * SdkLibrary ) createXmlFile ( mctx android . DefaultableHookContext ) {
2023-03-03 22:20:36 +01:00
moduleMinApiLevel := module . Library . MinSdkVersion ( mctx )
2021-09-28 17:40:23 +02:00
var moduleMinApiLevelStr = moduleMinApiLevel . String ( )
if moduleMinApiLevel == android . NoneApiLevel {
moduleMinApiLevelStr = "current"
}
2020-02-17 09:28:10 +01:00
props := struct {
2021-09-28 17:40:23 +02:00
Name * string
Lib_name * string
Apex_available [ ] string
On_bootclasspath_since * string
On_bootclasspath_before * string
Min_device_sdk * string
Max_device_sdk * string
Sdk_library_min_api_level * string
Add the ability for a java_sdk_library to depend on another.
This simply exports all of the uses_libs: [] libraries into a
"dependency=''" statement in the generated XML file (with the <library>
stanza in it).
Test: `go test` in java/
Bug: 184396657
NOTE FOR REVIEWERS - original patch and result patch are not identical.
PLEASE REVIEW CAREFULLY.
Diffs between the patches:
func formattedDependenciesAttribute(dependencies []string) string {
> + if dependencies == nil {
> + return ""
> + }
> + return fmt.Sprintf(` dependency=\"%s\"\n`, strings.Join(dependencies, ":"))
> +}
> +
> + dependenciesAttr := formattedDependenciesAttribute(module.properties.Uses_libs_dependencies)
> + dependenciesAttr,
> --- java/sdk_library_test.go
> +++ java/sdk_library_test.go
> +
> +func TestSdkLibraryDependency(t *testing.T) {
> + result := android.GroupFixturePreparers(
> + prepareForJavaTest,
> + PrepareForTestWithJavaSdkLibraryFiles,
> + FixtureWithPrebuiltApis(map[string][]string{
> + "30": {"bar", "foo"},
> + }),
> + ).RunTestWithBp(t,
> + `
> + java_sdk_library {
> + name: "foo",
> + srcs: ["a.java", "b.java"],
> + api_packages: ["foo"],
> + }
> +
> + java_sdk_library {
> + name: "bar",
> + srcs: ["c.java", "b.java"],
> + libs: [
> + "foo",
> + ],
> + uses_libs: [
> + "foo",
> + ],
> + }
> +`)
> +
> + barPermissions := result.ModuleForTests("bar.xml", "android_common").Rule("java_sdk_xml")
> +
> + android.AssertStringDoesContain(t, "bar.xml java_sdk_xml command", barPermissions.RuleParams.Command, `dependency=\"foo\"`)
> +}
Original patch:
diff --git a/java/sdk_library.go b/java/sdk_library.go
old mode 100644
new mode 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared libra
[[[Original patch trimmed due to size. Decoded string size: 3559. Decoded string SHA1: 67fbd040aa818732a686514c4556850c8c36dc8d.]]]
Result patch:
diff --git a/java/sdk_library.go b/java/sdk_library.go
index fb27812..fbfe509 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared library
[[[Result patch trimmed due to size. Decoded string size: 3614. Decoded string SHA1: b5730ecbeeaad420439ddb67eaaa9150ede94585.]]]
Change-Id: I73f69e2a4573e416492f68e083fe739f3f75b721
2023-11-27 13:07:36 +01:00
Uses_libs_dependencies [ ] string
2020-02-17 09:28:10 +01:00
} {
2021-09-28 17:40:23 +02:00
Name : proptools . StringPtr ( module . xmlPermissionsModuleName ( ) ) ,
Lib_name : proptools . StringPtr ( module . BaseModuleName ( ) ) ,
Apex_available : module . ApexProperties . Apex_available ,
On_bootclasspath_since : module . commonSdkLibraryProperties . On_bootclasspath_since ,
On_bootclasspath_before : module . commonSdkLibraryProperties . On_bootclasspath_before ,
Min_device_sdk : module . commonSdkLibraryProperties . Min_device_sdk ,
Max_device_sdk : module . commonSdkLibraryProperties . Max_device_sdk ,
Sdk_library_min_api_level : & moduleMinApiLevelStr ,
Add the ability for a java_sdk_library to depend on another.
This simply exports all of the uses_libs: [] libraries into a
"dependency=''" statement in the generated XML file (with the <library>
stanza in it).
Test: `go test` in java/
Bug: 184396657
NOTE FOR REVIEWERS - original patch and result patch are not identical.
PLEASE REVIEW CAREFULLY.
Diffs between the patches:
func formattedDependenciesAttribute(dependencies []string) string {
> + if dependencies == nil {
> + return ""
> + }
> + return fmt.Sprintf(` dependency=\"%s\"\n`, strings.Join(dependencies, ":"))
> +}
> +
> + dependenciesAttr := formattedDependenciesAttribute(module.properties.Uses_libs_dependencies)
> + dependenciesAttr,
> --- java/sdk_library_test.go
> +++ java/sdk_library_test.go
> +
> +func TestSdkLibraryDependency(t *testing.T) {
> + result := android.GroupFixturePreparers(
> + prepareForJavaTest,
> + PrepareForTestWithJavaSdkLibraryFiles,
> + FixtureWithPrebuiltApis(map[string][]string{
> + "30": {"bar", "foo"},
> + }),
> + ).RunTestWithBp(t,
> + `
> + java_sdk_library {
> + name: "foo",
> + srcs: ["a.java", "b.java"],
> + api_packages: ["foo"],
> + }
> +
> + java_sdk_library {
> + name: "bar",
> + srcs: ["c.java", "b.java"],
> + libs: [
> + "foo",
> + ],
> + uses_libs: [
> + "foo",
> + ],
> + }
> +`)
> +
> + barPermissions := result.ModuleForTests("bar.xml", "android_common").Rule("java_sdk_xml")
> +
> + android.AssertStringDoesContain(t, "bar.xml java_sdk_xml command", barPermissions.RuleParams.Command, `dependency=\"foo\"`)
> +}
Original patch:
diff --git a/java/sdk_library.go b/java/sdk_library.go
old mode 100644
new mode 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared libra
[[[Original patch trimmed due to size. Decoded string size: 3559. Decoded string SHA1: 67fbd040aa818732a686514c4556850c8c36dc8d.]]]
Result patch:
diff --git a/java/sdk_library.go b/java/sdk_library.go
index fb27812..fbfe509 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared library
[[[Result patch trimmed due to size. Decoded string size: 3614. Decoded string SHA1: b5730ecbeeaad420439ddb67eaaa9150ede94585.]]]
Change-Id: I73f69e2a4573e416492f68e083fe739f3f75b721
2023-11-27 13:07:36 +01:00
Uses_libs_dependencies : module . usesLibraryProperties . Uses_libs ,
2020-02-17 09:28:10 +01:00
}
mctx . CreateModule ( sdkLibraryXmlFactory , & props )
2018-04-10 06:07:10 +02:00
}
2021-03-29 13:11:58 +02:00
func PrebuiltJars ( ctx android . BaseModuleContext , baseName string , s android . SdkSpec ) android . Paths {
2021-03-31 11:17:53 +02:00
var ver android . ApiLevel
2021-03-29 13:11:58 +02:00
var kind android . SdkKind
if s . UsePrebuilt ( ctx ) {
2021-03-31 11:17:53 +02:00
ver = s . ApiLevel
2021-03-29 13:11:58 +02:00
kind = s . Kind
2018-10-19 06:46:09 +02:00
} else {
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
// We don't have prebuilt SDK for the specific sdkVersion.
// Instead of breaking the build, fallback to use "system_current"
2021-03-31 11:17:53 +02:00
ver = android . FutureApiLevel
2021-03-29 13:11:58 +02:00
kind = android . SdkSystem
2018-10-19 06:46:09 +02:00
}
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
dir := filepath . Join ( "prebuilts" , "sdk" , ver . String ( ) , kind . String ( ) )
2020-01-21 17:31:05 +01:00
jar := filepath . Join ( dir , baseName + ".jar" )
2018-10-19 06:46:09 +02:00
jarPath := android . ExistentPathForSource ( ctx , jar )
2019-02-28 07:01:28 +01:00
if ! jarPath . Valid ( ) {
2020-01-07 18:34:44 +01:00
if ctx . Config ( ) . AllowMissingDependencies ( ) {
return android . Paths { android . PathForSource ( ctx , jar ) }
} else {
2021-03-29 13:11:58 +02:00
ctx . PropertyErrorf ( "sdk_library" , "invalid sdk version %q, %q does not exist" , s . Raw , jar )
2020-01-07 18:34:44 +01:00
}
2019-02-28 07:01:28 +01:00
return nil
}
2018-10-19 06:46:09 +02:00
return android . Paths { jarPath . Path ( ) }
}
Reland: Deduplicate APEX variants that would build identically
APEX variants that share the same SDK version and updatability
almost always use identical command line arguments to build but
with different intermediates directories. This causes unnecessary
build time and disk space for duplicated work.
Deduplicate APEX variants that would build identically. Create
aliases from the per-APEX variations to the new shared variations
so that the APEX modules can continue to depend on them via the
APEX name as the variation.
This has one significant change in behavior. Before this change,
if an APEX had two libraries in its direct dependencies and one
of those libraries depended on the other, and the second library
had stubs, then the first library would depend on the implementation
of the second library and not the stubs. After this change, if
the first library is also present in a second APEX but the second
library is not, then the common variant shared between the two
APEXes would use the stubs, not the implementation.
In a correctly configured set of build rules this change will
be irrelevant, because if the compilation worked for the second
APEX using stubs then it will work for the common variant using
stubs. However, if an incorrect change to the build rules is
made this could lead to confusing errors, as a previously-working
common variant could suddenly stop building when a module is added
to a new APEX without its dependencies that require implementation
APIs to compile.
This change reduces the number of modules in an AOSP arm64-userdebug
build by 3% (52242 to 50586), reduces the number of variants of the
libcutils module from 74 to 53, and reduces the number of variants
of the massive libart[d] modules from 44 to 32.
This relands I0529837476a253c32b3dfb98dcccf107427c742c with a fix
to always mark permissions XML files of java_sdk_library modules as
unique per apex since they contain the APEX filename, and a fix
to UpdateUniqueApexVariationsForDeps to check ApexInfo.InApexes
instead of DepIsInSameApex to check if two modules are in the same
apex to account for a module that depends on another in a way that
doesn't normally include the dependency in the APEX (e.g. a libs
property), but the dependency is directly included in the APEX.
Bug: 164216768
Test: go test ./build/soong/apex/...
Change-Id: I2ae170601f764e5b88d0be2e0e6adc84e3a4d9cc
2020-08-11 21:17:01 +02:00
// Check to see if the other module is within the same set of named APEXes as this module.
2020-05-26 14:21:35 +02:00
//
// If either this or the other module are on the platform then this will return
// false.
2020-09-16 03:30:11 +02:00
func withinSameApexesAs ( ctx android . BaseModuleContext , other android . Module ) bool {
2023-12-14 00:54:49 +01:00
apexInfo , _ := android . ModuleProvider ( ctx , android . ApexInfoProvider )
2023-12-13 22:47:44 +01:00
otherApexInfo , _ := android . OtherModuleProvider ( ctx , other , android . ApexInfoProvider )
2021-05-12 10:13:56 +02:00
return len ( otherApexInfo . InApexVariants ) > 0 && reflect . DeepEqual ( apexInfo . InApexVariants , otherApexInfo . InApexVariants )
2020-05-26 14:21:35 +02:00
}
2021-03-29 13:11:58 +02:00
func ( module * SdkLibrary ) sdkJars ( ctx android . BaseModuleContext , sdkVersion android . SdkSpec , headerJars bool ) android . Paths {
2020-05-27 17:19:53 +02:00
// If the client doesn't set sdk_version, but if this library prefers stubs over
// the impl library, let's provide the widest API surface possible. To do so,
// force override sdk_version to module_current so that the closest possible API
// surface could be found in selectHeaderJarsForSdkVersion
2021-03-29 13:11:58 +02:00
if module . defaultsToStubs ( ) && ! sdkVersion . Specified ( ) {
2021-04-02 01:45:46 +02:00
sdkVersion = android . SdkSpecFrom ( ctx , "module_current" )
2020-05-27 17:19:53 +02:00
}
2020-01-22 12:57:20 +01:00
2020-05-26 19:13:57 +02:00
// Only provide access to the implementation library if it is actually built.
if module . requiresRuntimeImplementationLibrary ( ) {
// Check any special cases for java_sdk_library.
//
// Only allow access to the implementation library in the following condition:
// * No sdk_version specified on the referencing module.
2020-05-26 14:21:35 +02:00
// * The referencing module is in the same apex as this.
2021-03-29 13:11:58 +02:00
if sdkVersion . Kind == android . SdkPrivate || withinSameApexesAs ( ctx , module ) {
2020-05-26 19:13:57 +02:00
if headerJars {
return module . HeaderJars ( )
} else {
return module . ImplementationJars ( )
}
2018-10-19 06:46:09 +02:00
}
2018-04-10 06:07:10 +02:00
}
2020-05-20 13:19:10 +02:00
2020-05-20 15:20:02 +02:00
return module . selectHeaderJarsForSdkVersion ( ctx , sdkVersion )
2018-04-10 06:07:10 +02:00
}
2020-01-22 12:57:20 +01:00
// to satisfy SdkLibraryDependency interface
2021-03-29 13:11:58 +02:00
func ( module * SdkLibrary ) SdkHeaderJars ( ctx android . BaseModuleContext , sdkVersion android . SdkSpec ) android . Paths {
2020-01-22 12:57:20 +01:00
return module . sdkJars ( ctx , sdkVersion , true /*headerJars*/ )
}
2018-07-13 09:16:44 +02:00
// to satisfy SdkLibraryDependency interface
2021-03-29 13:11:58 +02:00
func ( module * SdkLibrary ) SdkImplementationJars ( ctx android . BaseModuleContext , sdkVersion android . SdkSpec ) android . Paths {
2020-01-22 12:57:20 +01:00
return module . sdkJars ( ctx , sdkVersion , false /*headerJars*/ )
2018-07-13 09:16:44 +02:00
}
2019-02-04 20:22:08 +01:00
var javaSdkLibrariesKey = android . NewOnceKey ( "javaSdkLibraries" )
2018-04-23 14:41:26 +02:00
func javaSdkLibraries ( config android . Config ) * [ ] string {
2019-02-04 20:22:08 +01:00
return config . Once ( javaSdkLibrariesKey , func ( ) interface { } {
2018-04-23 14:41:26 +02:00
return & [ ] string { }
} ) . ( * [ ] string )
}
2019-12-30 18:23:46 +01:00
func ( module * SdkLibrary ) getApiDir ( ) string {
return proptools . StringDefault ( module . sdkLibraryProperties . Api_dir , "api" )
}
2018-04-10 06:07:10 +02:00
// For a java_sdk_library module, create internal modules for stubs, docs,
// runtime libs and xml file. If requested, the stubs and docs are created twice
// once for public API level and once for system API level
2020-04-29 17:47:28 +02:00
func ( module * SdkLibrary ) CreateInternalModules ( mctx android . DefaultableHookContext ) {
// If the module has been disabled then don't create any child modules.
if ! module . Enabled ( ) {
return
}
2020-05-16 19:54:24 +02:00
if len ( module . properties . Srcs ) == 0 {
2019-02-08 13:00:45 +01:00
mctx . PropertyErrorf ( "srcs" , "java_sdk_library must specify srcs" )
2019-12-18 07:34:32 +01:00
return
2019-02-08 13:00:45 +01:00
}
2018-04-10 06:07:10 +02:00
2019-12-30 18:20:10 +01:00
// If this builds against standard libraries (i.e. is not part of the core libraries)
2020-11-19 15:53:43 +01:00
// then assume it provides both system and test apis.
2021-03-29 13:11:58 +02:00
sdkDep := decodeSdkDep ( mctx , android . SdkContext ( & module . Library ) )
2019-12-30 18:20:10 +01:00
hasSystemAndTestApis := sdkDep . hasStandardLibs ( )
2020-04-28 11:44:03 +02:00
module . sdkLibraryProperties . Generate_system_and_test_apis = hasSystemAndTestApis
2020-11-19 15:53:43 +01:00
2020-12-21 18:11:10 +01:00
missingCurrentApi := false
2019-03-18 02:19:51 +01:00
2020-04-28 11:44:03 +02:00
generatedScopes := module . getGeneratedApiScopes ( mctx )
2020-01-22 12:57:20 +01:00
2019-12-30 18:23:46 +01:00
apiDir := module . getApiDir ( )
2020-04-28 11:44:03 +02:00
for _ , scope := range generatedScopes {
2019-03-18 02:19:51 +01:00
for _ , api := range [ ] string { "current.txt" , "removed.txt" } {
2020-01-22 12:57:20 +01:00
path := path . Join ( mctx . ModuleDir ( ) , apiDir , scope . apiFilePrefix + api )
2019-03-18 02:19:51 +01:00
p := android . ExistentPathForSource ( mctx , path )
if ! p . Valid ( ) {
2021-05-21 02:56:54 +02:00
if mctx . Config ( ) . AllowMissingDependencies ( ) {
mctx . AddMissingDependencies ( [ ] string { path } )
} else {
mctx . ModuleErrorf ( "Current api file %#v doesn't exist" , path )
missingCurrentApi = true
}
2019-03-18 02:19:51 +01:00
}
}
}
2020-12-21 18:11:10 +01:00
if missingCurrentApi {
2019-03-18 02:19:51 +01:00
script := "build/soong/scripts/gen-java-current-api-files.sh"
p := android . ExistentPathForSource ( mctx , script )
if ! p . Valid ( ) {
panic ( fmt . Sprintf ( "script file %s doesn't exist" , script ) )
}
mctx . ModuleErrorf ( "One or more current api files are missing. " +
"You can update them by:\n" +
2019-12-30 18:20:10 +01:00
"%s %q %s && m update-api" ,
2020-01-22 12:57:20 +01:00
script , filepath . Join ( mctx . ModuleDir ( ) , apiDir ) ,
2020-04-28 11:44:03 +02:00
strings . Join ( generatedScopes . Strings ( func ( s * apiScope ) string { return s . apiFilePrefix } ) , " " ) )
2019-03-18 02:19:51 +01:00
return
}
2020-04-28 11:44:03 +02:00
for _ , scope := range generatedScopes {
2020-07-20 19:04:44 +02:00
// Use the stubs source name for legacy reasons.
module . createStubsSourcesAndApi ( mctx , scope , module . stubsSourceModuleName ( scope ) , scope . droidstubsArgs )
2020-04-29 14:30:54 +02:00
2020-01-22 12:57:20 +01:00
module . createStubsLibrary ( mctx , scope )
2023-12-20 03:53:38 +01:00
module . createExportableStubsLibrary ( mctx , scope )
2023-03-23 18:44:51 +01:00
2023-08-02 08:44:57 +02:00
alternativeFullApiSurfaceStubLib := ""
if scope == apiScopePublic {
alternativeFullApiSurfaceStubLib = module . alternativeFullApiSurfaceStubLib ( )
}
contributesToApiSurface := module . contributesToApiSurface ( mctx . Config ( ) ) || alternativeFullApiSurfaceStubLib != ""
2023-06-09 01:25:57 +02:00
if contributesToApiSurface {
2023-08-02 08:44:57 +02:00
module . createApiLibrary ( mctx , scope , alternativeFullApiSurfaceStubLib )
2023-03-23 18:44:51 +01:00
}
2023-06-09 01:25:57 +02:00
module . createTopLevelStubsLibrary ( mctx , scope , contributesToApiSurface )
2023-12-20 03:53:38 +01:00
module . createTopLevelExportableStubsLibrary ( mctx , scope )
2019-12-30 18:35:49 +01:00
}
2018-04-23 14:41:26 +02:00
2020-05-15 21:37:11 +02:00
if module . requiresRuntimeImplementationLibrary ( ) {
2020-05-16 16:52:12 +02:00
// Create child module to create an implementation library.
//
// This temporarily creates a second implementation library that can be explicitly
// referenced.
//
// TODO(b/156618935) - update comment once only one implementation library is created.
module . createImplLibrary ( mctx )
2020-05-15 21:37:11 +02:00
// Only create an XML permissions file that declares the library as being usable
// as a shared library if required.
if module . sharedLibrary ( ) {
module . createXmlFile ( mctx )
}
2019-02-08 13:00:45 +01:00
2019-12-30 18:35:49 +01:00
// record java_sdk_library modules so that they are exported to make
javaSdkLibraries := javaSdkLibraries ( mctx . Config ( ) )
javaSdkLibrariesLock . Lock ( )
defer javaSdkLibrariesLock . Unlock ( )
* javaSdkLibraries = append ( * javaSdkLibraries , module . BaseModuleName ( ) )
}
2020-10-08 15:47:23 +02:00
2022-04-28 16:13:30 +02:00
// Add the impl_only_libs and impl_only_static_libs *after* we're done using them in submodules.
2020-10-08 15:47:23 +02:00
module . properties . Libs = append ( module . properties . Libs , module . sdkLibraryProperties . Impl_only_libs ... )
2022-04-28 16:13:30 +02:00
module . properties . Static_libs = append ( module . properties . Static_libs , module . sdkLibraryProperties . Impl_only_static_libs ... )
2018-04-10 06:07:10 +02:00
}
2019-02-08 13:00:45 +01:00
func ( module * SdkLibrary ) InitSdkLibraryProperties ( ) {
2020-06-16 01:09:53 +02:00
module . addHostAndDeviceProperties ( )
module . AddProperties ( & module . sdkLibraryProperties )
2018-10-19 06:46:09 +02:00
2021-06-23 12:39:47 +02:00
module . initSdkLibraryComponent ( module )
2020-05-15 11:20:31 +02:00
2020-05-16 19:54:24 +02:00
module . properties . Installable = proptools . BoolPtr ( true )
module . deviceProperties . IsSDKLibrary = true
2019-02-08 13:00:45 +01:00
}
2018-10-19 06:46:09 +02:00
2020-05-15 21:37:11 +02:00
func ( module * SdkLibrary ) requiresRuntimeImplementationLibrary ( ) bool {
return ! proptools . Bool ( module . sdkLibraryProperties . Api_only )
}
2020-05-27 17:19:53 +02:00
func ( module * SdkLibrary ) defaultsToStubs ( ) bool {
return proptools . Bool ( module . sdkLibraryProperties . Default_to_stubs )
}
2020-05-08 14:44:43 +02:00
// Defines how to name the individual component modules the sdk library creates.
type sdkLibraryComponentNamingScheme interface {
stubsLibraryModuleName ( scope * apiScope , baseName string ) string
stubsSourceModuleName ( scope * apiScope , baseName string ) string
2023-03-23 18:44:51 +01:00
apiLibraryModuleName ( scope * apiScope , baseName string ) string
2023-06-09 01:25:57 +02:00
2023-12-20 03:53:38 +01:00
sourceStubsLibraryModuleName ( scope * apiScope , baseName string ) string
exportableStubsLibraryModuleName ( scope * apiScope , baseName string ) string
exportableSourceStubsLibraryModuleName ( scope * apiScope , baseName string ) string
2020-05-08 14:44:43 +02:00
}
type defaultNamingScheme struct {
}
func ( s * defaultNamingScheme ) stubsLibraryModuleName ( scope * apiScope , baseName string ) string {
return scope . stubsLibraryModuleName ( baseName )
}
func ( s * defaultNamingScheme ) stubsSourceModuleName ( scope * apiScope , baseName string ) string {
return scope . stubsSourceModuleName ( baseName )
}
2023-03-23 18:44:51 +01:00
func ( s * defaultNamingScheme ) apiLibraryModuleName ( scope * apiScope , baseName string ) string {
return scope . apiLibraryModuleName ( baseName )
}
2023-12-20 03:53:38 +01:00
func ( s * defaultNamingScheme ) sourceStubsLibraryModuleName ( scope * apiScope , baseName string ) string {
2023-06-09 01:25:57 +02:00
return scope . sourceStubLibraryModuleName ( baseName )
}
2023-12-20 03:53:38 +01:00
func ( s * defaultNamingScheme ) exportableStubsLibraryModuleName ( scope * apiScope , baseName string ) string {
return scope . exportableStubsLibraryModuleName ( baseName )
}
func ( s * defaultNamingScheme ) exportableSourceStubsLibraryModuleName ( scope * apiScope , baseName string ) string {
return scope . exportableSourceStubsLibraryModuleName ( baseName )
}
2020-05-08 14:44:43 +02:00
var _ sdkLibraryComponentNamingScheme = ( * defaultNamingScheme ) ( nil )
2020-05-08 16:36:30 +02:00
2023-12-20 03:53:38 +01:00
func hasStubsLibrarySuffix ( name string , apiScope * apiScope ) bool {
return strings . HasSuffix ( name , apiScope . stubsLibraryModuleNameSuffix ( ) ) ||
strings . HasSuffix ( name , apiScope . exportableStubsLibraryModuleNameSuffix ( ) )
}
2021-03-11 02:02:43 +01:00
func moduleStubLinkType ( name string ) ( stub bool , ret sdkLinkType ) {
2023-06-09 01:25:57 +02:00
name = strings . TrimSuffix ( name , ".from-source" )
2020-05-25 13:20:51 +02:00
// This suffix-based approach is fragile and could potentially mis-trigger.
// TODO(b/155164730): Clean this up when modules no longer reference sdk_lib stubs directly.
2023-12-20 03:53:38 +01:00
if hasStubsLibrarySuffix ( name , apiScopePublic ) {
2021-04-07 16:32:19 +02:00
if name == "hwbinder.stubs" || name == "libcore_private.stubs" {
// Due to a previous bug, these modules were not considered stubs, so we retain that.
return false , javaPlatform
}
2020-05-25 13:20:51 +02:00
return true , javaSdk
}
2023-12-20 03:53:38 +01:00
if hasStubsLibrarySuffix ( name , apiScopeSystem ) {
2020-05-25 13:20:51 +02:00
return true , javaSystem
}
2023-12-20 03:53:38 +01:00
if hasStubsLibrarySuffix ( name , apiScopeModuleLib ) {
2020-05-25 13:20:51 +02:00
return true , javaModule
}
2023-12-20 03:53:38 +01:00
if hasStubsLibrarySuffix ( name , apiScopeTest ) {
2020-05-25 13:20:51 +02:00
return true , javaSystem
}
2023-12-20 03:53:38 +01:00
if hasStubsLibrarySuffix ( name , apiScopeSystemServer ) {
2023-06-09 01:25:57 +02:00
return true , javaSystemServer
}
2020-05-25 13:20:51 +02:00
return false , javaPlatform
}
2019-07-11 19:05:35 +02:00
// java_sdk_library is a special Java library that provides optional platform APIs to apps.
// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
// are linked against to, 2) droiddoc module that internally generates API stubs source files,
// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
// the runtime lib to the classpath at runtime if requested via <uses-library>.
2019-02-08 13:00:45 +01:00
func SdkLibraryFactory ( ) android . Module {
module := & SdkLibrary { }
2020-05-08 15:16:20 +02:00
// Initialize information common between source and prebuilt.
2021-06-23 12:39:47 +02:00
module . initCommon ( module )
2020-05-08 15:16:20 +02:00
2019-02-08 13:00:45 +01:00
module . InitSdkLibraryProperties ( )
2019-12-18 07:34:32 +01:00
android . InitApexModule ( module )
2018-10-19 06:46:09 +02:00
InitJavaModule ( module , android . HostAndDeviceSupported )
2020-04-28 11:44:03 +02:00
// Initialize the map from scope to scope specific properties.
scopeToProperties := make ( map [ * apiScope ] * ApiScopeProperties )
for _ , scope := range allApiScopes {
scopeToProperties [ scope ] = scope . scopeSpecificProperties ( module )
}
module . scopeToProperties = scopeToProperties
2020-04-30 00:35:13 +02:00
// Add the properties containing visibility rules so that they are checked.
2020-05-16 16:52:12 +02:00
android . AddVisibilityProperty ( module , "impl_library_visibility" , & module . sdkLibraryProperties . Impl_library_visibility )
2020-04-30 00:35:13 +02:00
android . AddVisibilityProperty ( module , "stubs_library_visibility" , & module . sdkLibraryProperties . Stubs_library_visibility )
android . AddVisibilityProperty ( module , "stubs_source_visibility" , & module . sdkLibraryProperties . Stubs_source_visibility )
2020-05-08 14:44:43 +02:00
module . SetDefaultableHook ( func ( ctx android . DefaultableHookContext ) {
2020-05-15 21:37:11 +02:00
// If no implementation is required then it cannot be used as a shared library
// either.
if ! module . requiresRuntimeImplementationLibrary ( ) {
// If shared_library has been explicitly set to true then it is incompatible
// with api_only: true.
if proptools . Bool ( module . commonSdkLibraryProperties . Shared_library ) {
ctx . PropertyErrorf ( "api_only/shared_library" , "inconsistent settings, shared_library and api_only cannot both be true" )
}
// Set shared_library: false.
module . commonSdkLibraryProperties . Shared_library = proptools . BoolPtr ( false )
}
2020-05-08 14:44:43 +02:00
if module . initCommonAfterDefaultsApplied ( ctx ) {
module . CreateInternalModules ( ctx )
}
} )
2018-04-10 06:07:10 +02:00
return module
}
2019-04-17 20:11:46 +02:00
//
// SDK library prebuilts
//
2020-01-31 14:36:25 +01:00
// Properties associated with each api scope.
type sdkLibraryScopeProperties struct {
2019-04-17 20:11:46 +02:00
Jars [ ] string ` android:"path" `
Sdk_version * string
// List of shared java libs that this module has dependencies to
Libs [ ] string
2020-04-09 01:10:17 +02:00
2020-04-29 21:45:27 +02:00
// The stubs source.
2020-04-09 01:10:17 +02:00
Stub_srcs [ ] string ` android:"path" `
2020-04-09 02:08:11 +02:00
// The current.txt
2020-05-20 17:18:00 +02:00
Current_api * string ` android:"path" `
2020-04-09 02:08:11 +02:00
// The removed.txt
2020-05-20 17:18:00 +02:00
Removed_api * string ` android:"path" `
2021-09-21 16:25:12 +02:00
// Annotation zip
Annotations * string ` android:"path" `
2019-04-17 20:11:46 +02:00
}
2020-01-31 14:36:25 +01:00
type sdkLibraryImportProperties struct {
2020-01-31 18:54:30 +01:00
// List of shared java libs, common to all scopes, that this module has
// dependencies to
Libs [ ] string
2021-04-16 18:21:36 +02:00
// If set to true, compile dex files for the stubs. Defaults to false.
Compile_dex * bool
2021-07-15 15:14:41 +02:00
// If not empty, classes are restricted to the specified packages and their sub-packages.
Permitted_packages [ ] string
2024-01-19 01:22:22 +01:00
// Name of the source soong module that gets shadowed by this prebuilt
// If unspecified, follows the naming convention that the source module of
// the prebuilt is Name() without "prebuilt_" prefix
Source_module_name * string
2020-01-31 14:36:25 +01:00
}
2020-06-12 18:46:39 +02:00
type SdkLibraryImport struct {
2019-04-17 20:11:46 +02:00
android . ModuleBase
android . DefaultableModuleBase
prebuilt android . Prebuilt
2020-02-10 14:37:10 +01:00
android . ApexModuleBase
2019-04-17 20:11:46 +02:00
2021-02-26 15:24:15 +01:00
hiddenAPI
2021-09-09 10:12:46 +02:00
dexpreopter
2021-02-26 15:24:15 +01:00
2019-04-17 20:11:46 +02:00
properties sdkLibraryImportProperties
2020-04-07 20:27:04 +02:00
// Map from api scope to the scope specific property structure.
scopeProperties map [ * apiScope ] * sdkLibraryScopeProperties
2020-01-31 14:36:25 +01:00
commonToSdkLibraryAndImport
2020-06-12 18:46:39 +02:00
// The reference to the implementation library created by the source module.
// Is nil if the source module does not exist.
implLibraryModule * Library
// The reference to the xml permissions module created by the source module.
// Is nil if the source module does not exist.
xmlPermissionsFileModule * sdkLibraryXml
2021-02-26 12:09:39 +01:00
2021-07-07 18:13:11 +02:00
// Build path to the dex implementation jar obtained from the prebuilt_apex, if any.
2023-12-13 00:23:53 +01:00
dexJarFile OptionalDexJarPath
dexJarFileErr error
2021-07-07 18:13:11 +02:00
// Expected install file path of the source module(sdk_library)
// or dex implementation jar obtained from the prebuilt_apex, if any.
installFile android . Path
2019-04-17 20:11:46 +02:00
}
2020-06-12 18:46:39 +02:00
var _ SdkLibraryDependency = ( * SdkLibraryImport ) ( nil )
2019-04-17 20:11:46 +02:00
2020-04-07 20:27:04 +02:00
// The type of a structure that contains a field of type sdkLibraryScopeProperties
// for each apiscope in allApiScopes, e.g. something like:
2022-08-16 19:27:33 +02:00
//
// struct {
// Public sdkLibraryScopeProperties
// System sdkLibraryScopeProperties
// ...
// }
2020-04-07 20:27:04 +02:00
var allScopeStructType = createAllScopePropertiesStructType ( )
// Dynamically create a structure type for each apiscope in allApiScopes.
func createAllScopePropertiesStructType ( ) reflect . Type {
var fields [ ] reflect . StructField
for _ , apiScope := range allApiScopes {
field := reflect . StructField {
Name : apiScope . fieldName ,
Type : reflect . TypeOf ( sdkLibraryScopeProperties { } ) ,
}
fields = append ( fields , field )
}
return reflect . StructOf ( fields )
}
// Create an instance of the scope specific structure type and return a map
// from apiscope to a pointer to each scope specific field.
func createPropertiesInstance ( ) ( interface { } , map [ * apiScope ] * sdkLibraryScopeProperties ) {
allScopePropertiesPtr := reflect . New ( allScopeStructType )
allScopePropertiesStruct := allScopePropertiesPtr . Elem ( )
scopeProperties := make ( map [ * apiScope ] * sdkLibraryScopeProperties )
for _ , apiScope := range allApiScopes {
field := allScopePropertiesStruct . FieldByName ( apiScope . fieldName )
scopeProperties [ apiScope ] = field . Addr ( ) . Interface ( ) . ( * sdkLibraryScopeProperties )
}
return allScopePropertiesPtr . Interface ( ) , scopeProperties
}
2019-07-11 19:05:35 +02:00
// java_sdk_library_import imports a prebuilt java_sdk_library.
2019-04-17 20:11:46 +02:00
func sdkLibraryImportFactory ( ) android . Module {
2020-06-12 18:46:39 +02:00
module := & SdkLibraryImport { }
2019-04-17 20:11:46 +02:00
2020-04-07 20:27:04 +02:00
allScopeProperties , scopeToProperties := createPropertiesInstance ( )
module . scopeProperties = scopeToProperties
2023-02-08 17:09:24 +01:00
module . AddProperties ( & module . properties , allScopeProperties , & module . importDexpreoptProperties )
2019-04-17 20:11:46 +02:00
2020-05-08 15:16:20 +02:00
// Initialize information common between source and prebuilt.
2021-06-23 12:39:47 +02:00
module . initCommon ( module )
2020-05-08 15:16:20 +02:00
2020-02-06 16:24:57 +01:00
android . InitPrebuiltModule ( module , & [ ] string { "" } )
2020-02-10 14:37:10 +01:00
android . InitApexModule ( module )
2019-04-17 20:11:46 +02:00
InitJavaModule ( module , android . HostAndDeviceSupported )
2020-05-08 14:44:43 +02:00
module . SetDefaultableHook ( func ( mctx android . DefaultableHookContext ) {
if module . initCommonAfterDefaultsApplied ( mctx ) {
module . createInternalModules ( mctx )
}
} )
2019-04-17 20:11:46 +02:00
return module
}
2021-07-15 14:35:26 +02:00
var _ PermittedPackagesForUpdatableBootJars = ( * SdkLibraryImport ) ( nil )
func ( module * SdkLibraryImport ) PermittedPackagesForUpdatableBootJars ( ) [ ] string {
return module . properties . Permitted_packages
}
2020-06-12 18:46:39 +02:00
func ( module * SdkLibraryImport ) Prebuilt ( ) * android . Prebuilt {
2019-04-17 20:11:46 +02:00
return & module . prebuilt
}
2020-06-12 18:46:39 +02:00
func ( module * SdkLibraryImport ) Name ( ) string {
2019-04-17 20:11:46 +02:00
return module . prebuilt . Name ( module . ModuleBase . Name ( ) )
}
2024-01-19 01:22:22 +01:00
func ( module * SdkLibraryImport ) BaseModuleName ( ) string {
return proptools . StringDefault ( module . properties . Source_module_name , module . ModuleBase . Name ( ) )
}
2020-06-12 18:46:39 +02:00
func ( module * SdkLibraryImport ) createInternalModules ( mctx android . DefaultableHookContext ) {
2019-04-17 20:11:46 +02:00
2020-01-21 17:31:05 +01:00
// If the build is configured to use prebuilts then force this to be preferred.
2020-07-07 18:09:23 +02:00
if mctx . Config ( ) . AlwaysUsePrebuiltSdks ( ) {
2020-01-21 17:31:05 +01:00
module . prebuilt . ForcePrefer ( )
}
2020-04-07 20:27:04 +02:00
for apiScope , scopeProperties := range module . scopeProperties {
2020-01-31 14:36:25 +01:00
if len ( scopeProperties . Jars ) == 0 {
continue
}
2020-04-09 01:07:11 +02:00
module . createJavaImportForStubs ( mctx , apiScope , scopeProperties )
2020-04-09 01:10:17 +02:00
2020-05-20 17:18:00 +02:00
if len ( scopeProperties . Stub_srcs ) > 0 {
module . createPrebuiltStubsSources ( mctx , apiScope , scopeProperties )
}
2023-09-13 03:01:53 +02:00
if scopeProperties . Current_api != nil {
module . createPrebuiltApiContribution ( mctx , apiScope , scopeProperties )
}
2020-01-31 14:36:25 +01:00
}
2019-04-17 20:11:46 +02:00
javaSdkLibraries := javaSdkLibraries ( mctx . Config ( ) )
javaSdkLibrariesLock . Lock ( )
defer javaSdkLibrariesLock . Unlock ( )
* javaSdkLibraries = append ( * javaSdkLibraries , module . BaseModuleName ( ) )
}
2020-06-12 18:46:39 +02:00
func ( module * SdkLibraryImport ) createJavaImportForStubs ( mctx android . DefaultableHookContext , apiScope * apiScope , scopeProperties * sdkLibraryScopeProperties ) {
2020-04-09 01:07:11 +02:00
// Creates a java import for the jar with ".stubs" suffix
props := struct {
2024-01-19 01:22:22 +01:00
Name * string
Source_module_name * string
Created_by_java_sdk_library_name * string
Sdk_version * string
Libs [ ] string
Jars [ ] string
Compile_dex * bool
2024-02-12 23:49:21 +01:00
Is_stubs_module * bool
2022-09-27 13:41:52 +02:00
android . UserSuppliedPrebuiltProperties
2020-04-09 01:07:11 +02:00
} { }
2020-05-08 15:16:20 +02:00
props . Name = proptools . StringPtr ( module . stubsLibraryModuleName ( apiScope ) )
2024-01-19 01:22:22 +01:00
props . Source_module_name = proptools . StringPtr ( apiScope . stubsLibraryModuleName ( module . BaseModuleName ( ) ) )
props . Created_by_java_sdk_library_name = proptools . StringPtr ( module . RootLibraryName ( ) )
2020-04-09 01:07:11 +02:00
props . Sdk_version = scopeProperties . Sdk_version
// Prepend any of the libs from the legacy public properties to the libs for each of the
// scopes to avoid having to duplicate them in each scope.
props . Libs = append ( module . properties . Libs , scopeProperties . Libs ... )
props . Jars = scopeProperties . Jars
2020-05-16 10:57:59 +02:00
2020-05-13 17:08:09 +02:00
// The imports are preferred if the java_sdk_library_import is preferred.
2022-09-27 13:41:52 +02:00
props . CopyUserSuppliedPropertiesFromPrebuilt ( & module . prebuilt )
2020-05-15 11:20:31 +02:00
2021-04-16 18:21:36 +02:00
// The imports need to be compiled to dex if the java_sdk_library_import requests it.
2021-05-13 23:34:45 +02:00
compileDex := module . properties . Compile_dex
if module . stubLibrariesCompiledForDex ( ) {
compileDex = proptools . BoolPtr ( true )
}
props . Compile_dex = compileDex
2024-02-12 23:49:21 +01:00
props . Is_stubs_module = proptools . BoolPtr ( true )
2021-04-16 18:21:36 +02:00
2020-05-15 11:20:31 +02:00
mctx . CreateModule ( ImportFactory , & props , module . sdkComponentPropertiesForChildLibrary ( ) )
2020-04-09 01:07:11 +02:00
}
2020-06-12 18:46:39 +02:00
func ( module * SdkLibraryImport ) createPrebuiltStubsSources ( mctx android . DefaultableHookContext , apiScope * apiScope , scopeProperties * sdkLibraryScopeProperties ) {
2020-04-09 01:10:17 +02:00
props := struct {
2024-01-19 01:22:22 +01:00
Name * string
Source_module_name * string
Created_by_java_sdk_library_name * string
Srcs [ ] string
2022-09-27 13:41:52 +02:00
android . UserSuppliedPrebuiltProperties
2020-04-09 01:10:17 +02:00
} { }
2020-05-08 15:16:20 +02:00
props . Name = proptools . StringPtr ( module . stubsSourceModuleName ( apiScope ) )
2024-01-19 01:22:22 +01:00
props . Source_module_name = proptools . StringPtr ( apiScope . stubsSourceModuleName ( module . BaseModuleName ( ) ) )
props . Created_by_java_sdk_library_name = proptools . StringPtr ( module . RootLibraryName ( ) )
2020-04-09 01:10:17 +02:00
props . Srcs = scopeProperties . Stub_srcs
2020-05-13 17:08:09 +02:00
// The stubs source is preferred if the java_sdk_library_import is preferred.
2022-09-27 13:41:52 +02:00
props . CopyUserSuppliedPropertiesFromPrebuilt ( & module . prebuilt )
2023-10-27 19:21:52 +02:00
mctx . CreateModule ( PrebuiltStubsSourcesFactory , & props , module . sdkComponentPropertiesForChildLibrary ( ) )
2020-04-09 01:10:17 +02:00
}
2023-09-13 03:01:53 +02:00
func ( module * SdkLibraryImport ) createPrebuiltApiContribution ( mctx android . DefaultableHookContext , apiScope * apiScope , scopeProperties * sdkLibraryScopeProperties ) {
api_file := scopeProperties . Current_api
api_surface := & apiScope . name
props := struct {
2024-01-19 01:22:22 +01:00
Name * string
Source_module_name * string
Created_by_java_sdk_library_name * string
Api_surface * string
Api_file * string
Visibility [ ] string
2023-09-13 03:01:53 +02:00
} { }
props . Name = proptools . StringPtr ( module . stubsSourceModuleName ( apiScope ) + ".api.contribution" )
2024-01-19 01:22:22 +01:00
props . Source_module_name = proptools . StringPtr ( apiScope . stubsSourceModuleName ( module . BaseModuleName ( ) ) + ".api.contribution" )
props . Created_by_java_sdk_library_name = proptools . StringPtr ( module . RootLibraryName ( ) )
2023-09-13 03:01:53 +02:00
props . Api_surface = api_surface
props . Api_file = api_file
props . Visibility = [ ] string { "//visibility:override" , "//visibility:public" }
2023-10-27 19:21:52 +02:00
mctx . CreateModule ( ApiContributionImportFactory , & props , module . sdkComponentPropertiesForChildLibrary ( ) )
2023-09-13 03:01:53 +02:00
}
2020-06-26 21:17:02 +02:00
// Add the dependencies on the child module in the component deps mutator so that it
// creates references to the prebuilt and not the source modules.
func ( module * SdkLibraryImport ) ComponentDepsMutator ( ctx android . BottomUpMutatorContext ) {
2020-04-07 20:27:04 +02:00
for apiScope , scopeProperties := range module . scopeProperties {
2020-01-31 14:36:25 +01:00
if len ( scopeProperties . Jars ) == 0 {
continue
}
// Add dependencies to the prebuilt stubs library
2024-01-22 20:40:08 +01:00
ctx . AddVariationDependencies ( nil , apiScope . prebuiltStubsTag , android . PrebuiltNameFromSource ( module . stubsLibraryModuleName ( apiScope ) ) )
2020-05-20 17:18:00 +02:00
if len ( scopeProperties . Stub_srcs ) > 0 {
// Add dependencies to the prebuilt stubs source library
2021-04-02 11:24:13 +02:00
ctx . AddVariationDependencies ( nil , apiScope . stubsSourceTag , android . PrebuiltNameFromSource ( module . stubsSourceModuleName ( apiScope ) ) )
2020-05-20 17:18:00 +02:00
}
2020-01-31 14:36:25 +01:00
}
2020-06-26 21:17:02 +02:00
}
// Add other dependencies as normal.
func ( module * SdkLibraryImport ) DepsMutator ( ctx android . BottomUpMutatorContext ) {
2020-06-12 18:46:39 +02:00
implName := module . implLibraryModuleName ( )
if ctx . OtherModuleExists ( implName ) {
ctx . AddVariationDependencies ( nil , implLibraryTag , implName )
xmlPermissionsModuleName := module . xmlPermissionsModuleName ( )
if module . sharedLibrary ( ) && ctx . OtherModuleExists ( xmlPermissionsModuleName ) {
// Add dependency to the rule for generating the xml permissions file
ctx . AddDependency ( module , xmlPermissionsFileTag , xmlPermissionsModuleName )
}
}
2019-04-17 20:11:46 +02:00
}
2020-12-15 14:29:02 +01:00
var _ android . ApexModule = ( * SdkLibraryImport ) ( nil )
// Implements android.ApexModule
2020-06-12 18:46:39 +02:00
func ( module * SdkLibraryImport ) DepIsInSameApex ( mctx android . BaseModuleContext , dep android . Module ) bool {
depTag := mctx . OtherModuleDependencyTag ( dep )
if depTag == xmlPermissionsFileTag {
return true
}
// None of the other dependencies of the java_sdk_library_import are in the same apex
// as the one that references this module.
return false
}
2020-12-15 14:29:02 +01:00
// Implements android.ApexModule
2020-07-23 07:32:17 +02:00
func ( module * SdkLibraryImport ) ShouldSupportSdkVersion ( ctx android . BaseModuleContext ,
sdkVersion android . ApiLevel ) error {
2020-04-15 04:03:39 +02:00
// we don't check prebuilt modules for sdk_version
return nil
}
2021-06-24 14:25:57 +02:00
// Implements android.ApexModule
func ( module * SdkLibraryImport ) UniqueApexVariations ( ) bool {
return module . uniqueApexVariations ( )
}
2022-04-28 18:45:11 +02:00
// MinSdkVersion - Implements hiddenAPIModule
2023-03-03 22:20:36 +01:00
func ( module * SdkLibraryImport ) MinSdkVersion ( ctx android . EarlyModuleContext ) android . ApiLevel {
return android . NoneApiLevel
2022-04-28 18:45:11 +02:00
}
var _ hiddenAPIModule = ( * SdkLibraryImport ) ( nil )
2020-06-12 18:46:39 +02:00
func ( module * SdkLibraryImport ) OutputFiles ( tag string ) ( android . Paths , error ) {
2022-04-29 15:21:25 +02:00
paths , err := module . commonOutputFiles ( tag )
if paths != nil || err != nil {
return paths , err
}
if module . implLibraryModule != nil {
return module . implLibraryModule . OutputFiles ( tag )
} else {
return nil , nil
}
2020-05-14 16:39:10 +02:00
}
2020-06-12 18:46:39 +02:00
func ( module * SdkLibraryImport ) GenerateAndroidBuildActions ( ctx android . ModuleContext ) {
2020-09-11 12:55:00 +02:00
module . generateCommonBuildActions ( ctx )
2021-07-07 18:13:11 +02:00
// Assume that source module(sdk_library) is installed in /<sdk_library partition>/framework
module . installFile = android . PathForModuleInstall ( ctx , "framework" , module . Stem ( ) + ".jar" )
2020-05-20 17:18:00 +02:00
// Record the paths to the prebuilt stubs library and stubs source.
2019-04-17 20:11:46 +02:00
ctx . VisitDirectDeps ( func ( to android . Module ) {
tag := ctx . OtherModuleDependencyTag ( to )
2020-05-20 17:18:00 +02:00
// Extract information from any of the scope specific dependencies.
if scopeTag , ok := tag . ( scopeDependencyTag ) ; ok {
apiScope := scopeTag . apiScope
scopePaths := module . getScopePathsCreateIfNeeded ( apiScope )
// Extract information from the dependency. The exact information extracted
// is determined by the nature of the dependency which is determined by the tag.
scopeTag . extractDepInfo ( ctx , to , scopePaths )
2020-06-12 18:46:39 +02:00
} else if tag == implLibraryTag {
if implLibrary , ok := to . ( * Library ) ; ok {
module . implLibraryModule = implLibrary
} else {
ctx . ModuleErrorf ( "implementation library must be of type *java.Library but was %T" , to )
}
} else if tag == xmlPermissionsFileTag {
if xmlPermissionsFileModule , ok := to . ( * sdkLibraryXml ) ; ok {
module . xmlPermissionsFileModule = xmlPermissionsFileModule
} else {
ctx . ModuleErrorf ( "xml permissions file module must be of type *sdkLibraryXml but was %T" , to )
}
2019-04-17 20:11:46 +02:00
}
} )
2020-05-20 17:18:00 +02:00
// Populate the scope paths with information from the properties.
for apiScope , scopeProperties := range module . scopeProperties {
if len ( scopeProperties . Jars ) == 0 {
continue
}
paths := module . getScopePathsCreateIfNeeded ( apiScope )
2021-09-21 16:25:12 +02:00
paths . annotationsZip = android . OptionalPathForModuleSrc ( ctx , scopeProperties . Annotations )
2020-05-20 17:18:00 +02:00
paths . currentApiFilePath = android . OptionalPathForModuleSrc ( ctx , scopeProperties . Current_api )
paths . removedApiFilePath = android . OptionalPathForModuleSrc ( ctx , scopeProperties . Removed_api )
}
2021-02-26 12:09:39 +01:00
if ctx . Device ( ) {
// If this is a variant created for a prebuilt_apex then use the dex implementation jar
// obtained from the associated deapexer module.
2023-12-14 00:54:49 +01:00
ai , _ := android . ModuleProvider ( ctx , android . ApexInfoProvider )
2021-02-26 12:09:39 +01:00
if ai . ForPrebuiltApex {
// Get the path of the dex implementation jar from the `deapexer` module.
2023-12-13 00:23:53 +01:00
di , err := android . FindDeapexerProviderForModule ( ctx )
if err != nil {
// An error was found, possibly due to multiple apexes in the tree that export this library
// Defer the error till a client tries to call DexJarBuildPath
module . dexJarFileErr = err
2024-01-17 19:26:27 +01:00
module . initHiddenAPIError ( err )
2023-12-13 00:23:53 +01:00
return
2021-09-17 02:44:12 +02:00
}
2023-12-13 01:06:32 +01:00
dexJarFileApexRootRelative := ApexRootRelativePathToJavaLib ( module . BaseModuleName ( ) )
2023-02-08 14:56:07 +01:00
if dexOutputPath := di . PrebuiltExportPath ( dexJarFileApexRootRelative ) ; dexOutputPath != nil {
2021-09-15 04:34:04 +02:00
dexJarFile := makeDexJarPathFromPath ( dexOutputPath )
module . dexJarFile = dexJarFile
2021-09-09 10:12:46 +02:00
installPath := android . PathForModuleInPartitionInstall (
2023-02-08 14:56:07 +01:00
ctx , "apex" , ai . ApexVariationName , dexJarFileApexRootRelative )
2021-09-09 10:12:46 +02:00
module . installFile = installPath
2021-09-15 04:34:04 +02:00
module . initHiddenAPI ( ctx , dexJarFile , module . findScopePaths ( apiScopePublic ) . stubsImplPath [ 0 ] , nil )
2021-09-09 10:12:46 +02:00
2024-01-24 00:56:29 +01:00
module . dexpreopter . installPath = module . dexpreopter . getInstallPath ( ctx , android . RemoveOptionalPrebuiltPrefix ( ctx . ModuleName ( ) ) , installPath )
2021-09-09 10:12:46 +02:00
module . dexpreopter . isSDKLibrary = true
2024-01-24 00:56:29 +01:00
module . dexpreopter . uncompressedDex = shouldUncompressDex ( ctx , android . RemoveOptionalPrebuiltPrefix ( ctx . ModuleName ( ) ) , & module . dexpreopter )
2023-02-08 14:56:07 +01:00
if profilePath := di . PrebuiltExportPath ( dexJarFileApexRootRelative + ".prof" ) ; profilePath != nil {
module . dexpreopter . inputProfilePathOnHost = profilePath
}
2021-02-26 12:09:39 +01:00
} else {
// This should never happen as a variant for a prebuilt_apex is only created if the
// prebuilt_apex has been configured to export the java library dex file.
2021-09-17 02:44:12 +02:00
ctx . ModuleErrorf ( "internal error: no dex implementation jar available from prebuilt APEX %s" , di . ApexModuleName ( ) )
2021-02-26 12:09:39 +01:00
}
}
}
2019-04-17 20:11:46 +02:00
}
2021-03-29 13:11:58 +02:00
func ( module * SdkLibraryImport ) sdkJars ( ctx android . BaseModuleContext , sdkVersion android . SdkSpec , headerJars bool ) android . Paths {
2020-06-12 18:46:39 +02:00
// For consistency with SdkLibrary make the implementation jar available to libraries that
// are within the same APEX.
implLibraryModule := module . implLibraryModule
2020-09-16 03:30:11 +02:00
if implLibraryModule != nil && withinSameApexesAs ( ctx , module ) {
2020-06-12 18:46:39 +02:00
if headerJars {
return implLibraryModule . HeaderJars ( )
} else {
return implLibraryModule . ImplementationJars ( )
}
}
2020-05-20 15:20:02 +02:00
return module . selectHeaderJarsForSdkVersion ( ctx , sdkVersion )
2020-01-31 14:36:25 +01:00
}
2019-04-17 20:11:46 +02:00
// to satisfy SdkLibraryDependency interface
2021-03-29 13:11:58 +02:00
func ( module * SdkLibraryImport ) SdkHeaderJars ( ctx android . BaseModuleContext , sdkVersion android . SdkSpec ) android . Paths {
2019-04-17 20:11:46 +02:00
// This module is just a wrapper for the prebuilt stubs.
2020-06-12 18:46:39 +02:00
return module . sdkJars ( ctx , sdkVersion , true )
2019-04-17 20:11:46 +02:00
}
// to satisfy SdkLibraryDependency interface
2021-03-29 13:11:58 +02:00
func ( module * SdkLibraryImport ) SdkImplementationJars ( ctx android . BaseModuleContext , sdkVersion android . SdkSpec ) android . Paths {
2019-04-17 20:11:46 +02:00
// This module is just a wrapper for the stubs.
2020-06-12 18:46:39 +02:00
return module . sdkJars ( ctx , sdkVersion , false )
}
2020-12-17 13:07:54 +01:00
// to satisfy UsesLibraryDependency interface
2024-01-09 22:35:56 +01:00
func ( module * SdkLibraryImport ) DexJarBuildPath ( ctx android . ModuleErrorfContext ) OptionalDexJarPath {
2021-02-26 12:09:39 +01:00
// The dex implementation jar extracted from the .apex file should be used in preference to the
// source.
2023-12-13 00:23:53 +01:00
if module . dexJarFileErr != nil {
2024-01-09 22:35:56 +01:00
ctx . ModuleErrorf ( module . dexJarFileErr . Error ( ) )
2023-12-13 00:23:53 +01:00
}
2021-09-15 04:34:04 +02:00
if module . dexJarFile . IsSet ( ) {
2021-02-26 12:09:39 +01:00
return module . dexJarFile
}
2020-06-12 18:46:39 +02:00
if module . implLibraryModule == nil {
2021-09-15 04:34:04 +02:00
return makeUnsetDexJarPath ( )
2020-06-12 18:46:39 +02:00
} else {
2024-01-09 22:35:56 +01:00
return module . implLibraryModule . DexJarBuildPath ( ctx )
2020-06-12 18:46:39 +02:00
}
}
2020-12-17 13:07:54 +01:00
// to satisfy UsesLibraryDependency interface
2020-08-14 18:32:16 +02:00
func ( module * SdkLibraryImport ) DexJarInstallPath ( ) android . Path {
2021-07-07 18:13:11 +02:00
return module . installFile
2020-08-14 18:32:16 +02:00
}
2020-12-17 13:07:54 +01:00
// to satisfy UsesLibraryDependency interface
func ( module * SdkLibraryImport ) ClassLoaderContexts ( ) dexpreopt . ClassLoaderContextMap {
return nil
}
2020-06-12 18:46:39 +02:00
// to satisfy apex.javaDependency interface
func ( module * SdkLibraryImport ) JacocoReportClassesFile ( ) android . Path {
if module . implLibraryModule == nil {
return nil
} else {
return module . implLibraryModule . JacocoReportClassesFile ( )
}
}
2020-07-22 05:31:17 +02:00
// to satisfy apex.javaDependency interface
func ( module * SdkLibraryImport ) LintDepSets ( ) LintDepSets {
if module . implLibraryModule == nil {
return LintDepSets { }
} else {
return module . implLibraryModule . LintDepSets ( )
}
}
2022-01-14 22:19:14 +01:00
func ( module * SdkLibraryImport ) GetStrictUpdatabilityLinting ( ) bool {
2021-05-11 00:30:00 +02:00
if module . implLibraryModule == nil {
return false
} else {
2022-01-14 22:19:14 +01:00
return module . implLibraryModule . GetStrictUpdatabilityLinting ( )
2021-05-11 00:30:00 +02:00
}
}
2022-01-14 22:19:14 +01:00
func ( module * SdkLibraryImport ) SetStrictUpdatabilityLinting ( strictLinting bool ) {
2021-05-11 00:30:00 +02:00
if module . implLibraryModule != nil {
2022-01-14 22:19:14 +01:00
module . implLibraryModule . SetStrictUpdatabilityLinting ( strictLinting )
2021-05-11 00:30:00 +02:00
}
}
2020-06-12 18:46:39 +02:00
// to satisfy apex.javaDependency interface
func ( module * SdkLibraryImport ) Stem ( ) string {
return module . BaseModuleName ( )
2019-04-17 20:11:46 +02:00
}
2020-02-17 09:28:10 +01:00
2020-06-17 17:59:43 +02:00
var _ ApexDependency = ( * SdkLibraryImport ) ( nil )
// to satisfy java.ApexDependency interface
func ( module * SdkLibraryImport ) HeaderJars ( ) android . Paths {
if module . implLibraryModule == nil {
return nil
} else {
return module . implLibraryModule . HeaderJars ( )
}
}
// to satisfy java.ApexDependency interface
func ( module * SdkLibraryImport ) ImplementationAndResourcesJars ( ) android . Paths {
if module . implLibraryModule == nil {
return nil
} else {
return module . implLibraryModule . ImplementationAndResourcesJars ( )
}
}
2021-09-09 10:12:46 +02:00
// to satisfy java.DexpreopterInterface interface
func ( module * SdkLibraryImport ) IsInstallable ( ) bool {
return true
}
2021-06-17 15:56:05 +02:00
var _ android . RequiredFilesFromPrebuiltApex = ( * SdkLibraryImport ) ( nil )
2021-06-17 16:59:07 +02:00
func ( module * SdkLibraryImport ) RequiredFilesFromPrebuiltApex ( ctx android . BaseModuleContext ) [ ] string {
2021-06-17 15:56:05 +02:00
name := module . BaseModuleName ( )
2023-02-08 14:56:07 +01:00
return requiredFilesFromPrebuiltApexForImport ( name , & module . dexpreopter )
2021-06-17 15:56:05 +02:00
}
2024-01-25 23:12:50 +01:00
func ( j * SdkLibraryImport ) UseProfileGuidedDexpreopt ( ) bool {
return proptools . Bool ( j . importDexpreoptProperties . Dex_preopt . Profile_guided )
}
2020-02-17 09:28:10 +01:00
// java_sdk_library_xml
type sdkLibraryXml struct {
android . ModuleBase
android . DefaultableModuleBase
android . ApexModuleBase
properties sdkLibraryXmlProperties
outputFilePath android . OutputPath
installDirPath android . InstallPath
2020-09-16 03:30:11 +02:00
hideApexVariantFromMake bool
2020-02-17 09:28:10 +01:00
}
type sdkLibraryXmlProperties struct {
// canonical name of the lib
Lib_name * string
2021-09-07 19:21:59 +02:00
// Signals that this shared library is part of the bootclasspath starting
// on the version indicated in this attribute.
//
// This will make platforms at this level and above to ignore
// <uses-library> tags with this library name because the library is already
// available
On_bootclasspath_since * string
// Signals that this shared library was part of the bootclasspath before
// (but not including) the version indicated in this attribute.
//
// The system will automatically add a <uses-library> tag with this library to
// apps that target any SDK less than the version indicated in this attribute.
On_bootclasspath_before * string
// Indicates that PackageManager should ignore this shared library if the
// platform is below the version indicated in this attribute.
//
// This means that the device won't recognise this library as installed.
Min_device_sdk * string
// Indicates that PackageManager should ignore this shared library if the
// platform is above the version indicated in this attribute.
//
// This means that the device won't recognise this library as installed.
Max_device_sdk * string
2021-09-28 17:40:23 +02:00
// The SdkLibrary's min api level as a string
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level * string
Add the ability for a java_sdk_library to depend on another.
This simply exports all of the uses_libs: [] libraries into a
"dependency=''" statement in the generated XML file (with the <library>
stanza in it).
Test: `go test` in java/
Bug: 184396657
NOTE FOR REVIEWERS - original patch and result patch are not identical.
PLEASE REVIEW CAREFULLY.
Diffs between the patches:
func formattedDependenciesAttribute(dependencies []string) string {
> + if dependencies == nil {
> + return ""
> + }
> + return fmt.Sprintf(` dependency=\"%s\"\n`, strings.Join(dependencies, ":"))
> +}
> +
> + dependenciesAttr := formattedDependenciesAttribute(module.properties.Uses_libs_dependencies)
> + dependenciesAttr,
> --- java/sdk_library_test.go
> +++ java/sdk_library_test.go
> +
> +func TestSdkLibraryDependency(t *testing.T) {
> + result := android.GroupFixturePreparers(
> + prepareForJavaTest,
> + PrepareForTestWithJavaSdkLibraryFiles,
> + FixtureWithPrebuiltApis(map[string][]string{
> + "30": {"bar", "foo"},
> + }),
> + ).RunTestWithBp(t,
> + `
> + java_sdk_library {
> + name: "foo",
> + srcs: ["a.java", "b.java"],
> + api_packages: ["foo"],
> + }
> +
> + java_sdk_library {
> + name: "bar",
> + srcs: ["c.java", "b.java"],
> + libs: [
> + "foo",
> + ],
> + uses_libs: [
> + "foo",
> + ],
> + }
> +`)
> +
> + barPermissions := result.ModuleForTests("bar.xml", "android_common").Rule("java_sdk_xml")
> +
> + android.AssertStringDoesContain(t, "bar.xml java_sdk_xml command", barPermissions.RuleParams.Command, `dependency=\"foo\"`)
> +}
Original patch:
diff --git a/java/sdk_library.go b/java/sdk_library.go
old mode 100644
new mode 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared libra
[[[Original patch trimmed due to size. Decoded string size: 3559. Decoded string SHA1: 67fbd040aa818732a686514c4556850c8c36dc8d.]]]
Result patch:
diff --git a/java/sdk_library.go b/java/sdk_library.go
index fb27812..fbfe509 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared library
[[[Result patch trimmed due to size. Decoded string size: 3614. Decoded string SHA1: b5730ecbeeaad420439ddb67eaaa9150ede94585.]]]
Change-Id: I73f69e2a4573e416492f68e083fe739f3f75b721
2023-11-27 13:07:36 +01:00
// Uses-libs dependencies that the shared library requires to work correctly.
//
// This will add dependency="foo:bar" to the <library> section.
Uses_libs_dependencies [ ] string
2020-02-17 09:28:10 +01:00
}
// java_sdk_library_xml builds the permission xml file for a java_sdk_library.
// Not to be used directly by users. java_sdk_library internally uses this.
func sdkLibraryXmlFactory ( ) android . Module {
module := & sdkLibraryXml { }
module . AddProperties ( & module . properties )
android . InitApexModule ( module )
android . InitAndroidArchModule ( module , android . DeviceSupported , android . MultilibCommon )
return module
}
Reland: Deduplicate APEX variants that would build identically
APEX variants that share the same SDK version and updatability
almost always use identical command line arguments to build but
with different intermediates directories. This causes unnecessary
build time and disk space for duplicated work.
Deduplicate APEX variants that would build identically. Create
aliases from the per-APEX variations to the new shared variations
so that the APEX modules can continue to depend on them via the
APEX name as the variation.
This has one significant change in behavior. Before this change,
if an APEX had two libraries in its direct dependencies and one
of those libraries depended on the other, and the second library
had stubs, then the first library would depend on the implementation
of the second library and not the stubs. After this change, if
the first library is also present in a second APEX but the second
library is not, then the common variant shared between the two
APEXes would use the stubs, not the implementation.
In a correctly configured set of build rules this change will
be irrelevant, because if the compilation worked for the second
APEX using stubs then it will work for the common variant using
stubs. However, if an incorrect change to the build rules is
made this could lead to confusing errors, as a previously-working
common variant could suddenly stop building when a module is added
to a new APEX without its dependencies that require implementation
APIs to compile.
This change reduces the number of modules in an AOSP arm64-userdebug
build by 3% (52242 to 50586), reduces the number of variants of the
libcutils module from 74 to 53, and reduces the number of variants
of the massive libart[d] modules from 44 to 32.
This relands I0529837476a253c32b3dfb98dcccf107427c742c with a fix
to always mark permissions XML files of java_sdk_library modules as
unique per apex since they contain the APEX filename, and a fix
to UpdateUniqueApexVariationsForDeps to check ApexInfo.InApexes
instead of DepIsInSameApex to check if two modules are in the same
apex to account for a module that depends on another in a way that
doesn't normally include the dependency in the APEX (e.g. a libs
property), but the dependency is directly included in the APEX.
Bug: 164216768
Test: go test ./build/soong/apex/...
Change-Id: I2ae170601f764e5b88d0be2e0e6adc84e3a4d9cc
2020-08-11 21:17:01 +02:00
func ( module * sdkLibraryXml ) UniqueApexVariations ( ) bool {
// sdkLibraryXml needs a unique variation per APEX because the generated XML file contains the path to the
// mounted APEX, which contains the name of the APEX.
return true
}
2020-08-26 15:11:53 +02:00
// from android.PrebuiltEtcModule
func ( module * sdkLibraryXml ) BaseDir ( ) string {
return "etc"
}
2020-02-17 09:28:10 +01:00
// from android.PrebuiltEtcModule
func ( module * sdkLibraryXml ) SubDir ( ) string {
return "permissions"
}
// from android.PrebuiltEtcModule
func ( module * sdkLibraryXml ) OutputFile ( ) android . OutputPath {
return module . outputFilePath
}
// from android.ApexModule
func ( module * sdkLibraryXml ) AvailableFor ( what string ) bool {
return true
}
func ( module * sdkLibraryXml ) DepsMutator ( ctx android . BottomUpMutatorContext ) {
// do nothing
}
2020-12-15 14:29:02 +01:00
var _ android . ApexModule = ( * sdkLibraryXml ) ( nil )
// Implements android.ApexModule
2020-07-23 07:32:17 +02:00
func ( module * sdkLibraryXml ) ShouldSupportSdkVersion ( ctx android . BaseModuleContext ,
sdkVersion android . ApiLevel ) error {
2020-04-15 04:03:39 +02:00
// sdkLibraryXml doesn't need to be checked separately because java_sdk_library is checked
return nil
}
2020-02-17 09:28:10 +01:00
// File path to the runtime implementation library
2020-09-16 03:30:11 +02:00
func ( module * sdkLibraryXml ) implPath ( ctx android . ModuleContext ) string {
2020-02-17 09:28:10 +01:00
implName := proptools . String ( module . properties . Lib_name )
2023-12-14 00:54:49 +01:00
if apexInfo , _ := android . ModuleProvider ( ctx , android . ApexInfoProvider ) ; ! apexInfo . IsForPlatform ( ) {
2020-08-13 20:24:56 +02:00
// TODO(b/146468504): ApexVariationName() is only a soong module name, not apex name.
2020-02-17 09:28:10 +01:00
// In most cases, this works fine. But when apex_name is set or override_apex is used
// this can be wrong.
2020-09-16 03:30:11 +02:00
return fmt . Sprintf ( "/apex/%s/javalib/%s.jar" , apexInfo . ApexVariationName , implName )
2020-02-17 09:28:10 +01:00
}
partition := "system"
if module . SocSpecific ( ) {
partition = "vendor"
} else if module . DeviceSpecific ( ) {
partition = "odm"
} else if module . ProductSpecific ( ) {
partition = "product"
} else if module . SystemExtSpecific ( ) {
partition = "system_ext"
}
return "/" + partition + "/framework/" + implName + ".jar"
}
2021-09-07 19:21:59 +02:00
func formattedOptionalSdkLevelAttribute ( ctx android . ModuleContext , attrName string , value * string ) string {
if value == nil {
return ""
}
apiLevel , err := android . ApiLevelFromUser ( ctx , * value )
if err != nil {
2021-10-29 11:32:32 +02:00
// attributes in bp files have underscores but in the xml have dashes.
ctx . PropertyErrorf ( strings . ReplaceAll ( attrName , "-" , "_" ) , err . Error ( ) )
2021-09-07 19:21:59 +02:00
return ""
}
2021-12-22 16:28:05 +01:00
if apiLevel . IsCurrent ( ) {
// passing "current" would always mean a future release, never the current (or the current in
// progress) which means some conditions would never be triggered.
ctx . PropertyErrorf ( strings . ReplaceAll ( attrName , "-" , "_" ) ,
` "current" is not an allowed value for this attribute ` )
return ""
}
2022-06-17 22:01:21 +02:00
// "safeValue" is safe because it translates finalized codenames to a string
// with their SDK int.
safeValue := apiLevel . String ( )
return formattedOptionalAttribute ( attrName , & safeValue )
2021-09-07 19:21:59 +02:00
}
// formats an attribute for the xml permissions file if the value is not null
// returns empty string otherwise
func formattedOptionalAttribute ( attrName string , value * string ) string {
if value == nil {
return ""
}
return fmt . Sprintf ( ` %s=\"%s\"\n ` , attrName , * value )
}
Add the ability for a java_sdk_library to depend on another.
This simply exports all of the uses_libs: [] libraries into a
"dependency=''" statement in the generated XML file (with the <library>
stanza in it).
Test: `go test` in java/
Bug: 184396657
NOTE FOR REVIEWERS - original patch and result patch are not identical.
PLEASE REVIEW CAREFULLY.
Diffs between the patches:
func formattedDependenciesAttribute(dependencies []string) string {
> + if dependencies == nil {
> + return ""
> + }
> + return fmt.Sprintf(` dependency=\"%s\"\n`, strings.Join(dependencies, ":"))
> +}
> +
> + dependenciesAttr := formattedDependenciesAttribute(module.properties.Uses_libs_dependencies)
> + dependenciesAttr,
> --- java/sdk_library_test.go
> +++ java/sdk_library_test.go
> +
> +func TestSdkLibraryDependency(t *testing.T) {
> + result := android.GroupFixturePreparers(
> + prepareForJavaTest,
> + PrepareForTestWithJavaSdkLibraryFiles,
> + FixtureWithPrebuiltApis(map[string][]string{
> + "30": {"bar", "foo"},
> + }),
> + ).RunTestWithBp(t,
> + `
> + java_sdk_library {
> + name: "foo",
> + srcs: ["a.java", "b.java"],
> + api_packages: ["foo"],
> + }
> +
> + java_sdk_library {
> + name: "bar",
> + srcs: ["c.java", "b.java"],
> + libs: [
> + "foo",
> + ],
> + uses_libs: [
> + "foo",
> + ],
> + }
> +`)
> +
> + barPermissions := result.ModuleForTests("bar.xml", "android_common").Rule("java_sdk_xml")
> +
> + android.AssertStringDoesContain(t, "bar.xml java_sdk_xml command", barPermissions.RuleParams.Command, `dependency=\"foo\"`)
> +}
Original patch:
diff --git a/java/sdk_library.go b/java/sdk_library.go
old mode 100644
new mode 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared libra
[[[Original patch trimmed due to size. Decoded string size: 3559. Decoded string SHA1: 67fbd040aa818732a686514c4556850c8c36dc8d.]]]
Result patch:
diff --git a/java/sdk_library.go b/java/sdk_library.go
index fb27812..fbfe509 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared library
[[[Result patch trimmed due to size. Decoded string size: 3614. Decoded string SHA1: b5730ecbeeaad420439ddb67eaaa9150ede94585.]]]
Change-Id: I73f69e2a4573e416492f68e083fe739f3f75b721
2023-11-27 13:07:36 +01:00
func formattedDependenciesAttribute ( dependencies [ ] string ) string {
if dependencies == nil {
return ""
}
return fmt . Sprintf ( ` dependency=\"%s\"\n ` , strings . Join ( dependencies , ":" ) )
}
2021-09-07 19:21:59 +02:00
func ( module * sdkLibraryXml ) permissionsContents ( ctx android . ModuleContext ) string {
libName := proptools . String ( module . properties . Lib_name )
libNameAttr := formattedOptionalAttribute ( "name" , & libName )
filePath := module . implPath ( ctx )
filePathAttr := formattedOptionalAttribute ( "file" , & filePath )
2021-10-29 11:32:32 +02:00
implicitFromAttr := formattedOptionalSdkLevelAttribute ( ctx , "on-bootclasspath-since" , module . properties . On_bootclasspath_since )
implicitUntilAttr := formattedOptionalSdkLevelAttribute ( ctx , "on-bootclasspath-before" , module . properties . On_bootclasspath_before )
minSdkAttr := formattedOptionalSdkLevelAttribute ( ctx , "min-device-sdk" , module . properties . Min_device_sdk )
maxSdkAttr := formattedOptionalSdkLevelAttribute ( ctx , "max-device-sdk" , module . properties . Max_device_sdk )
Add the ability for a java_sdk_library to depend on another.
This simply exports all of the uses_libs: [] libraries into a
"dependency=''" statement in the generated XML file (with the <library>
stanza in it).
Test: `go test` in java/
Bug: 184396657
NOTE FOR REVIEWERS - original patch and result patch are not identical.
PLEASE REVIEW CAREFULLY.
Diffs between the patches:
func formattedDependenciesAttribute(dependencies []string) string {
> + if dependencies == nil {
> + return ""
> + }
> + return fmt.Sprintf(` dependency=\"%s\"\n`, strings.Join(dependencies, ":"))
> +}
> +
> + dependenciesAttr := formattedDependenciesAttribute(module.properties.Uses_libs_dependencies)
> + dependenciesAttr,
> --- java/sdk_library_test.go
> +++ java/sdk_library_test.go
> +
> +func TestSdkLibraryDependency(t *testing.T) {
> + result := android.GroupFixturePreparers(
> + prepareForJavaTest,
> + PrepareForTestWithJavaSdkLibraryFiles,
> + FixtureWithPrebuiltApis(map[string][]string{
> + "30": {"bar", "foo"},
> + }),
> + ).RunTestWithBp(t,
> + `
> + java_sdk_library {
> + name: "foo",
> + srcs: ["a.java", "b.java"],
> + api_packages: ["foo"],
> + }
> +
> + java_sdk_library {
> + name: "bar",
> + srcs: ["c.java", "b.java"],
> + libs: [
> + "foo",
> + ],
> + uses_libs: [
> + "foo",
> + ],
> + }
> +`)
> +
> + barPermissions := result.ModuleForTests("bar.xml", "android_common").Rule("java_sdk_xml")
> +
> + android.AssertStringDoesContain(t, "bar.xml java_sdk_xml command", barPermissions.RuleParams.Command, `dependency=\"foo\"`)
> +}
Original patch:
diff --git a/java/sdk_library.go b/java/sdk_library.go
old mode 100644
new mode 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared libra
[[[Original patch trimmed due to size. Decoded string size: 3559. Decoded string SHA1: 67fbd040aa818732a686514c4556850c8c36dc8d.]]]
Result patch:
diff --git a/java/sdk_library.go b/java/sdk_library.go
index fb27812..fbfe509 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared library
[[[Result patch trimmed due to size. Decoded string size: 3614. Decoded string SHA1: b5730ecbeeaad420439ddb67eaaa9150ede94585.]]]
Change-Id: I73f69e2a4573e416492f68e083fe739f3f75b721
2023-11-27 13:07:36 +01:00
dependenciesAttr := formattedDependenciesAttribute ( module . properties . Uses_libs_dependencies )
2021-12-22 20:53:01 +01:00
// <library> is understood in all android versions whereas <apex-library> is only understood from API T (and ignored before that).
// similarly, min_device_sdk is only understood from T. So if a library is using that, we need to use the apex-library to make sure this library is not loaded before T
2021-09-28 17:40:23 +02:00
var libraryTag string
if module . properties . Min_device_sdk != nil {
2021-12-22 20:53:01 +01:00
libraryTag = ` <apex-library\n `
2021-09-28 17:40:23 +02:00
} else {
libraryTag = ` <library\n `
}
2021-09-07 19:21:59 +02:00
return strings . Join ( [ ] string {
` <?xml version=\"1.0\" encoding=\"utf-8\"?>\n ` ,
` <!-- Copyright (C) 2018 The Android Open Source Project\n ` ,
` \n ` ,
` Licensed under the Apache License, Version 2.0 (the \"License\");\n ` ,
` you may not use this file except in compliance with the License.\n ` ,
` You may obtain a copy of the License at\n ` ,
` \n ` ,
` http://www.apache.org/licenses/LICENSE-2.0\n ` ,
` \n ` ,
` Unless required by applicable law or agreed to in writing, software\n ` ,
` distributed under the License is distributed on an \"AS IS\" BASIS,\n ` ,
` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n ` ,
` See the License for the specific language governing permissions and\n ` ,
` limitations under the License.\n ` ,
` -->\n ` ,
` <permissions>\n ` ,
2021-09-28 17:40:23 +02:00
libraryTag ,
2021-09-07 19:21:59 +02:00
libNameAttr ,
filePathAttr ,
implicitFromAttr ,
implicitUntilAttr ,
minSdkAttr ,
maxSdkAttr ,
Add the ability for a java_sdk_library to depend on another.
This simply exports all of the uses_libs: [] libraries into a
"dependency=''" statement in the generated XML file (with the <library>
stanza in it).
Test: `go test` in java/
Bug: 184396657
NOTE FOR REVIEWERS - original patch and result patch are not identical.
PLEASE REVIEW CAREFULLY.
Diffs between the patches:
func formattedDependenciesAttribute(dependencies []string) string {
> + if dependencies == nil {
> + return ""
> + }
> + return fmt.Sprintf(` dependency=\"%s\"\n`, strings.Join(dependencies, ":"))
> +}
> +
> + dependenciesAttr := formattedDependenciesAttribute(module.properties.Uses_libs_dependencies)
> + dependenciesAttr,
> --- java/sdk_library_test.go
> +++ java/sdk_library_test.go
> +
> +func TestSdkLibraryDependency(t *testing.T) {
> + result := android.GroupFixturePreparers(
> + prepareForJavaTest,
> + PrepareForTestWithJavaSdkLibraryFiles,
> + FixtureWithPrebuiltApis(map[string][]string{
> + "30": {"bar", "foo"},
> + }),
> + ).RunTestWithBp(t,
> + `
> + java_sdk_library {
> + name: "foo",
> + srcs: ["a.java", "b.java"],
> + api_packages: ["foo"],
> + }
> +
> + java_sdk_library {
> + name: "bar",
> + srcs: ["c.java", "b.java"],
> + libs: [
> + "foo",
> + ],
> + uses_libs: [
> + "foo",
> + ],
> + }
> +`)
> +
> + barPermissions := result.ModuleForTests("bar.xml", "android_common").Rule("java_sdk_xml")
> +
> + android.AssertStringDoesContain(t, "bar.xml java_sdk_xml command", barPermissions.RuleParams.Command, `dependency=\"foo\"`)
> +}
Original patch:
diff --git a/java/sdk_library.go b/java/sdk_library.go
old mode 100644
new mode 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared libra
[[[Original patch trimmed due to size. Decoded string size: 3559. Decoded string SHA1: 67fbd040aa818732a686514c4556850c8c36dc8d.]]]
Result patch:
diff --git a/java/sdk_library.go b/java/sdk_library.go
index fb27812..fbfe509 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared library
[[[Result patch trimmed due to size. Decoded string size: 3614. Decoded string SHA1: b5730ecbeeaad420439ddb67eaaa9150ede94585.]]]
Change-Id: I73f69e2a4573e416492f68e083fe739f3f75b721
2023-11-27 13:07:36 +01:00
dependenciesAttr ,
2021-09-07 19:21:59 +02:00
` />\n ` ,
` </permissions>\n ` } , "" )
}
2020-02-17 09:28:10 +01:00
func ( module * sdkLibraryXml ) GenerateAndroidBuildActions ( ctx android . ModuleContext ) {
2023-12-14 00:54:49 +01:00
apexInfo , _ := android . ModuleProvider ( ctx , android . ApexInfoProvider )
module . hideApexVariantFromMake = ! apexInfo . IsForPlatform ( )
2020-09-16 03:30:11 +02:00
2020-02-17 09:28:10 +01:00
libName := proptools . String ( module . properties . Lib_name )
2021-09-28 17:40:23 +02:00
module . selfValidate ( ctx )
2021-09-07 19:21:59 +02:00
xmlContent := module . permissionsContents ( ctx )
2020-02-17 09:28:10 +01:00
module . outputFilePath = android . PathForModuleOut ( ctx , libName + ".xml" ) . OutputPath
2020-11-17 02:32:30 +01:00
rule := android . NewRuleBuilder ( pctx , ctx )
2020-02-17 09:28:10 +01:00
rule . Command ( ) .
Text ( "/bin/bash -c \"echo -e '" + xmlContent + "'\" > " ) .
Output ( module . outputFilePath )
2020-11-17 02:32:30 +01:00
rule . Build ( "java_sdk_xml" , "Permission XML" )
2020-02-17 09:28:10 +01:00
module . installDirPath = android . PathForModuleInstall ( ctx , "etc" , module . SubDir ( ) )
}
func ( module * sdkLibraryXml ) AndroidMkEntries ( ) [ ] android . AndroidMkEntries {
2020-09-16 03:30:11 +02:00
if module . hideApexVariantFromMake {
2021-12-06 12:40:46 +01:00
return [ ] android . AndroidMkEntries { {
2020-02-17 09:28:10 +01:00
Disabled : true ,
} }
}
2021-12-06 12:40:46 +01:00
return [ ] android . AndroidMkEntries { {
2020-02-17 09:28:10 +01:00
Class : "ETC" ,
OutputFile : android . OptionalPathForPath ( module . outputFilePath ) ,
ExtraEntries : [ ] android . AndroidMkExtraEntriesFunc {
2020-07-03 22:18:24 +02:00
func ( ctx android . AndroidMkExtraEntriesContext , entries * android . AndroidMkEntries ) {
2020-02-17 09:28:10 +01:00
entries . SetString ( "LOCAL_MODULE_TAGS" , "optional" )
2021-11-12 03:59:15 +01:00
entries . SetString ( "LOCAL_MODULE_PATH" , module . installDirPath . String ( ) )
2020-02-17 09:28:10 +01:00
entries . SetString ( "LOCAL_INSTALLED_MODULE_STEM" , module . outputFilePath . Base ( ) )
} ,
} ,
} }
}
2020-02-10 14:37:10 +01:00
2021-09-28 17:40:23 +02:00
func ( module * sdkLibraryXml ) selfValidate ( ctx android . ModuleContext ) {
module . validateAtLeastTAttributes ( ctx )
module . validateMinAndMaxDeviceSdk ( ctx )
module . validateMinMaxDeviceSdkAndModuleMinSdk ( ctx )
module . validateOnBootclasspathBeforeRequirements ( ctx )
}
func ( module * sdkLibraryXml ) validateAtLeastTAttributes ( ctx android . ModuleContext ) {
t := android . ApiLevelOrPanic ( ctx , "Tiramisu" )
module . attrAtLeastT ( ctx , t , module . properties . Min_device_sdk , "min_device_sdk" )
module . attrAtLeastT ( ctx , t , module . properties . Max_device_sdk , "max_device_sdk" )
module . attrAtLeastT ( ctx , t , module . properties . On_bootclasspath_before , "on_bootclasspath_before" )
module . attrAtLeastT ( ctx , t , module . properties . On_bootclasspath_since , "on_bootclasspath_since" )
}
func ( module * sdkLibraryXml ) attrAtLeastT ( ctx android . ModuleContext , t android . ApiLevel , attr * string , attrName string ) {
if attr != nil {
if level , err := android . ApiLevelFromUser ( ctx , * attr ) ; err == nil {
// we will inform the user of invalid inputs when we try to write the
// permissions xml file so we don't need to do it here
if t . GreaterThan ( level ) {
ctx . PropertyErrorf ( attrName , "Attribute value needs to be at least T" )
}
}
}
}
func ( module * sdkLibraryXml ) validateMinAndMaxDeviceSdk ( ctx android . ModuleContext ) {
if module . properties . Min_device_sdk != nil && module . properties . Max_device_sdk != nil {
min , minErr := android . ApiLevelFromUser ( ctx , * module . properties . Min_device_sdk )
max , maxErr := android . ApiLevelFromUser ( ctx , * module . properties . Max_device_sdk )
if minErr == nil && maxErr == nil {
// we will inform the user of invalid inputs when we try to write the
// permissions xml file so we don't need to do it here
if min . GreaterThan ( max ) {
ctx . ModuleErrorf ( "min_device_sdk can't be greater than max_device_sdk" )
}
}
}
}
func ( module * sdkLibraryXml ) validateMinMaxDeviceSdkAndModuleMinSdk ( ctx android . ModuleContext ) {
moduleMinApi := android . ApiLevelOrPanic ( ctx , * module . properties . Sdk_library_min_api_level )
if module . properties . Min_device_sdk != nil {
api , err := android . ApiLevelFromUser ( ctx , * module . properties . Min_device_sdk )
if err == nil {
if moduleMinApi . GreaterThan ( api ) {
ctx . PropertyErrorf ( "min_device_sdk" , "Can't be less than module's min sdk (%s)" , moduleMinApi )
}
}
}
if module . properties . Max_device_sdk != nil {
api , err := android . ApiLevelFromUser ( ctx , * module . properties . Max_device_sdk )
if err == nil {
if moduleMinApi . GreaterThan ( api ) {
ctx . PropertyErrorf ( "max_device_sdk" , "Can't be less than module's min sdk (%s)" , moduleMinApi )
}
}
}
}
func ( module * sdkLibraryXml ) validateOnBootclasspathBeforeRequirements ( ctx android . ModuleContext ) {
moduleMinApi := android . ApiLevelOrPanic ( ctx , * module . properties . Sdk_library_min_api_level )
if module . properties . On_bootclasspath_before != nil {
t := android . ApiLevelOrPanic ( ctx , "Tiramisu" )
// if we use the attribute, then we need to do this validation
if moduleMinApi . LessThan ( t ) {
// if minAPi is < T, then we need to have min_device_sdk (which only accepts T+)
if module . properties . Min_device_sdk == nil {
ctx . PropertyErrorf ( "on_bootclasspath_before" , "Using this property requires that the module's min_sdk_version or the shared library's min_device_sdk is at least T" )
}
}
}
}
2020-02-10 14:37:10 +01:00
type sdkLibrarySdkMemberType struct {
android . SdkMemberTypeBase
}
2021-07-14 11:29:36 +02:00
func ( s * sdkLibrarySdkMemberType ) AddDependencies ( ctx android . SdkDependencyContext , dependencyTag blueprint . DependencyTag , names [ ] string ) {
ctx . AddVariationDependencies ( nil , dependencyTag , names ... )
2020-02-10 14:37:10 +01:00
}
func ( s * sdkLibrarySdkMemberType ) IsInstance ( module android . Module ) bool {
_ , ok := module . ( * SdkLibrary )
return ok
}
func ( s * sdkLibrarySdkMemberType ) AddPrebuiltModule ( ctx android . SdkMemberContext , member android . SdkMember ) android . BpModule {
return ctx . SnapshotBuilder ( ) . AddPrebuiltModule ( member , "java_sdk_library_import" )
}
func ( s * sdkLibrarySdkMemberType ) CreateVariantPropertiesStruct ( ) android . SdkMemberProperties {
return & sdkLibrarySdkMemberProperties { }
}
2021-04-28 00:20:26 +02:00
var javaSdkLibrarySdkMemberType = & sdkLibrarySdkMemberType {
android . SdkMemberTypeBase {
PropertyName : "java_sdk_libs" ,
SupportsSdk : true ,
} ,
}
2020-02-10 14:37:10 +01:00
type sdkLibrarySdkMemberProperties struct {
android . SdkMemberPropertiesBase
2022-09-22 17:24:46 +02:00
// Stem name for files in the sdk snapshot.
//
// This is used to construct the path names of various sdk library files in the sdk snapshot to
// make sure that they match the finalized versions of those files in prebuilts/sdk.
//
// This property is marked as keep so that it will be kept in all instances of this struct, will
// not be cleared but will be copied to common structs. That is needed because this field is used
// to construct many file names for other parts of this struct and so it needs to be present in
// all structs. If it was not marked as keep then it would be cleared in some structs and so would
// be unavailable for generating file names if there were other properties that were still set.
Stem string ` sdk:"keep" `
2020-02-10 14:37:10 +01:00
// Scope to per scope properties.
2022-01-27 17:39:06 +01:00
Scopes map [ * apiScope ] * scopeProperties
2020-02-10 14:37:10 +01:00
2020-04-09 01:10:17 +02:00
// The Java stubs source files.
Stub_srcs [ ] string
2020-05-13 17:54:55 +02:00
// The naming scheme.
Naming_scheme * string
2020-05-26 21:57:10 +02:00
// True if the java_sdk_library_import is for a shared library, false
// otherwise.
Shared_library * bool
2020-09-11 12:55:00 +02:00
2021-04-16 18:21:36 +02:00
// True if the stub imports should produce dex jars.
Compile_dex * bool
2020-09-11 12:55:00 +02:00
// The paths to the doctag files to add to the prebuilt.
Doctag_paths android . Paths
2021-07-15 15:14:41 +02:00
Permitted_packages [ ] string
2021-09-07 19:21:59 +02:00
// Signals that this shared library is part of the bootclasspath starting
// on the version indicated in this attribute.
//
// This will make platforms at this level and above to ignore
// <uses-library> tags with this library name because the library is already
// available
On_bootclasspath_since * string
// Signals that this shared library was part of the bootclasspath before
// (but not including) the version indicated in this attribute.
//
// The system will automatically add a <uses-library> tag with this library to
// apps that target any SDK less than the version indicated in this attribute.
On_bootclasspath_before * string
// Indicates that PackageManager should ignore this shared library if the
// platform is below the version indicated in this attribute.
//
// This means that the device won't recognise this library as installed.
Min_device_sdk * string
// Indicates that PackageManager should ignore this shared library if the
// platform is above the version indicated in this attribute.
//
// This means that the device won't recognise this library as installed.
Max_device_sdk * string
2023-02-08 17:09:24 +01:00
DexPreoptProfileGuided * bool ` supported_build_releases:"UpsideDownCake+" `
2020-02-10 14:37:10 +01:00
}
type scopeProperties struct {
2020-04-09 02:08:11 +02:00
Jars android . Paths
StubsSrcJar android . Path
CurrentApiFile android . Path
RemovedApiFile android . Path
2022-02-10 14:06:54 +01:00
AnnotationsZip android . Path ` supported_build_releases:"Tiramisu+" `
2020-04-09 02:08:11 +02:00
SdkVersion string
2020-02-10 14:37:10 +01:00
}
func ( s * sdkLibrarySdkMemberProperties ) PopulateFromVariant ( ctx android . SdkMemberContext , variant android . Module ) {
sdk := variant . ( * SdkLibrary )
2022-09-22 17:24:46 +02:00
// Copy the stem name for files in the sdk snapshot.
s . Stem = sdk . distStem ( )
2022-01-27 17:39:06 +01:00
s . Scopes = make ( map [ * apiScope ] * scopeProperties )
2020-02-10 14:37:10 +01:00
for _ , apiScope := range allApiScopes {
2020-05-20 12:52:25 +02:00
paths := sdk . findScopePaths ( apiScope )
if paths == nil {
continue
}
2020-02-10 14:37:10 +01:00
jars := paths . stubsImplPath
if len ( jars ) > 0 {
properties := scopeProperties { }
properties . Jars = jars
2020-05-12 16:52:55 +02:00
properties . SdkVersion = sdk . sdkVersionForStubsLibrary ( ctx . SdkModuleContext ( ) , apiScope )
2020-05-20 17:18:00 +02:00
properties . StubsSrcJar = paths . stubsSrcJar . Path ( )
2020-06-19 19:39:55 +02:00
if paths . currentApiFilePath . Valid ( ) {
properties . CurrentApiFile = paths . currentApiFilePath . Path ( )
}
if paths . removedApiFilePath . Valid ( ) {
properties . RemovedApiFile = paths . removedApiFilePath . Path ( )
}
2021-09-21 16:25:12 +02:00
// The annotations zip is only available for modules that set annotations_enabled: true.
if paths . annotationsZip . Valid ( ) {
properties . AnnotationsZip = paths . annotationsZip . Path ( )
}
2022-01-27 17:39:06 +01:00
s . Scopes [ apiScope ] = & properties
2020-02-10 14:37:10 +01:00
}
}
2020-05-15 21:37:11 +02:00
s . Naming_scheme = sdk . commonSdkLibraryProperties . Naming_scheme
2020-05-26 21:57:10 +02:00
s . Shared_library = proptools . BoolPtr ( sdk . sharedLibrary ( ) )
2021-04-16 18:21:36 +02:00
s . Compile_dex = sdk . dexProperties . Compile_dex
2020-09-11 12:55:00 +02:00
s . Doctag_paths = sdk . doctagPaths
2021-07-15 15:14:41 +02:00
s . Permitted_packages = sdk . PermittedPackagesForUpdatableBootJars ( )
2021-09-07 19:21:59 +02:00
s . On_bootclasspath_since = sdk . commonSdkLibraryProperties . On_bootclasspath_since
s . On_bootclasspath_before = sdk . commonSdkLibraryProperties . On_bootclasspath_before
s . Min_device_sdk = sdk . commonSdkLibraryProperties . Min_device_sdk
s . Max_device_sdk = sdk . commonSdkLibraryProperties . Max_device_sdk
2023-02-08 17:09:24 +01:00
if sdk . dexpreopter . dexpreoptProperties . Dex_preopt_result . Profile_guided {
s . DexPreoptProfileGuided = proptools . BoolPtr ( true )
}
2020-02-10 14:37:10 +01:00
}
func ( s * sdkLibrarySdkMemberProperties ) AddToPropertySet ( ctx android . SdkMemberContext , propertySet android . BpPropertySet ) {
2020-05-13 17:54:55 +02:00
if s . Naming_scheme != nil {
propertySet . AddProperty ( "naming_scheme" , proptools . String ( s . Naming_scheme ) )
}
2020-05-26 21:57:10 +02:00
if s . Shared_library != nil {
propertySet . AddProperty ( "shared_library" , * s . Shared_library )
}
2021-04-16 18:21:36 +02:00
if s . Compile_dex != nil {
propertySet . AddProperty ( "compile_dex" , * s . Compile_dex )
}
2021-07-15 15:14:41 +02:00
if len ( s . Permitted_packages ) > 0 {
propertySet . AddProperty ( "permitted_packages" , s . Permitted_packages )
}
2023-02-08 17:09:24 +01:00
dexPreoptSet := propertySet . AddPropertySet ( "dex_preopt" )
if s . DexPreoptProfileGuided != nil {
dexPreoptSet . AddProperty ( "profile_guided" , proptools . Bool ( s . DexPreoptProfileGuided ) )
}
2020-05-13 17:54:55 +02:00
2022-09-22 17:24:46 +02:00
stem := s . Stem
2020-02-10 14:37:10 +01:00
for _ , apiScope := range allApiScopes {
if properties , ok := s . Scopes [ apiScope ] ; ok {
2020-05-13 20:19:49 +02:00
scopeSet := propertySet . AddPropertySet ( apiScope . propertyName )
2020-02-10 14:37:10 +01:00
2022-05-16 15:10:47 +02:00
scopeDir := apiScope . snapshotRelativeDir ( )
2020-04-09 01:10:17 +02:00
2020-02-10 14:37:10 +01:00
var jars [ ] string
for _ , p := range properties . Jars {
2022-09-22 17:24:46 +02:00
dest := filepath . Join ( scopeDir , stem + "-stubs.jar" )
2020-02-10 14:37:10 +01:00
ctx . SnapshotBuilder ( ) . CopyToSnapshot ( p , dest )
jars = append ( jars , dest )
}
scopeSet . AddProperty ( "jars" , jars )
2021-05-13 00:13:22 +02:00
if ctx . SdkModuleContext ( ) . Config ( ) . IsEnvTrue ( "SOONG_SDK_SNAPSHOT_USE_SRCJAR" ) {
// Copy the stubs source jar into the snapshot zip as is.
2022-09-22 17:24:46 +02:00
srcJarSnapshotPath := filepath . Join ( scopeDir , stem + ".srcjar" )
2021-05-13 00:13:22 +02:00
ctx . SnapshotBuilder ( ) . CopyToSnapshot ( properties . StubsSrcJar , srcJarSnapshotPath )
scopeSet . AddProperty ( "stub_srcs" , [ ] string { srcJarSnapshotPath } )
} else {
// Merge the stubs source jar into the snapshot zip so that when it is unpacked
// the source files are also unpacked.
2022-09-22 17:24:46 +02:00
snapshotRelativeDir := filepath . Join ( scopeDir , stem + "_stub_sources" )
2021-05-13 00:13:22 +02:00
ctx . SnapshotBuilder ( ) . UnzipToSnapshot ( properties . StubsSrcJar , snapshotRelativeDir )
scopeSet . AddProperty ( "stub_srcs" , [ ] string { snapshotRelativeDir } )
}
2020-04-09 01:10:17 +02:00
2020-04-09 02:08:11 +02:00
if properties . CurrentApiFile != nil {
2022-09-22 17:24:46 +02:00
currentApiSnapshotPath := apiScope . snapshotRelativeCurrentApiTxtPath ( stem )
2020-04-09 02:08:11 +02:00
ctx . SnapshotBuilder ( ) . CopyToSnapshot ( properties . CurrentApiFile , currentApiSnapshotPath )
scopeSet . AddProperty ( "current_api" , currentApiSnapshotPath )
}
if properties . RemovedApiFile != nil {
2022-09-22 17:24:46 +02:00
removedApiSnapshotPath := apiScope . snapshotRelativeRemovedApiTxtPath ( stem )
2020-06-02 14:00:02 +02:00
ctx . SnapshotBuilder ( ) . CopyToSnapshot ( properties . RemovedApiFile , removedApiSnapshotPath )
2020-04-09 02:08:11 +02:00
scopeSet . AddProperty ( "removed_api" , removedApiSnapshotPath )
}
2021-09-21 16:25:12 +02:00
if properties . AnnotationsZip != nil {
2022-09-22 17:24:46 +02:00
annotationsSnapshotPath := filepath . Join ( scopeDir , stem + "_annotations.zip" )
2021-09-21 16:25:12 +02:00
ctx . SnapshotBuilder ( ) . CopyToSnapshot ( properties . AnnotationsZip , annotationsSnapshotPath )
scopeSet . AddProperty ( "annotations" , annotationsSnapshotPath )
}
2020-02-10 14:37:10 +01:00
if properties . SdkVersion != "" {
scopeSet . AddProperty ( "sdk_version" , properties . SdkVersion )
}
}
}
2020-09-11 12:55:00 +02:00
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 )
}
2020-02-10 14:37:10 +01:00
}