| 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" | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 22 | "github.com/google/blueprint" | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 23 |  | 
| Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 24 | "android/soong/android" | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 25 | ) | 
|  | 26 |  | 
|  | 27 | func init() { | 
| David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 28 | pctx.SourcePathVariable("lexCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/flex") | 
| Dan Willemsen | 613564e | 2020-07-23 21:37:35 +0000 | [diff] [blame] | 29 | pctx.SourcePathVariable("m4Cmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/m4") | 
|  | 30 |  | 
| Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 31 | pctx.HostBinToolVariable("aidlCmd", "aidl-cpp") | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 32 | pctx.HostBinToolVariable("syspropCmd", "sysprop_cpp") | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 33 | } | 
|  | 34 |  | 
|  | 35 | var ( | 
| David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 36 | lex = pctx.AndroidStaticRule("lex", | 
|  | 37 | blueprint.RuleParams{ | 
| Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 38 | Command:     "M4=$m4Cmd $lexCmd $flags -o$out $in", | 
| David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 39 | CommandDeps: []string{"$lexCmd", "$m4Cmd"}, | 
| Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 40 | }, "flags") | 
| David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 41 |  | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 42 | sysprop = pctx.AndroidStaticRule("sysprop", | 
|  | 43 | blueprint.RuleParams{ | 
| Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 44 | Command: "$syspropCmd --header-dir=$headerOutDir --public-header-dir=$publicOutDir " + | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 45 | "--source-dir=$srcOutDir --include-name=$includeName $in", | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 46 | CommandDeps: []string{"$syspropCmd"}, | 
|  | 47 | }, | 
| Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 48 | "headerOutDir", "publicOutDir", "srcOutDir", "includeName") | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 49 | ) | 
|  | 50 |  | 
| Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 51 | type YaccProperties struct { | 
|  | 52 | // list of module-specific flags that will be used for .y and .yy compiles | 
|  | 53 | Flags []string | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 54 |  | 
| Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 55 | // whether the yacc files will produce a location.hh file | 
|  | 56 | Gen_location_hh *bool | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 57 |  | 
| Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 58 | // whether the yacc files will product a position.hh file | 
|  | 59 | Gen_position_hh *bool | 
|  | 60 | } | 
|  | 61 |  | 
|  | 62 | func genYacc(ctx android.ModuleContext, rule *android.RuleBuilder, yaccFile android.Path, | 
| David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 63 | outFile android.ModuleGenPath, props *YaccProperties) (headerFiles android.Paths) { | 
| Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 64 |  | 
|  | 65 | outDir := android.PathForModuleGen(ctx, "yacc") | 
|  | 66 | headerFile := android.GenPathWithExt(ctx, "yacc", yaccFile, "h") | 
|  | 67 | ret := android.Paths{headerFile} | 
|  | 68 |  | 
|  | 69 | cmd := rule.Command() | 
|  | 70 |  | 
|  | 71 | // Fix up #line markers to not use the sbox temporary directory | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 72 | // android.sboxPathForOutput(outDir, outDir) returns the sbox placeholder for the out | 
| Colin Cross | 3d68051 | 2020-11-13 16:23:53 -0800 | [diff] [blame] | 73 | // directory itself, without any filename appended. | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 74 | sboxOutDir := cmd.PathForOutput(outDir) | 
| Colin Cross | 3d68051 | 2020-11-13 16:23:53 -0800 | [diff] [blame] | 75 | sedCmd := "sed -i.bak 's#" + sboxOutDir + "#" + outDir.String() + "#'" | 
| Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 76 | rule.Command().Text(sedCmd).Input(outFile) | 
|  | 77 | rule.Command().Text(sedCmd).Input(headerFile) | 
|  | 78 |  | 
|  | 79 | var flags []string | 
|  | 80 | if props != nil { | 
|  | 81 | flags = props.Flags | 
|  | 82 |  | 
|  | 83 | if Bool(props.Gen_location_hh) { | 
|  | 84 | locationHeader := outFile.InSameDir(ctx, "location.hh") | 
|  | 85 | ret = append(ret, locationHeader) | 
|  | 86 | cmd.ImplicitOutput(locationHeader) | 
|  | 87 | rule.Command().Text(sedCmd).Input(locationHeader) | 
|  | 88 | } | 
|  | 89 | if Bool(props.Gen_position_hh) { | 
|  | 90 | positionHeader := outFile.InSameDir(ctx, "position.hh") | 
|  | 91 | ret = append(ret, positionHeader) | 
|  | 92 | cmd.ImplicitOutput(positionHeader) | 
|  | 93 | rule.Command().Text(sedCmd).Input(positionHeader) | 
|  | 94 | } | 
|  | 95 | } | 
|  | 96 |  | 
| David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 97 | cmd.Text("BISON_PKGDATADIR=prebuilts/build-tools/common/bison"). | 
|  | 98 | FlagWithInput("M4=", ctx.Config().PrebuiltBuildTool(ctx, "m4")). | 
|  | 99 | PrebuiltBuildTool(ctx, "bison"). | 
| Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 100 | Flag("-d"). | 
|  | 101 | Flags(flags). | 
|  | 102 | FlagWithOutput("--defines=", headerFile). | 
|  | 103 | Flag("-o").Output(outFile).Input(yaccFile) | 
|  | 104 |  | 
|  | 105 | return ret | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 106 | } | 
|  | 107 |  | 
| Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 108 | func genAidl( | 
|  | 109 | ctx android.ModuleContext, | 
|  | 110 | rule *android.RuleBuilder, | 
|  | 111 | outDirBase string, | 
|  | 112 | aidlFile android.Path, | 
|  | 113 | aidlHdrs android.Paths, | 
|  | 114 | aidlFlags string, | 
|  | 115 | ) (cppFile android.OutputPath, headerFiles android.Paths) { | 
| Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 116 | aidlPackage := strings.TrimSuffix(aidlFile.Rel(), aidlFile.Base()) | 
|  | 117 | baseName := strings.TrimSuffix(aidlFile.Base(), aidlFile.Ext()) | 
| Daniel Norman | 10b7435 | 2019-09-24 17:39:58 -0700 | [diff] [blame] | 118 | shortName := baseName | 
|  | 119 | // TODO(b/111362593): aidl_to_cpp_common.cpp uses heuristics to figure out if | 
|  | 120 | //   an interface name has a leading I. Those same heuristics have been | 
|  | 121 | //   moved here. | 
|  | 122 | if len(baseName) >= 2 && baseName[0] == 'I' && | 
|  | 123 | strings.ToUpper(baseName)[1] == baseName[1] { | 
|  | 124 | shortName = strings.TrimPrefix(baseName, "I") | 
|  | 125 | } | 
| Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 126 |  | 
| Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 127 | outDir := android.PathForModuleGen(ctx, outDirBase) | 
| Jiyong Park | c7e592c | 2021-04-07 21:49:34 +0900 | [diff] [blame] | 128 | cppFile = outDir.Join(ctx, aidlPackage, baseName+".cpp") | 
|  | 129 | depFile := outDir.Join(ctx, aidlPackage, baseName+".cpp.d") | 
| Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 130 | headerI := outDir.Join(ctx, aidlPackage, baseName+".h") | 
|  | 131 | headerBn := outDir.Join(ctx, aidlPackage, "Bn"+shortName+".h") | 
|  | 132 | headerBp := outDir.Join(ctx, aidlPackage, "Bp"+shortName+".h") | 
|  | 133 |  | 
|  | 134 | cmd := rule.Command() | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 135 | cmd.BuiltTool("aidl-cpp"). | 
| Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 136 | // libc++ is default stl for aidl-cpp (a cc_binary_host module) | 
|  | 137 | ImplicitTool(ctx.Config().HostCcSharedLibPath(ctx, "libc++")). | 
| Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 138 | FlagWithDepFile("-d", depFile). | 
|  | 139 | Flag("--ninja"). | 
|  | 140 | Flag(aidlFlags). | 
|  | 141 | Input(aidlFile). | 
|  | 142 | OutputDir(). | 
| Jiyong Park | c7e592c | 2021-04-07 21:49:34 +0900 | [diff] [blame] | 143 | Output(cppFile). | 
| Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 144 | ImplicitOutputs(android.WritablePaths{ | 
|  | 145 | headerI, | 
|  | 146 | headerBn, | 
|  | 147 | headerBp, | 
|  | 148 | }) | 
|  | 149 |  | 
| Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 150 | if aidlHdrs != nil { | 
|  | 151 | cmd.Implicits(aidlHdrs) | 
|  | 152 | } | 
|  | 153 |  | 
| Jiyong Park | c7e592c | 2021-04-07 21:49:34 +0900 | [diff] [blame] | 154 | return cppFile, android.Paths{ | 
| Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 155 | headerI, | 
|  | 156 | headerBn, | 
|  | 157 | headerBp, | 
|  | 158 | } | 
| Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 159 | } | 
|  | 160 |  | 
| Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 161 | type LexProperties struct { | 
|  | 162 | // list of module-specific flags that will be used for .l and .ll compiles | 
|  | 163 | Flags []string | 
|  | 164 | } | 
|  | 165 |  | 
|  | 166 | func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.ModuleGenPath, props *LexProperties) { | 
|  | 167 | var flags []string | 
|  | 168 | if props != nil { | 
|  | 169 | flags = props.Flags | 
|  | 170 | } | 
|  | 171 | flagsString := strings.Join(flags[:], " ") | 
| David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 172 | ctx.Build(pctx, android.BuildParams{ | 
|  | 173 | Rule:        lex, | 
|  | 174 | Description: "lex " + lexFile.Rel(), | 
|  | 175 | Output:      outFile, | 
|  | 176 | Input:       lexFile, | 
| Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 177 | Args:        map[string]string{"flags": flagsString}, | 
| David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 178 | }) | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 179 | } | 
|  | 180 |  | 
| Inseob Kim | ed2641f | 2020-02-19 10:42:41 +0900 | [diff] [blame] | 181 | func genSysprop(ctx android.ModuleContext, syspropFile android.Path) (android.Path, android.Paths) { | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 182 | headerFile := android.PathForModuleGen(ctx, "sysprop", "include", syspropFile.Rel()+".h") | 
| Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 183 | publicHeaderFile := android.PathForModuleGen(ctx, "sysprop/public", "include", syspropFile.Rel()+".h") | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 184 | cppFile := android.PathForModuleGen(ctx, "sysprop", syspropFile.Rel()+".cpp") | 
|  | 185 |  | 
| Inseob Kim | ed2641f | 2020-02-19 10:42:41 +0900 | [diff] [blame] | 186 | headers := android.WritablePaths{headerFile, publicHeaderFile} | 
|  | 187 |  | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 188 | ctx.Build(pctx, android.BuildParams{ | 
| Inseob Kim | ed2641f | 2020-02-19 10:42:41 +0900 | [diff] [blame] | 189 | Rule:            sysprop, | 
|  | 190 | Description:     "sysprop " + syspropFile.Rel(), | 
|  | 191 | Output:          cppFile, | 
|  | 192 | ImplicitOutputs: headers, | 
|  | 193 | Input:           syspropFile, | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 194 | Args: map[string]string{ | 
|  | 195 | "headerOutDir": filepath.Dir(headerFile.String()), | 
| Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 196 | "publicOutDir": filepath.Dir(publicHeaderFile.String()), | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 197 | "srcOutDir":    filepath.Dir(cppFile.String()), | 
|  | 198 | "includeName":  syspropFile.Rel() + ".h", | 
|  | 199 | }, | 
|  | 200 | }) | 
|  | 201 |  | 
| Inseob Kim | ed2641f | 2020-02-19 10:42:41 +0900 | [diff] [blame] | 202 | return cppFile, headers.Paths() | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 203 | } | 
|  | 204 |  | 
| Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 205 | // Used to communicate information from the genSources method back to the library code that uses | 
|  | 206 | // it. | 
|  | 207 | type generatedSourceInfo struct { | 
|  | 208 | // The headers created from .proto files | 
|  | 209 | protoHeaders android.Paths | 
|  | 210 |  | 
|  | 211 | // The files that can be used as order only dependencies in order to ensure that the proto header | 
|  | 212 | // files are up to date. | 
|  | 213 | protoOrderOnlyDeps android.Paths | 
|  | 214 |  | 
|  | 215 | // The headers created from .aidl files | 
|  | 216 | aidlHeaders android.Paths | 
|  | 217 |  | 
|  | 218 | // The files that can be used as order only dependencies in order to ensure that the aidl header | 
|  | 219 | // files are up to date. | 
|  | 220 | aidlOrderOnlyDeps android.Paths | 
|  | 221 |  | 
|  | 222 | // The headers created from .sysprop files | 
|  | 223 | syspropHeaders android.Paths | 
|  | 224 |  | 
|  | 225 | // The files that can be used as order only dependencies in order to ensure that the sysprop | 
|  | 226 | // header files are up to date. | 
|  | 227 | syspropOrderOnlyDeps android.Paths | 
| JaeMan Park | 3dba4d2 | 2024-01-05 15:29:48 +0900 | [diff] [blame] | 228 |  | 
|  | 229 | // List of generated code path. | 
|  | 230 | //   ex) '*.cpp' files generated from '*.ll / *.yy'. | 
|  | 231 | generatedSources android.Paths | 
| Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 232 | } | 
|  | 233 |  | 
| Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 234 | func genSources( | 
|  | 235 | ctx android.ModuleContext, | 
|  | 236 | aidlLibraryInfos []aidl_library.AidlLibraryInfo, | 
|  | 237 | srcFiles android.Paths, | 
| Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 238 | buildFlags builderFlags, | 
|  | 239 | ) (android.Paths, android.Paths, generatedSourceInfo) { | 
| Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 240 |  | 
|  | 241 | var info generatedSourceInfo | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 242 |  | 
| Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 243 | var deps android.Paths | 
| Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 244 | var rsFiles android.Paths | 
|  | 245 |  | 
| Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 246 | // aidlRule supports compiling aidl files from srcs prop while aidlLibraryRule supports | 
|  | 247 | // compiling aidl files from aidl_library modules specified in aidl.libs prop. | 
|  | 248 | // 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] | 249 | var aidlRule *android.RuleBuilder | 
| Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 250 | var aidlLibraryRule *android.RuleBuilder | 
| Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 251 |  | 
| Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 252 | var yaccRule_ *android.RuleBuilder | 
|  | 253 | yaccRule := func() *android.RuleBuilder { | 
|  | 254 | if yaccRule_ == nil { | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 255 | yaccRule_ = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "yacc"), | 
| Colin Cross | e16ce36 | 2020-11-12 08:29:30 -0800 | [diff] [blame] | 256 | android.PathForModuleGen(ctx, "yacc.sbox.textproto")) | 
| Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 257 | } | 
|  | 258 | return yaccRule_ | 
|  | 259 | } | 
|  | 260 |  | 
| JaeMan Park | 3dba4d2 | 2024-01-05 15:29:48 +0900 | [diff] [blame] | 261 | var generatedSources android.Paths = nil | 
|  | 262 |  | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 263 | for i, srcFile := range srcFiles { | 
| Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 264 | switch srcFile.Ext() { | 
| Dan Willemsen | f0c73e0 | 2016-03-01 15:15:26 -0800 | [diff] [blame] | 265 | case ".y": | 
| Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 266 | cFile := android.GenPathWithExt(ctx, "yacc", srcFile, "c") | 
| Dan Willemsen | f0c73e0 | 2016-03-01 15:15:26 -0800 | [diff] [blame] | 267 | srcFiles[i] = cFile | 
| David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 268 | deps = append(deps, genYacc(ctx, yaccRule(), srcFile, cFile, buildFlags.yacc)...) | 
| JaeMan Park | 3dba4d2 | 2024-01-05 15:29:48 +0900 | [diff] [blame] | 269 | generatedSources = append(generatedSources, cFile) | 
| Dan Willemsen | f0c73e0 | 2016-03-01 15:15:26 -0800 | [diff] [blame] | 270 | case ".yy": | 
| Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 271 | cppFile := android.GenPathWithExt(ctx, "yacc", srcFile, "cpp") | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 272 | srcFiles[i] = cppFile | 
| David Su | dd18efd | 2020-07-24 17:19:23 +0000 | [diff] [blame] | 273 | deps = append(deps, genYacc(ctx, yaccRule(), srcFile, cppFile, buildFlags.yacc)...) | 
| JaeMan Park | 3dba4d2 | 2024-01-05 15:29:48 +0900 | [diff] [blame] | 274 | generatedSources = append(generatedSources, cppFile) | 
| Dan Willemsen | f0c73e0 | 2016-03-01 15:15:26 -0800 | [diff] [blame] | 275 | case ".l": | 
| Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 276 | cFile := android.GenPathWithExt(ctx, "lex", srcFile, "c") | 
| Dan Willemsen | f0c73e0 | 2016-03-01 15:15:26 -0800 | [diff] [blame] | 277 | srcFiles[i] = cFile | 
| Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 278 | genLex(ctx, srcFile, cFile, buildFlags.lex) | 
| JaeMan Park | 3dba4d2 | 2024-01-05 15:29:48 +0900 | [diff] [blame] | 279 | generatedSources = append(generatedSources, cFile) | 
| Dan Willemsen | f0c73e0 | 2016-03-01 15:15:26 -0800 | [diff] [blame] | 280 | case ".ll": | 
| Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 281 | cppFile := android.GenPathWithExt(ctx, "lex", srcFile, "cpp") | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 282 | srcFiles[i] = cppFile | 
| Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 283 | genLex(ctx, srcFile, cppFile, buildFlags.lex) | 
| JaeMan Park | 3dba4d2 | 2024-01-05 15:29:48 +0900 | [diff] [blame] | 284 | generatedSources = append(generatedSources, cppFile) | 
| Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 285 | case ".proto": | 
| Dan Willemsen | 60e62f0 | 2018-11-16 21:05:32 -0800 | [diff] [blame] | 286 | ccFile, headerFile := genProto(ctx, srcFile, buildFlags) | 
| Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 287 | srcFiles[i] = ccFile | 
| Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 288 | info.protoHeaders = append(info.protoHeaders, headerFile) | 
|  | 289 | // Use the generated header as an order only dep to ensure that it is up to date when needed. | 
|  | 290 | info.protoOrderOnlyDeps = append(info.protoOrderOnlyDeps, headerFile) | 
| JaeMan Park | 3dba4d2 | 2024-01-05 15:29:48 +0900 | [diff] [blame] | 291 | generatedSources = append(generatedSources, ccFile) | 
| Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 292 | case ".aidl": | 
| Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 293 | if aidlRule == nil { | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 294 | aidlRule = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "aidl"), | 
| Colin Cross | e16ce36 | 2020-11-12 08:29:30 -0800 | [diff] [blame] | 295 | android.PathForModuleGen(ctx, "aidl.sbox.textproto")) | 
| Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 296 | } | 
| Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 297 | baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel()) | 
| Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 298 | cppFile, aidlHeaders := genAidl( | 
|  | 299 | ctx, | 
|  | 300 | aidlRule, | 
|  | 301 | "aidl", | 
|  | 302 | srcFile, | 
|  | 303 | nil, | 
|  | 304 | buildFlags.aidlFlags+" -I"+baseDir, | 
|  | 305 | ) | 
| Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 306 | srcFiles[i] = cppFile | 
| Jiyong Park | c7e592c | 2021-04-07 21:49:34 +0900 | [diff] [blame] | 307 |  | 
| Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 308 | info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...) | 
|  | 309 | // Use the generated headers as order only deps to ensure that they are up to date when | 
|  | 310 | // needed. | 
|  | 311 | // TODO: Reduce the size of the ninja file by using one order only dep for the whole rule | 
|  | 312 | info.aidlOrderOnlyDeps = append(info.aidlOrderOnlyDeps, aidlHeaders...) | 
| JaeMan Park | 3dba4d2 | 2024-01-05 15:29:48 +0900 | [diff] [blame] | 313 | generatedSources = append(generatedSources, cppFile) | 
| Jeff Vander Stoep | d612627 | 2019-07-15 19:08:37 -0700 | [diff] [blame] | 314 | case ".rscript", ".fs": | 
| Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 315 | cppFile := rsGeneratedCppFile(ctx, srcFile) | 
|  | 316 | rsFiles = append(rsFiles, srcFiles[i]) | 
|  | 317 | srcFiles[i] = cppFile | 
| JaeMan Park | 3dba4d2 | 2024-01-05 15:29:48 +0900 | [diff] [blame] | 318 | generatedSources = append(generatedSources, cppFile) | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 319 | case ".sysprop": | 
| Inseob Kim | ed2641f | 2020-02-19 10:42:41 +0900 | [diff] [blame] | 320 | cppFile, headerFiles := genSysprop(ctx, srcFile) | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 321 | srcFiles[i] = cppFile | 
| Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 322 | info.syspropHeaders = append(info.syspropHeaders, headerFiles...) | 
|  | 323 | // Use the generated headers as order only deps to ensure that they are up to date when | 
|  | 324 | // needed. | 
|  | 325 | info.syspropOrderOnlyDeps = append(info.syspropOrderOnlyDeps, headerFiles...) | 
| JaeMan Park | 3dba4d2 | 2024-01-05 15:29:48 +0900 | [diff] [blame] | 326 | generatedSources = append(generatedSources, cppFile) | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 327 | } | 
|  | 328 | } | 
|  | 329 |  | 
| JaeMan Park | 3dba4d2 | 2024-01-05 15:29:48 +0900 | [diff] [blame] | 330 | info.generatedSources = generatedSources | 
|  | 331 |  | 
| Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 332 | for _, aidlLibraryInfo := range aidlLibraryInfos { | 
| Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 333 | if aidlLibraryRule == nil { | 
|  | 334 | aidlLibraryRule = android.NewRuleBuilder(pctx, ctx).Sbox( | 
|  | 335 | android.PathForModuleGen(ctx, "aidl_library"), | 
|  | 336 | android.PathForModuleGen(ctx, "aidl_library.sbox.textproto"), | 
|  | 337 | ).SandboxInputs() | 
|  | 338 | } | 
| Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 339 | for _, aidlSrc := range aidlLibraryInfo.Srcs { | 
| Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 340 | cppFile, aidlHeaders := genAidl( | 
|  | 341 | ctx, | 
|  | 342 | aidlLibraryRule, | 
|  | 343 | "aidl_library", | 
|  | 344 | aidlSrc, | 
|  | 345 | aidlLibraryInfo.Hdrs.ToList(), | 
|  | 346 | buildFlags.aidlFlags, | 
|  | 347 | ) | 
| Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 348 |  | 
|  | 349 | srcFiles = append(srcFiles, cppFile) | 
|  | 350 | info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...) | 
|  | 351 | // Use the generated headers as order only deps to ensure that they are up to date when | 
|  | 352 | // needed. | 
|  | 353 | // TODO: Reduce the size of the ninja file by using one order only dep for the whole rule | 
|  | 354 | info.aidlOrderOnlyDeps = append(info.aidlOrderOnlyDeps, aidlHeaders...) | 
|  | 355 | } | 
|  | 356 | } | 
|  | 357 |  | 
| Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 358 | if aidlRule != nil { | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 359 | aidlRule.Build("aidl", "gen aidl") | 
| Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 360 | } | 
|  | 361 |  | 
| Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 362 | if aidlLibraryRule != nil { | 
|  | 363 | aidlLibraryRule.Build("aidl_library", "gen aidl_library") | 
|  | 364 | } | 
|  | 365 |  | 
| Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 366 | if yaccRule_ != nil { | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 367 | yaccRule_.Build("yacc", "gen yacc") | 
| Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 368 | } | 
|  | 369 |  | 
| Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 370 | deps = append(deps, info.protoOrderOnlyDeps...) | 
|  | 371 | deps = append(deps, info.aidlOrderOnlyDeps...) | 
|  | 372 | deps = append(deps, info.syspropOrderOnlyDeps...) | 
|  | 373 |  | 
| Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 374 | if len(rsFiles) > 0 { | 
|  | 375 | deps = append(deps, rsGenerateCpp(ctx, rsFiles, buildFlags.rsFlags)...) | 
|  | 376 | } | 
|  | 377 |  | 
| Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 378 | return srcFiles, deps, info | 
| Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 379 | } |