diff options
author | 2024-06-11 23:24:13 +0000 | |
---|---|---|
committer | 2024-06-13 21:49:47 +0000 | |
commit | 71825167e0b4a9f078daf5872ea148b43b86b298 (patch) | |
tree | 1b32a850ef6781e5464c359b604852c47ca611f5 /sh/sh_binary.go | |
parent | a551b011d0f25e5d41ec63922e69f8b86539920e (diff) |
Modify the installation rules of sh binary based on the image variants
This change modifes the build rules of sh binary module type so that:
- The installation paths respects the image variations and the
*_available properties.
- The androidmk entries have subnames so that the names of the different
variants do not collide.
Test: Patch ag/27004177 and run m nothing
Bug: 336582138
Change-Id: Id85c428980ab459bff8d84098bd6c501a12231ed
Diffstat (limited to 'sh/sh_binary.go')
-rw-r--r-- | sh/sh_binary.go | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/sh/sh_binary.go b/sh/sh_binary.go index 3a4adc6f3..3f82560c0 100644 --- a/sh/sh_binary.go +++ b/sh/sh_binary.go @@ -99,6 +99,12 @@ type shBinaryProperties struct { // Make this module available when building for recovery. Recovery_available *bool + + // The name of the image this module is built for + ImageVariation string `blueprint:"mutated"` + + // Suffix for the name of Android.mk entries generated by this module + SubName string `blueprint:"mutated"` } type TestProperties struct { @@ -207,15 +213,15 @@ var _ android.ImageInterface = (*ShBinary)(nil) func (s *ShBinary) ImageMutatorBegin(ctx android.BaseModuleContext) {} func (s *ShBinary) CoreVariantNeeded(ctx android.BaseModuleContext) bool { - return !s.ModuleBase.InstallInRecovery() && !s.ModuleBase.InstallInRamdisk() + return !s.InstallInRecovery() && !s.InstallInRamdisk() && !s.InstallInVendorRamdisk() && !s.ModuleBase.InstallInVendor() } func (s *ShBinary) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { - return proptools.Bool(s.properties.Ramdisk_available) || s.ModuleBase.InstallInRamdisk() + return proptools.Bool(s.properties.Ramdisk_available) || s.InstallInRamdisk() } func (s *ShBinary) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { - return proptools.Bool(s.properties.Vendor_ramdisk_available) || s.ModuleBase.InstallInVendorRamdisk() + return proptools.Bool(s.properties.Vendor_ramdisk_available) || s.InstallInVendorRamdisk() } func (s *ShBinary) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { @@ -223,14 +229,45 @@ func (s *ShBinary) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool } func (s *ShBinary) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { - return proptools.Bool(s.properties.Recovery_available) || s.ModuleBase.InstallInRecovery() + return proptools.Bool(s.properties.Recovery_available) || s.InstallInRecovery() } func (s *ShBinary) ExtraImageVariations(ctx android.BaseModuleContext) []string { - return nil + extraVariations := []string{} + if s.InstallInProduct() { + extraVariations = append(extraVariations, cc.ProductVariation) + } + if s.InstallInVendor() { + extraVariations = append(extraVariations, cc.VendorVariation) + } + return extraVariations } func (s *ShBinary) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { + if m, ok := module.(*ShBinary); ok { + m.properties.ImageVariation = variation + } +} + +// Overrides ModuleBase.InstallInRamdisk() so that the install rule respects +// Ramdisk_available property for ramdisk variant +func (s *ShBinary) InstallInRamdisk() bool { + return s.ModuleBase.InstallInRamdisk() || + (proptools.Bool(s.properties.Ramdisk_available) && s.properties.ImageVariation == android.RamdiskVariation) +} + +// Overrides ModuleBase.InstallInVendorRamdisk() so that the install rule respects +// Vendor_ramdisk_available property for vendor ramdisk variant +func (s *ShBinary) InstallInVendorRamdisk() bool { + return s.ModuleBase.InstallInVendorRamdisk() || + (proptools.Bool(s.properties.Vendor_ramdisk_available) && s.properties.ImageVariation == android.VendorRamdiskVariation) +} + +// Overrides ModuleBase.InstallInRecovery() so that the install rule respects +// Recovery_available property for recovery variant +func (s *ShBinary) InstallInRecovery() bool { + return s.ModuleBase.InstallInRecovery() || + (proptools.Bool(s.properties.Recovery_available) && s.properties.ImageVariation == android.RecoveryVariation) } func (s *ShBinary) generateAndroidBuildActions(ctx android.ModuleContext) { @@ -260,11 +297,24 @@ func (s *ShBinary) generateAndroidBuildActions(ctx android.ModuleContext) { Output: s.outputFilePath, Input: s.sourceFilePath, }) + + s.properties.SubName = s.GetSubname(ctx) + android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: []string{s.sourceFilePath.String()}}) ctx.SetOutputFiles(android.Paths{s.outputFilePath}, "") } +func (s *ShBinary) GetSubname(ctx android.ModuleContext) string { + ret := "" + if s.properties.ImageVariation != "" { + if s.properties.ImageVariation != cc.VendorVariation { + ret = "." + s.properties.ImageVariation + } + } + return ret +} + func (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) { s.generateAndroidBuildActions(ctx) installDir := android.PathForModuleInstall(ctx, "bin", proptools.String(s.properties.Sub_dir)) @@ -278,7 +328,7 @@ func (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) { } func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries { - return []android.AndroidMkEntries{android.AndroidMkEntries{ + return []android.AndroidMkEntries{{ Class: "EXECUTABLES", OutputFile: android.OptionalPathForPath(s.outputFilePath), Include: "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk", @@ -289,6 +339,7 @@ func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries { entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !s.Installable()) }, }, + SubName: s.properties.SubName, }} } |