blob: 6e8313a9554c076f6e3bc7539bb8e19fb7ae7cd9 [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",
47 Description: "aidl $out",
48 },
49 "depFile", "aidlFlags")
Colin Crossf05fe972015-04-10 17:45:20 -070050
51 logtags = pctx.StaticRule("logtags",
52 blueprint.RuleParams{
53 Command: "$logtagsCmd -o $out $in $allLogtagsFile",
54 Description: "logtags $out",
55 })
56
57 mergeLogtags = pctx.StaticRule("mergeLogtags",
58 blueprint.RuleParams{
59 Command: "$mergeLogtagsCmd -o $out $in",
60 Description: "merge logtags $out",
61 })
Colin Crossc0b06f12015-04-08 13:03:43 -070062)
63
64func genAidl(ctx common.AndroidModuleContext, aidlFile, aidlFlags string) string {
Colin Cross6e18ca42015-07-14 18:55:36 -070065 javaFile := common.SrcDirRelPath(ctx, aidlFile)
Colin Crossc0b06f12015-04-08 13:03:43 -070066 javaFile = filepath.Join(common.ModuleGenDir(ctx), javaFile)
67 javaFile = pathtools.ReplaceExtension(javaFile, "java")
68 depFile := javaFile + ".d"
69
70 ctx.Build(pctx, blueprint.BuildParams{
71 Rule: aidl,
72 Outputs: []string{javaFile},
73 Inputs: []string{aidlFile},
74 Implicits: []string{"$aidlCmd"},
75 Args: map[string]string{
76 "depFile": depFile,
77 "aidlFlags": aidlFlags,
78 },
79 })
80
81 return javaFile
82}
83
Colin Crossf05fe972015-04-10 17:45:20 -070084func genLogtags(ctx common.AndroidModuleContext, logtagsFile string) string {
Colin Cross6e18ca42015-07-14 18:55:36 -070085 javaFile := common.SrcDirRelPath(ctx, logtagsFile)
Colin Crossf05fe972015-04-10 17:45:20 -070086 javaFile = filepath.Join(common.ModuleGenDir(ctx), javaFile)
87 javaFile = pathtools.ReplaceExtension(javaFile, "java")
88
89 ctx.Build(pctx, blueprint.BuildParams{
90 Rule: logtags,
91 Outputs: []string{javaFile},
92 Inputs: []string{logtagsFile},
93 Implicits: []string{"$logtagsCmd"},
94 })
95
96 return javaFile
97}
98
99func (j *javaBase) genSources(ctx common.AndroidModuleContext, srcFiles []string,
Colin Crossc0b06f12015-04-08 13:03:43 -0700100 flags javaBuilderFlags) []string {
101
102 for i, srcFile := range srcFiles {
103 switch filepath.Ext(srcFile) {
104 case ".aidl":
105 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
106 srcFiles[i] = javaFile
Colin Crossf05fe972015-04-10 17:45:20 -0700107 case ".logtags":
108 j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
109 javaFile := genLogtags(ctx, srcFile)
110 srcFiles[i] = javaFile
Colin Crossc0b06f12015-04-08 13:03:43 -0700111 }
112 }
113
114 return srcFiles
115}
Colin Crossf05fe972015-04-10 17:45:20 -0700116
117func LogtagsSingleton() blueprint.Singleton {
118 return &logtagsSingleton{}
119}
120
121type logtagsProducer interface {
122 logtags() []string
123}
124
125type logtagsSingleton struct{}
126
127func (l *logtagsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
128 var allLogtags []string
129 ctx.VisitAllModules(func(module blueprint.Module) {
130 if logtags, ok := module.(logtagsProducer); ok {
131 allLogtags = append(allLogtags, logtags.logtags()...)
132 }
133 })
134
135 ctx.Build(pctx, blueprint.BuildParams{
136 Rule: mergeLogtags,
137 Outputs: []string{"$allLogtagsFile"},
138 Inputs: allLogtags,
139 })
140}