blob: 0f605d84ad685fa284c594673e23a37ae2be8400 [file] [log] [blame]
Inseob Kim5eb7ee92022-04-27 10:30:34 +09001// Copyright 2021 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package multitree
16
17import (
18 "android/soong/android"
Inseob Kim5eb7ee92022-04-27 10:30:34 +090019 "github.com/google/blueprint"
20)
21
22var (
23 pctx = android.NewPackageContext("android/soong/multitree")
24)
25
26func init() {
27 RegisterApiSurfaceBuildComponents(android.InitRegistrationContext)
28}
29
30var PrepareForTestWithApiSurface = android.FixtureRegisterWithContext(RegisterApiSurfaceBuildComponents)
31
32func RegisterApiSurfaceBuildComponents(ctx android.RegistrationContext) {
33 ctx.RegisterModuleType("api_surface", ApiSurfaceFactory)
34}
35
36type ApiSurface struct {
37 android.ModuleBase
38 ExportableModuleBase
39 properties apiSurfaceProperties
40
Inseob Kim5eb7ee92022-04-27 10:30:34 +090041 taggedOutputs map[string]android.Paths
42}
43
44type apiSurfaceProperties struct {
45 Contributions []string
46}
47
48func ApiSurfaceFactory() android.Module {
49 module := &ApiSurface{}
50 module.AddProperties(&module.properties)
51 android.InitAndroidModule(module)
52 InitExportableModule(module)
53 return module
54}
55
56func (surface *ApiSurface) DepsMutator(ctx android.BottomUpMutatorContext) {
57 if surface.properties.Contributions != nil {
58 ctx.AddVariationDependencies(nil, nil, surface.properties.Contributions...)
59 }
60
61}
62func (surface *ApiSurface) GenerateAndroidBuildActions(ctx android.ModuleContext) {
63 contributionFiles := make(map[string]android.Paths)
64 var allOutputs android.Paths
65 ctx.WalkDeps(func(child, parent android.Module) bool {
66 if contribution, ok := child.(ApiContribution); ok {
67 copied := contribution.CopyFilesWithTag(ctx)
68 for tag, files := range copied {
69 contributionFiles[child.Name()+"#"+tag] = files
70 }
71 for _, paths := range copied {
72 allOutputs = append(allOutputs, paths...)
73 }
74 return false // no transitive dependencies
75 }
76 return false
77 })
78
79 // phony target
80 ctx.Build(pctx, android.BuildParams{
81 Rule: blueprint.Phony,
82 Output: android.PathForPhony(ctx, ctx.ModuleName()),
83 Inputs: allOutputs,
84 })
85
Inseob Kim5eb7ee92022-04-27 10:30:34 +090086 surface.taggedOutputs = contributionFiles
Inseob Kim5eb7ee92022-04-27 10:30:34 +090087
mrziwange7ec89e2024-06-13 12:05:18 -070088 ctx.SetOutputFiles(allOutputs, "")
Inseob Kim5eb7ee92022-04-27 10:30:34 +090089}
90
91func (surface *ApiSurface) TaggedOutputs() map[string]android.Paths {
92 return surface.taggedOutputs
93}
94
95func (surface *ApiSurface) Exportable() bool {
96 return true
97}
98
Inseob Kim5eb7ee92022-04-27 10:30:34 +090099var _ Exportable = (*ApiSurface)(nil)
100
101type ApiContribution interface {
102 // copy files necessaryt to construct an API surface
103 // For C, it will be map.txt and .h files
104 // For Java, it will be api.txt
105 CopyFilesWithTag(ctx android.ModuleContext) map[string]android.Paths // output paths
106
107 // Generate Android.bp in out/ to use the exported .txt files
108 // GenerateBuildFiles(ctx ModuleContext) Paths //output paths
109}