blob: dd86f66f0671816b73e36337b1e23140ff6b8881 [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 (
22 "path/filepath"
23 "strings"
24
25 "github.com/google/blueprint"
26 "github.com/google/blueprint/pathtools"
27
28 "android/soong/common"
29)
30
31func init() {
32 pctx.VariableFunc("aidlCmd", func(c interface{}) (string, error) {
33 return c.(common.Config).HostBinTool("aidl")
34 })
Colin Crossf05fe972015-04-10 17:45:20 -070035 pctx.StaticVariable("logtagsCmd", "${srcDir}/build/tools/java-event-log-tags.py")
36 pctx.StaticVariable("mergeLogtagsCmd", "${srcDir}/build/tools/merge-event-log-tags.py")
Colin Crossc0b06f12015-04-08 13:03:43 -070037 pctx.VariableConfigMethod("srcDir", common.Config.SrcDir)
Colin Crossf05fe972015-04-10 17:45:20 -070038
39 pctx.VariableFunc("allLogtagsFile", func(c interface{}) (string, error) {
40 return filepath.Join(c.(common.Config).IntermediatesDir(), "all-event-log-tags.txt"), nil
41 })
Colin Crossc0b06f12015-04-08 13:03:43 -070042}
43
44var (
45 aidl = pctx.StaticRule("aidl",
46 blueprint.RuleParams{
47 Command: "$aidlCmd -d$depFile $aidlFlags $in $out",
48 Description: "aidl $out",
49 },
50 "depFile", "aidlFlags")
Colin Crossf05fe972015-04-10 17:45:20 -070051
52 logtags = pctx.StaticRule("logtags",
53 blueprint.RuleParams{
54 Command: "$logtagsCmd -o $out $in $allLogtagsFile",
55 Description: "logtags $out",
56 })
57
58 mergeLogtags = pctx.StaticRule("mergeLogtags",
59 blueprint.RuleParams{
60 Command: "$mergeLogtagsCmd -o $out $in",
61 Description: "merge logtags $out",
62 })
Colin Crossc0b06f12015-04-08 13:03:43 -070063)
64
65func genAidl(ctx common.AndroidModuleContext, aidlFile, aidlFlags string) string {
66 javaFile := strings.TrimPrefix(aidlFile, common.ModuleSrcDir(ctx))
67 javaFile = filepath.Join(common.ModuleGenDir(ctx), javaFile)
68 javaFile = pathtools.ReplaceExtension(javaFile, "java")
69 depFile := javaFile + ".d"
70
71 ctx.Build(pctx, blueprint.BuildParams{
72 Rule: aidl,
73 Outputs: []string{javaFile},
74 Inputs: []string{aidlFile},
75 Implicits: []string{"$aidlCmd"},
76 Args: map[string]string{
77 "depFile": depFile,
78 "aidlFlags": aidlFlags,
79 },
80 })
81
82 return javaFile
83}
84
Colin Crossf05fe972015-04-10 17:45:20 -070085func genLogtags(ctx common.AndroidModuleContext, logtagsFile string) string {
86 javaFile := strings.TrimPrefix(logtagsFile, common.ModuleSrcDir(ctx))
87 javaFile = filepath.Join(common.ModuleGenDir(ctx), javaFile)
88 javaFile = pathtools.ReplaceExtension(javaFile, "java")
89
90 ctx.Build(pctx, blueprint.BuildParams{
91 Rule: logtags,
92 Outputs: []string{javaFile},
93 Inputs: []string{logtagsFile},
94 Implicits: []string{"$logtagsCmd"},
95 })
96
97 return javaFile
98}
99
100func (j *javaBase) genSources(ctx common.AndroidModuleContext, srcFiles []string,
Colin Crossc0b06f12015-04-08 13:03:43 -0700101 flags javaBuilderFlags) []string {
102
103 for i, srcFile := range srcFiles {
104 switch filepath.Ext(srcFile) {
105 case ".aidl":
106 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
107 srcFiles[i] = javaFile
Colin Crossf05fe972015-04-10 17:45:20 -0700108 case ".logtags":
109 j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
110 javaFile := genLogtags(ctx, srcFile)
111 srcFiles[i] = javaFile
Colin Crossc0b06f12015-04-08 13:03:43 -0700112 }
113 }
114
115 return srcFiles
116}
Colin Crossf05fe972015-04-10 17:45:20 -0700117
118func LogtagsSingleton() blueprint.Singleton {
119 return &logtagsSingleton{}
120}
121
122type logtagsProducer interface {
123 logtags() []string
124}
125
126type logtagsSingleton struct{}
127
128func (l *logtagsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
129 var allLogtags []string
130 ctx.VisitAllModules(func(module blueprint.Module) {
131 if logtags, ok := module.(logtagsProducer); ok {
132 allLogtags = append(allLogtags, logtags.logtags()...)
133 }
134 })
135
136 ctx.Build(pctx, blueprint.BuildParams{
137 Rule: mergeLogtags,
138 Outputs: []string{"$allLogtagsFile"},
139 Inputs: allLogtags,
140 })
141}