Export Soong install rules to Make
Previously Soong's install rules have been disabled when embedded in Make (ctx.Config().KatiEnabled() == true). The primary blocker for moving installation into Soong has been the `required` proeprty, which is too vague to be easily handled in Soong. Keeping installation in Make has resulted in two host bin directories, the Make-owned directory (e.g. out/host/linux-x86/bin), and the Soong-owned directory (e.g. out/soong/host/linux-x86/bin). The lack of knowledge in Soong about the final, Make-owned installation location makes it hard to support NOTICE files entirely in Soong. This patch begins to solve this problem by supporting the creation of the installation rules into Soong, but rather than writing the rules to the ninja file it writes them to a Makefile and lets Kati convert them to ninja. This allows Kati to inject extra dependencies to handle the `required` property. Converting all modules to create their installation rules in Soong would be too complex, so only modules that return true from InstallBypassMake will use the Soong installation rules. This is currently only set for robolectric tests. Bug: 204136549 Test: m checkbuild Change-Id: I28af9fa7fadece8ea1f98f5efd140c823751cae7
This commit is contained in:
@@ -17,6 +17,8 @@ package android
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -222,6 +224,9 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
lateOutFile := absolutePath(PathForOutput(ctx,
|
||||
"late"+proptools.String(ctx.Config().productVariables.Make_suffix)+".mk").String())
|
||||
|
||||
installsFile := absolutePath(PathForOutput(ctx,
|
||||
"installs"+proptools.String(ctx.Config().productVariables.Make_suffix)+".mk").String())
|
||||
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
@@ -229,6 +234,8 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
var vars []makeVarsVariable
|
||||
var dists []dist
|
||||
var phonies []phony
|
||||
var katiInstalls []katiInstall
|
||||
var katiSymlinks []katiInstall
|
||||
|
||||
providers := append([]makeVarsProvider(nil), makeVarsInitProviders...)
|
||||
providers = append(providers, *ctx.Config().Get(singletonMakeVarsProvidersKey).(*[]makeVarsProvider)...)
|
||||
@@ -258,6 +265,11 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
phonies = append(phonies, mctx.phonies...)
|
||||
dists = append(dists, mctx.dists...)
|
||||
}
|
||||
|
||||
if m.ExportedToMake() {
|
||||
katiInstalls = append(katiInstalls, m.base().katiInstalls...)
|
||||
katiSymlinks = append(katiSymlinks, m.base().katiSymlinks...)
|
||||
}
|
||||
})
|
||||
|
||||
if ctx.Failed() {
|
||||
@@ -297,6 +309,10 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
ctx.Errorf(err.Error())
|
||||
}
|
||||
|
||||
installsBytes := s.writeInstalls(katiInstalls, katiSymlinks)
|
||||
if err := pathtools.WriteFileIfChanged(installsFile, installsBytes, 0666); err != nil {
|
||||
ctx.Errorf(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (s *makeVarsSingleton) writeVars(vars []makeVarsVariable) []byte {
|
||||
@@ -405,6 +421,84 @@ func (s *makeVarsSingleton) writeLate(phonies []phony, dists []dist) []byte {
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
// writeInstalls writes the list of install rules generated by Soong to a makefile. The rules
|
||||
// are exported to Make instead of written directly to the ninja file so that main.mk can add
|
||||
// the dependencies from the `required` property that are hard to resolve in Soong.
|
||||
func (s *makeVarsSingleton) writeInstalls(installs, symlinks []katiInstall) []byte {
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
fmt.Fprint(buf, `# Autogenerated file
|
||||
|
||||
# Values written by Soong to generate install rules that can be amended by Kati.
|
||||
|
||||
|
||||
`)
|
||||
|
||||
preserveSymlinksFlag := "-d"
|
||||
if runtime.GOOS == "darwin" {
|
||||
preserveSymlinksFlag = "-R"
|
||||
}
|
||||
|
||||
for _, install := range installs {
|
||||
// Write a rule for each install request in the form:
|
||||
// to: from [ deps ] [ | order only deps ]
|
||||
// cp -f -d $< $@ [ && chmod +x $@ ]
|
||||
fmt.Fprintf(buf, "%s: %s", install.to.String(), install.from.String())
|
||||
for _, dep := range install.implicitDeps {
|
||||
fmt.Fprintf(buf, " %s", dep.String())
|
||||
}
|
||||
if len(install.orderOnlyDeps) > 0 {
|
||||
fmt.Fprintf(buf, " |")
|
||||
}
|
||||
for _, dep := range install.orderOnlyDeps {
|
||||
fmt.Fprintf(buf, " %s", dep.String())
|
||||
}
|
||||
fmt.Fprintln(buf)
|
||||
|
||||
fmt.Fprintf(buf, "\trm -f $@ && cp -f %s $< $@", preserveSymlinksFlag)
|
||||
if install.executable {
|
||||
fmt.Fprintf(buf, " && chmod +x $@")
|
||||
}
|
||||
fmt.Fprintln(buf)
|
||||
fmt.Fprintln(buf)
|
||||
}
|
||||
|
||||
for _, symlink := range symlinks {
|
||||
fmt.Fprintf(buf, "%s:", symlink.to.String())
|
||||
for _, dep := range symlink.implicitDeps {
|
||||
fmt.Fprintf(buf, " %s", dep.String())
|
||||
}
|
||||
if symlink.from != nil || len(symlink.orderOnlyDeps) > 0 {
|
||||
fmt.Fprintf(buf, " |")
|
||||
}
|
||||
if symlink.from != nil {
|
||||
fmt.Fprintf(buf, " %s", symlink.from.String())
|
||||
}
|
||||
for _, dep := range symlink.orderOnlyDeps {
|
||||
fmt.Fprintf(buf, " %s", dep.String())
|
||||
}
|
||||
fmt.Fprintln(buf)
|
||||
|
||||
fromStr := ""
|
||||
if symlink.from != nil {
|
||||
rel, err := filepath.Rel(filepath.Dir(symlink.to.String()), symlink.from.String())
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to find relative path for symlink from %q to %q: %w",
|
||||
symlink.from.String(), symlink.to.String(), err))
|
||||
}
|
||||
fromStr = rel
|
||||
} else {
|
||||
fromStr = symlink.absFrom
|
||||
}
|
||||
|
||||
fmt.Fprintf(buf, "\trm -f $@ && ln -sfn %s $@", fromStr)
|
||||
fmt.Fprintln(buf)
|
||||
fmt.Fprintln(buf)
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func (c *makeVarsContext) DeviceConfig() DeviceConfig {
|
||||
return DeviceConfig{c.Config().deviceConfig}
|
||||
}
|
||||
|
Reference in New Issue
Block a user