blob: a99382974e5cd8b6997659bd1bf6e6df5624dcc6 [file] [log] [blame]
Colin Crossc0b06f12015-04-08 13:03:43 -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
15package java
16
17// This file generates the final rules for compiling all C/C++. All properties related to
18// compiling should have been translated into builderFlags or another argument to the Transform*
19// functions.
20
21import (
Colin Crossc0b06f12015-04-08 13:03:43 -070022 "github.com/google/blueprint"
Colin Crossc0b06f12015-04-08 13:03:43 -070023
Colin Cross635c3b02016-05-18 15:37:25 -070024 "android/soong/android"
Colin Crossc0b06f12015-04-08 13:03:43 -070025)
26
27func init() {
Dan Willemsen34cc69e2015-09-23 15:26:20 -070028 pctx.HostBinToolVariable("aidlCmd", "aidl")
29 pctx.SourcePathVariable("logtagsCmd", "build/tools/java-event-log-tags.py")
30 pctx.SourcePathVariable("mergeLogtagsCmd", "build/tools/merge-event-log-tags.py")
Colin Crossc0b06f12015-04-08 13:03:43 -070031}
32
33var (
Colin Cross9d45bb72016-08-29 16:14:13 -070034 aidl = pctx.AndroidStaticRule("aidl",
Colin Crossc0b06f12015-04-08 13:03:43 -070035 blueprint.RuleParams{
36 Command: "$aidlCmd -d$depFile $aidlFlags $in $out",
Dan Willemsenc94a7682015-11-17 15:27:28 -080037 CommandDeps: []string{"$aidlCmd"},
Colin Crossc0b06f12015-04-08 13:03:43 -070038 },
39 "depFile", "aidlFlags")
Colin Crossf05fe972015-04-10 17:45:20 -070040
Colin Cross9d45bb72016-08-29 16:14:13 -070041 logtags = pctx.AndroidStaticRule("logtags",
Colin Crossf05fe972015-04-10 17:45:20 -070042 blueprint.RuleParams{
Colin Crossb1bd1aa2017-11-15 22:47:16 -080043 Command: "$logtagsCmd -o $out $in",
Dan Willemsenc94a7682015-11-17 15:27:28 -080044 CommandDeps: []string{"$logtagsCmd"},
Colin Crossf05fe972015-04-10 17:45:20 -070045 })
46
Colin Cross9d45bb72016-08-29 16:14:13 -070047 mergeLogtags = pctx.AndroidStaticRule("mergeLogtags",
Colin Crossf05fe972015-04-10 17:45:20 -070048 blueprint.RuleParams{
49 Command: "$mergeLogtagsCmd -o $out $in",
Dan Willemsenc94a7682015-11-17 15:27:28 -080050 CommandDeps: []string{"$mergeLogtagsCmd"},
Colin Crossf05fe972015-04-10 17:45:20 -070051 })
Colin Crossc0b06f12015-04-08 13:03:43 -070052)
53
Colin Cross635c3b02016-05-18 15:37:25 -070054func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string) android.Path {
Dan Willemsen21ec4902016-11-02 20:43:13 -070055 javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java")
Dan Willemsen34cc69e2015-09-23 15:26:20 -070056 depFile := javaFile.String() + ".d"
Colin Crossc0b06f12015-04-08 13:03:43 -070057
Colin Crossae887032017-10-23 17:16:14 -070058 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070059 Rule: aidl,
60 Description: "aidl " + aidlFile.Rel(),
61 Output: javaFile,
62 Input: aidlFile,
Colin Crossc0b06f12015-04-08 13:03:43 -070063 Args: map[string]string{
64 "depFile": depFile,
65 "aidlFlags": aidlFlags,
66 },
67 })
68
69 return javaFile
70}
71
Colin Cross635c3b02016-05-18 15:37:25 -070072func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path {
Dan Willemsen21ec4902016-11-02 20:43:13 -070073 javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java")
Colin Crossf05fe972015-04-10 17:45:20 -070074
Colin Crossae887032017-10-23 17:16:14 -070075 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070076 Rule: logtags,
77 Description: "logtags " + logtagsFile.Rel(),
78 Output: javaFile,
79 Input: logtagsFile,
Colin Crossf05fe972015-04-10 17:45:20 -070080 })
81
82 return javaFile
83}
84
Colin Cross46c9b8b2017-06-22 16:51:17 -070085func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Colin Crossaf050172017-11-15 23:01:59 -080086 flags javaBuilderFlags) android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -070087
Colin Cross6af17aa2017-09-20 12:59:05 -070088 outSrcFiles := make(android.Paths, 0, len(srcFiles))
89
90 for _, srcFile := range srcFiles {
Dan Willemsen34cc69e2015-09-23 15:26:20 -070091 switch srcFile.Ext() {
Colin Crossc0b06f12015-04-08 13:03:43 -070092 case ".aidl":
93 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
Colin Cross6af17aa2017-09-20 12:59:05 -070094 outSrcFiles = append(outSrcFiles, javaFile)
Colin Crossf05fe972015-04-10 17:45:20 -070095 case ".logtags":
96 j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
97 javaFile := genLogtags(ctx, srcFile)
Colin Cross6af17aa2017-09-20 12:59:05 -070098 outSrcFiles = append(outSrcFiles, javaFile)
99 case ".proto":
Dan Willemsenab9f4262018-02-14 13:58:34 -0800100 srcJarFile := genProto(ctx, srcFile, flags)
101 outSrcFiles = append(outSrcFiles, srcJarFile)
Colin Cross6af17aa2017-09-20 12:59:05 -0700102 default:
103 outSrcFiles = append(outSrcFiles, srcFile)
Colin Crossc0b06f12015-04-08 13:03:43 -0700104 }
105 }
106
Colin Crossaf050172017-11-15 23:01:59 -0800107 return outSrcFiles
Colin Crossc0b06f12015-04-08 13:03:43 -0700108}
Colin Crossf05fe972015-04-10 17:45:20 -0700109
Colin Cross0875c522017-11-28 17:34:01 -0800110func LogtagsSingleton() android.Singleton {
Colin Crossf05fe972015-04-10 17:45:20 -0700111 return &logtagsSingleton{}
112}
113
114type logtagsProducer interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700115 logtags() android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700116}
117
118type logtagsSingleton struct{}
119
Colin Cross0875c522017-11-28 17:34:01 -0800120func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700121 var allLogtags android.Paths
Colin Cross0875c522017-11-28 17:34:01 -0800122 ctx.VisitAllModules(func(module android.Module) {
Colin Crossf05fe972015-04-10 17:45:20 -0700123 if logtags, ok := module.(logtagsProducer); ok {
124 allLogtags = append(allLogtags, logtags.logtags()...)
125 }
126 })
127
Colin Cross0875c522017-11-28 17:34:01 -0800128 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700129 Rule: mergeLogtags,
130 Description: "merge logtags",
Colin Cross0875c522017-11-28 17:34:01 -0800131 Output: android.PathForIntermediates(ctx, "all-event-log-tags.txt"),
132 Inputs: allLogtags,
Colin Crossf05fe972015-04-10 17:45:20 -0700133 })
134}