Merge changes from topic "cherrypicker-L21100000956698586:N81600001300765487" into tm-mainline-prod

* changes:
  Remove deviceInstalls from bootImageVariant
  Remove profilePathOnHost from bootImageConfig
  Document bootImageConfig and bootImageVariant structs
This commit is contained in:
TreeHugger Robot
2022-10-06 15:09:52 +00:00
committed by Android (Google) Code Review
3 changed files with 92 additions and 41 deletions

View File

@@ -264,7 +264,7 @@ type commonBootclasspathFragment interface {
// //
// If it could not create the files then it will return nil. Otherwise, it will return a map from // If it could not create the files then it will return nil. Otherwise, it will return a map from
// android.ArchType to the predefined paths of the boot image files. // android.ArchType to the predefined paths of the boot image files.
produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageFilesByArch produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs
} }
var _ commonBootclasspathFragment = (*BootclasspathFragmentModule)(nil) var _ commonBootclasspathFragment = (*BootclasspathFragmentModule)(nil)
@@ -583,23 +583,24 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo
// Perform hidden API processing. // Perform hidden API processing.
hiddenAPIOutput := b.generateHiddenAPIBuildActions(ctx, contents, fragments) hiddenAPIOutput := b.generateHiddenAPIBuildActions(ctx, contents, fragments)
var bootImageFilesByArch bootImageFilesByArch var bootImageFiles bootImageOutputs
if imageConfig != nil { if imageConfig != nil {
// Delegate the production of the boot image files to a module type specific method. // Delegate the production of the boot image files to a module type specific method.
common := ctx.Module().(commonBootclasspathFragment) common := ctx.Module().(commonBootclasspathFragment)
bootImageFilesByArch = common.produceBootImageFiles(ctx, imageConfig) bootImageFiles = common.produceBootImageFiles(ctx, imageConfig)
if shouldCopyBootFilesToPredefinedLocations(ctx, imageConfig) { if shouldCopyBootFilesToPredefinedLocations(ctx, imageConfig) {
// Zip the boot image files up, if available. This will generate the zip file in a // Zip the boot image files up, if available. This will generate the zip file in a
// predefined location. // predefined location.
buildBootImageZipInPredefinedLocation(ctx, imageConfig, bootImageFilesByArch) buildBootImageZipInPredefinedLocation(ctx, imageConfig, bootImageFiles.byArch)
// Copy the dex jars of this fragment's content modules to their predefined locations. // Copy the dex jars of this fragment's content modules to their predefined locations.
copyBootJarsToPredefinedLocations(ctx, hiddenAPIOutput.EncodedBootDexFilesByModule, imageConfig.dexPathsByModule) copyBootJarsToPredefinedLocations(ctx, hiddenAPIOutput.EncodedBootDexFilesByModule, imageConfig.dexPathsByModule)
} }
for _, variant := range imageConfig.apexVariants() { for _, variant := range bootImageFiles.variants {
arch := variant.target.Arch.ArchType.String() archType := variant.config.target.Arch.ArchType
arch := archType.String()
for _, install := range variant.deviceInstalls { for _, install := range variant.deviceInstalls {
// Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT. // Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT.
installDir := strings.TrimPrefix(filepath.Dir(install.To), "/") installDir := strings.TrimPrefix(filepath.Dir(install.To), "/")
@@ -620,7 +621,7 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo
// A prebuilt fragment cannot contribute to an apex. // A prebuilt fragment cannot contribute to an apex.
if !android.IsModulePrebuilt(ctx.Module()) { if !android.IsModulePrebuilt(ctx.Module()) {
// Provide the apex content info. // Provide the apex content info.
b.provideApexContentInfo(ctx, imageConfig, hiddenAPIOutput, bootImageFilesByArch) b.provideApexContentInfo(ctx, imageConfig, hiddenAPIOutput, bootImageFiles)
} }
} else { } else {
// Versioned fragments are not needed by make. // Versioned fragments are not needed by make.
@@ -663,7 +664,7 @@ func shouldCopyBootFilesToPredefinedLocations(ctx android.ModuleContext, imageCo
// provideApexContentInfo creates, initializes and stores the apex content info for use by other // provideApexContentInfo creates, initializes and stores the apex content info for use by other
// modules. // modules.
func (b *BootclasspathFragmentModule) provideApexContentInfo(ctx android.ModuleContext, imageConfig *bootImageConfig, hiddenAPIOutput *HiddenAPIOutput, bootImageFilesByArch bootImageFilesByArch) { func (b *BootclasspathFragmentModule) provideApexContentInfo(ctx android.ModuleContext, imageConfig *bootImageConfig, hiddenAPIOutput *HiddenAPIOutput, bootImageFiles bootImageOutputs) {
// Construct the apex content info from the config. // Construct the apex content info from the config.
info := BootclasspathFragmentApexContentInfo{ info := BootclasspathFragmentApexContentInfo{
// Populate the apex content info with paths to the dex jars. // Populate the apex content info with paths to the dex jars.
@@ -674,14 +675,14 @@ func (b *BootclasspathFragmentModule) provideApexContentInfo(ctx android.ModuleC
info.modules = imageConfig.modules info.modules = imageConfig.modules
global := dexpreopt.GetGlobalConfig(ctx) global := dexpreopt.GetGlobalConfig(ctx)
if !global.DisableGenerateProfile { if !global.DisableGenerateProfile {
info.profilePathOnHost = imageConfig.profilePathOnHost info.profilePathOnHost = bootImageFiles.profile
info.profileInstallPathInApex = imageConfig.profileInstallPathInApex info.profileInstallPathInApex = imageConfig.profileInstallPathInApex
} }
info.shouldInstallBootImageInApex = imageConfig.shouldInstallInApex() info.shouldInstallBootImageInApex = imageConfig.shouldInstallInApex()
} }
info.bootImageFilesByArch = bootImageFilesByArch info.bootImageFilesByArch = bootImageFiles.byArch
// Make the apex content info available for other modules. // Make the apex content info available for other modules.
ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info) ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info)
@@ -936,9 +937,9 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC
} }
// produceBootImageFiles builds the boot image files from the source if it is required. // produceBootImageFiles builds the boot image files from the source if it is required.
func (b *BootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageFilesByArch { func (b *BootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs {
if SkipDexpreoptBootJars(ctx) { if SkipDexpreoptBootJars(ctx) {
return nil return bootImageOutputs{}
} }
// Only generate the boot image if the configuration does not skip it. // Only generate the boot image if the configuration does not skip it.
@@ -950,21 +951,21 @@ func (b *BootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleCo
// //
// If it could not create the files then it will return nil. Otherwise, it will return a map from // If it could not create the files then it will return nil. Otherwise, it will return a map from
// android.ArchType to the predefined paths of the boot image files. // android.ArchType to the predefined paths of the boot image files.
func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageFilesByArch { func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs {
global := dexpreopt.GetGlobalConfig(ctx) global := dexpreopt.GetGlobalConfig(ctx)
if !shouldBuildBootImages(ctx.Config(), global) { if !shouldBuildBootImages(ctx.Config(), global) {
return nil return bootImageOutputs{}
} }
// Bootclasspath fragment modules that are for the platform do not produce a boot image. // Bootclasspath fragment modules that are for the platform do not produce a boot image.
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if apexInfo.IsForPlatform() { if apexInfo.IsForPlatform() {
return nil return bootImageOutputs{}
} }
// Bootclasspath fragment modules that are versioned do not produce a boot image. // Bootclasspath fragment modules that are versioned do not produce a boot image.
if android.IsModuleInVersionedSdk(ctx.Module()) { if android.IsModuleInVersionedSdk(ctx.Module()) {
return nil return bootImageOutputs{}
} }
// Build a profile for the image config and then use that to build the boot image. // Build a profile for the image config and then use that to build the boot image.
@@ -974,11 +975,11 @@ func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android.
buildBootImageVariantsForBuildOs(ctx, imageConfig, profile) buildBootImageVariantsForBuildOs(ctx, imageConfig, profile)
// Build boot image files for the android variants. // Build boot image files for the android variants.
androidBootImageFilesByArch := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) bootImageFiles := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile)
// Return the boot image files for the android variants for inclusion in an APEX and to be zipped // Return the boot image files for the android variants for inclusion in an APEX and to be zipped
// up for the dist. // up for the dist.
return androidBootImageFilesByArch return bootImageFiles
} }
func (b *BootclasspathFragmentModule) AndroidMkEntries() []android.AndroidMkEntries { func (b *BootclasspathFragmentModule) AndroidMkEntries() []android.AndroidMkEntries {
@@ -1279,14 +1280,14 @@ func (module *PrebuiltBootclasspathFragmentModule) produceHiddenAPIOutput(ctx an
} }
// produceBootImageFiles extracts the boot image files from the APEX if available. // produceBootImageFiles extracts the boot image files from the APEX if available.
func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageFilesByArch { func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs {
if !shouldCopyBootFilesToPredefinedLocations(ctx, imageConfig) { if !shouldCopyBootFilesToPredefinedLocations(ctx, imageConfig) {
return nil return bootImageOutputs{}
} }
di := android.FindDeapexerProviderForModule(ctx) di := android.FindDeapexerProviderForModule(ctx)
if di == nil { if di == nil {
return nil // An error has been reported by FindDeapexerProviderForModule. return bootImageOutputs{} // An error has been reported by FindDeapexerProviderForModule.
} }
profile := (android.WritablePath)(nil) profile := (android.WritablePath)(nil)
@@ -1304,8 +1305,17 @@ func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and
// If the boot image files for the android variants are in the prebuilt apex, we must use those // If the boot image files for the android variants are in the prebuilt apex, we must use those
// rather than building new ones because those boot image files are going to be used on device. // rather than building new ones because those boot image files are going to be used on device.
files := bootImageFilesByArch{} files := bootImageFilesByArch{}
bootImageFiles := bootImageOutputs{
byArch: files,
profile: profile,
}
for _, variant := range imageConfig.apexVariants() { for _, variant := range imageConfig.apexVariants() {
arch := variant.target.Arch.ArchType arch := variant.target.Arch.ArchType
bootImageFiles.variants = append(bootImageFiles.variants, bootImageVariantOutputs{
variant,
// No device installs needed when installed in APEX.
nil,
})
for _, toPath := range variant.imagesDeps { for _, toPath := range variant.imagesDeps {
apexRelativePath := apexRootRelativePathToBootImageFile(arch, toPath.Base()) apexRelativePath := apexRootRelativePathToBootImageFile(arch, toPath.Base())
// Get the path to the file that the deapexer extracted from the prebuilt apex file. // Get the path to the file that the deapexer extracted from the prebuilt apex file.
@@ -1323,11 +1333,11 @@ func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and
}) })
} }
} }
return files return bootImageFiles
} else { } else {
if profile == nil { if profile == nil {
ctx.ModuleErrorf("Unable to produce boot image files: neither boot image files nor profiles exists in the prebuilt apex") ctx.ModuleErrorf("Unable to produce boot image files: neither boot image files nor profiles exists in the prebuilt apex")
return nil return bootImageOutputs{}
} }
// Build boot image files for the android variants from the dex files provided by the contents // Build boot image files for the android variants from the dex files provided by the contents
// of this module. // of this module.

View File

@@ -234,6 +234,11 @@ func init() {
} }
// Target-independent description of a boot image. // Target-independent description of a boot image.
//
// WARNING: All fields in this struct should be initialized in the genBootImageConfigs function.
// Failure to do so can lead to data races if there is no synchronization enforced ordering between
// the writer and the reader. Fields which break this rule are marked as deprecated and should be
// removed and replaced with something else, e.g. providers.
type bootImageConfig struct { type bootImageConfig struct {
// If this image is an extension, the image that it extends. // If this image is an extension, the image that it extends.
extends *bootImageConfig extends *bootImageConfig
@@ -274,14 +279,15 @@ type bootImageConfig struct {
zip android.WritablePath zip android.WritablePath
// Rules which should be used in make to install the outputs. // Rules which should be used in make to install the outputs.
//
// Deprecated: Not initialized correctly, see struct comment.
profileInstalls android.RuleBuilderInstalls profileInstalls android.RuleBuilderInstalls
// Path to the license metadata file for the module that built the profile. // Path to the license metadata file for the module that built the profile.
//
// Deprecated: Not initialized correctly, see struct comment.
profileLicenseMetadataFile android.OptionalPath profileLicenseMetadataFile android.OptionalPath
// Path to the image profile file on host (or empty, if profile is not generated).
profilePathOnHost android.Path
// Target-dependent fields. // Target-dependent fields.
variants []*bootImageVariant variants []*bootImageVariant
@@ -290,6 +296,8 @@ type bootImageConfig struct {
} }
// Target-dependent description of a boot image. // Target-dependent description of a boot image.
//
// WARNING: The warning comment on bootImageConfig applies here too.
type bootImageVariant struct { type bootImageVariant struct {
*bootImageConfig *bootImageConfig
@@ -320,14 +328,23 @@ type bootImageVariant struct {
primaryImagesDeps android.Paths primaryImagesDeps android.Paths
// Rules which should be used in make to install the outputs on host. // Rules which should be used in make to install the outputs on host.
installs android.RuleBuilderInstalls //
vdexInstalls android.RuleBuilderInstalls // Deprecated: Not initialized correctly, see struct comment.
installs android.RuleBuilderInstalls
// Rules which should be used in make to install the vdex outputs on host.
//
// Deprecated: Not initialized correctly, see struct comment.
vdexInstalls android.RuleBuilderInstalls
// Rules which should be used in make to install the unstripped outputs on host.
//
// Deprecated: Not initialized correctly, see struct comment.
unstrippedInstalls android.RuleBuilderInstalls unstrippedInstalls android.RuleBuilderInstalls
// Rules which should be used in make to install the outputs on device.
deviceInstalls android.RuleBuilderInstalls
// Path to the license metadata file for the module that built the image. // Path to the license metadata file for the module that built the image.
//
// Deprecated: Not initialized correctly, see struct comment.
licenseMetadataFile android.OptionalPath licenseMetadataFile android.OptionalPath
} }
@@ -554,7 +571,7 @@ func copyBootJarsToPredefinedLocations(ctx android.ModuleContext, srcBootDexJars
// boot image files. // boot image files.
// //
// The paths are returned because they are needed elsewhere in Soong, e.g. for populating an APEX. // The paths are returned because they are needed elsewhere in Soong, e.g. for populating an APEX.
func buildBootImageVariantsForAndroidOs(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath) bootImageFilesByArch { func buildBootImageVariantsForAndroidOs(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath) bootImageOutputs {
return buildBootImageForOsType(ctx, image, profile, android.Android) return buildBootImageForOsType(ctx, image, profile, android.Android)
} }
@@ -569,21 +586,38 @@ func buildBootImageVariantsForBuildOs(ctx android.ModuleContext, image *bootImag
buildBootImageForOsType(ctx, image, profile, ctx.Config().BuildOS) buildBootImageForOsType(ctx, image, profile, ctx.Config().BuildOS)
} }
// bootImageOutputs encapsulates information about boot images that were created/obtained by
// commonBootclasspathFragment.produceBootImageFiles.
type bootImageOutputs struct {
// Map from arch to the paths to the boot image files created/obtained for that arch.
byArch bootImageFilesByArch
variants []bootImageVariantOutputs
// The path to the profile file created/obtained for the boot image.
profile android.WritablePath
}
// buildBootImageForOsType takes a bootImageConfig, a profile file and an android.OsType // buildBootImageForOsType takes a bootImageConfig, a profile file and an android.OsType
// boot image files are required for and it creates rules to build the boot image // boot image files are required for and it creates rules to build the boot image
// files for all the required architectures for them. // files for all the required architectures for them.
// //
// It returns a map from android.ArchType to the predefined paths of the boot image files. // It returns a map from android.ArchType to the predefined paths of the boot image files.
func buildBootImageForOsType(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath, requiredOsType android.OsType) bootImageFilesByArch { func buildBootImageForOsType(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath, requiredOsType android.OsType) bootImageOutputs {
filesByArch := bootImageFilesByArch{} filesByArch := bootImageFilesByArch{}
imageOutputs := bootImageOutputs{
byArch: filesByArch,
profile: profile,
}
for _, variant := range image.variants { for _, variant := range image.variants {
if variant.target.Os == requiredOsType { if variant.target.Os == requiredOsType {
buildBootImageVariant(ctx, variant, profile) variantOutputs := buildBootImageVariant(ctx, variant, profile)
imageOutputs.variants = append(imageOutputs.variants, variantOutputs)
filesByArch[variant.target.Arch.ArchType] = variant.imagesDeps.Paths() filesByArch[variant.target.Arch.ArchType] = variant.imagesDeps.Paths()
} }
} }
return filesByArch return imageOutputs
} }
// buildBootImageZipInPredefinedLocation generates a zip file containing all the boot image files. // buildBootImageZipInPredefinedLocation generates a zip file containing all the boot image files.
@@ -611,8 +645,13 @@ func buildBootImageZipInPredefinedLocation(ctx android.ModuleContext, image *boo
rule.Build("zip_"+image.name, "zip "+image.name+" image") rule.Build("zip_"+image.name, "zip "+image.name+" image")
} }
type bootImageVariantOutputs struct {
config *bootImageVariant
deviceInstalls android.RuleBuilderInstalls
}
// Generate boot image build rules for a specific target. // Generate boot image build rules for a specific target.
func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, profile android.Path) { func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, profile android.Path) bootImageVariantOutputs {
globalSoong := dexpreopt.GetGlobalSoongConfig(ctx) globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx) global := dexpreopt.GetGlobalConfig(ctx)
@@ -773,8 +812,12 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p
image.installs = rule.Installs() image.installs = rule.Installs()
image.vdexInstalls = vdexInstalls image.vdexInstalls = vdexInstalls
image.unstrippedInstalls = unstrippedInstalls image.unstrippedInstalls = unstrippedInstalls
image.deviceInstalls = deviceInstalls
image.licenseMetadataFile = android.OptionalPathForPath(ctx.LicenseMetadataFile()) image.licenseMetadataFile = android.OptionalPathForPath(ctx.LicenseMetadataFile())
return bootImageVariantOutputs{
image,
deviceInstalls,
}
} }
const failureMessage = `ERROR: Dex2oat failed to compile a boot image. const failureMessage = `ERROR: Dex2oat failed to compile a boot image.
@@ -828,8 +871,6 @@ func bootImageProfileRule(ctx android.ModuleContext, image *bootImageConfig) and
rule.Build("bootJarsProfile", "profile boot jars") rule.Build("bootJarsProfile", "profile boot jars")
image.profilePathOnHost = profile
return profile return profile
} }

View File

@@ -436,10 +436,10 @@ func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.
profile := bootImageProfileRule(ctx, imageConfig) profile := bootImageProfileRule(ctx, imageConfig)
// Build boot image files for the android variants. // Build boot image files for the android variants.
androidBootImageFilesByArch := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) androidBootImageFiles := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile)
// Zip the android variant boot image files up. // Zip the android variant boot image files up.
buildBootImageZipInPredefinedLocation(ctx, imageConfig, androidBootImageFilesByArch) buildBootImageZipInPredefinedLocation(ctx, imageConfig, androidBootImageFiles.byArch)
// Build boot image files for the host variants. There are use directly by ART host side tests. // Build boot image files for the host variants. There are use directly by ART host side tests.
buildBootImageVariantsForBuildOs(ctx, imageConfig, profile) buildBootImageVariantsForBuildOs(ctx, imageConfig, profile)