2015-04-09 04:03:43 +08: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.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
import (
|
2019-06-15 09:51:47 +08:00
|
|
|
"strconv"
|
2019-07-07 15:27:47 +08:00
|
|
|
"strings"
|
|
|
|
|
2015-04-09 04:03:43 +08:00
|
|
|
"github.com/google/blueprint"
|
2019-06-15 09:51:47 +08:00
|
|
|
"github.com/google/blueprint/pathtools"
|
2015-04-09 04:03:43 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
"android/soong/android"
|
2015-04-09 04:03:43 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-04-08 00:44:35 +08:00
|
|
|
pctx.SourcePathVariable("logtagsCmd", "build/make/tools/java-event-log-tags.py")
|
|
|
|
pctx.SourcePathVariable("mergeLogtagsCmd", "build/make/tools/merge-event-log-tags.py")
|
|
|
|
pctx.SourcePathVariable("logtagsLib", "build/make/tools/event_log_tags.py")
|
2015-04-09 04:03:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2016-08-30 07:14:13 +08:00
|
|
|
logtags = pctx.AndroidStaticRule("logtags",
|
2015-04-11 08:45:20 +08:00
|
|
|
blueprint.RuleParams{
|
2017-11-16 14:47:16 +08:00
|
|
|
Command: "$logtagsCmd -o $out $in",
|
2019-04-08 00:44:35 +08:00
|
|
|
CommandDeps: []string{"$logtagsCmd", "$logtagsLib"},
|
2015-04-11 08:45:20 +08:00
|
|
|
})
|
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
mergeLogtags = pctx.AndroidStaticRule("mergeLogtags",
|
2015-04-11 08:45:20 +08:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$mergeLogtagsCmd -o $out $in",
|
2019-04-08 00:44:35 +08:00
|
|
|
CommandDeps: []string{"$mergeLogtagsCmd", "$logtagsLib"},
|
2015-04-11 08:45:20 +08:00
|
|
|
})
|
2015-04-09 04:03:43 +08:00
|
|
|
)
|
|
|
|
|
2019-06-15 09:51:47 +08:00
|
|
|
func genAidl(ctx android.ModuleContext, aidlFiles android.Paths, aidlFlags string, deps android.Paths) android.Paths {
|
|
|
|
// Shard aidl files into groups of 50 to avoid having to recompile all of them if one changes and to avoid
|
|
|
|
// hitting command line length limits.
|
|
|
|
shards := android.ShardPaths(aidlFiles, 50)
|
2015-04-09 04:03:43 +08:00
|
|
|
|
2019-06-15 09:51:47 +08:00
|
|
|
srcJarFiles := make(android.Paths, 0, len(shards))
|
2015-04-09 04:03:43 +08:00
|
|
|
|
2019-06-15 09:51:47 +08:00
|
|
|
for i, shard := range shards {
|
|
|
|
srcJarFile := android.PathForModuleGen(ctx, "aidl", "aidl"+strconv.Itoa(i)+".srcjar")
|
|
|
|
srcJarFiles = append(srcJarFiles, srcJarFile)
|
|
|
|
|
|
|
|
outDir := srcJarFile.ReplaceExtension(ctx, "tmp")
|
|
|
|
|
|
|
|
rule := android.NewRuleBuilder()
|
|
|
|
|
|
|
|
rule.Command().Text("rm -rf").Flag(outDir.String())
|
|
|
|
rule.Command().Text("mkdir -p").Flag(outDir.String())
|
|
|
|
rule.Command().Text("FLAGS=' " + aidlFlags + "'")
|
|
|
|
|
|
|
|
for _, aidlFile := range shard {
|
|
|
|
depFile := srcJarFile.InSameDir(ctx, aidlFile.String()+".d")
|
|
|
|
javaFile := outDir.Join(ctx, pathtools.ReplaceExtension(aidlFile.String(), "java"))
|
|
|
|
rule.Command().
|
|
|
|
Tool(ctx.Config().HostToolPath(ctx, "aidl")).
|
|
|
|
FlagWithDepFile("-d", depFile).
|
|
|
|
Flag("$FLAGS").
|
|
|
|
Input(aidlFile).
|
|
|
|
Output(javaFile).
|
|
|
|
Implicits(deps)
|
|
|
|
rule.Temporary(javaFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
Tool(ctx.Config().HostToolPath(ctx, "soong_zip")).
|
|
|
|
// TODO(b/124333557): this can't use -srcjar for now, aidl on parcelables generates java files
|
|
|
|
// without a package statement, which causes -srcjar to put them in the top level of the zip file.
|
|
|
|
// Once aidl skips parcelables we can use -srcjar.
|
|
|
|
//Flag("-srcjar").
|
|
|
|
Flag("-write_if_changed").
|
|
|
|
FlagWithOutput("-o ", srcJarFile).
|
|
|
|
FlagWithArg("-C ", outDir.String()).
|
|
|
|
FlagWithArg("-D ", outDir.String())
|
|
|
|
|
|
|
|
rule.Command().Text("rm -rf").Flag(outDir.String())
|
|
|
|
|
|
|
|
rule.Restat()
|
|
|
|
|
|
|
|
ruleName := "aidl"
|
|
|
|
ruleDesc := "aidl"
|
|
|
|
if len(shards) > 1 {
|
|
|
|
ruleName += "_" + strconv.Itoa(i)
|
|
|
|
ruleDesc += " " + strconv.Itoa(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
rule.Build(pctx, ctx, ruleName, ruleDesc)
|
|
|
|
}
|
|
|
|
|
|
|
|
return srcJarFiles
|
2015-04-09 04:03:43 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path {
|
2016-11-03 11:43:13 +08:00
|
|
|
javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java")
|
2015-04-11 08:45:20 +08:00
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: logtags,
|
|
|
|
Description: "logtags " + logtagsFile.Rel(),
|
|
|
|
Output: javaFile,
|
|
|
|
Input: logtagsFile,
|
2015-04-11 08:45:20 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
return javaFile
|
|
|
|
}
|
|
|
|
|
2019-08-16 20:12:10 +08:00
|
|
|
func genAidlIncludeFlags(srcFiles android.Paths) string {
|
|
|
|
var baseDirs []string
|
|
|
|
for _, srcFile := range srcFiles {
|
|
|
|
if srcFile.Ext() == ".aidl" {
|
|
|
|
baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel())
|
|
|
|
if baseDir != "" && !android.InList(baseDir, baseDirs) {
|
|
|
|
baseDirs = append(baseDirs, baseDir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return android.JoinWithPrefix(baseDirs, " -I")
|
|
|
|
}
|
|
|
|
|
2017-06-23 07:51:17 +08:00
|
|
|
func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
2017-11-16 15:01:59 +08:00
|
|
|
flags javaBuilderFlags) android.Paths {
|
2015-04-09 04:03:43 +08:00
|
|
|
|
2017-09-21 03:59:05 +08:00
|
|
|
outSrcFiles := make(android.Paths, 0, len(srcFiles))
|
2019-06-15 09:51:12 +08:00
|
|
|
var protoSrcs android.Paths
|
2019-06-15 09:51:47 +08:00
|
|
|
var aidlSrcs android.Paths
|
2017-09-21 03:59:05 +08:00
|
|
|
|
2019-08-16 20:12:10 +08:00
|
|
|
aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
|
|
|
|
|
2017-09-21 03:59:05 +08:00
|
|
|
for _, srcFile := range srcFiles {
|
2015-09-24 06:26:20 +08:00
|
|
|
switch srcFile.Ext() {
|
2015-04-09 04:03:43 +08:00
|
|
|
case ".aidl":
|
2019-06-15 09:51:47 +08:00
|
|
|
aidlSrcs = append(aidlSrcs, srcFile)
|
2015-04-11 08:45:20 +08:00
|
|
|
case ".logtags":
|
|
|
|
j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
|
|
|
|
javaFile := genLogtags(ctx, srcFile)
|
2017-09-21 03:59:05 +08:00
|
|
|
outSrcFiles = append(outSrcFiles, javaFile)
|
|
|
|
case ".proto":
|
2019-06-15 09:51:12 +08:00
|
|
|
protoSrcs = append(protoSrcs, srcFile)
|
2017-09-21 03:59:05 +08:00
|
|
|
default:
|
|
|
|
outSrcFiles = append(outSrcFiles, srcFile)
|
2015-04-09 04:03:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-15 09:51:12 +08:00
|
|
|
// Process all proto files together to support sharding them into one or more rules that produce srcjars.
|
|
|
|
if len(protoSrcs) > 0 {
|
|
|
|
srcJarFiles := genProto(ctx, protoSrcs, flags.proto)
|
|
|
|
outSrcFiles = append(outSrcFiles, srcJarFiles...)
|
|
|
|
}
|
|
|
|
|
2019-06-15 09:51:47 +08:00
|
|
|
// Process all aidl files together to support sharding them into one or more rules that produce srcjars.
|
|
|
|
if len(aidlSrcs) > 0 {
|
|
|
|
srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
|
|
|
|
outSrcFiles = append(outSrcFiles, srcJarFiles...)
|
|
|
|
}
|
|
|
|
|
2017-11-16 15:01:59 +08:00
|
|
|
return outSrcFiles
|
2015-04-09 04:03:43 +08:00
|
|
|
}
|
2015-04-11 08:45:20 +08:00
|
|
|
|
2017-11-29 09:34:01 +08:00
|
|
|
func LogtagsSingleton() android.Singleton {
|
2015-04-11 08:45:20 +08:00
|
|
|
return &logtagsSingleton{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type logtagsProducer interface {
|
2016-05-19 06:37:25 +08:00
|
|
|
logtags() android.Paths
|
2015-04-11 08:45:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type logtagsSingleton struct{}
|
|
|
|
|
2017-11-29 09:34:01 +08:00
|
|
|
func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
2016-05-19 06:37:25 +08:00
|
|
|
var allLogtags android.Paths
|
2017-11-29 09:34:01 +08:00
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
2015-04-11 08:45:20 +08:00
|
|
|
if logtags, ok := module.(logtagsProducer); ok {
|
|
|
|
allLogtags = append(allLogtags, logtags.logtags()...)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-11-29 09:34:01 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: mergeLogtags,
|
|
|
|
Description: "merge logtags",
|
2017-11-29 09:34:01 +08:00
|
|
|
Output: android.PathForIntermediates(ctx, "all-event-log-tags.txt"),
|
|
|
|
Inputs: allLogtags,
|
2015-04-11 08:45:20 +08:00
|
|
|
})
|
|
|
|
}
|