diff options
Diffstat (limited to 'android/module.go')
| -rw-r--r-- | android/module.go | 174 |
1 files changed, 126 insertions, 48 deletions
diff --git a/android/module.go b/android/module.go index d677406a6..6b659d2cd 100644 --- a/android/module.go +++ b/android/module.go @@ -440,6 +440,7 @@ type Module interface { TargetRequiredModuleNames() []string FilesToInstall() InstallPaths + PackagingSpecs() []PackagingSpec } // Qualified id for a module @@ -716,7 +717,9 @@ type commonProperties struct { DebugMutators []string `blueprint:"mutated"` DebugVariations []string `blueprint:"mutated"` - // set by ImageMutator + // ImageVariation is set by ImageMutator to specify which image this variation is for, + // for example "" for core or "recovery" for recovery. It will often be set to one of the + // constants in image.go, but can also be set to a custom value by individual module types. ImageVariation string `blueprint:"mutated"` } @@ -765,27 +768,32 @@ const ( type HostOrDeviceSupported int const ( - _ HostOrDeviceSupported = iota + hostSupported = 1 << iota + hostCrossSupported + deviceSupported + hostDefault + deviceDefault // Host and HostCross are built by default. Device is not supported. - HostSupported + HostSupported = hostSupported | hostCrossSupported | hostDefault // Host is built by default. HostCross and Device are not supported. - HostSupportedNoCross + HostSupportedNoCross = hostSupported | hostDefault // Device is built by default. Host and HostCross are not supported. - DeviceSupported + DeviceSupported = deviceSupported | deviceDefault // Device is built by default. Host and HostCross are supported. - HostAndDeviceSupported + HostAndDeviceSupported = hostSupported | hostCrossSupported | deviceSupported | deviceDefault // Host, HostCross, and Device are built by default. - HostAndDeviceDefault + HostAndDeviceDefault = hostSupported | hostCrossSupported | hostDefault | + deviceSupported | deviceDefault // Nothing is supported. This is not exposed to the user, but used to mark a // host only module as unsupported when the module type is not supported on // the host OS. E.g. benchmarks are supported on Linux but not Darwin. - NeitherHostNorDeviceSupported + NeitherHostNorDeviceSupported = 0 ) type moduleKind int @@ -819,6 +827,8 @@ func initAndroidModuleBase(m Module) { m.base().module = m } +// InitAndroidModule initializes the Module as an Android module that is not architecture-specific. +// It adds the common properties, for example "name" and "enabled". func InitAndroidModule(m Module) { initAndroidModuleBase(m) base := m.base() @@ -838,6 +848,12 @@ func InitAndroidModule(m Module) { setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility) } +// InitAndroidArchModule initializes the Module as an Android module that is architecture-specific. +// It adds the common properties, for example "name" and "enabled", as well as runtime generated +// property structs for architecture-specific versions of generic properties tagged with +// `android:"arch_variant"`. +// +// InitAndroidModule should not be called if InitAndroidArchModule was called. func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { InitAndroidModule(m) @@ -847,21 +863,37 @@ func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib base.commonProperties.ArchSpecific = true base.commonProperties.UseTargetVariants = true - switch hod { - case HostAndDeviceSupported, HostAndDeviceDefault: + if hod&hostSupported != 0 && hod&deviceSupported != 0 { m.AddProperties(&base.hostAndDeviceProperties) } - InitArchModule(m) + initArchModule(m) } +// InitAndroidMultiTargetsArchModule initializes the Module as an Android module that is +// architecture-specific, but will only have a single variant per OS that handles all the +// architectures simultaneously. The list of Targets that it must handle will be available from +// ModuleContext.MultiTargets. It adds the common properties, for example "name" and "enabled", as +// well as runtime generated property structs for architecture-specific versions of generic +// properties tagged with `android:"arch_variant"`. +// +// InitAndroidModule or InitAndroidArchModule should not be called if +// InitAndroidMultiTargetsArchModule was called. func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { InitAndroidArchModule(m, hod, defaultMultilib) m.base().commonProperties.UseTargetVariants = false } -// As InitAndroidMultiTargetsArchModule except it creates an additional CommonOS variant that -// has dependencies on all the OsType specific variants. +// InitCommonOSAndroidMultiTargetsArchModule initializes the Module as an Android module that is +// architecture-specific, but will only have a single variant per OS that handles all the +// architectures simultaneously, and will also have an additional CommonOS variant that has +// dependencies on all the OS-specific variants. The list of Targets that it must handle will be +// available from ModuleContext.MultiTargets. It adds the common properties, for example "name" and +// "enabled", as well as runtime generated property structs for architecture-specific versions of +// generic properties tagged with `android:"arch_variant"`. +// +// InitAndroidModule, InitAndroidArchModule or InitAndroidMultiTargetsArchModule should not be +// called if InitCommonOSAndroidMultiTargetsArchModule was called. func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { InitAndroidArchModule(m, hod, defaultMultilib) m.base().commonProperties.UseTargetVariants = false @@ -934,6 +966,7 @@ type ModuleBase struct { noAddressSanitizer bool installFiles InstallPaths checkbuildFiles Paths + packagingSpecs []PackagingSpec noticeFiles Paths phonies map[string]Paths @@ -1098,43 +1131,54 @@ func (m *ModuleBase) IsCommonOSVariant() bool { return m.commonProperties.CommonOSVariant } -func (m *ModuleBase) supportsTarget(target Target, config Config) bool { - switch m.commonProperties.HostOrDeviceSupported { - case HostSupported: - return target.Os.Class == Host - case HostSupportedNoCross: - return target.Os.Class == Host && !target.HostCross - case DeviceSupported: - return target.Os.Class == Device - case HostAndDeviceSupported, HostAndDeviceDefault: - supported := false - if Bool(m.hostAndDeviceProperties.Host_supported) || - (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault && - m.hostAndDeviceProperties.Host_supported == nil) { - supported = supported || target.Os.Class == Host - } - if m.hostAndDeviceProperties.Device_supported == nil || - *m.hostAndDeviceProperties.Device_supported { - supported = supported || target.Os.Class == Device +// supportsTarget returns true if the given Target is supported by the current module. +func (m *ModuleBase) supportsTarget(target Target) bool { + switch target.Os.Class { + case Host: + if target.HostCross { + return m.HostCrossSupported() + } else { + return m.HostSupported() } - return supported + case Device: + return m.DeviceSupported() default: return false } } +// DeviceSupported returns true if the current module is supported and enabled for device targets, +// i.e. the factory method set the HostOrDeviceSupported value to include device support and +// the device support is enabled by default or enabled by the device_supported property. func (m *ModuleBase) DeviceSupported() bool { - return m.commonProperties.HostOrDeviceSupported == DeviceSupported || - m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && - (m.hostAndDeviceProperties.Device_supported == nil || - *m.hostAndDeviceProperties.Device_supported) + hod := m.commonProperties.HostOrDeviceSupported + // deviceEnabled is true if the device_supported property is true or the HostOrDeviceSupported + // value has the deviceDefault bit set. + deviceEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Device_supported, hod&deviceDefault != 0) + return hod&deviceSupported != 0 && deviceEnabled } +// HostSupported returns true if the current module is supported and enabled for host targets, +// i.e. the factory method set the HostOrDeviceSupported value to include host support and +// the host support is enabled by default or enabled by the host_supported property. func (m *ModuleBase) HostSupported() bool { - return m.commonProperties.HostOrDeviceSupported == HostSupported || - m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && - (m.hostAndDeviceProperties.Host_supported != nil && - *m.hostAndDeviceProperties.Host_supported) + hod := m.commonProperties.HostOrDeviceSupported + // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported + // value has the hostDefault bit set. + hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0) + return hod&hostSupported != 0 && hostEnabled +} + +// HostCrossSupported returns true if the current module is supported and enabled for host cross +// targets, i.e. the factory method set the HostOrDeviceSupported value to include host cross +// support and the host cross support is enabled by default or enabled by the +// host_supported property. +func (m *ModuleBase) HostCrossSupported() bool { + hod := m.commonProperties.HostOrDeviceSupported + // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported + // value has the hostDefault bit set. + hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0) + return hod&hostCrossSupported != 0 && hostEnabled } func (m *ModuleBase) Platform() bool { @@ -1259,6 +1303,10 @@ func (m *ModuleBase) FilesToInstall() InstallPaths { return m.installFiles } +func (m *ModuleBase) PackagingSpecs() []PackagingSpec { + return m.packagingSpecs +} + func (m *ModuleBase) NoAddressSanitizer() bool { return m.noAddressSanitizer } @@ -1581,6 +1629,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) m.installFiles = append(m.installFiles, ctx.installFiles...) m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...) + m.packagingSpecs = append(m.packagingSpecs, ctx.packagingSpecs...) m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc) m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments) for k, v := range ctx.phonies { @@ -1748,6 +1797,7 @@ func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleCon type moduleContext struct { bp blueprint.ModuleContext baseModuleContext + packagingSpecs []PackagingSpec installDeps InstallPaths installFiles InstallPaths checkbuildFiles Paths @@ -2284,16 +2334,15 @@ func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool { func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath { - return m.installFile(installPath, name, srcPath, Cp, deps) + return m.installFile(installPath, name, srcPath, deps, false) } func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath { - return m.installFile(installPath, name, srcPath, CpExecutable, deps) + return m.installFile(installPath, name, srcPath, deps, true) } -func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, - rule blueprint.Rule, deps []Path) InstallPath { +func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []Path, executable bool) InstallPath { fullInstallPath := installPath.Join(m, name) m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false) @@ -2312,6 +2361,11 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat orderOnlyDeps = deps } + rule := Cp + if executable { + rule = CpExecutable + } + m.Build(pctx, BuildParams{ Rule: rule, Description: "install " + fullInstallPath.Base(), @@ -2324,6 +2378,14 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat m.installFiles = append(m.installFiles, fullInstallPath) } + + m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{ + relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), + srcPath: srcPath, + symlinkTarget: "", + executable: executable, + }) + m.checkbuildFiles = append(m.checkbuildFiles, srcPath) return fullInstallPath } @@ -2332,12 +2394,12 @@ func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, src fullInstallPath := installPath.Join(m, name) m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true) + relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String()) + if err != nil { + panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err)) + } if !m.skipInstall(fullInstallPath) { - relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String()) - if err != nil { - panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err)) - } m.Build(pctx, BuildParams{ Rule: Symlink, Description: "install symlink " + fullInstallPath.Base(), @@ -2352,6 +2414,14 @@ func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, src m.installFiles = append(m.installFiles, fullInstallPath) m.checkbuildFiles = append(m.checkbuildFiles, srcPath) } + + m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{ + relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), + srcPath: nil, + symlinkTarget: relPath, + executable: false, + }) + return fullInstallPath } @@ -2374,6 +2444,14 @@ func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name str m.installFiles = append(m.installFiles, fullInstallPath) } + + m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{ + relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), + srcPath: nil, + symlinkTarget: absPath, + executable: false, + }) + return fullInstallPath } |