blob: 13daf470b810e815ac1ccffb3251209a625935ee [file] [log] [blame]
Jihoon Kang2a43e562024-02-12 19:05:12 +00001// 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
15package codegen
16
17import (
Yu Liu67a28422024-03-05 00:36:31 +000018 "maps"
19
20 "android/soong/android"
Jihoon Kang2a43e562024-02-12 19:05:12 +000021
22 "github.com/google/blueprint"
23)
24
25type dependencyTag struct {
26 blueprint.BaseDependencyTag
27 name string
28}
29
30var (
31 aconfigDeclarationsGroupTag = dependencyTag{name: "aconfigDeclarationsGroup"}
32 javaAconfigLibraryTag = dependencyTag{name: "javaAconfigLibrary"}
33 ccAconfigLibraryTag = dependencyTag{name: "ccAconfigLibrary"}
34 rustAconfigLibraryTag = dependencyTag{name: "rustAconfigLibrary"}
35)
36
37type AconfigDeclarationsGroup struct {
38 android.ModuleBase
39 android.DefaultableModuleBase
40
41 properties AconfigDeclarationsGroupProperties
Jihoon Kang2a43e562024-02-12 19:05:12 +000042}
43
44type 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
59func AconfigDeclarationsGroupFactory() android.Module {
60 module := &AconfigDeclarationsGroup{}
61 module.AddProperties(&module.properties)
62 android.InitAndroidModule(module)
63 android.InitDefaultableModule(module)
64 return module
65}
66
67func (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 Faust779d41c2024-06-14 11:14:33 -070074func (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 Kang2a43e562024-02-12 19:05:12 +000079 ctx.VisitDirectDeps(func(dep android.Module) {
80 tag := ctx.OtherModuleDependencyTag(dep)
Yu Liu67a28422024-03-05 00:36:31 +000081 if provider, ok := android.OtherModuleProvider(ctx, dep, android.CodegenInfoProvider); ok {
Jihoon Kang2a43e562024-02-12 19:05:12 +000082
83 // aconfig declaration names and cache files are collected for all aconfig library dependencies
Cole Faust779d41c2024-06-14 11:14:33 -070084 aconfigDeclarationNames = append(aconfigDeclarationNames, provider.AconfigDeclarations...)
85 intermediateCacheOutputPaths = append(intermediateCacheOutputPaths, provider.IntermediateCacheOutputPaths...)
Jihoon Kang2a43e562024-02-12 19:05:12 +000086
87 switch tag {
88 case aconfigDeclarationsGroupTag:
89 // Will retrieve outputs from another language codegen modules when support is added
Cole Faust779d41c2024-06-14 11:14:33 -070090 javaSrcjars = append(javaSrcjars, provider.Srcjars...)
91 maps.Copy(modeInfos, provider.ModeInfos)
Jihoon Kang2a43e562024-02-12 19:05:12 +000092 case javaAconfigLibraryTag:
Cole Faust779d41c2024-06-14 11:14:33 -070093 javaSrcjars = append(javaSrcjars, provider.Srcjars...)
94 maps.Copy(modeInfos, provider.ModeInfos)
Yu Liu67a28422024-03-05 00:36:31 +000095 case ccAconfigLibraryTag:
Cole Faust779d41c2024-06-14 11:14:33 -070096 maps.Copy(modeInfos, provider.ModeInfos)
Yu Liu67a28422024-03-05 00:36:31 +000097 case rustAconfigLibraryTag:
Cole Faust779d41c2024-06-14 11:14:33 -070098 maps.Copy(modeInfos, provider.ModeInfos)
Jihoon Kang2a43e562024-02-12 19:05:12 +000099 }
100 }
101 })
Jihoon Kang2a43e562024-02-12 19:05:12 +0000102
Cole Faust779d41c2024-06-14 11:14:33 -0700103 aconfigDeclarationNames = android.FirstUniqueStrings(aconfigDeclarationNames)
104 intermediateCacheOutputPaths = android.FirstUniquePaths(intermediateCacheOutputPaths)
Jihoon Kang2a43e562024-02-12 19:05:12 +0000105
Yu Liu67a28422024-03-05 00:36:31 +0000106 android.SetProvider(ctx, android.CodegenInfoProvider, android.CodegenInfo{
Cole Faust779d41c2024-06-14 11:14:33 -0700107 AconfigDeclarations: aconfigDeclarationNames,
108 IntermediateCacheOutputPaths: intermediateCacheOutputPaths,
109 Srcjars: javaSrcjars,
110 ModeInfos: modeInfos,
Jihoon Kang2a43e562024-02-12 19:05:12 +0000111 })
Jihoon Kang2a43e562024-02-12 19:05:12 +0000112
Cole Faust779d41c2024-06-14 11:14:33 -0700113 ctx.SetOutputFiles(intermediateCacheOutputPaths, "")
114 ctx.SetOutputFiles(javaSrcjars, ".srcjars")
Jihoon Kang2a43e562024-02-12 19:05:12 +0000115}