Remove profilePathOnHost from bootImageConfig

The use of this field to return information from bootImageProfileRule
up the call stack to one of the users resulted in data races being
detected. This change simply returns the profile path back up the call
stack.

Bug: 245956352
Test: m nothing
      go test -race ./sdk/... -run TestSnapshotWithBootclasspathFragment_ImageName -test.count 100
      # Run the previous command without this change and sometimes it
      # shows the data race around profilePathOnHost. With this change
      # that data race is not reported. Although there is still another
      # data race.
Change-Id: I03b09e514cc94f2a6c9d5117d3b2f130cc2e4f5b
This commit is contained in:
Paul Duffin
2022-10-04 15:36:44 +01:00
parent a8df7e1c5b
commit 9f6ac0bb42
3 changed files with 42 additions and 33 deletions

View File

@@ -282,11 +282,6 @@ type bootImageConfig struct {
// Deprecated: Not initialized correctly, see struct comment.
profileLicenseMetadataFile android.OptionalPath
// Path to the image profile file on host (or empty, if profile is not generated).
//
// Deprecated: Not initialized correctly, see struct comment.
profilePathOnHost android.Path
// Target-dependent fields.
variants []*bootImageVariant
@@ -575,7 +570,7 @@ func copyBootJarsToPredefinedLocations(ctx android.ModuleContext, srcBootDexJars
// boot image files.
//
// 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)
}
@@ -590,12 +585,22 @@ func buildBootImageVariantsForBuildOs(ctx android.ModuleContext, image *bootImag
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
// 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
// boot image files are required for and it creates rules to build the boot image
// files for all the required architectures for them.
//
// 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{}
for _, variant := range image.variants {
if variant.target.Os == requiredOsType {
@@ -604,7 +609,10 @@ func buildBootImageForOsType(ctx android.ModuleContext, image *bootImageConfig,
}
}
return filesByArch
return bootImageOutputs{
filesByArch,
profile,
}
}
// buildBootImageZipInPredefinedLocation generates a zip file containing all the boot image files.
@@ -851,8 +859,6 @@ func bootImageProfileRule(ctx android.ModuleContext, image *bootImageConfig) and
rule.Build("bootJarsProfile", "profile boot jars")
image.profilePathOnHost = profile
return profile
}