2021-03-29 23:18:45 +02:00
// Copyright 2021 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 (
2021-04-12 15:15:22 +02:00
"fmt"
2021-03-29 23:18:45 +02:00
"android/soong/android"
"android/soong/dexpreopt"
)
func init ( ) {
registerPlatformBootclasspathBuildComponents ( android . InitRegistrationContext )
}
func registerPlatformBootclasspathBuildComponents ( ctx android . RegistrationContext ) {
2023-05-16 02:58:37 +02:00
ctx . RegisterParallelSingletonModuleType ( "platform_bootclasspath" , platformBootclasspathFactory )
2021-03-22 23:09:42 +01:00
}
2021-04-26 21:05:39 +02:00
// The tags used for the dependencies between the platform bootclasspath and any configured boot
// jars.
var (
2021-07-21 15:23:52 +02:00
platformBootclasspathArtBootJarDepTag = bootclasspathDependencyTag { name : "art-boot-jar" }
platformBootclasspathBootJarDepTag = bootclasspathDependencyTag { name : "platform-boot-jar" }
platformBootclasspathApexBootJarDepTag = bootclasspathDependencyTag { name : "apex-boot-jar" }
2021-04-26 21:05:39 +02:00
)
2021-03-22 23:09:42 +01:00
2021-03-29 23:18:45 +02:00
type platformBootclasspathModule struct {
2021-04-29 11:34:11 +02:00
android . SingletonModuleBase
2021-04-07 16:17:14 +02:00
ClasspathFragmentBase
2021-03-22 23:09:42 +01:00
2021-04-07 21:35:11 +02:00
properties platformBootclasspathProperties
2021-03-22 23:09:42 +01:00
// The apex:module pairs obtained from the configured modules.
configuredModules [ ] android . Module
2021-04-07 21:35:11 +02:00
// The apex:module pairs obtained from the fragments.
fragments [ ] android . Module
2021-04-12 15:15:22 +02:00
// Path to the monolithic hiddenapi-flags.csv file.
2021-04-13 14:02:29 +02:00
hiddenAPIFlagsCSV android . OutputPath
2021-04-12 15:15:22 +02:00
// Path to the monolithic hiddenapi-index.csv file.
2021-04-13 14:02:29 +02:00
hiddenAPIIndexCSV android . OutputPath
2021-04-12 15:15:22 +02:00
// Path to the monolithic hiddenapi-unsupported.csv file.
2021-04-13 14:02:29 +02:00
hiddenAPIMetadataCSV android . OutputPath
2023-09-21 18:23:20 +02:00
// Path to a srcjar containing all the transitive sources of the bootclasspath.
srcjar android . OutputPath
2021-04-07 21:35:11 +02:00
}
type platformBootclasspathProperties struct {
2021-04-22 12:49:41 +02:00
BootclasspathFragmentsDepsProperties
2021-04-08 21:12:41 +02:00
2022-07-27 18:16:54 +02:00
HiddenAPIFlagFileProperties
2021-03-29 23:18:45 +02:00
}
2021-04-29 11:34:11 +02:00
func platformBootclasspathFactory ( ) android . SingletonModule {
2021-03-29 23:18:45 +02:00
m := & platformBootclasspathModule { }
2021-04-07 21:35:11 +02:00
m . AddProperties ( & m . properties )
2021-04-29 12:50:26 +02:00
initClasspathFragment ( m , BOOTCLASSPATH )
2021-03-29 23:18:45 +02:00
android . InitAndroidArchModule ( m , android . DeviceSupported , android . MultilibCommon )
return m
}
2021-04-12 15:15:22 +02:00
var _ android . OutputFileProducer = ( * platformBootclasspathModule ) ( nil )
2021-04-07 16:17:14 +02:00
func ( b * platformBootclasspathModule ) AndroidMkEntries ( ) ( entries [ ] android . AndroidMkEntries ) {
entries = append ( entries , android . AndroidMkEntries {
Class : "FAKE" ,
// Need at least one output file in order for this to take effect.
OutputFile : android . OptionalPathForPath ( b . hiddenAPIFlagsCSV ) ,
Include : "$(BUILD_PHONY_PACKAGE)" ,
} )
2021-05-06 14:21:15 +02:00
entries = append ( entries , b . classpathFragmentBase ( ) . androidMkEntries ( ) ... )
2021-04-07 16:17:14 +02:00
return
2021-04-12 15:15:22 +02:00
}
// Make the hidden API files available from the platform-bootclasspath module.
func ( b * platformBootclasspathModule ) OutputFiles ( tag string ) ( android . Paths , error ) {
switch tag {
case "hiddenapi-flags.csv" :
return android . Paths { b . hiddenAPIFlagsCSV } , nil
case "hiddenapi-index.csv" :
return android . Paths { b . hiddenAPIIndexCSV } , nil
case "hiddenapi-metadata.csv" :
return android . Paths { b . hiddenAPIMetadataCSV } , nil
2023-09-21 18:23:20 +02:00
case ".srcjar" :
return android . Paths { b . srcjar } , nil
2021-04-12 15:15:22 +02:00
}
return nil , fmt . Errorf ( "unknown tag %s" , tag )
}
2021-03-29 23:18:45 +02:00
func ( b * platformBootclasspathModule ) DepsMutator ( ctx android . BottomUpMutatorContext ) {
Use the correct bootjars for hiddneapi when multiple prebuilts exist
hiddenapi processing require boot jars from apexes to determine the full
set of methods available at runtime.
When building with prebuilts, this comes via
java_import/java_sdk_library_import, which acts as a hook for
prebuilt_apex/apex_set. If we have multiple apexes in the tree, this
hook becomes 1:many. This CL prepares platform_bootclasspath to select the right
deapexerd .jar files when mutliple prebuilts exist.
Implementation details
- Create a dependency edge from platform_bootclasspath to
all_apex_contributions (DepsMutator)
- For every boot jar, query all_apex_contributions to get the path to
dexjar file (GenerateAndroidBuildActions)
Some other important details
- This CL does not drop the old mechanism to get the dex file (i.e. by
creating a dep on java_library). Once all mainline
modules have been flagged using apex_contributions, the old mechanism
will be dropped
- This CL has a functional change when building with source apexes. At
ToT, the unecoded hiddenapi dex jar is used for package check and
generating the monolithic stub file. After this change, the hiddenapi
encoded file will be used for these operations.
This should be fine since the
package and dex signature do not change across the encoded and
unencoded dex file. In fact, we already have a split today. When
building with prebuilts, we use the encoded dex file. When building
with source, we use the unecoded dex file.
Test: Added a unit test
Test: Manual testing in internal described below
- lunch cf_x86_64_phone-next-userdebug
- flagged com.google.android.adservices using apex_contributions
- aninja -t commands out/soong/hiddenapi/hiddenapi-stubs-flags.txt # no
diff before and after
Bug: 308790777
Change-Id: I72c70f0ae1b587679203ea254c9c12a48e7aa782
2023-12-20 21:13:34 +01:00
// Create a dependency on all_apex_contributions to determine the selected mainline module
ctx . AddDependency ( ctx . Module ( ) , apexContributionsMetadataDepTag , "all_apex_contributions" )
2021-04-21 15:10:42 +02:00
b . hiddenAPIDepsMutator ( ctx )
2023-05-08 18:28:38 +02:00
if ! dexpreopt . IsDex2oatNeeded ( ctx ) {
2023-05-05 17:03:24 +02:00
return
}
2021-03-29 23:18:45 +02:00
// Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
// path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
dexpreopt . RegisterToolDeps ( ctx )
}
2021-04-21 15:10:42 +02:00
func ( b * platformBootclasspathModule ) hiddenAPIDepsMutator ( ctx android . BottomUpMutatorContext ) {
2023-07-20 13:19:04 +02:00
if ctx . Config ( ) . DisableHiddenApiChecks ( ) {
2021-04-21 15:10:42 +02:00
return
}
// Add dependencies onto the stub lib modules.
2021-06-18 19:14:25 +02:00
apiLevelToStubLibModules := hiddenAPIComputeMonolithicStubLibModules ( ctx . Config ( ) )
hiddenAPIAddStubLibDependencies ( ctx , apiLevelToStubLibModules )
2021-04-21 15:10:42 +02:00
}
2021-04-22 13:08:59 +02:00
func ( b * platformBootclasspathModule ) BootclasspathDepsMutator ( ctx android . BottomUpMutatorContext ) {
2023-07-13 12:03:38 +02:00
// Add dependencies on all the ART jars.
global := dexpreopt . GetGlobalConfig ( ctx )
Use the correct bootjars for hiddneapi when multiple prebuilts exist
hiddenapi processing require boot jars from apexes to determine the full
set of methods available at runtime.
When building with prebuilts, this comes via
java_import/java_sdk_library_import, which acts as a hook for
prebuilt_apex/apex_set. If we have multiple apexes in the tree, this
hook becomes 1:many. This CL prepares platform_bootclasspath to select the right
deapexerd .jar files when mutliple prebuilts exist.
Implementation details
- Create a dependency edge from platform_bootclasspath to
all_apex_contributions (DepsMutator)
- For every boot jar, query all_apex_contributions to get the path to
dexjar file (GenerateAndroidBuildActions)
Some other important details
- This CL does not drop the old mechanism to get the dex file (i.e. by
creating a dep on java_library). Once all mainline
modules have been flagged using apex_contributions, the old mechanism
will be dropped
- This CL has a functional change when building with source apexes. At
ToT, the unecoded hiddenapi dex jar is used for package check and
generating the monolithic stub file. After this change, the hiddenapi
encoded file will be used for these operations.
This should be fine since the
package and dex signature do not change across the encoded and
unencoded dex file. In fact, we already have a split today. When
building with prebuilts, we use the encoded dex file. When building
with source, we use the unecoded dex file.
Test: Added a unit test
Test: Manual testing in internal described below
- lunch cf_x86_64_phone-next-userdebug
- flagged com.google.android.adservices using apex_contributions
- aninja -t commands out/soong/hiddenapi/hiddenapi-stubs-flags.txt # no
diff before and after
Bug: 308790777
Change-Id: I72c70f0ae1b587679203ea254c9c12a48e7aa782
2023-12-20 21:13:34 +01:00
addDependenciesOntoSelectedBootImageApexes ( ctx , "com.android.art" )
// TODO: b/308174306 - Remove the mechanism of depending on the java_sdk_library(_import) directly
2023-07-13 12:03:38 +02:00
addDependenciesOntoBootImageModules ( ctx , global . ArtApexJars , platformBootclasspathArtBootJarDepTag )
2021-03-22 23:09:42 +01:00
2023-07-13 12:03:38 +02:00
// Add dependencies on all the non-updatable jars, which are on the platform or in non-updatable
// APEXes.
2023-05-10 19:38:34 +02:00
addDependenciesOntoBootImageModules ( ctx , b . platformJars ( ctx ) , platformBootclasspathBootJarDepTag )
2021-03-22 23:09:42 +01:00
2023-07-13 12:03:38 +02:00
// Add dependencies on all the updatable jars, except the ART jars.
2021-07-21 15:23:52 +02:00
apexJars := dexpreopt . GetGlobalConfig ( ctx ) . ApexBootJars
Use the correct bootjars for hiddneapi when multiple prebuilts exist
hiddenapi processing require boot jars from apexes to determine the full
set of methods available at runtime.
When building with prebuilts, this comes via
java_import/java_sdk_library_import, which acts as a hook for
prebuilt_apex/apex_set. If we have multiple apexes in the tree, this
hook becomes 1:many. This CL prepares platform_bootclasspath to select the right
deapexerd .jar files when mutliple prebuilts exist.
Implementation details
- Create a dependency edge from platform_bootclasspath to
all_apex_contributions (DepsMutator)
- For every boot jar, query all_apex_contributions to get the path to
dexjar file (GenerateAndroidBuildActions)
Some other important details
- This CL does not drop the old mechanism to get the dex file (i.e. by
creating a dep on java_library). Once all mainline
modules have been flagged using apex_contributions, the old mechanism
will be dropped
- This CL has a functional change when building with source apexes. At
ToT, the unecoded hiddenapi dex jar is used for package check and
generating the monolithic stub file. After this change, the hiddenapi
encoded file will be used for these operations.
This should be fine since the
package and dex signature do not change across the encoded and
unencoded dex file. In fact, we already have a split today. When
building with prebuilts, we use the encoded dex file. When building
with source, we use the unecoded dex file.
Test: Added a unit test
Test: Manual testing in internal described below
- lunch cf_x86_64_phone-next-userdebug
- flagged com.google.android.adservices using apex_contributions
- aninja -t commands out/soong/hiddenapi/hiddenapi-stubs-flags.txt # no
diff before and after
Bug: 308790777
Change-Id: I72c70f0ae1b587679203ea254c9c12a48e7aa782
2023-12-20 21:13:34 +01:00
apexes := [ ] string { }
for i := 0 ; i < apexJars . Len ( ) ; i ++ {
apexes = append ( apexes , apexJars . Apex ( i ) )
}
addDependenciesOntoSelectedBootImageApexes ( ctx , android . FirstUniqueStrings ( apexes ) ... )
// TODO: b/308174306 - Remove the mechanism of depending on the java_sdk_library(_import) directly
2021-07-21 15:23:52 +02:00
addDependenciesOntoBootImageModules ( ctx , apexJars , platformBootclasspathApexBootJarDepTag )
2021-04-07 21:35:11 +02:00
2021-04-22 13:08:59 +02:00
// Add dependencies on all the fragments.
b . properties . BootclasspathFragmentsDepsProperties . addDependenciesOntoFragments ( ctx )
2021-03-22 23:09:42 +01:00
}
2021-04-26 21:05:39 +02:00
func addDependenciesOntoBootImageModules ( ctx android . BottomUpMutatorContext , modules android . ConfiguredJarList , tag bootclasspathDependencyTag ) {
2021-03-22 23:09:42 +01:00
for i := 0 ; i < modules . Len ( ) ; i ++ {
apex := modules . Apex ( i )
name := modules . Jar ( i )
2021-04-26 21:05:39 +02:00
addDependencyOntoApexModulePair ( ctx , apex , name , tag )
2021-03-22 23:09:42 +01:00
}
}
2021-04-29 11:34:11 +02:00
// GenerateSingletonBuildActions does nothing and must never do anything.
//
// This module only implements android.SingletonModule so that it can implement
// android.SingletonMakeVarsProvider.
func ( b * platformBootclasspathModule ) GenerateSingletonBuildActions ( android . SingletonContext ) {
// Keep empty
}
func ( d * platformBootclasspathModule ) MakeVars ( ctx android . MakeVarsContext ) {
2021-04-29 14:50:01 +02:00
d . generateHiddenApiMakeVars ( ctx )
2021-04-29 11:34:11 +02:00
}
2021-03-29 23:18:45 +02:00
func ( b * platformBootclasspathModule ) GenerateAndroidBuildActions ( ctx android . ModuleContext ) {
2021-07-21 15:23:52 +02:00
// Gather all the dependencies from the art, platform, and apex boot jars.
2021-04-26 21:05:39 +02:00
artModules := gatherApexModulePairDepsWithTag ( ctx , platformBootclasspathArtBootJarDepTag )
2021-07-21 15:23:52 +02:00
platformModules := gatherApexModulePairDepsWithTag ( ctx , platformBootclasspathBootJarDepTag )
apexModules := gatherApexModulePairDepsWithTag ( ctx , platformBootclasspathApexBootJarDepTag )
2021-04-26 21:05:39 +02:00
// Concatenate them all, in order as they would appear on the bootclasspath.
var allModules [ ] android . Module
allModules = append ( allModules , artModules ... )
2021-07-21 15:23:52 +02:00
allModules = append ( allModules , platformModules ... )
allModules = append ( allModules , apexModules ... )
2021-04-26 21:05:39 +02:00
b . configuredModules = allModules
2023-09-20 15:41:30 +02:00
var transitiveSrcFiles android . Paths
for _ , module := range allModules {
2023-12-13 22:47:44 +01:00
depInfo , _ := android . OtherModuleProvider ( ctx , module , JavaInfoProvider )
2023-09-20 15:41:30 +02:00
if depInfo . TransitiveSrcFiles != nil {
transitiveSrcFiles = append ( transitiveSrcFiles , depInfo . TransitiveSrcFiles . ToList ( ) ... )
}
}
jarArgs := resourcePathsToJarArgs ( transitiveSrcFiles )
jarArgs = append ( jarArgs , "-srcjar" ) // Move srcfiles to the right package
2023-09-21 18:23:20 +02:00
b . srcjar = android . PathForModuleOut ( ctx , ctx . ModuleName ( ) + "-transitive.srcjar" ) . OutputPath
TransformResourcesToJar ( ctx , b . srcjar , jarArgs , transitiveSrcFiles )
2023-09-20 15:41:30 +02:00
2021-04-26 21:05:39 +02:00
// Gather all the fragments dependencies.
2021-04-28 22:16:02 +02:00
b . fragments = gatherApexModulePairDepsWithTag ( ctx , bootclasspathFragmentDepTag )
2021-03-22 23:09:42 +01:00
2021-04-27 13:42:20 +02:00
// Check the configuration of the boot modules.
// ART modules are checked by the art-bootclasspath-fragment.
2021-07-21 15:23:52 +02:00
b . checkPlatformModules ( ctx , platformModules )
b . checkApexModules ( ctx , apexModules )
2021-04-27 13:42:20 +02:00
2021-05-07 00:38:10 +02:00
b . generateClasspathProtoBuildActions ( ctx )
2021-06-07 20:28:15 +02:00
bootDexJarByModule := b . generateHiddenAPIBuildActions ( ctx , b . configuredModules , b . fragments )
buildRuleForBootJarsPackageCheck ( ctx , bootDexJarByModule )
2021-03-29 23:18:45 +02:00
}
2021-05-07 00:38:10 +02:00
// Generate classpaths.proto config
func ( b * platformBootclasspathModule ) generateClasspathProtoBuildActions ( ctx android . ModuleContext ) {
2021-06-15 18:49:10 +02:00
configuredJars := b . configuredJars ( ctx )
2021-05-07 00:38:10 +02:00
// ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH
2021-06-15 18:49:10 +02:00
classpathJars := configuredJarListToClasspathJars ( ctx , configuredJars , BOOTCLASSPATH , DEX2OATBOOTCLASSPATH )
b . classpathFragmentBase ( ) . generateClasspathProtoBuildActions ( ctx , configuredJars , classpathJars )
2021-05-07 00:38:10 +02:00
}
2021-06-15 17:21:17 +02:00
func ( b * platformBootclasspathModule ) configuredJars ( ctx android . ModuleContext ) android . ConfiguredJarList {
2021-06-15 18:49:10 +02:00
// Include all non APEX jars
2023-05-10 19:38:34 +02:00
jars := b . platformJars ( ctx )
2021-06-15 18:49:10 +02:00
// Include jars from APEXes that don't populate their classpath proto config.
2021-07-21 15:23:52 +02:00
remainingJars := dexpreopt . GetGlobalConfig ( ctx ) . ApexBootJars
2021-06-15 18:49:10 +02:00
for _ , fragment := range b . fragments {
2023-12-13 22:47:44 +01:00
info , _ := android . OtherModuleProvider ( ctx , fragment , ClasspathFragmentProtoContentInfoProvider )
2021-06-15 18:49:10 +02:00
if info . ClasspathFragmentProtoGenerated {
remainingJars = remainingJars . RemoveList ( info . ClasspathFragmentProtoContents )
}
}
for i := 0 ; i < remainingJars . Len ( ) ; i ++ {
jars = jars . Append ( remainingJars . Apex ( i ) , remainingJars . Jar ( i ) )
}
return jars
2021-05-07 00:38:10 +02:00
}
2023-05-10 19:38:34 +02:00
func ( b * platformBootclasspathModule ) platformJars ( ctx android . PathContext ) android . ConfiguredJarList {
2023-07-13 12:03:38 +02:00
global := dexpreopt . GetGlobalConfig ( ctx )
return global . BootJars . RemoveList ( global . ArtApexJars )
2023-05-10 19:38:34 +02:00
}
2021-07-21 15:23:52 +02:00
// checkPlatformModules ensures that the non-updatable modules supplied are not part of an
// apex module.
func ( b * platformBootclasspathModule ) checkPlatformModules ( ctx android . ModuleContext , modules [ ] android . Module ) {
// TODO(satayev): change this check to only allow core-icu4j, all apex jars should not be here.
2021-04-27 13:42:20 +02:00
for _ , m := range modules {
2023-12-13 22:47:44 +01:00
apexInfo , _ := android . OtherModuleProvider ( ctx , m , android . ApexInfoProvider )
2021-04-27 13:42:20 +02:00
fromUpdatableApex := apexInfo . Updatable
if fromUpdatableApex {
// error: this jar is part of an updatable apex
2023-05-10 19:38:34 +02:00
ctx . ModuleErrorf ( "module %q from updatable apexes %q is not allowed in the platform bootclasspath" , ctx . OtherModuleName ( m ) , apexInfo . InApexVariants )
2021-04-27 13:42:20 +02:00
} else {
// ok: this jar is part of the platform or a non-updatable apex
}
}
}
2021-07-21 15:23:52 +02:00
// checkApexModules ensures that the apex modules supplied are not from the platform.
func ( b * platformBootclasspathModule ) checkApexModules ( ctx android . ModuleContext , modules [ ] android . Module ) {
2021-04-27 13:42:20 +02:00
for _ , m := range modules {
2023-12-13 22:47:44 +01:00
apexInfo , _ := android . OtherModuleProvider ( ctx , m , android . ApexInfoProvider )
2021-04-27 13:42:20 +02:00
fromUpdatableApex := apexInfo . Updatable
if fromUpdatableApex {
// ok: this jar is part of an updatable apex
} else {
name := ctx . OtherModuleName ( m )
if apexInfo . IsForPlatform ( ) {
2021-05-19 10:36:09 +02:00
// If AlwaysUsePrebuiltSdks() returns true then it is possible that the updatable list will
// include platform variants of a prebuilt module due to workarounds elsewhere. In that case
// do not treat this as an error.
// TODO(b/179354495): Always treat this as an error when migration to bootclasspath_fragment
// modules is complete.
if ! ctx . Config ( ) . AlwaysUsePrebuiltSdks ( ) {
// error: this jar is part of the platform
2021-07-21 15:23:52 +02:00
ctx . ModuleErrorf ( "module %q from platform is not allowed in the apex boot jars list" , name )
2021-05-19 10:36:09 +02:00
}
2021-04-27 13:42:20 +02:00
} else {
// TODO(b/177892522): Treat this as an error.
// Cannot do that at the moment because framework-wifi and framework-tethering are in the
2021-07-21 15:23:52 +02:00
// PRODUCT_APEX_BOOT_JARS but not marked as updatable in AOSP.
2021-04-27 13:42:20 +02:00
}
}
}
}
2021-04-08 21:12:41 +02:00
// generateHiddenAPIBuildActions generates all the hidden API related build rules.
2021-06-07 20:28:15 +02:00
func ( b * platformBootclasspathModule ) generateHiddenAPIBuildActions ( ctx android . ModuleContext , modules [ ] android . Module , fragments [ ] android . Module ) bootDexJarByModule {
2021-04-08 21:12:41 +02:00
2021-04-13 13:25:01 +02:00
// Save the paths to the monolithic files for retrieval via OutputFiles().
b . hiddenAPIFlagsCSV = hiddenAPISingletonPaths ( ctx ) . flags
b . hiddenAPIIndexCSV = hiddenAPISingletonPaths ( ctx ) . index
b . hiddenAPIMetadataCSV = hiddenAPISingletonPaths ( ctx ) . metadata
2021-04-12 15:15:22 +02:00
2021-06-21 16:03:11 +02:00
bootDexJarByModule := extractBootDexJarsFromModules ( ctx , modules )
2023-07-20 13:19:04 +02:00
// Don't run any hiddenapi rules if hidden api checks are disabled. This is a performance
2021-04-13 14:02:29 +02:00
// optimization that can be used to reduce the incremental build time but as its name suggests it
// can be unsafe to use, e.g. when the changes affect anything that goes on the bootclasspath.
2023-07-20 13:19:04 +02:00
if ctx . Config ( ) . DisableHiddenApiChecks ( ) {
2021-04-13 14:02:29 +02:00
paths := android . OutputPaths { b . hiddenAPIFlagsCSV , b . hiddenAPIIndexCSV , b . hiddenAPIMetadataCSV }
for _ , path := range paths {
ctx . Build ( pctx , android . BuildParams {
Rule : android . Touch ,
Output : path ,
} )
}
2021-06-21 16:03:11 +02:00
return bootDexJarByModule
2021-04-13 14:02:29 +02:00
}
2021-06-16 02:42:33 +02:00
// Construct a list of ClasspathElement objects from the modules and fragments.
classpathElements := CreateClasspathElements ( ctx , modules , fragments )
monolithicInfo := b . createAndProvideMonolithicHiddenAPIInfo ( ctx , classpathElements )
// Extract the classes jars only from those libraries that do not have corresponding fragments as
// the fragments will have already provided the flags that are needed.
classesJars := monolithicInfo . ClassesJars
2021-06-24 00:20:43 +02:00
// Create the input to pass to buildRuleToGenerateHiddenAPIStubFlagsFile
2021-05-21 23:18:49 +02:00
input := newHiddenAPIFlagInput ( )
// Gather stub library information from the dependencies on modules provided by
// hiddenAPIComputeMonolithicStubLibModules.
input . gatherStubLibInfo ( ctx , nil )
// Use the flag files from this module and all the fragments.
input . FlagFilesByCategory = monolithicInfo . FlagsFilesByCategory
2021-04-08 21:12:41 +02:00
2021-05-14 11:38:00 +02:00
// Generate the monolithic stub-flags.csv file.
stubFlags := hiddenAPISingletonPaths ( ctx ) . stubFlags
2021-07-21 18:38:47 +02:00
buildRuleToGenerateHiddenAPIStubFlagsFile ( ctx , "platform-bootclasspath-monolithic-hiddenapi-stub-flags" , "monolithic hidden API stub flags" , stubFlags , bootDexJarByModule . bootDexJars ( ) , input , monolithicInfo . StubFlagSubsets )
2021-04-21 15:10:42 +02:00
2021-05-14 11:38:00 +02:00
// Generate the annotation-flags.csv file from all the module annotations.
2021-06-07 22:36:01 +02:00
annotationFlags := android . PathForModuleOut ( ctx , "hiddenapi-monolithic" , "annotation-flags-from-classes.csv" )
buildRuleToGenerateAnnotationFlags ( ctx , "intermediate hidden API flags" , classesJars , stubFlags , annotationFlags )
// Generate the monolithic hiddenapi-flags.csv file.
//
// Use annotation flags generated directly from the classes jars as well as annotation flag files
// provided by prebuilts.
allAnnotationFlagFiles := android . Paths { annotationFlags }
allAnnotationFlagFiles = append ( allAnnotationFlagFiles , monolithicInfo . AnnotationFlagsPaths ... )
2021-05-14 11:38:00 +02:00
allFlags := hiddenAPISingletonPaths ( ctx ) . flags
2021-07-21 18:38:47 +02:00
buildRuleToGenerateHiddenApiFlags ( ctx , "hiddenAPIFlagsFile" , "monolithic hidden API flags" , allFlags , stubFlags , allAnnotationFlagFiles , monolithicInfo . FlagsFilesByCategory , monolithicInfo . FlagSubsets , android . OptionalPath { } )
2021-04-13 01:14:38 +02:00
2021-05-14 11:38:00 +02:00
// Generate an intermediate monolithic hiddenapi-metadata.csv file directly from the annotations
// in the source code.
2021-06-07 22:36:01 +02:00
intermediateMetadataCSV := android . PathForModuleOut ( ctx , "hiddenapi-monolithic" , "metadata-from-classes.csv" )
buildRuleToGenerateMetadata ( ctx , "intermediate hidden API metadata" , classesJars , stubFlags , intermediateMetadataCSV )
// Generate the monolithic hiddenapi-metadata.csv file.
//
// Use metadata files generated directly from the classes jars as well as metadata files provided
// by prebuilts.
//
// This has the side effect of ensuring that the output file uses | quotes just in case that is
// important for the tools that consume the metadata file.
allMetadataFlagFiles := android . Paths { intermediateMetadataCSV }
allMetadataFlagFiles = append ( allMetadataFlagFiles , monolithicInfo . MetadataPaths ... )
2021-05-14 11:38:00 +02:00
metadataCSV := hiddenAPISingletonPaths ( ctx ) . metadata
2021-06-07 22:36:01 +02:00
b . buildRuleMergeCSV ( ctx , "monolithic hidden API metadata" , allMetadataFlagFiles , metadataCSV )
// Generate an intermediate monolithic hiddenapi-index.csv file directly from the CSV files in the
// classes jars.
intermediateIndexCSV := android . PathForModuleOut ( ctx , "hiddenapi-monolithic" , "index-from-classes.csv" )
buildRuleToGenerateIndex ( ctx , "intermediate hidden API index" , classesJars , intermediateIndexCSV )
// Generate the monolithic hiddenapi-index.csv file.
//
// Use index files generated directly from the classes jars as well as index files provided
// by prebuilts.
allIndexFlagFiles := android . Paths { intermediateIndexCSV }
allIndexFlagFiles = append ( allIndexFlagFiles , monolithicInfo . IndexPaths ... )
2021-05-14 11:38:00 +02:00
indexCSV := hiddenAPISingletonPaths ( ctx ) . index
2021-06-07 22:36:01 +02:00
b . buildRuleMergeCSV ( ctx , "monolithic hidden API index" , allIndexFlagFiles , indexCSV )
2021-06-07 20:28:15 +02:00
return bootDexJarByModule
2021-05-14 11:38:00 +02:00
}
2021-04-13 01:14:38 +02:00
2021-05-21 17:58:23 +02:00
// createAndProvideMonolithicHiddenAPIInfo creates a MonolithicHiddenAPIInfo and provides it for
// testing.
2021-06-16 02:42:33 +02:00
func ( b * platformBootclasspathModule ) createAndProvideMonolithicHiddenAPIInfo ( ctx android . ModuleContext , classpathElements ClasspathElements ) MonolithicHiddenAPIInfo {
2021-05-21 23:18:49 +02:00
// Create a temporary input structure in which to collate information provided directly by this
// module, either through properties or direct dependencies.
temporaryInput := newHiddenAPIFlagInput ( )
// Create paths to the flag files specified in the properties.
2022-07-27 18:16:54 +02:00
temporaryInput . extractFlagFilesFromProperties ( ctx , & b . properties . HiddenAPIFlagFileProperties )
2021-05-21 23:18:49 +02:00
// Create the monolithic info, by starting with the flag files specified on this and then merging
// in information from all the fragment dependencies of this.
2021-06-16 02:42:33 +02:00
monolithicInfo := newMonolithicHiddenAPIInfo ( ctx , temporaryInput . FlagFilesByCategory , classpathElements )
2021-05-21 17:58:23 +02:00
// Store the information for testing.
2023-12-14 00:19:49 +01:00
android . SetProvider ( ctx , MonolithicHiddenAPIInfoProvider , monolithicInfo )
2021-05-21 17:58:23 +02:00
return monolithicInfo
}
2021-05-14 11:38:00 +02:00
func ( b * platformBootclasspathModule ) buildRuleMergeCSV ( ctx android . ModuleContext , desc string , inputPaths android . Paths , outputPath android . WritablePath ) {
rule := android . NewRuleBuilder ( pctx , ctx )
2021-04-13 01:14:38 +02:00
rule . Command ( ) .
BuiltTool ( "merge_csv" ) .
Flag ( "--key_field signature" ) .
FlagWithOutput ( "--output=" , outputPath ) .
2021-05-14 11:38:00 +02:00
Inputs ( inputPaths )
2021-04-13 01:14:38 +02:00
2021-05-14 11:38:00 +02:00
rule . Build ( desc , desc )
2021-04-13 01:14:38 +02:00
}
2021-04-26 17:44:00 +02:00
2021-04-29 14:50:01 +02:00
// generateHiddenApiMakeVars generates make variables needed by hidden API related make rules, e.g.
// veridex and run-appcompat.
func ( b * platformBootclasspathModule ) generateHiddenApiMakeVars ( ctx android . MakeVarsContext ) {
if ctx . Config ( ) . IsEnvTrue ( "UNSAFE_DISABLE_HIDDENAPI_FLAGS" ) {
return
}
// INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/.
ctx . Strict ( "INTERNAL_PLATFORM_HIDDENAPI_FLAGS" , b . hiddenAPIFlagsCSV . String ( ) )
}