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.
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
package etc
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2020-11-16 13:32:51 +01:00
|
|
|
// This file implements module types that install prebuilt artifacts.
|
|
|
|
//
|
|
|
|
// There exist two classes of prebuilt modules in the Android tree. The first class are the ones
|
|
|
|
// based on `android.Prebuilt`, such as `cc_prebuilt_library` and `java_import`. This kind of
|
|
|
|
// modules may exist both as prebuilts and source at the same time, though only one would be
|
|
|
|
// installed and the other would be marked disabled. The `prebuilt_postdeps` mutator would select
|
|
|
|
// the actual modules to be installed. More details in android/prebuilt.go.
|
|
|
|
//
|
|
|
|
// The second class is described in this file. Unlike `android.Prebuilt` based module types,
|
|
|
|
// `prebuilt_etc` exist only as prebuilts and cannot have a same-named source module counterpart.
|
|
|
|
// This makes the logic of `prebuilt_etc` to be much simpler as they don't need to go through the
|
|
|
|
// various `prebuilt_*` mutators.
|
2020-06-01 19:45:49 +02:00
|
|
|
|
2020-11-16 13:32:51 +01:00
|
|
|
import (
|
2021-07-19 04:38:04 +02:00
|
|
|
"encoding/json"
|
2021-02-15 22:50:37 +01:00
|
|
|
"fmt"
|
2021-07-19 04:38:04 +02:00
|
|
|
"path/filepath"
|
2022-06-09 20:52:05 +02:00
|
|
|
"reflect"
|
2021-04-06 14:00:17 +02:00
|
|
|
"strings"
|
2021-02-15 22:50:37 +01:00
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2021-07-28 14:03:16 +02:00
|
|
|
"android/soong/bazel"
|
2023-06-06 00:49:50 +02:00
|
|
|
"android/soong/bazel/cquery"
|
2021-07-19 04:38:04 +02:00
|
|
|
"android/soong/snapshot"
|
2023-09-05 15:18:50 +02:00
|
|
|
"android/soong/ui/metrics/bp2build_metrics_proto"
|
2020-06-01 19:45:49 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var pctx = android.NewPackageContext("android/soong/etc")
|
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() {
|
2020-06-01 19:45:49 +02:00
|
|
|
pctx.Import("android/soong/android")
|
2020-08-26 15:11:53 +02:00
|
|
|
RegisterPrebuiltEtcBuildComponents(android.InitRegistrationContext)
|
2021-07-19 04:38:04 +02:00
|
|
|
snapshot.RegisterSnapshotAction(generatePrebuiltSnapshot)
|
2020-08-26 15:11:53 +02:00
|
|
|
}
|
2020-06-01 19:45:49 +02:00
|
|
|
|
2020-08-26 15:11:53 +02:00
|
|
|
func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
|
|
|
|
ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
|
2022-12-01 19:38:26 +01:00
|
|
|
ctx.RegisterModuleType("prebuilt_etc_cacerts", PrebuiltEtcCaCertsFactory)
|
2021-04-06 14:00:17 +02:00
|
|
|
ctx.RegisterModuleType("prebuilt_root", PrebuiltRootFactory)
|
2022-01-04 23:27:52 +01:00
|
|
|
ctx.RegisterModuleType("prebuilt_root_host", PrebuiltRootHostFactory)
|
2020-08-26 15:11:53 +02:00
|
|
|
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)
|
2021-04-09 18:41:23 +02:00
|
|
|
ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory)
|
2021-05-06 13:46:11 +02:00
|
|
|
|
|
|
|
ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory)
|
2021-07-28 14:03:16 +02:00
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2021-03-08 12:28:18 +01:00
|
|
|
var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents)
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
type prebuiltEtcProperties struct {
|
2020-11-16 13:32:51 +01:00
|
|
|
// Source file of this prebuilt. Can reference a genrule type module with the ":module" syntax.
|
2019-03-05 07:35:41 +01:00
|
|
|
Src *string `android:"path,arch_variant"`
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2020-11-18 08:28:42 +01:00
|
|
|
// Optional name for the installed file. If unspecified, name of the module is used as the file
|
|
|
|
// name.
|
2018-10-26 14:49:39 +02:00
|
|
|
Filename *string `android:"arch_variant"`
|
|
|
|
|
2020-11-18 08:28:42 +01:00
|
|
|
// When set to true, and filename property is not set, the name for the installed file
|
2018-11-13 03:59:12 +01:00
|
|
|
// is the same as the file name of the source file.
|
|
|
|
Filename_from_src *bool `android:"arch_variant"`
|
|
|
|
|
2020-01-22 00:53:22 +01:00
|
|
|
// Make this module available when building for ramdisk.
|
2020-10-26 20:43:12 +01:00
|
|
|
// On device without a dedicated recovery partition, the module is only
|
|
|
|
// available after switching root into
|
|
|
|
// /first_stage_ramdisk. To expose the module before switching root, install
|
|
|
|
// the recovery variant instead.
|
2020-01-22 00:53:22 +01:00
|
|
|
Ramdisk_available *bool
|
|
|
|
|
2020-10-22 00:17:56 +02:00
|
|
|
// Make this module available when building for vendor ramdisk.
|
2020-10-26 20:43:12 +01:00
|
|
|
// On device without a dedicated recovery partition, the module is only
|
|
|
|
// available after switching root into
|
|
|
|
// /first_stage_ramdisk. To expose the module before switching root, install
|
|
|
|
// the recovery variant instead.
|
2020-10-22 00:17:56 +02:00
|
|
|
Vendor_ramdisk_available *bool
|
|
|
|
|
2021-04-08 14:13:22 +02:00
|
|
|
// Make this module available when building for debug ramdisk.
|
|
|
|
Debug_ramdisk_available *bool
|
|
|
|
|
2018-08-15 07:20:22 +02:00
|
|
|
// Make this module available when building for recovery.
|
|
|
|
Recovery_available *bool
|
|
|
|
|
2018-10-31 14:49:57 +01:00
|
|
|
// Whether this module is directly installable to one of the partitions. Default: true.
|
|
|
|
Installable *bool
|
2020-05-27 11:56:39 +02:00
|
|
|
|
|
|
|
// Install symlinks to the installed file.
|
|
|
|
Symlinks []string `android:"arch_variant"`
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 14:00:17 +02:00
|
|
|
type prebuiltSubdirProperties struct {
|
|
|
|
// 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"`
|
|
|
|
}
|
|
|
|
|
2019-11-06 08:53:07 +01:00
|
|
|
type PrebuiltEtcModule interface {
|
2020-06-01 19:45:49 +02:00
|
|
|
android.Module
|
2020-11-18 08:28:42 +01:00
|
|
|
|
|
|
|
// Returns the base install directory, such as "etc", "usr/share".
|
2020-08-26 15:11:53 +02:00
|
|
|
BaseDir() string
|
2020-11-18 08:28:42 +01:00
|
|
|
|
|
|
|
// Returns the sub install directory relative to BaseDir().
|
2019-11-06 08:53:07 +01:00
|
|
|
SubDir() string
|
2020-11-18 08:28:42 +01:00
|
|
|
|
|
|
|
// Returns an android.OutputPath to the intermeidate file, which is the renamed prebuilt source
|
|
|
|
// file.
|
2020-06-01 19:45:49 +02:00
|
|
|
OutputFile() android.OutputPath
|
2019-11-06 08:53:07 +01:00
|
|
|
}
|
|
|
|
|
2018-04-25 15:57:34 +02:00
|
|
|
type PrebuiltEtc struct {
|
2020-06-01 19:45:49 +02:00
|
|
|
android.ModuleBase
|
2021-05-06 13:46:11 +02:00
|
|
|
android.DefaultableModuleBase
|
2021-07-28 14:03:16 +02:00
|
|
|
android.BazelModuleBase
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2021-07-19 04:38:04 +02:00
|
|
|
snapshot.VendorSnapshotModuleInterface
|
|
|
|
snapshot.RecoverySnapshotModuleInterface
|
|
|
|
|
2021-04-06 14:00:17 +02:00
|
|
|
properties prebuiltEtcProperties
|
|
|
|
subdirProperties prebuiltSubdirProperties
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
sourceFilePath android.Path
|
|
|
|
outputFilePath android.OutputPath
|
2019-02-13 14:50:33 +01:00
|
|
|
// 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
|
2020-11-18 08:28:42 +01:00
|
|
|
// The base install location when soc_specific property is set to true, e.g. "firmware" for
|
|
|
|
// prebuilt_firmware.
|
2019-06-04 00:29:27 +02:00
|
|
|
socInstallDirBase string
|
2020-06-01 19:45:49 +02:00
|
|
|
installDirPath android.InstallPath
|
|
|
|
additionalDependencies *android.Paths
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2021-05-06 13:46:11 +02:00
|
|
|
type Defaults struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultsModuleBase
|
|
|
|
}
|
|
|
|
|
2020-01-22 00:53:22 +01:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2020-10-22 00:17:56 +02:00
|
|
|
func (p *PrebuiltEtc) inVendorRamdisk() bool {
|
|
|
|
return p.ModuleBase.InVendorRamdisk() || p.ModuleBase.InstallInVendorRamdisk()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) onlyInVendorRamdisk() bool {
|
|
|
|
return p.ModuleBase.InstallInVendorRamdisk()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) InstallInVendorRamdisk() bool {
|
|
|
|
return p.inVendorRamdisk()
|
|
|
|
}
|
|
|
|
|
2021-04-08 14:13:22 +02:00
|
|
|
func (p *PrebuiltEtc) inDebugRamdisk() bool {
|
|
|
|
return p.ModuleBase.InDebugRamdisk() || p.ModuleBase.InstallInDebugRamdisk()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) onlyInDebugRamdisk() bool {
|
|
|
|
return p.ModuleBase.InstallInDebugRamdisk()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) InstallInDebugRamdisk() bool {
|
|
|
|
return p.inDebugRamdisk()
|
|
|
|
}
|
|
|
|
|
2021-07-19 04:38:04 +02:00
|
|
|
func (p *PrebuiltEtc) InRecovery() bool {
|
2019-11-19 01:00:16 +01:00
|
|
|
return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery()
|
2018-08-15 07:20:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) onlyInRecovery() bool {
|
|
|
|
return p.ModuleBase.InstallInRecovery()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) InstallInRecovery() bool {
|
2021-07-19 04:38:04 +02:00
|
|
|
return p.InRecovery()
|
2018-08-15 07:20:22 +02:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
var _ android.ImageInterface = (*PrebuiltEtc)(nil)
|
2019-11-19 01:00:16 +01:00
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (p *PrebuiltEtc) ImageMutatorBegin(ctx android.BaseModuleContext) {}
|
2019-11-19 01:00:16 +01:00
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (p *PrebuiltEtc) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
|
2020-10-22 00:17:56 +02:00
|
|
|
return !p.ModuleBase.InstallInRecovery() && !p.ModuleBase.InstallInRamdisk() &&
|
2021-04-08 14:13:22 +02:00
|
|
|
!p.ModuleBase.InstallInVendorRamdisk() && !p.ModuleBase.InstallInDebugRamdisk()
|
2020-01-22 00:53:22 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (p *PrebuiltEtc) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return proptools.Bool(p.properties.Ramdisk_available) || p.ModuleBase.InstallInRamdisk()
|
2019-11-19 01:00:16 +01:00
|
|
|
}
|
|
|
|
|
2020-10-22 00:17:56 +02:00
|
|
|
func (p *PrebuiltEtc) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return proptools.Bool(p.properties.Vendor_ramdisk_available) || p.ModuleBase.InstallInVendorRamdisk()
|
|
|
|
}
|
|
|
|
|
2021-04-08 14:13:22 +02:00
|
|
|
func (p *PrebuiltEtc) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return proptools.Bool(p.properties.Debug_ramdisk_available) || p.ModuleBase.InstallInDebugRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return proptools.Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery()
|
2019-11-19 01:00:16 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (p *PrebuiltEtc) ExtraImageVariations(ctx android.BaseModuleContext) []string {
|
2019-11-19 01:00:16 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (p *PrebuiltEtc) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
|
2019-11-19 01:00:16 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (p *PrebuiltEtc) SourceFilePath(ctx android.ModuleContext) android.Path {
|
2020-11-18 08:28:42 +01:00
|
|
|
return android.PathForModuleSrc(ctx, proptools.String(p.properties.Src))
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (p *PrebuiltEtc) InstallDirPath() android.InstallPath {
|
2019-07-22 08:48:36 +02:00
|
|
|
return p.installDirPath
|
|
|
|
}
|
|
|
|
|
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.
|
2020-06-01 19:45:49 +02:00
|
|
|
func (p *PrebuiltEtc) SetAdditionalDependencies(paths android.Paths) {
|
2018-04-25 15:57:34 +02:00
|
|
|
p.additionalDependencies = &paths
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (p *PrebuiltEtc) OutputFile() android.OutputPath {
|
2018-10-04 13:27:15 +02:00
|
|
|
return p.outputFilePath
|
|
|
|
}
|
|
|
|
|
2021-02-15 22:50:37 +01:00
|
|
|
var _ android.OutputFileProducer = (*PrebuiltEtc)(nil)
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
switch tag {
|
|
|
|
case "":
|
|
|
|
return android.Paths{p.outputFilePath}, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 13:27:15 +02:00
|
|
|
func (p *PrebuiltEtc) SubDir() string {
|
2021-04-06 14:00:17 +02:00
|
|
|
if subDir := proptools.String(p.subdirProperties.Sub_dir); subDir != "" {
|
2020-06-26 19:12:36 +02:00
|
|
|
return subDir
|
|
|
|
}
|
2021-04-06 14:00:17 +02:00
|
|
|
return proptools.String(p.subdirProperties.Relative_install_path)
|
2018-10-04 13:27:15 +02:00
|
|
|
}
|
|
|
|
|
2020-08-26 15:11:53 +02:00
|
|
|
func (p *PrebuiltEtc) BaseDir() string {
|
2020-09-21 04:02:57 +02:00
|
|
|
return p.installDirBase
|
2020-08-26 15:11:53 +02:00
|
|
|
}
|
|
|
|
|
2018-10-31 14:49:57 +01:00
|
|
|
func (p *PrebuiltEtc) Installable() bool {
|
2020-11-18 08:28:42 +01:00
|
|
|
return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
|
2018-10-31 14:49:57 +01:00
|
|
|
}
|
|
|
|
|
2021-07-19 04:38:04 +02:00
|
|
|
func (p *PrebuiltEtc) InVendor() bool {
|
|
|
|
return p.ModuleBase.InstallInVendor()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) ExcludeFromVendorSnapshot() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrebuiltEtc) ExcludeFromRecoverySnapshot() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2020-11-18 08:28:42 +01:00
|
|
|
filename := proptools.String(p.properties.Filename)
|
|
|
|
filenameFromSrc := proptools.Bool(p.properties.Filename_from_src)
|
2022-10-04 00:31:29 +02:00
|
|
|
if p.properties.Src != nil {
|
|
|
|
p.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(p.properties.Src))
|
|
|
|
|
|
|
|
// Determine the output file basename.
|
|
|
|
// If Filename is set, use the name specified by the property.
|
|
|
|
// If Filename_from_src is set, use the source file name.
|
|
|
|
// Otherwise use the module name.
|
|
|
|
if filename != "" {
|
|
|
|
if filenameFromSrc {
|
|
|
|
ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else if filenameFromSrc {
|
|
|
|
filename = p.sourceFilePath.Base()
|
|
|
|
} else {
|
|
|
|
filename = ctx.ModuleName()
|
|
|
|
}
|
|
|
|
} else if ctx.Config().AllowMissingDependencies() {
|
|
|
|
// If no srcs was set and AllowMissingDependencies is enabled then
|
|
|
|
// mark the module as missing dependencies and set a fake source path
|
|
|
|
// and file name.
|
|
|
|
ctx.AddMissingDependencies([]string{"MISSING_PREBUILT_SRC_FILE"})
|
|
|
|
p.sourceFilePath = android.PathForModuleSrc(ctx)
|
|
|
|
if filename == "" {
|
|
|
|
filename = ctx.ModuleName()
|
2018-11-13 03:59:12 +01:00
|
|
|
}
|
2020-11-18 08:28:42 +01:00
|
|
|
} else {
|
2022-10-04 00:31:29 +02:00
|
|
|
ctx.PropertyErrorf("src", "missing prebuilt source file")
|
|
|
|
return
|
2018-10-26 14:49:39 +02:00
|
|
|
}
|
2019-06-04 00:29:27 +02:00
|
|
|
|
2021-04-06 14:00:17 +02:00
|
|
|
if strings.Contains(filename, "/") {
|
|
|
|
ctx.PropertyErrorf("filename", "filename cannot contain separator '/'")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-18 08:28:42 +01:00
|
|
|
// Check that `sub_dir` and `relative_install_path` are not set at the same time.
|
2021-04-06 14:00:17 +02:00
|
|
|
if p.subdirProperties.Sub_dir != nil && p.subdirProperties.Relative_install_path != nil {
|
2020-06-26 19:12:36 +02:00
|
|
|
ctx.PropertyErrorf("sub_dir", "relative_install_path is set. Cannot set sub_dir")
|
|
|
|
}
|
|
|
|
|
2020-11-18 08:28:42 +01:00
|
|
|
// If soc install dir was specified and SOC specific is set, set the installDirPath to the
|
|
|
|
// specified socInstallDirBase.
|
2020-09-21 04:02:57 +02:00
|
|
|
installBaseDir := p.installDirBase
|
|
|
|
if p.SocSpecific() && p.socInstallDirBase != "" {
|
|
|
|
installBaseDir = p.socInstallDirBase
|
|
|
|
}
|
|
|
|
p.installDirPath = android.PathForModuleInstall(ctx, installBaseDir, p.SubDir())
|
2018-10-04 13:27:15 +02:00
|
|
|
|
2023-06-06 00:49:50 +02:00
|
|
|
// Call InstallFile even when uninstallable to make the module included in the package
|
|
|
|
ip := installProperties{
|
|
|
|
installable: p.Installable(),
|
|
|
|
filename: filename,
|
|
|
|
sourceFilePath: p.sourceFilePath,
|
|
|
|
symlinks: p.properties.Symlinks,
|
|
|
|
}
|
|
|
|
p.addInstallRules(ctx, ip)
|
|
|
|
}
|
|
|
|
|
|
|
|
type installProperties struct {
|
|
|
|
installable bool
|
|
|
|
filename string
|
|
|
|
sourceFilePath android.Path
|
|
|
|
symlinks []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// utility function to add install rules to the build graph.
|
|
|
|
// Reduces code duplication between Soong and Mixed build analysis
|
|
|
|
func (p *PrebuiltEtc) addInstallRules(ctx android.ModuleContext, ip installProperties) {
|
|
|
|
if !ip.installable {
|
|
|
|
p.SkipInstall()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the file from src to a location in out/ with the correct `filename`
|
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.
|
2023-06-06 00:49:50 +02:00
|
|
|
p.outputFilePath = android.PathForModuleOut(ctx, ip.filename).OutputPath
|
2020-06-01 19:45:49 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
2018-10-04 13:27:15 +02:00
|
|
|
Output: p.outputFilePath,
|
2023-06-06 00:49:50 +02:00
|
|
|
Input: ip.sourceFilePath,
|
2018-10-04 13:27:15 +02:00
|
|
|
})
|
2020-09-29 13:15:08 +02:00
|
|
|
|
2023-06-06 00:49:50 +02:00
|
|
|
installPath := ctx.InstallFile(p.installDirPath, ip.filename, p.outputFilePath)
|
|
|
|
for _, sl := range ip.symlinks {
|
2021-02-17 07:48:53 +01:00
|
|
|
ctx.InstallSymlink(p.installDirPath, sl, installPath)
|
2020-09-29 13:15:08 +02:00
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries {
|
2019-04-04 00:47:29 +02:00
|
|
|
nameSuffix := ""
|
2020-01-22 00:53:22 +01:00
|
|
|
if p.inRamdisk() && !p.onlyInRamdisk() {
|
|
|
|
nameSuffix = ".ramdisk"
|
|
|
|
}
|
2020-10-22 00:17:56 +02:00
|
|
|
if p.inVendorRamdisk() && !p.onlyInVendorRamdisk() {
|
|
|
|
nameSuffix = ".vendor_ramdisk"
|
|
|
|
}
|
2021-04-08 14:13:22 +02:00
|
|
|
if p.inDebugRamdisk() && !p.onlyInDebugRamdisk() {
|
|
|
|
nameSuffix = ".debug_ramdisk"
|
|
|
|
}
|
2021-07-19 04:38:04 +02:00
|
|
|
if p.InRecovery() && !p.onlyInRecovery() {
|
2019-04-04 00:47:29 +02:00
|
|
|
nameSuffix = ".recovery"
|
|
|
|
}
|
2020-06-01 19:45:49 +02:00
|
|
|
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
2019-04-04 00:47:29 +02:00
|
|
|
Class: "ETC",
|
|
|
|
SubName: nameSuffix,
|
2020-06-01 19:45:49 +02:00
|
|
|
OutputFile: android.OptionalPathForPath(p.outputFilePath),
|
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
2020-07-03 22:18:24 +02:00
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
2019-08-28 02:33:16 +02:00
|
|
|
entries.SetString("LOCAL_MODULE_TAGS", "optional")
|
2021-11-12 03:59:15 +01:00
|
|
|
entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String())
|
2019-08-28 02:33:16 +02:00
|
|
|
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
|
2020-05-27 11:56:39 +02:00
|
|
|
if len(p.properties.Symlinks) > 0 {
|
|
|
|
entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...)
|
|
|
|
}
|
2020-11-16 13:32:51 +01:00
|
|
|
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.Installable())
|
2019-08-28 02:33:16 +02:00
|
|
|
if p.additionalDependencies != nil {
|
2020-11-16 13:32:51 +01:00
|
|
|
entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", p.additionalDependencies.Strings()...)
|
2018-04-25 15:57:34 +02:00
|
|
|
}
|
2019-08-28 02:33:16 +02:00
|
|
|
},
|
2018-04-10 06:07:10 +02:00
|
|
|
},
|
2019-12-03 05:24:29 +01:00
|
|
|
}}
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2019-07-22 08:48:36 +02:00
|
|
|
func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) {
|
|
|
|
p.installDirBase = dirBase
|
2018-04-25 15:57:34 +02:00
|
|
|
p.AddProperties(&p.properties)
|
2021-04-06 14:00:17 +02:00
|
|
|
p.AddProperties(&p.subdirProperties)
|
|
|
|
}
|
|
|
|
|
|
|
|
func InitPrebuiltRootModule(p *PrebuiltEtc) {
|
|
|
|
p.installDirBase = "."
|
|
|
|
p.AddProperties(&p.properties)
|
2018-04-25 15:57:34 +02:00
|
|
|
}
|
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.
|
2020-06-01 19:45:49 +02:00
|
|
|
func PrebuiltEtcFactory() android.Module {
|
2019-07-22 08:48:36 +02:00
|
|
|
module := &PrebuiltEtc{}
|
|
|
|
InitPrebuiltEtcModule(module, "etc")
|
2018-04-25 15:57:34 +02:00
|
|
|
// This module is device-only
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
|
2021-05-06 13:46:11 +02:00
|
|
|
android.InitDefaultableModule(module)
|
2021-07-28 14:03:16 +02:00
|
|
|
android.InitBazelModule(module)
|
2021-05-06 13:46:11 +02:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultsFactory() android.Module {
|
|
|
|
return DefaultsFactory()
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultsFactory(props ...interface{}) android.Module {
|
|
|
|
module := &Defaults{}
|
|
|
|
|
|
|
|
module.AddProperties(props...)
|
|
|
|
module.AddProperties(
|
|
|
|
&prebuiltEtcProperties{},
|
|
|
|
&prebuiltSubdirProperties{},
|
|
|
|
)
|
|
|
|
|
|
|
|
android.InitDefaultsModule(module)
|
|
|
|
|
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.
|
2020-06-01 19:45:49 +02:00
|
|
|
func PrebuiltEtcHostFactory() android.Module {
|
2019-07-22 08:48:36 +02:00
|
|
|
module := &PrebuiltEtc{}
|
|
|
|
InitPrebuiltEtcModule(module, "etc")
|
2019-02-04 23:34:10 +01:00
|
|
|
// This module is host-only
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
|
2021-10-14 01:42:59 +02:00
|
|
|
android.InitDefaultableModule(module)
|
2021-12-22 21:32:18 +01:00
|
|
|
android.InitBazelModule(module)
|
2019-02-04 23:34:10 +01:00
|
|
|
return module
|
2019-02-13 14:50:33 +01:00
|
|
|
}
|
|
|
|
|
2022-12-01 19:38:26 +01:00
|
|
|
// prebuilt_etc_host is for a host prebuilt artifact that is installed in
|
|
|
|
// <partition>/etc/<sub_dir> directory.
|
|
|
|
func PrebuiltEtcCaCertsFactory() android.Module {
|
|
|
|
module := &PrebuiltEtc{}
|
|
|
|
InitPrebuiltEtcModule(module, "cacerts")
|
|
|
|
// This module is device-only
|
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
|
|
|
|
android.InitBazelModule(module)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2021-04-06 14:00:17 +02:00
|
|
|
// prebuilt_root is for a prebuilt artifact that is installed in
|
|
|
|
// <partition>/ directory. Can't have any sub directories.
|
|
|
|
func PrebuiltRootFactory() android.Module {
|
|
|
|
module := &PrebuiltEtc{}
|
|
|
|
InitPrebuiltRootModule(module)
|
|
|
|
// This module is device-only
|
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
|
2021-10-14 01:42:59 +02:00
|
|
|
android.InitDefaultableModule(module)
|
2021-04-06 14:00:17 +02:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2022-01-04 23:27:52 +01:00
|
|
|
// prebuilt_root_host is for a host prebuilt artifact that is installed in $(HOST_OUT)/<sub_dir>
|
|
|
|
// directory.
|
|
|
|
func PrebuiltRootHostFactory() android.Module {
|
|
|
|
module := &PrebuiltEtc{}
|
|
|
|
InitPrebuiltEtcModule(module, ".")
|
|
|
|
// This module is host-only
|
|
|
|
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
|
|
|
|
android.InitDefaultableModule(module)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
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.
|
2020-06-01 19:45:49 +02:00
|
|
|
func PrebuiltUserShareFactory() android.Module {
|
2019-07-22 08:48:36 +02:00
|
|
|
module := &PrebuiltEtc{}
|
|
|
|
InitPrebuiltEtcModule(module, "usr/share")
|
2019-02-13 14:50:33 +01:00
|
|
|
// This module is device-only
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
|
2021-10-14 01:42:59 +02:00
|
|
|
android.InitDefaultableModule(module)
|
2022-03-01 00:22:59 +01:00
|
|
|
android.InitBazelModule(module)
|
2019-02-13 14:50:33 +01:00
|
|
|
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.
|
2020-06-01 19:45:49 +02:00
|
|
|
func PrebuiltUserShareHostFactory() android.Module {
|
2019-07-22 08:48:36 +02:00
|
|
|
module := &PrebuiltEtc{}
|
|
|
|
InitPrebuiltEtcModule(module, "usr/share")
|
2019-02-23 00:47:57 +01:00
|
|
|
// This module is host-only
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
|
2021-10-14 01:42:59 +02:00
|
|
|
android.InitDefaultableModule(module)
|
2019-02-23 00:47:57 +01:00
|
|
|
return module
|
2019-02-04 23:34:10 +01:00
|
|
|
}
|
|
|
|
|
2019-05-14 17:20:45 +02:00
|
|
|
// prebuilt_font installs a font in <partition>/fonts directory.
|
2020-06-01 19:45:49 +02:00
|
|
|
func PrebuiltFontFactory() android.Module {
|
2019-07-22 08:48:36 +02:00
|
|
|
module := &PrebuiltEtc{}
|
|
|
|
InitPrebuiltEtcModule(module, "fonts")
|
2019-05-14 17:20:45 +02:00
|
|
|
// This module is device-only
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
|
2021-10-14 01:42:59 +02:00
|
|
|
android.InitDefaultableModule(module)
|
2019-05-14 17:20:45 +02:00
|
|
|
return module
|
|
|
|
}
|
2019-06-04 00:29:27 +02:00
|
|
|
|
2020-11-18 08:28:42 +01: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.
|
2020-06-01 19:45:49 +02:00
|
|
|
func PrebuiltFirmwareFactory() android.Module {
|
2019-07-22 08:48:36 +02:00
|
|
|
module := &PrebuiltEtc{}
|
|
|
|
module.socInstallDirBase = "firmware"
|
|
|
|
InitPrebuiltEtcModule(module, "etc/firmware")
|
2019-06-04 00:29:27 +02:00
|
|
|
// This module is device-only
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
|
2021-10-14 01:42:59 +02:00
|
|
|
android.InitDefaultableModule(module)
|
2019-06-04 00:29:27 +02:00
|
|
|
return module
|
|
|
|
}
|
2020-06-08 23:40:25 +02:00
|
|
|
|
|
|
|
// prebuilt_dsp installs a DSP related file to <partition>/etc/dsp directory for system image.
|
2020-11-18 08:28:42 +01:00
|
|
|
// If soc_specific property is set to true, the DSP related file is installed to the
|
|
|
|
// vendor <partition>/dsp directory for vendor image.
|
2020-06-08 23:40:25 +02:00
|
|
|
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)
|
2021-10-14 01:42:59 +02:00
|
|
|
android.InitDefaultableModule(module)
|
2020-06-08 23:40:25 +02:00
|
|
|
return module
|
|
|
|
}
|
2021-04-09 18:41:23 +02:00
|
|
|
|
|
|
|
// prebuilt_rfsa installs a firmware file that will be available through Qualcomm's RFSA
|
|
|
|
// to the <partition>/lib/rfsa directory.
|
|
|
|
func PrebuiltRFSAFactory() android.Module {
|
|
|
|
module := &PrebuiltEtc{}
|
|
|
|
// Ideally these would go in /vendor/dsp, but the /vendor/lib/rfsa paths are hardcoded in too
|
|
|
|
// many places outside of the application processor. They could be moved to /vendor/dsp once
|
|
|
|
// that is cleaned up.
|
|
|
|
InitPrebuiltEtcModule(module, "lib/rfsa")
|
|
|
|
// This module is device-only
|
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
|
2021-10-14 01:42:59 +02:00
|
|
|
android.InitDefaultableModule(module)
|
2021-04-09 18:41:23 +02:00
|
|
|
return module
|
|
|
|
}
|
2021-07-19 04:38:04 +02:00
|
|
|
|
|
|
|
// Copy file into the snapshot
|
|
|
|
func copyFile(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath {
|
|
|
|
if fake {
|
|
|
|
// Create empty file instead for the fake snapshot
|
|
|
|
return snapshot.WriteStringToFileRule(ctx, "", out)
|
|
|
|
} else {
|
|
|
|
return snapshot.CopyFileRule(pctx, ctx, path, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the module is target of the snapshot
|
|
|
|
func isSnapshotAware(ctx android.SingletonContext, m *PrebuiltEtc, image snapshot.SnapshotImage) bool {
|
|
|
|
if !m.Enabled() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip if the module is not included in the image
|
|
|
|
if !image.InImage(m)() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// When android/prebuilt.go selects between source and prebuilt, it sets
|
|
|
|
// HideFromMake on the other one to avoid duplicate install rules in make.
|
|
|
|
if m.IsHideFromMake() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// There are some prebuilt_etc module with multiple definition of same name.
|
|
|
|
// Check if the target would be included from the build
|
|
|
|
if !m.ExportedToMake() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip if the module is in the predefined path list to skip
|
|
|
|
if image.IsProprietaryPath(ctx.ModuleDir(m), ctx.DeviceConfig()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip if the module should be excluded
|
|
|
|
if image.ExcludeFromSnapshot(m) || image.ExcludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip from other exceptional cases
|
|
|
|
if m.Target().Os.Class != android.Device {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if m.Target().NativeBridge == android.NativeBridgeEnabled {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-04-11 11:20:07 +02:00
|
|
|
func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths {
|
2021-07-19 04:38:04 +02:00
|
|
|
/*
|
|
|
|
Snapshot zipped artifacts directory structure for etc modules:
|
|
|
|
{SNAPSHOT_ARCH}/
|
|
|
|
arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
|
|
|
|
etc/
|
|
|
|
(prebuilt etc files)
|
|
|
|
arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
|
|
|
|
etc/
|
|
|
|
(prebuilt etc files)
|
|
|
|
NOTICE_FILES/
|
|
|
|
(notice files)
|
|
|
|
*/
|
|
|
|
var snapshotOutputs android.Paths
|
2023-04-11 11:20:07 +02:00
|
|
|
var snapshotNotices android.Paths
|
2021-07-19 04:38:04 +02:00
|
|
|
installedNotices := make(map[string]bool)
|
|
|
|
|
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
|
|
|
m, ok := module.(*PrebuiltEtc)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isSnapshotAware(ctx, m, s.Image) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
targetArch := "arch-" + m.Target().Arch.ArchType.String()
|
|
|
|
|
|
|
|
snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "etc", m.BaseModuleName())
|
|
|
|
snapshotOutputs = append(snapshotOutputs, copyFile(ctx, m.OutputFile(), snapshotLibOut, s.Fake))
|
|
|
|
|
2021-08-10 22:42:03 +02:00
|
|
|
prop := snapshot.SnapshotJsonFlags{}
|
2021-07-19 04:38:04 +02:00
|
|
|
propOut := snapshotLibOut + ".json"
|
2023-04-11 11:20:07 +02:00
|
|
|
prop.InitBaseSnapshotProps(m)
|
2023-05-12 08:53:06 +02:00
|
|
|
prop.RelativeInstallPath = m.SubDir()
|
2021-07-19 04:38:04 +02:00
|
|
|
|
|
|
|
if m.properties.Filename != nil {
|
|
|
|
prop.Filename = *m.properties.Filename
|
|
|
|
}
|
|
|
|
|
|
|
|
j, err := json.Marshal(prop)
|
|
|
|
if err != nil {
|
|
|
|
ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
snapshotOutputs = append(snapshotOutputs, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
|
|
|
|
|
2023-04-11 11:20:07 +02:00
|
|
|
for _, notice := range m.EffectiveLicenseFiles() {
|
|
|
|
if _, ok := installedNotices[notice.String()]; !ok {
|
|
|
|
installedNotices[notice.String()] = true
|
|
|
|
snapshotNotices = append(snapshotNotices, notice)
|
2021-07-19 04:38:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2023-04-11 11:20:07 +02:00
|
|
|
return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices}
|
2021-07-19 04:38:04 +02:00
|
|
|
}
|
2021-07-28 14:03:16 +02:00
|
|
|
|
|
|
|
// For Bazel / bp2build
|
|
|
|
|
2022-03-01 00:22:59 +01:00
|
|
|
type bazelPrebuiltFileAttributes struct {
|
2022-06-15 19:42:14 +02:00
|
|
|
Src bazel.LabelAttribute
|
|
|
|
Filename bazel.LabelAttribute
|
|
|
|
Dir string
|
|
|
|
Installable bazel.BoolAttribute
|
|
|
|
Filename_from_src bazel.BoolAttribute
|
2021-07-28 14:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-06-27 22:57:44 +02:00
|
|
|
// Bp2buildHelper returns a bazelPrebuiltFileAttributes used for the conversion
|
|
|
|
// of prebuilt_* modules. bazelPrebuiltFileAttributes has the common attributes
|
|
|
|
// used by both prebuilt_etc_xml and other prebuilt_* moodules
|
2023-09-05 15:18:50 +02:00
|
|
|
func (module *PrebuiltEtc) Bp2buildHelper(ctx android.TopDownMutatorContext) (*bazelPrebuiltFileAttributes, bool) {
|
2022-03-01 00:22:59 +01:00
|
|
|
var src bazel.LabelAttribute
|
2021-10-04 19:44:34 +02:00
|
|
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltEtcProperties{}) {
|
|
|
|
for config, p := range configToProps {
|
|
|
|
props, ok := p.(*prebuiltEtcProperties)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if props.Src != nil {
|
2023-09-05 15:18:50 +02:00
|
|
|
srcStr := proptools.String(props.Src)
|
|
|
|
if srcStr == ctx.ModuleName() {
|
|
|
|
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "src == name")
|
|
|
|
return &bazelPrebuiltFileAttributes{}, false
|
|
|
|
}
|
|
|
|
label := android.BazelLabelForModuleSrcSingle(ctx, srcStr)
|
2022-03-01 00:22:59 +01:00
|
|
|
src.SetSelectValue(axis, config, label)
|
2021-10-04 19:44:34 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-09 20:52:05 +02:00
|
|
|
|
2023-03-08 21:29:50 +01:00
|
|
|
for propName, productConfigProps := range android.ProductVariableProperties(ctx, ctx.Module()) {
|
2022-06-09 20:52:05 +02:00
|
|
|
for configProp, propVal := range productConfigProps {
|
|
|
|
if propName == "Src" {
|
|
|
|
props, ok := propVal.(*string)
|
|
|
|
if !ok {
|
|
|
|
ctx.PropertyErrorf(" Expected Property to have type string, but was %s\n", reflect.TypeOf(propVal).String())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if props != nil {
|
|
|
|
label := android.BazelLabelForModuleSrcSingle(ctx, *props)
|
|
|
|
src.SetSelectValue(configProp.ConfigurationAxis(), configProp.SelectKey(), label)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-28 14:03:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var filename string
|
2022-06-15 19:42:14 +02:00
|
|
|
var filenameFromSrc bool
|
|
|
|
moduleProps := module.properties
|
|
|
|
|
|
|
|
if moduleProps.Filename != nil && *moduleProps.Filename != "" {
|
|
|
|
filename = *moduleProps.Filename
|
|
|
|
} else if moduleProps.Filename_from_src != nil && *moduleProps.Filename_from_src {
|
|
|
|
if moduleProps.Src != nil {
|
|
|
|
filename = *moduleProps.Src
|
|
|
|
}
|
|
|
|
filenameFromSrc = true
|
|
|
|
} else {
|
|
|
|
filename = ctx.ModuleName()
|
2021-07-28 14:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-03-01 00:22:59 +01:00
|
|
|
var dir = module.installDirBase
|
|
|
|
if subDir := module.subdirProperties.Sub_dir; subDir != nil {
|
|
|
|
dir = dir + "/" + *subDir
|
2021-07-28 14:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-03-01 00:22:59 +01:00
|
|
|
var installable bazel.BoolAttribute
|
|
|
|
if install := module.properties.Installable; install != nil {
|
|
|
|
installable.Value = install
|
2021-07-28 14:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-03-01 00:22:59 +01:00
|
|
|
attrs := &bazelPrebuiltFileAttributes{
|
|
|
|
Src: src,
|
|
|
|
Dir: dir,
|
|
|
|
Installable: installable,
|
2021-07-28 14:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-06-15 19:42:14 +02:00
|
|
|
if filename != "" {
|
|
|
|
attrs.Filename = bazel.LabelAttribute{Value: &bazel.Label{Label: filename}}
|
|
|
|
} else if filenameFromSrc {
|
|
|
|
attrs.Filename_from_src = bazel.BoolAttribute{Value: moduleProps.Filename_from_src}
|
|
|
|
}
|
|
|
|
|
2023-09-05 15:18:50 +02:00
|
|
|
return attrs, true
|
2022-06-27 22:57:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConvertWithBp2build performs bp2build conversion of PrebuiltEtc
|
|
|
|
// prebuilt_* modules (except prebuilt_etc_xml) are PrebuiltEtc,
|
|
|
|
// which we treat as *PrebuiltFile*
|
|
|
|
func (module *PrebuiltEtc) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
|
|
|
var dir = module.installDirBase
|
|
|
|
// prebuilt_file supports only `etc` or `usr/share`
|
|
|
|
if !(dir == "etc" || dir == "usr/share") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-09-05 15:18:50 +02:00
|
|
|
attrs, convertible := module.Bp2buildHelper(ctx)
|
|
|
|
if !convertible {
|
|
|
|
return
|
|
|
|
}
|
2022-06-27 22:57:44 +02:00
|
|
|
|
2021-07-28 14:03:16 +02:00
|
|
|
props := bazel.BazelTargetModuleProperties{
|
2022-02-28 23:38:34 +01:00
|
|
|
Rule_class: "prebuilt_file",
|
|
|
|
Bzl_load_location: "//build/bazel/rules:prebuilt_file.bzl",
|
2021-07-28 14:03:16 +02:00
|
|
|
}
|
|
|
|
|
2021-08-31 22:30:36 +02:00
|
|
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
|
2021-07-28 14:03:16 +02:00
|
|
|
}
|
2023-06-06 00:49:50 +02:00
|
|
|
|
|
|
|
var _ android.MixedBuildBuildable = (*PrebuiltEtc)(nil)
|
|
|
|
|
|
|
|
func (pe *PrebuiltEtc) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pe *PrebuiltEtc) QueueBazelCall(ctx android.BaseModuleContext) {
|
|
|
|
ctx.Config().BazelContext.QueueBazelRequest(
|
|
|
|
pe.GetBazelLabel(ctx, pe),
|
|
|
|
cquery.GetPrebuiltFileInfo,
|
|
|
|
android.GetConfigKey(ctx),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pe *PrebuiltEtc) ProcessBazelQueryResponse(ctx android.ModuleContext) {
|
|
|
|
bazelCtx := ctx.Config().BazelContext
|
|
|
|
pfi, err := bazelCtx.GetPrebuiltFileInfo(pe.GetBazelLabel(ctx, pe), android.GetConfigKey(ctx))
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set properties for androidmk
|
|
|
|
pe.installDirPath = android.PathForModuleInstall(ctx, pfi.Dir)
|
|
|
|
|
|
|
|
// Installation rules
|
|
|
|
ip := installProperties{
|
|
|
|
installable: pfi.Installable,
|
|
|
|
filename: pfi.Filename,
|
|
|
|
sourceFilePath: android.PathForSource(ctx, pfi.Src),
|
|
|
|
// symlinks: pe.properties.Symlinks, // TODO: b/207489266 - Fully support all properties in prebuilt_file
|
|
|
|
}
|
|
|
|
pe.addInstallRules(ctx, ip)
|
|
|
|
}
|