blob: c73a446ce8031b1b8d9b7ec426d0d471e0ffd8ef [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 Crossf05fe972015-04-10 17:45:20 -070031
Dan Willemsen34cc69e2015-09-23 15:26:20 -070032 pctx.IntermediatesPathVariable("allLogtagsFile", "all-event-log-tags.txt")
Colin Crossc0b06f12015-04-08 13:03:43 -070033}
34
35var (
Colin Cross9d45bb72016-08-29 16:14:13 -070036 aidl = pctx.AndroidStaticRule("aidl",
Colin Crossc0b06f12015-04-08 13:03:43 -070037 blueprint.RuleParams{
38 Command: "$aidlCmd -d$depFile $aidlFlags $in $out",
Dan Willemsenc94a7682015-11-17 15:27:28 -080039 CommandDeps: []string{"$aidlCmd"},
Colin Crossc0b06f12015-04-08 13:03:43 -070040 },
41 "depFile", "aidlFlags")
Colin Crossf05fe972015-04-10 17:45:20 -070042
Colin Cross9d45bb72016-08-29 16:14:13 -070043 logtags = pctx.AndroidStaticRule("logtags",
Colin Crossf05fe972015-04-10 17:45:20 -070044 blueprint.RuleParams{
45 Command: "$logtagsCmd -o $out $in $allLogtagsFile",
Dan Willemsenc94a7682015-11-17 15:27:28 -080046 CommandDeps: []string{"$logtagsCmd"},
Colin Crossf05fe972015-04-10 17:45:20 -070047 })
48
Colin Cross9d45bb72016-08-29 16:14:13 -070049 mergeLogtags = pctx.AndroidStaticRule("mergeLogtags",
Colin Crossf05fe972015-04-10 17:45:20 -070050 blueprint.RuleParams{
51 Command: "$mergeLogtagsCmd -o $out $in",
Dan Willemsenc94a7682015-11-17 15:27:28 -080052 CommandDeps: []string{"$mergeLogtagsCmd"},
Colin Crossf05fe972015-04-10 17:45:20 -070053 })
Colin Crossc0b06f12015-04-08 13:03:43 -070054)
55
Colin Cross635c3b02016-05-18 15:37:25 -070056func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string) android.Path {
Dan Willemsen21ec4902016-11-02 20:43:13 -070057 javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java")
Dan Willemsen34cc69e2015-09-23 15:26:20 -070058 depFile := javaFile.String() + ".d"
Colin Crossc0b06f12015-04-08 13:03:43 -070059
Colin Crossae887032017-10-23 17:16:14 -070060 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070061 Rule: aidl,
62 Description: "aidl " + aidlFile.Rel(),
63 Output: javaFile,
64 Input: aidlFile,
Colin Crossc0b06f12015-04-08 13:03:43 -070065 Args: map[string]string{
66 "depFile": depFile,
67 "aidlFlags": aidlFlags,
68 },
69 })
70
71 return javaFile
72}
73
Colin Cross635c3b02016-05-18 15:37:25 -070074func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path {
Dan Willemsen21ec4902016-11-02 20:43:13 -070075 javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java")
Colin Crossf05fe972015-04-10 17:45:20 -070076
Colin Crossae887032017-10-23 17:16:14 -070077 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070078 Rule: logtags,
79 Description: "logtags " + logtagsFile.Rel(),
80 Output: javaFile,
81 Input: logtagsFile,
Colin Crossf05fe972015-04-10 17:45:20 -070082 })
83
84 return javaFile
85}
86
Colin Cross46c9b8b2017-06-22 16:51:17 -070087func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Colin Crossaf050172017-11-15 23:01:59 -080088 flags javaBuilderFlags) android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -070089
Colin Cross6af17aa2017-09-20 12:59:05 -070090 var protoFiles android.Paths
91 outSrcFiles := make(android.Paths, 0, len(srcFiles))
92
93 for _, srcFile := range srcFiles {
Dan Willemsen34cc69e2015-09-23 15:26:20 -070094 switch srcFile.Ext() {
Colin Crossc0b06f12015-04-08 13:03:43 -070095 case ".aidl":
96 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
Colin Cross6af17aa2017-09-20 12:59:05 -070097 outSrcFiles = append(outSrcFiles, javaFile)
Colin Crossf05fe972015-04-10 17:45:20 -070098 case ".logtags":
99 j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
100 javaFile := genLogtags(ctx, srcFile)
Colin Cross6af17aa2017-09-20 12:59:05 -0700101 outSrcFiles = append(outSrcFiles, javaFile)
102 case ".proto":
103 protoFiles = append(protoFiles, srcFile)
104 default:
105 outSrcFiles = append(outSrcFiles, srcFile)
Colin Crossc0b06f12015-04-08 13:03:43 -0700106 }
107 }
108
Colin Cross6af17aa2017-09-20 12:59:05 -0700109 if len(protoFiles) > 0 {
Colin Crossaf050172017-11-15 23:01:59 -0800110 protoSrcJar := android.PathForModuleGen(ctx, "proto.srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700111 genProto(ctx, protoSrcJar, protoFiles,
Colin Cross6af17aa2017-09-20 12:59:05 -0700112 flags.protoFlags, flags.protoOutFlag, "")
113
Colin Crossaf050172017-11-15 23:01:59 -0800114 outSrcFiles = append(outSrcFiles, protoSrcJar)
Colin Cross6af17aa2017-09-20 12:59:05 -0700115 }
116
Colin Crossaf050172017-11-15 23:01:59 -0800117 return outSrcFiles
Colin Crossc0b06f12015-04-08 13:03:43 -0700118}
Colin Crossf05fe972015-04-10 17:45:20 -0700119
120func LogtagsSingleton() blueprint.Singleton {
121 return &logtagsSingleton{}
122}
123
124type logtagsProducer interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700125 logtags() android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700126}
127
128type logtagsSingleton struct{}
129
130func (l *logtagsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700131 var allLogtags android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700132 ctx.VisitAllModules(func(module blueprint.Module) {
133 if logtags, ok := module.(logtagsProducer); ok {
134 allLogtags = append(allLogtags, logtags.logtags()...)
135 }
136 })
137
138 ctx.Build(pctx, blueprint.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700139 Rule: mergeLogtags,
140 Description: "merge logtags",
141 Outputs: []string{"$allLogtagsFile"},
142 Inputs: allLogtags.Strings(),
Colin Crossf05fe972015-04-10 17:45:20 -0700143 })
144}