blob: 1d1d96c0194231e1b203d19a12f284f1b048e33b [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
Alex Humesky29e3bbe2020-11-20 21:30:13 -050015// A genrule module takes a list of source files ("srcs" property), an optional
16// list of tools ("tools" property), and a command line ("cmd" property), to
17// generate output files ("out" property).
18
Colin Cross5049f022015-03-18 13:28:46 -070019package genrule
20
21import (
Colin Cross6f080df2016-11-04 15:32:58 -070022 "fmt"
Colin Crossa4ad2b02019-03-18 22:15:32 -070023 "io"
Colin Cross3d680512020-11-13 16:23:53 -080024 "path/filepath"
Colin Cross1a527682019-09-23 15:55:30 -070025 "strconv"
Colin Cross6f080df2016-11-04 15:32:58 -070026 "strings"
Dan Willemsen3f4539b2016-09-28 16:19:10 -070027
Colin Cross70b40592015-03-23 12:57:34 -070028 "github.com/google/blueprint"
Dan Willemsen8eded0a2017-09-13 16:07:44 -070029 "github.com/google/blueprint/bootstrap"
Nan Zhangea568a42017-11-08 21:20:04 -080030 "github.com/google/blueprint/proptools"
Colin Cross5049f022015-03-18 13:28:46 -070031
Colin Cross635c3b02016-05-18 15:37:25 -070032 "android/soong/android"
Jingwen Chen30f5aaa2020-11-19 05:38:02 -050033 "android/soong/bazel"
Colin Cross5049f022015-03-18 13:28:46 -070034)
35
Colin Cross463a90e2015-06-17 14:20:06 -070036func init() {
Colin Crosse9fe2942020-11-10 18:12:15 -080037 RegisterGenruleBuildComponents(android.InitRegistrationContext)
Martin Stjernholm710ec3a2020-01-16 15:12:04 +000038}
Jaewoong Jung98716bd2018-12-10 08:13:18 -080039
Colin Crosse9fe2942020-11-10 18:12:15 -080040func RegisterGenruleBuildComponents(ctx android.RegistrationContext) {
Martin Stjernholm710ec3a2020-01-16 15:12:04 +000041 ctx.RegisterModuleType("genrule_defaults", defaultsFactory)
42
43 ctx.RegisterModuleType("gensrcs", GenSrcsFactory)
44 ctx.RegisterModuleType("genrule", GenRuleFactory)
45
46 ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
47 ctx.BottomUp("genrule_tool_deps", toolDepsMutator).Parallel()
48 })
Colin Cross463a90e2015-06-17 14:20:06 -070049}
50
Colin Cross5049f022015-03-18 13:28:46 -070051var (
Colin Cross635c3b02016-05-18 15:37:25 -070052 pctx = android.NewPackageContext("android/soong/genrule")
Colin Cross1a527682019-09-23 15:55:30 -070053
Alex Humesky29e3bbe2020-11-20 21:30:13 -050054 // Used by gensrcs when there is more than 1 shard to merge the outputs
55 // of each shard into a zip file.
Colin Cross1a527682019-09-23 15:55:30 -070056 gensrcsMerge = pctx.AndroidStaticRule("gensrcsMerge", blueprint.RuleParams{
57 Command: "${soongZip} -o ${tmpZip} @${tmpZip}.rsp && ${zipSync} -d ${genDir} ${tmpZip}",
58 CommandDeps: []string{"${soongZip}", "${zipSync}"},
59 Rspfile: "${tmpZip}.rsp",
60 RspfileContent: "${zipArgs}",
61 }, "tmpZip", "genDir", "zipArgs")
Colin Cross5049f022015-03-18 13:28:46 -070062)
63
Jeff Gastonefc1b412017-03-29 17:29:06 -070064func init() {
Dan Willemsenddf504c2019-08-09 16:21:29 -070065 pctx.Import("android/soong/android")
Jeff Gastonefc1b412017-03-29 17:29:06 -070066 pctx.HostBinToolVariable("sboxCmd", "sbox")
Colin Cross1a527682019-09-23 15:55:30 -070067
68 pctx.HostBinToolVariable("soongZip", "soong_zip")
69 pctx.HostBinToolVariable("zipSync", "zipsync")
Jeff Gastonefc1b412017-03-29 17:29:06 -070070}
71
Colin Cross5049f022015-03-18 13:28:46 -070072type SourceFileGenerator interface {
Colin Cross635c3b02016-05-18 15:37:25 -070073 GeneratedSourceFiles() android.Paths
Colin Cross5ed99c62016-11-22 12:55:55 -080074 GeneratedHeaderDirs() android.Paths
Dan Willemsen9da9d492018-02-21 18:28:18 -080075 GeneratedDeps() android.Paths
Colin Cross5049f022015-03-18 13:28:46 -070076}
77
Colin Crossfe17f6f2019-03-28 19:30:56 -070078// Alias for android.HostToolProvider
79// Deprecated: use android.HostToolProvider instead.
Colin Crossd350ecd2015-04-28 13:25:36 -070080type HostToolProvider interface {
Colin Crossfe17f6f2019-03-28 19:30:56 -070081 android.HostToolProvider
Colin Crossd350ecd2015-04-28 13:25:36 -070082}
Colin Cross5049f022015-03-18 13:28:46 -070083
Dan Willemsend6ba0d52017-09-13 15:46:47 -070084type hostToolDependencyTag struct {
85 blueprint.BaseDependencyTag
Colin Cross08f15ab2018-10-04 23:29:14 -070086 label string
Dan Willemsend6ba0d52017-09-13 15:46:47 -070087}
Colin Cross7d5136f2015-05-11 13:39:40 -070088type generatorProperties struct {
Jeff Gastonefc1b412017-03-29 17:29:06 -070089 // The command to run on one or more input files. Cmd supports substitution of a few variables
Jeff Gastonefc1b412017-03-29 17:29:06 -070090 //
91 // Available variables for substitution:
92 //
Colin Cross2296f5b2017-10-17 21:38:14 -070093 // $(location): the path to the first entry in tools or tool_files
Colin Cross08f15ab2018-10-04 23:29:14 -070094 // $(location <label>): the path to the tool, tool_file, input or output with name <label>
Colin Cross2296f5b2017-10-17 21:38:14 -070095 // $(in): one or more input files
96 // $(out): a single output file
97 // $(depfile): a file to which dependencies will be written, if the depfile property is set to true
98 // $(genDir): the sandbox directory for this tool; contains $(out)
99 // $$: a literal $
Nan Zhangea568a42017-11-08 21:20:04 -0800100 Cmd *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700101
Colin Cross33bfb0a2016-11-21 17:23:08 -0800102 // Enable reading a file containing dependencies in gcc format after the command completes
Nan Zhangea568a42017-11-08 21:20:04 -0800103 Depfile *bool
Colin Cross33bfb0a2016-11-21 17:23:08 -0800104
Colin Cross6f080df2016-11-04 15:32:58 -0700105 // name of the modules (if any) that produces the host executable. Leave empty for
Colin Cross7d5136f2015-05-11 13:39:40 -0700106 // prebuilts or scripts that do not need a module to build them.
Colin Cross6f080df2016-11-04 15:32:58 -0700107 Tools []string
Dan Willemsenf7f3d692016-04-20 14:54:32 -0700108
109 // Local file that is used as the tool
Colin Cross27b922f2019-03-04 22:35:41 -0800110 Tool_files []string `android:"path"`
Colin Cross5ed99c62016-11-22 12:55:55 -0800111
112 // List of directories to export generated headers from
113 Export_include_dirs []string
Colin Cross708c4242017-01-13 18:05:49 -0800114
115 // list of input files
Colin Cross27b922f2019-03-04 22:35:41 -0800116 Srcs []string `android:"path,arch_variant"`
Dan Willemseneefa0262018-11-17 14:01:18 -0800117
118 // input files to exclude
Colin Cross27b922f2019-03-04 22:35:41 -0800119 Exclude_srcs []string `android:"path,arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700120
Jingwen Chen30f5aaa2020-11-19 05:38:02 -0500121 // Properties for Bazel migration purposes.
122 bazel.Properties
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400123}
Alex Humesky29e3bbe2020-11-20 21:30:13 -0500124
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700125type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700126 android.ModuleBase
Jaewoong Jung98716bd2018-12-10 08:13:18 -0800127 android.DefaultableModuleBase
Jiyong Parkfc752ca2019-06-12 13:27:29 +0900128 android.ApexModuleBase
Colin Crossd350ecd2015-04-28 13:25:36 -0700129
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700130 // For other packages to make their own genrules with extra
131 // properties
132 Extra interface{}
Colin Cross7228ecd2019-11-18 16:00:16 -0800133 android.ImageInterface
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700134
Colin Cross7d5136f2015-05-11 13:39:40 -0700135 properties generatorProperties
Colin Crossd350ecd2015-04-28 13:25:36 -0700136
Alex Humesky29e3bbe2020-11-20 21:30:13 -0500137 // For the different tasks that genrule and gensrc generate. genrule will
138 // generate 1 task, and gensrc will generate 1 or more tasks based on the
139 // number of shards the input files are sharded into.
Jeff Gaston437d23c2017-11-08 12:38:00 -0800140 taskGenerator taskFunc
Colin Crossd350ecd2015-04-28 13:25:36 -0700141
Colin Cross1a527682019-09-23 15:55:30 -0700142 rule blueprint.Rule
143 rawCommands []string
Colin Crossd350ecd2015-04-28 13:25:36 -0700144
Colin Cross5ed99c62016-11-22 12:55:55 -0800145 exportedIncludeDirs android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700146
Colin Cross635c3b02016-05-18 15:37:25 -0700147 outputFiles android.Paths
Dan Willemsen9da9d492018-02-21 18:28:18 -0800148 outputDeps android.Paths
Colin Crossa4ad2b02019-03-18 22:15:32 -0700149
150 subName string
Colin Cross1a527682019-09-23 15:55:30 -0700151 subDir string
bralee1fbf4402020-05-21 10:11:59 +0800152
153 // Collect the module directory for IDE info in java/jdeps.go.
154 modulePaths []string
Colin Crossd350ecd2015-04-28 13:25:36 -0700155}
156
Colin Cross1a527682019-09-23 15:55:30 -0700157type taskFunc func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask
Colin Crossd350ecd2015-04-28 13:25:36 -0700158
159type generateTask struct {
Colin Cross3ea4eb82020-11-24 13:07:27 -0800160 in android.Paths
161 out android.WritablePaths
162 depFile android.WritablePath
Alex Humesky29e3bbe2020-11-20 21:30:13 -0500163 copyTo android.WritablePaths // For gensrcs to set on gensrcsMerge rule.
Colin Cross3ea4eb82020-11-24 13:07:27 -0800164 genDir android.WritablePath
165 extraTools android.Paths // dependencies on tools used by the generator
166
Alex Humesky29e3bbe2020-11-20 21:30:13 -0500167 cmd string
168 // For gensrsc sharding.
Colin Cross3ea4eb82020-11-24 13:07:27 -0800169 shard int
170 shards int
Colin Crossd350ecd2015-04-28 13:25:36 -0700171}
172
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700173func (g *Module) GeneratedSourceFiles() android.Paths {
Colin Crossd350ecd2015-04-28 13:25:36 -0700174 return g.outputFiles
175}
176
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700177func (g *Module) Srcs() android.Paths {
Nan Zhange42777a2018-03-27 16:19:42 -0700178 return append(android.Paths{}, g.outputFiles...)
Colin Cross068e0fe2016-12-13 15:23:47 -0800179}
180
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700181func (g *Module) GeneratedHeaderDirs() android.Paths {
Colin Cross5ed99c62016-11-22 12:55:55 -0800182 return g.exportedIncludeDirs
Dan Willemsenb40aab62016-04-20 14:21:14 -0700183}
184
Dan Willemsen9da9d492018-02-21 18:28:18 -0800185func (g *Module) GeneratedDeps() android.Paths {
186 return g.outputDeps
187}
188
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000189func toolDepsMutator(ctx android.BottomUpMutatorContext) {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700190 if g, ok := ctx.Module().(*Module); ok {
Colin Cross08f15ab2018-10-04 23:29:14 -0700191 for _, tool := range g.properties.Tools {
192 tag := hostToolDependencyTag{label: tool}
193 if m := android.SrcIsModule(tool); m != "" {
194 tool = m
195 }
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700196 ctx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), tag, tool)
Colin Cross6362e272015-10-29 15:25:03 -0700197 }
Colin Crossd350ecd2015-04-28 13:25:36 -0700198 }
Colin Crossd350ecd2015-04-28 13:25:36 -0700199}
200
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400201// Returns true if information was available from Bazel, false if bazel invocation still needs to occur.
202func (c *Module) generateBazelBuildActions(ctx android.ModuleContext, label string) bool {
203 bazelCtx := ctx.Config().BazelContext
204 filePaths, ok := bazelCtx.GetAllFiles(label)
205 if ok {
206 var bazelOutputFiles android.Paths
207 for _, bazelOutputFile := range filePaths {
Chris Parsonsdbcb1ff2020-12-10 17:19:18 -0500208 bazelOutputFiles = append(bazelOutputFiles, android.PathForBazelOut(ctx, bazelOutputFile))
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400209 }
210 c.outputFiles = bazelOutputFiles
211 c.outputDeps = bazelOutputFiles
212 }
213 return ok
214}
Colin Crossf1885962020-11-20 15:28:30 -0800215
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700216func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crossa4ad2b02019-03-18 22:15:32 -0700217 g.subName = ctx.ModuleSubDir()
218
bralee1fbf4402020-05-21 10:11:59 +0800219 // Collect the module directory for IDE info in java/jdeps.go.
220 g.modulePaths = append(g.modulePaths, ctx.ModuleDir())
221
Colin Cross5ed99c62016-11-22 12:55:55 -0800222 if len(g.properties.Export_include_dirs) > 0 {
223 for _, dir := range g.properties.Export_include_dirs {
224 g.exportedIncludeDirs = append(g.exportedIncludeDirs,
Colin Cross1a527682019-09-23 15:55:30 -0700225 android.PathForModuleGen(ctx, g.subDir, ctx.ModuleDir(), dir))
Colin Cross5ed99c62016-11-22 12:55:55 -0800226 }
227 } else {
Colin Cross1a527682019-09-23 15:55:30 -0700228 g.exportedIncludeDirs = append(g.exportedIncludeDirs, android.PathForModuleGen(ctx, g.subDir))
Colin Cross5ed99c62016-11-22 12:55:55 -0800229 }
Dan Willemsen3f4539b2016-09-28 16:19:10 -0700230
Colin Cross08f15ab2018-10-04 23:29:14 -0700231 locationLabels := map[string][]string{}
232 firstLabel := ""
233
234 addLocationLabel := func(label string, paths []string) {
235 if firstLabel == "" {
236 firstLabel = label
237 }
238 if _, exists := locationLabels[label]; !exists {
239 locationLabels[label] = paths
240 } else {
241 ctx.ModuleErrorf("multiple labels for %q, %q and %q",
242 label, strings.Join(locationLabels[label], " "), strings.Join(paths, " "))
243 }
244 }
Dan Willemsen3f4539b2016-09-28 16:19:10 -0700245
Colin Crossba9e4032020-11-24 16:32:22 -0800246 var tools android.Paths
247 var packagedTools []android.PackagingSpec
Colin Cross6f080df2016-11-04 15:32:58 -0700248 if len(g.properties.Tools) > 0 {
Colin Crossba71a3f2019-03-18 12:12:48 -0700249 seenTools := make(map[string]bool)
250
Colin Cross35143d02017-11-16 00:11:20 -0800251 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross08f15ab2018-10-04 23:29:14 -0700252 switch tag := ctx.OtherModuleDependencyTag(module).(type) {
253 case hostToolDependencyTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700254 tool := ctx.OtherModuleName(module)
255
Colin Crossba9e4032020-11-24 16:32:22 -0800256 switch t := module.(type) {
257 case android.HostToolProvider:
258 // A HostToolProvider provides the path to a tool, which will be copied
259 // into the sandbox.
Colin Cross35143d02017-11-16 00:11:20 -0800260 if !t.(android.Module).Enabled() {
Colin Cross6510f912017-11-29 00:27:14 -0800261 if ctx.Config().AllowMissingDependencies() {
Colin Cross35143d02017-11-16 00:11:20 -0800262 ctx.AddMissingDependencies([]string{tool})
263 } else {
264 ctx.ModuleErrorf("depends on disabled module %q", tool)
265 }
Colin Crossba9e4032020-11-24 16:32:22 -0800266 return
Colin Cross35143d02017-11-16 00:11:20 -0800267 }
Colin Crossba9e4032020-11-24 16:32:22 -0800268 path := t.HostToolPath()
269 if !path.Valid() {
270 ctx.ModuleErrorf("host tool %q missing output file", tool)
271 return
272 }
273 if specs := t.TransitivePackagingSpecs(); specs != nil {
274 // If the HostToolProvider has PackgingSpecs, which are definitions of the
275 // required relative locations of the tool and its dependencies, use those
276 // instead. They will be copied to those relative locations in the sbox
277 // sandbox.
278 packagedTools = append(packagedTools, specs...)
279 // Assume that the first PackagingSpec of the module is the tool.
280 addLocationLabel(tag.label, []string{android.SboxPathForPackagedTool(specs[0])})
281 } else {
282 tools = append(tools, path.Path())
283 addLocationLabel(tag.label, []string{android.SboxPathForTool(ctx, path.Path())})
284 }
285 case bootstrap.GoBinaryTool:
286 // A GoBinaryTool provides the install path to a tool, which will be copied.
Dan Willemsen8eded0a2017-09-13 16:07:44 -0700287 if s, err := filepath.Rel(android.PathForOutput(ctx).String(), t.InstallPath()); err == nil {
Colin Crossba9e4032020-11-24 16:32:22 -0800288 toolPath := android.PathForOutput(ctx, s)
289 tools = append(tools, toolPath)
290 addLocationLabel(tag.label, []string{android.SboxPathForTool(ctx, toolPath)})
Colin Cross6f080df2016-11-04 15:32:58 -0700291 } else {
Dan Willemsen8eded0a2017-09-13 16:07:44 -0700292 ctx.ModuleErrorf("cannot find path for %q: %v", tool, err)
Colin Crossba9e4032020-11-24 16:32:22 -0800293 return
Colin Cross6f080df2016-11-04 15:32:58 -0700294 }
Colin Crossba9e4032020-11-24 16:32:22 -0800295 default:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700296 ctx.ModuleErrorf("%q is not a host tool provider", tool)
Colin Crossba9e4032020-11-24 16:32:22 -0800297 return
Dan Willemsen8eded0a2017-09-13 16:07:44 -0700298 }
299
Colin Crossba9e4032020-11-24 16:32:22 -0800300 seenTools[tag.label] = true
Colin Crossd350ecd2015-04-28 13:25:36 -0700301 }
Dan Willemsenf7f3d692016-04-20 14:54:32 -0700302 })
Colin Crossba71a3f2019-03-18 12:12:48 -0700303
304 // If AllowMissingDependencies is enabled, the build will not have stopped when
305 // AddFarVariationDependencies was called on a missing tool, which will result in nonsensical
Liz Kammer20ebfb42020-07-28 11:32:07 -0700306 // "cmd: unknown location label ..." errors later. Add a placeholder file to the local label.
307 // The command that uses this placeholder file will never be executed because the rule will be
308 // replaced with an android.Error rule reporting the missing dependencies.
Colin Crossba71a3f2019-03-18 12:12:48 -0700309 if ctx.Config().AllowMissingDependencies() {
310 for _, tool := range g.properties.Tools {
311 if !seenTools[tool] {
312 addLocationLabel(tool, []string{"***missing tool " + tool + "***"})
313 }
314 }
315 }
Dan Willemsenf7f3d692016-04-20 14:54:32 -0700316 }
Colin Crossd350ecd2015-04-28 13:25:36 -0700317
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700318 if ctx.Failed() {
319 return
320 }
321
Colin Cross08f15ab2018-10-04 23:29:14 -0700322 for _, toolFile := range g.properties.Tool_files {
Colin Cross8a497952019-03-05 22:25:09 -0800323 paths := android.PathsForModuleSrc(ctx, []string{toolFile})
Colin Crossba9e4032020-11-24 16:32:22 -0800324 tools = append(tools, paths...)
325 var sandboxPaths []string
326 for _, path := range paths {
327 sandboxPaths = append(sandboxPaths, android.SboxPathForTool(ctx, path))
328 }
329 addLocationLabel(toolFile, sandboxPaths)
Colin Cross08f15ab2018-10-04 23:29:14 -0700330 }
331
332 var srcFiles android.Paths
333 for _, in := range g.properties.Srcs {
Colin Crossba71a3f2019-03-18 12:12:48 -0700334 paths, missingDeps := android.PathsAndMissingDepsForModuleSrcExcludes(ctx, []string{in}, g.properties.Exclude_srcs)
335 if len(missingDeps) > 0 {
336 if !ctx.Config().AllowMissingDependencies() {
337 panic(fmt.Errorf("should never get here, the missing dependencies %q should have been reported in DepsMutator",
338 missingDeps))
339 }
340
341 // If AllowMissingDependencies is enabled, the build will not have stopped when
342 // the dependency was added on a missing SourceFileProducer module, which will result in nonsensical
Liz Kammer20ebfb42020-07-28 11:32:07 -0700343 // "cmd: label ":..." has no files" errors later. Add a placeholder file to the local label.
344 // The command that uses this placeholder file will never be executed because the rule will be
345 // replaced with an android.Error rule reporting the missing dependencies.
Colin Crossba71a3f2019-03-18 12:12:48 -0700346 ctx.AddMissingDependencies(missingDeps)
347 addLocationLabel(in, []string{"***missing srcs " + in + "***"})
348 } else {
349 srcFiles = append(srcFiles, paths...)
350 addLocationLabel(in, paths.Strings())
351 }
Colin Cross08f15ab2018-10-04 23:29:14 -0700352 }
353
Colin Cross1a527682019-09-23 15:55:30 -0700354 var copyFrom android.Paths
355 var outputFiles android.WritablePaths
356 var zipArgs strings.Builder
Colin Cross08f15ab2018-10-04 23:29:14 -0700357
Alex Humesky29e3bbe2020-11-20 21:30:13 -0500358 // Generate tasks, either from genrule or gensrcs.
Colin Cross1a527682019-09-23 15:55:30 -0700359 for _, task := range g.taskGenerator(ctx, String(g.properties.Cmd), srcFiles) {
Colin Cross3d680512020-11-13 16:23:53 -0800360 if len(task.out) == 0 {
361 ctx.ModuleErrorf("must have at least one output file")
362 return
Colin Cross85a2e892018-07-09 09:45:06 -0700363 }
364
Colin Crossf1a035e2020-11-16 17:32:30 -0800365 // Pick a unique path outside the task.genDir for the sbox manifest textproto,
366 // a unique rule name, and the user-visible description.
367 manifestName := "genrule.sbox.textproto"
368 desc := "generate"
369 name := "generator"
370 if task.shards > 0 {
371 manifestName = "genrule_" + strconv.Itoa(task.shard) + ".sbox.textproto"
372 desc += " " + strconv.Itoa(task.shard)
373 name += strconv.Itoa(task.shard)
374 } else if len(task.out) == 1 {
375 desc += " " + task.out[0].Base()
376 }
377
378 manifestPath := android.PathForModuleOut(ctx, manifestName)
379
380 // Use a RuleBuilder to create a rule that runs the command inside an sbox sandbox.
Colin Crossba9e4032020-11-24 16:32:22 -0800381 rule := android.NewRuleBuilder(pctx, ctx).Sbox(task.genDir, manifestPath).SandboxTools()
Colin Crossf1a035e2020-11-16 17:32:30 -0800382 cmd := rule.Command()
383
Colin Cross3d680512020-11-13 16:23:53 -0800384 for _, out := range task.out {
Colin Crossf1a035e2020-11-16 17:32:30 -0800385 addLocationLabel(out.Rel(), []string{cmd.PathForOutput(out)})
Colin Cross3d680512020-11-13 16:23:53 -0800386 }
387
Colin Cross1a527682019-09-23 15:55:30 -0700388 referencedDepfile := false
389
Colin Cross3d680512020-11-13 16:23:53 -0800390 rawCommand, err := android.Expand(task.cmd, func(name string) (string, error) {
Colin Cross1a527682019-09-23 15:55:30 -0700391 // report the error directly without returning an error to android.Expand to catch multiple errors in a
392 // single run
Colin Cross3d680512020-11-13 16:23:53 -0800393 reportError := func(fmt string, args ...interface{}) (string, error) {
Colin Cross1a527682019-09-23 15:55:30 -0700394 ctx.PropertyErrorf("cmd", fmt, args...)
Colin Cross3d680512020-11-13 16:23:53 -0800395 return "SOONG_ERROR", nil
Colin Cross6f080df2016-11-04 15:32:58 -0700396 }
Colin Cross1a527682019-09-23 15:55:30 -0700397
398 switch name {
399 case "location":
400 if len(g.properties.Tools) == 0 && len(g.properties.Tool_files) == 0 {
401 return reportError("at least one `tools` or `tool_files` is required if $(location) is used")
Colin Cross6f080df2016-11-04 15:32:58 -0700402 }
Colin Cross1a527682019-09-23 15:55:30 -0700403 paths := locationLabels[firstLabel]
404 if len(paths) == 0 {
405 return reportError("default label %q has no files", firstLabel)
406 } else if len(paths) > 1 {
407 return reportError("default label %q has multiple files, use $(locations %s) to reference it",
408 firstLabel, firstLabel)
Colin Cross08f15ab2018-10-04 23:29:14 -0700409 }
Colin Cross3d680512020-11-13 16:23:53 -0800410 return locationLabels[firstLabel][0], nil
Colin Cross1a527682019-09-23 15:55:30 -0700411 case "in":
Colin Cross3d680512020-11-13 16:23:53 -0800412 return strings.Join(srcFiles.Strings(), " "), nil
Colin Cross1a527682019-09-23 15:55:30 -0700413 case "out":
Colin Cross3d680512020-11-13 16:23:53 -0800414 var sandboxOuts []string
415 for _, out := range task.out {
Colin Crossf1a035e2020-11-16 17:32:30 -0800416 sandboxOuts = append(sandboxOuts, cmd.PathForOutput(out))
Colin Cross3d680512020-11-13 16:23:53 -0800417 }
418 return strings.Join(sandboxOuts, " "), nil
Colin Cross1a527682019-09-23 15:55:30 -0700419 case "depfile":
420 referencedDepfile = true
421 if !Bool(g.properties.Depfile) {
422 return reportError("$(depfile) used without depfile property")
423 }
Colin Cross3d680512020-11-13 16:23:53 -0800424 return "__SBOX_DEPFILE__", nil
Colin Cross1a527682019-09-23 15:55:30 -0700425 case "genDir":
Colin Crossf1a035e2020-11-16 17:32:30 -0800426 return cmd.PathForOutput(task.genDir), nil
Colin Cross1a527682019-09-23 15:55:30 -0700427 default:
428 if strings.HasPrefix(name, "location ") {
429 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
430 if paths, ok := locationLabels[label]; ok {
431 if len(paths) == 0 {
432 return reportError("label %q has no files", label)
433 } else if len(paths) > 1 {
434 return reportError("label %q has multiple files, use $(locations %s) to reference it",
435 label, label)
436 }
Colin Cross3d680512020-11-13 16:23:53 -0800437 return paths[0], nil
Colin Cross1a527682019-09-23 15:55:30 -0700438 } else {
439 return reportError("unknown location label %q", label)
440 }
441 } else if strings.HasPrefix(name, "locations ") {
442 label := strings.TrimSpace(strings.TrimPrefix(name, "locations "))
443 if paths, ok := locationLabels[label]; ok {
444 if len(paths) == 0 {
445 return reportError("label %q has no files", label)
446 }
Colin Cross3d680512020-11-13 16:23:53 -0800447 return strings.Join(paths, " "), nil
Colin Cross1a527682019-09-23 15:55:30 -0700448 } else {
449 return reportError("unknown locations label %q", label)
450 }
451 } else {
452 return reportError("unknown variable '$(%s)'", name)
453 }
Colin Cross6f080df2016-11-04 15:32:58 -0700454 }
Colin Cross1a527682019-09-23 15:55:30 -0700455 })
456
457 if err != nil {
458 ctx.PropertyErrorf("cmd", "%s", err.Error())
459 return
Colin Cross6f080df2016-11-04 15:32:58 -0700460 }
Colin Cross6f080df2016-11-04 15:32:58 -0700461
Colin Cross1a527682019-09-23 15:55:30 -0700462 if Bool(g.properties.Depfile) && !referencedDepfile {
463 ctx.PropertyErrorf("cmd", "specified depfile=true but did not include a reference to '${depfile}' in cmd")
464 return
465 }
Colin Cross1a527682019-09-23 15:55:30 -0700466 g.rawCommands = append(g.rawCommands, rawCommand)
Bill Peckhamc087be12020-02-13 15:55:10 -0800467
Colin Cross3d680512020-11-13 16:23:53 -0800468 cmd.Text(rawCommand)
469 cmd.ImplicitOutputs(task.out)
470 cmd.Implicits(task.in)
Colin Crossba9e4032020-11-24 16:32:22 -0800471 cmd.ImplicitTools(tools)
472 cmd.ImplicitTools(task.extraTools)
473 cmd.ImplicitPackagedTools(packagedTools)
Colin Cross3d680512020-11-13 16:23:53 -0800474 if Bool(g.properties.Depfile) {
475 cmd.ImplicitDepFile(task.depFile)
476 }
477
478 // Create the rule to run the genrule command inside sbox.
Colin Crossf1a035e2020-11-16 17:32:30 -0800479 rule.Build(name, desc)
Colin Cross1a527682019-09-23 15:55:30 -0700480
481 if len(task.copyTo) > 0 {
Colin Cross3d680512020-11-13 16:23:53 -0800482 // If copyTo is set, multiple shards need to be copied into a single directory.
483 // task.out contains the per-shard paths, and copyTo contains the corresponding
484 // final path. The files need to be copied into the final directory by a
485 // single rule so it can remove the directory before it starts to ensure no
486 // old files remain. zipsync already does this, so build up zipArgs that
487 // zip all the per-shard directories into a single zip.
Colin Cross1a527682019-09-23 15:55:30 -0700488 outputFiles = append(outputFiles, task.copyTo...)
489 copyFrom = append(copyFrom, task.out.Paths()...)
490 zipArgs.WriteString(" -C " + task.genDir.String())
491 zipArgs.WriteString(android.JoinWithPrefix(task.out.Strings(), " -f "))
492 } else {
493 outputFiles = append(outputFiles, task.out...)
494 }
Colin Cross6f080df2016-11-04 15:32:58 -0700495 }
496
Colin Cross1a527682019-09-23 15:55:30 -0700497 if len(copyFrom) > 0 {
Colin Cross3d680512020-11-13 16:23:53 -0800498 // Create a rule that zips all the per-shard directories into a single zip and then
499 // uses zipsync to unzip it into the final directory.
Colin Cross1a527682019-09-23 15:55:30 -0700500 ctx.Build(pctx, android.BuildParams{
Colin Crossf1885962020-11-20 15:28:30 -0800501 Rule: gensrcsMerge,
502 Implicits: copyFrom,
503 Outputs: outputFiles,
504 Description: "merge shards",
Colin Cross1a527682019-09-23 15:55:30 -0700505 Args: map[string]string{
506 "zipArgs": zipArgs.String(),
507 "tmpZip": android.PathForModuleGen(ctx, g.subDir+".zip").String(),
508 "genDir": android.PathForModuleGen(ctx, g.subDir).String(),
509 },
510 })
Colin Cross85a2e892018-07-09 09:45:06 -0700511 }
512
Colin Cross1a527682019-09-23 15:55:30 -0700513 g.outputFiles = outputFiles.Paths()
Jeff Gastonefc1b412017-03-29 17:29:06 -0700514
Chris Parsonsaa8be052020-10-14 16:22:37 -0400515 bazelModuleLabel := g.properties.Bazel_module.Label
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400516 bazelActionsUsed := false
517 if ctx.Config().BazelContext.BazelEnabled() && len(bazelModuleLabel) > 0 {
518 bazelActionsUsed = g.generateBazelBuildActions(ctx, bazelModuleLabel)
Jeff Gaston02a684b2017-10-27 14:59:27 -0700519 }
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400520 if !bazelActionsUsed {
521 // For <= 6 outputs, just embed those directly in the users. Right now, that covers >90% of
522 // the genrules on AOSP. That will make things simpler to look at the graph in the common
523 // case. For larger sets of outputs, inject a phony target in between to limit ninja file
524 // growth.
525 if len(g.outputFiles) <= 6 {
526 g.outputDeps = g.outputFiles
527 } else {
528 phonyFile := android.PathForModuleGen(ctx, "genrule-phony")
529 ctx.Build(pctx, android.BuildParams{
530 Rule: blueprint.Phony,
531 Output: phonyFile,
532 Inputs: g.outputFiles,
533 })
534 g.outputDeps = android.Paths{phonyFile}
535 }
536 }
Colin Crossd350ecd2015-04-28 13:25:36 -0700537}
Colin Crossd350ecd2015-04-28 13:25:36 -0700538
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700539// Collect information for opening IDE project files in java/jdeps.go.
540func (g *Module) IDEInfo(dpInfo *android.IdeInfo) {
541 dpInfo.Srcs = append(dpInfo.Srcs, g.Srcs().Strings()...)
542 for _, src := range g.properties.Srcs {
543 if strings.HasPrefix(src, ":") {
544 src = strings.Trim(src, ":")
545 dpInfo.Deps = append(dpInfo.Deps, src)
546 }
547 }
bralee1fbf4402020-05-21 10:11:59 +0800548 dpInfo.Paths = append(dpInfo.Paths, g.modulePaths...)
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700549}
550
Colin Crossa4ad2b02019-03-18 22:15:32 -0700551func (g *Module) AndroidMk() android.AndroidMkData {
552 return android.AndroidMkData{
Anton Hansson72f18492020-10-30 16:34:45 +0000553 Class: "ETC",
Colin Crossa4ad2b02019-03-18 22:15:32 -0700554 OutputFile: android.OptionalPathForPath(g.outputFiles[0]),
555 SubName: g.subName,
556 Extra: []android.AndroidMkExtraFunc{
557 func(w io.Writer, outputFile android.Path) {
Anton Hansson72f18492020-10-30 16:34:45 +0000558 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossa4ad2b02019-03-18 22:15:32 -0700559 },
560 },
561 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
562 android.WriteAndroidMkData(w, data)
563 if data.SubName != "" {
564 fmt.Fprintln(w, ".PHONY:", name)
565 fmt.Fprintln(w, name, ":", name+g.subName)
566 }
567 },
568 }
569}
570
Dan Albertc8060532020-07-22 22:32:17 -0700571func (g *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
572 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +0900573 // Because generated outputs are checked by client modules(e.g. cc_library, ...)
574 // we can safely ignore the check here.
575 return nil
576}
577
Jeff Gaston437d23c2017-11-08 12:38:00 -0800578func generatorFactory(taskGenerator taskFunc, props ...interface{}) *Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700579 module := &Module{
Jeff Gaston437d23c2017-11-08 12:38:00 -0800580 taskGenerator: taskGenerator,
Colin Crossd350ecd2015-04-28 13:25:36 -0700581 }
582
Colin Cross36242852017-06-23 15:06:31 -0700583 module.AddProperties(props...)
584 module.AddProperties(&module.properties)
Colin Crossd350ecd2015-04-28 13:25:36 -0700585
Colin Cross7228ecd2019-11-18 16:00:16 -0800586 module.ImageInterface = noopImageInterface{}
587
Colin Cross36242852017-06-23 15:06:31 -0700588 return module
Colin Crossd350ecd2015-04-28 13:25:36 -0700589}
590
Colin Cross7228ecd2019-11-18 16:00:16 -0800591type noopImageInterface struct{}
592
593func (x noopImageInterface) ImageMutatorBegin(android.BaseModuleContext) {}
594func (x noopImageInterface) CoreVariantNeeded(android.BaseModuleContext) bool { return false }
Yifan Hong1b3348d2020-01-21 15:53:22 -0800595func (x noopImageInterface) RamdiskVariantNeeded(android.BaseModuleContext) bool { return false }
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700596func (x noopImageInterface) VendorRamdiskVariantNeeded(android.BaseModuleContext) bool { return false }
Colin Cross7228ecd2019-11-18 16:00:16 -0800597func (x noopImageInterface) RecoveryVariantNeeded(android.BaseModuleContext) bool { return false }
598func (x noopImageInterface) ExtraImageVariations(ctx android.BaseModuleContext) []string { return nil }
599func (x noopImageInterface) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
600}
601
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700602func NewGenSrcs() *Module {
Colin Crossd350ecd2015-04-28 13:25:36 -0700603 properties := &genSrcsProperties{}
604
Colin Crossf1885962020-11-20 15:28:30 -0800605 // finalSubDir is the name of the subdirectory that output files will be generated into.
606 // It is used so that per-shard directories can be placed alongside it an then finally
607 // merged into it.
608 const finalSubDir = "gensrcs"
609
Colin Cross1a527682019-09-23 15:55:30 -0700610 taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask {
Colin Cross1a527682019-09-23 15:55:30 -0700611 shardSize := defaultShardSize
612 if s := properties.Shard_size; s != nil {
613 shardSize = int(*s)
614 }
Jeff Gaston437d23c2017-11-08 12:38:00 -0800615
Colin Crossf1885962020-11-20 15:28:30 -0800616 // gensrcs rules can easily hit command line limits by repeating the command for
617 // every input file. Shard the input files into groups.
Colin Cross1a527682019-09-23 15:55:30 -0700618 shards := android.ShardPaths(srcFiles, shardSize)
619 var generateTasks []generateTask
Colin Crossbaccf5b2018-02-21 14:07:48 -0800620
Colin Cross1a527682019-09-23 15:55:30 -0700621 for i, shard := range shards {
622 var commands []string
623 var outFiles android.WritablePaths
Colin Cross3ea4eb82020-11-24 13:07:27 -0800624 var commandDepFiles []string
Colin Cross1a527682019-09-23 15:55:30 -0700625 var copyTo android.WritablePaths
Colin Cross1a527682019-09-23 15:55:30 -0700626
Colin Crossf1885962020-11-20 15:28:30 -0800627 // When sharding is enabled (i.e. len(shards) > 1), the sbox rules for each
628 // shard will be write to their own directories and then be merged together
629 // into finalSubDir. If sharding is not enabled (i.e. len(shards) == 1),
630 // the sbox rule will write directly to finalSubDir.
631 genSubDir := finalSubDir
Colin Cross1a527682019-09-23 15:55:30 -0700632 if len(shards) > 1 {
Colin Crossf1885962020-11-20 15:28:30 -0800633 genSubDir = strconv.Itoa(i)
Jeff Gaston437d23c2017-11-08 12:38:00 -0800634 }
635
Colin Crossf1885962020-11-20 15:28:30 -0800636 genDir := android.PathForModuleGen(ctx, genSubDir)
Colin Crossf1a035e2020-11-16 17:32:30 -0800637 // TODO(ccross): this RuleBuilder is a hack to be able to call
638 // rule.Command().PathForOutput. Replace this with passing the rule into the
639 // generator.
Colin Crossba9e4032020-11-24 16:32:22 -0800640 rule := android.NewRuleBuilder(pctx, ctx).Sbox(genDir, nil).SandboxTools()
Jeff Gaston437d23c2017-11-08 12:38:00 -0800641
Colin Cross3ea4eb82020-11-24 13:07:27 -0800642 for _, in := range shard {
Colin Crossf1885962020-11-20 15:28:30 -0800643 outFile := android.GenPathWithExt(ctx, finalSubDir, in, String(properties.Output_extension))
644
645 // If sharding is enabled, then outFile is the path to the output file in
646 // the shard directory, and copyTo is the path to the output file in the
647 // final directory.
Colin Cross1a527682019-09-23 15:55:30 -0700648 if len(shards) > 1 {
Colin Crossf1885962020-11-20 15:28:30 -0800649 shardFile := android.GenPathWithExt(ctx, genSubDir, in, String(properties.Output_extension))
Colin Cross1a527682019-09-23 15:55:30 -0700650 copyTo = append(copyTo, outFile)
651 outFile = shardFile
652 }
653
654 outFiles = append(outFiles, outFile)
Colin Cross1a527682019-09-23 15:55:30 -0700655
Colin Crossf1885962020-11-20 15:28:30 -0800656 // pre-expand the command line to replace $in and $out with references to
657 // a single input and output file.
Colin Cross1a527682019-09-23 15:55:30 -0700658 command, err := android.Expand(rawCommand, func(name string) (string, error) {
659 switch name {
660 case "in":
661 return in.String(), nil
662 case "out":
Colin Crossf1a035e2020-11-16 17:32:30 -0800663 return rule.Command().PathForOutput(outFile), nil
Colin Cross3ea4eb82020-11-24 13:07:27 -0800664 case "depfile":
665 // Generate a depfile for each output file. Store the list for
666 // later in order to combine them all into a single depfile.
Colin Crossf1a035e2020-11-16 17:32:30 -0800667 depFile := rule.Command().PathForOutput(outFile.ReplaceExtension(ctx, "d"))
Colin Cross3ea4eb82020-11-24 13:07:27 -0800668 commandDepFiles = append(commandDepFiles, depFile)
669 return depFile, nil
Colin Cross1a527682019-09-23 15:55:30 -0700670 default:
671 return "$(" + name + ")", nil
672 }
673 })
674 if err != nil {
675 ctx.PropertyErrorf("cmd", err.Error())
676 }
677
678 // escape the command in case for example it contains '#', an odd number of '"', etc
679 command = fmt.Sprintf("bash -c %v", proptools.ShellEscape(command))
680 commands = append(commands, command)
681 }
682 fullCommand := strings.Join(commands, " && ")
683
Colin Cross3ea4eb82020-11-24 13:07:27 -0800684 var outputDepfile android.WritablePath
685 var extraTools android.Paths
686 if len(commandDepFiles) > 0 {
687 // Each command wrote to a depfile, but ninja can only handle one
688 // depfile per rule. Use the dep_fixer tool at the end of the
689 // command to combine all the depfiles into a single output depfile.
690 outputDepfile = android.PathForModuleGen(ctx, genSubDir, "gensrcs.d")
691 depFixerTool := ctx.Config().HostToolPath(ctx, "dep_fixer")
692 fullCommand += fmt.Sprintf(" && %s -o $(depfile) %s",
Colin Crossba9e4032020-11-24 16:32:22 -0800693 android.SboxPathForTool(ctx, depFixerTool),
694 strings.Join(commandDepFiles, " "))
Colin Cross3ea4eb82020-11-24 13:07:27 -0800695 extraTools = append(extraTools, depFixerTool)
696 }
697
Colin Cross1a527682019-09-23 15:55:30 -0700698 generateTasks = append(generateTasks, generateTask{
Colin Cross3ea4eb82020-11-24 13:07:27 -0800699 in: shard,
700 out: outFiles,
701 depFile: outputDepfile,
702 copyTo: copyTo,
703 genDir: genDir,
704 cmd: fullCommand,
705 shard: i,
706 shards: len(shards),
707 extraTools: extraTools,
Colin Cross1a527682019-09-23 15:55:30 -0700708 })
Jeff Gaston437d23c2017-11-08 12:38:00 -0800709 }
Colin Cross1a527682019-09-23 15:55:30 -0700710
711 return generateTasks
Colin Crossd350ecd2015-04-28 13:25:36 -0700712 }
713
Colin Cross1a527682019-09-23 15:55:30 -0700714 g := generatorFactory(taskGenerator, properties)
Colin Crossf1885962020-11-20 15:28:30 -0800715 g.subDir = finalSubDir
Colin Cross1a527682019-09-23 15:55:30 -0700716 return g
Colin Crossd350ecd2015-04-28 13:25:36 -0700717}
718
Colin Cross54190b32017-10-09 15:34:10 -0700719func GenSrcsFactory() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700720 m := NewGenSrcs()
721 android.InitAndroidModule(m)
722 return m
723}
724
Colin Crossd350ecd2015-04-28 13:25:36 -0700725type genSrcsProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700726 // extension that will be substituted for each output file
Nan Zhanga5e7cb42017-11-09 22:42:32 -0800727 Output_extension *string
Colin Cross1a527682019-09-23 15:55:30 -0700728
729 // maximum number of files that will be passed on a single command line.
730 Shard_size *int64
Colin Cross5049f022015-03-18 13:28:46 -0700731}
732
Evgenii Stepanovf47c90d2020-12-02 18:55:09 -0800733const defaultShardSize = 50
Colin Cross1a527682019-09-23 15:55:30 -0700734
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700735func NewGenRule() *Module {
Colin Crossd350ecd2015-04-28 13:25:36 -0700736 properties := &genRuleProperties{}
Colin Cross5049f022015-03-18 13:28:46 -0700737
Colin Cross1a527682019-09-23 15:55:30 -0700738 taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask {
Dan Willemsen9c8681f2016-09-28 16:21:00 -0700739 outs := make(android.WritablePaths, len(properties.Out))
Colin Cross3d680512020-11-13 16:23:53 -0800740 var depFile android.WritablePath
Dan Willemsen9c8681f2016-09-28 16:21:00 -0700741 for i, out := range properties.Out {
Colin Cross3d680512020-11-13 16:23:53 -0800742 outPath := android.PathForModuleGen(ctx, out)
743 if i == 0 {
744 depFile = outPath.ReplaceExtension(ctx, "d")
745 }
746 outs[i] = outPath
Dan Willemsen9c8681f2016-09-28 16:21:00 -0700747 }
Colin Cross1a527682019-09-23 15:55:30 -0700748 return []generateTask{{
Colin Cross3d680512020-11-13 16:23:53 -0800749 in: srcFiles,
750 out: outs,
751 depFile: depFile,
752 genDir: android.PathForModuleGen(ctx),
753 cmd: rawCommand,
Colin Cross1a527682019-09-23 15:55:30 -0700754 }}
Colin Cross5049f022015-03-18 13:28:46 -0700755 }
Colin Crossd350ecd2015-04-28 13:25:36 -0700756
Jeff Gaston437d23c2017-11-08 12:38:00 -0800757 return generatorFactory(taskGenerator, properties)
Colin Cross5049f022015-03-18 13:28:46 -0700758}
759
Colin Cross54190b32017-10-09 15:34:10 -0700760func GenRuleFactory() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700761 m := NewGenRule()
762 android.InitAndroidModule(m)
Jaewoong Jung98716bd2018-12-10 08:13:18 -0800763 android.InitDefaultableModule(m)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700764 return m
765}
766
Colin Crossd350ecd2015-04-28 13:25:36 -0700767type genRuleProperties struct {
Dan Willemsen9c8681f2016-09-28 16:21:00 -0700768 // names of the output files that will be generated
Colin Crossef354482018-10-23 11:27:50 -0700769 Out []string `android:"arch_variant"`
Colin Cross5049f022015-03-18 13:28:46 -0700770}
Nan Zhangea568a42017-11-08 21:20:04 -0800771
772var Bool = proptools.Bool
773var String = proptools.String
Jaewoong Jung98716bd2018-12-10 08:13:18 -0800774
775//
776// Defaults
777//
778type Defaults struct {
779 android.ModuleBase
780 android.DefaultsModuleBase
781}
782
Jaewoong Jung98716bd2018-12-10 08:13:18 -0800783func defaultsFactory() android.Module {
784 return DefaultsFactory()
785}
786
787func DefaultsFactory(props ...interface{}) android.Module {
788 module := &Defaults{}
789
790 module.AddProperties(props...)
791 module.AddProperties(
792 &generatorProperties{},
793 &genRuleProperties{},
794 )
795
796 android.InitDefaultsModule(module)
797
798 return module
799}