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
This commit is contained in:
Jiyong Park
2020-11-09 14:08:34 +09:00
parent e3d308b5a5
commit 073ea55fad
3 changed files with 79 additions and 8 deletions

View File

@@ -440,6 +440,7 @@ type Module interface {
TargetRequiredModuleNames() []string
FilesToInstall() InstallPaths
PackagingSpecs() []PackagingSpec
}
// Qualified id for a module
@@ -934,6 +935,7 @@ type ModuleBase struct {
noAddressSanitizer bool
installFiles InstallPaths
checkbuildFiles Paths
packagingSpecs []PackagingSpec
noticeFiles Paths
phonies map[string]Paths
@@ -1259,6 +1261,10 @@ func (m *ModuleBase) FilesToInstall() InstallPaths {
return m.installFiles
}
func (m *ModuleBase) PackagingSpecs() []PackagingSpec {
return m.packagingSpecs
}
func (m *ModuleBase) NoAddressSanitizer() bool {
return m.noAddressSanitizer
}
@@ -1581,6 +1587,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
m.installFiles = append(m.installFiles, ctx.installFiles...)
m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
m.packagingSpecs = append(m.packagingSpecs, ctx.packagingSpecs...)
m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc)
m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments)
for k, v := range ctx.phonies {
@@ -1748,6 +1755,7 @@ func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleCon
type moduleContext struct {
bp blueprint.ModuleContext
baseModuleContext
packagingSpecs []PackagingSpec
installDeps InstallPaths
installFiles InstallPaths
checkbuildFiles Paths
@@ -2284,16 +2292,15 @@ func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
deps ...Path) InstallPath {
return m.installFile(installPath, name, srcPath, Cp, deps)
return m.installFile(installPath, name, srcPath, deps, false)
}
func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
deps ...Path) InstallPath {
return m.installFile(installPath, name, srcPath, CpExecutable, deps)
return m.installFile(installPath, name, srcPath, deps, true)
}
func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path,
rule blueprint.Rule, deps []Path) InstallPath {
func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []Path, executable bool) InstallPath {
fullInstallPath := installPath.Join(m, name)
m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
@@ -2312,6 +2319,11 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat
orderOnlyDeps = deps
}
rule := Cp
if executable {
rule = CpExecutable
}
m.Build(pctx, BuildParams{
Rule: rule,
Description: "install " + fullInstallPath.Base(),
@@ -2324,6 +2336,14 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat
m.installFiles = append(m.installFiles, fullInstallPath)
}
m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
srcPath: srcPath,
symlinkTarget: "",
executable: executable,
})
m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
return fullInstallPath
}
@@ -2332,12 +2352,12 @@ func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, src
fullInstallPath := installPath.Join(m, name)
m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true)
relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
if err != nil {
panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
}
if !m.skipInstall(fullInstallPath) {
relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
if err != nil {
panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
}
m.Build(pctx, BuildParams{
Rule: Symlink,
Description: "install symlink " + fullInstallPath.Base(),
@@ -2352,6 +2372,14 @@ func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, src
m.installFiles = append(m.installFiles, fullInstallPath)
m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
}
m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
srcPath: nil,
symlinkTarget: relPath,
executable: false,
})
return fullInstallPath
}
@@ -2374,6 +2402,14 @@ func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name str
m.installFiles = append(m.installFiles, fullInstallPath)
}
m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
srcPath: nil,
symlinkTarget: absPath,
executable: false,
})
return fullInstallPath
}