blob: 69739155ba7d6925180d1c89d1ff76baad22b314 [file] [log] [blame]
Colin Cross2fe66872015-03-30 17:20:39 -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 contains the module types for compiling Java for Android, and converts the properties
Colin Cross46c9b8b2017-06-22 16:51:17 -070018// into the flags and filenames necessary to pass to the Module. The final creation of the rules
Colin Cross2fe66872015-03-30 17:20:39 -070019// is handled in builder.go
20
21import (
22 "fmt"
Colin Crossfc3674a2017-09-18 17:41:52 -070023 "path/filepath"
Colin Cross74d73e22017-08-02 11:05:49 -070024 "strconv"
Colin Cross2fe66872015-03-30 17:20:39 -070025 "strings"
26
27 "github.com/google/blueprint"
Colin Cross76b5f0c2017-08-29 16:02:06 -070028 "github.com/google/blueprint/proptools"
Colin Cross2fe66872015-03-30 17:20:39 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Cross3e3e72d2017-06-22 17:20:19 -070031 "android/soong/java/config"
Colin Cross2fe66872015-03-30 17:20:39 -070032)
33
Colin Cross463a90e2015-06-17 14:20:06 -070034func init() {
Colin Cross89536d42017-07-07 14:35:50 -070035 android.RegisterModuleType("java_defaults", defaultsFactory)
36
Colin Crossa60ead82017-10-02 18:10:21 -070037 android.RegisterModuleType("java_library", LibraryFactory(true))
38 android.RegisterModuleType("java_library_static", LibraryFactory(false))
Colin Crossf506d872017-07-19 15:53:04 -070039 android.RegisterModuleType("java_library_host", LibraryHostFactory)
40 android.RegisterModuleType("java_binary", BinaryFactory)
41 android.RegisterModuleType("java_binary_host", BinaryHostFactory)
Colin Cross74d73e22017-08-02 11:05:49 -070042 android.RegisterModuleType("java_import", ImportFactory)
43 android.RegisterModuleType("java_import_host", ImportFactoryHost)
Colin Cross798bfce2016-10-12 14:28:16 -070044 android.RegisterModuleType("android_app", AndroidAppFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070045
Colin Cross798bfce2016-10-12 14:28:16 -070046 android.RegisterSingletonType("logtags", LogtagsSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -070047}
48
Colin Cross2fe66872015-03-30 17:20:39 -070049// TODO:
50// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070051// Renderscript
52// Post-jar passes:
53// Proguard
Colin Crossba211132017-06-22 15:36:39 -070054// Jacoco
Colin Cross2fe66872015-03-30 17:20:39 -070055// Jarjar
56// Dex
57// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -070058// DroidDoc
59// Findbugs
60
Colin Cross89536d42017-07-07 14:35:50 -070061type CompilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -070062 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
63 // or .aidl files.
Dan Willemsen2ef08f42015-06-30 18:15:24 -070064 Srcs []string `android:"arch_variant"`
65
66 // list of source files that should not be used to build the Java module.
67 // This is most useful in the arch/multilib variants to remove non-common files
68 Exclude_srcs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070069
70 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -070071 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070072
Colin Cross86a63ff2017-09-27 17:33:10 -070073 // list of directories that should be excluded from java_resource_dirs
74 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -070075
Colin Cross0f37af02017-09-27 17:42:05 -070076 // list of files to use as Java resources
77 Java_resources []string `android:"arch_variant"`
78
79 // list of files that should be excluded from java_resources
80 Exclude_java_resources []string `android:"arch_variant"`
81
Colin Crossfa5eb232017-10-01 20:33:03 -070082 // don't build against the default libraries (bootclasspath, legacy-test, core-junit,
Colin Cross7d5136f2015-05-11 13:39:40 -070083 // ext, and framework for device targets)
Colin Cross76b5f0c2017-08-29 16:02:06 -070084 No_standard_libs *bool
Colin Cross7d5136f2015-05-11 13:39:40 -070085
Colin Crossfa5eb232017-10-01 20:33:03 -070086 // don't build against the framework libraries (legacy-test, core-junit,
87 // ext, and framework for device targets)
88 No_framework_libs *bool
89
Colin Cross7d5136f2015-05-11 13:39:40 -070090 // list of module-specific flags that will be used for javac compiles
91 Javacflags []string `android:"arch_variant"`
92
Colin Cross7d5136f2015-05-11 13:39:40 -070093 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -070094 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070095
96 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -070097 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070098
99 // manifest file to be included in resulting jar
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700100 Manifest *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700101
Colin Cross540eff82017-06-22 17:01:52 -0700102 // if not blank, run jarjar using the specified rules file
Colin Cross975f9f72017-10-17 13:55:55 -0700103 Jarjar_rules *string `android:"arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700104
105 // If not blank, set the java version passed to javac as -source and -target
106 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700107
108 // If set to false, don't allow this module to be installed. Defaults to true.
109 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700110
Colin Cross0f37af02017-09-27 17:42:05 -0700111 // If set to true, include sources used to compile the module in to the final jar
112 Include_srcs *bool
113
Colin Cross32f676a2017-09-06 13:41:06 -0700114 // List of modules to use as annotation processors
115 Annotation_processors []string
116
117 // List of classes to pass to javac to use as annotation processors
118 Annotation_processor_classes []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700119
120 Openjdk9 struct {
121 // List of source files that should only be used when passing -source 1.9
122 Srcs []string
123
124 // List of javac flags that should only be used when passing -source 1.9
125 Javacflags []string
126 }
Colin Cross540eff82017-06-22 17:01:52 -0700127}
128
Colin Cross89536d42017-07-07 14:35:50 -0700129type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700130 // list of module-specific flags that will be used for dex compiles
131 Dxflags []string `android:"arch_variant"`
132
Colin Cross7d5136f2015-05-11 13:39:40 -0700133 // if not blank, set to the version of the sdk to compile against
134 Sdk_version string
135
Colin Cross7d5136f2015-05-11 13:39:40 -0700136 // directories to pass to aidl tool
137 Aidl_includes []string
138
139 // directories that should be added as include directories
140 // for any aidl sources of modules that depend on this module
141 Export_aidl_include_dirs []string
Colin Cross92430102017-10-09 14:59:32 -0700142
143 // If true, export a copy of the module as a -hostdex module for host testing.
144 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700145
Colin Crossa22116e2017-10-19 14:18:58 -0700146 // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to
147 // true.
148 Dex_preopt *bool
149
Colin Cross1369cdb2017-09-29 17:58:17 -0700150 // When targeting 1.9, override the modules to use with --system
151 System_modules *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700152}
153
Colin Cross46c9b8b2017-06-22 16:51:17 -0700154// Module contains the properties and members used by all java module types
155type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700156 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700157 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700158
Colin Cross89536d42017-07-07 14:35:50 -0700159 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700160 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700161 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700162
163 // output file suitable for inserting into the classpath of another compile
Colin Cross635c3b02016-05-18 15:37:25 -0700164 classpathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700165
Colin Cross6ade34f2017-09-15 13:00:47 -0700166 // output file containing classes.dex
167 dexJarFile android.Path
168
Colin Crossb7a63242015-04-16 14:09:14 -0700169 // output file suitable for installing or running
Colin Cross635c3b02016-05-18 15:37:25 -0700170 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700171
Colin Cross635c3b02016-05-18 15:37:25 -0700172 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700173
Colin Cross635c3b02016-05-18 15:37:25 -0700174 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700175
Colin Cross59149b62017-10-16 18:07:29 -0700176 // jars containing source files that should be included in the javac command line,
Colin Crossb7a63242015-04-16 14:09:14 -0700177 // for example R.java generated by aapt for android apps
Colin Cross59149b62017-10-16 18:07:29 -0700178 ExtraSrcJars android.Paths
Colin Crossb7a63242015-04-16 14:09:14 -0700179
Colin Cross2fe66872015-03-30 17:20:39 -0700180 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700181 installFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700182}
183
Colin Crossf506d872017-07-19 15:53:04 -0700184type Dependency interface {
Colin Cross74d73e22017-08-02 11:05:49 -0700185 ClasspathFiles() android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700186 AidlIncludeDirs() android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700187}
188
Colin Cross89536d42017-07-07 14:35:50 -0700189func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
190 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
191 android.InitDefaultableModule(module)
192}
193
Colin Crossbe1da472017-07-07 15:59:46 -0700194type dependencyTag struct {
195 blueprint.BaseDependencyTag
196 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700197}
198
Colin Crossbe1da472017-07-07 15:59:46 -0700199var (
Colin Cross6ade34f2017-09-15 13:00:47 -0700200 staticLibTag = dependencyTag{name: "staticlib"}
201 libTag = dependencyTag{name: "javalib"}
202 bootClasspathTag = dependencyTag{name: "bootclasspath"}
Colin Cross1369cdb2017-09-29 17:58:17 -0700203 systemModulesTag = dependencyTag{name: "system modules"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700204 frameworkResTag = dependencyTag{name: "framework-res"}
Colin Cross93e85952017-08-15 13:34:18 -0700205 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossbe1da472017-07-07 15:59:46 -0700206)
Colin Cross2fe66872015-03-30 17:20:39 -0700207
Colin Crossfc3674a2017-09-18 17:41:52 -0700208type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700209 useModule, useFiles, useDefaultLibs, invalidVersion bool
210
Colin Cross1369cdb2017-09-29 17:58:17 -0700211 module string
212 systemModules string
213
214 jar android.Path
215 aidl android.Path
216}
217
218func sdkStringToNumber(ctx android.BaseContext, v string) int {
219 switch v {
220 case "", "current", "system_current", "test_current":
221 return 10000
222 default:
223 if i, err := strconv.Atoi(v); err != nil {
224 ctx.PropertyErrorf("sdk_version", "invalid sdk version")
225 return -1
226 } else {
227 return i
228 }
229 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700230}
231
232func decodeSdkDep(ctx android.BaseContext, v string) sdkDep {
Colin Cross1369cdb2017-09-29 17:58:17 -0700233 i := sdkStringToNumber(ctx, v)
234 if i == -1 {
235 // Invalid sdk version, error handled by sdkStringToNumber.
236 return sdkDep{}
Colin Crossfc3674a2017-09-18 17:41:52 -0700237 }
238
239 toFile := func(v string) sdkDep {
240 dir := filepath.Join("prebuilts/sdk", v)
241 jar := filepath.Join(dir, "android.jar")
242 aidl := filepath.Join(dir, "framework.aidl")
243 jarPath := android.ExistentPathForSource(ctx, "sdkdir", jar)
244 aidlPath := android.ExistentPathForSource(ctx, "sdkdir", aidl)
Colin Cross47ff2522017-10-02 14:22:08 -0700245
246 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.AConfig().AllowMissingDependencies() {
247 return sdkDep{
248 invalidVersion: true,
249 module: "sdk_v" + v,
250 }
251 }
252
Colin Crossfc3674a2017-09-18 17:41:52 -0700253 if !jarPath.Valid() {
254 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar)
255 return sdkDep{}
256 }
Colin Cross47ff2522017-10-02 14:22:08 -0700257
Colin Crossfc3674a2017-09-18 17:41:52 -0700258 if !aidlPath.Valid() {
259 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl)
260 return sdkDep{}
261 }
Colin Cross47ff2522017-10-02 14:22:08 -0700262
Colin Crossfc3674a2017-09-18 17:41:52 -0700263 return sdkDep{
264 useFiles: true,
265 jar: jarPath.Path(),
266 aidl: aidlPath.Path(),
267 }
268 }
269
270 toModule := func(m string) sdkDep {
271 return sdkDep{
Colin Cross1369cdb2017-09-29 17:58:17 -0700272 useModule: true,
273 module: m,
274 systemModules: m + "_system_modules",
Colin Crossfc3674a2017-09-18 17:41:52 -0700275 }
276 }
277
Colin Cross8b9d37b2017-09-22 15:30:06 -0700278 if ctx.AConfig().UnbundledBuild() && v != "" {
Colin Crossfc3674a2017-09-18 17:41:52 -0700279 return toFile(v)
280 }
281
282 switch v {
283 case "":
284 return sdkDep{
285 useDefaultLibs: true,
286 }
287 case "current":
288 return toModule("android_stubs_current")
289 case "system_current":
290 return toModule("android_system_stubs_current")
291 case "test_current":
292 return toModule("android_test_stubs_current")
293 default:
294 return toFile(v)
295 }
296}
297
Colin Crossbe1da472017-07-07 15:59:46 -0700298func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700299 if ctx.Device() {
300 if !proptools.Bool(j.properties.No_standard_libs) {
Colin Crossfc3674a2017-09-18 17:41:52 -0700301 sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version)
302 if sdkDep.useDefaultLibs {
Colin Crosscb2c9292017-09-23 19:57:16 -0700303 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Colin Cross1369cdb2017-09-29 17:58:17 -0700304 if ctx.AConfig().TargetOpenJDK9() {
305 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
306 }
Colin Crossfa5eb232017-10-01 20:33:03 -0700307 if !proptools.Bool(j.properties.No_framework_libs) {
308 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
309 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700310 } else if sdkDep.useModule {
311 if ctx.AConfig().TargetOpenJDK9() {
312 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
313 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700314 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module)
Colin Crossbe1da472017-07-07 15:59:46 -0700315 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700316 } else if j.deviceProperties.System_modules == nil {
317 ctx.PropertyErrorf("no_standard_libs",
318 "system_modules is required to be set when no_standard_libs is true, did you mean no_framework_libs?")
319 } else if *j.deviceProperties.System_modules != "none" && ctx.AConfig().TargetOpenJDK9() {
320 ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700321 }
322 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700323
Colin Crossf506d872017-07-19 15:53:04 -0700324 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
325 ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
Colin Cross6ade34f2017-09-15 13:00:47 -0700326 ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...)
Colin Cross7f9036c2017-08-30 13:27:57 -0700327
328 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700329 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross6af17aa2017-09-20 12:59:05 -0700330
331 if j.hasSrcExt(".proto") {
332 protoDeps(ctx, &j.protoProperties)
333 }
Colin Cross93e85952017-08-15 13:34:18 -0700334
335 if j.hasSrcExt(".kt") {
336 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
337 // Kotlin files
338 ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib")
339 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700340}
341
342func hasSrcExt(srcs []string, ext string) bool {
343 for _, src := range srcs {
344 if filepath.Ext(src) == ext {
345 return true
346 }
347 }
348
349 return false
350}
351
352func (j *Module) hasSrcExt(ext string) bool {
353 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700354}
355
Colin Cross46c9b8b2017-06-22 16:51:17 -0700356func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700357 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700358
Colin Cross540eff82017-06-22 17:01:52 -0700359 localAidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl_includes)
Colin Crossc0b06f12015-04-08 13:03:43 -0700360
361 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700362 if aidlPreprocess.Valid() {
363 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700364 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700365 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700366 }
367
Colin Cross635c3b02016-05-18 15:37:25 -0700368 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
369 flags = append(flags, android.JoinWithPrefix(localAidlIncludes.Strings(), "-I"))
370 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Crossd48633a2017-07-13 14:41:17 -0700371 if src := android.ExistentPathForSource(ctx, "", "src"); src.Valid() {
372 flags = append(flags, "-I"+src.String())
373 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700374
Colin Crossf03c82b2015-04-13 13:53:40 -0700375 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700376}
377
Colin Cross32f676a2017-09-06 13:41:06 -0700378type deps struct {
Colin Cross6ade34f2017-09-15 13:00:47 -0700379 classpath android.Paths
380 bootClasspath android.Paths
381 staticJars android.Paths
382 staticJarResources android.Paths
383 aidlIncludeDirs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700384 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700385 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700386 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700387 kotlinStdlib android.Paths
Colin Cross32f676a2017-09-06 13:41:06 -0700388}
Colin Cross2fe66872015-03-30 17:20:39 -0700389
Colin Cross32f676a2017-09-06 13:41:06 -0700390func (j *Module) collectDeps(ctx android.ModuleContext) deps {
391 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700392
393 sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version)
Colin Cross47ff2522017-10-02 14:22:08 -0700394 if sdkDep.invalidVersion {
395 ctx.AddMissingDependencies([]string{sdkDep.module})
396 } else if sdkDep.useFiles {
Colin Crossfc3674a2017-09-18 17:41:52 -0700397 deps.classpath = append(deps.classpath, sdkDep.jar)
398 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
399 }
400
Colin Cross2fe66872015-03-30 17:20:39 -0700401 ctx.VisitDirectDeps(func(module blueprint.Module) {
402 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700403 tag := ctx.OtherModuleDependencyTag(module)
404
Colin Crossf506d872017-07-19 15:53:04 -0700405 dep, _ := module.(Dependency)
406 if dep == nil {
Colin Crossec7a0422017-07-07 14:47:12 -0700407 switch tag {
408 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700409 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700410 case systemModulesTag:
411 if deps.systemModules != nil {
412 panic("Found two system module dependencies")
413 }
414 sm := module.(*SystemModules)
415 if sm.outputFile == nil {
416 panic("Missing directory for system module dependency")
417 }
418 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700419 default:
420 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700421 }
Colin Crossec7a0422017-07-07 14:47:12 -0700422 return
423 }
424
Colin Crossbe1da472017-07-07 15:59:46 -0700425 switch tag {
426 case bootClasspathTag:
Colin Cross32f676a2017-09-06 13:41:06 -0700427 deps.bootClasspath = append(deps.bootClasspath, dep.ClasspathFiles()...)
Colin Crossf506d872017-07-19 15:53:04 -0700428 case libTag:
Colin Cross32f676a2017-09-06 13:41:06 -0700429 deps.classpath = append(deps.classpath, dep.ClasspathFiles()...)
Colin Crossf506d872017-07-19 15:53:04 -0700430 case staticLibTag:
Colin Cross32f676a2017-09-06 13:41:06 -0700431 deps.classpath = append(deps.classpath, dep.ClasspathFiles()...)
432 deps.staticJars = append(deps.staticJars, dep.ClasspathFiles()...)
Colin Crossbe1da472017-07-07 15:59:46 -0700433 case frameworkResTag:
Colin Crossec7a0422017-07-07 14:47:12 -0700434 if ctx.ModuleName() == "framework" {
435 // framework.jar has a one-off dependency on the R.java and Manifest.java files
436 // generated by framework-res.apk
Colin Cross59149b62017-10-16 18:07:29 -0700437 // TODO(ccross): aapt java files should go in a src jar
Colin Crossec7a0422017-07-07 14:47:12 -0700438 }
Colin Cross93e85952017-08-15 13:34:18 -0700439 case kotlinStdlibTag:
440 deps.kotlinStdlib = dep.ClasspathFiles()
Colin Crossbe1da472017-07-07 15:59:46 -0700441 default:
442 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
Colin Cross2fe66872015-03-30 17:20:39 -0700443 }
Colin Crossbe1da472017-07-07 15:59:46 -0700444
Colin Cross32f676a2017-09-06 13:41:06 -0700445 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2fe66872015-03-30 17:20:39 -0700446 })
447
Colin Cross32f676a2017-09-06 13:41:06 -0700448 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700449}
450
Colin Cross46c9b8b2017-06-22 16:51:17 -0700451func (j *Module) compile(ctx android.ModuleContext) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700452
Colin Cross540eff82017-06-22 17:01:52 -0700453 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Export_aidl_include_dirs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700454
Colin Cross32f676a2017-09-06 13:41:06 -0700455 deps := j.collectDeps(ctx)
Colin Crossc0b06f12015-04-08 13:03:43 -0700456
Colin Crossf03c82b2015-04-13 13:53:40 -0700457 var flags javaBuilderFlags
458
459 javacFlags := j.properties.Javacflags
Colin Cross1369cdb2017-09-29 17:58:17 -0700460 if ctx.AConfig().TargetOpenJDK9() {
461 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
462 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
Colin Cross4f26bc02017-09-06 12:52:16 -0700463 }
Colin Cross64162712017-08-08 13:17:59 -0700464
Colin Cross1369cdb2017-09-29 17:58:17 -0700465 sdk := sdkStringToNumber(ctx, j.deviceProperties.Sdk_version)
Colin Cross64162712017-08-08 13:17:59 -0700466 if j.properties.Java_version != nil {
467 flags.javaVersion = *j.properties.Java_version
Colin Cross1369cdb2017-09-29 17:58:17 -0700468 } else if ctx.Device() && sdk <= 23 {
469 flags.javaVersion = "1.7"
470 } else if ctx.Device() && sdk <= 26 || !ctx.AConfig().TargetOpenJDK9() {
471 flags.javaVersion = "1.8"
Colin Cross64162712017-08-08 13:17:59 -0700472 } else {
Colin Cross1369cdb2017-09-29 17:58:17 -0700473 flags.javaVersion = "1.9"
Colin Cross64162712017-08-08 13:17:59 -0700474 }
475
Colin Cross6ade34f2017-09-15 13:00:47 -0700476 flags.bootClasspath.AddPaths(deps.bootClasspath)
477 flags.classpath.AddPaths(deps.classpath)
478
Colin Cross1369cdb2017-09-29 17:58:17 -0700479 if deps.systemModules != nil {
480 flags.systemModules = append(flags.systemModules, deps.systemModules)
481 }
482
Colin Crossf03c82b2015-04-13 13:53:40 -0700483 if len(javacFlags) > 0 {
484 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
485 flags.javacFlags = "$javacFlags"
486 }
487
Colin Cross32f676a2017-09-06 13:41:06 -0700488 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700489 if len(aidlFlags) > 0 {
490 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
491 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700492 }
493
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700494 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700495
Colin Cross6af17aa2017-09-20 12:59:05 -0700496 if hasSrcExt(srcFiles.Strings(), ".proto") {
497 flags = protoFlags(ctx, &j.protoProperties, flags)
498 }
499
Colin Cross59149b62017-10-16 18:07:29 -0700500 var srcJars classpath
501 srcFiles, srcJars = j.genSources(ctx, srcFiles, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700502
Colin Cross59149b62017-10-16 18:07:29 -0700503 srcJars = append(srcJars, deps.srcJars...)
Colin Cross6af17aa2017-09-20 12:59:05 -0700504
Colin Cross59149b62017-10-16 18:07:29 -0700505 srcJars = append(srcJars, j.ExtraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700506
Colin Cross0a6e0072017-08-30 14:24:55 -0700507 var jars android.Paths
508
Colin Cross1ee23172017-10-18 14:44:18 -0700509 jarName := ctx.ModuleName() + ".jar"
510
Colin Cross93e85952017-08-15 13:34:18 -0700511 if srcFiles.HasExt(".kt") {
512 // If there are kotlin files, compile them first but pass all the kotlin and java files
513 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
514 // won't emit any classes for them.
515
516 flags.kotlincFlags = "-no-stdlib"
517 if ctx.Device() {
518 flags.kotlincFlags += " -no-jdk"
519 }
520
521 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
522 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
523
Colin Cross1ee23172017-10-18 14:44:18 -0700524 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross93e85952017-08-15 13:34:18 -0700525 TransformKotlinToClasses(ctx, kotlinJar, srcFiles, srcJars, flags)
526 if ctx.Failed() {
527 return
528 }
529
530 // Make javac rule depend on the kotlinc rule
531 flags.classpath = append(flags.classpath, kotlinJar)
532 // Jar kotlin classes into the final jar after javac
533 jars = append(jars, kotlinJar)
534 jars = append(jars, deps.kotlinStdlib...)
535 }
536
537 if javaSrcFiles := srcFiles.FilterByExt(".java"); len(javaSrcFiles) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -0700538 var extraJarDeps android.Paths
Colin Crossc6bbef32017-08-14 14:16:06 -0700539 if ctx.AConfig().IsEnvTrue("RUN_ERROR_PRONE") {
540 // If error-prone is enabled, add an additional rule to compile the java files into
541 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -0700542 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -0700543 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
544 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -0700545 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Colin Cross93e85952017-08-15 13:34:18 -0700546 RunErrorProne(ctx, errorprone, javaSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -0700547 extraJarDeps = append(extraJarDeps, errorprone)
548 }
549
Colin Crossd6891432017-09-27 17:39:56 -0700550 // Compile java sources into .class files
Colin Cross1ee23172017-10-18 14:44:18 -0700551 classes := android.PathForModuleOut(ctx, "javac", jarName)
Colin Cross93e85952017-08-15 13:34:18 -0700552 TransformJavaToClasses(ctx, classes, javaSrcFiles, srcJars, flags, extraJarDeps)
Colin Crossd6891432017-09-27 17:39:56 -0700553 if ctx.Failed() {
554 return
555 }
556
Colin Cross0a6e0072017-08-30 14:24:55 -0700557 jars = append(jars, classes)
Colin Cross2fe66872015-03-30 17:20:39 -0700558 }
559
Colin Cross0f37af02017-09-27 17:42:05 -0700560 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
561 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
562
563 var resArgs []string
564 var resDeps android.Paths
565
566 resArgs = append(resArgs, dirArgs...)
567 resDeps = append(resDeps, dirDeps...)
568
569 resArgs = append(resArgs, fileArgs...)
570 resDeps = append(resDeps, fileDeps...)
571
572 if proptools.Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -0700573 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700574 resArgs = append(resArgs, srcArgs...)
575 resDeps = append(resDeps, srcDeps...)
576 }
Colin Cross40a36712017-09-27 17:41:35 -0700577
578 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -0700579 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700580 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -0700581 if ctx.Failed() {
582 return
583 }
Colin Cross20978302015-04-10 17:05:07 -0700584
Colin Cross0a6e0072017-08-30 14:24:55 -0700585 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -0700586 }
587
Colin Cross6ade34f2017-09-15 13:00:47 -0700588 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -0700589 jars = append(jars, deps.staticJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -0700590
Colin Cross635acc92017-09-12 22:50:46 -0700591 manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
592
Colin Cross0a6e0072017-08-30 14:24:55 -0700593 // Combine the classes built from sources, any manifests, and any static libraries into
Colin Cross8649b262017-09-27 18:03:17 -0700594 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -0700595 var outputFile android.Path
596
597 if len(jars) == 1 && !manifest.Valid() {
598 // Optimization: skip the combine step if there is nothing to do
599 outputFile = jars[0]
600 } else {
Colin Cross1ee23172017-10-18 14:44:18 -0700601 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700602 TransformJarsToJar(ctx, combinedJar, jars, manifest, false)
603 outputFile = combinedJar
604 }
Colin Cross0a6e0072017-08-30 14:24:55 -0700605
606 if j.properties.Jarjar_rules != nil {
607 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -0700608 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -0700609 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700610 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
611 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -0700612 if ctx.Failed() {
613 return
614 }
615 }
616
Colin Cross2fe66872015-03-30 17:20:39 -0700617 j.classpathFile = outputFile
618
Colin Crossc157a8d2017-10-03 17:17:07 -0700619 if ctx.Device() && j.installable() {
Colin Cross540eff82017-06-22 17:01:52 -0700620 dxFlags := j.deviceProperties.Dxflags
Colin Cross2fe66872015-03-30 17:20:39 -0700621 if false /* emma enabled */ {
622 // If you instrument class files that have local variable debug information in
623 // them emma does not correctly maintain the local variable table.
624 // This will cause an error when you try to convert the class files for Android.
625 // The workaround here is to build different dex file here based on emma switch
626 // then later copy into classes.dex. When emma is on, dx is run with --no-locals
627 // option to remove local variable information
628 dxFlags = append(dxFlags, "--no-locals")
629 }
630
Colin Cross1332b002015-04-07 17:11:30 -0700631 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700632 dxFlags = append(dxFlags, "--no-optimize")
633 }
634
Colin Cross1332b002015-04-07 17:11:30 -0700635 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700636 dxFlags = append(dxFlags,
637 "--debug",
638 "--verbose",
Colin Cross635c3b02016-05-18 15:37:25 -0700639 "--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(),
Colin Cross2fe66872015-03-30 17:20:39 -0700640 "--dump-width=1000")
641 }
642
Colin Cross595a4062017-08-31 12:30:37 -0700643 var minSdkVersion string
644 switch j.deviceProperties.Sdk_version {
645 case "", "current", "test_current", "system_current":
646 minSdkVersion = strconv.Itoa(ctx.AConfig().DefaultAppTargetSdkInt())
647 default:
648 minSdkVersion = j.deviceProperties.Sdk_version
649 }
650
651 dxFlags = append(dxFlags, "--min-sdk-version="+minSdkVersion)
652
Colin Cross2fe66872015-03-30 17:20:39 -0700653 flags.dxFlags = strings.Join(dxFlags, " ")
654
Colin Cross6ade34f2017-09-15 13:00:47 -0700655 desugarFlags := []string{
656 "--min_sdk_version " + minSdkVersion,
657 "--desugar_try_with_resources_if_needed=false",
658 "--allow_empty_bootclasspath",
659 }
660
661 if inList("--core-library", dxFlags) {
662 desugarFlags = append(desugarFlags, "--core_library")
663 }
664
665 flags.desugarFlags = strings.Join(desugarFlags, " ")
666
Colin Cross1ee23172017-10-18 14:44:18 -0700667 desugarJar := android.PathForModuleOut(ctx, "desugar", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700668 TransformDesugar(ctx, desugarJar, outputFile, flags)
669 outputFile = desugarJar
Colin Cross2fe66872015-03-30 17:20:39 -0700670 if ctx.Failed() {
671 return
672 }
673
Colin Cross1ee23172017-10-18 14:44:18 -0700674 // Compile classes.jar into classes.dex and then a dex jar
675 dexJar := android.PathForModuleOut(ctx, "dex", jarName)
676 TransformClassesJarToDexJar(ctx, dexJar, desugarJar, flags)
677 outputFile = dexJar
Colin Cross6ade34f2017-09-15 13:00:47 -0700678 if ctx.Failed() {
679 return
680 }
681
Colin Cross6ade34f2017-09-15 13:00:47 -0700682 j.dexJarFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700683 }
Colin Crossb7a63242015-04-16 14:09:14 -0700684 ctx.CheckbuildFile(outputFile)
685 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700686}
687
Colin Cross59f1bb62017-09-27 17:59:10 -0700688func (j *Module) installable() bool {
689 return j.properties.Installable == nil || *j.properties.Installable
690}
691
Colin Crossf506d872017-07-19 15:53:04 -0700692var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700693
Colin Cross74d73e22017-08-02 11:05:49 -0700694func (j *Module) ClasspathFiles() android.Paths {
695 return android.Paths{j.classpathFile}
Colin Cross2fe66872015-03-30 17:20:39 -0700696}
697
Colin Cross46c9b8b2017-06-22 16:51:17 -0700698func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700699 return j.exportAidlIncludeDirs
700}
701
Colin Cross46c9b8b2017-06-22 16:51:17 -0700702var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -0700703
Colin Cross46c9b8b2017-06-22 16:51:17 -0700704func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -0700705 return j.logtagsSrcs
706}
707
Colin Cross2fe66872015-03-30 17:20:39 -0700708//
709// Java libraries (.jar file)
710//
711
Colin Crossf506d872017-07-19 15:53:04 -0700712type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700713 Module
Colin Cross2fe66872015-03-30 17:20:39 -0700714}
715
Colin Crossf506d872017-07-19 15:53:04 -0700716func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700717 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -0700718
Colin Cross59f1bb62017-09-27 17:59:10 -0700719 if j.installable() {
Colin Cross2c429dc2017-08-31 16:45:16 -0700720 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
721 ctx.ModuleName()+".jar", j.outputFile)
722 }
Colin Crossb7a63242015-04-16 14:09:14 -0700723}
724
Colin Crossf506d872017-07-19 15:53:04 -0700725func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700726 j.deps(ctx)
727}
728
Colin Crossa60ead82017-10-02 18:10:21 -0700729func LibraryFactory(installable bool) func() android.Module {
730 return func() android.Module {
731 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -0700732
Colin Crossa60ead82017-10-02 18:10:21 -0700733 if !installable {
734 module.properties.Installable = proptools.BoolPtr(false)
735 }
Colin Cross2fe66872015-03-30 17:20:39 -0700736
Colin Crossa60ead82017-10-02 18:10:21 -0700737 module.AddProperties(
738 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -0700739 &module.Module.deviceProperties,
740 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -0700741
Colin Crossa60ead82017-10-02 18:10:21 -0700742 InitJavaModule(module, android.HostAndDeviceSupported)
743 return module
744 }
Colin Cross2fe66872015-03-30 17:20:39 -0700745}
746
Colin Crossf506d872017-07-19 15:53:04 -0700747func LibraryHostFactory() android.Module {
748 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -0700749
Colin Cross6af17aa2017-09-20 12:59:05 -0700750 module.AddProperties(
751 &module.Module.properties,
752 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -0700753
Colin Cross89536d42017-07-07 14:35:50 -0700754 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -0700755 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700756}
757
758//
759// Java Binaries (.jar file plus wrapper script)
760//
761
Colin Crossf506d872017-07-19 15:53:04 -0700762type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700763 // installable script to execute the resulting jar
764 Wrapper string
765}
766
Colin Crossf506d872017-07-19 15:53:04 -0700767type Binary struct {
768 Library
Colin Cross2fe66872015-03-30 17:20:39 -0700769
Colin Crossf506d872017-07-19 15:53:04 -0700770 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -0700771
772 wrapperFile android.ModuleSrcPath
773 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -0700774}
775
Colin Crossf506d872017-07-19 15:53:04 -0700776func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
777 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross2fe66872015-03-30 17:20:39 -0700778
779 // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
780 // another build rule before the jar has been installed.
Colin Cross10a03492017-08-10 17:09:43 -0700781 j.wrapperFile = android.PathForModuleSrc(ctx, j.binaryProperties.Wrapper)
Colin Cross5c517922017-08-31 12:29:17 -0700782 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
783 ctx.ModuleName(), j.wrapperFile, j.installFile)
Colin Cross2fe66872015-03-30 17:20:39 -0700784}
785
Colin Crossf506d872017-07-19 15:53:04 -0700786func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700787 j.deps(ctx)
788}
789
Colin Crossf506d872017-07-19 15:53:04 -0700790func BinaryFactory() android.Module {
791 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -0700792
Colin Cross36242852017-06-23 15:06:31 -0700793 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700794 &module.Module.properties,
795 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -0700796 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -0700797 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -0700798
Colin Cross89536d42017-07-07 14:35:50 -0700799 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -0700800 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700801}
802
Colin Crossf506d872017-07-19 15:53:04 -0700803func BinaryHostFactory() android.Module {
804 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -0700805
Colin Cross36242852017-06-23 15:06:31 -0700806 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700807 &module.Module.properties,
808 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -0700809 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -0700810 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -0700811
Colin Cross89536d42017-07-07 14:35:50 -0700812 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -0700813 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700814}
815
816//
817// Java prebuilts
818//
819
Colin Cross74d73e22017-08-02 11:05:49 -0700820type ImportProperties struct {
821 Jars []string
822}
823
824type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700825 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -0700826 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -0700827
Colin Cross74d73e22017-08-02 11:05:49 -0700828 properties ImportProperties
829
Colin Cross0a6e0072017-08-30 14:24:55 -0700830 classpathFiles android.Paths
831 combinedClasspathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700832}
833
Colin Cross74d73e22017-08-02 11:05:49 -0700834func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -0700835 return &j.prebuilt
836}
837
Colin Cross74d73e22017-08-02 11:05:49 -0700838func (j *Import) PrebuiltSrcs() []string {
839 return j.properties.Jars
840}
841
842func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -0700843 return j.prebuilt.Name(j.ModuleBase.Name())
844}
845
Colin Cross74d73e22017-08-02 11:05:49 -0700846func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross1e676be2016-10-12 14:38:15 -0700847}
848
Colin Cross74d73e22017-08-02 11:05:49 -0700849func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
850 j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -0700851
Colin Crosse9a275b2017-10-16 17:09:48 -0700852 outputFile := android.PathForModuleOut(ctx, "classes.jar")
853 TransformJarsToJar(ctx, outputFile, j.classpathFiles, android.OptionalPath{}, false)
854 j.combinedClasspathFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700855}
856
Colin Cross74d73e22017-08-02 11:05:49 -0700857var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700858
Colin Cross74d73e22017-08-02 11:05:49 -0700859func (j *Import) ClasspathFiles() android.Paths {
860 return j.classpathFiles
Colin Cross2fe66872015-03-30 17:20:39 -0700861}
862
Colin Cross74d73e22017-08-02 11:05:49 -0700863func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700864 return nil
865}
866
Colin Cross74d73e22017-08-02 11:05:49 -0700867var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700868
Colin Cross74d73e22017-08-02 11:05:49 -0700869func ImportFactory() android.Module {
870 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -0700871
Colin Cross74d73e22017-08-02 11:05:49 -0700872 module.AddProperties(&module.properties)
873
874 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -0700875 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
876 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700877}
878
Colin Cross74d73e22017-08-02 11:05:49 -0700879func ImportFactoryHost() android.Module {
880 module := &Import{}
881
882 module.AddProperties(&module.properties)
883
884 android.InitPrebuiltModule(module, &module.properties.Jars)
885 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
886 return module
887}
888
Colin Cross2fe66872015-03-30 17:20:39 -0700889func inList(s string, l []string) bool {
890 for _, e := range l {
891 if e == s {
892 return true
893 }
894 }
895 return false
896}
Colin Cross89536d42017-07-07 14:35:50 -0700897
898//
899// Defaults
900//
901type Defaults struct {
902 android.ModuleBase
903 android.DefaultsModuleBase
904}
905
906func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
907}
908
909func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
910}
911
912func defaultsFactory() android.Module {
913 return DefaultsFactory()
914}
915
916func DefaultsFactory(props ...interface{}) android.Module {
917 module := &Defaults{}
918
919 module.AddProperties(props...)
920 module.AddProperties(
921 &CompilerProperties{},
922 &CompilerDeviceProperties{},
923 )
924
925 android.InitDefaultsModule(module)
926
927 return module
928}