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-07-07 15:27:47 +08:00
|
|
|
"strings"
|
|
|
|
|
2015-04-09 04:03:43 +08:00
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
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
|
|
|
aidl = pctx.AndroidStaticRule("aidl",
|
2015-04-09 04:03:43 +08:00
|
|
|
blueprint.RuleParams{
|
2019-08-09 03:56:34 +08:00
|
|
|
Command: "${config.AidlCmd} -d$depFile $aidlFlags $in $out",
|
|
|
|
CommandDeps: []string{"${config.AidlCmd}"},
|
2015-04-09 04:03:43 +08:00
|
|
|
},
|
|
|
|
"depFile", "aidlFlags")
|
2015-04-11 08:45:20 +08:00
|
|
|
|
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-04-19 01:56:44 +08:00
|
|
|
func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string, deps android.Paths) android.Path {
|
2016-11-03 11:43:13 +08:00
|
|
|
javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java")
|
2015-09-24 06:26:20 +08:00
|
|
|
depFile := javaFile.String() + ".d"
|
2015-04-09 04:03:43 +08:00
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: aidl,
|
|
|
|
Description: "aidl " + aidlFile.Rel(),
|
|
|
|
Output: javaFile,
|
|
|
|
Input: aidlFile,
|
2019-04-19 01:56:44 +08:00
|
|
|
Implicits: deps,
|
2015-04-09 04:03:43 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"depFile": depFile,
|
|
|
|
"aidlFlags": aidlFlags,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return javaFile
|
|
|
|
}
|
|
|
|
|
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
|
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-08-16 20:12:10 +08:00
|
|
|
javaFile := genAidl(ctx, srcFile, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
|
2017-09-21 03:59:05 +08:00
|
|
|
outSrcFiles = append(outSrcFiles, javaFile)
|
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...)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
})
|
|
|
|
}
|