blob: b26b1a21367f8f930f2f4a3b537d7afebd9d4369 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -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 genrule
16
17import (
Colin Cross6f080df2016-11-04 15:32:58 -070018 "fmt"
19 "strings"
Dan Willemsen3f4539b2016-09-28 16:19:10 -070020
Colin Cross70b40592015-03-23 12:57:34 -070021 "github.com/google/blueprint"
Dan Willemsen8eded0a2017-09-13 16:07:44 -070022 "github.com/google/blueprint/bootstrap"
Colin Cross5049f022015-03-18 13:28:46 -070023
Colin Cross635c3b02016-05-18 15:37:25 -070024 "android/soong/android"
Jeff Gastonefc1b412017-03-29 17:29:06 -070025 "android/soong/shared"
26 "path/filepath"
Jeff Gaston437d23c2017-11-08 12:38:00 -080027
28 "github.com/google/blueprint/proptools"
Colin Cross5049f022015-03-18 13:28:46 -070029)
30
Colin Cross463a90e2015-06-17 14:20:06 -070031func init() {
Colin Cross54190b32017-10-09 15:34:10 -070032 android.RegisterModuleType("gensrcs", GenSrcsFactory)
33 android.RegisterModuleType("genrule", GenRuleFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070034}
35
Colin Cross5049f022015-03-18 13:28:46 -070036var (
Colin Cross635c3b02016-05-18 15:37:25 -070037 pctx = android.NewPackageContext("android/soong/genrule")
Colin Cross5049f022015-03-18 13:28:46 -070038)
39
Jeff Gastonefc1b412017-03-29 17:29:06 -070040func init() {
41 pctx.HostBinToolVariable("sboxCmd", "sbox")
42}
43
Colin Cross5049f022015-03-18 13:28:46 -070044type SourceFileGenerator interface {
Colin Cross635c3b02016-05-18 15:37:25 -070045 GeneratedSourceFiles() android.Paths
Colin Cross5ed99c62016-11-22 12:55:55 -080046 GeneratedHeaderDirs() android.Paths
Colin Cross5049f022015-03-18 13:28:46 -070047}
48
Colin Crossd350ecd2015-04-28 13:25:36 -070049type HostToolProvider interface {
Colin Cross635c3b02016-05-18 15:37:25 -070050 HostToolPath() android.OptionalPath
Colin Crossd350ecd2015-04-28 13:25:36 -070051}
Colin Cross5049f022015-03-18 13:28:46 -070052
Dan Willemsend6ba0d52017-09-13 15:46:47 -070053type hostToolDependencyTag struct {
54 blueprint.BaseDependencyTag
55}
56
57var hostToolDepTag hostToolDependencyTag
58
Colin Cross7d5136f2015-05-11 13:39:40 -070059type generatorProperties struct {
Jeff Gastonefc1b412017-03-29 17:29:06 -070060 // The command to run on one or more input files. Cmd supports substitution of a few variables
61 // (the actual substitution is implemented in GenerateAndroidBuildActions below)
62 //
63 // Available variables for substitution:
64 //
Colin Cross2296f5b2017-10-17 21:38:14 -070065 // $(location): the path to the first entry in tools or tool_files
66 // $(location <label>): the path to the tool or tool_file with name <label>
67 // $(in): one or more input files
68 // $(out): a single output file
69 // $(depfile): a file to which dependencies will be written, if the depfile property is set to true
70 // $(genDir): the sandbox directory for this tool; contains $(out)
71 // $$: a literal $
Colin Cross6f080df2016-11-04 15:32:58 -070072 //
Jeff Gastonefc1b412017-03-29 17:29:06 -070073 // All files used must be declared as inputs (to ensure proper up-to-date checks).
74 // Use "$(in)" directly in Cmd to ensure that all inputs used are declared.
Colin Cross7d5136f2015-05-11 13:39:40 -070075 Cmd string
76
Colin Cross33bfb0a2016-11-21 17:23:08 -080077 // Enable reading a file containing dependencies in gcc format after the command completes
78 Depfile bool
79
Colin Cross6f080df2016-11-04 15:32:58 -070080 // name of the modules (if any) that produces the host executable. Leave empty for
Colin Cross7d5136f2015-05-11 13:39:40 -070081 // prebuilts or scripts that do not need a module to build them.
Colin Cross6f080df2016-11-04 15:32:58 -070082 Tools []string
Dan Willemsenf7f3d692016-04-20 14:54:32 -070083
84 // Local file that is used as the tool
Colin Cross6f080df2016-11-04 15:32:58 -070085 Tool_files []string
Colin Cross5ed99c62016-11-22 12:55:55 -080086
87 // List of directories to export generated headers from
88 Export_include_dirs []string
Colin Cross708c4242017-01-13 18:05:49 -080089
90 // list of input files
91 Srcs []string
Colin Cross7d5136f2015-05-11 13:39:40 -070092}
93
Dan Willemsen3e5bdf22017-09-13 18:37:08 -070094type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -070095 android.ModuleBase
Colin Crossd350ecd2015-04-28 13:25:36 -070096
Dan Willemsen3e5bdf22017-09-13 18:37:08 -070097 // For other packages to make their own genrules with extra
98 // properties
99 Extra interface{}
100
Colin Cross7d5136f2015-05-11 13:39:40 -0700101 properties generatorProperties
Colin Crossd350ecd2015-04-28 13:25:36 -0700102
Jeff Gaston437d23c2017-11-08 12:38:00 -0800103 taskGenerator taskFunc
Colin Crossd350ecd2015-04-28 13:25:36 -0700104
Colin Cross635c3b02016-05-18 15:37:25 -0700105 deps android.Paths
Colin Crossd350ecd2015-04-28 13:25:36 -0700106 rule blueprint.Rule
107
Colin Cross5ed99c62016-11-22 12:55:55 -0800108 exportedIncludeDirs android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700109
Colin Cross635c3b02016-05-18 15:37:25 -0700110 outputFiles android.Paths
Colin Crossd350ecd2015-04-28 13:25:36 -0700111}
112
Jeff Gaston437d23c2017-11-08 12:38:00 -0800113type taskFunc func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask
Colin Crossd350ecd2015-04-28 13:25:36 -0700114
115type generateTask struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700116 in android.Paths
Dan Willemsen9c8681f2016-09-28 16:21:00 -0700117 out android.WritablePaths
Jeff Gaston437d23c2017-11-08 12:38:00 -0800118 cmd string
Colin Crossd350ecd2015-04-28 13:25:36 -0700119}
120
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700121func (g *Module) GeneratedSourceFiles() android.Paths {
Colin Crossd350ecd2015-04-28 13:25:36 -0700122 return g.outputFiles
123}
124
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700125func (g *Module) Srcs() android.Paths {
Colin Cross068e0fe2016-12-13 15:23:47 -0800126 return g.outputFiles
127}
128
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700129func (g *Module) GeneratedHeaderDirs() android.Paths {
Colin Cross5ed99c62016-11-22 12:55:55 -0800130 return g.exportedIncludeDirs
Dan Willemsenb40aab62016-04-20 14:21:14 -0700131}
132
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700133func (g *Module) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross708c4242017-01-13 18:05:49 -0800134 android.ExtractSourcesDeps(ctx, g.properties.Srcs)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700135 if g, ok := ctx.Module().(*Module); ok {
Colin Cross6f080df2016-11-04 15:32:58 -0700136 if len(g.properties.Tools) > 0 {
Dan Willemsen490fd492015-11-24 17:53:15 -0800137 ctx.AddFarVariationDependencies([]blueprint.Variation{
Colin Crossa1ad8d12016-06-01 17:09:44 -0700138 {"arch", ctx.AConfig().BuildOsVariant},
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700139 }, hostToolDepTag, g.properties.Tools...)
Colin Cross6362e272015-10-29 15:25:03 -0700140 }
Colin Crossd350ecd2015-04-28 13:25:36 -0700141 }
Colin Crossd350ecd2015-04-28 13:25:36 -0700142}
143
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700144func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6f080df2016-11-04 15:32:58 -0700145 if len(g.properties.Tools) == 0 && len(g.properties.Tool_files) == 0 {
146 ctx.ModuleErrorf("at least one `tools` or `tool_files` is required")
Dan Willemsenf7f3d692016-04-20 14:54:32 -0700147 return
148 }
149
Colin Cross5ed99c62016-11-22 12:55:55 -0800150 if len(g.properties.Export_include_dirs) > 0 {
151 for _, dir := range g.properties.Export_include_dirs {
152 g.exportedIncludeDirs = append(g.exportedIncludeDirs,
153 android.PathForModuleGen(ctx, ctx.ModuleDir(), dir))
154 }
155 } else {
156 g.exportedIncludeDirs = append(g.exportedIncludeDirs, android.PathForModuleGen(ctx, ""))
157 }
Dan Willemsen3f4539b2016-09-28 16:19:10 -0700158
Colin Cross6f080df2016-11-04 15:32:58 -0700159 tools := map[string]android.Path{}
Dan Willemsen3f4539b2016-09-28 16:19:10 -0700160
Colin Cross6f080df2016-11-04 15:32:58 -0700161 if len(g.properties.Tools) > 0 {
Colin Crossd11fcda2017-10-23 17:59:01 -0700162 ctx.VisitDirectDeps(func(module android.Module) {
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700163 switch ctx.OtherModuleDependencyTag(module) {
164 case android.SourceDepTag:
165 // Nothing to do
166 case hostToolDepTag:
167 tool := ctx.OtherModuleName(module)
Dan Willemsen8eded0a2017-09-13 16:07:44 -0700168 var path android.OptionalPath
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700169
170 if t, ok := module.(HostToolProvider); ok {
Dan Willemsen8eded0a2017-09-13 16:07:44 -0700171 path = t.HostToolPath()
172 } else if t, ok := module.(bootstrap.GoBinaryTool); ok {
173 if s, err := filepath.Rel(android.PathForOutput(ctx).String(), t.InstallPath()); err == nil {
174 path = android.OptionalPathForPath(android.PathForOutput(ctx, s))
Colin Cross6f080df2016-11-04 15:32:58 -0700175 } else {
Dan Willemsen8eded0a2017-09-13 16:07:44 -0700176 ctx.ModuleErrorf("cannot find path for %q: %v", tool, err)
177 break
Colin Cross6f080df2016-11-04 15:32:58 -0700178 }
Dan Willemsenf7f3d692016-04-20 14:54:32 -0700179 } else {
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700180 ctx.ModuleErrorf("%q is not a host tool provider", tool)
Dan Willemsen8eded0a2017-09-13 16:07:44 -0700181 break
182 }
183
184 if path.Valid() {
185 g.deps = append(g.deps, path.Path())
186 if _, exists := tools[tool]; !exists {
187 tools[tool] = path.Path()
188 } else {
189 ctx.ModuleErrorf("multiple tools for %q, %q and %q", tool, tools[tool], path.Path().String())
190 }
191 } else {
192 ctx.ModuleErrorf("host tool %q missing output file", tool)
Dan Willemsenf7f3d692016-04-20 14:54:32 -0700193 }
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700194 default:
195 ctx.ModuleErrorf("unknown dependency on %q", ctx.OtherModuleName(module))
Colin Crossd350ecd2015-04-28 13:25:36 -0700196 }
Dan Willemsenf7f3d692016-04-20 14:54:32 -0700197 })
198 }
Colin Crossd350ecd2015-04-28 13:25:36 -0700199
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700200 if ctx.Failed() {
201 return
202 }
203
Colin Cross6f080df2016-11-04 15:32:58 -0700204 for _, tool := range g.properties.Tool_files {
205 toolPath := android.PathForModuleSrc(ctx, tool)
206 g.deps = append(g.deps, toolPath)
207 if _, exists := tools[tool]; !exists {
208 tools[tool] = toolPath
209 } else {
210 ctx.ModuleErrorf("multiple tools for %q, %q and %q", tool, tools[tool], toolPath.String())
211 }
212 }
213
Jeff Gaston02a684b2017-10-27 14:59:27 -0700214 referencedDepfile := false
215
Jeff Gaston437d23c2017-11-08 12:38:00 -0800216 srcFiles := ctx.ExpandSources(g.properties.Srcs, nil)
217 task := g.taskGenerator(ctx, g.properties.Cmd, srcFiles)
Jeff Gaston5acec2b2017-11-06 14:15:16 -0800218
Jeff Gaston437d23c2017-11-08 12:38:00 -0800219 rawCommand, err := android.Expand(task.cmd, func(name string) (string, error) {
Colin Cross6f080df2016-11-04 15:32:58 -0700220 switch name {
221 case "location":
222 if len(g.properties.Tools) > 0 {
223 return tools[g.properties.Tools[0]].String(), nil
224 } else {
225 return tools[g.properties.Tool_files[0]].String(), nil
226 }
227 case "in":
228 return "${in}", nil
229 case "out":
Jeff Gastonefc1b412017-03-29 17:29:06 -0700230 return "__SBOX_OUT_FILES__", nil
Colin Cross33bfb0a2016-11-21 17:23:08 -0800231 case "depfile":
Jeff Gaston02a684b2017-10-27 14:59:27 -0700232 referencedDepfile = true
Colin Cross33bfb0a2016-11-21 17:23:08 -0800233 if !g.properties.Depfile {
234 return "", fmt.Errorf("$(depfile) used without depfile property")
235 }
Jeff Gaston02a684b2017-10-27 14:59:27 -0700236 return "__SBOX_DEPFILE__", nil
Colin Cross6f080df2016-11-04 15:32:58 -0700237 case "genDir":
Jeff Gaston5acec2b2017-11-06 14:15:16 -0800238 return "__SBOX_OUT_DIR__", nil
Colin Cross6f080df2016-11-04 15:32:58 -0700239 default:
240 if strings.HasPrefix(name, "location ") {
241 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
242 if tool, ok := tools[label]; ok {
243 return tool.String(), nil
244 } else {
245 return "", fmt.Errorf("unknown location label %q", label)
246 }
247 }
248 return "", fmt.Errorf("unknown variable '$(%s)'", name)
249 }
250 })
251
Jeff Gaston02a684b2017-10-27 14:59:27 -0700252 if g.properties.Depfile && !referencedDepfile {
253 ctx.PropertyErrorf("cmd", "specified depfile=true but did not include a reference to '${depfile}' in cmd")
254 }
255
Colin Cross6f080df2016-11-04 15:32:58 -0700256 if err != nil {
257 ctx.PropertyErrorf("cmd", "%s", err.Error())
Colin Cross54c5dd52017-04-19 14:23:26 -0700258 return
Colin Cross6f080df2016-11-04 15:32:58 -0700259 }
260
Jeff Gastonefc1b412017-03-29 17:29:06 -0700261 // tell the sbox command which directory to use as its sandbox root
Jeff Gaston193f2fb2017-06-12 15:00:12 -0700262 buildDir := android.PathForOutput(ctx).String()
263 sandboxPath := shared.TempDirForOutDir(buildDir)
Jeff Gastonefc1b412017-03-29 17:29:06 -0700264
265 // recall that Sprintf replaces percent sign expressions, whereas dollar signs expressions remain as written,
266 // to be replaced later by ninja_strings.go
Jeff Gaston02a684b2017-10-27 14:59:27 -0700267 depfilePlaceholder := ""
268 if g.properties.Depfile {
269 depfilePlaceholder = "$depfileArgs"
270 }
Jeff Gaston5acec2b2017-11-06 14:15:16 -0800271
Jeff Gaston437d23c2017-11-08 12:38:00 -0800272 genDir := android.PathForModuleGen(ctx)
273 sandboxCommand := fmt.Sprintf("$sboxCmd --sandbox-path %s --output-root %s -c %q %s $allouts", sandboxPath, genDir, rawCommand, depfilePlaceholder)
Jeff Gastonefc1b412017-03-29 17:29:06 -0700274
Colin Cross33bfb0a2016-11-21 17:23:08 -0800275 ruleParams := blueprint.RuleParams{
Jeff Gastonefc1b412017-03-29 17:29:06 -0700276 Command: sandboxCommand,
277 CommandDeps: []string{"$sboxCmd"},
Colin Cross33bfb0a2016-11-21 17:23:08 -0800278 }
Colin Cross15e86d92017-10-20 15:07:08 -0700279 args := []string{"allouts"}
Colin Cross33bfb0a2016-11-21 17:23:08 -0800280 if g.properties.Depfile {
281 ruleParams.Deps = blueprint.DepsGCC
Jeff Gaston02a684b2017-10-27 14:59:27 -0700282 args = append(args, "depfileArgs")
Colin Cross33bfb0a2016-11-21 17:23:08 -0800283 }
284 g.rule = ctx.Rule(pctx, "generator", ruleParams, args...)
Colin Cross6f080df2016-11-04 15:32:58 -0700285
Jeff Gaston437d23c2017-11-08 12:38:00 -0800286 g.generateSourceFile(ctx, task)
287
Colin Crossd350ecd2015-04-28 13:25:36 -0700288}
289
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700290func (g *Module) generateSourceFile(ctx android.ModuleContext, task generateTask) {
Colin Cross67a5c132017-05-09 13:45:28 -0700291 desc := "generate"
Colin Cross15e86d92017-10-20 15:07:08 -0700292 if len(task.out) == 0 {
293 ctx.ModuleErrorf("must have at least one output file")
294 return
295 }
Colin Cross67a5c132017-05-09 13:45:28 -0700296 if len(task.out) == 1 {
297 desc += " " + task.out[0].Base()
298 }
299
Jeff Gaston02a684b2017-10-27 14:59:27 -0700300 var depFile android.ModuleGenPath
301 if g.properties.Depfile {
302 depFile = android.PathForModuleGen(ctx, task.out[0].Rel()+".d")
303 }
304
Colin Crossae887032017-10-23 17:16:14 -0700305 params := android.BuildParams{
Colin Cross15e86d92017-10-20 15:07:08 -0700306 Rule: g.rule,
307 Description: "generate",
308 Output: task.out[0],
309 ImplicitOutputs: task.out[1:],
310 Inputs: task.in,
311 Implicits: g.deps,
312 Args: map[string]string{
313 "allouts": strings.Join(task.out.Strings(), " "),
314 },
Colin Cross33bfb0a2016-11-21 17:23:08 -0800315 }
316 if g.properties.Depfile {
Jeff Gaston02a684b2017-10-27 14:59:27 -0700317 params.Depfile = android.PathForModuleGen(ctx, task.out[0].Rel()+".d")
318 params.Args["depfileArgs"] = "--depfile-out " + depFile.String()
Colin Cross33bfb0a2016-11-21 17:23:08 -0800319 }
Jeff Gaston02a684b2017-10-27 14:59:27 -0700320
Colin Crossae887032017-10-23 17:16:14 -0700321 ctx.Build(pctx, params)
Colin Crossd350ecd2015-04-28 13:25:36 -0700322
Dan Willemsen9c8681f2016-09-28 16:21:00 -0700323 for _, outputFile := range task.out {
324 g.outputFiles = append(g.outputFiles, outputFile)
325 }
Colin Crossd350ecd2015-04-28 13:25:36 -0700326}
327
Jeff Gaston437d23c2017-11-08 12:38:00 -0800328func generatorFactory(taskGenerator taskFunc, props ...interface{}) *Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700329 module := &Module{
Jeff Gaston437d23c2017-11-08 12:38:00 -0800330 taskGenerator: taskGenerator,
Colin Crossd350ecd2015-04-28 13:25:36 -0700331 }
332
Colin Cross36242852017-06-23 15:06:31 -0700333 module.AddProperties(props...)
334 module.AddProperties(&module.properties)
Colin Crossd350ecd2015-04-28 13:25:36 -0700335
Colin Cross36242852017-06-23 15:06:31 -0700336 return module
Colin Crossd350ecd2015-04-28 13:25:36 -0700337}
338
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700339func NewGenSrcs() *Module {
Colin Crossd350ecd2015-04-28 13:25:36 -0700340 properties := &genSrcsProperties{}
341
Jeff Gaston437d23c2017-11-08 12:38:00 -0800342 taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask {
343 commands := []string{}
344 outFiles := android.WritablePaths{}
345 genPath := android.PathForModuleGen(ctx).String()
Colin Crossd350ecd2015-04-28 13:25:36 -0700346 for _, in := range srcFiles {
Jeff Gaston437d23c2017-11-08 12:38:00 -0800347 outFile := android.GenPathWithExt(ctx, "", in, properties.Output_extension)
348 outFiles = append(outFiles, outFile)
349
350 // replace "out" with "__SBOX_OUT_DIR__/<the value of ${out}>"
351 relOut, err := filepath.Rel(genPath, outFile.String())
352 if err != nil {
353 panic(fmt.Sprintf("Could not make ${out} relative: %v", err))
354 }
355 sandboxOutfile := filepath.Join("__SBOX_OUT_DIR__", relOut)
356 command, err := android.Expand(rawCommand, func(name string) (string, error) {
357 switch name {
358 case "in":
359 return in.String(), nil
360 case "out":
361 return sandboxOutfile, nil
362 default:
363 return "$(" + name + ")", nil
364 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700365 })
Jeff Gaston437d23c2017-11-08 12:38:00 -0800366 if err != nil {
367 ctx.PropertyErrorf("cmd", err.Error())
368 }
369
370 // escape the command in case for example it contains '#', an odd number of '"', etc
371 command = fmt.Sprintf("bash -c %v", proptools.ShellEscape([]string{command})[0])
372 commands = append(commands, command)
Colin Crossd350ecd2015-04-28 13:25:36 -0700373 }
Jeff Gaston437d23c2017-11-08 12:38:00 -0800374 fullCommand := strings.Join(commands, " && ")
375
376 return generateTask{
377 in: srcFiles,
378 out: outFiles,
379 cmd: fullCommand,
380 }
Colin Crossd350ecd2015-04-28 13:25:36 -0700381 }
382
Jeff Gaston437d23c2017-11-08 12:38:00 -0800383 return generatorFactory(taskGenerator, properties)
Colin Crossd350ecd2015-04-28 13:25:36 -0700384}
385
Colin Cross54190b32017-10-09 15:34:10 -0700386func GenSrcsFactory() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700387 m := NewGenSrcs()
388 android.InitAndroidModule(m)
389 return m
390}
391
Colin Crossd350ecd2015-04-28 13:25:36 -0700392type genSrcsProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700393 // extension that will be substituted for each output file
Colin Cross5049f022015-03-18 13:28:46 -0700394 Output_extension string
395}
396
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700397func NewGenRule() *Module {
Colin Crossd350ecd2015-04-28 13:25:36 -0700398 properties := &genRuleProperties{}
Colin Cross5049f022015-03-18 13:28:46 -0700399
Jeff Gaston437d23c2017-11-08 12:38:00 -0800400 taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask {
Dan Willemsen9c8681f2016-09-28 16:21:00 -0700401 outs := make(android.WritablePaths, len(properties.Out))
402 for i, out := range properties.Out {
403 outs[i] = android.PathForModuleGen(ctx, out)
404 }
Jeff Gaston437d23c2017-11-08 12:38:00 -0800405 return generateTask{
406 in: srcFiles,
407 out: outs,
408 cmd: rawCommand,
Colin Crossd350ecd2015-04-28 13:25:36 -0700409 }
Colin Cross5049f022015-03-18 13:28:46 -0700410 }
Colin Crossd350ecd2015-04-28 13:25:36 -0700411
Jeff Gaston437d23c2017-11-08 12:38:00 -0800412 return generatorFactory(taskGenerator, properties)
Colin Cross5049f022015-03-18 13:28:46 -0700413}
414
Colin Cross54190b32017-10-09 15:34:10 -0700415func GenRuleFactory() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700416 m := NewGenRule()
417 android.InitAndroidModule(m)
418 return m
419}
420
Colin Crossd350ecd2015-04-28 13:25:36 -0700421type genRuleProperties struct {
Dan Willemsen9c8681f2016-09-28 16:21:00 -0700422 // names of the output files that will be generated
423 Out []string
Colin Cross5049f022015-03-18 13:28:46 -0700424}