blob: 151f23d9eb80a516781d89f4ce02e34e038e79d9 [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"
Trevor Radcliffe9b81d792023-09-29 15:22:52 +000023 "android/soong/sysprop/bp2build"
Vinh Tran367d89d2023-04-28 11:21:25 -040024
Colin Cross581c1892015-04-07 16:50:10 -070025 "github.com/google/blueprint"
Colin Cross581c1892015-04-07 16:50:10 -070026
Colin Cross635c3b02016-05-18 15:37:25 -070027 "android/soong/android"
Colin Cross581c1892015-04-07 16:50:10 -070028)
29
30func init() {
David Sudd18efd2020-07-24 17:19:23 +000031 pctx.SourcePathVariable("lexCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/flex")
Dan Willemsen613564e2020-07-23 21:37:35 +000032 pctx.SourcePathVariable("m4Cmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/m4")
33
Dan Willemsene1240db2016-11-03 14:28:51 -070034 pctx.HostBinToolVariable("aidlCmd", "aidl-cpp")
Inseob Kim21f26902018-09-06 00:55:20 +090035 pctx.HostBinToolVariable("syspropCmd", "sysprop_cpp")
Colin Cross581c1892015-04-07 16:50:10 -070036}
37
38var (
David Sudd18efd2020-07-24 17:19:23 +000039 lex = pctx.AndroidStaticRule("lex",
40 blueprint.RuleParams{
Matthias Maennich22fd4d12020-07-15 10:58:56 +020041 Command: "M4=$m4Cmd $lexCmd $flags -o$out $in",
David Sudd18efd2020-07-24 17:19:23 +000042 CommandDeps: []string{"$lexCmd", "$m4Cmd"},
Matthias Maennich22fd4d12020-07-15 10:58:56 +020043 }, "flags")
David Sudd18efd2020-07-24 17:19:23 +000044
Inseob Kim21f26902018-09-06 00:55:20 +090045 sysprop = pctx.AndroidStaticRule("sysprop",
46 blueprint.RuleParams{
Inseob Kim5cefbd22019-06-08 20:36:59 +090047 Command: "$syspropCmd --header-dir=$headerOutDir --public-header-dir=$publicOutDir " +
Inseob Kimc0907f12019-02-08 21:00:45 +090048 "--source-dir=$srcOutDir --include-name=$includeName $in",
Inseob Kim21f26902018-09-06 00:55:20 +090049 CommandDeps: []string{"$syspropCmd"},
50 },
Inseob Kim5cefbd22019-06-08 20:36:59 +090051 "headerOutDir", "publicOutDir", "srcOutDir", "includeName")
Colin Cross581c1892015-04-07 16:50:10 -070052)
53
Dan Willemsen4e0aa232019-04-10 22:59:54 -070054type YaccProperties struct {
55 // list of module-specific flags that will be used for .y and .yy compiles
56 Flags []string
Colin Cross581c1892015-04-07 16:50:10 -070057
Dan Willemsen4e0aa232019-04-10 22:59:54 -070058 // whether the yacc files will produce a location.hh file
59 Gen_location_hh *bool
Colin Cross581c1892015-04-07 16:50:10 -070060
Dan Willemsen4e0aa232019-04-10 22:59:54 -070061 // whether the yacc files will product a position.hh file
62 Gen_position_hh *bool
63}
64
65func genYacc(ctx android.ModuleContext, rule *android.RuleBuilder, yaccFile android.Path,
David Sudd18efd2020-07-24 17:19:23 +000066 outFile android.ModuleGenPath, props *YaccProperties) (headerFiles android.Paths) {
Dan Willemsen4e0aa232019-04-10 22:59:54 -070067
68 outDir := android.PathForModuleGen(ctx, "yacc")
69 headerFile := android.GenPathWithExt(ctx, "yacc", yaccFile, "h")
70 ret := android.Paths{headerFile}
71
72 cmd := rule.Command()
73
74 // Fix up #line markers to not use the sbox temporary directory
Colin Crossf1a035e2020-11-16 17:32:30 -080075 // android.sboxPathForOutput(outDir, outDir) returns the sbox placeholder for the out
Colin Cross3d680512020-11-13 16:23:53 -080076 // directory itself, without any filename appended.
Colin Crossf1a035e2020-11-16 17:32:30 -080077 sboxOutDir := cmd.PathForOutput(outDir)
Colin Cross3d680512020-11-13 16:23:53 -080078 sedCmd := "sed -i.bak 's#" + sboxOutDir + "#" + outDir.String() + "#'"
Dan Willemsen4e0aa232019-04-10 22:59:54 -070079 rule.Command().Text(sedCmd).Input(outFile)
80 rule.Command().Text(sedCmd).Input(headerFile)
81
82 var flags []string
83 if props != nil {
84 flags = props.Flags
85
86 if Bool(props.Gen_location_hh) {
87 locationHeader := outFile.InSameDir(ctx, "location.hh")
88 ret = append(ret, locationHeader)
89 cmd.ImplicitOutput(locationHeader)
90 rule.Command().Text(sedCmd).Input(locationHeader)
91 }
92 if Bool(props.Gen_position_hh) {
93 positionHeader := outFile.InSameDir(ctx, "position.hh")
94 ret = append(ret, positionHeader)
95 cmd.ImplicitOutput(positionHeader)
96 rule.Command().Text(sedCmd).Input(positionHeader)
97 }
98 }
99
David Sudd18efd2020-07-24 17:19:23 +0000100 cmd.Text("BISON_PKGDATADIR=prebuilts/build-tools/common/bison").
101 FlagWithInput("M4=", ctx.Config().PrebuiltBuildTool(ctx, "m4")).
102 PrebuiltBuildTool(ctx, "bison").
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700103 Flag("-d").
104 Flags(flags).
105 FlagWithOutput("--defines=", headerFile).
106 Flag("-o").Output(outFile).Input(yaccFile)
107
108 return ret
Colin Cross581c1892015-04-07 16:50:10 -0700109}
110
Vinh Tran09581952023-05-16 16:03:20 -0400111func genAidl(
112 ctx android.ModuleContext,
113 rule *android.RuleBuilder,
114 outDirBase string,
115 aidlFile android.Path,
116 aidlHdrs android.Paths,
117 aidlFlags string,
118) (cppFile android.OutputPath, headerFiles android.Paths) {
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700119 aidlPackage := strings.TrimSuffix(aidlFile.Rel(), aidlFile.Base())
120 baseName := strings.TrimSuffix(aidlFile.Base(), aidlFile.Ext())
Daniel Norman10b74352019-09-24 17:39:58 -0700121 shortName := baseName
122 // TODO(b/111362593): aidl_to_cpp_common.cpp uses heuristics to figure out if
123 // an interface name has a leading I. Those same heuristics have been
124 // moved here.
125 if len(baseName) >= 2 && baseName[0] == 'I' &&
126 strings.ToUpper(baseName)[1] == baseName[1] {
127 shortName = strings.TrimPrefix(baseName, "I")
128 }
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700129
Vinh Tran09581952023-05-16 16:03:20 -0400130 outDir := android.PathForModuleGen(ctx, outDirBase)
Jiyong Parkc7e592c2021-04-07 21:49:34 +0900131 cppFile = outDir.Join(ctx, aidlPackage, baseName+".cpp")
132 depFile := outDir.Join(ctx, aidlPackage, baseName+".cpp.d")
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700133 headerI := outDir.Join(ctx, aidlPackage, baseName+".h")
134 headerBn := outDir.Join(ctx, aidlPackage, "Bn"+shortName+".h")
135 headerBp := outDir.Join(ctx, aidlPackage, "Bp"+shortName+".h")
136
137 cmd := rule.Command()
Colin Crossf1a035e2020-11-16 17:32:30 -0800138 cmd.BuiltTool("aidl-cpp").
Vinh Tran09581952023-05-16 16:03:20 -0400139 // libc++ is default stl for aidl-cpp (a cc_binary_host module)
140 ImplicitTool(ctx.Config().HostCcSharedLibPath(ctx, "libc++")).
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700141 FlagWithDepFile("-d", depFile).
142 Flag("--ninja").
143 Flag(aidlFlags).
144 Input(aidlFile).
145 OutputDir().
Jiyong Parkc7e592c2021-04-07 21:49:34 +0900146 Output(cppFile).
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700147 ImplicitOutputs(android.WritablePaths{
148 headerI,
149 headerBn,
150 headerBp,
151 })
152
Vinh Tran09581952023-05-16 16:03:20 -0400153 if aidlHdrs != nil {
154 cmd.Implicits(aidlHdrs)
155 }
156
Jiyong Parkc7e592c2021-04-07 21:49:34 +0900157 return cppFile, android.Paths{
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700158 headerI,
159 headerBn,
160 headerBp,
161 }
Dan Willemsene1240db2016-11-03 14:28:51 -0700162}
163
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200164type LexProperties struct {
165 // list of module-specific flags that will be used for .l and .ll compiles
166 Flags []string
167}
168
169func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.ModuleGenPath, props *LexProperties) {
170 var flags []string
171 if props != nil {
172 flags = props.Flags
173 }
174 flagsString := strings.Join(flags[:], " ")
David Sudd18efd2020-07-24 17:19:23 +0000175 ctx.Build(pctx, android.BuildParams{
176 Rule: lex,
177 Description: "lex " + lexFile.Rel(),
178 Output: outFile,
179 Input: lexFile,
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200180 Args: map[string]string{"flags": flagsString},
David Sudd18efd2020-07-24 17:19:23 +0000181 })
Colin Cross581c1892015-04-07 16:50:10 -0700182}
183
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000184type LexAttrs struct {
185 Srcs bazel.LabelListAttribute
186 Lexopts bazel.StringListAttribute
187}
188
189type LexNames struct {
190 cSrcName bazel.LabelAttribute
191 srcName bazel.LabelAttribute
192}
193
194func bp2BuildLex(ctx android.Bp2buildMutatorContext, moduleName string, ca compilerAttributes) LexNames {
195 names := LexNames{}
196 if !ca.lSrcs.IsEmpty() {
197 names.cSrcName = createLexTargetModule(ctx, moduleName+"_genlex_l", ca.lSrcs, ca.lexopts)
198 }
199 if !ca.llSrcs.IsEmpty() {
200 names.srcName = createLexTargetModule(ctx, moduleName+"_genlex_ll", ca.llSrcs, ca.lexopts)
201 }
202 return names
203}
204
205func createLexTargetModule(ctx android.Bp2buildMutatorContext, name string, srcs bazel.LabelListAttribute, opts bazel.StringListAttribute) bazel.LabelAttribute {
206 ctx.CreateBazelTargetModule(
207 bazel.BazelTargetModuleProperties{
208 Rule_class: "genlex",
209 Bzl_load_location: "//build/bazel/rules/cc:flex.bzl",
210 },
211 android.CommonAttributes{Name: name},
212 &LexAttrs{
213 Srcs: srcs,
214 Lexopts: opts,
215 })
216 return bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + name}}
217}
218
Inseob Kimed2641f2020-02-19 10:42:41 +0900219func genSysprop(ctx android.ModuleContext, syspropFile android.Path) (android.Path, android.Paths) {
Inseob Kim21f26902018-09-06 00:55:20 +0900220 headerFile := android.PathForModuleGen(ctx, "sysprop", "include", syspropFile.Rel()+".h")
Inseob Kim5cefbd22019-06-08 20:36:59 +0900221 publicHeaderFile := android.PathForModuleGen(ctx, "sysprop/public", "include", syspropFile.Rel()+".h")
Inseob Kim21f26902018-09-06 00:55:20 +0900222 cppFile := android.PathForModuleGen(ctx, "sysprop", syspropFile.Rel()+".cpp")
223
Inseob Kimed2641f2020-02-19 10:42:41 +0900224 headers := android.WritablePaths{headerFile, publicHeaderFile}
225
Inseob Kim21f26902018-09-06 00:55:20 +0900226 ctx.Build(pctx, android.BuildParams{
Inseob Kimed2641f2020-02-19 10:42:41 +0900227 Rule: sysprop,
228 Description: "sysprop " + syspropFile.Rel(),
229 Output: cppFile,
230 ImplicitOutputs: headers,
231 Input: syspropFile,
Inseob Kim21f26902018-09-06 00:55:20 +0900232 Args: map[string]string{
233 "headerOutDir": filepath.Dir(headerFile.String()),
Inseob Kim5cefbd22019-06-08 20:36:59 +0900234 "publicOutDir": filepath.Dir(publicHeaderFile.String()),
Inseob Kim21f26902018-09-06 00:55:20 +0900235 "srcOutDir": filepath.Dir(cppFile.String()),
236 "includeName": syspropFile.Rel() + ".h",
237 },
238 })
239
Inseob Kimed2641f2020-02-19 10:42:41 +0900240 return cppFile, headers.Paths()
Inseob Kim21f26902018-09-06 00:55:20 +0900241}
242
Trevor Radcliffecee4e052022-09-06 19:31:25 +0000243func bp2buildCcSysprop(ctx android.Bp2buildMutatorContext, moduleName string, minSdkVersion *string, srcs bazel.LabelListAttribute) *bazel.LabelAttribute {
Trevor Radcliffe9b81d792023-09-29 15:22:52 +0000244 labels := bp2build.SyspropLibraryLabels{
245 SyspropLibraryLabel: moduleName + "_sysprop_library",
246 CcStaticLibraryLabel: moduleName + "_cc_sysprop_library_static",
Trevor Radcliffecee4e052022-09-06 19:31:25 +0000247 }
Trevor Radcliffe9b81d792023-09-29 15:22:52 +0000248 bp2build.Bp2buildBaseSyspropLibrary(ctx, labels.SyspropLibraryLabel, srcs)
249 bp2build.Bp2buildSyspropCc(ctx, labels, minSdkVersion)
250 return createLabelAttributeCorrespondingToSrcs(":"+labels.CcStaticLibraryLabel, srcs)
Trevor Radcliffecee4e052022-09-06 19:31:25 +0000251}
252
253// Creates a LabelAttribute for a given label where the value is only set for
254// the same config values that have values in a given LabelListAttribute
255func createLabelAttributeCorrespondingToSrcs(baseLabelName string, srcs bazel.LabelListAttribute) *bazel.LabelAttribute {
256 baseLabel := bazel.Label{Label: baseLabelName}
257 label := bazel.LabelAttribute{}
258 if !srcs.Value.IsNil() && !srcs.Value.IsEmpty() {
259 label.Value = &baseLabel
260 return &label
261 }
262 for axis, configToSrcs := range srcs.ConfigurableValues {
263 for config, val := range configToSrcs {
264 if !val.IsNil() && !val.IsEmpty() {
265 label.SetSelectValue(axis, config, baseLabel)
266 }
267 }
268 }
269 return &label
270}
271
Paul Duffin33056e82021-02-19 13:49:08 +0000272// Used to communicate information from the genSources method back to the library code that uses
273// it.
274type generatedSourceInfo struct {
275 // The headers created from .proto files
276 protoHeaders android.Paths
277
278 // The files that can be used as order only dependencies in order to ensure that the proto header
279 // files are up to date.
280 protoOrderOnlyDeps android.Paths
281
282 // The headers created from .aidl files
283 aidlHeaders android.Paths
284
285 // The files that can be used as order only dependencies in order to ensure that the aidl header
286 // files are up to date.
287 aidlOrderOnlyDeps android.Paths
288
289 // The headers created from .sysprop files
290 syspropHeaders android.Paths
291
292 // The files that can be used as order only dependencies in order to ensure that the sysprop
293 // header files are up to date.
294 syspropOrderOnlyDeps android.Paths
295}
296
Vinh Tran367d89d2023-04-28 11:21:25 -0400297func genSources(
298 ctx android.ModuleContext,
299 aidlLibraryInfos []aidl_library.AidlLibraryInfo,
300 srcFiles android.Paths,
Vinh Tran09581952023-05-16 16:03:20 -0400301 buildFlags builderFlags,
302) (android.Paths, android.Paths, generatedSourceInfo) {
Paul Duffin33056e82021-02-19 13:49:08 +0000303
304 var info generatedSourceInfo
Colin Cross581c1892015-04-07 16:50:10 -0700305
Colin Cross635c3b02016-05-18 15:37:25 -0700306 var deps android.Paths
Colin Cross2a252be2017-05-01 17:37:24 -0700307 var rsFiles android.Paths
308
Vinh Tran09581952023-05-16 16:03:20 -0400309 // aidlRule supports compiling aidl files from srcs prop while aidlLibraryRule supports
310 // compiling aidl files from aidl_library modules specified in aidl.libs prop.
311 // The rules are separated so that they don't wipe out the other's outputDir
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700312 var aidlRule *android.RuleBuilder
Vinh Tran09581952023-05-16 16:03:20 -0400313 var aidlLibraryRule *android.RuleBuilder
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700314
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700315 var yaccRule_ *android.RuleBuilder
316 yaccRule := func() *android.RuleBuilder {
317 if yaccRule_ == nil {
Colin Crossf1a035e2020-11-16 17:32:30 -0800318 yaccRule_ = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "yacc"),
Colin Crosse16ce362020-11-12 08:29:30 -0800319 android.PathForModuleGen(ctx, "yacc.sbox.textproto"))
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700320 }
321 return yaccRule_
322 }
323
Colin Cross581c1892015-04-07 16:50:10 -0700324 for i, srcFile := range srcFiles {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700325 switch srcFile.Ext() {
Dan Willemsenf0c73e02016-03-01 15:15:26 -0800326 case ".y":
Dan Willemsen21ec4902016-11-02 20:43:13 -0700327 cFile := android.GenPathWithExt(ctx, "yacc", srcFile, "c")
Dan Willemsenf0c73e02016-03-01 15:15:26 -0800328 srcFiles[i] = cFile
David Sudd18efd2020-07-24 17:19:23 +0000329 deps = append(deps, genYacc(ctx, yaccRule(), srcFile, cFile, buildFlags.yacc)...)
Dan Willemsenf0c73e02016-03-01 15:15:26 -0800330 case ".yy":
Dan Willemsen21ec4902016-11-02 20:43:13 -0700331 cppFile := android.GenPathWithExt(ctx, "yacc", srcFile, "cpp")
Colin Cross581c1892015-04-07 16:50:10 -0700332 srcFiles[i] = cppFile
David Sudd18efd2020-07-24 17:19:23 +0000333 deps = append(deps, genYacc(ctx, yaccRule(), srcFile, cppFile, buildFlags.yacc)...)
Dan Willemsenf0c73e02016-03-01 15:15:26 -0800334 case ".l":
Dan Willemsen21ec4902016-11-02 20:43:13 -0700335 cFile := android.GenPathWithExt(ctx, "lex", srcFile, "c")
Dan Willemsenf0c73e02016-03-01 15:15:26 -0800336 srcFiles[i] = cFile
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200337 genLex(ctx, srcFile, cFile, buildFlags.lex)
Dan Willemsenf0c73e02016-03-01 15:15:26 -0800338 case ".ll":
Dan Willemsen21ec4902016-11-02 20:43:13 -0700339 cppFile := android.GenPathWithExt(ctx, "lex", srcFile, "cpp")
Colin Cross581c1892015-04-07 16:50:10 -0700340 srcFiles[i] = cppFile
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200341 genLex(ctx, srcFile, cppFile, buildFlags.lex)
Colin Cross0c461f12016-10-20 16:11:43 -0700342 case ".proto":
Dan Willemsen60e62f02018-11-16 21:05:32 -0800343 ccFile, headerFile := genProto(ctx, srcFile, buildFlags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700344 srcFiles[i] = ccFile
Paul Duffin33056e82021-02-19 13:49:08 +0000345 info.protoHeaders = append(info.protoHeaders, headerFile)
346 // Use the generated header as an order only dep to ensure that it is up to date when needed.
347 info.protoOrderOnlyDeps = append(info.protoOrderOnlyDeps, headerFile)
Dan Willemsene1240db2016-11-03 14:28:51 -0700348 case ".aidl":
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700349 if aidlRule == nil {
Colin Crossf1a035e2020-11-16 17:32:30 -0800350 aidlRule = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "aidl"),
Colin Crosse16ce362020-11-12 08:29:30 -0800351 android.PathForModuleGen(ctx, "aidl.sbox.textproto"))
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700352 }
Vinh Tran367d89d2023-04-28 11:21:25 -0400353 baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel())
Vinh Tran09581952023-05-16 16:03:20 -0400354 cppFile, aidlHeaders := genAidl(
355 ctx,
356 aidlRule,
357 "aidl",
358 srcFile,
359 nil,
360 buildFlags.aidlFlags+" -I"+baseDir,
361 )
Dan Willemsene1240db2016-11-03 14:28:51 -0700362 srcFiles[i] = cppFile
Jiyong Parkc7e592c2021-04-07 21:49:34 +0900363
Paul Duffin33056e82021-02-19 13:49:08 +0000364 info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...)
365 // Use the generated headers as order only deps to ensure that they are up to date when
366 // needed.
367 // TODO: Reduce the size of the ninja file by using one order only dep for the whole rule
368 info.aidlOrderOnlyDeps = append(info.aidlOrderOnlyDeps, aidlHeaders...)
Jeff Vander Stoepd6126272019-07-15 19:08:37 -0700369 case ".rscript", ".fs":
Colin Cross2a252be2017-05-01 17:37:24 -0700370 cppFile := rsGeneratedCppFile(ctx, srcFile)
371 rsFiles = append(rsFiles, srcFiles[i])
372 srcFiles[i] = cppFile
Inseob Kim21f26902018-09-06 00:55:20 +0900373 case ".sysprop":
Inseob Kimed2641f2020-02-19 10:42:41 +0900374 cppFile, headerFiles := genSysprop(ctx, srcFile)
Inseob Kim21f26902018-09-06 00:55:20 +0900375 srcFiles[i] = cppFile
Paul Duffin33056e82021-02-19 13:49:08 +0000376 info.syspropHeaders = append(info.syspropHeaders, headerFiles...)
377 // Use the generated headers as order only deps to ensure that they are up to date when
378 // needed.
379 info.syspropOrderOnlyDeps = append(info.syspropOrderOnlyDeps, headerFiles...)
Colin Cross581c1892015-04-07 16:50:10 -0700380 }
381 }
382
Vinh Tran367d89d2023-04-28 11:21:25 -0400383 for _, aidlLibraryInfo := range aidlLibraryInfos {
Vinh Tran09581952023-05-16 16:03:20 -0400384 if aidlLibraryRule == nil {
385 aidlLibraryRule = android.NewRuleBuilder(pctx, ctx).Sbox(
386 android.PathForModuleGen(ctx, "aidl_library"),
387 android.PathForModuleGen(ctx, "aidl_library.sbox.textproto"),
388 ).SandboxInputs()
389 }
Vinh Tran367d89d2023-04-28 11:21:25 -0400390 for _, aidlSrc := range aidlLibraryInfo.Srcs {
Vinh Tran09581952023-05-16 16:03:20 -0400391 cppFile, aidlHeaders := genAidl(
392 ctx,
393 aidlLibraryRule,
394 "aidl_library",
395 aidlSrc,
396 aidlLibraryInfo.Hdrs.ToList(),
397 buildFlags.aidlFlags,
398 )
Vinh Tran367d89d2023-04-28 11:21:25 -0400399
400 srcFiles = append(srcFiles, cppFile)
401 info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...)
402 // Use the generated headers as order only deps to ensure that they are up to date when
403 // needed.
404 // TODO: Reduce the size of the ninja file by using one order only dep for the whole rule
405 info.aidlOrderOnlyDeps = append(info.aidlOrderOnlyDeps, aidlHeaders...)
406 }
407 }
408
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700409 if aidlRule != nil {
Colin Crossf1a035e2020-11-16 17:32:30 -0800410 aidlRule.Build("aidl", "gen aidl")
Dan Willemsen1945a4b2019-06-04 17:10:41 -0700411 }
412
Vinh Tran09581952023-05-16 16:03:20 -0400413 if aidlLibraryRule != nil {
414 aidlLibraryRule.Build("aidl_library", "gen aidl_library")
415 }
416
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700417 if yaccRule_ != nil {
Colin Crossf1a035e2020-11-16 17:32:30 -0800418 yaccRule_.Build("yacc", "gen yacc")
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700419 }
420
Paul Duffin33056e82021-02-19 13:49:08 +0000421 deps = append(deps, info.protoOrderOnlyDeps...)
422 deps = append(deps, info.aidlOrderOnlyDeps...)
423 deps = append(deps, info.syspropOrderOnlyDeps...)
424
Colin Cross2a252be2017-05-01 17:37:24 -0700425 if len(rsFiles) > 0 {
426 deps = append(deps, rsGenerateCpp(ctx, rsFiles, buildFlags.rsFlags)...)
427 }
428
Paul Duffin33056e82021-02-19 13:49:08 +0000429 return srcFiles, deps, info
Colin Cross581c1892015-04-07 16:50:10 -0700430}