blob: 0624708545b8b834d5deb09b41cae72e27eebe4b [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 Description: "aidl $out",
41 },
42 "depFile", "aidlFlags")
Colin Crossf05fe972015-04-10 17:45:20 -070043
Colin Cross9d45bb72016-08-29 16:14:13 -070044 logtags = pctx.AndroidStaticRule("logtags",
Colin Crossf05fe972015-04-10 17:45:20 -070045 blueprint.RuleParams{
46 Command: "$logtagsCmd -o $out $in $allLogtagsFile",
Dan Willemsenc94a7682015-11-17 15:27:28 -080047 CommandDeps: []string{"$logtagsCmd"},
Colin Crossf05fe972015-04-10 17:45:20 -070048 Description: "logtags $out",
49 })
50
Colin Cross9d45bb72016-08-29 16:14:13 -070051 mergeLogtags = pctx.AndroidStaticRule("mergeLogtags",
Colin Crossf05fe972015-04-10 17:45:20 -070052 blueprint.RuleParams{
53 Command: "$mergeLogtagsCmd -o $out $in",
Dan Willemsenc94a7682015-11-17 15:27:28 -080054 CommandDeps: []string{"$mergeLogtagsCmd"},
Colin Crossf05fe972015-04-10 17:45:20 -070055 Description: "merge logtags $out",
56 })
Colin Crossc0b06f12015-04-08 13:03:43 -070057)
58
Colin Cross635c3b02016-05-18 15:37:25 -070059func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string) android.Path {
Dan Willemsen21ec4902016-11-02 20:43:13 -070060 javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java")
Dan Willemsen34cc69e2015-09-23 15:26:20 -070061 depFile := javaFile.String() + ".d"
Colin Crossc0b06f12015-04-08 13:03:43 -070062
Colin Cross635c3b02016-05-18 15:37:25 -070063 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Dan Willemsen34cc69e2015-09-23 15:26:20 -070064 Rule: aidl,
65 Output: javaFile,
66 Input: aidlFile,
Colin Crossc0b06f12015-04-08 13:03:43 -070067 Args: map[string]string{
68 "depFile": depFile,
69 "aidlFlags": aidlFlags,
70 },
71 })
72
73 return javaFile
74}
75
Colin Cross635c3b02016-05-18 15:37:25 -070076func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path {
Dan Willemsen21ec4902016-11-02 20:43:13 -070077 javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java")
Colin Crossf05fe972015-04-10 17:45:20 -070078
Colin Cross635c3b02016-05-18 15:37:25 -070079 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Dan Willemsen34cc69e2015-09-23 15:26:20 -070080 Rule: logtags,
81 Output: javaFile,
82 Input: logtagsFile,
Colin Crossf05fe972015-04-10 17:45:20 -070083 })
84
85 return javaFile
86}
87
Colin Cross635c3b02016-05-18 15:37:25 -070088func (j *javaBase) genSources(ctx android.ModuleContext, srcFiles android.Paths,
89 flags javaBuilderFlags) android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -070090
91 for i, srcFile := range srcFiles {
Dan Willemsen34cc69e2015-09-23 15:26:20 -070092 switch srcFile.Ext() {
Colin Crossc0b06f12015-04-08 13:03:43 -070093 case ".aidl":
94 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
95 srcFiles[i] = javaFile
Colin Crossf05fe972015-04-10 17:45:20 -070096 case ".logtags":
97 j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
98 javaFile := genLogtags(ctx, srcFile)
99 srcFiles[i] = javaFile
Colin Crossc0b06f12015-04-08 13:03:43 -0700100 }
101 }
102
103 return srcFiles
104}
Colin Crossf05fe972015-04-10 17:45:20 -0700105
106func LogtagsSingleton() blueprint.Singleton {
107 return &logtagsSingleton{}
108}
109
110type logtagsProducer interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700111 logtags() android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700112}
113
114type logtagsSingleton struct{}
115
116func (l *logtagsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700117 var allLogtags android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700118 ctx.VisitAllModules(func(module blueprint.Module) {
119 if logtags, ok := module.(logtagsProducer); ok {
120 allLogtags = append(allLogtags, logtags.logtags()...)
121 }
122 })
123
124 ctx.Build(pctx, blueprint.BuildParams{
125 Rule: mergeLogtags,
126 Outputs: []string{"$allLogtagsFile"},
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700127 Inputs: allLogtags.Strings(),
Colin Crossf05fe972015-04-10 17:45:20 -0700128 })
129}