blob: 51f9959da01078ab15d4b782c88e1587920aa98c [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
24 "android/soong/common"
25)
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 (
36 aidl = pctx.StaticRule("aidl",
37 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
44 logtags = pctx.StaticRule("logtags",
45 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
51 mergeLogtags = pctx.StaticRule("mergeLogtags",
52 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
Dan Willemsen34cc69e2015-09-23 15:26:20 -070059func genAidl(ctx common.AndroidModuleContext, aidlFile common.Path, aidlFlags string) common.Path {
60 javaFile := common.GenPathWithExt(ctx, aidlFile, "java")
61 depFile := javaFile.String() + ".d"
Colin Crossc0b06f12015-04-08 13:03:43 -070062
Dan Willemsen34cc69e2015-09-23 15:26:20 -070063 ctx.ModuleBuild(pctx, common.ModuleBuildParams{
64 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
Dan Willemsen34cc69e2015-09-23 15:26:20 -070076func genLogtags(ctx common.AndroidModuleContext, logtagsFile common.Path) common.Path {
77 javaFile := common.GenPathWithExt(ctx, logtagsFile, "java")
Colin Crossf05fe972015-04-10 17:45:20 -070078
Dan Willemsen34cc69e2015-09-23 15:26:20 -070079 ctx.ModuleBuild(pctx, common.ModuleBuildParams{
80 Rule: logtags,
81 Output: javaFile,
82 Input: logtagsFile,
Colin Crossf05fe972015-04-10 17:45:20 -070083 })
84
85 return javaFile
86}
87
Dan Willemsen34cc69e2015-09-23 15:26:20 -070088func (j *javaBase) genSources(ctx common.AndroidModuleContext, srcFiles common.Paths,
89 flags javaBuilderFlags) common.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 {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700111 logtags() common.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700112}
113
114type logtagsSingleton struct{}
115
116func (l *logtagsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700117 var allLogtags common.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}