2018-04-10 06:07:10 +02:00
|
|
|
// Copyright 2016 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 android
|
|
|
|
|
2019-04-04 00:47:29 +02:00
|
|
|
import "strconv"
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2019-02-13 14:50:33 +01:00
|
|
|
// TODO(jungw): Now that it handles more than the ones in etc/, consider renaming this file.
|
2018-04-10 06:07:10 +02:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
|
2019-02-07 17:28:03 +01:00
|
|
|
RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
|
2019-02-13 14:50:33 +01:00
|
|
|
RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
|
2019-02-23 00:47:57 +01:00
|
|
|
RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
|
2019-05-14 17:20:45 +02:00
|
|
|
RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
|
2019-06-04 00:29:27 +02:00
|
|
|
RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
|
2018-08-15 07:20:22 +02:00
|
|
|
|
|
|
|
PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
|
|
|
ctx.BottomUp("prebuilt_etc", prebuiltEtcMutator).Parallel()
|
|
|
|
})
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type prebuiltEtcProperties struct {
|
|
|
|
// Source file of this prebuilt.
|
2019-03-05 07:35:41 +01:00
|
|
|
Src *string `android:"path,arch_variant"`
|
2018-04-10 06:07:10 +02:00
|
|
|
|
|
|
|
// optional subdirectory under which this file is installed into
|
|
|
|
Sub_dir *string `android:"arch_variant"`
|
2018-08-15 07:20:22 +02:00
|
|
|
|
2018-10-26 14:49:39 +02:00
|
|
|
// optional name for the installed file. If unspecified, name of the module is used as the file name
|
|
|
|
Filename *string `android:"arch_variant"`
|
|
|
|
|
2018-11-13 03:59:12 +01:00
|
|
|
// when set to true, and filename property is not set, the name for the installed file
|
|
|
|
// is the same as the file name of the source file.
|
|
|
|
Filename_from_src *bool `android:"arch_variant"`
|
|
|
|
|
2018-08-15 07:20:22 +02:00
|
|
|
// Make this module available when building for recovery.
|
|
|
|
Recovery_available *bool
|
|
|
|
|
|
|
|
InRecovery bool `blueprint:"mutated"`
|
2018-10-31 14:49:57 +01:00
|
|
|
|
|
|
|
// Whether this module is directly installable to one of the partitions. Default: true.
|
|
|
|
Installable *bool
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 15:57:34 +02:00
|
|
|
type PrebuiltEtc struct {
|
2018-04-10 06:07:10 +02:00
|
|
|
ModuleBase
|
|
|
|
|
|
|
|
properties prebuiltEtcProperties
|
|
|
|
|
2019-02-13 14:50:33 +01:00
|
|
|
sourceFilePath Path
|
|
|
|
outputFilePath OutputPath
|
|
|
|
// The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share.
|
2019-06-04 00:29:27 +02:00
|
|
|
installDirBase string
|
|
|
|
// The base install location when soc_specific property is set to true, e.g. "firmware" for prebuilt_firmware.
|
|
|
|
socInstallDirBase string
|
2018-04-25 15:57:34 +02:00
|
|
|
installDirPath OutputPath
|
|
|
|
additionalDependencies *Paths
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2018-08-15 07:20:22 +02:00
|
|
|
func (p *PrebuiltEtc) inRecovery() bool {
|
|
|
|
return p.properties.InRecovery || p.ModuleBase.InstallInRecovery()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) onlyInRecovery() bool {
|
|
|
|
return p.ModuleBase.InstallInRecovery()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) InstallInRecovery() bool {
|
|
|
|
return p.inRecovery()
|
|
|
|
}
|
|
|
|
|
2018-04-25 15:57:34 +02:00
|
|
|
func (p *PrebuiltEtc) DepsMutator(ctx BottomUpMutatorContext) {
|
|
|
|
if p.properties.Src == nil {
|
|
|
|
ctx.PropertyErrorf("src", "missing prebuilt source file")
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
2018-04-25 15:57:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) SourceFilePath(ctx ModuleContext) Path {
|
2019-03-06 07:25:09 +01:00
|
|
|
return PathForModuleSrc(ctx, String(p.properties.Src))
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 15:57:34 +02:00
|
|
|
// This allows other derivative modules (e.g. prebuilt_etc_xml) to perform
|
|
|
|
// additional steps (like validating the src) before the file is installed.
|
|
|
|
func (p *PrebuiltEtc) SetAdditionalDependencies(paths Paths) {
|
|
|
|
p.additionalDependencies = &paths
|
|
|
|
}
|
|
|
|
|
2018-10-04 13:27:15 +02:00
|
|
|
func (p *PrebuiltEtc) OutputFile() OutputPath {
|
|
|
|
return p.outputFilePath
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) SubDir() string {
|
|
|
|
return String(p.properties.Sub_dir)
|
|
|
|
}
|
|
|
|
|
2018-10-31 14:49:57 +01:00
|
|
|
func (p *PrebuiltEtc) Installable() bool {
|
|
|
|
return p.properties.Installable == nil || Bool(p.properties.Installable)
|
|
|
|
}
|
|
|
|
|
2018-04-25 15:57:34 +02:00
|
|
|
func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx ModuleContext) {
|
2019-03-06 07:25:09 +01:00
|
|
|
p.sourceFilePath = PathForModuleSrc(ctx, String(p.properties.Src))
|
2018-10-26 14:49:39 +02:00
|
|
|
filename := String(p.properties.Filename)
|
2018-11-13 03:59:12 +01:00
|
|
|
filename_from_src := Bool(p.properties.Filename_from_src)
|
2018-10-26 14:49:39 +02:00
|
|
|
if filename == "" {
|
2018-11-13 03:59:12 +01:00
|
|
|
if filename_from_src {
|
|
|
|
filename = p.sourceFilePath.Base()
|
|
|
|
} else {
|
|
|
|
filename = ctx.ModuleName()
|
|
|
|
}
|
|
|
|
} else if filename_from_src {
|
|
|
|
ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
|
|
|
|
return
|
2018-10-26 14:49:39 +02:00
|
|
|
}
|
|
|
|
p.outputFilePath = PathForModuleOut(ctx, filename).OutputPath
|
2019-06-04 00:29:27 +02:00
|
|
|
|
|
|
|
// If soc install dir was specified and SOC specific is set, set the installDirPath to the specified
|
|
|
|
// socInstallDirBase.
|
|
|
|
installBaseDir := p.installDirBase
|
|
|
|
if ctx.SocSpecific() && p.socInstallDirBase != "" {
|
|
|
|
installBaseDir = p.socInstallDirBase
|
|
|
|
}
|
|
|
|
p.installDirPath = PathForModuleInstall(ctx, installBaseDir, String(p.properties.Sub_dir))
|
2018-10-04 13:27:15 +02:00
|
|
|
|
2019-01-26 01:04:11 +01:00
|
|
|
// This ensures that outputFilePath has the correct name for others to
|
|
|
|
// use, as the source file may have a different name.
|
2018-10-04 13:27:15 +02:00
|
|
|
ctx.Build(pctx, BuildParams{
|
|
|
|
Rule: Cp,
|
|
|
|
Output: p.outputFilePath,
|
|
|
|
Input: p.sourceFilePath,
|
|
|
|
})
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2019-04-04 00:47:29 +02:00
|
|
|
func (p *PrebuiltEtc) AndroidMkEntries() AndroidMkEntries {
|
|
|
|
nameSuffix := ""
|
|
|
|
if p.inRecovery() && !p.onlyInRecovery() {
|
|
|
|
nameSuffix = ".recovery"
|
|
|
|
}
|
|
|
|
return AndroidMkEntries{
|
|
|
|
Class: "ETC",
|
|
|
|
SubName: nameSuffix,
|
|
|
|
OutputFile: OptionalPathForPath(p.outputFilePath),
|
|
|
|
AddCustomEntries: func(name, prefix, moduleDir string, entries *AndroidMkEntries) {
|
|
|
|
entries.SetString("LOCAL_MODULE_TAGS", "optional")
|
|
|
|
entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString())
|
|
|
|
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
|
|
|
|
entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable()))
|
2018-04-25 15:57:34 +02:00
|
|
|
if p.additionalDependencies != nil {
|
|
|
|
for _, path := range *p.additionalDependencies {
|
2019-04-04 00:47:29 +02:00
|
|
|
entries.SetString("LOCAL_ADDITIONAL_DEPENDENCIES", path.String())
|
2018-04-25 15:57:34 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 15:57:34 +02:00
|
|
|
func InitPrebuiltEtcModule(p *PrebuiltEtc) {
|
|
|
|
p.AddProperties(&p.properties)
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2019-03-11 23:58:50 +01:00
|
|
|
// prebuilt_etc is for a prebuilt artifact that is installed in
|
|
|
|
// <partition>/etc/<sub_dir> directory.
|
2018-04-25 15:57:34 +02:00
|
|
|
func PrebuiltEtcFactory() Module {
|
2019-02-13 14:50:33 +01:00
|
|
|
module := &PrebuiltEtc{installDirBase: "etc"}
|
2018-04-25 15:57:34 +02:00
|
|
|
InitPrebuiltEtcModule(module)
|
|
|
|
// This module is device-only
|
2019-01-15 19:47:05 +01:00
|
|
|
InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
|
2018-04-10 06:07:10 +02:00
|
|
|
return module
|
|
|
|
}
|
2018-08-15 07:20:22 +02:00
|
|
|
|
2019-03-11 23:58:50 +01:00
|
|
|
// prebuilt_etc_host is for a host prebuilt artifact that is installed in
|
|
|
|
// $(HOST_OUT)/etc/<sub_dir> directory.
|
2019-02-07 17:28:03 +01:00
|
|
|
func PrebuiltEtcHostFactory() Module {
|
2019-02-13 14:50:33 +01:00
|
|
|
module := &PrebuiltEtc{installDirBase: "etc"}
|
2019-02-04 23:34:10 +01:00
|
|
|
InitPrebuiltEtcModule(module)
|
|
|
|
// This module is host-only
|
|
|
|
InitAndroidArchModule(module, HostSupported, MultilibCommon)
|
|
|
|
return module
|
2019-02-13 14:50:33 +01:00
|
|
|
}
|
|
|
|
|
2019-03-11 23:58:50 +01:00
|
|
|
// prebuilt_usr_share is for a prebuilt artifact that is installed in
|
|
|
|
// <partition>/usr/share/<sub_dir> directory.
|
2019-02-13 14:50:33 +01:00
|
|
|
func PrebuiltUserShareFactory() Module {
|
|
|
|
module := &PrebuiltEtc{installDirBase: "usr/share"}
|
|
|
|
InitPrebuiltEtcModule(module)
|
|
|
|
// This module is device-only
|
|
|
|
InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
|
|
|
|
return module
|
2019-02-23 00:47:57 +01:00
|
|
|
}
|
|
|
|
|
2019-03-11 23:58:50 +01:00
|
|
|
// prebuild_usr_share_host is for a host prebuilt artifact that is installed in
|
|
|
|
// $(HOST_OUT)/usr/share/<sub_dir> directory.
|
2019-02-23 00:47:57 +01:00
|
|
|
func PrebuiltUserShareHostFactory() Module {
|
|
|
|
module := &PrebuiltEtc{installDirBase: "usr/share"}
|
|
|
|
InitPrebuiltEtcModule(module)
|
|
|
|
// This module is host-only
|
|
|
|
InitAndroidArchModule(module, HostSupported, MultilibCommon)
|
|
|
|
return module
|
2019-02-04 23:34:10 +01:00
|
|
|
}
|
|
|
|
|
2018-08-15 07:20:22 +02:00
|
|
|
const (
|
|
|
|
// coreMode is the variant for modules to be installed to system.
|
|
|
|
coreMode = "core"
|
|
|
|
|
|
|
|
// recoveryMode means a module to be installed to recovery image.
|
|
|
|
recoveryMode = "recovery"
|
|
|
|
)
|
|
|
|
|
|
|
|
// prebuiltEtcMutator creates the needed variants to install the module to
|
|
|
|
// system or recovery.
|
|
|
|
func prebuiltEtcMutator(mctx BottomUpMutatorContext) {
|
|
|
|
m, ok := mctx.Module().(*PrebuiltEtc)
|
2019-02-04 23:34:10 +01:00
|
|
|
if !ok || m.Host() {
|
2018-08-15 07:20:22 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var coreVariantNeeded bool = true
|
|
|
|
var recoveryVariantNeeded bool = false
|
|
|
|
if Bool(m.properties.Recovery_available) {
|
|
|
|
recoveryVariantNeeded = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.ModuleBase.InstallInRecovery() {
|
|
|
|
recoveryVariantNeeded = true
|
|
|
|
coreVariantNeeded = false
|
|
|
|
}
|
|
|
|
|
|
|
|
var variants []string
|
|
|
|
if coreVariantNeeded {
|
|
|
|
variants = append(variants, coreMode)
|
|
|
|
}
|
|
|
|
if recoveryVariantNeeded {
|
|
|
|
variants = append(variants, recoveryMode)
|
|
|
|
}
|
|
|
|
mod := mctx.CreateVariations(variants...)
|
|
|
|
for i, v := range variants {
|
|
|
|
if v == recoveryMode {
|
|
|
|
m := mod[i].(*PrebuiltEtc)
|
|
|
|
m.properties.InRecovery = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-14 17:20:45 +02:00
|
|
|
|
|
|
|
// prebuilt_font installs a font in <partition>/fonts directory.
|
|
|
|
func PrebuiltFontFactory() Module {
|
|
|
|
module := &PrebuiltEtc{installDirBase: "fonts"}
|
|
|
|
InitPrebuiltEtcModule(module)
|
|
|
|
// This module is device-only
|
|
|
|
InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
|
|
|
|
return module
|
|
|
|
}
|
2019-06-04 00:29:27 +02:00
|
|
|
|
|
|
|
// prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system image.
|
|
|
|
// If soc_specific property is set to true, the firmware file is installed to the vendor <partition>/firmware
|
|
|
|
// directory for vendor image.
|
|
|
|
func PrebuiltFirmwareFactory() Module {
|
|
|
|
module := &PrebuiltEtc{installDirBase: "etc/firmware", socInstallDirBase: "firmware"}
|
|
|
|
InitPrebuiltEtcModule(module)
|
|
|
|
// This module is device-only
|
|
|
|
InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
|
|
|
|
return module
|
|
|
|
}
|