2015-03-18 21:28:46 +01:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2020-11-21 03:30:13 +01:00
|
|
|
// A genrule module takes a list of source files ("srcs" property), an optional
|
|
|
|
// list of tools ("tools" property), and a command line ("cmd" property), to
|
|
|
|
// generate output files ("out" property).
|
|
|
|
|
2015-03-18 21:28:46 +01:00
|
|
|
package genrule
|
|
|
|
|
|
|
|
import (
|
2016-11-04 23:32:58 +01:00
|
|
|
"fmt"
|
2019-03-19 06:15:32 +01:00
|
|
|
"io"
|
2020-11-14 01:23:53 +01:00
|
|
|
"path/filepath"
|
2019-09-24 00:55:30 +02:00
|
|
|
"strconv"
|
2016-11-04 23:32:58 +01:00
|
|
|
"strings"
|
2016-09-29 01:19:10 +02:00
|
|
|
|
2015-03-23 20:57:34 +01:00
|
|
|
"github.com/google/blueprint"
|
2017-09-14 01:07:44 +02:00
|
|
|
"github.com/google/blueprint/bootstrap"
|
2017-11-09 06:20:04 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
2015-03-18 21:28:46 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2020-11-19 11:38:02 +01:00
|
|
|
"android/soong/bazel"
|
2015-03-18 21:28:46 +01:00
|
|
|
)
|
|
|
|
|
2015-06-17 23:20:06 +02:00
|
|
|
func init() {
|
2020-11-11 03:12:15 +01:00
|
|
|
RegisterGenruleBuildComponents(android.InitRegistrationContext)
|
2020-01-16 16:12:04 +01:00
|
|
|
}
|
|
|
|
|
2020-11-11 03:12:15 +01:00
|
|
|
func RegisterGenruleBuildComponents(ctx android.RegistrationContext) {
|
2020-01-16 16:12:04 +01:00
|
|
|
ctx.RegisterModuleType("genrule_defaults", defaultsFactory)
|
|
|
|
|
|
|
|
ctx.RegisterModuleType("gensrcs", GenSrcsFactory)
|
|
|
|
ctx.RegisterModuleType("genrule", GenRuleFactory)
|
2018-12-10 17:13:18 +01:00
|
|
|
|
2020-01-16 16:12:04 +01:00
|
|
|
ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
|
|
|
ctx.BottomUp("genrule_tool_deps", toolDepsMutator).Parallel()
|
|
|
|
})
|
2015-06-17 23:20:06 +02:00
|
|
|
}
|
|
|
|
|
2015-03-18 21:28:46 +01:00
|
|
|
var (
|
2016-05-19 00:37:25 +02:00
|
|
|
pctx = android.NewPackageContext("android/soong/genrule")
|
2019-09-24 00:55:30 +02:00
|
|
|
|
2020-11-21 03:30:13 +01:00
|
|
|
// Used by gensrcs when there is more than 1 shard to merge the outputs
|
|
|
|
// of each shard into a zip file.
|
2019-09-24 00:55:30 +02:00
|
|
|
gensrcsMerge = pctx.AndroidStaticRule("gensrcsMerge", blueprint.RuleParams{
|
|
|
|
Command: "${soongZip} -o ${tmpZip} @${tmpZip}.rsp && ${zipSync} -d ${genDir} ${tmpZip}",
|
|
|
|
CommandDeps: []string{"${soongZip}", "${zipSync}"},
|
|
|
|
Rspfile: "${tmpZip}.rsp",
|
|
|
|
RspfileContent: "${zipArgs}",
|
|
|
|
}, "tmpZip", "genDir", "zipArgs")
|
2015-03-18 21:28:46 +01:00
|
|
|
)
|
|
|
|
|
2017-03-30 02:29:06 +02:00
|
|
|
func init() {
|
Expose all deps on genrules
For remote builds, we actually need to know that we depend on all
outputs from a genrule, not just the first one. But having every user
depend on every genrule output increases the ninja file size by >40%.
So to work around the increase in file size, use a ninja phony rule to
produce a single alias to all of the files. Unlike make, where phony
rules are always dirty, ninja does not attempt to stat phony rules as
long as they have inputs, so they act as an alias. (If they don't have
inputs, it will stat the file an only consider it dirty if it doesn't
exist.)
My remote build tooling can then see that it's a phony rule with inputs,
and collapse all of these inputs onto the actual rule.
This only applies to genrules that have >6 outputs, in order to keep the
graph simpler and easier to read for the common case. That's ~10% of the
genrules in AOSP, and it increases the ninja file size by ~1.3%.
Test: manual ninja file inspection
Test: treehugger
Change-Id: I1a26a02fe983f0c92ce726ada3133707223e662e
2019-08-10 01:21:29 +02:00
|
|
|
pctx.Import("android/soong/android")
|
2017-03-30 02:29:06 +02:00
|
|
|
pctx.HostBinToolVariable("sboxCmd", "sbox")
|
2019-09-24 00:55:30 +02:00
|
|
|
|
|
|
|
pctx.HostBinToolVariable("soongZip", "soong_zip")
|
|
|
|
pctx.HostBinToolVariable("zipSync", "zipsync")
|
2017-03-30 02:29:06 +02:00
|
|
|
}
|
|
|
|
|
2015-03-18 21:28:46 +01:00
|
|
|
type SourceFileGenerator interface {
|
2016-05-19 00:37:25 +02:00
|
|
|
GeneratedSourceFiles() android.Paths
|
2016-11-22 21:55:55 +01:00
|
|
|
GeneratedHeaderDirs() android.Paths
|
2018-02-22 03:28:18 +01:00
|
|
|
GeneratedDeps() android.Paths
|
2015-03-18 21:28:46 +01:00
|
|
|
}
|
|
|
|
|
2019-03-29 03:30:56 +01:00
|
|
|
// Alias for android.HostToolProvider
|
|
|
|
// Deprecated: use android.HostToolProvider instead.
|
2015-04-28 22:25:36 +02:00
|
|
|
type HostToolProvider interface {
|
2019-03-29 03:30:56 +01:00
|
|
|
android.HostToolProvider
|
2015-04-28 22:25:36 +02:00
|
|
|
}
|
2015-03-18 21:28:46 +01:00
|
|
|
|
2017-09-14 00:46:47 +02:00
|
|
|
type hostToolDependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
2018-10-05 08:29:14 +02:00
|
|
|
label string
|
2017-09-14 00:46:47 +02:00
|
|
|
}
|
2015-05-11 22:39:40 +02:00
|
|
|
type generatorProperties struct {
|
2017-03-30 02:29:06 +02:00
|
|
|
// The command to run on one or more input files. Cmd supports substitution of a few variables
|
|
|
|
//
|
|
|
|
// Available variables for substitution:
|
|
|
|
//
|
2017-10-18 06:38:14 +02:00
|
|
|
// $(location): the path to the first entry in tools or tool_files
|
2018-10-05 08:29:14 +02:00
|
|
|
// $(location <label>): the path to the tool, tool_file, input or output with name <label>
|
2017-10-18 06:38:14 +02:00
|
|
|
// $(in): one or more input files
|
|
|
|
// $(out): a single output file
|
|
|
|
// $(depfile): a file to which dependencies will be written, if the depfile property is set to true
|
|
|
|
// $(genDir): the sandbox directory for this tool; contains $(out)
|
|
|
|
// $$: a literal $
|
2017-11-09 06:20:04 +01:00
|
|
|
Cmd *string
|
2015-05-11 22:39:40 +02:00
|
|
|
|
2016-11-22 02:23:08 +01:00
|
|
|
// Enable reading a file containing dependencies in gcc format after the command completes
|
2017-11-09 06:20:04 +01:00
|
|
|
Depfile *bool
|
2016-11-22 02:23:08 +01:00
|
|
|
|
2016-11-04 23:32:58 +01:00
|
|
|
// name of the modules (if any) that produces the host executable. Leave empty for
|
2015-05-11 22:39:40 +02:00
|
|
|
// prebuilts or scripts that do not need a module to build them.
|
2016-11-04 23:32:58 +01:00
|
|
|
Tools []string
|
2016-04-20 23:54:32 +02:00
|
|
|
|
|
|
|
// Local file that is used as the tool
|
2019-03-05 07:35:41 +01:00
|
|
|
Tool_files []string `android:"path"`
|
2016-11-22 21:55:55 +01:00
|
|
|
|
|
|
|
// List of directories to export generated headers from
|
|
|
|
Export_include_dirs []string
|
2017-01-14 03:05:49 +01:00
|
|
|
|
|
|
|
// list of input files
|
2019-03-05 07:35:41 +01:00
|
|
|
Srcs []string `android:"path,arch_variant"`
|
2018-11-17 23:01:18 +01:00
|
|
|
|
|
|
|
// input files to exclude
|
2019-03-05 07:35:41 +01:00
|
|
|
Exclude_srcs []string `android:"path,arch_variant"`
|
2015-05-11 22:39:40 +02:00
|
|
|
|
2020-11-19 11:38:02 +01:00
|
|
|
// Properties for Bazel migration purposes.
|
|
|
|
bazel.Properties
|
2020-09-29 08:23:17 +02:00
|
|
|
}
|
2020-11-21 03:30:13 +01:00
|
|
|
|
2017-09-14 03:37:08 +02:00
|
|
|
type Module struct {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.ModuleBase
|
2018-12-10 17:13:18 +01:00
|
|
|
android.DefaultableModuleBase
|
2019-06-12 06:27:29 +02:00
|
|
|
android.ApexModuleBase
|
2015-03-18 21:28:46 +01:00
|
|
|
|
2017-09-14 03:37:08 +02:00
|
|
|
// For other packages to make their own genrules with extra
|
|
|
|
// properties
|
|
|
|
Extra interface{}
|
2019-11-19 01:00:16 +01:00
|
|
|
android.ImageInterface
|
2017-09-14 03:37:08 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
properties generatorProperties
|
2015-04-28 22:25:36 +02:00
|
|
|
|
2020-11-21 03:30:13 +01:00
|
|
|
// For the different tasks that genrule and gensrc generate. genrule will
|
|
|
|
// generate 1 task, and gensrc will generate 1 or more tasks based on the
|
|
|
|
// number of shards the input files are sharded into.
|
2017-11-08 21:38:00 +01:00
|
|
|
taskGenerator taskFunc
|
2015-04-28 22:25:36 +02:00
|
|
|
|
2019-09-24 00:55:30 +02:00
|
|
|
deps android.Paths
|
|
|
|
rule blueprint.Rule
|
|
|
|
rawCommands []string
|
2015-04-28 22:25:36 +02:00
|
|
|
|
2016-11-22 21:55:55 +01:00
|
|
|
exportedIncludeDirs android.Paths
|
2016-04-20 23:21:14 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
outputFiles android.Paths
|
2018-02-22 03:28:18 +01:00
|
|
|
outputDeps android.Paths
|
2019-03-19 06:15:32 +01:00
|
|
|
|
|
|
|
subName string
|
2019-09-24 00:55:30 +02:00
|
|
|
subDir string
|
2020-05-21 04:11:59 +02:00
|
|
|
|
|
|
|
// Collect the module directory for IDE info in java/jdeps.go.
|
|
|
|
modulePaths []string
|
2015-03-18 21:28:46 +01:00
|
|
|
}
|
|
|
|
|
2019-09-24 00:55:30 +02:00
|
|
|
type taskFunc func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask
|
2015-03-18 21:28:46 +01:00
|
|
|
|
2015-04-28 22:25:36 +02:00
|
|
|
type generateTask struct {
|
2020-11-24 22:07:27 +01:00
|
|
|
in android.Paths
|
|
|
|
out android.WritablePaths
|
|
|
|
depFile android.WritablePath
|
2020-11-21 03:30:13 +01:00
|
|
|
copyTo android.WritablePaths // For gensrcs to set on gensrcsMerge rule.
|
2020-11-24 22:07:27 +01:00
|
|
|
genDir android.WritablePath
|
|
|
|
extraTools android.Paths // dependencies on tools used by the generator
|
|
|
|
|
2020-11-21 03:30:13 +01:00
|
|
|
cmd string
|
|
|
|
// For gensrsc sharding.
|
2020-11-24 22:07:27 +01:00
|
|
|
shard int
|
|
|
|
shards int
|
2015-03-18 21:28:46 +01:00
|
|
|
}
|
|
|
|
|
2017-09-14 03:37:08 +02:00
|
|
|
func (g *Module) GeneratedSourceFiles() android.Paths {
|
2015-04-28 22:25:36 +02:00
|
|
|
return g.outputFiles
|
|
|
|
}
|
2015-03-18 21:28:46 +01:00
|
|
|
|
2017-09-14 03:37:08 +02:00
|
|
|
func (g *Module) Srcs() android.Paths {
|
2018-03-28 01:19:42 +02:00
|
|
|
return append(android.Paths{}, g.outputFiles...)
|
2016-12-14 00:23:47 +01:00
|
|
|
}
|
|
|
|
|
2017-09-14 03:37:08 +02:00
|
|
|
func (g *Module) GeneratedHeaderDirs() android.Paths {
|
2016-11-22 21:55:55 +01:00
|
|
|
return g.exportedIncludeDirs
|
2016-04-20 23:21:14 +02:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:28:18 +01:00
|
|
|
func (g *Module) GeneratedDeps() android.Paths {
|
|
|
|
return g.outputDeps
|
|
|
|
}
|
|
|
|
|
2020-01-16 16:12:04 +01:00
|
|
|
func toolDepsMutator(ctx android.BottomUpMutatorContext) {
|
2017-09-14 03:37:08 +02:00
|
|
|
if g, ok := ctx.Module().(*Module); ok {
|
2018-10-05 08:29:14 +02:00
|
|
|
for _, tool := range g.properties.Tools {
|
|
|
|
tag := hostToolDependencyTag{label: tool}
|
|
|
|
if m := android.SrcIsModule(tool); m != "" {
|
|
|
|
tool = m
|
|
|
|
}
|
2019-10-16 20:03:10 +02:00
|
|
|
ctx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), tag, tool)
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
2015-04-28 22:25:36 +02:00
|
|
|
}
|
2015-03-18 21:28:46 +01:00
|
|
|
}
|
|
|
|
|
2020-09-29 08:23:17 +02:00
|
|
|
// Returns true if information was available from Bazel, false if bazel invocation still needs to occur.
|
|
|
|
func (c *Module) generateBazelBuildActions(ctx android.ModuleContext, label string) bool {
|
|
|
|
bazelCtx := ctx.Config().BazelContext
|
|
|
|
filePaths, ok := bazelCtx.GetAllFiles(label)
|
|
|
|
if ok {
|
|
|
|
var bazelOutputFiles android.Paths
|
|
|
|
for _, bazelOutputFile := range filePaths {
|
|
|
|
bazelOutputFiles = append(bazelOutputFiles, android.PathForSource(ctx, bazelOutputFile))
|
|
|
|
}
|
|
|
|
c.outputFiles = bazelOutputFiles
|
|
|
|
c.outputDeps = bazelOutputFiles
|
|
|
|
}
|
|
|
|
return ok
|
|
|
|
}
|
2020-11-21 00:28:30 +01:00
|
|
|
|
2017-09-14 03:37:08 +02:00
|
|
|
func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2019-03-19 06:15:32 +01:00
|
|
|
g.subName = ctx.ModuleSubDir()
|
|
|
|
|
2020-05-21 04:11:59 +02:00
|
|
|
// Collect the module directory for IDE info in java/jdeps.go.
|
|
|
|
g.modulePaths = append(g.modulePaths, ctx.ModuleDir())
|
|
|
|
|
2016-11-22 21:55:55 +01:00
|
|
|
if len(g.properties.Export_include_dirs) > 0 {
|
|
|
|
for _, dir := range g.properties.Export_include_dirs {
|
|
|
|
g.exportedIncludeDirs = append(g.exportedIncludeDirs,
|
2019-09-24 00:55:30 +02:00
|
|
|
android.PathForModuleGen(ctx, g.subDir, ctx.ModuleDir(), dir))
|
2016-11-22 21:55:55 +01:00
|
|
|
}
|
|
|
|
} else {
|
2019-09-24 00:55:30 +02:00
|
|
|
g.exportedIncludeDirs = append(g.exportedIncludeDirs, android.PathForModuleGen(ctx, g.subDir))
|
2016-11-22 21:55:55 +01:00
|
|
|
}
|
2016-09-29 01:19:10 +02:00
|
|
|
|
2018-10-05 08:29:14 +02:00
|
|
|
locationLabels := map[string][]string{}
|
|
|
|
firstLabel := ""
|
|
|
|
|
|
|
|
addLocationLabel := func(label string, paths []string) {
|
|
|
|
if firstLabel == "" {
|
|
|
|
firstLabel = label
|
|
|
|
}
|
|
|
|
if _, exists := locationLabels[label]; !exists {
|
|
|
|
locationLabels[label] = paths
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("multiple labels for %q, %q and %q",
|
|
|
|
label, strings.Join(locationLabels[label], " "), strings.Join(paths, " "))
|
|
|
|
}
|
|
|
|
}
|
2016-09-29 01:19:10 +02:00
|
|
|
|
2016-11-04 23:32:58 +01:00
|
|
|
if len(g.properties.Tools) > 0 {
|
2019-03-18 20:12:48 +01:00
|
|
|
seenTools := make(map[string]bool)
|
|
|
|
|
2017-11-16 09:11:20 +01:00
|
|
|
ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
|
2018-10-05 08:29:14 +02:00
|
|
|
switch tag := ctx.OtherModuleDependencyTag(module).(type) {
|
|
|
|
case hostToolDependencyTag:
|
2017-09-14 00:46:47 +02:00
|
|
|
tool := ctx.OtherModuleName(module)
|
2017-09-14 01:07:44 +02:00
|
|
|
var path android.OptionalPath
|
2017-09-14 00:46:47 +02:00
|
|
|
|
2019-03-29 03:30:56 +01:00
|
|
|
if t, ok := module.(android.HostToolProvider); ok {
|
2017-11-16 09:11:20 +01:00
|
|
|
if !t.(android.Module).Enabled() {
|
2017-11-29 09:27:14 +01:00
|
|
|
if ctx.Config().AllowMissingDependencies() {
|
2017-11-16 09:11:20 +01:00
|
|
|
ctx.AddMissingDependencies([]string{tool})
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("depends on disabled module %q", tool)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
2017-09-14 01:07:44 +02:00
|
|
|
path = t.HostToolPath()
|
|
|
|
} else if t, ok := module.(bootstrap.GoBinaryTool); ok {
|
|
|
|
if s, err := filepath.Rel(android.PathForOutput(ctx).String(), t.InstallPath()); err == nil {
|
|
|
|
path = android.OptionalPathForPath(android.PathForOutput(ctx, s))
|
2016-11-04 23:32:58 +01:00
|
|
|
} else {
|
2017-09-14 01:07:44 +02:00
|
|
|
ctx.ModuleErrorf("cannot find path for %q: %v", tool, err)
|
|
|
|
break
|
2016-11-04 23:32:58 +01:00
|
|
|
}
|
2016-04-20 23:54:32 +02:00
|
|
|
} else {
|
2017-09-14 00:46:47 +02:00
|
|
|
ctx.ModuleErrorf("%q is not a host tool provider", tool)
|
2017-09-14 01:07:44 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if path.Valid() {
|
|
|
|
g.deps = append(g.deps, path.Path())
|
2018-10-05 08:29:14 +02:00
|
|
|
addLocationLabel(tag.label, []string{path.Path().String()})
|
2019-03-18 20:12:48 +01:00
|
|
|
seenTools[tag.label] = true
|
2017-09-14 01:07:44 +02:00
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("host tool %q missing output file", tool)
|
2016-04-20 23:54:32 +02:00
|
|
|
}
|
2015-04-28 22:25:36 +02:00
|
|
|
}
|
2016-04-20 23:54:32 +02:00
|
|
|
})
|
2019-03-18 20:12:48 +01:00
|
|
|
|
|
|
|
// If AllowMissingDependencies is enabled, the build will not have stopped when
|
|
|
|
// AddFarVariationDependencies was called on a missing tool, which will result in nonsensical
|
2020-07-28 20:32:07 +02:00
|
|
|
// "cmd: unknown location label ..." errors later. Add a placeholder file to the local label.
|
|
|
|
// The command that uses this placeholder file will never be executed because the rule will be
|
|
|
|
// replaced with an android.Error rule reporting the missing dependencies.
|
2019-03-18 20:12:48 +01:00
|
|
|
if ctx.Config().AllowMissingDependencies() {
|
|
|
|
for _, tool := range g.properties.Tools {
|
|
|
|
if !seenTools[tool] {
|
|
|
|
addLocationLabel(tool, []string{"***missing tool " + tool + "***"})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-20 23:54:32 +02:00
|
|
|
}
|
2015-03-18 21:28:46 +01:00
|
|
|
|
2017-09-14 00:46:47 +02:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-05 08:29:14 +02:00
|
|
|
for _, toolFile := range g.properties.Tool_files {
|
2019-03-06 07:25:09 +01:00
|
|
|
paths := android.PathsForModuleSrc(ctx, []string{toolFile})
|
2018-10-05 08:29:14 +02:00
|
|
|
g.deps = append(g.deps, paths...)
|
|
|
|
addLocationLabel(toolFile, paths.Strings())
|
2016-11-04 23:32:58 +01:00
|
|
|
}
|
|
|
|
|
2018-10-05 08:29:14 +02:00
|
|
|
var srcFiles android.Paths
|
|
|
|
for _, in := range g.properties.Srcs {
|
2019-03-18 20:12:48 +01:00
|
|
|
paths, missingDeps := android.PathsAndMissingDepsForModuleSrcExcludes(ctx, []string{in}, g.properties.Exclude_srcs)
|
|
|
|
if len(missingDeps) > 0 {
|
|
|
|
if !ctx.Config().AllowMissingDependencies() {
|
|
|
|
panic(fmt.Errorf("should never get here, the missing dependencies %q should have been reported in DepsMutator",
|
|
|
|
missingDeps))
|
|
|
|
}
|
|
|
|
|
|
|
|
// If AllowMissingDependencies is enabled, the build will not have stopped when
|
|
|
|
// the dependency was added on a missing SourceFileProducer module, which will result in nonsensical
|
2020-07-28 20:32:07 +02:00
|
|
|
// "cmd: label ":..." has no files" errors later. Add a placeholder file to the local label.
|
|
|
|
// The command that uses this placeholder file will never be executed because the rule will be
|
|
|
|
// replaced with an android.Error rule reporting the missing dependencies.
|
2019-03-18 20:12:48 +01:00
|
|
|
ctx.AddMissingDependencies(missingDeps)
|
|
|
|
addLocationLabel(in, []string{"***missing srcs " + in + "***"})
|
|
|
|
} else {
|
|
|
|
srcFiles = append(srcFiles, paths...)
|
|
|
|
addLocationLabel(in, paths.Strings())
|
|
|
|
}
|
2018-10-05 08:29:14 +02:00
|
|
|
}
|
2017-10-27 23:59:27 +02:00
|
|
|
|
2019-09-24 00:55:30 +02:00
|
|
|
var copyFrom android.Paths
|
|
|
|
var outputFiles android.WritablePaths
|
|
|
|
var zipArgs strings.Builder
|
2018-10-05 08:29:14 +02:00
|
|
|
|
2020-11-21 03:30:13 +01:00
|
|
|
// Generate tasks, either from genrule or gensrcs.
|
2019-09-24 00:55:30 +02:00
|
|
|
for _, task := range g.taskGenerator(ctx, String(g.properties.Cmd), srcFiles) {
|
2020-11-14 01:23:53 +01:00
|
|
|
if len(task.out) == 0 {
|
|
|
|
ctx.ModuleErrorf("must have at least one output file")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-17 02:32:30 +01:00
|
|
|
// Pick a unique path outside the task.genDir for the sbox manifest textproto,
|
|
|
|
// a unique rule name, and the user-visible description.
|
|
|
|
manifestName := "genrule.sbox.textproto"
|
|
|
|
desc := "generate"
|
|
|
|
name := "generator"
|
|
|
|
if task.shards > 0 {
|
|
|
|
manifestName = "genrule_" + strconv.Itoa(task.shard) + ".sbox.textproto"
|
|
|
|
desc += " " + strconv.Itoa(task.shard)
|
|
|
|
name += strconv.Itoa(task.shard)
|
|
|
|
} else if len(task.out) == 1 {
|
|
|
|
desc += " " + task.out[0].Base()
|
|
|
|
}
|
|
|
|
|
|
|
|
manifestPath := android.PathForModuleOut(ctx, manifestName)
|
|
|
|
|
|
|
|
// Use a RuleBuilder to create a rule that runs the command inside an sbox sandbox.
|
|
|
|
rule := android.NewRuleBuilder(pctx, ctx).Sbox(task.genDir, manifestPath)
|
|
|
|
cmd := rule.Command()
|
|
|
|
|
2019-09-24 00:55:30 +02:00
|
|
|
for _, out := range task.out {
|
2020-11-17 02:32:30 +01:00
|
|
|
addLocationLabel(out.Rel(), []string{cmd.PathForOutput(out)})
|
2018-07-09 18:45:06 +02:00
|
|
|
}
|
|
|
|
|
2019-09-24 00:55:30 +02:00
|
|
|
referencedDepfile := false
|
|
|
|
|
2020-11-14 01:23:53 +01:00
|
|
|
rawCommand, err := android.Expand(task.cmd, func(name string) (string, error) {
|
2019-09-24 00:55:30 +02:00
|
|
|
// report the error directly without returning an error to android.Expand to catch multiple errors in a
|
|
|
|
// single run
|
2020-11-14 01:23:53 +01:00
|
|
|
reportError := func(fmt string, args ...interface{}) (string, error) {
|
2019-09-24 00:55:30 +02:00
|
|
|
ctx.PropertyErrorf("cmd", fmt, args...)
|
2020-11-14 01:23:53 +01:00
|
|
|
return "SOONG_ERROR", nil
|
2016-11-22 02:23:08 +01:00
|
|
|
}
|
2019-09-24 00:55:30 +02:00
|
|
|
|
|
|
|
switch name {
|
|
|
|
case "location":
|
|
|
|
if len(g.properties.Tools) == 0 && len(g.properties.Tool_files) == 0 {
|
|
|
|
return reportError("at least one `tools` or `tool_files` is required if $(location) is used")
|
|
|
|
}
|
|
|
|
paths := locationLabels[firstLabel]
|
|
|
|
if len(paths) == 0 {
|
|
|
|
return reportError("default label %q has no files", firstLabel)
|
|
|
|
} else if len(paths) > 1 {
|
|
|
|
return reportError("default label %q has multiple files, use $(locations %s) to reference it",
|
|
|
|
firstLabel, firstLabel)
|
|
|
|
}
|
2020-11-14 01:23:53 +01:00
|
|
|
return locationLabels[firstLabel][0], nil
|
2019-09-24 00:55:30 +02:00
|
|
|
case "in":
|
2020-11-14 01:23:53 +01:00
|
|
|
return strings.Join(srcFiles.Strings(), " "), nil
|
2019-09-24 00:55:30 +02:00
|
|
|
case "out":
|
2020-11-14 01:23:53 +01:00
|
|
|
var sandboxOuts []string
|
|
|
|
for _, out := range task.out {
|
2020-11-17 02:32:30 +01:00
|
|
|
sandboxOuts = append(sandboxOuts, cmd.PathForOutput(out))
|
2020-11-14 01:23:53 +01:00
|
|
|
}
|
|
|
|
return strings.Join(sandboxOuts, " "), nil
|
2019-09-24 00:55:30 +02:00
|
|
|
case "depfile":
|
|
|
|
referencedDepfile = true
|
|
|
|
if !Bool(g.properties.Depfile) {
|
|
|
|
return reportError("$(depfile) used without depfile property")
|
2016-11-04 23:32:58 +01:00
|
|
|
}
|
2020-11-14 01:23:53 +01:00
|
|
|
return "__SBOX_DEPFILE__", nil
|
2019-09-24 00:55:30 +02:00
|
|
|
case "genDir":
|
2020-11-17 02:32:30 +01:00
|
|
|
return cmd.PathForOutput(task.genDir), nil
|
2019-09-24 00:55:30 +02:00
|
|
|
default:
|
|
|
|
if strings.HasPrefix(name, "location ") {
|
|
|
|
label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
|
|
|
|
if paths, ok := locationLabels[label]; ok {
|
|
|
|
if len(paths) == 0 {
|
|
|
|
return reportError("label %q has no files", label)
|
|
|
|
} else if len(paths) > 1 {
|
|
|
|
return reportError("label %q has multiple files, use $(locations %s) to reference it",
|
|
|
|
label, label)
|
|
|
|
}
|
2020-11-14 01:23:53 +01:00
|
|
|
return paths[0], nil
|
2019-09-24 00:55:30 +02:00
|
|
|
} else {
|
|
|
|
return reportError("unknown location label %q", label)
|
|
|
|
}
|
|
|
|
} else if strings.HasPrefix(name, "locations ") {
|
|
|
|
label := strings.TrimSpace(strings.TrimPrefix(name, "locations "))
|
|
|
|
if paths, ok := locationLabels[label]; ok {
|
|
|
|
if len(paths) == 0 {
|
|
|
|
return reportError("label %q has no files", label)
|
|
|
|
}
|
2020-11-14 01:23:53 +01:00
|
|
|
return strings.Join(paths, " "), nil
|
2019-09-24 00:55:30 +02:00
|
|
|
} else {
|
|
|
|
return reportError("unknown locations label %q", label)
|
2018-10-05 08:29:14 +02:00
|
|
|
}
|
|
|
|
} else {
|
2019-09-24 00:55:30 +02:00
|
|
|
return reportError("unknown variable '$(%s)'", name)
|
2018-10-05 08:29:14 +02:00
|
|
|
}
|
2016-11-04 23:32:58 +01:00
|
|
|
}
|
2019-09-24 00:55:30 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("cmd", "%s", err.Error())
|
|
|
|
return
|
2016-11-04 23:32:58 +01:00
|
|
|
}
|
|
|
|
|
2019-09-24 00:55:30 +02:00
|
|
|
if Bool(g.properties.Depfile) && !referencedDepfile {
|
|
|
|
ctx.PropertyErrorf("cmd", "specified depfile=true but did not include a reference to '${depfile}' in cmd")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
g.rawCommands = append(g.rawCommands, rawCommand)
|
2020-02-14 00:55:10 +01:00
|
|
|
|
2020-11-14 01:23:53 +01:00
|
|
|
cmd.Text(rawCommand)
|
|
|
|
cmd.ImplicitOutputs(task.out)
|
|
|
|
cmd.Implicits(task.in)
|
|
|
|
cmd.Implicits(g.deps)
|
2020-11-24 22:07:27 +01:00
|
|
|
cmd.Implicits(task.extraTools)
|
2019-09-24 00:55:30 +02:00
|
|
|
if Bool(g.properties.Depfile) {
|
2020-11-14 01:23:53 +01:00
|
|
|
cmd.ImplicitDepFile(task.depFile)
|
2019-09-24 00:55:30 +02:00
|
|
|
}
|
2017-11-06 23:15:16 +01:00
|
|
|
|
2020-11-14 01:23:53 +01:00
|
|
|
// Create the rule to run the genrule command inside sbox.
|
2020-11-17 02:32:30 +01:00
|
|
|
rule.Build(name, desc)
|
2017-03-30 02:29:06 +02:00
|
|
|
|
2019-09-24 00:55:30 +02:00
|
|
|
if len(task.copyTo) > 0 {
|
2020-11-14 01:23:53 +01:00
|
|
|
// If copyTo is set, multiple shards need to be copied into a single directory.
|
|
|
|
// task.out contains the per-shard paths, and copyTo contains the corresponding
|
|
|
|
// final path. The files need to be copied into the final directory by a
|
|
|
|
// single rule so it can remove the directory before it starts to ensure no
|
|
|
|
// old files remain. zipsync already does this, so build up zipArgs that
|
|
|
|
// zip all the per-shard directories into a single zip.
|
2019-09-24 00:55:30 +02:00
|
|
|
outputFiles = append(outputFiles, task.copyTo...)
|
|
|
|
copyFrom = append(copyFrom, task.out.Paths()...)
|
|
|
|
zipArgs.WriteString(" -C " + task.genDir.String())
|
|
|
|
zipArgs.WriteString(android.JoinWithPrefix(task.out.Strings(), " -f "))
|
|
|
|
} else {
|
|
|
|
outputFiles = append(outputFiles, task.out...)
|
|
|
|
}
|
2016-11-22 02:23:08 +01:00
|
|
|
}
|
2019-09-24 00:55:30 +02:00
|
|
|
|
|
|
|
if len(copyFrom) > 0 {
|
2020-11-14 01:23:53 +01:00
|
|
|
// Create a rule that zips all the per-shard directories into a single zip and then
|
|
|
|
// uses zipsync to unzip it into the final directory.
|
2019-09-24 00:55:30 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2020-11-21 00:28:30 +01:00
|
|
|
Rule: gensrcsMerge,
|
|
|
|
Implicits: copyFrom,
|
|
|
|
Outputs: outputFiles,
|
|
|
|
Description: "merge shards",
|
2019-09-24 00:55:30 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"zipArgs": zipArgs.String(),
|
|
|
|
"tmpZip": android.PathForModuleGen(ctx, g.subDir+".zip").String(),
|
|
|
|
"genDir": android.PathForModuleGen(ctx, g.subDir).String(),
|
|
|
|
},
|
|
|
|
})
|
2016-11-22 02:23:08 +01:00
|
|
|
}
|
2016-11-04 23:32:58 +01:00
|
|
|
|
2019-09-24 00:55:30 +02:00
|
|
|
g.outputFiles = outputFiles.Paths()
|
|
|
|
|
2020-10-14 22:22:37 +02:00
|
|
|
bazelModuleLabel := g.properties.Bazel_module.Label
|
2020-09-29 08:23:17 +02:00
|
|
|
bazelActionsUsed := false
|
|
|
|
if ctx.Config().BazelContext.BazelEnabled() && len(bazelModuleLabel) > 0 {
|
|
|
|
bazelActionsUsed = g.generateBazelBuildActions(ctx, bazelModuleLabel)
|
|
|
|
}
|
|
|
|
if !bazelActionsUsed {
|
|
|
|
// For <= 6 outputs, just embed those directly in the users. Right now, that covers >90% of
|
|
|
|
// the genrules on AOSP. That will make things simpler to look at the graph in the common
|
|
|
|
// case. For larger sets of outputs, inject a phony target in between to limit ninja file
|
|
|
|
// growth.
|
|
|
|
if len(g.outputFiles) <= 6 {
|
|
|
|
g.outputDeps = g.outputFiles
|
|
|
|
} else {
|
|
|
|
phonyFile := android.PathForModuleGen(ctx, "genrule-phony")
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: blueprint.Phony,
|
|
|
|
Output: phonyFile,
|
|
|
|
Inputs: g.outputFiles,
|
|
|
|
})
|
|
|
|
g.outputDeps = android.Paths{phonyFile}
|
|
|
|
}
|
2019-09-24 00:55:30 +02:00
|
|
|
}
|
2015-04-28 22:25:36 +02:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:35:38 +02:00
|
|
|
// Collect information for opening IDE project files in java/jdeps.go.
|
|
|
|
func (g *Module) IDEInfo(dpInfo *android.IdeInfo) {
|
|
|
|
dpInfo.Srcs = append(dpInfo.Srcs, g.Srcs().Strings()...)
|
|
|
|
for _, src := range g.properties.Srcs {
|
|
|
|
if strings.HasPrefix(src, ":") {
|
|
|
|
src = strings.Trim(src, ":")
|
|
|
|
dpInfo.Deps = append(dpInfo.Deps, src)
|
|
|
|
}
|
|
|
|
}
|
2020-05-21 04:11:59 +02:00
|
|
|
dpInfo.Paths = append(dpInfo.Paths, g.modulePaths...)
|
2018-08-16 00:35:38 +02:00
|
|
|
}
|
|
|
|
|
2019-03-19 06:15:32 +01:00
|
|
|
func (g *Module) AndroidMk() android.AndroidMkData {
|
|
|
|
return android.AndroidMkData{
|
2020-10-30 17:34:45 +01:00
|
|
|
Class: "ETC",
|
2019-03-19 06:15:32 +01:00
|
|
|
OutputFile: android.OptionalPathForPath(g.outputFiles[0]),
|
|
|
|
SubName: g.subName,
|
|
|
|
Extra: []android.AndroidMkExtraFunc{
|
|
|
|
func(w io.Writer, outputFile android.Path) {
|
2020-10-30 17:34:45 +01:00
|
|
|
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
|
2019-03-19 06:15:32 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
|
|
|
|
android.WriteAndroidMkData(w, data)
|
|
|
|
if data.SubName != "" {
|
|
|
|
fmt.Fprintln(w, ".PHONY:", name)
|
|
|
|
fmt.Fprintln(w, name, ":", name+g.subName)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 07:32:17 +02:00
|
|
|
func (g *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
|
|
|
|
sdkVersion android.ApiLevel) error {
|
2020-04-15 04:03:39 +02:00
|
|
|
// Because generated outputs are checked by client modules(e.g. cc_library, ...)
|
|
|
|
// we can safely ignore the check here.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-08 21:38:00 +01:00
|
|
|
func generatorFactory(taskGenerator taskFunc, props ...interface{}) *Module {
|
2017-09-14 03:37:08 +02:00
|
|
|
module := &Module{
|
2017-11-08 21:38:00 +01:00
|
|
|
taskGenerator: taskGenerator,
|
2015-03-18 21:28:46 +01:00
|
|
|
}
|
2015-04-28 22:25:36 +02:00
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
module.AddProperties(props...)
|
|
|
|
module.AddProperties(&module.properties)
|
2015-04-28 22:25:36 +02:00
|
|
|
|
2019-11-19 01:00:16 +01:00
|
|
|
module.ImageInterface = noopImageInterface{}
|
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
return module
|
2015-03-18 21:28:46 +01:00
|
|
|
}
|
|
|
|
|
2019-11-19 01:00:16 +01:00
|
|
|
type noopImageInterface struct{}
|
|
|
|
|
|
|
|
func (x noopImageInterface) ImageMutatorBegin(android.BaseModuleContext) {}
|
|
|
|
func (x noopImageInterface) CoreVariantNeeded(android.BaseModuleContext) bool { return false }
|
2020-01-22 00:53:22 +01:00
|
|
|
func (x noopImageInterface) RamdiskVariantNeeded(android.BaseModuleContext) bool { return false }
|
2020-10-22 00:17:56 +02:00
|
|
|
func (x noopImageInterface) VendorRamdiskVariantNeeded(android.BaseModuleContext) bool { return false }
|
2019-11-19 01:00:16 +01:00
|
|
|
func (x noopImageInterface) RecoveryVariantNeeded(android.BaseModuleContext) bool { return false }
|
|
|
|
func (x noopImageInterface) ExtraImageVariations(ctx android.BaseModuleContext) []string { return nil }
|
|
|
|
func (x noopImageInterface) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
|
|
|
|
}
|
|
|
|
|
2017-09-14 03:37:08 +02:00
|
|
|
func NewGenSrcs() *Module {
|
2015-04-28 22:25:36 +02:00
|
|
|
properties := &genSrcsProperties{}
|
|
|
|
|
2020-11-21 00:28:30 +01:00
|
|
|
// finalSubDir is the name of the subdirectory that output files will be generated into.
|
|
|
|
// It is used so that per-shard directories can be placed alongside it an then finally
|
|
|
|
// merged into it.
|
|
|
|
const finalSubDir = "gensrcs"
|
|
|
|
|
2019-09-24 00:55:30 +02:00
|
|
|
taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask {
|
|
|
|
shardSize := defaultShardSize
|
|
|
|
if s := properties.Shard_size; s != nil {
|
|
|
|
shardSize = int(*s)
|
|
|
|
}
|
|
|
|
|
2020-11-21 00:28:30 +01:00
|
|
|
// gensrcs rules can easily hit command line limits by repeating the command for
|
|
|
|
// every input file. Shard the input files into groups.
|
2019-09-24 00:55:30 +02:00
|
|
|
shards := android.ShardPaths(srcFiles, shardSize)
|
|
|
|
var generateTasks []generateTask
|
|
|
|
|
|
|
|
for i, shard := range shards {
|
|
|
|
var commands []string
|
|
|
|
var outFiles android.WritablePaths
|
2020-11-24 22:07:27 +01:00
|
|
|
var commandDepFiles []string
|
2019-09-24 00:55:30 +02:00
|
|
|
var copyTo android.WritablePaths
|
|
|
|
|
2020-11-21 00:28:30 +01:00
|
|
|
// When sharding is enabled (i.e. len(shards) > 1), the sbox rules for each
|
|
|
|
// shard will be write to their own directories and then be merged together
|
|
|
|
// into finalSubDir. If sharding is not enabled (i.e. len(shards) == 1),
|
|
|
|
// the sbox rule will write directly to finalSubDir.
|
|
|
|
genSubDir := finalSubDir
|
2019-09-24 00:55:30 +02:00
|
|
|
if len(shards) > 1 {
|
2020-11-21 00:28:30 +01:00
|
|
|
genSubDir = strconv.Itoa(i)
|
2017-11-08 21:38:00 +01:00
|
|
|
}
|
|
|
|
|
2020-11-21 00:28:30 +01:00
|
|
|
genDir := android.PathForModuleGen(ctx, genSubDir)
|
2020-11-17 02:32:30 +01:00
|
|
|
// TODO(ccross): this RuleBuilder is a hack to be able to call
|
|
|
|
// rule.Command().PathForOutput. Replace this with passing the rule into the
|
|
|
|
// generator.
|
|
|
|
rule := android.NewRuleBuilder(pctx, ctx).Sbox(genDir, nil)
|
2020-11-21 00:28:30 +01:00
|
|
|
|
2020-11-24 22:07:27 +01:00
|
|
|
for _, in := range shard {
|
2020-11-21 00:28:30 +01:00
|
|
|
outFile := android.GenPathWithExt(ctx, finalSubDir, in, String(properties.Output_extension))
|
2017-11-08 21:38:00 +01:00
|
|
|
|
2020-11-21 00:28:30 +01:00
|
|
|
// If sharding is enabled, then outFile is the path to the output file in
|
|
|
|
// the shard directory, and copyTo is the path to the output file in the
|
|
|
|
// final directory.
|
2019-09-24 00:55:30 +02:00
|
|
|
if len(shards) > 1 {
|
2020-11-21 00:28:30 +01:00
|
|
|
shardFile := android.GenPathWithExt(ctx, genSubDir, in, String(properties.Output_extension))
|
2019-09-24 00:55:30 +02:00
|
|
|
copyTo = append(copyTo, outFile)
|
|
|
|
outFile = shardFile
|
|
|
|
}
|
|
|
|
|
|
|
|
outFiles = append(outFiles, outFile)
|
|
|
|
|
2020-11-21 00:28:30 +01:00
|
|
|
// pre-expand the command line to replace $in and $out with references to
|
|
|
|
// a single input and output file.
|
2019-09-24 00:55:30 +02:00
|
|
|
command, err := android.Expand(rawCommand, func(name string) (string, error) {
|
|
|
|
switch name {
|
|
|
|
case "in":
|
|
|
|
return in.String(), nil
|
|
|
|
case "out":
|
2020-11-17 02:32:30 +01:00
|
|
|
return rule.Command().PathForOutput(outFile), nil
|
2020-11-24 22:07:27 +01:00
|
|
|
case "depfile":
|
|
|
|
// Generate a depfile for each output file. Store the list for
|
|
|
|
// later in order to combine them all into a single depfile.
|
2020-11-17 02:32:30 +01:00
|
|
|
depFile := rule.Command().PathForOutput(outFile.ReplaceExtension(ctx, "d"))
|
2020-11-24 22:07:27 +01:00
|
|
|
commandDepFiles = append(commandDepFiles, depFile)
|
|
|
|
return depFile, nil
|
2019-09-24 00:55:30 +02:00
|
|
|
default:
|
|
|
|
return "$(" + name + ")", nil
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("cmd", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// escape the command in case for example it contains '#', an odd number of '"', etc
|
|
|
|
command = fmt.Sprintf("bash -c %v", proptools.ShellEscape(command))
|
|
|
|
commands = append(commands, command)
|
|
|
|
}
|
|
|
|
fullCommand := strings.Join(commands, " && ")
|
|
|
|
|
2020-11-24 22:07:27 +01:00
|
|
|
var outputDepfile android.WritablePath
|
|
|
|
var extraTools android.Paths
|
|
|
|
if len(commandDepFiles) > 0 {
|
|
|
|
// Each command wrote to a depfile, but ninja can only handle one
|
|
|
|
// depfile per rule. Use the dep_fixer tool at the end of the
|
|
|
|
// command to combine all the depfiles into a single output depfile.
|
|
|
|
outputDepfile = android.PathForModuleGen(ctx, genSubDir, "gensrcs.d")
|
|
|
|
depFixerTool := ctx.Config().HostToolPath(ctx, "dep_fixer")
|
|
|
|
fullCommand += fmt.Sprintf(" && %s -o $(depfile) %s",
|
|
|
|
depFixerTool.String(), strings.Join(commandDepFiles, " "))
|
|
|
|
extraTools = append(extraTools, depFixerTool)
|
|
|
|
}
|
|
|
|
|
2019-09-24 00:55:30 +02:00
|
|
|
generateTasks = append(generateTasks, generateTask{
|
2020-11-24 22:07:27 +01:00
|
|
|
in: shard,
|
|
|
|
out: outFiles,
|
|
|
|
depFile: outputDepfile,
|
|
|
|
copyTo: copyTo,
|
|
|
|
genDir: genDir,
|
|
|
|
cmd: fullCommand,
|
|
|
|
shard: i,
|
|
|
|
shards: len(shards),
|
|
|
|
extraTools: extraTools,
|
2019-09-24 00:55:30 +02:00
|
|
|
})
|
2015-04-28 22:25:36 +02:00
|
|
|
}
|
2019-09-24 00:55:30 +02:00
|
|
|
|
|
|
|
return generateTasks
|
2015-04-28 22:25:36 +02:00
|
|
|
}
|
2015-03-18 21:28:46 +01:00
|
|
|
|
2019-09-24 00:55:30 +02:00
|
|
|
g := generatorFactory(taskGenerator, properties)
|
2020-11-21 00:28:30 +01:00
|
|
|
g.subDir = finalSubDir
|
2019-09-24 00:55:30 +02:00
|
|
|
return g
|
2015-04-28 22:25:36 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 00:34:10 +02:00
|
|
|
func GenSrcsFactory() android.Module {
|
2017-09-14 03:37:08 +02:00
|
|
|
m := NewGenSrcs()
|
|
|
|
android.InitAndroidModule(m)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:25:36 +02:00
|
|
|
type genSrcsProperties struct {
|
2015-05-11 22:39:40 +02:00
|
|
|
// extension that will be substituted for each output file
|
2017-11-10 07:42:32 +01:00
|
|
|
Output_extension *string
|
2019-09-24 00:55:30 +02:00
|
|
|
|
|
|
|
// maximum number of files that will be passed on a single command line.
|
|
|
|
Shard_size *int64
|
2015-04-28 22:25:36 +02:00
|
|
|
}
|
|
|
|
|
2020-12-03 03:55:09 +01:00
|
|
|
const defaultShardSize = 50
|
2019-09-24 00:55:30 +02:00
|
|
|
|
2017-09-14 03:37:08 +02:00
|
|
|
func NewGenRule() *Module {
|
2015-04-28 22:25:36 +02:00
|
|
|
properties := &genRuleProperties{}
|
|
|
|
|
2019-09-24 00:55:30 +02:00
|
|
|
taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask {
|
2016-09-29 01:21:00 +02:00
|
|
|
outs := make(android.WritablePaths, len(properties.Out))
|
2020-11-14 01:23:53 +01:00
|
|
|
var depFile android.WritablePath
|
2016-09-29 01:21:00 +02:00
|
|
|
for i, out := range properties.Out {
|
2020-11-14 01:23:53 +01:00
|
|
|
outPath := android.PathForModuleGen(ctx, out)
|
|
|
|
if i == 0 {
|
|
|
|
depFile = outPath.ReplaceExtension(ctx, "d")
|
|
|
|
}
|
|
|
|
outs[i] = outPath
|
2016-09-29 01:21:00 +02:00
|
|
|
}
|
2019-09-24 00:55:30 +02:00
|
|
|
return []generateTask{{
|
2020-11-14 01:23:53 +01:00
|
|
|
in: srcFiles,
|
|
|
|
out: outs,
|
|
|
|
depFile: depFile,
|
|
|
|
genDir: android.PathForModuleGen(ctx),
|
|
|
|
cmd: rawCommand,
|
2019-09-24 00:55:30 +02:00
|
|
|
}}
|
2015-04-28 22:25:36 +02:00
|
|
|
}
|
|
|
|
|
2017-11-08 21:38:00 +01:00
|
|
|
return generatorFactory(taskGenerator, properties)
|
2015-04-28 22:25:36 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 00:34:10 +02:00
|
|
|
func GenRuleFactory() android.Module {
|
2017-09-14 03:37:08 +02:00
|
|
|
m := NewGenRule()
|
|
|
|
android.InitAndroidModule(m)
|
2018-12-10 17:13:18 +01:00
|
|
|
android.InitDefaultableModule(m)
|
2017-09-14 03:37:08 +02:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:25:36 +02:00
|
|
|
type genRuleProperties struct {
|
2016-09-29 01:21:00 +02:00
|
|
|
// names of the output files that will be generated
|
2018-10-23 20:27:50 +02:00
|
|
|
Out []string `android:"arch_variant"`
|
2015-03-18 21:28:46 +01:00
|
|
|
}
|
2017-11-09 06:20:04 +01:00
|
|
|
|
|
|
|
var Bool = proptools.Bool
|
|
|
|
var String = proptools.String
|
2018-12-10 17:13:18 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Defaults
|
|
|
|
//
|
|
|
|
type Defaults struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultsModuleBase
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultsFactory() android.Module {
|
|
|
|
return DefaultsFactory()
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultsFactory(props ...interface{}) android.Module {
|
|
|
|
module := &Defaults{}
|
|
|
|
|
|
|
|
module.AddProperties(props...)
|
|
|
|
module.AddProperties(
|
|
|
|
&generatorProperties{},
|
|
|
|
&genRuleProperties{},
|
|
|
|
)
|
|
|
|
|
|
|
|
android.InitDefaultsModule(module)
|
|
|
|
|
|
|
|
return module
|
|
|
|
}
|