add PackagingSpec
Currently, installation of a module is defined as an action of copying
the built artifact of the module to an install path like out/soong/host
(for host modules) and out/target/product/<device>/<partition> (for
device modules). After the modules are installed, the installed files
are further processed to create packages like system.img, vendor.img,
cvd-host-package.tar.gz, etc.
This notion of installation seems to have originated from the old time
when system.img is the primary product of the entire build process
(modulo a few more like root.img). Packaging the installed files as the
filesystem image was considered as a post-build step then.
However, this model doesn't seem to fit well to the current and future
environment where we have a lot more filesystem images (system, vendor,
system_ext, product, ...). The filesystem images themselves are even
grouped together to form a higher-level filesystem image like super.img.
Furthermore, things like cvd-host-package.tar.gz requires us to be able
to group some of the host tools in a format that isn't filesystem image.
Lastly, we are expected to have more filesystem images that are subsets
of system.img (and their friends) for the Android-like mini OS that will
be running on on-device virtual machines. These all imply that the
packaging (which we call installation today) is not a global post-build
step, but a part of the build rules for creating the package-like
modules.
A model better fits to the new sitatuation might be this; a module
specifies its built artifact and the path where it should be placed. The
latter path is not rooted at out/. It's a relative path to the root
directory which will be determined by another module that implements the
packaging. For example, cc_library will have ./lib (or ./lib64), not
out/target/product/<device>/<partition>/lib as the path. Then packages
like system.img, cvd-host-package.tar.gz, etc. are explicitly modeled as
modules and they have deps to other modules. Then the modules are placed
at the relative path under the package root, and the entire root
directory finally is packaged as the output file (be it img, tar.gz, or
whatever).
PackagingSpec is the first step to implement the new model. It abstracts
a request to place a built artifact at a certain path in a package. It
has extra information about whether the path should be a symlink or not,
and whether the path is for an executable. It currently is created when
InstallFiles (and its friends) are called, and can be retrieved via
the new method PackagingSpecs().
In this CL, no one is using PackagingSpec. The installation is still
done by the existing rules created in InstallFiles, etc. and the
structs are not used for the filesystem images like system.img.
Bug: 159685774
Bug: 172414391
Test: m
Change-Id: Ie1dec72d1ac14382fc3b74e5c850472e9320d6a3
2020-11-09 06:08:34 +01:00
|
|
|
// Copyright 2020 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
|
|
|
|
|
2020-11-09 10:38:48 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
2023-12-21 08:39:15 +01:00
|
|
|
"strings"
|
2020-11-09 10:38:48 +01:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2024-05-17 07:58:24 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
2020-11-09 10:38:48 +01:00
|
|
|
)
|
|
|
|
|
2020-11-25 03:31:13 +01:00
|
|
|
// PackagingSpec abstracts a request to place a built artifact at a certain path in a package. A
|
|
|
|
// package can be the traditional <partition>.img, but isn't limited to those. Other examples could
|
|
|
|
// be a new filesystem image that is a subset of system.img (e.g. for an Android-like mini OS
|
|
|
|
// running on a VM), or a zip archive for some of the host tools.
|
add PackagingSpec
Currently, installation of a module is defined as an action of copying
the built artifact of the module to an install path like out/soong/host
(for host modules) and out/target/product/<device>/<partition> (for
device modules). After the modules are installed, the installed files
are further processed to create packages like system.img, vendor.img,
cvd-host-package.tar.gz, etc.
This notion of installation seems to have originated from the old time
when system.img is the primary product of the entire build process
(modulo a few more like root.img). Packaging the installed files as the
filesystem image was considered as a post-build step then.
However, this model doesn't seem to fit well to the current and future
environment where we have a lot more filesystem images (system, vendor,
system_ext, product, ...). The filesystem images themselves are even
grouped together to form a higher-level filesystem image like super.img.
Furthermore, things like cvd-host-package.tar.gz requires us to be able
to group some of the host tools in a format that isn't filesystem image.
Lastly, we are expected to have more filesystem images that are subsets
of system.img (and their friends) for the Android-like mini OS that will
be running on on-device virtual machines. These all imply that the
packaging (which we call installation today) is not a global post-build
step, but a part of the build rules for creating the package-like
modules.
A model better fits to the new sitatuation might be this; a module
specifies its built artifact and the path where it should be placed. The
latter path is not rooted at out/. It's a relative path to the root
directory which will be determined by another module that implements the
packaging. For example, cc_library will have ./lib (or ./lib64), not
out/target/product/<device>/<partition>/lib as the path. Then packages
like system.img, cvd-host-package.tar.gz, etc. are explicitly modeled as
modules and they have deps to other modules. Then the modules are placed
at the relative path under the package root, and the entire root
directory finally is packaged as the output file (be it img, tar.gz, or
whatever).
PackagingSpec is the first step to implement the new model. It abstracts
a request to place a built artifact at a certain path in a package. It
has extra information about whether the path should be a symlink or not,
and whether the path is for an executable. It currently is created when
InstallFiles (and its friends) are called, and can be retrieved via
the new method PackagingSpecs().
In this CL, no one is using PackagingSpec. The installation is still
done by the existing rules created in InstallFiles, etc. and the
structs are not used for the filesystem images like system.img.
Bug: 159685774
Bug: 172414391
Test: m
Change-Id: Ie1dec72d1ac14382fc3b74e5c850472e9320d6a3
2020-11-09 06:08:34 +01:00
|
|
|
type PackagingSpec struct {
|
|
|
|
// Path relative to the root of the package
|
|
|
|
relPathInPackage string
|
|
|
|
|
|
|
|
// The path to the built artifact
|
|
|
|
srcPath Path
|
|
|
|
|
|
|
|
// If this is not empty, then relPathInPackage should be a symlink to this target. (Then
|
|
|
|
// srcPath is of course ignored.)
|
|
|
|
symlinkTarget string
|
|
|
|
|
|
|
|
// Whether relPathInPackage should be marked as executable or not
|
|
|
|
executable bool
|
2021-07-14 06:52:04 +02:00
|
|
|
|
|
|
|
effectiveLicenseFiles *Paths
|
2022-03-21 07:13:38 +01:00
|
|
|
|
|
|
|
partition string
|
2024-04-30 14:24:21 +02:00
|
|
|
|
|
|
|
// Whether this packaging spec represents an installation of the srcPath (i.e. this struct
|
|
|
|
// is created via InstallFile or InstallSymlink) or a simple packaging (i.e. created via
|
|
|
|
// PackageFile).
|
|
|
|
skipInstall bool
|
2024-05-07 07:32:14 +02:00
|
|
|
|
|
|
|
// Paths of aconfig files for the built artifact
|
|
|
|
aconfigPaths *Paths
|
2024-05-14 14:49:11 +02:00
|
|
|
|
|
|
|
// ArchType of the module which produced this packaging spec
|
|
|
|
archType ArchType
|
add PackagingSpec
Currently, installation of a module is defined as an action of copying
the built artifact of the module to an install path like out/soong/host
(for host modules) and out/target/product/<device>/<partition> (for
device modules). After the modules are installed, the installed files
are further processed to create packages like system.img, vendor.img,
cvd-host-package.tar.gz, etc.
This notion of installation seems to have originated from the old time
when system.img is the primary product of the entire build process
(modulo a few more like root.img). Packaging the installed files as the
filesystem image was considered as a post-build step then.
However, this model doesn't seem to fit well to the current and future
environment where we have a lot more filesystem images (system, vendor,
system_ext, product, ...). The filesystem images themselves are even
grouped together to form a higher-level filesystem image like super.img.
Furthermore, things like cvd-host-package.tar.gz requires us to be able
to group some of the host tools in a format that isn't filesystem image.
Lastly, we are expected to have more filesystem images that are subsets
of system.img (and their friends) for the Android-like mini OS that will
be running on on-device virtual machines. These all imply that the
packaging (which we call installation today) is not a global post-build
step, but a part of the build rules for creating the package-like
modules.
A model better fits to the new sitatuation might be this; a module
specifies its built artifact and the path where it should be placed. The
latter path is not rooted at out/. It's a relative path to the root
directory which will be determined by another module that implements the
packaging. For example, cc_library will have ./lib (or ./lib64), not
out/target/product/<device>/<partition>/lib as the path. Then packages
like system.img, cvd-host-package.tar.gz, etc. are explicitly modeled as
modules and they have deps to other modules. Then the modules are placed
at the relative path under the package root, and the entire root
directory finally is packaged as the output file (be it img, tar.gz, or
whatever).
PackagingSpec is the first step to implement the new model. It abstracts
a request to place a built artifact at a certain path in a package. It
has extra information about whether the path should be a symlink or not,
and whether the path is for an executable. It currently is created when
InstallFiles (and its friends) are called, and can be retrieved via
the new method PackagingSpecs().
In this CL, no one is using PackagingSpec. The installation is still
done by the existing rules created in InstallFiles, etc. and the
structs are not used for the filesystem images like system.img.
Bug: 159685774
Bug: 172414391
Test: m
Change-Id: Ie1dec72d1ac14382fc3b74e5c850472e9320d6a3
2020-11-09 06:08:34 +01:00
|
|
|
}
|
2020-11-09 10:38:48 +01:00
|
|
|
|
2024-05-01 14:36:10 +02:00
|
|
|
func (p *PackagingSpec) Equals(other *PackagingSpec) bool {
|
|
|
|
if other == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if p.relPathInPackage != other.relPathInPackage {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if p.srcPath != other.srcPath || p.symlinkTarget != other.symlinkTarget {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if p.executable != other.executable {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if p.partition != other.partition {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-11-16 02:48:44 +01:00
|
|
|
// Get file name of installed package
|
|
|
|
func (p *PackagingSpec) FileName() string {
|
|
|
|
if p.relPathInPackage != "" {
|
|
|
|
return filepath.Base(p.relPathInPackage)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2021-02-01 12:08:28 +01:00
|
|
|
// Path relative to the root of the package
|
|
|
|
func (p *PackagingSpec) RelPathInPackage() string {
|
|
|
|
return p.relPathInPackage
|
|
|
|
}
|
|
|
|
|
2021-07-14 06:52:04 +02:00
|
|
|
func (p *PackagingSpec) SetRelPathInPackage(relPathInPackage string) {
|
|
|
|
p.relPathInPackage = relPathInPackage
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PackagingSpec) EffectiveLicenseFiles() Paths {
|
|
|
|
if p.effectiveLicenseFiles == nil {
|
|
|
|
return Paths{}
|
|
|
|
}
|
|
|
|
return *p.effectiveLicenseFiles
|
|
|
|
}
|
|
|
|
|
2022-03-21 07:13:38 +01:00
|
|
|
func (p *PackagingSpec) Partition() string {
|
|
|
|
return p.partition
|
|
|
|
}
|
|
|
|
|
2024-04-30 14:24:21 +02:00
|
|
|
func (p *PackagingSpec) SkipInstall() bool {
|
|
|
|
return p.skipInstall
|
|
|
|
}
|
|
|
|
|
2024-05-07 07:32:14 +02:00
|
|
|
// Paths of aconfig files for the built artifact
|
|
|
|
func (p *PackagingSpec) GetAconfigPaths() Paths {
|
|
|
|
return *p.aconfigPaths
|
|
|
|
}
|
|
|
|
|
2020-11-09 10:38:48 +01:00
|
|
|
type PackageModule interface {
|
|
|
|
Module
|
|
|
|
packagingBase() *PackagingBase
|
|
|
|
|
|
|
|
// AddDeps adds dependencies to the `deps` modules. This should be called in DepsMutator.
|
2021-03-10 07:40:34 +01:00
|
|
|
// When adding the dependencies, depTag is used as the tag. If `deps` modules are meant to
|
|
|
|
// be copied to a zip in CopyDepsToZip, `depTag` should implement PackagingItem marker interface.
|
2020-11-25 04:44:59 +01:00
|
|
|
AddDeps(ctx BottomUpMutatorContext, depTag blueprint.DependencyTag)
|
2020-11-09 10:38:48 +01:00
|
|
|
|
2022-03-25 03:40:12 +01:00
|
|
|
// GatherPackagingSpecs gathers PackagingSpecs of transitive dependencies.
|
|
|
|
GatherPackagingSpecs(ctx ModuleContext) map[string]PackagingSpec
|
2024-02-08 02:44:37 +01:00
|
|
|
GatherPackagingSpecsWithFilter(ctx ModuleContext, filter func(PackagingSpec) bool) map[string]PackagingSpec
|
2022-03-25 03:40:12 +01:00
|
|
|
|
2020-11-09 10:38:48 +01:00
|
|
|
// CopyDepsToZip zips the built artifacts of the dependencies into the given zip file and
|
2020-11-25 03:31:13 +01:00
|
|
|
// returns zip entries in it. This is expected to be called in GenerateAndroidBuildActions,
|
2020-11-09 10:38:48 +01:00
|
|
|
// followed by a build rule that unzips it and creates the final output (img, zip, tar.gz,
|
|
|
|
// etc.) from the extracted files
|
2022-03-25 03:40:12 +01:00
|
|
|
CopyDepsToZip(ctx ModuleContext, specs map[string]PackagingSpec, zipOut WritablePath) []string
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// PackagingBase provides basic functionality for packaging dependencies. A module is expected to
|
|
|
|
// include this struct and call InitPackageModule.
|
|
|
|
type PackagingBase struct {
|
|
|
|
properties PackagingProperties
|
|
|
|
|
2020-11-25 03:31:13 +01:00
|
|
|
// Allows this module to skip missing dependencies. In most cases, this is not required, but
|
|
|
|
// for rare cases like when there's a dependency to a module which exists in certain repo
|
|
|
|
// checkouts, this is needed.
|
2020-11-09 10:38:48 +01:00
|
|
|
IgnoreMissingDependencies bool
|
2024-05-15 16:01:54 +02:00
|
|
|
|
|
|
|
// If this is set to true by a module type inheriting PackagingBase, the deps property
|
|
|
|
// collects the first target only even with compile_multilib: true.
|
|
|
|
DepsCollectFirstTargetOnly bool
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type depsProperty struct {
|
|
|
|
// Modules to include in this package
|
2024-05-17 07:58:24 +02:00
|
|
|
Deps proptools.Configurable[[]string] `android:"arch_variant"`
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type packagingMultilibProperties struct {
|
2024-05-20 09:17:39 +02:00
|
|
|
First depsProperty `android:"arch_variant"`
|
|
|
|
Common depsProperty `android:"arch_variant"`
|
|
|
|
Lib32 depsProperty `android:"arch_variant"`
|
|
|
|
Lib64 depsProperty `android:"arch_variant"`
|
|
|
|
Both depsProperty `android:"arch_variant"`
|
|
|
|
Prefer32 depsProperty `android:"arch_variant"`
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
|
2021-02-01 15:24:56 +01:00
|
|
|
type packagingArchProperties struct {
|
|
|
|
Arm64 depsProperty
|
|
|
|
Arm depsProperty
|
|
|
|
X86_64 depsProperty
|
|
|
|
X86 depsProperty
|
|
|
|
}
|
|
|
|
|
2020-11-09 10:38:48 +01:00
|
|
|
type PackagingProperties struct {
|
2024-05-17 07:58:24 +02:00
|
|
|
Deps proptools.Configurable[[]string] `android:"arch_variant"`
|
|
|
|
Multilib packagingMultilibProperties `android:"arch_variant"`
|
2021-02-01 15:24:56 +01:00
|
|
|
Arch packagingArchProperties
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func InitPackageModule(p PackageModule) {
|
|
|
|
base := p.packagingBase()
|
|
|
|
p.AddProperties(&base.properties)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PackagingBase) packagingBase() *PackagingBase {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2020-11-25 03:31:13 +01:00
|
|
|
// From deps and multilib.*.deps, select the dependencies that are for the given arch deps is for
|
|
|
|
// the current archicture when this module is not configured for multi target. When configured for
|
|
|
|
// multi target, deps is selected for each of the targets and is NOT selected for the current
|
|
|
|
// architecture which would be Common.
|
2020-11-09 10:38:48 +01:00
|
|
|
func (p *PackagingBase) getDepsForArch(ctx BaseModuleContext, arch ArchType) []string {
|
2024-05-17 07:58:24 +02:00
|
|
|
get := func(prop proptools.Configurable[[]string]) []string {
|
|
|
|
return prop.GetOrDefault(ctx, nil)
|
|
|
|
}
|
|
|
|
|
2020-11-09 10:38:48 +01:00
|
|
|
var ret []string
|
|
|
|
if arch == ctx.Target().Arch.ArchType && len(ctx.MultiTargets()) == 0 {
|
2024-05-17 07:58:24 +02:00
|
|
|
ret = append(ret, get(p.properties.Deps)...)
|
2020-11-09 10:38:48 +01:00
|
|
|
} else if arch.Multilib == "lib32" {
|
2024-05-17 07:58:24 +02:00
|
|
|
ret = append(ret, get(p.properties.Multilib.Lib32.Deps)...)
|
2024-05-20 09:17:39 +02:00
|
|
|
// multilib.prefer32.deps are added for lib32 only when they support 32-bit arch
|
|
|
|
for _, dep := range get(p.properties.Multilib.Prefer32.Deps) {
|
|
|
|
if checkIfOtherModuleSupportsLib32(ctx, dep) {
|
|
|
|
ret = append(ret, dep)
|
|
|
|
}
|
|
|
|
}
|
2020-11-09 10:38:48 +01:00
|
|
|
} else if arch.Multilib == "lib64" {
|
2024-05-17 07:58:24 +02:00
|
|
|
ret = append(ret, get(p.properties.Multilib.Lib64.Deps)...)
|
2024-05-20 09:17:39 +02:00
|
|
|
// multilib.prefer32.deps are added for lib64 only when they don't support 32-bit arch
|
|
|
|
for _, dep := range get(p.properties.Multilib.Prefer32.Deps) {
|
|
|
|
if !checkIfOtherModuleSupportsLib32(ctx, dep) {
|
|
|
|
ret = append(ret, dep)
|
|
|
|
}
|
|
|
|
}
|
2020-11-09 10:38:48 +01:00
|
|
|
} else if arch == Common {
|
2024-05-17 07:58:24 +02:00
|
|
|
ret = append(ret, get(p.properties.Multilib.Common.Deps)...)
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
2021-02-01 15:24:56 +01:00
|
|
|
|
2024-05-15 16:01:54 +02:00
|
|
|
if p.DepsCollectFirstTargetOnly {
|
2024-05-17 07:58:24 +02:00
|
|
|
if len(get(p.properties.Multilib.First.Deps)) > 0 {
|
2024-05-15 16:01:54 +02:00
|
|
|
ctx.PropertyErrorf("multilib.first.deps", "not supported. use \"deps\" instead")
|
|
|
|
}
|
|
|
|
for i, t := range ctx.MultiTargets() {
|
|
|
|
if t.Arch.ArchType == arch {
|
2024-05-17 07:58:24 +02:00
|
|
|
ret = append(ret, get(p.properties.Multilib.Both.Deps)...)
|
2024-05-15 16:01:54 +02:00
|
|
|
if i == 0 {
|
2024-05-17 07:58:24 +02:00
|
|
|
ret = append(ret, get(p.properties.Deps)...)
|
2024-05-15 16:01:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2024-05-17 07:58:24 +02:00
|
|
|
if len(get(p.properties.Multilib.Both.Deps)) > 0 {
|
2024-05-15 16:01:54 +02:00
|
|
|
ctx.PropertyErrorf("multilib.both.deps", "not supported. use \"deps\" instead")
|
|
|
|
}
|
|
|
|
for i, t := range ctx.MultiTargets() {
|
|
|
|
if t.Arch.ArchType == arch {
|
2024-05-17 07:58:24 +02:00
|
|
|
ret = append(ret, get(p.properties.Deps)...)
|
2024-05-15 16:01:54 +02:00
|
|
|
if i == 0 {
|
2024-05-17 07:58:24 +02:00
|
|
|
ret = append(ret, get(p.properties.Multilib.First.Deps)...)
|
2024-05-15 16:01:54 +02:00
|
|
|
}
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-01 15:24:56 +01:00
|
|
|
|
|
|
|
if ctx.Arch().ArchType == Common {
|
|
|
|
switch arch {
|
|
|
|
case Arm64:
|
2024-05-17 07:58:24 +02:00
|
|
|
ret = append(ret, get(p.properties.Arch.Arm64.Deps)...)
|
2021-02-01 15:24:56 +01:00
|
|
|
case Arm:
|
2024-05-17 07:58:24 +02:00
|
|
|
ret = append(ret, get(p.properties.Arch.Arm.Deps)...)
|
2021-02-01 15:24:56 +01:00
|
|
|
case X86_64:
|
2024-05-17 07:58:24 +02:00
|
|
|
ret = append(ret, get(p.properties.Arch.X86_64.Deps)...)
|
2021-02-01 15:24:56 +01:00
|
|
|
case X86:
|
2024-05-17 07:58:24 +02:00
|
|
|
ret = append(ret, get(p.properties.Arch.X86.Deps)...)
|
2021-02-01 15:24:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-09 10:38:48 +01:00
|
|
|
return FirstUniqueStrings(ret)
|
|
|
|
}
|
|
|
|
|
2024-05-20 09:17:39 +02:00
|
|
|
func getSupportedTargets(ctx BaseModuleContext) []Target {
|
2020-11-09 10:38:48 +01:00
|
|
|
var ret []Target
|
|
|
|
// The current and the common OS targets are always supported
|
|
|
|
ret = append(ret, ctx.Target())
|
|
|
|
if ctx.Arch().ArchType != Common {
|
|
|
|
ret = append(ret, Target{Os: ctx.Os(), Arch: Arch{ArchType: Common}})
|
|
|
|
}
|
|
|
|
// If this module is configured for multi targets, those should be supported as well
|
|
|
|
ret = append(ret, ctx.MultiTargets()...)
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2024-05-20 09:17:39 +02:00
|
|
|
// getLib32Target returns the 32-bit target from the list of targets this module supports. If this
|
|
|
|
// module doesn't support 32-bit target, nil is returned.
|
|
|
|
func getLib32Target(ctx BaseModuleContext) *Target {
|
|
|
|
for _, t := range getSupportedTargets(ctx) {
|
|
|
|
if t.Arch.ArchType.Multilib == "lib32" {
|
|
|
|
return &t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// checkIfOtherModuleSUpportsLib32 returns true if 32-bit variant of dep exists.
|
|
|
|
func checkIfOtherModuleSupportsLib32(ctx BaseModuleContext, dep string) bool {
|
|
|
|
t := getLib32Target(ctx)
|
|
|
|
if t == nil {
|
|
|
|
// This packaging module doesn't support 32bit. No point of checking if dep supports 32-bit
|
|
|
|
// or not.
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return ctx.OtherModuleFarDependencyVariantExists(t.Variations(), dep)
|
|
|
|
}
|
|
|
|
|
2021-03-10 07:40:34 +01:00
|
|
|
// PackagingItem is a marker interface for dependency tags.
|
|
|
|
// Direct dependencies with a tag implementing PackagingItem are packaged in CopyDepsToZip().
|
|
|
|
type PackagingItem interface {
|
|
|
|
// IsPackagingItem returns true if the dep is to be packaged
|
|
|
|
IsPackagingItem() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// DepTag provides default implementation of PackagingItem interface.
|
|
|
|
// PackagingBase-derived modules can define their own dependency tag by embedding this, which
|
|
|
|
// can be passed to AddDeps() or AddDependencies().
|
|
|
|
type PackagingItemAlwaysDepTag struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsPackagingItem returns true if the dep is to be packaged
|
|
|
|
func (PackagingItemAlwaysDepTag) IsPackagingItem() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-11-09 10:38:48 +01:00
|
|
|
// See PackageModule.AddDeps
|
2020-11-25 04:44:59 +01:00
|
|
|
func (p *PackagingBase) AddDeps(ctx BottomUpMutatorContext, depTag blueprint.DependencyTag) {
|
2024-05-20 09:17:39 +02:00
|
|
|
for _, t := range getSupportedTargets(ctx) {
|
2020-11-09 10:38:48 +01:00
|
|
|
for _, dep := range p.getDepsForArch(ctx, t.Arch.ArchType) {
|
|
|
|
if p.IgnoreMissingDependencies && !ctx.OtherModuleExists(dep) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ctx.AddFarVariationDependencies(t.Variations(), depTag, dep)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-08 02:44:37 +01:00
|
|
|
func (p *PackagingBase) GatherPackagingSpecsWithFilter(ctx ModuleContext, filter func(PackagingSpec) bool) map[string]PackagingSpec {
|
2020-11-09 10:38:48 +01:00
|
|
|
m := make(map[string]PackagingSpec)
|
2024-05-14 14:49:11 +02:00
|
|
|
|
|
|
|
var arches []ArchType
|
2024-05-20 09:17:39 +02:00
|
|
|
for _, target := range getSupportedTargets(ctx) {
|
2024-05-14 14:49:11 +02:00
|
|
|
arches = append(arches, target.Arch.ArchType)
|
|
|
|
}
|
|
|
|
|
|
|
|
// filter out packaging specs for unsupported architecture
|
|
|
|
filterArch := func(ps PackagingSpec) bool {
|
|
|
|
for _, arch := range arches {
|
|
|
|
if arch == ps.archType {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-03-10 07:40:34 +01:00
|
|
|
ctx.VisitDirectDeps(func(child Module) {
|
|
|
|
if pi, ok := ctx.OtherModuleDependencyTag(child).(PackagingItem); !ok || !pi.IsPackagingItem() {
|
|
|
|
return
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
2021-03-10 07:40:34 +01:00
|
|
|
for _, ps := range child.TransitivePackagingSpecs() {
|
2024-05-14 14:49:11 +02:00
|
|
|
if !filterArch(ps) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-02-08 02:44:37 +01:00
|
|
|
if filter != nil {
|
|
|
|
if !filter(ps) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2024-05-01 14:36:10 +02:00
|
|
|
dstPath := ps.relPathInPackage
|
|
|
|
if existingPs, ok := m[dstPath]; ok {
|
|
|
|
if !existingPs.Equals(&ps) {
|
|
|
|
ctx.ModuleErrorf("packaging conflict at %v:\n%v\n%v", dstPath, existingPs, ps)
|
|
|
|
}
|
|
|
|
continue
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
2024-05-01 14:36:10 +02:00
|
|
|
|
|
|
|
m[dstPath] = ps
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
})
|
2021-05-11 04:13:30 +02:00
|
|
|
return m
|
|
|
|
}
|
2020-11-09 10:38:48 +01:00
|
|
|
|
2024-02-08 02:44:37 +01:00
|
|
|
// See PackageModule.GatherPackagingSpecs
|
|
|
|
func (p *PackagingBase) GatherPackagingSpecs(ctx ModuleContext) map[string]PackagingSpec {
|
|
|
|
return p.GatherPackagingSpecsWithFilter(ctx, nil)
|
|
|
|
}
|
|
|
|
|
2021-07-14 06:52:04 +02:00
|
|
|
// CopySpecsToDir is a helper that will add commands to the rule builder to copy the PackagingSpec
|
|
|
|
// entries into the specified directory.
|
2023-03-16 06:24:03 +01:00
|
|
|
func (p *PackagingBase) CopySpecsToDir(ctx ModuleContext, builder *RuleBuilder, specs map[string]PackagingSpec, dir WritablePath) (entries []string) {
|
2024-01-04 00:16:55 +01:00
|
|
|
if len(specs) == 0 {
|
|
|
|
return entries
|
|
|
|
}
|
2020-11-09 10:38:48 +01:00
|
|
|
seenDir := make(map[string]bool)
|
2023-12-21 08:39:15 +01:00
|
|
|
preparerPath := PathForModuleOut(ctx, "preparer.sh")
|
|
|
|
cmd := builder.Command().Tool(preparerPath)
|
|
|
|
var sb strings.Builder
|
2024-01-04 00:16:55 +01:00
|
|
|
sb.WriteString("set -e\n")
|
2023-03-01 01:02:16 +01:00
|
|
|
for _, k := range SortedKeys(specs) {
|
2022-03-25 03:40:12 +01:00
|
|
|
ps := specs[k]
|
2023-03-16 06:24:03 +01:00
|
|
|
destPath := filepath.Join(dir.String(), ps.relPathInPackage)
|
2020-11-09 10:38:48 +01:00
|
|
|
destDir := filepath.Dir(destPath)
|
|
|
|
entries = append(entries, ps.relPathInPackage)
|
|
|
|
if _, ok := seenDir[destDir]; !ok {
|
|
|
|
seenDir[destDir] = true
|
2023-12-21 08:39:15 +01:00
|
|
|
sb.WriteString(fmt.Sprintf("mkdir -p %s\n", destDir))
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
if ps.symlinkTarget == "" {
|
2023-12-21 08:39:15 +01:00
|
|
|
cmd.Implicit(ps.srcPath)
|
|
|
|
sb.WriteString(fmt.Sprintf("cp %s %s\n", ps.srcPath, destPath))
|
2020-11-09 10:38:48 +01:00
|
|
|
} else {
|
2023-12-21 08:39:15 +01:00
|
|
|
sb.WriteString(fmt.Sprintf("ln -sf %s %s\n", ps.symlinkTarget, destPath))
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
if ps.executable {
|
2023-12-21 08:39:15 +01:00
|
|
|
sb.WriteString(fmt.Sprintf("chmod a+x %s\n", destPath))
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-21 08:39:15 +01:00
|
|
|
WriteExecutableFileRuleVerbatim(ctx, preparerPath, sb.String())
|
|
|
|
|
2021-07-14 06:52:04 +02:00
|
|
|
return entries
|
|
|
|
}
|
|
|
|
|
|
|
|
// See PackageModule.CopyDepsToZip
|
2022-03-25 03:40:12 +01:00
|
|
|
func (p *PackagingBase) CopyDepsToZip(ctx ModuleContext, specs map[string]PackagingSpec, zipOut WritablePath) (entries []string) {
|
2021-07-14 06:52:04 +02:00
|
|
|
builder := NewRuleBuilder(pctx, ctx)
|
|
|
|
|
|
|
|
dir := PathForModuleOut(ctx, ".zip")
|
|
|
|
builder.Command().Text("rm").Flag("-rf").Text(dir.String())
|
|
|
|
builder.Command().Text("mkdir").Flag("-p").Text(dir.String())
|
2022-03-25 03:40:12 +01:00
|
|
|
entries = p.CopySpecsToDir(ctx, builder, specs, dir)
|
2021-07-14 06:52:04 +02:00
|
|
|
|
2020-11-09 10:38:48 +01:00
|
|
|
builder.Command().
|
2020-11-17 02:32:30 +01:00
|
|
|
BuiltTool("soong_zip").
|
2020-11-09 10:38:48 +01:00
|
|
|
FlagWithOutput("-o ", zipOut).
|
|
|
|
FlagWithArg("-C ", dir.String()).
|
|
|
|
Flag("-L 0"). // no compression because this will be unzipped soon
|
|
|
|
FlagWithArg("-D ", dir.String())
|
|
|
|
builder.Command().Text("rm").Flag("-rf").Text(dir.String())
|
|
|
|
|
2020-11-17 02:32:30 +01:00
|
|
|
builder.Build("zip_deps", fmt.Sprintf("Zipping deps for %s", ctx.ModuleName()))
|
2020-11-09 10:38:48 +01:00
|
|
|
return entries
|
|
|
|
}
|