diff options
Diffstat (limited to 'android/singleton.go')
-rw-r--r-- | android/singleton.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/android/singleton.go b/android/singleton.go index 0754b0ccb..df2204591 100644 --- a/android/singleton.go +++ b/android/singleton.go @@ -15,6 +15,9 @@ package android import ( + "slices" + "sync" + "github.com/google/blueprint" ) @@ -97,6 +100,24 @@ type SingletonContext interface { // HasMutatorFinished returns true if the given mutator has finished running. // It will panic if given an invalid mutator name. HasMutatorFinished(mutatorName string) bool + + // 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. + 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) } type singletonAdaptor struct { @@ -118,6 +139,13 @@ func (s *singletonAdaptor) GenerateBuildActions(ctx blueprint.SingletonContext) s.buildParams = sctx.buildParams s.ruleParams = sctx.ruleParams + + if len(sctx.dists) > 0 { + dists := getSingletonDists(sctx.Config()) + dists.lock.Lock() + defer dists.lock.Unlock() + dists.dists = append(dists.dists, sctx.dists...) + } } func (s *singletonAdaptor) BuildParamsForTests() []BuildParams { @@ -128,6 +156,19 @@ func (s *singletonAdaptor) RuleParamsForTests() map[blueprint.Rule]blueprint.Rul return s.ruleParams } +var singletonDistsKey = NewOnceKey("singletonDistsKey") + +type singletonDistsAndLock struct { + dists []dist + lock sync.Mutex +} + +func getSingletonDists(config Config) *singletonDistsAndLock { + return config.Once(singletonDistsKey, func() interface{} { + return &singletonDistsAndLock{} + }).(*singletonDistsAndLock) +} + type Singleton interface { GenerateBuildActions(SingletonContext) } @@ -137,6 +178,7 @@ type singletonContextAdaptor struct { buildParams []BuildParams ruleParams map[blueprint.Rule]blueprint.RuleParams + dists []dist } func (s *singletonContextAdaptor) blueprintSingletonContext() blueprint.SingletonContext { @@ -315,3 +357,31 @@ func (s *singletonContextAdaptor) OtherModulePropertyErrorf(module Module, prope func (s *singletonContextAdaptor) HasMutatorFinished(mutatorName string) bool { return s.blueprintSingletonContext().HasMutatorFinished(mutatorName) } +func (s *singletonContextAdaptor) DistForGoal(goal string, paths ...Path) { + s.DistForGoals([]string{goal}, paths...) +} + +func (s *singletonContextAdaptor) DistForGoalWithFilename(goal string, path Path, filename string) { + s.DistForGoalsWithFilename([]string{goal}, path, filename) +} + +func (s *singletonContextAdaptor) DistForGoals(goals []string, paths ...Path) { + var copies distCopies + for _, path := range paths { + copies = append(copies, distCopy{ + from: path, + dest: path.Base(), + }) + } + s.dists = append(s.dists, dist{ + goals: slices.Clone(goals), + paths: copies, + }) +} + +func (s *singletonContextAdaptor) DistForGoalsWithFilename(goals []string, path Path, filename string) { + s.dists = append(s.dists, dist{ + goals: slices.Clone(goals), + paths: distCopies{{from: path, dest: filename}}, + }) +} |