blob: 770c9c1fd42c3d35fa9d1c39013ff8b444e41fe0 [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 Crossbe1da472017-07-07 15:59:46 -0700201)
Colin Cross2fe66872015-03-30 17:20:39 -0700202
Colin Crossfc3674a2017-09-18 17:41:52 -0700203type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700204 useModule, useFiles, useDefaultLibs, invalidVersion bool
205
Colin Cross1369cdb2017-09-29 17:58:17 -0700206 module string
207 systemModules string
208
209 jar android.Path
210 aidl android.Path
211}
212
213func sdkStringToNumber(ctx android.BaseContext, v string) int {
214 switch v {
215 case "", "current", "system_current", "test_current":
216 return 10000
217 default:
218 if i, err := strconv.Atoi(v); err != nil {
219 ctx.PropertyErrorf("sdk_version", "invalid sdk version")
220 return -1
221 } else {
222 return i
223 }
224 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700225}
226
227func decodeSdkDep(ctx android.BaseContext, v string) sdkDep {
Colin Cross1369cdb2017-09-29 17:58:17 -0700228 i := sdkStringToNumber(ctx, v)
229 if i == -1 {
230 // Invalid sdk version, error handled by sdkStringToNumber.
231 return sdkDep{}
Colin Crossfc3674a2017-09-18 17:41:52 -0700232 }
233
234 toFile := func(v string) sdkDep {
235 dir := filepath.Join("prebuilts/sdk", v)
236 jar := filepath.Join(dir, "android.jar")
237 aidl := filepath.Join(dir, "framework.aidl")
238 jarPath := android.ExistentPathForSource(ctx, "sdkdir", jar)
239 aidlPath := android.ExistentPathForSource(ctx, "sdkdir", aidl)
Colin Cross47ff2522017-10-02 14:22:08 -0700240
241 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.AConfig().AllowMissingDependencies() {
242 return sdkDep{
243 invalidVersion: true,
244 module: "sdk_v" + v,
245 }
246 }
247
Colin Crossfc3674a2017-09-18 17:41:52 -0700248 if !jarPath.Valid() {
249 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar)
250 return sdkDep{}
251 }
Colin Cross47ff2522017-10-02 14:22:08 -0700252
Colin Crossfc3674a2017-09-18 17:41:52 -0700253 if !aidlPath.Valid() {
254 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl)
255 return sdkDep{}
256 }
Colin Cross47ff2522017-10-02 14:22:08 -0700257
Colin Crossfc3674a2017-09-18 17:41:52 -0700258 return sdkDep{
259 useFiles: true,
260 jar: jarPath.Path(),
261 aidl: aidlPath.Path(),
262 }
263 }
264
265 toModule := func(m string) sdkDep {
266 return sdkDep{
Colin Cross1369cdb2017-09-29 17:58:17 -0700267 useModule: true,
268 module: m,
269 systemModules: m + "_system_modules",
Colin Crossfc3674a2017-09-18 17:41:52 -0700270 }
271 }
272
Colin Cross8b9d37b2017-09-22 15:30:06 -0700273 if ctx.AConfig().UnbundledBuild() && v != "" {
Colin Crossfc3674a2017-09-18 17:41:52 -0700274 return toFile(v)
275 }
276
277 switch v {
278 case "":
279 return sdkDep{
280 useDefaultLibs: true,
281 }
282 case "current":
283 return toModule("android_stubs_current")
284 case "system_current":
285 return toModule("android_system_stubs_current")
286 case "test_current":
287 return toModule("android_test_stubs_current")
288 default:
289 return toFile(v)
290 }
291}
292
Colin Crossbe1da472017-07-07 15:59:46 -0700293func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700294 if ctx.Device() {
295 if !proptools.Bool(j.properties.No_standard_libs) {
Colin Crossfc3674a2017-09-18 17:41:52 -0700296 sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version)
297 if sdkDep.useDefaultLibs {
Colin Crosscb2c9292017-09-23 19:57:16 -0700298 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Colin Cross1369cdb2017-09-29 17:58:17 -0700299 if ctx.AConfig().TargetOpenJDK9() {
300 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
301 }
Colin Crossfa5eb232017-10-01 20:33:03 -0700302 if !proptools.Bool(j.properties.No_framework_libs) {
303 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
304 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700305 } else if sdkDep.useModule {
306 if ctx.AConfig().TargetOpenJDK9() {
307 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
308 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700309 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module)
Colin Crossbe1da472017-07-07 15:59:46 -0700310 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700311 } else if j.deviceProperties.System_modules == nil {
312 ctx.PropertyErrorf("no_standard_libs",
313 "system_modules is required to be set when no_standard_libs is true, did you mean no_framework_libs?")
314 } else if *j.deviceProperties.System_modules != "none" && ctx.AConfig().TargetOpenJDK9() {
315 ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700316 }
317 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700318
Colin Crossf506d872017-07-19 15:53:04 -0700319 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
320 ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
Colin Cross6ade34f2017-09-15 13:00:47 -0700321 ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...)
Colin Cross7f9036c2017-08-30 13:27:57 -0700322
323 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700324 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross6af17aa2017-09-20 12:59:05 -0700325
326 if j.hasSrcExt(".proto") {
327 protoDeps(ctx, &j.protoProperties)
328 }
329}
330
331func hasSrcExt(srcs []string, ext string) bool {
332 for _, src := range srcs {
333 if filepath.Ext(src) == ext {
334 return true
335 }
336 }
337
338 return false
339}
340
341func (j *Module) hasSrcExt(ext string) bool {
342 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700343}
344
Colin Cross46c9b8b2017-06-22 16:51:17 -0700345func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700346 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700347
Colin Cross540eff82017-06-22 17:01:52 -0700348 localAidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl_includes)
Colin Crossc0b06f12015-04-08 13:03:43 -0700349
350 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700351 if aidlPreprocess.Valid() {
352 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700353 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700354 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700355 }
356
Colin Cross635c3b02016-05-18 15:37:25 -0700357 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
358 flags = append(flags, android.JoinWithPrefix(localAidlIncludes.Strings(), "-I"))
359 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Crossd48633a2017-07-13 14:41:17 -0700360 if src := android.ExistentPathForSource(ctx, "", "src"); src.Valid() {
361 flags = append(flags, "-I"+src.String())
362 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700363
Colin Crossf03c82b2015-04-13 13:53:40 -0700364 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700365}
366
Colin Cross32f676a2017-09-06 13:41:06 -0700367type deps struct {
Colin Cross6ade34f2017-09-15 13:00:47 -0700368 classpath android.Paths
369 bootClasspath android.Paths
370 staticJars android.Paths
371 staticJarResources android.Paths
372 aidlIncludeDirs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700373 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700374 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700375 aidlPreprocess android.OptionalPath
Colin Cross32f676a2017-09-06 13:41:06 -0700376}
Colin Cross2fe66872015-03-30 17:20:39 -0700377
Colin Cross32f676a2017-09-06 13:41:06 -0700378func (j *Module) collectDeps(ctx android.ModuleContext) deps {
379 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700380
381 sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version)
Colin Cross47ff2522017-10-02 14:22:08 -0700382 if sdkDep.invalidVersion {
383 ctx.AddMissingDependencies([]string{sdkDep.module})
384 } else if sdkDep.useFiles {
Colin Crossfc3674a2017-09-18 17:41:52 -0700385 deps.classpath = append(deps.classpath, sdkDep.jar)
386 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
387 }
388
Colin Cross2fe66872015-03-30 17:20:39 -0700389 ctx.VisitDirectDeps(func(module blueprint.Module) {
390 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700391 tag := ctx.OtherModuleDependencyTag(module)
392
Colin Crossf506d872017-07-19 15:53:04 -0700393 dep, _ := module.(Dependency)
394 if dep == nil {
Colin Crossec7a0422017-07-07 14:47:12 -0700395 switch tag {
396 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700397 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700398 case systemModulesTag:
399 if deps.systemModules != nil {
400 panic("Found two system module dependencies")
401 }
402 sm := module.(*SystemModules)
403 if sm.outputFile == nil {
404 panic("Missing directory for system module dependency")
405 }
406 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700407 default:
408 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700409 }
Colin Crossec7a0422017-07-07 14:47:12 -0700410 return
411 }
412
Colin Crossbe1da472017-07-07 15:59:46 -0700413 switch tag {
414 case bootClasspathTag:
Colin Cross32f676a2017-09-06 13:41:06 -0700415 deps.bootClasspath = append(deps.bootClasspath, dep.ClasspathFiles()...)
Colin Crossf506d872017-07-19 15:53:04 -0700416 case libTag:
Colin Cross32f676a2017-09-06 13:41:06 -0700417 deps.classpath = append(deps.classpath, dep.ClasspathFiles()...)
Colin Crossf506d872017-07-19 15:53:04 -0700418 case staticLibTag:
Colin Cross32f676a2017-09-06 13:41:06 -0700419 deps.classpath = append(deps.classpath, dep.ClasspathFiles()...)
420 deps.staticJars = append(deps.staticJars, dep.ClasspathFiles()...)
Colin Crossbe1da472017-07-07 15:59:46 -0700421 case frameworkResTag:
Colin Crossec7a0422017-07-07 14:47:12 -0700422 if ctx.ModuleName() == "framework" {
423 // framework.jar has a one-off dependency on the R.java and Manifest.java files
424 // generated by framework-res.apk
Colin Cross59149b62017-10-16 18:07:29 -0700425 // TODO(ccross): aapt java files should go in a src jar
Colin Crossec7a0422017-07-07 14:47:12 -0700426 }
Colin Crossbe1da472017-07-07 15:59:46 -0700427 default:
428 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
Colin Cross2fe66872015-03-30 17:20:39 -0700429 }
Colin Crossbe1da472017-07-07 15:59:46 -0700430
Colin Cross32f676a2017-09-06 13:41:06 -0700431 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2fe66872015-03-30 17:20:39 -0700432 })
433
Colin Cross32f676a2017-09-06 13:41:06 -0700434 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700435}
436
Colin Cross46c9b8b2017-06-22 16:51:17 -0700437func (j *Module) compile(ctx android.ModuleContext) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700438
Colin Cross540eff82017-06-22 17:01:52 -0700439 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Export_aidl_include_dirs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700440
Colin Cross32f676a2017-09-06 13:41:06 -0700441 deps := j.collectDeps(ctx)
Colin Crossc0b06f12015-04-08 13:03:43 -0700442
Colin Crossf03c82b2015-04-13 13:53:40 -0700443 var flags javaBuilderFlags
444
445 javacFlags := j.properties.Javacflags
Colin Cross1369cdb2017-09-29 17:58:17 -0700446 if ctx.AConfig().TargetOpenJDK9() {
447 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
448 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
Colin Cross4f26bc02017-09-06 12:52:16 -0700449 }
Colin Cross64162712017-08-08 13:17:59 -0700450
Colin Cross1369cdb2017-09-29 17:58:17 -0700451 sdk := sdkStringToNumber(ctx, j.deviceProperties.Sdk_version)
Colin Cross64162712017-08-08 13:17:59 -0700452 if j.properties.Java_version != nil {
453 flags.javaVersion = *j.properties.Java_version
Colin Cross1369cdb2017-09-29 17:58:17 -0700454 } else if ctx.Device() && sdk <= 23 {
455 flags.javaVersion = "1.7"
456 } else if ctx.Device() && sdk <= 26 || !ctx.AConfig().TargetOpenJDK9() {
457 flags.javaVersion = "1.8"
Colin Cross64162712017-08-08 13:17:59 -0700458 } else {
Colin Cross1369cdb2017-09-29 17:58:17 -0700459 flags.javaVersion = "1.9"
Colin Cross64162712017-08-08 13:17:59 -0700460 }
461
Colin Cross6ade34f2017-09-15 13:00:47 -0700462 flags.bootClasspath.AddPaths(deps.bootClasspath)
463 flags.classpath.AddPaths(deps.classpath)
464
Colin Cross1369cdb2017-09-29 17:58:17 -0700465 if deps.systemModules != nil {
466 flags.systemModules = append(flags.systemModules, deps.systemModules)
467 }
468
Colin Crossf03c82b2015-04-13 13:53:40 -0700469 if len(javacFlags) > 0 {
470 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
471 flags.javacFlags = "$javacFlags"
472 }
473
Colin Cross32f676a2017-09-06 13:41:06 -0700474 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700475 if len(aidlFlags) > 0 {
476 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
477 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700478 }
479
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700480 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700481
Colin Cross6af17aa2017-09-20 12:59:05 -0700482 if hasSrcExt(srcFiles.Strings(), ".proto") {
483 flags = protoFlags(ctx, &j.protoProperties, flags)
484 }
485
Colin Cross59149b62017-10-16 18:07:29 -0700486 var srcJars classpath
487 srcFiles, srcJars = j.genSources(ctx, srcFiles, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700488
Colin Cross59149b62017-10-16 18:07:29 -0700489 srcJars = append(srcJars, deps.srcJars...)
Colin Cross6af17aa2017-09-20 12:59:05 -0700490
Colin Cross59149b62017-10-16 18:07:29 -0700491 srcJars = append(srcJars, j.ExtraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700492
Colin Cross0a6e0072017-08-30 14:24:55 -0700493 var jars android.Paths
494
Colin Cross8cf13342015-04-10 15:41:49 -0700495 if len(srcFiles) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -0700496 var extraJarDeps android.Paths
Colin Crossc6bbef32017-08-14 14:16:06 -0700497 if ctx.AConfig().IsEnvTrue("RUN_ERROR_PRONE") {
498 // If error-prone is enabled, add an additional rule to compile the java files into
499 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -0700500 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -0700501 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
502 // enable error-prone without affecting the output class files.
Colin Crosse9a275b2017-10-16 17:09:48 -0700503 errorprone := android.PathForModuleOut(ctx, "classes-errorprone.list")
Colin Cross59149b62017-10-16 18:07:29 -0700504 RunErrorProne(ctx, errorprone, srcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -0700505 extraJarDeps = append(extraJarDeps, errorprone)
506 }
507
Colin Crossd6891432017-09-27 17:39:56 -0700508 // Compile java sources into .class files
Colin Crosse9a275b2017-10-16 17:09:48 -0700509 classes := android.PathForModuleOut(ctx, "classes-compiled.jar")
Colin Cross59149b62017-10-16 18:07:29 -0700510 TransformJavaToClasses(ctx, classes, srcFiles, srcJars, flags, extraJarDeps)
Colin Crossd6891432017-09-27 17:39:56 -0700511 if ctx.Failed() {
512 return
513 }
514
Colin Cross0a6e0072017-08-30 14:24:55 -0700515 jars = append(jars, classes)
Colin Cross2fe66872015-03-30 17:20:39 -0700516 }
517
Colin Cross0f37af02017-09-27 17:42:05 -0700518 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
519 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
520
521 var resArgs []string
522 var resDeps android.Paths
523
524 resArgs = append(resArgs, dirArgs...)
525 resDeps = append(resDeps, dirDeps...)
526
527 resArgs = append(resArgs, fileArgs...)
528 resDeps = append(resDeps, fileDeps...)
529
530 if proptools.Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -0700531 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700532 resArgs = append(resArgs, srcArgs...)
533 resDeps = append(resDeps, srcDeps...)
534 }
Colin Cross40a36712017-09-27 17:41:35 -0700535
536 if len(resArgs) > 0 {
Colin Crosse9a275b2017-10-16 17:09:48 -0700537 resourceJar := android.PathForModuleOut(ctx, "res.jar")
538 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -0700539 if ctx.Failed() {
540 return
541 }
Colin Cross20978302015-04-10 17:05:07 -0700542
Colin Cross0a6e0072017-08-30 14:24:55 -0700543 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -0700544 }
545
Colin Cross6ade34f2017-09-15 13:00:47 -0700546 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -0700547 jars = append(jars, deps.staticJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -0700548
Colin Cross635acc92017-09-12 22:50:46 -0700549 manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
550
Colin Cross0a6e0072017-08-30 14:24:55 -0700551 // Combine the classes built from sources, any manifests, and any static libraries into
Colin Cross8649b262017-09-27 18:03:17 -0700552 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -0700553 var outputFile android.Path
554
555 if len(jars) == 1 && !manifest.Valid() {
556 // Optimization: skip the combine step if there is nothing to do
557 outputFile = jars[0]
558 } else {
559 combinedJar := android.PathForModuleOut(ctx, "classes.jar")
560 TransformJarsToJar(ctx, combinedJar, jars, manifest, false)
561 outputFile = combinedJar
562 }
Colin Cross0a6e0072017-08-30 14:24:55 -0700563
564 if j.properties.Jarjar_rules != nil {
565 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -0700566 // Transform classes.jar into classes-jarjar.jar
Colin Crosse9a275b2017-10-16 17:09:48 -0700567 jarjarFile := android.PathForModuleOut(ctx, "classes-jarjar.jar")
568 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
569 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -0700570 if ctx.Failed() {
571 return
572 }
573 }
574
Colin Cross2fe66872015-03-30 17:20:39 -0700575 j.classpathFile = outputFile
576
Colin Crossc157a8d2017-10-03 17:17:07 -0700577 if ctx.Device() && j.installable() {
Colin Cross540eff82017-06-22 17:01:52 -0700578 dxFlags := j.deviceProperties.Dxflags
Colin Cross2fe66872015-03-30 17:20:39 -0700579 if false /* emma enabled */ {
580 // If you instrument class files that have local variable debug information in
581 // them emma does not correctly maintain the local variable table.
582 // This will cause an error when you try to convert the class files for Android.
583 // The workaround here is to build different dex file here based on emma switch
584 // then later copy into classes.dex. When emma is on, dx is run with --no-locals
585 // option to remove local variable information
586 dxFlags = append(dxFlags, "--no-locals")
587 }
588
Colin Cross1332b002015-04-07 17:11:30 -0700589 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700590 dxFlags = append(dxFlags, "--no-optimize")
591 }
592
Colin Cross1332b002015-04-07 17:11:30 -0700593 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700594 dxFlags = append(dxFlags,
595 "--debug",
596 "--verbose",
Colin Cross635c3b02016-05-18 15:37:25 -0700597 "--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(),
Colin Cross2fe66872015-03-30 17:20:39 -0700598 "--dump-width=1000")
599 }
600
Colin Cross595a4062017-08-31 12:30:37 -0700601 var minSdkVersion string
602 switch j.deviceProperties.Sdk_version {
603 case "", "current", "test_current", "system_current":
604 minSdkVersion = strconv.Itoa(ctx.AConfig().DefaultAppTargetSdkInt())
605 default:
606 minSdkVersion = j.deviceProperties.Sdk_version
607 }
608
609 dxFlags = append(dxFlags, "--min-sdk-version="+minSdkVersion)
610
Colin Cross2fe66872015-03-30 17:20:39 -0700611 flags.dxFlags = strings.Join(dxFlags, " ")
612
Colin Cross6ade34f2017-09-15 13:00:47 -0700613 desugarFlags := []string{
614 "--min_sdk_version " + minSdkVersion,
615 "--desugar_try_with_resources_if_needed=false",
616 "--allow_empty_bootclasspath",
617 }
618
619 if inList("--core-library", dxFlags) {
620 desugarFlags = append(desugarFlags, "--core_library")
621 }
622
623 flags.desugarFlags = strings.Join(desugarFlags, " ")
624
Colin Crosse9a275b2017-10-16 17:09:48 -0700625 desugarJar := android.PathForModuleOut(ctx, "classes-desugar.jar")
626 TransformDesugar(ctx, desugarJar, outputFile, flags)
627 outputFile = desugarJar
Colin Cross2fe66872015-03-30 17:20:39 -0700628 if ctx.Failed() {
629 return
630 }
631
Colin Cross7db5d632017-10-04 17:07:09 -0700632 // Compile classes.jar into classes.dex and then javalib.jar
Colin Crosse9a275b2017-10-16 17:09:48 -0700633 javalibJar := android.PathForModuleOut(ctx, "javalib.jar")
634 TransformClassesJarToDexJar(ctx, javalibJar, desugarJar, flags)
635 outputFile = javalibJar
Colin Cross6ade34f2017-09-15 13:00:47 -0700636 if ctx.Failed() {
637 return
638 }
639
Colin Cross6ade34f2017-09-15 13:00:47 -0700640 j.dexJarFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700641 }
Colin Crossb7a63242015-04-16 14:09:14 -0700642 ctx.CheckbuildFile(outputFile)
643 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700644}
645
Colin Cross59f1bb62017-09-27 17:59:10 -0700646func (j *Module) installable() bool {
647 return j.properties.Installable == nil || *j.properties.Installable
648}
649
Colin Crossf506d872017-07-19 15:53:04 -0700650var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700651
Colin Cross74d73e22017-08-02 11:05:49 -0700652func (j *Module) ClasspathFiles() android.Paths {
653 return android.Paths{j.classpathFile}
Colin Cross2fe66872015-03-30 17:20:39 -0700654}
655
Colin Cross46c9b8b2017-06-22 16:51:17 -0700656func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700657 return j.exportAidlIncludeDirs
658}
659
Colin Cross46c9b8b2017-06-22 16:51:17 -0700660var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -0700661
Colin Cross46c9b8b2017-06-22 16:51:17 -0700662func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -0700663 return j.logtagsSrcs
664}
665
Colin Cross2fe66872015-03-30 17:20:39 -0700666//
667// Java libraries (.jar file)
668//
669
Colin Crossf506d872017-07-19 15:53:04 -0700670type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700671 Module
Colin Cross2fe66872015-03-30 17:20:39 -0700672}
673
Colin Crossf506d872017-07-19 15:53:04 -0700674func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700675 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -0700676
Colin Cross59f1bb62017-09-27 17:59:10 -0700677 if j.installable() {
Colin Cross2c429dc2017-08-31 16:45:16 -0700678 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
679 ctx.ModuleName()+".jar", j.outputFile)
680 }
Colin Crossb7a63242015-04-16 14:09:14 -0700681}
682
Colin Crossf506d872017-07-19 15:53:04 -0700683func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700684 j.deps(ctx)
685}
686
Colin Crossa60ead82017-10-02 18:10:21 -0700687func LibraryFactory(installable bool) func() android.Module {
688 return func() android.Module {
689 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -0700690
Colin Crossa60ead82017-10-02 18:10:21 -0700691 if !installable {
692 module.properties.Installable = proptools.BoolPtr(false)
693 }
Colin Cross2fe66872015-03-30 17:20:39 -0700694
Colin Crossa60ead82017-10-02 18:10:21 -0700695 module.AddProperties(
696 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -0700697 &module.Module.deviceProperties,
698 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -0700699
Colin Crossa60ead82017-10-02 18:10:21 -0700700 InitJavaModule(module, android.HostAndDeviceSupported)
701 return module
702 }
Colin Cross2fe66872015-03-30 17:20:39 -0700703}
704
Colin Crossf506d872017-07-19 15:53:04 -0700705func LibraryHostFactory() android.Module {
706 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -0700707
Colin Cross6af17aa2017-09-20 12:59:05 -0700708 module.AddProperties(
709 &module.Module.properties,
710 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -0700711
Colin Cross89536d42017-07-07 14:35:50 -0700712 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -0700713 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700714}
715
716//
717// Java Binaries (.jar file plus wrapper script)
718//
719
Colin Crossf506d872017-07-19 15:53:04 -0700720type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700721 // installable script to execute the resulting jar
722 Wrapper string
723}
724
Colin Crossf506d872017-07-19 15:53:04 -0700725type Binary struct {
726 Library
Colin Cross2fe66872015-03-30 17:20:39 -0700727
Colin Crossf506d872017-07-19 15:53:04 -0700728 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -0700729
730 wrapperFile android.ModuleSrcPath
731 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -0700732}
733
Colin Crossf506d872017-07-19 15:53:04 -0700734func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
735 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross2fe66872015-03-30 17:20:39 -0700736
737 // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
738 // another build rule before the jar has been installed.
Colin Cross10a03492017-08-10 17:09:43 -0700739 j.wrapperFile = android.PathForModuleSrc(ctx, j.binaryProperties.Wrapper)
Colin Cross5c517922017-08-31 12:29:17 -0700740 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
741 ctx.ModuleName(), j.wrapperFile, j.installFile)
Colin Cross2fe66872015-03-30 17:20:39 -0700742}
743
Colin Crossf506d872017-07-19 15:53:04 -0700744func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700745 j.deps(ctx)
746}
747
Colin Crossf506d872017-07-19 15:53:04 -0700748func BinaryFactory() android.Module {
749 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -0700750
Colin Cross36242852017-06-23 15:06:31 -0700751 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700752 &module.Module.properties,
753 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -0700754 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -0700755 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -0700756
Colin Cross89536d42017-07-07 14:35:50 -0700757 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -0700758 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700759}
760
Colin Crossf506d872017-07-19 15:53:04 -0700761func BinaryHostFactory() android.Module {
762 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -0700763
Colin Cross36242852017-06-23 15:06:31 -0700764 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700765 &module.Module.properties,
766 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -0700767 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -0700768 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -0700769
Colin Cross89536d42017-07-07 14:35:50 -0700770 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -0700771 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700772}
773
774//
775// Java prebuilts
776//
777
Colin Cross74d73e22017-08-02 11:05:49 -0700778type ImportProperties struct {
779 Jars []string
780}
781
782type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700783 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -0700784 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -0700785
Colin Cross74d73e22017-08-02 11:05:49 -0700786 properties ImportProperties
787
Colin Cross0a6e0072017-08-30 14:24:55 -0700788 classpathFiles android.Paths
789 combinedClasspathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700790}
791
Colin Cross74d73e22017-08-02 11:05:49 -0700792func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -0700793 return &j.prebuilt
794}
795
Colin Cross74d73e22017-08-02 11:05:49 -0700796func (j *Import) PrebuiltSrcs() []string {
797 return j.properties.Jars
798}
799
800func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -0700801 return j.prebuilt.Name(j.ModuleBase.Name())
802}
803
Colin Cross74d73e22017-08-02 11:05:49 -0700804func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross1e676be2016-10-12 14:38:15 -0700805}
806
Colin Cross74d73e22017-08-02 11:05:49 -0700807func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
808 j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -0700809
Colin Crosse9a275b2017-10-16 17:09:48 -0700810 outputFile := android.PathForModuleOut(ctx, "classes.jar")
811 TransformJarsToJar(ctx, outputFile, j.classpathFiles, android.OptionalPath{}, false)
812 j.combinedClasspathFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700813}
814
Colin Cross74d73e22017-08-02 11:05:49 -0700815var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700816
Colin Cross74d73e22017-08-02 11:05:49 -0700817func (j *Import) ClasspathFiles() android.Paths {
818 return j.classpathFiles
Colin Cross2fe66872015-03-30 17:20:39 -0700819}
820
Colin Cross74d73e22017-08-02 11:05:49 -0700821func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700822 return nil
823}
824
Colin Cross74d73e22017-08-02 11:05:49 -0700825var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700826
Colin Cross74d73e22017-08-02 11:05:49 -0700827func ImportFactory() android.Module {
828 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -0700829
Colin Cross74d73e22017-08-02 11:05:49 -0700830 module.AddProperties(&module.properties)
831
832 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -0700833 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
834 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700835}
836
Colin Cross74d73e22017-08-02 11:05:49 -0700837func ImportFactoryHost() android.Module {
838 module := &Import{}
839
840 module.AddProperties(&module.properties)
841
842 android.InitPrebuiltModule(module, &module.properties.Jars)
843 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
844 return module
845}
846
Colin Cross2fe66872015-03-30 17:20:39 -0700847func inList(s string, l []string) bool {
848 for _, e := range l {
849 if e == s {
850 return true
851 }
852 }
853 return false
854}
Colin Cross89536d42017-07-07 14:35:50 -0700855
856//
857// Defaults
858//
859type Defaults struct {
860 android.ModuleBase
861 android.DefaultsModuleBase
862}
863
864func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
865}
866
867func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
868}
869
870func defaultsFactory() android.Module {
871 return DefaultsFactory()
872}
873
874func DefaultsFactory(props ...interface{}) android.Module {
875 module := &Defaults{}
876
877 module.AddProperties(props...)
878 module.AddProperties(
879 &CompilerProperties{},
880 &CompilerDeviceProperties{},
881 )
882
883 android.InitDefaultsModule(module)
884
885 return module
886}