Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package multitree |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 19 | "github.com/google/blueprint" |
| 20 | ) |
| 21 | |
| 22 | var ( |
| 23 | pctx = android.NewPackageContext("android/soong/multitree") |
| 24 | ) |
| 25 | |
| 26 | func init() { |
| 27 | RegisterApiSurfaceBuildComponents(android.InitRegistrationContext) |
| 28 | } |
| 29 | |
| 30 | var PrepareForTestWithApiSurface = android.FixtureRegisterWithContext(RegisterApiSurfaceBuildComponents) |
| 31 | |
| 32 | func RegisterApiSurfaceBuildComponents(ctx android.RegistrationContext) { |
| 33 | ctx.RegisterModuleType("api_surface", ApiSurfaceFactory) |
| 34 | } |
| 35 | |
| 36 | type ApiSurface struct { |
| 37 | android.ModuleBase |
| 38 | ExportableModuleBase |
| 39 | properties apiSurfaceProperties |
| 40 | |
Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 41 | taggedOutputs map[string]android.Paths |
| 42 | } |
| 43 | |
| 44 | type apiSurfaceProperties struct { |
| 45 | Contributions []string |
| 46 | } |
| 47 | |
| 48 | func ApiSurfaceFactory() android.Module { |
| 49 | module := &ApiSurface{} |
| 50 | module.AddProperties(&module.properties) |
| 51 | android.InitAndroidModule(module) |
| 52 | InitExportableModule(module) |
| 53 | return module |
| 54 | } |
| 55 | |
| 56 | func (surface *ApiSurface) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 57 | if surface.properties.Contributions != nil { |
| 58 | ctx.AddVariationDependencies(nil, nil, surface.properties.Contributions...) |
| 59 | } |
| 60 | |
| 61 | } |
| 62 | func (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 Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 86 | surface.taggedOutputs = contributionFiles |
Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 87 | |
mrziwang | e7ec89e | 2024-06-13 12:05:18 -0700 | [diff] [blame] | 88 | ctx.SetOutputFiles(allOutputs, "") |
Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | func (surface *ApiSurface) TaggedOutputs() map[string]android.Paths { |
| 92 | return surface.taggedOutputs |
| 93 | } |
| 94 | |
| 95 | func (surface *ApiSurface) Exportable() bool { |
| 96 | return true |
| 97 | } |
| 98 | |
Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 99 | var _ Exportable = (*ApiSurface)(nil) |
| 100 | |
| 101 | type 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 | } |