blob: 3382cf2898aa717516d516b2e823f8bfaaeea612 [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
103 Jarjar_rules *string
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
146 // When targeting 1.9, override the modules to use with --system
147 System_modules *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700148}
149
Colin Cross46c9b8b2017-06-22 16:51:17 -0700150// Module contains the properties and members used by all java module types
151type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700152 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700153 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700154
Colin Cross89536d42017-07-07 14:35:50 -0700155 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700156 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700157 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700158
159 // output file suitable for inserting into the classpath of another compile
Colin Cross635c3b02016-05-18 15:37:25 -0700160 classpathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700161
Colin Cross6ade34f2017-09-15 13:00:47 -0700162 // output file containing classes.dex
163 dexJarFile android.Path
164
Colin Crossb7a63242015-04-16 14:09:14 -0700165 // output file suitable for installing or running
Colin Cross635c3b02016-05-18 15:37:25 -0700166 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700167
Colin Cross635c3b02016-05-18 15:37:25 -0700168 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700169
Colin Cross635c3b02016-05-18 15:37:25 -0700170 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700171
Colin Cross59149b62017-10-16 18:07:29 -0700172 // jars containing source files that should be included in the javac command line,
Colin Crossb7a63242015-04-16 14:09:14 -0700173 // for example R.java generated by aapt for android apps
Colin Cross59149b62017-10-16 18:07:29 -0700174 ExtraSrcJars android.Paths
Colin Crossb7a63242015-04-16 14:09:14 -0700175
Colin Cross2fe66872015-03-30 17:20:39 -0700176 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700177 installFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700178}
179
Colin Crossf506d872017-07-19 15:53:04 -0700180type Dependency interface {
Colin Cross74d73e22017-08-02 11:05:49 -0700181 ClasspathFiles() android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700182 AidlIncludeDirs() android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700183}
184
Colin Cross89536d42017-07-07 14:35:50 -0700185func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
186 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
187 android.InitDefaultableModule(module)
188}
189
Colin Crossbe1da472017-07-07 15:59:46 -0700190type dependencyTag struct {
191 blueprint.BaseDependencyTag
192 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700193}
194
Colin Crossbe1da472017-07-07 15:59:46 -0700195var (
Colin Cross6ade34f2017-09-15 13:00:47 -0700196 staticLibTag = dependencyTag{name: "staticlib"}
197 libTag = dependencyTag{name: "javalib"}
198 bootClasspathTag = dependencyTag{name: "bootclasspath"}
Colin Cross1369cdb2017-09-29 17:58:17 -0700199 systemModulesTag = dependencyTag{name: "system modules"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700200 frameworkResTag = dependencyTag{name: "framework-res"}
Colin Cross93e85952017-08-15 13:34:18 -0700201 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossbe1da472017-07-07 15:59:46 -0700202)
Colin Cross2fe66872015-03-30 17:20:39 -0700203
Colin Crossfc3674a2017-09-18 17:41:52 -0700204type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700205 useModule, useFiles, useDefaultLibs, invalidVersion bool
206
Colin Cross1369cdb2017-09-29 17:58:17 -0700207 module string
208 systemModules string
209
210 jar android.Path
211 aidl android.Path
212}
213
214func sdkStringToNumber(ctx android.BaseContext, v string) int {
215 switch v {
216 case "", "current", "system_current", "test_current":
217 return 10000
218 default:
219 if i, err := strconv.Atoi(v); err != nil {
220 ctx.PropertyErrorf("sdk_version", "invalid sdk version")
221 return -1
222 } else {
223 return i
224 }
225 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700226}
227
228func decodeSdkDep(ctx android.BaseContext, v string) sdkDep {
Colin Cross1369cdb2017-09-29 17:58:17 -0700229 i := sdkStringToNumber(ctx, v)
230 if i == -1 {
231 // Invalid sdk version, error handled by sdkStringToNumber.
232 return sdkDep{}
Colin Crossfc3674a2017-09-18 17:41:52 -0700233 }
234
235 toFile := func(v string) sdkDep {
236 dir := filepath.Join("prebuilts/sdk", v)
237 jar := filepath.Join(dir, "android.jar")
238 aidl := filepath.Join(dir, "framework.aidl")
239 jarPath := android.ExistentPathForSource(ctx, "sdkdir", jar)
240 aidlPath := android.ExistentPathForSource(ctx, "sdkdir", aidl)
Colin Cross47ff2522017-10-02 14:22:08 -0700241
242 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.AConfig().AllowMissingDependencies() {
243 return sdkDep{
244 invalidVersion: true,
245 module: "sdk_v" + v,
246 }
247 }
248
Colin Crossfc3674a2017-09-18 17:41:52 -0700249 if !jarPath.Valid() {
250 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar)
251 return sdkDep{}
252 }
Colin Cross47ff2522017-10-02 14:22:08 -0700253
Colin Crossfc3674a2017-09-18 17:41:52 -0700254 if !aidlPath.Valid() {
255 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl)
256 return sdkDep{}
257 }
Colin Cross47ff2522017-10-02 14:22:08 -0700258
Colin Crossfc3674a2017-09-18 17:41:52 -0700259 return sdkDep{
260 useFiles: true,
261 jar: jarPath.Path(),
262 aidl: aidlPath.Path(),
263 }
264 }
265
266 toModule := func(m string) sdkDep {
267 return sdkDep{
Colin Cross1369cdb2017-09-29 17:58:17 -0700268 useModule: true,
269 module: m,
270 systemModules: m + "_system_modules",
Colin Crossfc3674a2017-09-18 17:41:52 -0700271 }
272 }
273
Colin Cross8b9d37b2017-09-22 15:30:06 -0700274 if ctx.AConfig().UnbundledBuild() && v != "" {
Colin Crossfc3674a2017-09-18 17:41:52 -0700275 return toFile(v)
276 }
277
278 switch v {
279 case "":
280 return sdkDep{
281 useDefaultLibs: true,
282 }
283 case "current":
284 return toModule("android_stubs_current")
285 case "system_current":
286 return toModule("android_system_stubs_current")
287 case "test_current":
288 return toModule("android_test_stubs_current")
289 default:
290 return toFile(v)
291 }
292}
293
Colin Crossbe1da472017-07-07 15:59:46 -0700294func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700295 if ctx.Device() {
296 if !proptools.Bool(j.properties.No_standard_libs) {
Colin Crossfc3674a2017-09-18 17:41:52 -0700297 sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version)
298 if sdkDep.useDefaultLibs {
Colin Crosscb2c9292017-09-23 19:57:16 -0700299 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Colin Cross1369cdb2017-09-29 17:58:17 -0700300 if ctx.AConfig().TargetOpenJDK9() {
301 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
302 }
Colin Crossfa5eb232017-10-01 20:33:03 -0700303 if !proptools.Bool(j.properties.No_framework_libs) {
304 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
305 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700306 } else if sdkDep.useModule {
307 if ctx.AConfig().TargetOpenJDK9() {
308 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
309 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700310 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module)
Colin Crossbe1da472017-07-07 15:59:46 -0700311 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700312 } else if j.deviceProperties.System_modules == nil {
313 ctx.PropertyErrorf("no_standard_libs",
314 "system_modules is required to be set when no_standard_libs is true, did you mean no_framework_libs?")
315 } else if *j.deviceProperties.System_modules != "none" && ctx.AConfig().TargetOpenJDK9() {
316 ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700317 }
318 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700319
Colin Crossf506d872017-07-19 15:53:04 -0700320 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
321 ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
Colin Cross6ade34f2017-09-15 13:00:47 -0700322 ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...)
Colin Cross7f9036c2017-08-30 13:27:57 -0700323
324 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700325 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross6af17aa2017-09-20 12:59:05 -0700326
327 if j.hasSrcExt(".proto") {
328 protoDeps(ctx, &j.protoProperties)
329 }
Colin Cross93e85952017-08-15 13:34:18 -0700330
331 if j.hasSrcExt(".kt") {
332 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
333 // Kotlin files
334 ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib")
335 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700336}
337
338func hasSrcExt(srcs []string, ext string) bool {
339 for _, src := range srcs {
340 if filepath.Ext(src) == ext {
341 return true
342 }
343 }
344
345 return false
346}
347
348func (j *Module) hasSrcExt(ext string) bool {
349 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700350}
351
Colin Cross46c9b8b2017-06-22 16:51:17 -0700352func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700353 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700354
Colin Cross540eff82017-06-22 17:01:52 -0700355 localAidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl_includes)
Colin Crossc0b06f12015-04-08 13:03:43 -0700356
357 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700358 if aidlPreprocess.Valid() {
359 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700360 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700361 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700362 }
363
Colin Cross635c3b02016-05-18 15:37:25 -0700364 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
365 flags = append(flags, android.JoinWithPrefix(localAidlIncludes.Strings(), "-I"))
366 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Crossd48633a2017-07-13 14:41:17 -0700367 if src := android.ExistentPathForSource(ctx, "", "src"); src.Valid() {
368 flags = append(flags, "-I"+src.String())
369 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700370
Colin Crossf03c82b2015-04-13 13:53:40 -0700371 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700372}
373
Colin Cross32f676a2017-09-06 13:41:06 -0700374type deps struct {
Colin Cross6ade34f2017-09-15 13:00:47 -0700375 classpath android.Paths
376 bootClasspath android.Paths
377 staticJars android.Paths
378 staticJarResources android.Paths
379 aidlIncludeDirs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700380 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700381 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700382 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700383 kotlinStdlib android.Paths
Colin Cross32f676a2017-09-06 13:41:06 -0700384}
Colin Cross2fe66872015-03-30 17:20:39 -0700385
Colin Cross32f676a2017-09-06 13:41:06 -0700386func (j *Module) collectDeps(ctx android.ModuleContext) deps {
387 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700388
389 sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version)
Colin Cross47ff2522017-10-02 14:22:08 -0700390 if sdkDep.invalidVersion {
391 ctx.AddMissingDependencies([]string{sdkDep.module})
392 } else if sdkDep.useFiles {
Colin Crossfc3674a2017-09-18 17:41:52 -0700393 deps.classpath = append(deps.classpath, sdkDep.jar)
394 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
395 }
396
Colin Cross2fe66872015-03-30 17:20:39 -0700397 ctx.VisitDirectDeps(func(module blueprint.Module) {
398 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700399 tag := ctx.OtherModuleDependencyTag(module)
400
Colin Crossf506d872017-07-19 15:53:04 -0700401 dep, _ := module.(Dependency)
402 if dep == nil {
Colin Crossec7a0422017-07-07 14:47:12 -0700403 switch tag {
404 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700405 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700406 case systemModulesTag:
407 if deps.systemModules != nil {
408 panic("Found two system module dependencies")
409 }
410 sm := module.(*SystemModules)
411 if sm.outputFile == nil {
412 panic("Missing directory for system module dependency")
413 }
414 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700415 default:
416 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700417 }
Colin Crossec7a0422017-07-07 14:47:12 -0700418 return
419 }
420
Colin Crossbe1da472017-07-07 15:59:46 -0700421 switch tag {
422 case bootClasspathTag:
Colin Cross32f676a2017-09-06 13:41:06 -0700423 deps.bootClasspath = append(deps.bootClasspath, dep.ClasspathFiles()...)
Colin Crossf506d872017-07-19 15:53:04 -0700424 case libTag:
Colin Cross32f676a2017-09-06 13:41:06 -0700425 deps.classpath = append(deps.classpath, dep.ClasspathFiles()...)
Colin Crossf506d872017-07-19 15:53:04 -0700426 case staticLibTag:
Colin Cross32f676a2017-09-06 13:41:06 -0700427 deps.classpath = append(deps.classpath, dep.ClasspathFiles()...)
428 deps.staticJars = append(deps.staticJars, dep.ClasspathFiles()...)
Colin Crossbe1da472017-07-07 15:59:46 -0700429 case frameworkResTag:
Colin Crossec7a0422017-07-07 14:47:12 -0700430 if ctx.ModuleName() == "framework" {
431 // framework.jar has a one-off dependency on the R.java and Manifest.java files
432 // generated by framework-res.apk
Colin Cross59149b62017-10-16 18:07:29 -0700433 // TODO(ccross): aapt java files should go in a src jar
Colin Crossec7a0422017-07-07 14:47:12 -0700434 }
Colin Cross93e85952017-08-15 13:34:18 -0700435 case kotlinStdlibTag:
436 deps.kotlinStdlib = dep.ClasspathFiles()
Colin Crossbe1da472017-07-07 15:59:46 -0700437 default:
438 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
Colin Cross2fe66872015-03-30 17:20:39 -0700439 }
Colin Crossbe1da472017-07-07 15:59:46 -0700440
Colin Cross32f676a2017-09-06 13:41:06 -0700441 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2fe66872015-03-30 17:20:39 -0700442 })
443
Colin Cross32f676a2017-09-06 13:41:06 -0700444 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700445}
446
Colin Cross46c9b8b2017-06-22 16:51:17 -0700447func (j *Module) compile(ctx android.ModuleContext) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700448
Colin Cross540eff82017-06-22 17:01:52 -0700449 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Export_aidl_include_dirs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700450
Colin Cross32f676a2017-09-06 13:41:06 -0700451 deps := j.collectDeps(ctx)
Colin Crossc0b06f12015-04-08 13:03:43 -0700452
Colin Crossf03c82b2015-04-13 13:53:40 -0700453 var flags javaBuilderFlags
454
455 javacFlags := j.properties.Javacflags
Colin Cross1369cdb2017-09-29 17:58:17 -0700456 if ctx.AConfig().TargetOpenJDK9() {
457 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
458 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
Colin Cross4f26bc02017-09-06 12:52:16 -0700459 }
Colin Cross64162712017-08-08 13:17:59 -0700460
Colin Cross1369cdb2017-09-29 17:58:17 -0700461 sdk := sdkStringToNumber(ctx, j.deviceProperties.Sdk_version)
Colin Cross64162712017-08-08 13:17:59 -0700462 if j.properties.Java_version != nil {
463 flags.javaVersion = *j.properties.Java_version
Colin Cross1369cdb2017-09-29 17:58:17 -0700464 } else if ctx.Device() && sdk <= 23 {
465 flags.javaVersion = "1.7"
466 } else if ctx.Device() && sdk <= 26 || !ctx.AConfig().TargetOpenJDK9() {
467 flags.javaVersion = "1.8"
Colin Cross64162712017-08-08 13:17:59 -0700468 } else {
Colin Cross1369cdb2017-09-29 17:58:17 -0700469 flags.javaVersion = "1.9"
Colin Cross64162712017-08-08 13:17:59 -0700470 }
471
Colin Cross6ade34f2017-09-15 13:00:47 -0700472 flags.bootClasspath.AddPaths(deps.bootClasspath)
473 flags.classpath.AddPaths(deps.classpath)
474
Colin Cross1369cdb2017-09-29 17:58:17 -0700475 if deps.systemModules != nil {
476 flags.systemModules = append(flags.systemModules, deps.systemModules)
477 }
478
Colin Crossf03c82b2015-04-13 13:53:40 -0700479 if len(javacFlags) > 0 {
480 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
481 flags.javacFlags = "$javacFlags"
482 }
483
Colin Cross32f676a2017-09-06 13:41:06 -0700484 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700485 if len(aidlFlags) > 0 {
486 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
487 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700488 }
489
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700490 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700491
Colin Cross6af17aa2017-09-20 12:59:05 -0700492 if hasSrcExt(srcFiles.Strings(), ".proto") {
493 flags = protoFlags(ctx, &j.protoProperties, flags)
494 }
495
Colin Cross59149b62017-10-16 18:07:29 -0700496 var srcJars classpath
497 srcFiles, srcJars = j.genSources(ctx, srcFiles, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700498
Colin Cross59149b62017-10-16 18:07:29 -0700499 srcJars = append(srcJars, deps.srcJars...)
Colin Cross6af17aa2017-09-20 12:59:05 -0700500
Colin Cross59149b62017-10-16 18:07:29 -0700501 srcJars = append(srcJars, j.ExtraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700502
Colin Cross0a6e0072017-08-30 14:24:55 -0700503 var jars android.Paths
504
Colin Cross93e85952017-08-15 13:34:18 -0700505 if srcFiles.HasExt(".kt") {
506 // If there are kotlin files, compile them first but pass all the kotlin and java files
507 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
508 // won't emit any classes for them.
509
510 flags.kotlincFlags = "-no-stdlib"
511 if ctx.Device() {
512 flags.kotlincFlags += " -no-jdk"
513 }
514
515 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
516 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
517
518 kotlinJar := android.PathForModuleOut(ctx, "classes-kt.jar")
519 TransformKotlinToClasses(ctx, kotlinJar, srcFiles, srcJars, flags)
520 if ctx.Failed() {
521 return
522 }
523
524 // Make javac rule depend on the kotlinc rule
525 flags.classpath = append(flags.classpath, kotlinJar)
526 // Jar kotlin classes into the final jar after javac
527 jars = append(jars, kotlinJar)
528 jars = append(jars, deps.kotlinStdlib...)
529 }
530
531 if javaSrcFiles := srcFiles.FilterByExt(".java"); len(javaSrcFiles) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -0700532 var extraJarDeps android.Paths
Colin Crossc6bbef32017-08-14 14:16:06 -0700533 if ctx.AConfig().IsEnvTrue("RUN_ERROR_PRONE") {
534 // If error-prone is enabled, add an additional rule to compile the java files into
535 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -0700536 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -0700537 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
538 // enable error-prone without affecting the output class files.
Colin Crosse9a275b2017-10-16 17:09:48 -0700539 errorprone := android.PathForModuleOut(ctx, "classes-errorprone.list")
Colin Cross93e85952017-08-15 13:34:18 -0700540 RunErrorProne(ctx, errorprone, javaSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -0700541 extraJarDeps = append(extraJarDeps, errorprone)
542 }
543
Colin Crossd6891432017-09-27 17:39:56 -0700544 // Compile java sources into .class files
Colin Crosse9a275b2017-10-16 17:09:48 -0700545 classes := android.PathForModuleOut(ctx, "classes-compiled.jar")
Colin Cross93e85952017-08-15 13:34:18 -0700546 TransformJavaToClasses(ctx, classes, javaSrcFiles, srcJars, flags, extraJarDeps)
Colin Crossd6891432017-09-27 17:39:56 -0700547 if ctx.Failed() {
548 return
549 }
550
Colin Cross0a6e0072017-08-30 14:24:55 -0700551 jars = append(jars, classes)
Colin Cross2fe66872015-03-30 17:20:39 -0700552 }
553
Colin Cross0f37af02017-09-27 17:42:05 -0700554 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
555 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
556
557 var resArgs []string
558 var resDeps android.Paths
559
560 resArgs = append(resArgs, dirArgs...)
561 resDeps = append(resDeps, dirDeps...)
562
563 resArgs = append(resArgs, fileArgs...)
564 resDeps = append(resDeps, fileDeps...)
565
566 if proptools.Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -0700567 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700568 resArgs = append(resArgs, srcArgs...)
569 resDeps = append(resDeps, srcDeps...)
570 }
Colin Cross40a36712017-09-27 17:41:35 -0700571
572 if len(resArgs) > 0 {
Colin Crosse9a275b2017-10-16 17:09:48 -0700573 resourceJar := android.PathForModuleOut(ctx, "res.jar")
574 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -0700575 if ctx.Failed() {
576 return
577 }
Colin Cross20978302015-04-10 17:05:07 -0700578
Colin Cross0a6e0072017-08-30 14:24:55 -0700579 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -0700580 }
581
Colin Cross6ade34f2017-09-15 13:00:47 -0700582 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -0700583 jars = append(jars, deps.staticJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -0700584
Colin Cross635acc92017-09-12 22:50:46 -0700585 manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
586
Colin Cross0a6e0072017-08-30 14:24:55 -0700587 // Combine the classes built from sources, any manifests, and any static libraries into
Colin Cross8649b262017-09-27 18:03:17 -0700588 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -0700589 var outputFile android.Path
590
591 if len(jars) == 1 && !manifest.Valid() {
592 // Optimization: skip the combine step if there is nothing to do
593 outputFile = jars[0]
594 } else {
595 combinedJar := android.PathForModuleOut(ctx, "classes.jar")
596 TransformJarsToJar(ctx, combinedJar, jars, manifest, false)
597 outputFile = combinedJar
598 }
Colin Cross0a6e0072017-08-30 14:24:55 -0700599
600 if j.properties.Jarjar_rules != nil {
601 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -0700602 // Transform classes.jar into classes-jarjar.jar
Colin Crosse9a275b2017-10-16 17:09:48 -0700603 jarjarFile := android.PathForModuleOut(ctx, "classes-jarjar.jar")
604 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
605 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -0700606 if ctx.Failed() {
607 return
608 }
609 }
610
Colin Cross2fe66872015-03-30 17:20:39 -0700611 j.classpathFile = outputFile
612
Colin Crossc157a8d2017-10-03 17:17:07 -0700613 if ctx.Device() && j.installable() {
Colin Cross540eff82017-06-22 17:01:52 -0700614 dxFlags := j.deviceProperties.Dxflags
Colin Cross2fe66872015-03-30 17:20:39 -0700615 if false /* emma enabled */ {
616 // If you instrument class files that have local variable debug information in
617 // them emma does not correctly maintain the local variable table.
618 // This will cause an error when you try to convert the class files for Android.
619 // The workaround here is to build different dex file here based on emma switch
620 // then later copy into classes.dex. When emma is on, dx is run with --no-locals
621 // option to remove local variable information
622 dxFlags = append(dxFlags, "--no-locals")
623 }
624
Colin Cross1332b002015-04-07 17:11:30 -0700625 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700626 dxFlags = append(dxFlags, "--no-optimize")
627 }
628
Colin Cross1332b002015-04-07 17:11:30 -0700629 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700630 dxFlags = append(dxFlags,
631 "--debug",
632 "--verbose",
Colin Cross635c3b02016-05-18 15:37:25 -0700633 "--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(),
Colin Cross2fe66872015-03-30 17:20:39 -0700634 "--dump-width=1000")
635 }
636
Colin Cross595a4062017-08-31 12:30:37 -0700637 var minSdkVersion string
638 switch j.deviceProperties.Sdk_version {
639 case "", "current", "test_current", "system_current":
640 minSdkVersion = strconv.Itoa(ctx.AConfig().DefaultAppTargetSdkInt())
641 default:
642 minSdkVersion = j.deviceProperties.Sdk_version
643 }
644
645 dxFlags = append(dxFlags, "--min-sdk-version="+minSdkVersion)
646
Colin Cross2fe66872015-03-30 17:20:39 -0700647 flags.dxFlags = strings.Join(dxFlags, " ")
648
Colin Cross6ade34f2017-09-15 13:00:47 -0700649 desugarFlags := []string{
650 "--min_sdk_version " + minSdkVersion,
651 "--desugar_try_with_resources_if_needed=false",
652 "--allow_empty_bootclasspath",
653 }
654
655 if inList("--core-library", dxFlags) {
656 desugarFlags = append(desugarFlags, "--core_library")
657 }
658
659 flags.desugarFlags = strings.Join(desugarFlags, " ")
660
Colin Crosse9a275b2017-10-16 17:09:48 -0700661 desugarJar := android.PathForModuleOut(ctx, "classes-desugar.jar")
662 TransformDesugar(ctx, desugarJar, outputFile, flags)
663 outputFile = desugarJar
Colin Cross2fe66872015-03-30 17:20:39 -0700664 if ctx.Failed() {
665 return
666 }
667
Colin Cross7db5d632017-10-04 17:07:09 -0700668 // Compile classes.jar into classes.dex and then javalib.jar
Colin Crosse9a275b2017-10-16 17:09:48 -0700669 javalibJar := android.PathForModuleOut(ctx, "javalib.jar")
670 TransformClassesJarToDexJar(ctx, javalibJar, desugarJar, flags)
671 outputFile = javalibJar
Colin Cross6ade34f2017-09-15 13:00:47 -0700672 if ctx.Failed() {
673 return
674 }
675
Colin Cross6ade34f2017-09-15 13:00:47 -0700676 j.dexJarFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700677 }
Colin Crossb7a63242015-04-16 14:09:14 -0700678 ctx.CheckbuildFile(outputFile)
679 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700680}
681
Colin Cross59f1bb62017-09-27 17:59:10 -0700682func (j *Module) installable() bool {
683 return j.properties.Installable == nil || *j.properties.Installable
684}
685
Colin Crossf506d872017-07-19 15:53:04 -0700686var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700687
Colin Cross74d73e22017-08-02 11:05:49 -0700688func (j *Module) ClasspathFiles() android.Paths {
689 return android.Paths{j.classpathFile}
Colin Cross2fe66872015-03-30 17:20:39 -0700690}
691
Colin Cross46c9b8b2017-06-22 16:51:17 -0700692func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700693 return j.exportAidlIncludeDirs
694}
695
Colin Cross46c9b8b2017-06-22 16:51:17 -0700696var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -0700697
Colin Cross46c9b8b2017-06-22 16:51:17 -0700698func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -0700699 return j.logtagsSrcs
700}
701
Colin Cross2fe66872015-03-30 17:20:39 -0700702//
703// Java libraries (.jar file)
704//
705
Colin Crossf506d872017-07-19 15:53:04 -0700706type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700707 Module
Colin Cross2fe66872015-03-30 17:20:39 -0700708}
709
Colin Crossf506d872017-07-19 15:53:04 -0700710func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700711 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -0700712
Colin Cross59f1bb62017-09-27 17:59:10 -0700713 if j.installable() {
Colin Cross2c429dc2017-08-31 16:45:16 -0700714 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
715 ctx.ModuleName()+".jar", j.outputFile)
716 }
Colin Crossb7a63242015-04-16 14:09:14 -0700717}
718
Colin Crossf506d872017-07-19 15:53:04 -0700719func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700720 j.deps(ctx)
721}
722
Colin Crossa60ead82017-10-02 18:10:21 -0700723func LibraryFactory(installable bool) func() android.Module {
724 return func() android.Module {
725 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -0700726
Colin Crossa60ead82017-10-02 18:10:21 -0700727 if !installable {
728 module.properties.Installable = proptools.BoolPtr(false)
729 }
Colin Cross2fe66872015-03-30 17:20:39 -0700730
Colin Crossa60ead82017-10-02 18:10:21 -0700731 module.AddProperties(
732 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -0700733 &module.Module.deviceProperties,
734 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -0700735
Colin Crossa60ead82017-10-02 18:10:21 -0700736 InitJavaModule(module, android.HostAndDeviceSupported)
737 return module
738 }
Colin Cross2fe66872015-03-30 17:20:39 -0700739}
740
Colin Crossf506d872017-07-19 15:53:04 -0700741func LibraryHostFactory() android.Module {
742 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -0700743
Colin Cross6af17aa2017-09-20 12:59:05 -0700744 module.AddProperties(
745 &module.Module.properties,
746 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -0700747
Colin Cross89536d42017-07-07 14:35:50 -0700748 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -0700749 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700750}
751
752//
753// Java Binaries (.jar file plus wrapper script)
754//
755
Colin Crossf506d872017-07-19 15:53:04 -0700756type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700757 // installable script to execute the resulting jar
758 Wrapper string
759}
760
Colin Crossf506d872017-07-19 15:53:04 -0700761type Binary struct {
762 Library
Colin Cross2fe66872015-03-30 17:20:39 -0700763
Colin Crossf506d872017-07-19 15:53:04 -0700764 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -0700765
766 wrapperFile android.ModuleSrcPath
767 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -0700768}
769
Colin Crossf506d872017-07-19 15:53:04 -0700770func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
771 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross2fe66872015-03-30 17:20:39 -0700772
773 // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
774 // another build rule before the jar has been installed.
Colin Cross10a03492017-08-10 17:09:43 -0700775 j.wrapperFile = android.PathForModuleSrc(ctx, j.binaryProperties.Wrapper)
Colin Cross5c517922017-08-31 12:29:17 -0700776 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
777 ctx.ModuleName(), j.wrapperFile, j.installFile)
Colin Cross2fe66872015-03-30 17:20:39 -0700778}
779
Colin Crossf506d872017-07-19 15:53:04 -0700780func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700781 j.deps(ctx)
782}
783
Colin Crossf506d872017-07-19 15:53:04 -0700784func BinaryFactory() android.Module {
785 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -0700786
Colin Cross36242852017-06-23 15:06:31 -0700787 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700788 &module.Module.properties,
789 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -0700790 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -0700791 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -0700792
Colin Cross89536d42017-07-07 14:35:50 -0700793 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -0700794 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700795}
796
Colin Crossf506d872017-07-19 15:53:04 -0700797func BinaryHostFactory() android.Module {
798 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -0700799
Colin Cross36242852017-06-23 15:06:31 -0700800 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700801 &module.Module.properties,
802 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -0700803 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -0700804 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -0700805
Colin Cross89536d42017-07-07 14:35:50 -0700806 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -0700807 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700808}
809
810//
811// Java prebuilts
812//
813
Colin Cross74d73e22017-08-02 11:05:49 -0700814type ImportProperties struct {
815 Jars []string
816}
817
818type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700819 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -0700820 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -0700821
Colin Cross74d73e22017-08-02 11:05:49 -0700822 properties ImportProperties
823
Colin Cross0a6e0072017-08-30 14:24:55 -0700824 classpathFiles android.Paths
825 combinedClasspathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700826}
827
Colin Cross74d73e22017-08-02 11:05:49 -0700828func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -0700829 return &j.prebuilt
830}
831
Colin Cross74d73e22017-08-02 11:05:49 -0700832func (j *Import) PrebuiltSrcs() []string {
833 return j.properties.Jars
834}
835
836func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -0700837 return j.prebuilt.Name(j.ModuleBase.Name())
838}
839
Colin Cross74d73e22017-08-02 11:05:49 -0700840func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross1e676be2016-10-12 14:38:15 -0700841}
842
Colin Cross74d73e22017-08-02 11:05:49 -0700843func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
844 j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -0700845
Colin Crosse9a275b2017-10-16 17:09:48 -0700846 outputFile := android.PathForModuleOut(ctx, "classes.jar")
847 TransformJarsToJar(ctx, outputFile, j.classpathFiles, android.OptionalPath{}, false)
848 j.combinedClasspathFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700849}
850
Colin Cross74d73e22017-08-02 11:05:49 -0700851var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700852
Colin Cross74d73e22017-08-02 11:05:49 -0700853func (j *Import) ClasspathFiles() android.Paths {
854 return j.classpathFiles
Colin Cross2fe66872015-03-30 17:20:39 -0700855}
856
Colin Cross74d73e22017-08-02 11:05:49 -0700857func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700858 return nil
859}
860
Colin Cross74d73e22017-08-02 11:05:49 -0700861var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700862
Colin Cross74d73e22017-08-02 11:05:49 -0700863func ImportFactory() android.Module {
864 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -0700865
Colin Cross74d73e22017-08-02 11:05:49 -0700866 module.AddProperties(&module.properties)
867
868 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -0700869 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
870 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700871}
872
Colin Cross74d73e22017-08-02 11:05:49 -0700873func ImportFactoryHost() android.Module {
874 module := &Import{}
875
876 module.AddProperties(&module.properties)
877
878 android.InitPrebuiltModule(module, &module.properties.Jars)
879 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
880 return module
881}
882
Colin Cross2fe66872015-03-30 17:20:39 -0700883func inList(s string, l []string) bool {
884 for _, e := range l {
885 if e == s {
886 return true
887 }
888 }
889 return false
890}
Colin Cross89536d42017-07-07 14:35:50 -0700891
892//
893// Defaults
894//
895type Defaults struct {
896 android.ModuleBase
897 android.DefaultsModuleBase
898}
899
900func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
901}
902
903func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
904}
905
906func defaultsFactory() android.Module {
907 return DefaultsFactory()
908}
909
910func DefaultsFactory(props ...interface{}) android.Module {
911 module := &Defaults{}
912
913 module.AddProperties(props...)
914 module.AddProperties(
915 &CompilerProperties{},
916 &CompilerDeviceProperties{},
917 )
918
919 android.InitDefaultsModule(module)
920
921 return module
922}