1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
|
// 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 etc
import (
"strconv"
"github.com/google/blueprint/proptools"
"android/soong/android"
)
var pctx = android.NewPackageContext("android/soong/etc")
// TODO(jungw): Now that it handles more than the ones in etc/, consider renaming this file.
func init() {
pctx.Import("android/soong/android")
RegisterPrebuiltEtcBuildComponents(android.InitRegistrationContext)
}
func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
ctx.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
ctx.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory)
}
type prebuiltEtcProperties struct {
// Source file of this prebuilt.
Src *string `android:"path,arch_variant"`
// optional subdirectory under which this file is installed into, cannot be specified with relative_install_path, prefer relative_install_path
Sub_dir *string `android:"arch_variant"`
// optional subdirectory under which this file is installed into, cannot be specified with sub_dir
Relative_install_path *string `android:"arch_variant"`
// optional name for the installed file. If unspecified, name of the module is used as the file name
Filename *string `android:"arch_variant"`
// 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"`
// Make this module available when building for ramdisk.
Ramdisk_available *bool
// Make this module available when building for recovery.
Recovery_available *bool
// Whether this module is directly installable to one of the partitions. Default: true.
Installable *bool
// Install symlinks to the installed file.
Symlinks []string `android:"arch_variant"`
}
type PrebuiltEtcModule interface {
android.Module
BaseDir() string
SubDir() string
OutputFile() android.OutputPath
}
type PrebuiltEtc struct {
android.ModuleBase
properties prebuiltEtcProperties
sourceFilePath android.Path
outputFilePath android.OutputPath
// The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share.
installDirBase string
// The base install location when soc_specific property is set to true, e.g. "firmware" for prebuilt_firmware.
socInstallDirBase string
installDirPath android.InstallPath
additionalDependencies *android.Paths
}
func (p *PrebuiltEtc) inRamdisk() bool {
return p.ModuleBase.InRamdisk() || p.ModuleBase.InstallInRamdisk()
}
func (p *PrebuiltEtc) onlyInRamdisk() bool {
return p.ModuleBase.InstallInRamdisk()
}
func (p *PrebuiltEtc) InstallInRamdisk() bool {
return p.inRamdisk()
}
func (p *PrebuiltEtc) inRecovery() bool {
return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery()
}
func (p *PrebuiltEtc) onlyInRecovery() bool {
return p.ModuleBase.InstallInRecovery()
}
func (p *PrebuiltEtc) InstallInRecovery() bool {
return p.inRecovery()
}
var _ android.ImageInterface = (*PrebuiltEtc)(nil)
func (p *PrebuiltEtc) ImageMutatorBegin(ctx android.BaseModuleContext) {}
func (p *PrebuiltEtc) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
return !p.ModuleBase.InstallInRecovery() && !p.ModuleBase.InstallInRamdisk()
}
func (p *PrebuiltEtc) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
return proptools.Bool(p.properties.Ramdisk_available) || p.ModuleBase.InstallInRamdisk()
}
func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
return proptools.Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery()
}
func (p *PrebuiltEtc) ExtraImageVariations(ctx android.BaseModuleContext) []string {
return nil
}
func (p *PrebuiltEtc) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
}
func (p *PrebuiltEtc) DepsMutator(ctx android.BottomUpMutatorContext) {
if p.properties.Src == nil {
ctx.PropertyErrorf("src", "missing prebuilt source file")
}
}
func (p *PrebuiltEtc) SourceFilePath(ctx android.ModuleContext) android.Path {
return android.PathForModuleSrc(ctx, android.String(p.properties.Src))
}
func (p *PrebuiltEtc) InstallDirPath() android.InstallPath {
return p.installDirPath
}
// 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 android.Paths) {
p.additionalDependencies = &paths
}
func (p *PrebuiltEtc) OutputFile() android.OutputPath {
return p.outputFilePath
}
func (p *PrebuiltEtc) SubDir() string {
if subDir := proptools.String(p.properties.Sub_dir); subDir != "" {
return subDir
}
return proptools.String(p.properties.Relative_install_path)
}
func (p *PrebuiltEtc) BaseDir() string {
return p.installDirBase
}
func (p *PrebuiltEtc) Installable() bool {
return p.properties.Installable == nil || android.Bool(p.properties.Installable)
}
func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
p.sourceFilePath = android.PathForModuleSrc(ctx, android.String(p.properties.Src))
filename := android.String(p.properties.Filename)
filename_from_src := android.Bool(p.properties.Filename_from_src)
if filename == "" {
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
}
p.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
if p.properties.Sub_dir != nil && p.properties.Relative_install_path != nil {
ctx.PropertyErrorf("sub_dir", "relative_install_path is set. Cannot set sub_dir")
}
// If soc install dir was specified and SOC specific is set, set the installDirPath to the specified
// socInstallDirBase.
installBaseDir := p.installDirBase
if p.SocSpecific() && p.socInstallDirBase != "" {
installBaseDir = p.socInstallDirBase
}
p.installDirPath = android.PathForModuleInstall(ctx, installBaseDir, p.SubDir())
// This ensures that outputFilePath has the correct name for others to
// use, as the source file may have a different name.
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Output: p.outputFilePath,
Input: p.sourceFilePath,
})
if p.Installable() {
installPath := ctx.InstallFile(p.installDirPath, p.outputFilePath.Base(), p.outputFilePath)
for _, sl := range p.properties.Symlinks {
ctx.InstallSymlink(p.installDirPath, sl, installPath)
}
}
}
func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries {
nameSuffix := ""
if p.inRamdisk() && !p.onlyInRamdisk() {
nameSuffix = ".ramdisk"
}
if p.inRecovery() && !p.onlyInRecovery() {
nameSuffix = ".recovery"
}
return []android.AndroidMkEntries{android.AndroidMkEntries{
Class: "ETC",
SubName: nameSuffix,
OutputFile: android.OptionalPathForPath(p.outputFilePath),
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(entries *android.AndroidMkEntries) {
entries.SetString("LOCAL_MODULE_TAGS", "optional")
entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String())
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
if len(p.properties.Symlinks) > 0 {
entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...)
}
entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable()))
if p.additionalDependencies != nil {
for _, path := range *p.additionalDependencies {
entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", path.String())
}
}
},
},
}}
}
func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) {
p.installDirBase = dirBase
p.AddProperties(&p.properties)
}
// prebuilt_etc is for a prebuilt artifact that is installed in
// <partition>/etc/<sub_dir> directory.
func PrebuiltEtcFactory() android.Module {
module := &PrebuiltEtc{}
InitPrebuiltEtcModule(module, "etc")
// This module is device-only
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
return module
}
// prebuilt_etc_host is for a host prebuilt artifact that is installed in
// $(HOST_OUT)/etc/<sub_dir> directory.
func PrebuiltEtcHostFactory() android.Module {
module := &PrebuiltEtc{}
InitPrebuiltEtcModule(module, "etc")
// This module is host-only
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
return module
}
// prebuilt_usr_share is for a prebuilt artifact that is installed in
// <partition>/usr/share/<sub_dir> directory.
func PrebuiltUserShareFactory() android.Module {
module := &PrebuiltEtc{}
InitPrebuiltEtcModule(module, "usr/share")
// This module is device-only
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
return module
}
// prebuild_usr_share_host is for a host prebuilt artifact that is installed in
// $(HOST_OUT)/usr/share/<sub_dir> directory.
func PrebuiltUserShareHostFactory() android.Module {
module := &PrebuiltEtc{}
InitPrebuiltEtcModule(module, "usr/share")
// This module is host-only
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
return module
}
// prebuilt_font installs a font in <partition>/fonts directory.
func PrebuiltFontFactory() android.Module {
module := &PrebuiltEtc{}
InitPrebuiltEtcModule(module, "fonts")
// This module is device-only
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
return module
}
// 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() android.Module {
module := &PrebuiltEtc{}
module.socInstallDirBase = "firmware"
InitPrebuiltEtcModule(module, "etc/firmware")
// This module is device-only
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
return module
}
// prebuilt_dsp installs a DSP related file to <partition>/etc/dsp directory for system image.
// If soc_specific property is set to true, the DSP related file is installed to the vendor <partition>/dsp
// directory for vendor image.
func PrebuiltDSPFactory() android.Module {
module := &PrebuiltEtc{}
module.socInstallDirBase = "dsp"
InitPrebuiltEtcModule(module, "etc/dsp")
// This module is device-only
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
return module
}
|