blob: d9075b175a2ac3042b378204d82349ac6202ec65 [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 Cross463a90e2015-06-17 14:20:06 -070044
Colin Cross798bfce2016-10-12 14:28:16 -070045 android.RegisterSingletonType("logtags", LogtagsSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -070046}
47
Colin Cross2fe66872015-03-30 17:20:39 -070048// TODO:
49// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070050// Renderscript
51// Post-jar passes:
52// Proguard
Colin Cross2fe66872015-03-30 17:20:39 -070053// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -070054// DroidDoc
55// Findbugs
56
Colin Cross89536d42017-07-07 14:35:50 -070057type CompilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -070058 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
59 // or .aidl files.
Dan Willemsen2ef08f42015-06-30 18:15:24 -070060 Srcs []string `android:"arch_variant"`
61
62 // list of source files that should not be used to build the Java module.
63 // This is most useful in the arch/multilib variants to remove non-common files
64 Exclude_srcs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070065
66 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -070067 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070068
Colin Cross86a63ff2017-09-27 17:33:10 -070069 // list of directories that should be excluded from java_resource_dirs
70 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -070071
Colin Cross0f37af02017-09-27 17:42:05 -070072 // list of files to use as Java resources
73 Java_resources []string `android:"arch_variant"`
74
75 // list of files that should be excluded from java_resources
76 Exclude_java_resources []string `android:"arch_variant"`
77
Colin Crossfa5eb232017-10-01 20:33:03 -070078 // don't build against the default libraries (bootclasspath, legacy-test, core-junit,
Colin Cross7d5136f2015-05-11 13:39:40 -070079 // ext, and framework for device targets)
Colin Cross76b5f0c2017-08-29 16:02:06 -070080 No_standard_libs *bool
Colin Cross7d5136f2015-05-11 13:39:40 -070081
Colin Crossfa5eb232017-10-01 20:33:03 -070082 // don't build against the framework libraries (legacy-test, core-junit,
83 // ext, and framework for device targets)
84 No_framework_libs *bool
85
Colin Cross7d5136f2015-05-11 13:39:40 -070086 // list of module-specific flags that will be used for javac compiles
87 Javacflags []string `android:"arch_variant"`
88
Colin Cross7d5136f2015-05-11 13:39:40 -070089 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -070090 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070091
92 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -070093 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070094
95 // manifest file to be included in resulting jar
Dan Willemsen34cc69e2015-09-23 15:26:20 -070096 Manifest *string
Colin Cross7d5136f2015-05-11 13:39:40 -070097
Colin Cross540eff82017-06-22 17:01:52 -070098 // if not blank, run jarjar using the specified rules file
Colin Cross975f9f72017-10-17 13:55:55 -070099 Jarjar_rules *string `android:"arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700100
101 // If not blank, set the java version passed to javac as -source and -target
102 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700103
104 // If set to false, don't allow this module to be installed. Defaults to true.
105 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700106
Colin Cross0f37af02017-09-27 17:42:05 -0700107 // If set to true, include sources used to compile the module in to the final jar
108 Include_srcs *bool
109
Colin Cross32f676a2017-09-06 13:41:06 -0700110 // List of modules to use as annotation processors
111 Annotation_processors []string
112
113 // List of classes to pass to javac to use as annotation processors
114 Annotation_processor_classes []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700115
Nan Zhang61eaedb2017-11-02 13:28:15 -0700116 // The number of Java source entries each Javac instance can process
117 Javac_shard_size *int64
118
Colin Cross1369cdb2017-09-29 17:58:17 -0700119 Openjdk9 struct {
120 // List of source files that should only be used when passing -source 1.9
121 Srcs []string
122
123 // List of javac flags that should only be used when passing -source 1.9
124 Javacflags []string
125 }
Colin Crosscb933592017-11-22 13:49:43 -0800126
127 Jacoco struct {
128 // List of classes to include for instrumentation with jacoco to collect coverage
129 // information at runtime when building with coverage enabled. If unset defaults to all
130 // classes.
131 // Supports '*' as the last character of an entry in the list as a wildcard match.
132 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
133 // it matches classes in the package that have the class name as a prefix.
134 Include_filter []string
135
136 // List of classes to exclude from instrumentation with jacoco to collect coverage
137 // information at runtime when building with coverage enabled. Overrides classes selected
138 // by the include_filter property.
139 // Supports '*' as the last character of an entry in the list as a wildcard match.
140 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
141 // it matches classes in the package that have the class name as a prefix.
142 Exclude_filter []string
143 }
144
145 Instrument bool `blueprint:"mutated"`
Colin Cross540eff82017-06-22 17:01:52 -0700146}
147
Colin Cross89536d42017-07-07 14:35:50 -0700148type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700149 // list of module-specific flags that will be used for dex compiles
150 Dxflags []string `android:"arch_variant"`
151
Colin Cross7d5136f2015-05-11 13:39:40 -0700152 // if not blank, set to the version of the sdk to compile against
Nan Zhangea568a42017-11-08 21:20:04 -0800153 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700154
Colin Crossebe1a512017-11-14 13:12:14 -0800155 Aidl struct {
156 // Top level directories to pass to aidl tool
157 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700158
Colin Crossebe1a512017-11-14 13:12:14 -0800159 // Directories rooted at the Android.bp file to pass to aidl tool
160 Local_include_dirs []string
161
162 // directories that should be added as include directories for any aidl sources of modules
163 // that depend on this module, as well as to aidl for this module.
164 Export_include_dirs []string
165 }
Colin Cross92430102017-10-09 14:59:32 -0700166
167 // If true, export a copy of the module as a -hostdex module for host testing.
168 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700169
Colin Cross1bd87802017-12-05 15:31:19 -0800170 Dex_preopt struct {
171 // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to
172 // true.
173 Enabled *bool
174
175 // If true, generate an app image (.art file) for this module.
176 App_image *bool
177
178 // If true, use a checked-in profile to guide optimization. Defaults to false unless
179 // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR
180 // that matches the name of this module, in which case it is defaulted to true.
181 Profile_guided *bool
182
183 // If set, provides the path to profile relative to the Android.bp file. If not set,
184 // defaults to searching for a file that matches the name of this module in the default
185 // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found.
186 Profile *string
187 }
Colin Crossa22116e2017-10-19 14:18:58 -0700188
Colin Cross1369cdb2017-09-29 17:58:17 -0700189 // When targeting 1.9, override the modules to use with --system
190 System_modules *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700191}
192
Colin Cross46c9b8b2017-06-22 16:51:17 -0700193// Module contains the properties and members used by all java module types
194type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700195 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700196 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700197
Colin Cross89536d42017-07-07 14:35:50 -0700198 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700199 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700200 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700201
Nan Zhanged19fc32017-10-19 13:06:22 -0700202 // header jar file suitable for inserting into the bootclasspath/classpath of another compile
203 headerJarFile android.Path
204
205 // full implementation jar file suitable for static dependency of another module compile
206 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700207
Colin Cross6ade34f2017-09-15 13:00:47 -0700208 // output file containing classes.dex
209 dexJarFile android.Path
210
Colin Crosscb933592017-11-22 13:49:43 -0800211 // output file containing uninstrumented classes that will be instrumented by jacoco
212 jacocoReportClassesFile android.Path
213
Colin Crossb7a63242015-04-16 14:09:14 -0700214 // output file suitable for installing or running
Colin Cross635c3b02016-05-18 15:37:25 -0700215 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700216
Colin Cross635c3b02016-05-18 15:37:25 -0700217 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700218
Colin Cross635c3b02016-05-18 15:37:25 -0700219 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700220
Colin Cross2fe66872015-03-30 17:20:39 -0700221 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700222 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800223
224 // list of .java files and srcjars that was passed to javac
225 compiledJavaSrcs android.Paths
226 compiledSrcJars android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700227}
228
Colin Cross54250902017-12-05 09:28:08 -0800229func (j *Module) Srcs() android.Paths {
230 return android.Paths{j.implementationJarFile}
231}
232
233var _ android.SourceFileProducer = (*Module)(nil)
234
Colin Crossf506d872017-07-19 15:53:04 -0700235type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700236 HeaderJars() android.Paths
237 ImplementationJars() android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700238 AidlIncludeDirs() android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700239}
240
Colin Cross89536d42017-07-07 14:35:50 -0700241func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
242 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
243 android.InitDefaultableModule(module)
244}
245
Colin Crossbe1da472017-07-07 15:59:46 -0700246type dependencyTag struct {
247 blueprint.BaseDependencyTag
248 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700249}
250
Colin Crossbe1da472017-07-07 15:59:46 -0700251var (
Colin Cross6ade34f2017-09-15 13:00:47 -0700252 staticLibTag = dependencyTag{name: "staticlib"}
253 libTag = dependencyTag{name: "javalib"}
254 bootClasspathTag = dependencyTag{name: "bootclasspath"}
Colin Cross1369cdb2017-09-29 17:58:17 -0700255 systemModulesTag = dependencyTag{name: "system modules"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700256 frameworkResTag = dependencyTag{name: "framework-res"}
Colin Cross93e85952017-08-15 13:34:18 -0700257 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossbe1da472017-07-07 15:59:46 -0700258)
Colin Cross2fe66872015-03-30 17:20:39 -0700259
Colin Crossfc3674a2017-09-18 17:41:52 -0700260type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700261 useModule, useFiles, useDefaultLibs, invalidVersion bool
262
Colin Cross1369cdb2017-09-29 17:58:17 -0700263 module string
264 systemModules string
265
266 jar android.Path
267 aidl android.Path
268}
269
270func sdkStringToNumber(ctx android.BaseContext, v string) int {
271 switch v {
272 case "", "current", "system_current", "test_current":
273 return 10000
274 default:
Sundong Ahn0926fae2017-10-17 16:34:51 +0900275 if i, err := strconv.Atoi(android.GetNumericSdkVersion(v)); err != nil {
Colin Cross1369cdb2017-09-29 17:58:17 -0700276 ctx.PropertyErrorf("sdk_version", "invalid sdk version")
277 return -1
278 } else {
279 return i
280 }
281 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700282}
283
284func decodeSdkDep(ctx android.BaseContext, v string) sdkDep {
Colin Cross1369cdb2017-09-29 17:58:17 -0700285 i := sdkStringToNumber(ctx, v)
286 if i == -1 {
287 // Invalid sdk version, error handled by sdkStringToNumber.
288 return sdkDep{}
Colin Crossfc3674a2017-09-18 17:41:52 -0700289 }
290
291 toFile := func(v string) sdkDep {
292 dir := filepath.Join("prebuilts/sdk", v)
293 jar := filepath.Join(dir, "android.jar")
294 aidl := filepath.Join(dir, "framework.aidl")
295 jarPath := android.ExistentPathForSource(ctx, "sdkdir", jar)
296 aidlPath := android.ExistentPathForSource(ctx, "sdkdir", aidl)
Colin Cross47ff2522017-10-02 14:22:08 -0700297
Colin Cross6510f912017-11-29 00:27:14 -0800298 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
Sundong Ahn0926fae2017-10-17 16:34:51 +0900299 if strings.Contains(v, "system_") {
300 return sdkDep{
301 invalidVersion: true,
302 module: "vsdk_v" + strings.Replace(v, "system_", "", 1),
303 }
304 }
Colin Cross47ff2522017-10-02 14:22:08 -0700305 return sdkDep{
306 invalidVersion: true,
307 module: "sdk_v" + v,
308 }
309 }
310
Colin Crossfc3674a2017-09-18 17:41:52 -0700311 if !jarPath.Valid() {
312 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar)
313 return sdkDep{}
314 }
Colin Cross47ff2522017-10-02 14:22:08 -0700315
Colin Crossfc3674a2017-09-18 17:41:52 -0700316 if !aidlPath.Valid() {
317 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl)
318 return sdkDep{}
319 }
Colin Cross47ff2522017-10-02 14:22:08 -0700320
Colin Crossfc3674a2017-09-18 17:41:52 -0700321 return sdkDep{
322 useFiles: true,
323 jar: jarPath.Path(),
324 aidl: aidlPath.Path(),
325 }
326 }
327
Colin Cross2ebc4762017-10-20 14:00:31 -0700328 //toModule := func(m string) sdkDep {
329 // return sdkDep{
330 // useModule: true,
331 // module: m,
332 // systemModules: m + "_system_modules",
333 // }
334 //}
Colin Crossfc3674a2017-09-18 17:41:52 -0700335
Colin Cross6510f912017-11-29 00:27:14 -0800336 if ctx.Config().UnbundledBuild() && v != "" {
Colin Crossfc3674a2017-09-18 17:41:52 -0700337 return toFile(v)
338 }
339
340 switch v {
341 case "":
342 return sdkDep{
343 useDefaultLibs: true,
344 }
Colin Cross2ebc4762017-10-20 14:00:31 -0700345 // TODO(ccross): re-enable these once we generate stubs, until then
346 // use the stubs in prebuilts/sdk/*current
347 //case "current":
348 // return toModule("android_stubs_current")
349 //case "system_current":
350 // return toModule("android_system_stubs_current")
351 //case "test_current":
352 // return toModule("android_test_stubs_current")
Colin Crossfc3674a2017-09-18 17:41:52 -0700353 default:
354 return toFile(v)
355 }
356}
357
Colin Crossbe1da472017-07-07 15:59:46 -0700358func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700359 if ctx.Device() {
360 if !proptools.Bool(j.properties.No_standard_libs) {
Nan Zhangea568a42017-11-08 21:20:04 -0800361 sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
Colin Crossfc3674a2017-09-18 17:41:52 -0700362 if sdkDep.useDefaultLibs {
Colin Crosscb2c9292017-09-23 19:57:16 -0700363 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Colin Cross6510f912017-11-29 00:27:14 -0800364 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700365 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
366 }
Colin Crossfa5eb232017-10-01 20:33:03 -0700367 if !proptools.Bool(j.properties.No_framework_libs) {
368 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
369 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700370 } else if sdkDep.useModule {
Colin Cross6510f912017-11-29 00:27:14 -0800371 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700372 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
373 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700374 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module)
Colin Crossbe1da472017-07-07 15:59:46 -0700375 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700376 } else if j.deviceProperties.System_modules == nil {
377 ctx.PropertyErrorf("no_standard_libs",
378 "system_modules is required to be set when no_standard_libs is true, did you mean no_framework_libs?")
Colin Cross6510f912017-11-29 00:27:14 -0800379 } else if *j.deviceProperties.System_modules != "none" && ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700380 ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700381 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800382 if ctx.ModuleName() == "framework" {
383 ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res")
384 }
Colin Cross2fe66872015-03-30 17:20:39 -0700385 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700386
Colin Crossf506d872017-07-19 15:53:04 -0700387 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
388 ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
Colin Cross6ade34f2017-09-15 13:00:47 -0700389 ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...)
Colin Cross7f9036c2017-08-30 13:27:57 -0700390
391 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700392 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross366938f2017-12-11 16:29:02 -0800393 android.ExtractSourceDeps(ctx, j.properties.Manifest)
Colin Cross6af17aa2017-09-20 12:59:05 -0700394
395 if j.hasSrcExt(".proto") {
396 protoDeps(ctx, &j.protoProperties)
397 }
Colin Cross93e85952017-08-15 13:34:18 -0700398
399 if j.hasSrcExt(".kt") {
400 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
401 // Kotlin files
402 ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib")
403 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700404}
405
406func hasSrcExt(srcs []string, ext string) bool {
407 for _, src := range srcs {
408 if filepath.Ext(src) == ext {
409 return true
410 }
411 }
412
413 return false
414}
415
Nan Zhang61eaedb2017-11-02 13:28:15 -0700416func shardPaths(paths android.Paths, shardSize int) []android.Paths {
417 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
418 for len(paths) > shardSize {
419 ret = append(ret, paths[0:shardSize])
420 paths = paths[shardSize:]
421 }
422 if len(paths) > 0 {
423 ret = append(ret, paths)
424 }
425 return ret
426}
427
Colin Cross6af17aa2017-09-20 12:59:05 -0700428func (j *Module) hasSrcExt(ext string) bool {
429 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700430}
431
Colin Cross46c9b8b2017-06-22 16:51:17 -0700432func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700433 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700434
Colin Crossebe1a512017-11-14 13:12:14 -0800435 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
436 aidlIncludes = append(aidlIncludes,
437 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
438 aidlIncludes = append(aidlIncludes,
439 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700440
441 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700442 if aidlPreprocess.Valid() {
443 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700444 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700445 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700446 }
447
Colin Cross635c3b02016-05-18 15:37:25 -0700448 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800449 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700450 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Crosse243c232017-10-21 15:16:37 -0700451 if src := android.ExistentPathForSource(ctx, "", ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700452 flags = append(flags, "-I"+src.String())
453 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700454
Colin Crossf03c82b2015-04-13 13:53:40 -0700455 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700456}
457
Colin Cross32f676a2017-09-06 13:41:06 -0700458type deps struct {
Colin Cross6ade34f2017-09-15 13:00:47 -0700459 classpath android.Paths
460 bootClasspath android.Paths
461 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700462 staticHeaderJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700463 staticJarResources android.Paths
464 aidlIncludeDirs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700465 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700466 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700467 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700468 kotlinStdlib android.Paths
Colin Cross32f676a2017-09-06 13:41:06 -0700469}
Colin Cross2fe66872015-03-30 17:20:39 -0700470
Colin Cross54250902017-12-05 09:28:08 -0800471func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
472 for _, f := range dep.Srcs() {
473 if f.Ext() != ".jar" {
474 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
475 ctx.OtherModuleName(dep.(blueprint.Module)))
476 }
477 }
478}
479
Colin Cross32f676a2017-09-06 13:41:06 -0700480func (j *Module) collectDeps(ctx android.ModuleContext) deps {
481 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700482
Nan Zhangea568a42017-11-08 21:20:04 -0800483 sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
Colin Cross47ff2522017-10-02 14:22:08 -0700484 if sdkDep.invalidVersion {
485 ctx.AddMissingDependencies([]string{sdkDep.module})
486 } else if sdkDep.useFiles {
Nan Zhanged19fc32017-10-19 13:06:22 -0700487 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Crossfc3674a2017-09-18 17:41:52 -0700488 deps.classpath = append(deps.classpath, sdkDep.jar)
489 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
490 }
491
Colin Crossd11fcda2017-10-23 17:59:01 -0700492 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700493 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700494 tag := ctx.OtherModuleDependencyTag(module)
495
Colin Cross54250902017-12-05 09:28:08 -0800496 switch dep := module.(type) {
497 case Dependency:
498 switch tag {
499 case bootClasspathTag:
500 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
501 case libTag:
502 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
503 case staticLibTag:
504 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
505 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
506 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
507 case frameworkResTag:
508 if ctx.ModuleName() == "framework" {
509 // framework.jar has a one-off dependency on the R.java and Manifest.java files
510 // generated by framework-res.apk
511 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
512 }
513 case kotlinStdlibTag:
514 deps.kotlinStdlib = dep.HeaderJars()
515 default:
516 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
517 }
518
519 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
520 case android.SourceFileProducer:
521 switch tag {
522 case libTag:
523 checkProducesJars(ctx, dep)
524 deps.classpath = append(deps.classpath, dep.Srcs()...)
525 case staticLibTag:
526 checkProducesJars(ctx, dep)
527 deps.classpath = append(deps.classpath, dep.Srcs()...)
528 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
529 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
530 case android.DefaultsDepTag, android.SourceDepTag:
531 // Nothing to do
532 default:
533 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
534 }
535 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700536 switch tag {
537 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700538 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700539 case systemModulesTag:
540 if deps.systemModules != nil {
541 panic("Found two system module dependencies")
542 }
543 sm := module.(*SystemModules)
544 if sm.outputFile == nil {
545 panic("Missing directory for system module dependency")
546 }
547 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700548 default:
549 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700550 }
Colin Crossec7a0422017-07-07 14:47:12 -0700551 }
Colin Cross2fe66872015-03-30 17:20:39 -0700552 })
553
Colin Cross32f676a2017-09-06 13:41:06 -0700554 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700555}
556
Nan Zhanged19fc32017-10-19 13:06:22 -0700557func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700558
Colin Crossf03c82b2015-04-13 13:53:40 -0700559 var flags javaBuilderFlags
560
Nan Zhanged19fc32017-10-19 13:06:22 -0700561 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700562 javacFlags := j.properties.Javacflags
Colin Cross6510f912017-11-29 00:27:14 -0800563 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700564 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700565 }
Colin Cross6510f912017-11-29 00:27:14 -0800566 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700567 // Override the -g flag passed globally to remove local variable debug info to reduce
568 // disk and memory usage.
569 javacFlags = append(javacFlags, "-g:source,lines")
570 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700571 if len(javacFlags) > 0 {
572 // optimization.
573 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
574 flags.javacFlags = "$javacFlags"
Colin Cross4f26bc02017-09-06 12:52:16 -0700575 }
Colin Cross64162712017-08-08 13:17:59 -0700576
Nan Zhanged19fc32017-10-19 13:06:22 -0700577 // javaVersion flag.
Nan Zhangea568a42017-11-08 21:20:04 -0800578 sdk := sdkStringToNumber(ctx, String(j.deviceProperties.Sdk_version))
Colin Cross64162712017-08-08 13:17:59 -0700579 if j.properties.Java_version != nil {
580 flags.javaVersion = *j.properties.Java_version
Colin Cross1369cdb2017-09-29 17:58:17 -0700581 } else if ctx.Device() && sdk <= 23 {
582 flags.javaVersion = "1.7"
Colin Cross6510f912017-11-29 00:27:14 -0800583 } else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700584 flags.javaVersion = "1.8"
Nan Zhangea568a42017-11-08 21:20:04 -0800585 } else if ctx.Device() && String(j.deviceProperties.Sdk_version) != "" && sdk == 10000 {
Colin Cross2ebc4762017-10-20 14:00:31 -0700586 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
587 flags.javaVersion = "1.8"
Colin Cross64162712017-08-08 13:17:59 -0700588 } else {
Colin Cross1369cdb2017-09-29 17:58:17 -0700589 flags.javaVersion = "1.9"
Colin Cross64162712017-08-08 13:17:59 -0700590 }
591
Nan Zhanged19fc32017-10-19 13:06:22 -0700592 // classpath
Colin Cross6ade34f2017-09-15 13:00:47 -0700593 flags.bootClasspath.AddPaths(deps.bootClasspath)
594 flags.classpath.AddPaths(deps.classpath)
Nan Zhanged19fc32017-10-19 13:06:22 -0700595 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700596 if deps.systemModules != nil {
597 flags.systemModules = append(flags.systemModules, deps.systemModules)
598 }
599
Nan Zhanged19fc32017-10-19 13:06:22 -0700600 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700601 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700602 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700603 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700604 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
605 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700606 }
607
Nan Zhanged19fc32017-10-19 13:06:22 -0700608 return flags
609}
Colin Crossc0b06f12015-04-08 13:03:43 -0700610
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800611func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700612
Colin Crossebe1a512017-11-14 13:12:14 -0800613 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700614
615 deps := j.collectDeps(ctx)
616 flags := j.collectBuilderFlags(ctx, deps)
617
Colin Cross6510f912017-11-29 00:27:14 -0800618 if ctx.Config().TargetOpenJDK9() {
Nan Zhanged19fc32017-10-19 13:06:22 -0700619 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
620 }
621 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700622 if hasSrcExt(srcFiles.Strings(), ".proto") {
623 flags = protoFlags(ctx, &j.protoProperties, flags)
624 }
625
Colin Crossaf050172017-11-15 23:01:59 -0800626 srcFiles = j.genSources(ctx, srcFiles, flags)
627
628 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700629 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800630 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700631
Colin Cross0a6e0072017-08-30 14:24:55 -0700632 var jars android.Paths
633
Colin Cross1ee23172017-10-18 14:44:18 -0700634 jarName := ctx.ModuleName() + ".jar"
635
Colin Cross93e85952017-08-15 13:34:18 -0700636 if srcFiles.HasExt(".kt") {
637 // If there are kotlin files, compile them first but pass all the kotlin and java files
638 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
639 // won't emit any classes for them.
640
641 flags.kotlincFlags = "-no-stdlib"
642 if ctx.Device() {
643 flags.kotlincFlags += " -no-jdk"
644 }
645
646 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
647 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
648
Colin Cross1ee23172017-10-18 14:44:18 -0700649 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross93e85952017-08-15 13:34:18 -0700650 TransformKotlinToClasses(ctx, kotlinJar, srcFiles, srcJars, flags)
651 if ctx.Failed() {
652 return
653 }
654
655 // Make javac rule depend on the kotlinc rule
656 flags.classpath = append(flags.classpath, kotlinJar)
657 // Jar kotlin classes into the final jar after javac
658 jars = append(jars, kotlinJar)
659 jars = append(jars, deps.kotlinStdlib...)
660 }
661
Nan Zhanged19fc32017-10-19 13:06:22 -0700662 javaSrcFiles := srcFiles.FilterByExt(".java")
663 var uniqueSrcFiles android.Paths
664 set := make(map[string]bool)
665 for _, v := range javaSrcFiles {
666 if _, found := set[v.String()]; !found {
667 set[v.String()] = true
668 uniqueSrcFiles = append(uniqueSrcFiles, v)
669 }
670 }
671
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800672 // Store the list of .java files that was passed to javac
673 j.compiledJavaSrcs = uniqueSrcFiles
674 j.compiledSrcJars = srcJars
Alan Leung9f319112017-11-30 15:50:39 -0800675 fullD8 := ctx.AConfig().IsEnvTrue("USE_D8_DESUGAR")
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800676
Nan Zhang61eaedb2017-11-02 13:28:15 -0700677 enable_sharding := false
Colin Cross6510f912017-11-29 00:27:14 -0800678 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") {
Nan Zhang61eaedb2017-11-02 13:28:15 -0700679 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
680 enable_sharding = true
681 if len(j.properties.Annotation_processors) != 0 ||
682 len(j.properties.Annotation_processor_classes) != 0 {
683 ctx.PropertyErrorf("javac_shard_size",
684 "%q cannot be set when annotation processors are enabled.",
685 j.properties.Javac_shard_size)
686 }
687 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700688 // If sdk jar is java module, then directly return classesJar as header.jar
689 if j.Name() != "android_stubs_current" && j.Name() != "android_system_stubs_current" &&
690 j.Name() != "android_test_stubs_current" {
691 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName)
692 if ctx.Failed() {
693 return
694 }
695 }
696 }
Colin Cross8eadbf02017-10-24 17:46:00 -0700697 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -0700698 var extraJarDeps android.Paths
Colin Cross6510f912017-11-29 00:27:14 -0800699 if ctx.Config().IsEnvTrue("RUN_ERROR_PRONE") {
Colin Crossc6bbef32017-08-14 14:16:06 -0700700 // If error-prone is enabled, add an additional rule to compile the java files into
701 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -0700702 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -0700703 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
704 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -0700705 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -0700706 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -0700707 extraJarDeps = append(extraJarDeps, errorprone)
708 }
709
Nan Zhang61eaedb2017-11-02 13:28:15 -0700710 if enable_sharding {
711 flags.classpath.AddPaths([]android.Path{j.headerJarFile})
712 shardSize := int(*(j.properties.Javac_shard_size))
713 var shardSrcs []android.Paths
714 if len(uniqueSrcFiles) > 0 {
715 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
716 for idx, shardSrc := range shardSrcs {
717 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
718 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
719 jars = append(jars, classes)
720 }
721 }
722 if len(srcJars) > 0 {
723 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
724 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
725 jars = append(jars, classes)
726 }
727 } else {
728 classes := android.PathForModuleOut(ctx, "javac", jarName)
729 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
730 jars = append(jars, classes)
731 }
Colin Crossd6891432017-09-27 17:39:56 -0700732 if ctx.Failed() {
733 return
734 }
Colin Cross2fe66872015-03-30 17:20:39 -0700735 }
736
Colin Cross0f37af02017-09-27 17:42:05 -0700737 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
738 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
739
740 var resArgs []string
741 var resDeps android.Paths
742
743 resArgs = append(resArgs, dirArgs...)
744 resDeps = append(resDeps, dirDeps...)
745
746 resArgs = append(resArgs, fileArgs...)
747 resDeps = append(resDeps, fileDeps...)
748
749 if proptools.Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -0700750 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700751 resArgs = append(resArgs, srcArgs...)
752 resDeps = append(resDeps, srcDeps...)
753 }
Colin Cross40a36712017-09-27 17:41:35 -0700754
755 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -0700756 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700757 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -0700758 if ctx.Failed() {
759 return
760 }
Colin Cross20978302015-04-10 17:05:07 -0700761
Colin Cross0a6e0072017-08-30 14:24:55 -0700762 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -0700763 }
764
Colin Cross6ade34f2017-09-15 13:00:47 -0700765 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -0700766 jars = append(jars, deps.staticJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -0700767
Colin Cross366938f2017-12-11 16:29:02 -0800768 var manifest android.OptionalPath
769 if j.properties.Manifest != nil {
770 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
771 }
Colin Cross635acc92017-09-12 22:50:46 -0700772
Colin Cross0a6e0072017-08-30 14:24:55 -0700773 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -0700774 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -0700775 var outputFile android.Path
776
777 if len(jars) == 1 && !manifest.Valid() {
778 // Optimization: skip the combine step if there is nothing to do
779 outputFile = jars[0]
780 } else {
Colin Cross1ee23172017-10-18 14:44:18 -0700781 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Nan Zhanged19fc32017-10-19 13:06:22 -0700782 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -0700783 outputFile = combinedJar
784 }
Colin Cross0a6e0072017-08-30 14:24:55 -0700785
786 if j.properties.Jarjar_rules != nil {
787 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -0700788 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -0700789 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700790 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
791 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -0700792 if ctx.Failed() {
793 return
794 }
795 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700796 j.implementationJarFile = outputFile
797 if j.headerJarFile == nil {
798 j.headerJarFile = j.implementationJarFile
799 }
Colin Cross2fe66872015-03-30 17:20:39 -0700800
Alan Leung9f319112017-11-30 15:50:39 -0800801 if !fullD8 && ctx.Device() && j.installable() {
Colin Crosscb933592017-11-22 13:49:43 -0800802 outputFile = j.desugar(ctx, flags, outputFile, jarName)
803 }
804
Colin Cross6510f912017-11-29 00:27:14 -0800805 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -0800806 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
807 j.properties.Instrument = true
808 }
809 }
810
Colin Cross6510f912017-11-29 00:27:14 -0800811 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") && j.properties.Instrument {
Colin Crosscb933592017-11-22 13:49:43 -0800812 outputFile = j.instrument(ctx, flags, outputFile, jarName)
813 }
814
815 if ctx.Device() && j.installable() {
Alan Leung9f319112017-11-30 15:50:39 -0800816 if fullD8 {
817 outputFile = j.compileDexFullD8(ctx, flags, outputFile, jarName)
818 } else {
819 outputFile = j.compileDex(ctx, flags, outputFile, jarName)
820 }
Colin Cross2fe66872015-03-30 17:20:39 -0700821 if ctx.Failed() {
822 return
823 }
Colin Cross2fe66872015-03-30 17:20:39 -0700824 }
Colin Crossb7a63242015-04-16 14:09:14 -0700825 ctx.CheckbuildFile(outputFile)
826 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700827}
828
Colin Cross8eadbf02017-10-24 17:46:00 -0700829func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Nan Zhanged19fc32017-10-19 13:06:22 -0700830 deps deps, flags javaBuilderFlags, jarName string) android.Path {
831
832 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -0700833 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700834 // Compile java sources into turbine.jar.
835 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
836 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
837 if ctx.Failed() {
838 return nil
839 }
840 jars = append(jars, turbineJar)
841 }
842
843 // Combine any static header libraries into classes-header.jar. If there is only
844 // one input jar this step will be skipped.
845 var headerJar android.Path
846 jars = append(jars, deps.staticHeaderJars...)
847
Colin Cross5c6ecc12017-10-23 18:12:27 -0700848 // we cannot skip the combine step for now if there is only one jar
849 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
850 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
851 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, false, []string{"META-INF"})
852 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -0700853
854 if j.properties.Jarjar_rules != nil {
855 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
856 // Transform classes.jar into classes-jarjar.jar
857 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
858 TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules)
859 headerJar = jarjarFile
860 if ctx.Failed() {
861 return nil
862 }
863 }
864
865 return headerJar
866}
867
Colin Crosscb933592017-11-22 13:49:43 -0800868func (j *Module) desugar(ctx android.ModuleContext, flags javaBuilderFlags,
869 classesJar android.Path, jarName string) android.Path {
870
871 desugarFlags := []string{
872 "--min_sdk_version " + j.minSdkVersionNumber(ctx),
873 "--desugar_try_with_resources_if_needed=false",
874 "--allow_empty_bootclasspath",
875 }
876
877 if inList("--core-library", j.deviceProperties.Dxflags) {
878 desugarFlags = append(desugarFlags, "--core_library")
879 }
880
881 flags.desugarFlags = strings.Join(desugarFlags, " ")
882
883 desugarJar := android.PathForModuleOut(ctx, "desugar", jarName)
884 TransformDesugar(ctx, desugarJar, classesJar, flags)
885
886 return desugarJar
887}
888
889func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
890 classesJar android.Path, jarName string) android.Path {
891
892 specs := j.jacocoStripSpecs(ctx)
893
894 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco", "jacoco-report-classes.jar")
895 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
896
897 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
898
899 j.jacocoReportClassesFile = jacocoReportClassesFile
900
901 return instrumentedJar
902}
903
Nan Zhanged19fc32017-10-19 13:06:22 -0700904func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
905 classesJar android.Path, jarName string) android.Path {
906
907 dxFlags := j.deviceProperties.Dxflags
Nan Zhanged19fc32017-10-19 13:06:22 -0700908
Colin Cross6510f912017-11-29 00:27:14 -0800909 if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" {
Nan Zhanged19fc32017-10-19 13:06:22 -0700910 dxFlags = append(dxFlags, "--no-optimize")
911 }
912
Colin Cross6510f912017-11-29 00:27:14 -0800913 if ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" {
Nan Zhanged19fc32017-10-19 13:06:22 -0700914 dxFlags = append(dxFlags,
915 "--debug",
916 "--verbose",
917 "--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(),
918 "--dump-width=1000")
919 }
920
Colin Crosscb933592017-11-22 13:49:43 -0800921 dxFlags = append(dxFlags, "--min-sdk-version="+j.minSdkVersionNumber(ctx))
Nan Zhanged19fc32017-10-19 13:06:22 -0700922
923 flags.dxFlags = strings.Join(dxFlags, " ")
924
Nan Zhanged19fc32017-10-19 13:06:22 -0700925 // Compile classes.jar into classes.dex and then javalib.jar
926 javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
Colin Crosscb933592017-11-22 13:49:43 -0800927 TransformClassesJarToDexJar(ctx, javalibJar, classesJar, flags)
Nan Zhanged19fc32017-10-19 13:06:22 -0700928
929 j.dexJarFile = javalibJar
930 return javalibJar
931}
932
Alan Leung9f319112017-11-30 15:50:39 -0800933func (j *Module) compileDexFullD8(ctx android.ModuleContext, flags javaBuilderFlags,
934 classesJar android.Path, jarName string) android.Path {
935
936 // Translate all the DX flags to D8 ones until all the build files have been migrated
937 // to D8 flags. See: b/69377755
938 var dxFlags []string
939 for _, x := range j.deviceProperties.Dxflags {
940 if x == "--core-library" {
941 continue
942 }
943 if x == "--dex" {
944 continue
945 }
946 if x == "--multi-dex" {
947 continue
948 }
949 if x == "--no-locals" {
950 dxFlags = append(dxFlags, "--release")
951 continue
952 }
953 dxFlags = append(dxFlags, x)
954 }
955
956 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
957 dxFlags = append(dxFlags, "--debug")
958 }
959
960 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
961 dxFlags = append(dxFlags,
962 "--debug",
963 "--verbose")
964 }
965
966 dxFlags = append(dxFlags, "--min-api "+j.minSdkVersionNumber(ctx))
967
968 flags.dxFlags = strings.Join(dxFlags, " ")
969
970 // Compile classes.jar into classes.dex and then javalib.jar
971 javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
972 TransformClassesJarToDexJar(ctx, javalibJar, classesJar, flags)
973
974 j.dexJarFile = javalibJar
975 return javalibJar
976}
977
Colin Crosscb933592017-11-22 13:49:43 -0800978// Returns a sdk version as a string that is guaranteed to be a parseable as a number. For
979// modules targeting an unreleased SDK (meaning it does not yet have a number) it returns "10000".
980func (j *Module) minSdkVersionNumber(ctx android.ModuleContext) string {
981 switch String(j.deviceProperties.Sdk_version) {
982 case "", "current", "test_current", "system_current":
Colin Cross6510f912017-11-29 00:27:14 -0800983 return strconv.Itoa(ctx.Config().DefaultAppTargetSdkInt())
Colin Crosscb933592017-11-22 13:49:43 -0800984 default:
Sundong Ahn0926fae2017-10-17 16:34:51 +0900985 return android.GetNumericSdkVersion(String(j.deviceProperties.Sdk_version))
Colin Crosscb933592017-11-22 13:49:43 -0800986 }
987}
988
Colin Cross59f1bb62017-09-27 17:59:10 -0700989func (j *Module) installable() bool {
990 return j.properties.Installable == nil || *j.properties.Installable
991}
992
Colin Crossf506d872017-07-19 15:53:04 -0700993var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700994
Nan Zhanged19fc32017-10-19 13:06:22 -0700995func (j *Module) HeaderJars() android.Paths {
996 return android.Paths{j.headerJarFile}
997}
998
999func (j *Module) ImplementationJars() android.Paths {
1000 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001001}
1002
Colin Cross46c9b8b2017-06-22 16:51:17 -07001003func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001004 return j.exportAidlIncludeDirs
1005}
1006
Colin Cross46c9b8b2017-06-22 16:51:17 -07001007var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001008
Colin Cross46c9b8b2017-06-22 16:51:17 -07001009func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001010 return j.logtagsSrcs
1011}
1012
Colin Cross2fe66872015-03-30 17:20:39 -07001013//
1014// Java libraries (.jar file)
1015//
1016
Colin Crossf506d872017-07-19 15:53:04 -07001017type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001018 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001019}
1020
Colin Crossf506d872017-07-19 15:53:04 -07001021func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001022 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001023
Colin Cross59f1bb62017-09-27 17:59:10 -07001024 if j.installable() {
Colin Cross2c429dc2017-08-31 16:45:16 -07001025 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1026 ctx.ModuleName()+".jar", j.outputFile)
1027 }
Colin Crossb7a63242015-04-16 14:09:14 -07001028}
1029
Colin Crossf506d872017-07-19 15:53:04 -07001030func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001031 j.deps(ctx)
1032}
1033
Colin Crossa60ead82017-10-02 18:10:21 -07001034func LibraryFactory(installable bool) func() android.Module {
1035 return func() android.Module {
1036 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001037
Colin Crossa60ead82017-10-02 18:10:21 -07001038 if !installable {
1039 module.properties.Installable = proptools.BoolPtr(false)
1040 }
Colin Cross2fe66872015-03-30 17:20:39 -07001041
Colin Crossa60ead82017-10-02 18:10:21 -07001042 module.AddProperties(
1043 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001044 &module.Module.deviceProperties,
1045 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001046
Colin Crossa60ead82017-10-02 18:10:21 -07001047 InitJavaModule(module, android.HostAndDeviceSupported)
1048 return module
1049 }
Colin Cross2fe66872015-03-30 17:20:39 -07001050}
1051
Colin Crossf506d872017-07-19 15:53:04 -07001052func LibraryHostFactory() android.Module {
1053 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001054
Colin Cross6af17aa2017-09-20 12:59:05 -07001055 module.AddProperties(
1056 &module.Module.properties,
1057 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001058
Colin Cross89536d42017-07-07 14:35:50 -07001059 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001060 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001061}
1062
1063//
1064// Java Binaries (.jar file plus wrapper script)
1065//
1066
Colin Crossf506d872017-07-19 15:53:04 -07001067type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001068 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001069 Wrapper *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001070}
1071
Colin Crossf506d872017-07-19 15:53:04 -07001072type Binary struct {
1073 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001074
Colin Crossf506d872017-07-19 15:53:04 -07001075 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001076
Colin Cross6b4a32d2017-12-05 13:42:45 -08001077 isWrapperVariant bool
1078
Colin Crossc3315992017-12-08 19:12:36 -08001079 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001080 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001081}
1082
Alex Light24237172017-10-26 09:46:21 -07001083func (j *Binary) HostToolPath() android.OptionalPath {
1084 return android.OptionalPathForPath(j.binaryFile)
1085}
1086
Colin Crossf506d872017-07-19 15:53:04 -07001087func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001088 if ctx.Arch().ArchType == android.Common {
1089 // Compile the jar
1090 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001091 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001092 // Handle the binary wrapper
1093 j.isWrapperVariant = true
1094
Colin Cross366938f2017-12-11 16:29:02 -08001095 if j.binaryProperties.Wrapper != nil {
1096 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001097 } else {
1098 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1099 }
1100
1101 // Depend on the installed jar so that the wrapper doesn't get executed by
1102 // another build rule before the jar has been installed.
1103 jarFile := ctx.PrimaryModule().(*Binary).installFile
1104
1105 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1106 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001107 }
Colin Cross2fe66872015-03-30 17:20:39 -07001108}
1109
Colin Crossf506d872017-07-19 15:53:04 -07001110func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001111 if ctx.Arch().ArchType == android.Common {
1112 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001113 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001114 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001115 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001116}
1117
Colin Crossf506d872017-07-19 15:53:04 -07001118func BinaryFactory() android.Module {
1119 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001120
Colin Cross36242852017-06-23 15:06:31 -07001121 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001122 &module.Module.properties,
1123 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001124 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001125 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001126
Colin Cross6b4a32d2017-12-05 13:42:45 -08001127 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1128 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001129 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001130}
1131
Colin Crossf506d872017-07-19 15:53:04 -07001132func BinaryHostFactory() android.Module {
1133 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001134
Colin Cross36242852017-06-23 15:06:31 -07001135 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001136 &module.Module.properties,
1137 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001138 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001139 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001140
Colin Cross6b4a32d2017-12-05 13:42:45 -08001141 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1142 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001143 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001144}
1145
1146//
1147// Java prebuilts
1148//
1149
Colin Cross74d73e22017-08-02 11:05:49 -07001150type ImportProperties struct {
1151 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001152
Nan Zhangea568a42017-11-08 21:20:04 -08001153 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001154
1155 Installable *bool
Colin Cross74d73e22017-08-02 11:05:49 -07001156}
1157
1158type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001159 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001160 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001161
Colin Cross74d73e22017-08-02 11:05:49 -07001162 properties ImportProperties
1163
Colin Cross0a6e0072017-08-30 14:24:55 -07001164 classpathFiles android.Paths
1165 combinedClasspathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -07001166}
1167
Colin Cross74d73e22017-08-02 11:05:49 -07001168func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001169 return &j.prebuilt
1170}
1171
Colin Cross74d73e22017-08-02 11:05:49 -07001172func (j *Import) PrebuiltSrcs() []string {
1173 return j.properties.Jars
1174}
1175
1176func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001177 return j.prebuilt.Name(j.ModuleBase.Name())
1178}
1179
Colin Cross74d73e22017-08-02 11:05:49 -07001180func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross1e676be2016-10-12 14:38:15 -07001181}
1182
Colin Cross74d73e22017-08-02 11:05:49 -07001183func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1184 j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07001185
Colin Crosse9a275b2017-10-16 17:09:48 -07001186 outputFile := android.PathForModuleOut(ctx, "classes.jar")
Nan Zhanged19fc32017-10-19 13:06:22 -07001187 TransformJarsToJar(ctx, outputFile, "for prebuilts", j.classpathFiles, android.OptionalPath{}, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001188 j.combinedClasspathFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -07001189}
1190
Colin Cross74d73e22017-08-02 11:05:49 -07001191var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001192
Nan Zhanged19fc32017-10-19 13:06:22 -07001193func (j *Import) HeaderJars() android.Paths {
1194 return j.classpathFiles
1195}
1196
1197func (j *Import) ImplementationJars() android.Paths {
Colin Cross74d73e22017-08-02 11:05:49 -07001198 return j.classpathFiles
Colin Cross2fe66872015-03-30 17:20:39 -07001199}
1200
Colin Cross74d73e22017-08-02 11:05:49 -07001201func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001202 return nil
1203}
1204
Colin Cross74d73e22017-08-02 11:05:49 -07001205var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001206
Colin Cross74d73e22017-08-02 11:05:49 -07001207func ImportFactory() android.Module {
1208 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001209
Colin Cross74d73e22017-08-02 11:05:49 -07001210 module.AddProperties(&module.properties)
1211
1212 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -07001213 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1214 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001215}
1216
Colin Cross74d73e22017-08-02 11:05:49 -07001217func ImportFactoryHost() android.Module {
1218 module := &Import{}
1219
1220 module.AddProperties(&module.properties)
1221
1222 android.InitPrebuiltModule(module, &module.properties.Jars)
1223 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
1224 return module
1225}
1226
Colin Cross2fe66872015-03-30 17:20:39 -07001227func inList(s string, l []string) bool {
1228 for _, e := range l {
1229 if e == s {
1230 return true
1231 }
1232 }
1233 return false
1234}
Colin Cross89536d42017-07-07 14:35:50 -07001235
1236//
1237// Defaults
1238//
1239type Defaults struct {
1240 android.ModuleBase
1241 android.DefaultsModuleBase
1242}
1243
1244func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1245}
1246
1247func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1248}
1249
1250func defaultsFactory() android.Module {
1251 return DefaultsFactory()
1252}
1253
1254func DefaultsFactory(props ...interface{}) android.Module {
1255 module := &Defaults{}
1256
1257 module.AddProperties(props...)
1258 module.AddProperties(
1259 &CompilerProperties{},
1260 &CompilerDeviceProperties{},
1261 )
1262
1263 android.InitDefaultsModule(module)
1264
1265 return module
1266}
Nan Zhangea568a42017-11-08 21:20:04 -08001267
1268var Bool = proptools.Bool
1269var String = proptools.String