blob: b15f16496067403f97af997f3d21825d366fa7cf [file] [log] [blame]
Colin Cross581c1892015-04-07 16:50:10 -07001// Copyright 2015 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 cc
16
Colin Cross581c1892015-04-07 16:50:10 -070017import (
Inseob Kim21f26902018-09-06 00:55:20 +090018 "path/filepath"
Dan Willemsen1945a4b2019-06-04 17:10:41 -070019 "strings"
Inseob Kim21f26902018-09-06 00:55:20 +090020
Vinh Tran367d89d2023-04-28 11:21:25 -040021 "android/soong/aidl_library"
Trevor Radcliffeef9c9002022-05-13 20:55:35 +000022 "android/soong/bazel"
Vinh Tran367d89d2023-04-28 11:21:25 -040023
Colin Cross581c1892015-04-07 16:50:10 -070024 "github.com/google/blueprint"
Colin Cross581c1892015-04-07 16:50:10 -070025
Colin Cross635c3b02016-05-18 15:37:25 -070026 "android/soong/android"
Colin Cross581c1892015-04-07 16:50:10 -070027)
28
29func init() {
David Sudd18efd2020-07-24 17:19:23 +000030 pctx.SourcePathVariable("lexCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/flex")
Dan Willemsen613564e2020-07-23 21:37:35 +000031 pctx.SourcePathVariable("m4Cmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/m4")
32
Dan Willemsene1240db2016-11-03 14:28:51 -070033 pctx.HostBinToolVariable("aidlCmd", "aidl-cpp")
Inseob Kim21f26902018-09-06 00:55:20 +090034 pctx.HostBinToolVariable("syspropCmd", "sysprop_cpp")
Colin Cross581c1892015-04-07 16:50:10 -070035}
36
37var (
David Sudd18efd2020-07-24 17:19:23 +000038 lex = pctx.AndroidStaticRule("lex",
39 blueprint.RuleParams{
Matthias Maennich22fd4d12020-07-15 10:58:56 +020040 Command: "M4=$m4Cmd $lexCmd $flags -o$out $in",
David Sudd18efd2020-07-24 17:19:23 +000041 CommandDeps: []string{"$lexCmd", "$m4Cmd"},
Matthias Maennich22fd4d12020-07-15 10:58:56 +020042 }, "flags")
David Sudd18efd2020-07-24 17:19:23 +000043
Inseob Kim21f26902018-09-06 00:55:20 +090044 sysprop = pctx.AndroidStaticRule("sysprop",
45 blueprint.RuleParams{
Inseob Kim5cefbd22019-06-08 20:36:59 +090046 Command: "$syspropCmd --header-dir=$headerOutDir --public-header-dir=$publicOutDir " +
Inseob Kimc0907f12019-02-08 21:00:45 +090047 "--source-dir=$srcOutDir --include-name=$includeName $in",
Inseob Kim21f26902018-09-06 00:55:20 +090048 CommandDeps: []string{"$syspropCmd"},
49 },
Inseob Kim5cefbd22019-06-08 20:36:59 +090050 "headerOutDir", "publicOutDir", "srcOutDir", "includeName")
Colin Cross581c1892015-04-07 16:50:10 -070051)
52
Dan Willemsen4e0aa232019-04-10 22:59:54 -070053type YaccProperties struct {
54 // list of module-specific flags that will be used for .y and .yy compiles
55 Flags []string
Colin Cross581c1892015-04-07 16:50:10 -070056
Dan Willemsen4e0aa232019-04-10 22:59:54 -070057 // whether the yacc files will produce a location.hh file
58 Gen_location_hh *bool
Colin Cross581c1892015-04-07 16:50:10 -070059
Dan Willemsen4e0aa232019-04-10 22:59:54 -070060 // whether the yacc files will product a position.hh file
61 Gen_position_hh *bool
62}
63
64func genYacc(ctx android.ModuleContext, rule *android.RuleBuilder, yaccFile android.Path,
David Sudd18efd2020-07-24 17:19:23 +000065 outFile android.ModuleGenPath, props *YaccProperties) (headerFiles android.Paths) {
Dan Willemsen4e0aa232019-04-10 22:59:54 -070066
67 outDir := android.PathForModuleGen(ctx, "yacc")
68 headerFile := android.GenPathWithExt(ctx, "yacc", yaccFile, "h")
69 ret := android.Paths{headerFile}
70
71 cmd := rule.Command()
72
73 // Fix up #line markers to not use the sbox temporary directory
Colin Crossf1a035e2020-11-16 17:32:30 -080074 // android.sboxPathForOutput(outDir, outDir) returns the sbox placeholder for the out
Colin Cross3d680512020-11-13 16:23:53 -080075 // directory itself, without any filename appended.
Colin Crossf1a035e2020-11-16 17:32:30 -080076 sboxOutDir := cmd.PathForOutput(outDir)
Colin Cross3d680512020-11-13 16:23:53 -080077 sedCmd := "sed -i.bak 's#" + sboxOutDir + "#" + outDir.String() + "#'"
Dan Willemsen4e0aa232019-04-10 22:59:54 -070078 rule.Command().Text(sedCmd).Input(outFile)
79 rule.Command().Text(sedCmd).Input(headerFile)
80
81 var flags []string
82 if props != nil {
83 flags = props.Flags
84
85 if Bool(props.Gen_location_hh) {
86 locationHeader := outFile.InSameDir(ctx, "location.hh")
87 ret = append(ret, locationHeader)
88 cmd.ImplicitOutput(locationHeader)
89 rule.Command().Text(sedCmd).Input(locationHeader)
90 }
91 if Bool(props.Gen_position_hh) {
92 positionHeader := outFile.InSameDir(ctx, "position.hh")
93 ret = append(ret, positionHeader)
94 cmd.ImplicitOutput(positionHeader)
95 rule.Command().Text(sedCmd).Input(positionHeader)
96 }
97 }
98
David Sudd18efd2020-07-24 17:19:23 +000099 cmd.Text("BISON_PKGDATADIR=prebuilts/build-tools/common/bison").
100 FlagWithInput("M4=", ctx.Config().PrebuiltBuildTool(ctx, "m4")).
101 PrebuiltBuildTool(ctx, "bison").
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700102 Flag("-d").
103 Flags(flags).
104 FlagWithOutput("--defines=", headerFile).
105 Flag("-o").Output(outFile).Input(yaccFile)
106
107 return ret
Colin Cross581c1892015-04-07 16:50:10 -0700108}
109
Vinh Tran09581952023-05-16 16:03:20 -0400110func genAidl(
111 ctx android.ModuleContext,
112 rule *android.RuleBuilder,
113 outDirBase string,
114 aidlFile android.Path,
115 aidlHdrs android.Paths,
116 aidlFlags string,
117) (cppFile android.OutputPath, headerFiles android.Paths) {
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700118 aidlPackage := strings.TrimSuffix(aidlFile.Rel(), aidlFile.Base())
119 baseName := strings.TrimSuffix(aidlFile.Base(), aidlFile.Ext())
Daniel Norman10b74352019-09-24 17:39:58 -0700120 shortName := baseName
121 // TODO(b/111362593): aidl_to_cpp_common.cpp uses heuristics to figure out if
122 // an interface name has a leading I. Those same heuristics have been
123 // moved here.
124 if len(baseName) >= 2 && baseName[0] == 'I' &&
125 strings.ToUpper(baseName)[1] == baseName[1] {
126 shortName = strings.TrimPrefix(baseName, "I")
127 }
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700128
Vinh Tran09581952023-05-16 16:03:20 -0400129 outDir := android.PathForModuleGen(ctx, outDirBase)
Jiyong Parkc7e592c2021-04-07 21:49:34 +0900130 cppFile = outDir.Join(ctx, aidlPackage, baseName+".cpp")
131 depFile := outDir.Join(ctx, aidlPackage, baseName+".cpp.d")
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700132 headerI := outDir.Join(ctx, aidlPackage, baseName+".h")
133 headerBn := outDir.Join(ctx, aidlPackage, "Bn"+shortName+".h")
134 headerBp := outDir.Join(ctx, aidlPackage, "Bp"+shortName+".h")
135
136 cmd := rule.Command()
Colin Crossf1a035e2020-11-16 17:32:30 -0800137 cmd.BuiltTool("aidl-cpp").
Vinh Tran09581952023-05-16 16:03:20 -0400138 // libc++ is default stl for aidl-cpp (a cc_binary_host module)
139 ImplicitTool(ctx.Config().HostCcSharedLibPath(ctx, "libc++")).
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700140 FlagWithDepFile("-d", depFile).
141 Flag("--ninja").
142 Flag(aidlFlags).
143 Input(aidlFile).
144 OutputDir().
Jiyong Parkc7e592c2021-04-07 21:49:34 +0900145 Output(cppFile).
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700146 ImplicitOutputs(android.WritablePaths{
147 headerI,
148 headerBn,
149 headerBp,
150 })
151
Vinh Tran09581952023-05-16 16:03:20 -0400152 if aidlHdrs != nil {
153 cmd.Implicits(aidlHdrs)
154 }
155
Jiyong Parkc7e592c2021-04-07 21:49:34 +0900156 return cppFile, android.Paths{
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700157 headerI,
158 headerBn,
159 headerBp,
160 }
Dan Willemsene1240db2016-11-03 14:28:51 -0700161}
162
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200163type LexProperties struct {
164 // list of module-specific flags that will be used for .l and .ll compiles
165 Flags []string
166}
167
168func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.ModuleGenPath, props *LexProperties) {
169 var flags []string
170 if props != nil {
171 flags = props.Flags
172 }
173 flagsString := strings.Join(flags[:], " ")
David Sudd18efd2020-07-24 17:19:23 +0000174 ctx.Build(pctx, android.BuildParams{
175 Rule: lex,
176 Description: "lex " + lexFile.Rel(),
177 Output: outFile,
178 Input: lexFile,
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200179 Args: map[string]string{"flags": flagsString},
David Sudd18efd2020-07-24 17:19:23 +0000180 })
Colin Cross581c1892015-04-07 16:50:10 -0700181}
182
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000183type LexAttrs struct {
184 Srcs bazel.LabelListAttribute
185 Lexopts bazel.StringListAttribute
186}
187
188type LexNames struct {
189 cSrcName bazel.LabelAttribute
190 srcName bazel.LabelAttribute
191}
192
193func bp2BuildLex(ctx android.Bp2buildMutatorContext, moduleName string, ca compilerAttributes) LexNames {
194 names := LexNames{}
195 if !ca.lSrcs.IsEmpty() {
196 names.cSrcName = createLexTargetModule(ctx, moduleName+"_genlex_l", ca.lSrcs, ca.lexopts)
197 }
198 if !ca.llSrcs.IsEmpty() {
199 names.srcName = createLexTargetModule(ctx, moduleName+"_genlex_ll", ca.llSrcs, ca.lexopts)
200 }
201 return names
202}
203
204func createLexTargetModule(ctx android.Bp2buildMutatorContext, name string, srcs bazel.LabelListAttribute, opts bazel.StringListAttribute) bazel.LabelAttribute {
205 ctx.CreateBazelTargetModule(
206 bazel.BazelTargetModuleProperties{
207 Rule_class: "genlex",
208 Bzl_load_location: "//build/bazel/rules/cc:flex.bzl",
209 },
210 android.CommonAttributes{Name: name},
211 &LexAttrs{
212 Srcs: srcs,
213 Lexopts: opts,
214 })
215 return bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + name}}
216}
217
Inseob Kimed2641f2020-02-19 10:42:41 +0900218func genSysprop(ctx android.ModuleContext, syspropFile android.Path) (android.Path, android.Paths) {
Inseob Kim21f26902018-09-06 00:55:20 +0900219 headerFile := android.PathForModuleGen(ctx, "sysprop", "include", syspropFile.Rel()+".h")
Inseob Kim5cefbd22019-06-08 20:36:59 +0900220 publicHeaderFile := android.PathForModuleGen(ctx, "sysprop/public", "include", syspropFile.Rel()+".h")
Inseob Kim21f26902018-09-06 00:55:20 +0900221 cppFile := android.PathForModuleGen(ctx, "sysprop", syspropFile.Rel()+".cpp")
222
Inseob Kimed2641f2020-02-19 10:42:41 +0900223 headers := android.WritablePaths{headerFile, publicHeaderFile}
224
Inseob Kim21f26902018-09-06 00:55:20 +0900225 ctx.Build(pctx, android.BuildParams{
Inseob Kimed2641f2020-02-19 10:42:41 +0900226 Rule: sysprop,
227 Description: "sysprop " + syspropFile.Rel(),
228 Output: cppFile,
229 ImplicitOutputs: headers,
230 Input: syspropFile,
Inseob Kim21f26902018-09-06 00:55:20 +0900231 Args: map[string]string{
232 "headerOutDir": filepath.Dir(headerFile.String()),
Inseob Kim5cefbd22019-06-08 20:36:59 +0900233 "publicOutDir": filepath.Dir(publicHeaderFile.String()),
Inseob Kim21f26902018-09-06 00:55:20 +0900234 "srcOutDir": filepath.Dir(cppFile.String()),
235 "includeName": syspropFile.Rel() + ".h",
236 },
237 })
238
Inseob Kimed2641f2020-02-19 10:42:41 +0900239 return cppFile, headers.Paths()
Inseob Kim21f26902018-09-06 00:55:20 +0900240}
241
Trevor Radcliffecee4e052022-09-06 19:31:25 +0000242func bp2buildCcSysprop(ctx android.Bp2buildMutatorContext, moduleName string, minSdkVersion *string, srcs bazel.LabelListAttribute) *bazel.LabelAttribute {
243 labels := SyspropLibraryLabels{
244 SyspropLibraryLabel: moduleName + "_sysprop_library",
245 StaticLibraryLabel: moduleName + "_cc_sysprop_library_static",
246 }
247 Bp2buildSysprop(ctx, labels, srcs, minSdkVersion)
248 return createLabelAttributeCorrespondingToSrcs(":"+labels.StaticLibraryLabel, srcs)
249}
250
251// Creates a LabelAttribute for a given label where the value is only set for
252// the same config values that have values in a given LabelListAttribute
253func createLabelAttributeCorrespondingToSrcs(baseLabelName string, srcs bazel.LabelListAttribute) *bazel.LabelAttribute {
254 baseLabel := bazel.Label{Label: baseLabelName}
255 label := bazel.LabelAttribute{}
256 if !srcs.Value.IsNil() && !srcs.Value.IsEmpty() {
257 label.Value = &baseLabel
258 return &label
259 }
260 for axis, configToSrcs := range srcs.ConfigurableValues {
261 for config, val := range configToSrcs {
262 if !val.IsNil() && !val.IsEmpty() {
263 label.SetSelectValue(axis, config, baseLabel)
264 }
265 }
266 }
267 return &label
268}
269
Paul Duffin33056e82021-02-19 13:49:08 +0000270// Used to communicate information from the genSources method back to the library code that uses
271// it.
272type generatedSourceInfo struct {
273 // The headers created from .proto files
274 protoHeaders android.Paths
275
276 // The files that can be used as order only dependencies in order to ensure that the proto header
277 // files are up to date.
278 protoOrderOnlyDeps android.Paths
279
280 // The headers created from .aidl files
281 aidlHeaders android.Paths
282
283 // The files that can be used as order only dependencies in order to ensure that the aidl header
284 // files are up to date.
285 aidlOrderOnlyDeps android.Paths
286
287 // The headers created from .sysprop files
288 syspropHeaders android.Paths
289
290 // The files that can be used as order only dependencies in order to ensure that the sysprop
291 // header files are up to date.
292 syspropOrderOnlyDeps android.Paths
293}
294
Vinh Tran367d89d2023-04-28 11:21:25 -0400295func genSources(
296 ctx android.ModuleContext,
297 aidlLibraryInfos []aidl_library.AidlLibraryInfo,
298 srcFiles android.Paths,
Vinh Tran09581952023-05-16 16:03:20 -0400299 buildFlags builderFlags,
300) (android.Paths, android.Paths, generatedSourceInfo) {
Paul Duffin33056e82021-02-19 13:49:08 +0000301
302 var info generatedSourceInfo
Colin Cross581c1892015-04-07 16:50:10 -0700303
Colin Cross635c3b02016-05-18 15:37:25 -0700304 var deps android.Paths
Colin Cross2a252be2017-05-01 17:37:24 -0700305 var rsFiles android.Paths
306
Vinh Tran09581952023-05-16 16:03:20 -0400307 // aidlRule supports compiling aidl files from srcs prop while aidlLibraryRule supports
308 // compiling aidl files from aidl_library modules specified in aidl.libs prop.
309 // The rules are separated so that they don't wipe out the other's outputDir
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700310 var aidlRule *android.RuleBuilder
Vinh Tran09581952023-05-16 16:03:20 -0400311 var aidlLibraryRule *android.RuleBuilder
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700312
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700313 var yaccRule_ *android.RuleBuilder
314 yaccRule := func() *android.RuleBuilder {
315 if yaccRule_ == nil {
Colin Crossf1a035e2020-11-16 17:32:30 -0800316 yaccRule_ = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "yacc"),
Colin Crosse16ce362020-11-12 08:29:30 -0800317 android.PathForModuleGen(ctx, "yacc.sbox.textproto"))
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700318 }
319 return yaccRule_
320 }
321
Colin Cross581c1892015-04-07 16:50:10 -0700322 for i, srcFile := range srcFiles {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700323 switch srcFile.Ext() {
Dan Willemsenf0c73e02016-03-01 15:15:26 -0800324 case ".y":
Dan Willemsen21ec4902016-11-02 20:43:13 -0700325 cFile := android.GenPathWithExt(ctx, "yacc", srcFile, "c")
Dan Willemsenf0c73e02016-03-01 15:15:26 -0800326 srcFiles[i] = cFile
David Sudd18efd2020-07-24 17:19:23 +0000327 deps = append(deps, genYacc(ctx, yaccRule(), srcFile, cFile, buildFlags.yacc)...)
Dan Willemsenf0c73e02016-03-01 15:15:26 -0800328 case ".yy":
Dan Willemsen21ec4902016-11-02 20:43:13 -0700329 cppFile := android.GenPathWithExt(ctx, "yacc", srcFile, "cpp")
Colin Cross581c1892015-04-07 16:50:10 -0700330 srcFiles[i] = cppFile
David Sudd18efd2020-07-24 17:19:23 +0000331 deps = append(deps, genYacc(ctx, yaccRule(), srcFile, cppFile, buildFlags.yacc)...)
Dan Willemsenf0c73e02016-03-01 15:15:26 -0800332 case ".l":
Dan Willemsen21ec4902016-11-02 20:43:13 -0700333 cFile := android.GenPathWithExt(ctx, "lex", srcFile, "c")
Dan Willemsenf0c73e02016-03-01 15:15:26 -0800334 srcFiles[i] = cFile
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200335 genLex(ctx, srcFile, cFile, buildFlags.lex)
Dan Willemsenf0c73e02016-03-01 15:15:26 -0800336 case ".ll":
Dan Willemsen21ec4902016-11-02 20:43:13 -0700337 cppFile := android.GenPathWithExt(ctx, "lex", srcFile, "cpp")
Colin Cross581c1892015-04-07 16:50:10 -0700338 srcFiles[i] = cppFile
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200339 genLex(ctx, srcFile, cppFile, buildFlags.lex)
Colin Cross0c461f12016-10-20 16:11:43 -0700340 case ".proto":
Dan Willemsen60e62f02018-11-16 21:05:32 -0800341 ccFile, headerFile := genProto(ctx, srcFile, buildFlags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700342 srcFiles[i] = ccFile
Paul Duffin33056e82021-02-19 13:49:08 +0000343 info.protoHeaders = append(info.protoHeaders, headerFile)
344 // Use the generated header as an order only dep to ensure that it is up to date when needed.
345 info.protoOrderOnlyDeps = append(info.protoOrderOnlyDeps, headerFile)
Dan Willemsene1240db2016-11-03 14:28:51 -0700346 case ".aidl":
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700347 if aidlRule == nil {
Colin Crossf1a035e2020-11-16 17:32:30 -0800348 aidlRule = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "aidl"),
Colin Crosse16ce362020-11-12 08:29:30 -0800349 android.PathForModuleGen(ctx, "aidl.sbox.textproto"))
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700350 }
Vinh Tran367d89d2023-04-28 11:21:25 -0400351 baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel())
Vinh Tran09581952023-05-16 16:03:20 -0400352 cppFile, aidlHeaders := genAidl(
353 ctx,
354 aidlRule,
355 "aidl",
356 srcFile,
357 nil,
358 buildFlags.aidlFlags+" -I"+baseDir,
359 )
Dan Willemsene1240db2016-11-03 14:28:51 -0700360 srcFiles[i] = cppFile
Jiyong Parkc7e592c2021-04-07 21:49:34 +0900361
Paul Duffin33056e82021-02-19 13:49:08 +0000362 info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...)
363 // Use the generated headers as order only deps to ensure that they are up to date when
364 // needed.
365 // TODO: Reduce the size of the ninja file by using one order only dep for the whole rule
366 info.aidlOrderOnlyDeps = append(info.aidlOrderOnlyDeps, aidlHeaders...)
Jeff Vander Stoepd6126272019-07-15 19:08:37 -0700367 case ".rscript", ".fs":
Colin Cross2a252be2017-05-01 17:37:24 -0700368 cppFile := rsGeneratedCppFile(ctx, srcFile)
369 rsFiles = append(rsFiles, srcFiles[i])
370 srcFiles[i] = cppFile
Inseob Kim21f26902018-09-06 00:55:20 +0900371 case ".sysprop":
Inseob Kimed2641f2020-02-19 10:42:41 +0900372 cppFile, headerFiles := genSysprop(ctx, srcFile)
Inseob Kim21f26902018-09-06 00:55:20 +0900373 srcFiles[i] = cppFile
Paul Duffin33056e82021-02-19 13:49:08 +0000374 info.syspropHeaders = append(info.syspropHeaders, headerFiles...)
375 // Use the generated headers as order only deps to ensure that they are up to date when
376 // needed.
377 info.syspropOrderOnlyDeps = append(info.syspropOrderOnlyDeps, headerFiles...)
Colin Cross581c1892015-04-07 16:50:10 -0700378 }
379 }
380
Vinh Tran367d89d2023-04-28 11:21:25 -0400381 for _, aidlLibraryInfo := range aidlLibraryInfos {
Vinh Tran09581952023-05-16 16:03:20 -0400382 if aidlLibraryRule == nil {
383 aidlLibraryRule = android.NewRuleBuilder(pctx, ctx).Sbox(
384 android.PathForModuleGen(ctx, "aidl_library"),
385 android.PathForModuleGen(ctx, "aidl_library.sbox.textproto"),
386 ).SandboxInputs()
387 }
Vinh Tran367d89d2023-04-28 11:21:25 -0400388 for _, aidlSrc := range aidlLibraryInfo.Srcs {
Vinh Tran09581952023-05-16 16:03:20 -0400389 cppFile, aidlHeaders := genAidl(
390 ctx,
391 aidlLibraryRule,
392 "aidl_library",
393 aidlSrc,
394 aidlLibraryInfo.Hdrs.ToList(),
395 buildFlags.aidlFlags,
396 )
Vinh Tran367d89d2023-04-28 11:21:25 -0400397
398 srcFiles = append(srcFiles, cppFile)
399 info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...)
400 // Use the generated headers as order only deps to ensure that they are up to date when
401 // needed.
402 // TODO: Reduce the size of the ninja file by using one order only dep for the whole rule
403 info.aidlOrderOnlyDeps = append(info.aidlOrderOnlyDeps, aidlHeaders...)
404 }
405 }
406
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700407 if aidlRule != nil {
Colin Crossf1a035e2020-11-16 17:32:30 -0800408 aidlRule.Build("aidl", "gen aidl")
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700409 }
410
Vinh Tran09581952023-05-16 16:03:20 -0400411 if aidlLibraryRule != nil {
412 aidlLibraryRule.Build("aidl_library", "gen aidl_library")
413 }
414
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700415 if yaccRule_ != nil {
Colin Crossf1a035e2020-11-16 17:32:30 -0800416 yaccRule_.Build("yacc", "gen yacc")
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700417 }
418
Paul Duffin33056e82021-02-19 13:49:08 +0000419 deps = append(deps, info.protoOrderOnlyDeps...)
420 deps = append(deps, info.aidlOrderOnlyDeps...)
421 deps = append(deps, info.syspropOrderOnlyDeps...)
422
Colin Cross2a252be2017-05-01 17:37:24 -0700423 if len(rsFiles) > 0 {
424 deps = append(deps, rsGenerateCpp(ctx, rsFiles, buildFlags.rsFlags)...)
425 }
426
Paul Duffin33056e82021-02-19 13:49:08 +0000427 return srcFiles, deps, info
Colin Cross581c1892015-04-07 16:50:10 -0700428}