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 (
|
|
|
|
"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() {
|
2015-09-24 06:26:20 +08:00
|
|
|
pctx.HostBinToolVariable("aidlCmd", "aidl")
|
2018-10-04 18:39:35 +08:00
|
|
|
pctx.HostBinToolVariable("syspropCmd", "sysprop_java")
|
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{
|
|
|
|
Command: "$aidlCmd -d$depFile $aidlFlags $in $out",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$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
|
|
|
})
|
2018-10-04 18:39:35 +08:00
|
|
|
|
|
|
|
sysprop = pctx.AndroidStaticRule("sysprop",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
|
|
|
|
`$syspropCmd --java-output-dir $out.tmp $in && ` +
|
|
|
|
`${config.SoongZipCmd} -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
|
|
|
|
CommandDeps: []string{
|
|
|
|
"$syspropCmd",
|
|
|
|
"${config.SoongZipCmd}",
|
|
|
|
},
|
|
|
|
})
|
2015-04-09 04:03:43 +08:00
|
|
|
)
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string) 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,
|
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
|
|
|
|
}
|
|
|
|
|
2018-10-04 18:39:35 +08:00
|
|
|
func genSysprop(ctx android.ModuleContext, syspropFile android.Path) android.Path {
|
|
|
|
srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar")
|
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: sysprop,
|
|
|
|
Description: "sysprop_java " + syspropFile.Rel(),
|
|
|
|
Output: srcJarFile,
|
|
|
|
Input: syspropFile,
|
|
|
|
})
|
|
|
|
|
|
|
|
return srcJarFile
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
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":
|
|
|
|
javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
|
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-03-29 10:30:56 +08:00
|
|
|
srcJarFile := genProto(ctx, srcFile, flags.proto)
|
2018-02-15 05:58:34 +08:00
|
|
|
outSrcFiles = append(outSrcFiles, srcJarFile)
|
2018-10-04 18:39:35 +08:00
|
|
|
case ".sysprop":
|
|
|
|
srcJarFile := genSysprop(ctx, srcFile)
|
|
|
|
outSrcFiles = append(outSrcFiles, srcJarFile)
|
2017-09-21 03:59:05 +08:00
|
|
|
default:
|
|
|
|
outSrcFiles = append(outSrcFiles, srcFile)
|
2015-04-09 04:03:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
})
|
|
|
|
}
|