blob: f98987549e8b3eb765ec89d0543722d137c0ca7a [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"
Colin Crossc0b06f12015-04-08 13:03:43 -070023
24 "github.com/google/blueprint"
25 "github.com/google/blueprint/pathtools"
26
27 "android/soong/common"
28)
29
30func init() {
31 pctx.VariableFunc("aidlCmd", func(c interface{}) (string, error) {
32 return c.(common.Config).HostBinTool("aidl")
33 })
Colin Crossf05fe972015-04-10 17:45:20 -070034 pctx.StaticVariable("logtagsCmd", "${srcDir}/build/tools/java-event-log-tags.py")
35 pctx.StaticVariable("mergeLogtagsCmd", "${srcDir}/build/tools/merge-event-log-tags.py")
Colin Crossc0b06f12015-04-08 13:03:43 -070036 pctx.VariableConfigMethod("srcDir", common.Config.SrcDir)
Colin Crossf05fe972015-04-10 17:45:20 -070037
38 pctx.VariableFunc("allLogtagsFile", func(c interface{}) (string, error) {
39 return filepath.Join(c.(common.Config).IntermediatesDir(), "all-event-log-tags.txt"), nil
40 })
Colin Crossc0b06f12015-04-08 13:03:43 -070041}
42
43var (
44 aidl = pctx.StaticRule("aidl",
45 blueprint.RuleParams{
46 Command: "$aidlCmd -d$depFile $aidlFlags $in $out",
Dan Willemsenc94a7682015-11-17 15:27:28 -080047 CommandDeps: []string{"$aidlCmd"},
Colin Crossc0b06f12015-04-08 13:03:43 -070048 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",
Dan Willemsenc94a7682015-11-17 15:27:28 -080055 CommandDeps: []string{"$logtagsCmd"},
Colin Crossf05fe972015-04-10 17:45:20 -070056 Description: "logtags $out",
57 })
58
59 mergeLogtags = pctx.StaticRule("mergeLogtags",
60 blueprint.RuleParams{
61 Command: "$mergeLogtagsCmd -o $out $in",
Dan Willemsenc94a7682015-11-17 15:27:28 -080062 CommandDeps: []string{"$mergeLogtagsCmd"},
Colin Crossf05fe972015-04-10 17:45:20 -070063 Description: "merge logtags $out",
64 })
Colin Crossc0b06f12015-04-08 13:03:43 -070065)
66
67func genAidl(ctx common.AndroidModuleContext, aidlFile, aidlFlags string) string {
Colin Cross6e18ca42015-07-14 18:55:36 -070068 javaFile := common.SrcDirRelPath(ctx, aidlFile)
Colin Crossc0b06f12015-04-08 13:03:43 -070069 javaFile = filepath.Join(common.ModuleGenDir(ctx), javaFile)
70 javaFile = pathtools.ReplaceExtension(javaFile, "java")
71 depFile := javaFile + ".d"
72
73 ctx.Build(pctx, blueprint.BuildParams{
Dan Willemsenc94a7682015-11-17 15:27:28 -080074 Rule: aidl,
75 Outputs: []string{javaFile},
76 Inputs: []string{aidlFile},
Colin Crossc0b06f12015-04-08 13:03:43 -070077 Args: map[string]string{
78 "depFile": depFile,
79 "aidlFlags": aidlFlags,
80 },
81 })
82
83 return javaFile
84}
85
Colin Crossf05fe972015-04-10 17:45:20 -070086func genLogtags(ctx common.AndroidModuleContext, logtagsFile string) string {
Colin Cross6e18ca42015-07-14 18:55:36 -070087 javaFile := common.SrcDirRelPath(ctx, logtagsFile)
Colin Crossf05fe972015-04-10 17:45:20 -070088 javaFile = filepath.Join(common.ModuleGenDir(ctx), javaFile)
89 javaFile = pathtools.ReplaceExtension(javaFile, "java")
90
91 ctx.Build(pctx, blueprint.BuildParams{
Dan Willemsenc94a7682015-11-17 15:27:28 -080092 Rule: logtags,
93 Outputs: []string{javaFile},
94 Inputs: []string{logtagsFile},
Colin Crossf05fe972015-04-10 17:45:20 -070095 })
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}