summaryrefslogtreecommitdiff
path: root/android/makevars.go
diff options
context:
space:
mode:
Diffstat (limited to 'android/makevars.go')
-rw-r--r--android/makevars.go124
1 files changed, 111 insertions, 13 deletions
diff --git a/android/makevars.go b/android/makevars.go
index aba4ccec3..ff7c8e4a7 100644
--- a/android/makevars.go
+++ b/android/makevars.go
@@ -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,29 @@ 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)
+
+ // DistForGoal creates a rule to copy one or more Paths to the artifacts
+ // directory on the build server when the specified goal is built.
+ DistForGoal(goal string, paths ...Path)
+
+ // DistForGoalWithFilename creates a rule to copy a Path to the artifacts
+ // directory on the build server with the given filename when the specified
+ // goal is built.
+ DistForGoalWithFilename(goal string, path Path, filename string)
+
+ // DistForGoals creates a rule to copy one or more Paths to the artifacts
+ // directory on the build server when any of the specified goals are built.
+ DistForGoals(goals []string, paths ...Path)
+
+ // DistForGoalsWithFilename creates a rule to copy a Path to the artifacts
+ // directory on the build server with the given filename when any of the
+ // specified goals are built.
+ DistForGoalsWithFilename(goals []string, path Path, filename string)
}
var _ PathContext = MakeVarsContext(nil)
@@ -130,9 +152,11 @@ var makeVarsProviders []makeVarsProvider
type makeVarsContext struct {
SingletonContext
- config Config
- pctx PackageContext
- vars []makeVarsVariable
+ config Config
+ pctx PackageContext
+ vars []makeVarsVariable
+ phonies []phony
+ dists []dist
}
var _ MakeVarsContext = &makeVarsContext{}
@@ -144,6 +168,16 @@ type makeVarsVariable struct {
strict bool
}
+type phony struct {
+ name string
+ deps []string
+}
+
+type dist struct {
+ goals []string
+ paths []string
+}
+
func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
if !ctx.Config().EmbeddedInMake() {
return
@@ -152,11 +186,16 @@ 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 vars []makeVarsVariable
+ var dists []dist
+ var phonies []phony
for _, provider := range makeVarsProviders {
mctx := &makeVarsContext{
SingletonContext: ctx,
@@ -166,6 +205,8 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
provider.call(mctx)
vars = append(vars, mctx.vars...)
+ phonies = append(phonies, mctx.phonies...)
+ dists = append(dists, mctx.dists...)
}
if ctx.Failed() {
@@ -174,17 +215,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 := pathtools.WriteFileIfChanged(outFile, outBytes, 0666); err != nil {
+ ctx.Errorf(err.Error())
}
- if err := ioutil.WriteFile(absolutePath(outFile), outBytes, 0666); err != nil {
+ lateOutBytes := s.writeLate(phonies, dists)
+
+ if err := pathtools.WriteFileIfChanged(lateOutFile, lateOutBytes, 0666); err != nil {
ctx.Errorf(err.Error())
}
+
}
func (s *makeVarsSingleton) writeVars(vars []makeVarsVariable) []byte {
@@ -263,6 +303,33 @@ my_check_failed :=
fmt.Fprintln(buf, "\nsoong-compare-var :=")
+ fmt.Fprintln(buf)
+
+ return buf.Bytes()
+}
+
+func (s *makeVarsSingleton) writeLate(phonies []phony, dists []dist) []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 "))
+ }
+
+ fmt.Fprintln(buf)
+
+ for _, dist := range dists {
+ fmt.Fprintf(buf, "$(call dist-for-goals,%s,%s)\n",
+ strings.Join(dist.goals, " "), strings.Join(dist.paths, " "))
+ }
+
return buf.Bytes()
}
@@ -299,6 +366,17 @@ 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) addDist(goals []string, paths []string) {
+ c.dists = append(c.dists, dist{
+ goals: goals,
+ paths: paths,
+ })
+}
+
func (c *makeVarsContext) Strict(name, ninjaStr string) {
c.addVariable(name, ninjaStr, true, false)
}
@@ -318,3 +396,23 @@ 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())
+}
+
+func (c *makeVarsContext) DistForGoal(goal string, paths ...Path) {
+ c.DistForGoals([]string{goal}, paths...)
+}
+
+func (c *makeVarsContext) DistForGoalWithFilename(goal string, path Path, filename string) {
+ c.DistForGoalsWithFilename([]string{goal}, path, filename)
+}
+
+func (c *makeVarsContext) DistForGoals(goals []string, paths ...Path) {
+ c.addDist(goals, Paths(paths).Strings())
+}
+
+func (c *makeVarsContext) DistForGoalsWithFilename(goals []string, path Path, filename string) {
+ c.addDist(goals, []string{path.String() + ":" + filename})
+}