diff --git a/android/makevars.go b/android/makevars.go index 0acd0f665..ff7c8e4a7 100644 --- a/android/makevars.go +++ b/android/makevars.go @@ -88,6 +88,24 @@ type MakeVarsContext interface { // 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) @@ -138,6 +156,7 @@ type makeVarsContext struct { pctx PackageContext vars []makeVarsVariable phonies []phony + dists []dist } var _ MakeVarsContext = &makeVarsContext{} @@ -154,6 +173,11 @@ type phony struct { deps []string } +type dist struct { + goals []string + paths []string +} + func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) { if !ctx.Config().EmbeddedInMake() { return @@ -169,7 +193,8 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) { return } - vars := []makeVarsVariable{} + var vars []makeVarsVariable + var dists []dist var phonies []phony for _, provider := range makeVarsProviders { mctx := &makeVarsContext{ @@ -181,6 +206,7 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) { vars = append(vars, mctx.vars...) phonies = append(phonies, mctx.phonies...) + dists = append(dists, mctx.dists...) } if ctx.Failed() { @@ -193,7 +219,7 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) { ctx.Errorf(err.Error()) } - lateOutBytes := s.writeLate(phonies) + lateOutBytes := s.writeLate(phonies, dists) if err := pathtools.WriteFileIfChanged(lateOutFile, lateOutBytes, 0666); err != nil { ctx.Errorf(err.Error()) @@ -282,7 +308,7 @@ my_check_failed := return buf.Bytes() } -func (s *makeVarsSingleton) writeLate(phonies []phony) []byte { +func (s *makeVarsSingleton) writeLate(phonies []phony, dists []dist) []byte { buf := &bytes.Buffer{} fmt.Fprint(buf, `# Autogenerated file @@ -297,6 +323,13 @@ func (s *makeVarsSingleton) writeLate(phonies []phony) []byte { 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() } @@ -337,6 +370,13 @@ 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) } @@ -360,3 +400,19 @@ func (c *makeVarsContext) CheckRaw(name, value string) { 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}) +}