Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 1 | // Copyright 2024 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 codegen |
| 16 | |
| 17 | import ( |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 18 | "maps" |
| 19 | |
| 20 | "android/soong/android" |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 21 | |
| 22 | "github.com/google/blueprint" |
| 23 | ) |
| 24 | |
| 25 | type dependencyTag struct { |
| 26 | blueprint.BaseDependencyTag |
| 27 | name string |
| 28 | } |
| 29 | |
| 30 | var ( |
| 31 | aconfigDeclarationsGroupTag = dependencyTag{name: "aconfigDeclarationsGroup"} |
| 32 | javaAconfigLibraryTag = dependencyTag{name: "javaAconfigLibrary"} |
| 33 | ccAconfigLibraryTag = dependencyTag{name: "ccAconfigLibrary"} |
| 34 | rustAconfigLibraryTag = dependencyTag{name: "rustAconfigLibrary"} |
| 35 | ) |
| 36 | |
| 37 | type AconfigDeclarationsGroup struct { |
| 38 | android.ModuleBase |
| 39 | android.DefaultableModuleBase |
| 40 | |
| 41 | properties AconfigDeclarationsGroupProperties |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | type AconfigDeclarationsGroupProperties struct { |
| 45 | |
| 46 | // Name of the aconfig_declarations_group modules |
| 47 | Aconfig_declarations_groups []string |
| 48 | |
| 49 | // Name of the java_aconfig_library modules |
| 50 | Java_aconfig_libraries []string |
| 51 | |
| 52 | // Name of the cc_aconfig_library modules |
| 53 | Cc_aconfig_libraries []string |
| 54 | |
| 55 | // Name of the rust_aconfig_library modules |
| 56 | Rust_aconfig_libraries []string |
| 57 | } |
| 58 | |
| 59 | func AconfigDeclarationsGroupFactory() android.Module { |
| 60 | module := &AconfigDeclarationsGroup{} |
| 61 | module.AddProperties(&module.properties) |
| 62 | android.InitAndroidModule(module) |
| 63 | android.InitDefaultableModule(module) |
| 64 | return module |
| 65 | } |
| 66 | |
| 67 | func (adg *AconfigDeclarationsGroup) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 68 | ctx.AddDependency(ctx.Module(), aconfigDeclarationsGroupTag, adg.properties.Aconfig_declarations_groups...) |
| 69 | ctx.AddDependency(ctx.Module(), javaAconfigLibraryTag, adg.properties.Java_aconfig_libraries...) |
| 70 | ctx.AddDependency(ctx.Module(), ccAconfigLibraryTag, adg.properties.Cc_aconfig_libraries...) |
| 71 | ctx.AddDependency(ctx.Module(), rustAconfigLibraryTag, adg.properties.Rust_aconfig_libraries...) |
| 72 | } |
| 73 | |
Cole Faust | 779d41c | 2024-06-14 11:14:33 -0700 | [diff] [blame] | 74 | func (adg *AconfigDeclarationsGroup) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 75 | modeInfos := make(map[string]android.ModeInfo) |
| 76 | var aconfigDeclarationNames []string |
| 77 | var intermediateCacheOutputPaths android.Paths |
| 78 | var javaSrcjars android.Paths |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 79 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 80 | tag := ctx.OtherModuleDependencyTag(dep) |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 81 | if provider, ok := android.OtherModuleProvider(ctx, dep, android.CodegenInfoProvider); ok { |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 82 | |
| 83 | // aconfig declaration names and cache files are collected for all aconfig library dependencies |
Cole Faust | 779d41c | 2024-06-14 11:14:33 -0700 | [diff] [blame] | 84 | aconfigDeclarationNames = append(aconfigDeclarationNames, provider.AconfigDeclarations...) |
| 85 | intermediateCacheOutputPaths = append(intermediateCacheOutputPaths, provider.IntermediateCacheOutputPaths...) |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 86 | |
| 87 | switch tag { |
| 88 | case aconfigDeclarationsGroupTag: |
| 89 | // Will retrieve outputs from another language codegen modules when support is added |
Cole Faust | 779d41c | 2024-06-14 11:14:33 -0700 | [diff] [blame] | 90 | javaSrcjars = append(javaSrcjars, provider.Srcjars...) |
| 91 | maps.Copy(modeInfos, provider.ModeInfos) |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 92 | case javaAconfigLibraryTag: |
Cole Faust | 779d41c | 2024-06-14 11:14:33 -0700 | [diff] [blame] | 93 | javaSrcjars = append(javaSrcjars, provider.Srcjars...) |
| 94 | maps.Copy(modeInfos, provider.ModeInfos) |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 95 | case ccAconfigLibraryTag: |
Cole Faust | 779d41c | 2024-06-14 11:14:33 -0700 | [diff] [blame] | 96 | maps.Copy(modeInfos, provider.ModeInfos) |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 97 | case rustAconfigLibraryTag: |
Cole Faust | 779d41c | 2024-06-14 11:14:33 -0700 | [diff] [blame] | 98 | maps.Copy(modeInfos, provider.ModeInfos) |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | }) |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 102 | |
Cole Faust | 779d41c | 2024-06-14 11:14:33 -0700 | [diff] [blame] | 103 | aconfigDeclarationNames = android.FirstUniqueStrings(aconfigDeclarationNames) |
| 104 | intermediateCacheOutputPaths = android.FirstUniquePaths(intermediateCacheOutputPaths) |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 105 | |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 106 | android.SetProvider(ctx, android.CodegenInfoProvider, android.CodegenInfo{ |
Cole Faust | 779d41c | 2024-06-14 11:14:33 -0700 | [diff] [blame] | 107 | AconfigDeclarations: aconfigDeclarationNames, |
| 108 | IntermediateCacheOutputPaths: intermediateCacheOutputPaths, |
| 109 | Srcjars: javaSrcjars, |
| 110 | ModeInfos: modeInfos, |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 111 | }) |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 112 | |
Cole Faust | 779d41c | 2024-06-14 11:14:33 -0700 | [diff] [blame] | 113 | ctx.SetOutputFiles(intermediateCacheOutputPaths, "") |
| 114 | ctx.SetOutputFiles(javaSrcjars, ".srcjars") |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 115 | } |