blob: 6485f06548817675aa4e599f93408667acf5ba74 [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 Crossb7a63242015-04-16 14:09:14 -0700172 // filelists of extra source files that should be included in the javac command line,
173 // for example R.java generated by aapt for android apps
Colin Cross635c3b02016-05-18 15:37:25 -0700174 ExtraSrcLists 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
373 srcFileLists 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 Cross32f676a2017-09-06 13:41:06 -0700425 deps.srcFileLists = append(deps.srcFileLists, module.(*AndroidApp).aaptJavaFileList)
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
486 var srcFileLists android.Paths
487
488 srcFiles, srcFileLists = j.genSources(ctx, srcFiles, flags)
489
490 srcFileLists = append(srcFileLists, deps.srcFileLists...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700491
Colin Cross6af17aa2017-09-20 12:59:05 -0700492 srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
Colin Crossb7a63242015-04-16 14:09:14 -0700493
Colin Cross0a6e0072017-08-30 14:24:55 -0700494 var jars android.Paths
495
Colin Cross8cf13342015-04-10 15:41:49 -0700496 if len(srcFiles) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -0700497 var extraJarDeps android.Paths
Colin Crossc6bbef32017-08-14 14:16:06 -0700498 if ctx.AConfig().IsEnvTrue("RUN_ERROR_PRONE") {
499 // If error-prone is enabled, add an additional rule to compile the java files into
500 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -0700501 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -0700502 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
503 // enable error-prone without affecting the output class files.
Colin Crosse9a275b2017-10-16 17:09:48 -0700504 errorprone := android.PathForModuleOut(ctx, "classes-errorprone.list")
505 RunErrorProne(ctx, errorprone, srcFiles, srcFileLists, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -0700506 extraJarDeps = append(extraJarDeps, errorprone)
507 }
508
Colin Crossd6891432017-09-27 17:39:56 -0700509 // Compile java sources into .class files
Colin Crosse9a275b2017-10-16 17:09:48 -0700510 classes := android.PathForModuleOut(ctx, "classes-compiled.jar")
511 TransformJavaToClasses(ctx, classes, srcFiles, srcFileLists, flags, extraJarDeps)
Colin Crossd6891432017-09-27 17:39:56 -0700512 if ctx.Failed() {
513 return
514 }
515
Colin Cross0a6e0072017-08-30 14:24:55 -0700516 jars = append(jars, classes)
Colin Cross2fe66872015-03-30 17:20:39 -0700517 }
518
Colin Cross0f37af02017-09-27 17:42:05 -0700519 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
520 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
521
522 var resArgs []string
523 var resDeps android.Paths
524
525 resArgs = append(resArgs, dirArgs...)
526 resDeps = append(resDeps, dirDeps...)
527
528 resArgs = append(resArgs, fileArgs...)
529 resDeps = append(resDeps, fileDeps...)
530
531 if proptools.Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -0700532 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700533 resArgs = append(resArgs, srcArgs...)
534 resDeps = append(resDeps, srcDeps...)
535 }
Colin Cross40a36712017-09-27 17:41:35 -0700536
537 if len(resArgs) > 0 {
Colin Crosse9a275b2017-10-16 17:09:48 -0700538 resourceJar := android.PathForModuleOut(ctx, "res.jar")
539 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -0700540 if ctx.Failed() {
541 return
542 }
Colin Cross20978302015-04-10 17:05:07 -0700543
Colin Cross0a6e0072017-08-30 14:24:55 -0700544 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -0700545 }
546
Colin Cross6ade34f2017-09-15 13:00:47 -0700547 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -0700548 jars = append(jars, deps.staticJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -0700549
Colin Cross635acc92017-09-12 22:50:46 -0700550 manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
551
Colin Cross0a6e0072017-08-30 14:24:55 -0700552 // Combine the classes built from sources, any manifests, and any static libraries into
Colin Cross8649b262017-09-27 18:03:17 -0700553 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -0700554 var outputFile android.Path
555
556 if len(jars) == 1 && !manifest.Valid() {
557 // Optimization: skip the combine step if there is nothing to do
558 outputFile = jars[0]
559 } else {
560 combinedJar := android.PathForModuleOut(ctx, "classes.jar")
561 TransformJarsToJar(ctx, combinedJar, jars, manifest, false)
562 outputFile = combinedJar
563 }
Colin Cross0a6e0072017-08-30 14:24:55 -0700564
565 if j.properties.Jarjar_rules != nil {
566 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -0700567 // Transform classes.jar into classes-jarjar.jar
Colin Crosse9a275b2017-10-16 17:09:48 -0700568 jarjarFile := android.PathForModuleOut(ctx, "classes-jarjar.jar")
569 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
570 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -0700571 if ctx.Failed() {
572 return
573 }
574 }
575
Colin Cross2fe66872015-03-30 17:20:39 -0700576 j.classpathFile = outputFile
577
Colin Crossc157a8d2017-10-03 17:17:07 -0700578 if ctx.Device() && j.installable() {
Colin Cross540eff82017-06-22 17:01:52 -0700579 dxFlags := j.deviceProperties.Dxflags
Colin Cross2fe66872015-03-30 17:20:39 -0700580 if false /* emma enabled */ {
581 // If you instrument class files that have local variable debug information in
582 // them emma does not correctly maintain the local variable table.
583 // This will cause an error when you try to convert the class files for Android.
584 // The workaround here is to build different dex file here based on emma switch
585 // then later copy into classes.dex. When emma is on, dx is run with --no-locals
586 // option to remove local variable information
587 dxFlags = append(dxFlags, "--no-locals")
588 }
589
Colin Cross1332b002015-04-07 17:11:30 -0700590 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700591 dxFlags = append(dxFlags, "--no-optimize")
592 }
593
Colin Cross1332b002015-04-07 17:11:30 -0700594 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700595 dxFlags = append(dxFlags,
596 "--debug",
597 "--verbose",
Colin Cross635c3b02016-05-18 15:37:25 -0700598 "--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(),
Colin Cross2fe66872015-03-30 17:20:39 -0700599 "--dump-width=1000")
600 }
601
Colin Cross595a4062017-08-31 12:30:37 -0700602 var minSdkVersion string
603 switch j.deviceProperties.Sdk_version {
604 case "", "current", "test_current", "system_current":
605 minSdkVersion = strconv.Itoa(ctx.AConfig().DefaultAppTargetSdkInt())
606 default:
607 minSdkVersion = j.deviceProperties.Sdk_version
608 }
609
610 dxFlags = append(dxFlags, "--min-sdk-version="+minSdkVersion)
611
Colin Cross2fe66872015-03-30 17:20:39 -0700612 flags.dxFlags = strings.Join(dxFlags, " ")
613
Colin Cross6ade34f2017-09-15 13:00:47 -0700614 desugarFlags := []string{
615 "--min_sdk_version " + minSdkVersion,
616 "--desugar_try_with_resources_if_needed=false",
617 "--allow_empty_bootclasspath",
618 }
619
620 if inList("--core-library", dxFlags) {
621 desugarFlags = append(desugarFlags, "--core_library")
622 }
623
624 flags.desugarFlags = strings.Join(desugarFlags, " ")
625
Colin Crosse9a275b2017-10-16 17:09:48 -0700626 desugarJar := android.PathForModuleOut(ctx, "classes-desugar.jar")
627 TransformDesugar(ctx, desugarJar, outputFile, flags)
628 outputFile = desugarJar
Colin Cross2fe66872015-03-30 17:20:39 -0700629 if ctx.Failed() {
630 return
631 }
632
Colin Cross7db5d632017-10-04 17:07:09 -0700633 // Compile classes.jar into classes.dex and then javalib.jar
Colin Crosse9a275b2017-10-16 17:09:48 -0700634 javalibJar := android.PathForModuleOut(ctx, "javalib.jar")
635 TransformClassesJarToDexJar(ctx, javalibJar, desugarJar, flags)
636 outputFile = javalibJar
Colin Cross6ade34f2017-09-15 13:00:47 -0700637 if ctx.Failed() {
638 return
639 }
640
Colin Cross6ade34f2017-09-15 13:00:47 -0700641 j.dexJarFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700642 }
Colin Crossb7a63242015-04-16 14:09:14 -0700643 ctx.CheckbuildFile(outputFile)
644 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700645}
646
Colin Cross59f1bb62017-09-27 17:59:10 -0700647func (j *Module) installable() bool {
648 return j.properties.Installable == nil || *j.properties.Installable
649}
650
Colin Crossf506d872017-07-19 15:53:04 -0700651var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700652
Colin Cross74d73e22017-08-02 11:05:49 -0700653func (j *Module) ClasspathFiles() android.Paths {
654 return android.Paths{j.classpathFile}
Colin Cross2fe66872015-03-30 17:20:39 -0700655}
656
Colin Cross46c9b8b2017-06-22 16:51:17 -0700657func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700658 return j.exportAidlIncludeDirs
659}
660
Colin Cross46c9b8b2017-06-22 16:51:17 -0700661var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -0700662
Colin Cross46c9b8b2017-06-22 16:51:17 -0700663func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -0700664 return j.logtagsSrcs
665}
666
Colin Cross2fe66872015-03-30 17:20:39 -0700667//
668// Java libraries (.jar file)
669//
670
Colin Crossf506d872017-07-19 15:53:04 -0700671type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700672 Module
Colin Cross2fe66872015-03-30 17:20:39 -0700673}
674
Colin Crossf506d872017-07-19 15:53:04 -0700675func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700676 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -0700677
Colin Cross59f1bb62017-09-27 17:59:10 -0700678 if j.installable() {
Colin Cross2c429dc2017-08-31 16:45:16 -0700679 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
680 ctx.ModuleName()+".jar", j.outputFile)
681 }
Colin Crossb7a63242015-04-16 14:09:14 -0700682}
683
Colin Crossf506d872017-07-19 15:53:04 -0700684func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700685 j.deps(ctx)
686}
687
Colin Crossa60ead82017-10-02 18:10:21 -0700688func LibraryFactory(installable bool) func() android.Module {
689 return func() android.Module {
690 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -0700691
Colin Crossa60ead82017-10-02 18:10:21 -0700692 if !installable {
693 module.properties.Installable = proptools.BoolPtr(false)
694 }
Colin Cross2fe66872015-03-30 17:20:39 -0700695
Colin Crossa60ead82017-10-02 18:10:21 -0700696 module.AddProperties(
697 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -0700698 &module.Module.deviceProperties,
699 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -0700700
Colin Crossa60ead82017-10-02 18:10:21 -0700701 InitJavaModule(module, android.HostAndDeviceSupported)
702 return module
703 }
Colin Cross2fe66872015-03-30 17:20:39 -0700704}
705
Colin Crossf506d872017-07-19 15:53:04 -0700706func LibraryHostFactory() android.Module {
707 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -0700708
Colin Cross6af17aa2017-09-20 12:59:05 -0700709 module.AddProperties(
710 &module.Module.properties,
711 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -0700712
Colin Cross89536d42017-07-07 14:35:50 -0700713 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -0700714 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700715}
716
717//
718// Java Binaries (.jar file plus wrapper script)
719//
720
Colin Crossf506d872017-07-19 15:53:04 -0700721type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700722 // installable script to execute the resulting jar
723 Wrapper string
724}
725
Colin Crossf506d872017-07-19 15:53:04 -0700726type Binary struct {
727 Library
Colin Cross2fe66872015-03-30 17:20:39 -0700728
Colin Crossf506d872017-07-19 15:53:04 -0700729 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -0700730
731 wrapperFile android.ModuleSrcPath
732 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -0700733}
734
Colin Crossf506d872017-07-19 15:53:04 -0700735func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
736 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross2fe66872015-03-30 17:20:39 -0700737
738 // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
739 // another build rule before the jar has been installed.
Colin Cross10a03492017-08-10 17:09:43 -0700740 j.wrapperFile = android.PathForModuleSrc(ctx, j.binaryProperties.Wrapper)
Colin Cross5c517922017-08-31 12:29:17 -0700741 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
742 ctx.ModuleName(), j.wrapperFile, j.installFile)
Colin Cross2fe66872015-03-30 17:20:39 -0700743}
744
Colin Crossf506d872017-07-19 15:53:04 -0700745func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700746 j.deps(ctx)
747}
748
Colin Crossf506d872017-07-19 15:53:04 -0700749func BinaryFactory() android.Module {
750 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -0700751
Colin Cross36242852017-06-23 15:06:31 -0700752 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700753 &module.Module.properties,
754 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -0700755 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -0700756 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -0700757
Colin Cross89536d42017-07-07 14:35:50 -0700758 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -0700759 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700760}
761
Colin Crossf506d872017-07-19 15:53:04 -0700762func BinaryHostFactory() android.Module {
763 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -0700764
Colin Cross36242852017-06-23 15:06:31 -0700765 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700766 &module.Module.properties,
767 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -0700768 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -0700769 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -0700770
Colin Cross89536d42017-07-07 14:35:50 -0700771 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -0700772 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700773}
774
775//
776// Java prebuilts
777//
778
Colin Cross74d73e22017-08-02 11:05:49 -0700779type ImportProperties struct {
780 Jars []string
781}
782
783type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700784 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -0700785 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -0700786
Colin Cross74d73e22017-08-02 11:05:49 -0700787 properties ImportProperties
788
Colin Cross0a6e0072017-08-30 14:24:55 -0700789 classpathFiles android.Paths
790 combinedClasspathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700791}
792
Colin Cross74d73e22017-08-02 11:05:49 -0700793func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -0700794 return &j.prebuilt
795}
796
Colin Cross74d73e22017-08-02 11:05:49 -0700797func (j *Import) PrebuiltSrcs() []string {
798 return j.properties.Jars
799}
800
801func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -0700802 return j.prebuilt.Name(j.ModuleBase.Name())
803}
804
Colin Cross74d73e22017-08-02 11:05:49 -0700805func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross1e676be2016-10-12 14:38:15 -0700806}
807
Colin Cross74d73e22017-08-02 11:05:49 -0700808func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
809 j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -0700810
Colin Crosse9a275b2017-10-16 17:09:48 -0700811 outputFile := android.PathForModuleOut(ctx, "classes.jar")
812 TransformJarsToJar(ctx, outputFile, j.classpathFiles, android.OptionalPath{}, false)
813 j.combinedClasspathFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700814}
815
Colin Cross74d73e22017-08-02 11:05:49 -0700816var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700817
Colin Cross74d73e22017-08-02 11:05:49 -0700818func (j *Import) ClasspathFiles() android.Paths {
819 return j.classpathFiles
Colin Cross2fe66872015-03-30 17:20:39 -0700820}
821
Colin Cross74d73e22017-08-02 11:05:49 -0700822func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700823 return nil
824}
825
Colin Cross74d73e22017-08-02 11:05:49 -0700826var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700827
Colin Cross74d73e22017-08-02 11:05:49 -0700828func ImportFactory() android.Module {
829 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -0700830
Colin Cross74d73e22017-08-02 11:05:49 -0700831 module.AddProperties(&module.properties)
832
833 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -0700834 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
835 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700836}
837
Colin Cross74d73e22017-08-02 11:05:49 -0700838func ImportFactoryHost() android.Module {
839 module := &Import{}
840
841 module.AddProperties(&module.properties)
842
843 android.InitPrebuiltModule(module, &module.properties.Jars)
844 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
845 return module
846}
847
Colin Cross2fe66872015-03-30 17:20:39 -0700848func inList(s string, l []string) bool {
849 for _, e := range l {
850 if e == s {
851 return true
852 }
853 }
854 return false
855}
Colin Cross89536d42017-07-07 14:35:50 -0700856
857//
858// Defaults
859//
860type Defaults struct {
861 android.ModuleBase
862 android.DefaultsModuleBase
863}
864
865func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
866}
867
868func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
869}
870
871func defaultsFactory() android.Module {
872 return DefaultsFactory()
873}
874
875func DefaultsFactory(props ...interface{}) android.Module {
876 module := &Defaults{}
877
878 module.AddProperties(props...)
879 module.AddProperties(
880 &CompilerProperties{},
881 &CompilerDeviceProperties{},
882 )
883
884 android.InitDefaultsModule(module)
885
886 return module
887}