blob: 993e6d1396e71ae4e59eb89cb7853164983adb38 [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")
Inseob Kim108be542018-10-04 19:39:35 +090029 pctx.HostBinToolVariable("syspropCmd", "sysprop_java")
Dan Willemsen34cc69e2015-09-23 15:26:20 -070030 pctx.SourcePathVariable("logtagsCmd", "build/tools/java-event-log-tags.py")
31 pctx.SourcePathVariable("mergeLogtagsCmd", "build/tools/merge-event-log-tags.py")
Colin Crossc0b06f12015-04-08 13:03:43 -070032}
33
34var (
Colin Cross9d45bb72016-08-29 16:14:13 -070035 aidl = pctx.AndroidStaticRule("aidl",
Colin Crossc0b06f12015-04-08 13:03:43 -070036 blueprint.RuleParams{
37 Command: "$aidlCmd -d$depFile $aidlFlags $in $out",
Dan Willemsenc94a7682015-11-17 15:27:28 -080038 CommandDeps: []string{"$aidlCmd"},
Colin Crossc0b06f12015-04-08 13:03:43 -070039 },
40 "depFile", "aidlFlags")
Colin Crossf05fe972015-04-10 17:45:20 -070041
Colin Cross9d45bb72016-08-29 16:14:13 -070042 logtags = pctx.AndroidStaticRule("logtags",
Colin Crossf05fe972015-04-10 17:45:20 -070043 blueprint.RuleParams{
Colin Crossb1bd1aa2017-11-15 22:47:16 -080044 Command: "$logtagsCmd -o $out $in",
Dan Willemsenc94a7682015-11-17 15:27:28 -080045 CommandDeps: []string{"$logtagsCmd"},
Colin Crossf05fe972015-04-10 17:45:20 -070046 })
47
Colin Cross9d45bb72016-08-29 16:14:13 -070048 mergeLogtags = pctx.AndroidStaticRule("mergeLogtags",
Colin Crossf05fe972015-04-10 17:45:20 -070049 blueprint.RuleParams{
50 Command: "$mergeLogtagsCmd -o $out $in",
Dan Willemsenc94a7682015-11-17 15:27:28 -080051 CommandDeps: []string{"$mergeLogtagsCmd"},
Colin Crossf05fe972015-04-10 17:45:20 -070052 })
Inseob Kim108be542018-10-04 19:39:35 +090053
54 sysprop = pctx.AndroidStaticRule("sysprop",
55 blueprint.RuleParams{
56 Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
57 `$syspropCmd --java-output-dir $out.tmp $in && ` +
58 `${config.SoongZipCmd} -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
59 CommandDeps: []string{
60 "$syspropCmd",
61 "${config.SoongZipCmd}",
62 },
63 })
Colin Crossc0b06f12015-04-08 13:03:43 -070064)
65
Colin Cross635c3b02016-05-18 15:37:25 -070066func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string) android.Path {
Dan Willemsen21ec4902016-11-02 20:43:13 -070067 javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java")
Dan Willemsen34cc69e2015-09-23 15:26:20 -070068 depFile := javaFile.String() + ".d"
Colin Crossc0b06f12015-04-08 13:03:43 -070069
Colin Crossae887032017-10-23 17:16:14 -070070 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070071 Rule: aidl,
72 Description: "aidl " + aidlFile.Rel(),
73 Output: javaFile,
74 Input: aidlFile,
Colin Crossc0b06f12015-04-08 13:03:43 -070075 Args: map[string]string{
76 "depFile": depFile,
77 "aidlFlags": aidlFlags,
78 },
79 })
80
81 return javaFile
82}
83
Colin Cross635c3b02016-05-18 15:37:25 -070084func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path {
Dan Willemsen21ec4902016-11-02 20:43:13 -070085 javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java")
Colin Crossf05fe972015-04-10 17:45:20 -070086
Colin Crossae887032017-10-23 17:16:14 -070087 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070088 Rule: logtags,
89 Description: "logtags " + logtagsFile.Rel(),
90 Output: javaFile,
91 Input: logtagsFile,
Colin Crossf05fe972015-04-10 17:45:20 -070092 })
93
94 return javaFile
95}
96
Inseob Kim108be542018-10-04 19:39:35 +090097func genSysprop(ctx android.ModuleContext, syspropFile android.Path) android.Path {
98 srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar")
99
100 ctx.Build(pctx, android.BuildParams{
101 Rule: sysprop,
102 Description: "sysprop_java " + syspropFile.Rel(),
103 Output: srcJarFile,
104 Input: syspropFile,
105 })
106
107 return srcJarFile
108}
109
Colin Cross46c9b8b2017-06-22 16:51:17 -0700110func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Colin Crossaf050172017-11-15 23:01:59 -0800111 flags javaBuilderFlags) android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700112
Colin Cross6af17aa2017-09-20 12:59:05 -0700113 outSrcFiles := make(android.Paths, 0, len(srcFiles))
114
115 for _, srcFile := range srcFiles {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700116 switch srcFile.Ext() {
Colin Crossc0b06f12015-04-08 13:03:43 -0700117 case ".aidl":
118 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700119 outSrcFiles = append(outSrcFiles, javaFile)
Colin Crossf05fe972015-04-10 17:45:20 -0700120 case ".logtags":
121 j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
122 javaFile := genLogtags(ctx, srcFile)
Colin Cross6af17aa2017-09-20 12:59:05 -0700123 outSrcFiles = append(outSrcFiles, javaFile)
124 case ".proto":
Dan Willemsenab9f4262018-02-14 13:58:34 -0800125 srcJarFile := genProto(ctx, srcFile, flags)
126 outSrcFiles = append(outSrcFiles, srcJarFile)
Inseob Kim108be542018-10-04 19:39:35 +0900127 case ".sysprop":
128 srcJarFile := genSysprop(ctx, srcFile)
129 outSrcFiles = append(outSrcFiles, srcJarFile)
Colin Cross6af17aa2017-09-20 12:59:05 -0700130 default:
131 outSrcFiles = append(outSrcFiles, srcFile)
Colin Crossc0b06f12015-04-08 13:03:43 -0700132 }
133 }
134
Colin Crossaf050172017-11-15 23:01:59 -0800135 return outSrcFiles
Colin Crossc0b06f12015-04-08 13:03:43 -0700136}
Colin Crossf05fe972015-04-10 17:45:20 -0700137
Colin Cross0875c522017-11-28 17:34:01 -0800138func LogtagsSingleton() android.Singleton {
Colin Crossf05fe972015-04-10 17:45:20 -0700139 return &logtagsSingleton{}
140}
141
142type logtagsProducer interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700143 logtags() android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700144}
145
146type logtagsSingleton struct{}
147
Colin Cross0875c522017-11-28 17:34:01 -0800148func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700149 var allLogtags android.Paths
Colin Cross0875c522017-11-28 17:34:01 -0800150 ctx.VisitAllModules(func(module android.Module) {
Colin Crossf05fe972015-04-10 17:45:20 -0700151 if logtags, ok := module.(logtagsProducer); ok {
152 allLogtags = append(allLogtags, logtags.logtags()...)
153 }
154 })
155
Colin Cross0875c522017-11-28 17:34:01 -0800156 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700157 Rule: mergeLogtags,
158 Description: "merge logtags",
Colin Cross0875c522017-11-28 17:34:01 -0800159 Output: android.PathForIntermediates(ctx, "all-event-log-tags.txt"),
160 Inputs: allLogtags,
Colin Crossf05fe972015-04-10 17:45:20 -0700161 })
162}