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 |
| 42 | |
| 43 | aconfigDeclarationNames []string |
| 44 | intermediateCacheOutputPaths android.Paths |
| 45 | javaSrcjars android.Paths |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 46 | modeInfos map[string]android.ModeInfo |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | type AconfigDeclarationsGroupProperties struct { |
| 50 | |
| 51 | // Name of the aconfig_declarations_group modules |
| 52 | Aconfig_declarations_groups []string |
| 53 | |
| 54 | // Name of the java_aconfig_library modules |
| 55 | Java_aconfig_libraries []string |
| 56 | |
| 57 | // Name of the cc_aconfig_library modules |
| 58 | Cc_aconfig_libraries []string |
| 59 | |
| 60 | // Name of the rust_aconfig_library modules |
| 61 | Rust_aconfig_libraries []string |
| 62 | } |
| 63 | |
| 64 | func AconfigDeclarationsGroupFactory() android.Module { |
| 65 | module := &AconfigDeclarationsGroup{} |
| 66 | module.AddProperties(&module.properties) |
| 67 | android.InitAndroidModule(module) |
| 68 | android.InitDefaultableModule(module) |
| 69 | return module |
| 70 | } |
| 71 | |
| 72 | func (adg *AconfigDeclarationsGroup) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 73 | ctx.AddDependency(ctx.Module(), aconfigDeclarationsGroupTag, adg.properties.Aconfig_declarations_groups...) |
| 74 | ctx.AddDependency(ctx.Module(), javaAconfigLibraryTag, adg.properties.Java_aconfig_libraries...) |
| 75 | ctx.AddDependency(ctx.Module(), ccAconfigLibraryTag, adg.properties.Cc_aconfig_libraries...) |
| 76 | ctx.AddDependency(ctx.Module(), rustAconfigLibraryTag, adg.properties.Rust_aconfig_libraries...) |
| 77 | } |
| 78 | |
| 79 | func (adg *AconfigDeclarationsGroup) VisitDeps(ctx android.ModuleContext) { |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 80 | adg.modeInfos = make(map[string]android.ModeInfo) |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 81 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 82 | tag := ctx.OtherModuleDependencyTag(dep) |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 83 | if provider, ok := android.OtherModuleProvider(ctx, dep, android.CodegenInfoProvider); ok { |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 84 | |
| 85 | // aconfig declaration names and cache files are collected for all aconfig library dependencies |
| 86 | adg.aconfigDeclarationNames = append(adg.aconfigDeclarationNames, provider.AconfigDeclarations...) |
| 87 | adg.intermediateCacheOutputPaths = append(adg.intermediateCacheOutputPaths, provider.IntermediateCacheOutputPaths...) |
| 88 | |
| 89 | switch tag { |
| 90 | case aconfigDeclarationsGroupTag: |
| 91 | // Will retrieve outputs from another language codegen modules when support is added |
| 92 | adg.javaSrcjars = append(adg.javaSrcjars, provider.Srcjars...) |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 93 | maps.Copy(adg.modeInfos, provider.ModeInfos) |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 94 | case javaAconfigLibraryTag: |
| 95 | adg.javaSrcjars = append(adg.javaSrcjars, provider.Srcjars...) |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 96 | maps.Copy(adg.modeInfos, provider.ModeInfos) |
| 97 | case ccAconfigLibraryTag: |
| 98 | maps.Copy(adg.modeInfos, provider.ModeInfos) |
| 99 | case rustAconfigLibraryTag: |
| 100 | maps.Copy(adg.modeInfos, provider.ModeInfos) |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | }) |
| 104 | } |
| 105 | |
| 106 | func (adg *AconfigDeclarationsGroup) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 107 | adg.VisitDeps(ctx) |
| 108 | adg.aconfigDeclarationNames = android.FirstUniqueStrings(adg.aconfigDeclarationNames) |
| 109 | adg.intermediateCacheOutputPaths = android.FirstUniquePaths(adg.intermediateCacheOutputPaths) |
| 110 | |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 111 | android.SetProvider(ctx, android.CodegenInfoProvider, android.CodegenInfo{ |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 112 | AconfigDeclarations: adg.aconfigDeclarationNames, |
| 113 | IntermediateCacheOutputPaths: adg.intermediateCacheOutputPaths, |
| 114 | Srcjars: adg.javaSrcjars, |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 115 | ModeInfos: adg.modeInfos, |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 116 | }) |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 117 | |
mrziwang | 937f35f | 2024-06-11 14:01:41 -0700 | [diff] [blame] | 118 | ctx.SetOutputFiles(adg.intermediateCacheOutputPaths, "") |
| 119 | ctx.SetOutputFiles(adg.javaSrcjars, ".srcjars") |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | func (adg *AconfigDeclarationsGroup) Srcjars() android.Paths { |
| 123 | return adg.javaSrcjars |
| 124 | } |
| 125 | |
| 126 | func (adg *AconfigDeclarationsGroup) AconfigDeclarations() []string { |
| 127 | return adg.aconfigDeclarationNames |
| 128 | } |