Merge "Export Soong install rules to Make"

This commit is contained in:
Colin Cross
2021-11-01 21:31:56 +00:00
committed by Gerrit Code Review
4 changed files with 220 additions and 43 deletions

View File

@@ -1194,7 +1194,10 @@ type ModuleBase struct {
packagingSpecs []PackagingSpec
packagingSpecsDepSet *packagingSpecsDepSet
noticeFiles Paths
phonies map[string]Paths
// katiInstalls tracks the install rules that were created by Soong but are being exported
// to Make to convert to ninja rules so that Make can add additional dependencies.
katiInstalls katiInstalls
katiSymlinks katiInstalls
// The files to copy to the dist as explicitly specified in the .bp file.
distFiles TaggedDistFiles
@@ -2016,9 +2019,8 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
m.tidyFiles = append(m.tidyFiles, ctx.tidyFiles...)
m.packagingSpecs = append(m.packagingSpecs, ctx.packagingSpecs...)
for k, v := range ctx.phonies {
m.phonies[k] = append(m.phonies[k], v...)
}
m.katiInstalls = append(m.katiInstalls, ctx.katiInstalls...)
m.katiSymlinks = append(m.katiSymlinks, ctx.katiSymlinks...)
} else if ctx.Config().AllowMissingDependencies() {
// If the module is not enabled it will not create any build rules, nothing will call
// ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
@@ -2217,12 +2219,52 @@ type moduleContext struct {
module Module
phonies map[string]Paths
katiInstalls []katiInstall
katiSymlinks []katiInstall
// For tests
buildParams []BuildParams
ruleParams map[blueprint.Rule]blueprint.RuleParams
variables map[string]string
}
// katiInstall stores a request from Soong to Make to create an install rule.
type katiInstall struct {
from Path
to InstallPath
implicitDeps Paths
orderOnlyDeps Paths
executable bool
absFrom string
}
type katiInstalls []katiInstall
// BuiltInstalled returns the katiInstalls in the form used by $(call copy-many-files) in Make, a
// space separated list of from:to tuples.
func (installs katiInstalls) BuiltInstalled() string {
sb := strings.Builder{}
for i, install := range installs {
if i != 0 {
sb.WriteRune(' ')
}
sb.WriteString(install.from.String())
sb.WriteRune(':')
sb.WriteString(install.to.String())
}
return sb.String()
}
// InstallPaths returns the install path of each entry.
func (installs katiInstalls) InstallPaths() InstallPaths {
paths := make(InstallPaths, 0, len(installs))
for _, install := range installs {
paths = append(paths, install.to)
}
return paths
}
func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
return pctx, BuildParams{
Rule: ErrorRule,
@@ -2854,20 +2896,33 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat
orderOnlyDeps = deps
}
rule := Cp
if executable {
rule = CpExecutable
}
if m.Config().KatiEnabled() && m.InstallBypassMake() {
// When creating the install rule in Soong but embedding in Make, write the rule to a
// makefile instead of directly to the ninja file so that main.mk can add the
// dependencies from the `required` property that are hard to resolve in Soong.
m.katiInstalls = append(m.katiInstalls, katiInstall{
from: srcPath,
to: fullInstallPath,
implicitDeps: implicitDeps,
orderOnlyDeps: orderOnlyDeps,
executable: executable,
})
} else {
rule := Cp
if executable {
rule = CpExecutable
}
m.Build(pctx, BuildParams{
Rule: rule,
Description: "install " + fullInstallPath.Base(),
Output: fullInstallPath,
Input: srcPath,
Implicits: implicitDeps,
OrderOnly: orderOnlyDeps,
Default: !m.Config().KatiEnabled(),
})
m.Build(pctx, BuildParams{
Rule: rule,
Description: "install " + fullInstallPath.Base(),
Output: fullInstallPath,
Input: srcPath,
Implicits: implicitDeps,
OrderOnly: orderOnlyDeps,
Default: !m.Config().KatiEnabled(),
})
}
m.installFiles = append(m.installFiles, fullInstallPath)
}
@@ -2889,16 +2944,26 @@ func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, src
}
if !m.skipInstall() {
m.Build(pctx, BuildParams{
Rule: Symlink,
Description: "install symlink " + fullInstallPath.Base(),
Output: fullInstallPath,
Input: srcPath,
Default: !m.Config().KatiEnabled(),
Args: map[string]string{
"fromPath": relPath,
},
})
if m.Config().KatiEnabled() && m.InstallBypassMake() {
// When creating the symlink rule in Soong but embedding in Make, write the rule to a
// makefile instead of directly to the ninja file so that main.mk can add the
// dependencies from the `required` property that are hard to resolve in Soong.
m.katiSymlinks = append(m.katiSymlinks, katiInstall{
from: srcPath,
to: fullInstallPath,
})
} else {
m.Build(pctx, BuildParams{
Rule: Symlink,
Description: "install symlink " + fullInstallPath.Base(),
Output: fullInstallPath,
Input: srcPath,
Default: !m.Config().KatiEnabled(),
Args: map[string]string{
"fromPath": relPath,
},
})
}
m.installFiles = append(m.installFiles, fullInstallPath)
m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
@@ -2921,15 +2986,25 @@ func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name str
m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true)
if !m.skipInstall() {
m.Build(pctx, BuildParams{
Rule: Symlink,
Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
Output: fullInstallPath,
Default: !m.Config().KatiEnabled(),
Args: map[string]string{
"fromPath": absPath,
},
})
if m.Config().KatiEnabled() && m.InstallBypassMake() {
// When creating the symlink rule in Soong but embedding in Make, write the rule to a
// makefile instead of directly to the ninja file so that main.mk can add the
// dependencies from the `required` property that are hard to resolve in Soong.
m.katiSymlinks = append(m.katiSymlinks, katiInstall{
absFrom: absPath,
to: fullInstallPath,
})
} else {
m.Build(pctx, BuildParams{
Rule: Symlink,
Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
Output: fullInstallPath,
Default: !m.Config().KatiEnabled(),
Args: map[string]string{
"fromPath": absPath,
},
})
}
m.installFiles = append(m.installFiles, fullInstallPath)
}