Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 17 | import ( |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 18 | "path/filepath" |
Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 19 | "strings" |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 20 | |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 21 | "android/soong/aidl_library" |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 22 | "android/soong/bazel" |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 23 | |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 24 | "github.com/google/blueprint" |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 25 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 26 | "android/soong/android" |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | func init() { |
David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 30 | pctx.SourcePathVariable("lexCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/flex") |
Dan Willemsen | 613564e | 2020-07-23 21:37:35 +0000 | [diff] [blame] | 31 | pctx.SourcePathVariable("m4Cmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/m4") |
| 32 | |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 33 | pctx.HostBinToolVariable("aidlCmd", "aidl-cpp") |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 34 | pctx.HostBinToolVariable("syspropCmd", "sysprop_cpp") |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | var ( |
David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 38 | lex = pctx.AndroidStaticRule("lex", |
| 39 | blueprint.RuleParams{ |
Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 40 | Command: "M4=$m4Cmd $lexCmd $flags -o$out $in", |
David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 41 | CommandDeps: []string{"$lexCmd", "$m4Cmd"}, |
Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 42 | }, "flags") |
David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 43 | |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 44 | sysprop = pctx.AndroidStaticRule("sysprop", |
| 45 | blueprint.RuleParams{ |
Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 46 | Command: "$syspropCmd --header-dir=$headerOutDir --public-header-dir=$publicOutDir " + |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 47 | "--source-dir=$srcOutDir --include-name=$includeName $in", |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 48 | CommandDeps: []string{"$syspropCmd"}, |
| 49 | }, |
Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 50 | "headerOutDir", "publicOutDir", "srcOutDir", "includeName") |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 51 | ) |
| 52 | |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 53 | type YaccProperties struct { |
| 54 | // list of module-specific flags that will be used for .y and .yy compiles |
| 55 | Flags []string |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 56 | |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 57 | // whether the yacc files will produce a location.hh file |
| 58 | Gen_location_hh *bool |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 59 | |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 60 | // whether the yacc files will product a position.hh file |
| 61 | Gen_position_hh *bool |
| 62 | } |
| 63 | |
| 64 | func genYacc(ctx android.ModuleContext, rule *android.RuleBuilder, yaccFile android.Path, |
David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 65 | outFile android.ModuleGenPath, props *YaccProperties) (headerFiles android.Paths) { |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 66 | |
| 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 Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 74 | // android.sboxPathForOutput(outDir, outDir) returns the sbox placeholder for the out |
Colin Cross | 3d68051 | 2020-11-13 16:23:53 -0800 | [diff] [blame] | 75 | // directory itself, without any filename appended. |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 76 | sboxOutDir := cmd.PathForOutput(outDir) |
Colin Cross | 3d68051 | 2020-11-13 16:23:53 -0800 | [diff] [blame] | 77 | sedCmd := "sed -i.bak 's#" + sboxOutDir + "#" + outDir.String() + "#'" |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 78 | 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 Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 99 | cmd.Text("BISON_PKGDATADIR=prebuilts/build-tools/common/bison"). |
| 100 | FlagWithInput("M4=", ctx.Config().PrebuiltBuildTool(ctx, "m4")). |
| 101 | PrebuiltBuildTool(ctx, "bison"). |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 102 | Flag("-d"). |
| 103 | Flags(flags). |
| 104 | FlagWithOutput("--defines=", headerFile). |
| 105 | Flag("-o").Output(outFile).Input(yaccFile) |
| 106 | |
| 107 | return ret |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 110 | func 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 Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 118 | aidlPackage := strings.TrimSuffix(aidlFile.Rel(), aidlFile.Base()) |
| 119 | baseName := strings.TrimSuffix(aidlFile.Base(), aidlFile.Ext()) |
Daniel Norman | 10b7435 | 2019-09-24 17:39:58 -0700 | [diff] [blame] | 120 | 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 Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 128 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 129 | outDir := android.PathForModuleGen(ctx, outDirBase) |
Jiyong Park | c7e592c | 2021-04-07 21:49:34 +0900 | [diff] [blame] | 130 | cppFile = outDir.Join(ctx, aidlPackage, baseName+".cpp") |
| 131 | depFile := outDir.Join(ctx, aidlPackage, baseName+".cpp.d") |
Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 132 | 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 Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 137 | cmd.BuiltTool("aidl-cpp"). |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 138 | // libc++ is default stl for aidl-cpp (a cc_binary_host module) |
| 139 | ImplicitTool(ctx.Config().HostCcSharedLibPath(ctx, "libc++")). |
Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 140 | FlagWithDepFile("-d", depFile). |
| 141 | Flag("--ninja"). |
| 142 | Flag(aidlFlags). |
| 143 | Input(aidlFile). |
| 144 | OutputDir(). |
Jiyong Park | c7e592c | 2021-04-07 21:49:34 +0900 | [diff] [blame] | 145 | Output(cppFile). |
Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 146 | ImplicitOutputs(android.WritablePaths{ |
| 147 | headerI, |
| 148 | headerBn, |
| 149 | headerBp, |
| 150 | }) |
| 151 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 152 | if aidlHdrs != nil { |
| 153 | cmd.Implicits(aidlHdrs) |
| 154 | } |
| 155 | |
Jiyong Park | c7e592c | 2021-04-07 21:49:34 +0900 | [diff] [blame] | 156 | return cppFile, android.Paths{ |
Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 157 | headerI, |
| 158 | headerBn, |
| 159 | headerBp, |
| 160 | } |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 163 | type LexProperties struct { |
| 164 | // list of module-specific flags that will be used for .l and .ll compiles |
| 165 | Flags []string |
| 166 | } |
| 167 | |
| 168 | func 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 Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 174 | ctx.Build(pctx, android.BuildParams{ |
| 175 | Rule: lex, |
| 176 | Description: "lex " + lexFile.Rel(), |
| 177 | Output: outFile, |
| 178 | Input: lexFile, |
Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 179 | Args: map[string]string{"flags": flagsString}, |
David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 180 | }) |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 183 | type LexAttrs struct { |
| 184 | Srcs bazel.LabelListAttribute |
| 185 | Lexopts bazel.StringListAttribute |
| 186 | } |
| 187 | |
| 188 | type LexNames struct { |
| 189 | cSrcName bazel.LabelAttribute |
| 190 | srcName bazel.LabelAttribute |
| 191 | } |
| 192 | |
| 193 | func 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 | |
| 204 | func 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 Kim | ed2641f | 2020-02-19 10:42:41 +0900 | [diff] [blame] | 218 | func genSysprop(ctx android.ModuleContext, syspropFile android.Path) (android.Path, android.Paths) { |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 219 | headerFile := android.PathForModuleGen(ctx, "sysprop", "include", syspropFile.Rel()+".h") |
Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 220 | publicHeaderFile := android.PathForModuleGen(ctx, "sysprop/public", "include", syspropFile.Rel()+".h") |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 221 | cppFile := android.PathForModuleGen(ctx, "sysprop", syspropFile.Rel()+".cpp") |
| 222 | |
Inseob Kim | ed2641f | 2020-02-19 10:42:41 +0900 | [diff] [blame] | 223 | headers := android.WritablePaths{headerFile, publicHeaderFile} |
| 224 | |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 225 | ctx.Build(pctx, android.BuildParams{ |
Inseob Kim | ed2641f | 2020-02-19 10:42:41 +0900 | [diff] [blame] | 226 | Rule: sysprop, |
| 227 | Description: "sysprop " + syspropFile.Rel(), |
| 228 | Output: cppFile, |
| 229 | ImplicitOutputs: headers, |
| 230 | Input: syspropFile, |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 231 | Args: map[string]string{ |
| 232 | "headerOutDir": filepath.Dir(headerFile.String()), |
Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 233 | "publicOutDir": filepath.Dir(publicHeaderFile.String()), |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 234 | "srcOutDir": filepath.Dir(cppFile.String()), |
| 235 | "includeName": syspropFile.Rel() + ".h", |
| 236 | }, |
| 237 | }) |
| 238 | |
Inseob Kim | ed2641f | 2020-02-19 10:42:41 +0900 | [diff] [blame] | 239 | return cppFile, headers.Paths() |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 240 | } |
| 241 | |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 242 | func 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 |
| 253 | func 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 Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 270 | // Used to communicate information from the genSources method back to the library code that uses |
| 271 | // it. |
| 272 | type 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 Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 295 | func genSources( |
| 296 | ctx android.ModuleContext, |
| 297 | aidlLibraryInfos []aidl_library.AidlLibraryInfo, |
| 298 | srcFiles android.Paths, |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 299 | buildFlags builderFlags, |
| 300 | ) (android.Paths, android.Paths, generatedSourceInfo) { |
Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 301 | |
| 302 | var info generatedSourceInfo |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 303 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 304 | var deps android.Paths |
Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 305 | var rsFiles android.Paths |
| 306 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 307 | // 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 Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 310 | var aidlRule *android.RuleBuilder |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 311 | var aidlLibraryRule *android.RuleBuilder |
Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 312 | |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 313 | var yaccRule_ *android.RuleBuilder |
| 314 | yaccRule := func() *android.RuleBuilder { |
| 315 | if yaccRule_ == nil { |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 316 | yaccRule_ = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "yacc"), |
Colin Cross | e16ce36 | 2020-11-12 08:29:30 -0800 | [diff] [blame] | 317 | android.PathForModuleGen(ctx, "yacc.sbox.textproto")) |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 318 | } |
| 319 | return yaccRule_ |
| 320 | } |
| 321 | |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 322 | for i, srcFile := range srcFiles { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 323 | switch srcFile.Ext() { |
Dan Willemsen | f0c73e0 | 2016-03-01 15:15:26 -0800 | [diff] [blame] | 324 | case ".y": |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 325 | cFile := android.GenPathWithExt(ctx, "yacc", srcFile, "c") |
Dan Willemsen | f0c73e0 | 2016-03-01 15:15:26 -0800 | [diff] [blame] | 326 | srcFiles[i] = cFile |
David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 327 | deps = append(deps, genYacc(ctx, yaccRule(), srcFile, cFile, buildFlags.yacc)...) |
Dan Willemsen | f0c73e0 | 2016-03-01 15:15:26 -0800 | [diff] [blame] | 328 | case ".yy": |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 329 | cppFile := android.GenPathWithExt(ctx, "yacc", srcFile, "cpp") |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 330 | srcFiles[i] = cppFile |
David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 331 | deps = append(deps, genYacc(ctx, yaccRule(), srcFile, cppFile, buildFlags.yacc)...) |
Dan Willemsen | f0c73e0 | 2016-03-01 15:15:26 -0800 | [diff] [blame] | 332 | case ".l": |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 333 | cFile := android.GenPathWithExt(ctx, "lex", srcFile, "c") |
Dan Willemsen | f0c73e0 | 2016-03-01 15:15:26 -0800 | [diff] [blame] | 334 | srcFiles[i] = cFile |
Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 335 | genLex(ctx, srcFile, cFile, buildFlags.lex) |
Dan Willemsen | f0c73e0 | 2016-03-01 15:15:26 -0800 | [diff] [blame] | 336 | case ".ll": |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 337 | cppFile := android.GenPathWithExt(ctx, "lex", srcFile, "cpp") |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 338 | srcFiles[i] = cppFile |
Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 339 | genLex(ctx, srcFile, cppFile, buildFlags.lex) |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 340 | case ".proto": |
Dan Willemsen | 60e62f0 | 2018-11-16 21:05:32 -0800 | [diff] [blame] | 341 | ccFile, headerFile := genProto(ctx, srcFile, buildFlags) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 342 | srcFiles[i] = ccFile |
Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 343 | 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 Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 346 | case ".aidl": |
Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 347 | if aidlRule == nil { |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 348 | aidlRule = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "aidl"), |
Colin Cross | e16ce36 | 2020-11-12 08:29:30 -0800 | [diff] [blame] | 349 | android.PathForModuleGen(ctx, "aidl.sbox.textproto")) |
Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 350 | } |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 351 | baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel()) |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 352 | cppFile, aidlHeaders := genAidl( |
| 353 | ctx, |
| 354 | aidlRule, |
| 355 | "aidl", |
| 356 | srcFile, |
| 357 | nil, |
| 358 | buildFlags.aidlFlags+" -I"+baseDir, |
| 359 | ) |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 360 | srcFiles[i] = cppFile |
Jiyong Park | c7e592c | 2021-04-07 21:49:34 +0900 | [diff] [blame] | 361 | |
Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 362 | 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 Stoep | d612627 | 2019-07-15 19:08:37 -0700 | [diff] [blame] | 367 | case ".rscript", ".fs": |
Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 368 | cppFile := rsGeneratedCppFile(ctx, srcFile) |
| 369 | rsFiles = append(rsFiles, srcFiles[i]) |
| 370 | srcFiles[i] = cppFile |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 371 | case ".sysprop": |
Inseob Kim | ed2641f | 2020-02-19 10:42:41 +0900 | [diff] [blame] | 372 | cppFile, headerFiles := genSysprop(ctx, srcFile) |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 373 | srcFiles[i] = cppFile |
Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 374 | 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 Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 381 | for _, aidlLibraryInfo := range aidlLibraryInfos { |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 382 | 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 Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 388 | for _, aidlSrc := range aidlLibraryInfo.Srcs { |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 389 | cppFile, aidlHeaders := genAidl( |
| 390 | ctx, |
| 391 | aidlLibraryRule, |
| 392 | "aidl_library", |
| 393 | aidlSrc, |
| 394 | aidlLibraryInfo.Hdrs.ToList(), |
| 395 | buildFlags.aidlFlags, |
| 396 | ) |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 397 | |
| 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 Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 407 | if aidlRule != nil { |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 408 | aidlRule.Build("aidl", "gen aidl") |
Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 411 | if aidlLibraryRule != nil { |
| 412 | aidlLibraryRule.Build("aidl_library", "gen aidl_library") |
| 413 | } |
| 414 | |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 415 | if yaccRule_ != nil { |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 416 | yaccRule_.Build("yacc", "gen yacc") |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 419 | deps = append(deps, info.protoOrderOnlyDeps...) |
| 420 | deps = append(deps, info.aidlOrderOnlyDeps...) |
| 421 | deps = append(deps, info.syspropOrderOnlyDeps...) |
| 422 | |
Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 423 | if len(rsFiles) > 0 { |
| 424 | deps = append(deps, rsGenerateCpp(ctx, rsFiles, buildFlags.rsFlags)...) |
| 425 | } |
| 426 | |
Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 427 | return srcFiles, deps, info |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 428 | } |