Define Soong phony rules in Make
To support dist-for-goals in Soong, we need to define all phony rules in Make so that dist-for-goals can insert additional dependencies on them. Collect all the phony rules in phonySingleton and write them out as Make rules when Soong is embedded in Make, or as blueprint.Phony rules when Soong is run standalone. Test: m checkbuild Change-Id: I68201eff30744b0f487fc4f11f033767b53a627d
This commit is contained in:
@@ -17,12 +17,11 @@ package android
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/pathtools"
|
||||
"github.com/google/blueprint/proptools"
|
||||
)
|
||||
|
||||
@@ -84,6 +83,11 @@ type MakeVarsContext interface {
|
||||
// builder whenever a file matching the pattern as added or removed, without rerunning if a
|
||||
// file that does not match the pattern is added to a searched directory.
|
||||
GlobWithDeps(pattern string, excludes []string) ([]string, error)
|
||||
|
||||
// Phony creates a phony rule in Make, which will allow additional DistForGoal
|
||||
// dependencies to be added to it. Phony can be called on the same name multiple
|
||||
// times to add additional dependencies.
|
||||
Phony(names string, deps ...Path)
|
||||
}
|
||||
|
||||
var _ PathContext = MakeVarsContext(nil)
|
||||
@@ -130,9 +134,10 @@ var makeVarsProviders []makeVarsProvider
|
||||
|
||||
type makeVarsContext struct {
|
||||
SingletonContext
|
||||
config Config
|
||||
pctx PackageContext
|
||||
vars []makeVarsVariable
|
||||
config Config
|
||||
pctx PackageContext
|
||||
vars []makeVarsVariable
|
||||
phonies []phony
|
||||
}
|
||||
|
||||
var _ MakeVarsContext = &makeVarsContext{}
|
||||
@@ -144,6 +149,11 @@ type makeVarsVariable struct {
|
||||
strict bool
|
||||
}
|
||||
|
||||
type phony struct {
|
||||
name string
|
||||
deps []string
|
||||
}
|
||||
|
||||
func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
if !ctx.Config().EmbeddedInMake() {
|
||||
return
|
||||
@@ -152,11 +162,15 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
outFile := absolutePath(PathForOutput(ctx,
|
||||
"make_vars"+proptools.String(ctx.Config().productVariables.Make_suffix)+".mk").String())
|
||||
|
||||
lateOutFile := absolutePath(PathForOutput(ctx,
|
||||
"late"+proptools.String(ctx.Config().productVariables.Make_suffix)+".mk").String())
|
||||
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
vars := []makeVarsVariable{}
|
||||
var phonies []phony
|
||||
for _, provider := range makeVarsProviders {
|
||||
mctx := &makeVarsContext{
|
||||
SingletonContext: ctx,
|
||||
@@ -166,6 +180,7 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
provider.call(mctx)
|
||||
|
||||
vars = append(vars, mctx.vars...)
|
||||
phonies = append(phonies, mctx.phonies...)
|
||||
}
|
||||
|
||||
if ctx.Failed() {
|
||||
@@ -174,17 +189,16 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
|
||||
outBytes := s.writeVars(vars)
|
||||
|
||||
if _, err := os.Stat(absolutePath(outFile)); err == nil {
|
||||
if data, err := ioutil.ReadFile(absolutePath(outFile)); err == nil {
|
||||
if bytes.Equal(data, outBytes) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(absolutePath(outFile), outBytes, 0666); err != nil {
|
||||
if err := pathtools.WriteFileIfChanged(outFile, outBytes, 0666); err != nil {
|
||||
ctx.Errorf(err.Error())
|
||||
}
|
||||
|
||||
lateOutBytes := s.writeLate(phonies)
|
||||
|
||||
if err := pathtools.WriteFileIfChanged(lateOutFile, lateOutBytes, 0666); err != nil {
|
||||
ctx.Errorf(err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *makeVarsSingleton) writeVars(vars []makeVarsVariable) []byte {
|
||||
@@ -263,6 +277,26 @@ my_check_failed :=
|
||||
|
||||
fmt.Fprintln(buf, "\nsoong-compare-var :=")
|
||||
|
||||
fmt.Fprintln(buf)
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func (s *makeVarsSingleton) writeLate(phonies []phony) []byte {
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
fmt.Fprint(buf, `# Autogenerated file
|
||||
|
||||
# Values written by Soong read after parsing all Android.mk files.
|
||||
|
||||
|
||||
`)
|
||||
|
||||
for _, phony := range phonies {
|
||||
fmt.Fprintf(buf, ".PHONY: %s\n", phony.name)
|
||||
fmt.Fprintf(buf, "%s: %s\n", phony.name, strings.Join(phony.deps, "\\\n "))
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
@@ -299,6 +333,10 @@ func (c *makeVarsContext) addVariable(name, ninjaStr string, strict, sort bool)
|
||||
c.addVariableRaw(name, value, strict, sort)
|
||||
}
|
||||
|
||||
func (c *makeVarsContext) addPhony(name string, deps []string) {
|
||||
c.phonies = append(c.phonies, phony{name, deps})
|
||||
}
|
||||
|
||||
func (c *makeVarsContext) Strict(name, ninjaStr string) {
|
||||
c.addVariable(name, ninjaStr, true, false)
|
||||
}
|
||||
@@ -318,3 +356,7 @@ func (c *makeVarsContext) CheckSorted(name, ninjaStr string) {
|
||||
func (c *makeVarsContext) CheckRaw(name, value string) {
|
||||
c.addVariableRaw(name, value, false, false)
|
||||
}
|
||||
|
||||
func (c *makeVarsContext) Phony(name string, deps ...Path) {
|
||||
c.addPhony(name, Paths(deps).Strings())
|
||||
}
|
||||
|
Reference in New Issue
Block a user