blob: 65e3b4151c6834b4a168fc46f075e3036c68b8b5 [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
Colin Cross0f2ee152017-12-14 15:22:43 -0800145 Proto struct {
146 // List of extra options that will be passed to the proto generator.
147 Output_params []string
148 }
149
Colin Crosscb933592017-11-22 13:49:43 -0800150 Instrument bool `blueprint:"mutated"`
Colin Cross540eff82017-06-22 17:01:52 -0700151}
152
Colin Cross89536d42017-07-07 14:35:50 -0700153type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700154 // list of module-specific flags that will be used for dex compiles
155 Dxflags []string `android:"arch_variant"`
156
Colin Cross7d5136f2015-05-11 13:39:40 -0700157 // if not blank, set to the version of the sdk to compile against
Nan Zhangea568a42017-11-08 21:20:04 -0800158 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700159
Colin Crossebe1a512017-11-14 13:12:14 -0800160 Aidl struct {
161 // Top level directories to pass to aidl tool
162 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700163
Colin Crossebe1a512017-11-14 13:12:14 -0800164 // Directories rooted at the Android.bp file to pass to aidl tool
165 Local_include_dirs []string
166
167 // directories that should be added as include directories for any aidl sources of modules
168 // that depend on this module, as well as to aidl for this module.
169 Export_include_dirs []string
170 }
Colin Cross92430102017-10-09 14:59:32 -0700171
172 // If true, export a copy of the module as a -hostdex module for host testing.
173 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700174
Colin Cross1bd87802017-12-05 15:31:19 -0800175 Dex_preopt struct {
176 // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to
177 // true.
178 Enabled *bool
179
180 // If true, generate an app image (.art file) for this module.
181 App_image *bool
182
183 // If true, use a checked-in profile to guide optimization. Defaults to false unless
184 // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR
185 // that matches the name of this module, in which case it is defaulted to true.
186 Profile_guided *bool
187
188 // If set, provides the path to profile relative to the Android.bp file. If not set,
189 // defaults to searching for a file that matches the name of this module in the default
190 // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found.
191 Profile *string
192 }
Colin Crossa22116e2017-10-19 14:18:58 -0700193
Colin Cross66dbc0b2017-12-28 12:23:20 -0800194 Optimize struct {
195 // If false, disable all optimization. Defaults to true for apps, false for
196 // libraries and tests.
197 Enabled *bool
198
199 // If true, optimize for size by removing unused code. Defaults to true for apps,
200 // false for libraries and tests.
201 Shrink *bool
202
203 // If true, optimize bytecode. Defaults to false.
204 Optimize *bool
205
206 // If true, obfuscate bytecode. Defaults to false.
207 Obfuscate *bool
208
209 // If true, do not use the flag files generated by aapt that automatically keep
210 // classes referenced by the app manifest. Defaults to false.
211 No_aapt_flags *bool
212
213 // Flags to pass to proguard.
214 Proguard_flags []string
215
216 // Specifies the locations of files containing proguard flags.
217 Proguard_flags_files []string
218 }
219
Colin Cross1369cdb2017-09-29 17:58:17 -0700220 // When targeting 1.9, override the modules to use with --system
221 System_modules *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700222}
223
Colin Cross46c9b8b2017-06-22 16:51:17 -0700224// Module contains the properties and members used by all java module types
225type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700226 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700227 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700228
Colin Cross89536d42017-07-07 14:35:50 -0700229 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700230 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700231 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700232
Nan Zhanged19fc32017-10-19 13:06:22 -0700233 // header jar file suitable for inserting into the bootclasspath/classpath of another compile
234 headerJarFile android.Path
235
236 // full implementation jar file suitable for static dependency of another module compile
237 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700238
Colin Cross6ade34f2017-09-15 13:00:47 -0700239 // output file containing classes.dex
240 dexJarFile android.Path
241
Colin Crosscb933592017-11-22 13:49:43 -0800242 // output file containing uninstrumented classes that will be instrumented by jacoco
243 jacocoReportClassesFile android.Path
244
Colin Cross66dbc0b2017-12-28 12:23:20 -0800245 // output file containing mapping of obfuscated names
246 proguardDictionary android.Path
247
Colin Crossb7a63242015-04-16 14:09:14 -0700248 // output file suitable for installing or running
Colin Cross635c3b02016-05-18 15:37:25 -0700249 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700250
Colin Cross635c3b02016-05-18 15:37:25 -0700251 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700252
Colin Cross635c3b02016-05-18 15:37:25 -0700253 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700254
Colin Cross2fe66872015-03-30 17:20:39 -0700255 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700256 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800257
258 // list of .java files and srcjars that was passed to javac
259 compiledJavaSrcs android.Paths
260 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800261
262 // list of extra progurad flag files
263 extraProguardFlagFiles android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700264}
265
Colin Cross54250902017-12-05 09:28:08 -0800266func (j *Module) Srcs() android.Paths {
267 return android.Paths{j.implementationJarFile}
268}
269
270var _ android.SourceFileProducer = (*Module)(nil)
271
Colin Crossf506d872017-07-19 15:53:04 -0700272type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700273 HeaderJars() android.Paths
274 ImplementationJars() android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700275 AidlIncludeDirs() android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700276}
277
Colin Cross89536d42017-07-07 14:35:50 -0700278func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
279 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
280 android.InitDefaultableModule(module)
281}
282
Colin Crossbe1da472017-07-07 15:59:46 -0700283type dependencyTag struct {
284 blueprint.BaseDependencyTag
285 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700286}
287
Colin Crossbe1da472017-07-07 15:59:46 -0700288var (
Colin Cross6ade34f2017-09-15 13:00:47 -0700289 staticLibTag = dependencyTag{name: "staticlib"}
290 libTag = dependencyTag{name: "javalib"}
291 bootClasspathTag = dependencyTag{name: "bootclasspath"}
Colin Cross1369cdb2017-09-29 17:58:17 -0700292 systemModulesTag = dependencyTag{name: "system modules"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700293 frameworkResTag = dependencyTag{name: "framework-res"}
Colin Cross93e85952017-08-15 13:34:18 -0700294 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Cross66dbc0b2017-12-28 12:23:20 -0800295 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
Colin Crossbe1da472017-07-07 15:59:46 -0700296)
Colin Cross2fe66872015-03-30 17:20:39 -0700297
Colin Crossfc3674a2017-09-18 17:41:52 -0700298type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700299 useModule, useFiles, useDefaultLibs, invalidVersion bool
300
Colin Cross1369cdb2017-09-29 17:58:17 -0700301 module string
302 systemModules string
303
304 jar android.Path
305 aidl android.Path
306}
307
308func sdkStringToNumber(ctx android.BaseContext, v string) int {
309 switch v {
310 case "", "current", "system_current", "test_current":
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900311 return android.FutureApiLevel
Colin Cross1369cdb2017-09-29 17:58:17 -0700312 default:
Sundong Ahn0926fae2017-10-17 16:34:51 +0900313 if i, err := strconv.Atoi(android.GetNumericSdkVersion(v)); err != nil {
Colin Cross1369cdb2017-09-29 17:58:17 -0700314 ctx.PropertyErrorf("sdk_version", "invalid sdk version")
315 return -1
316 } else {
317 return i
318 }
319 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700320}
321
Colin Cross3144dfc2018-01-03 15:06:47 -0800322func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
323 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
324}
325
326func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
327 return j.shouldInstrument(ctx) &&
328 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
329 ctx.Config().UnbundledBuild())
330}
331
Colin Crossfc3674a2017-09-18 17:41:52 -0700332func decodeSdkDep(ctx android.BaseContext, v string) sdkDep {
Colin Cross1369cdb2017-09-29 17:58:17 -0700333 i := sdkStringToNumber(ctx, v)
334 if i == -1 {
335 // Invalid sdk version, error handled by sdkStringToNumber.
336 return sdkDep{}
Colin Crossfc3674a2017-09-18 17:41:52 -0700337 }
338
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900339 // Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks)
340 // or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set)
341 if strings.HasPrefix(v, "system_") && i != android.FutureApiLevel {
342 allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions()
343 if ctx.DeviceSpecific() || ctx.SocSpecific() {
344 if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 {
345 allowed_versions = ctx.DeviceConfig().SystemSdkVersions()
346 }
347 }
348 version := strings.TrimPrefix(v, "system_")
349 if len(allowed_versions) > 0 && !android.InList(version, allowed_versions) {
350 ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q",
351 v, allowed_versions)
352 }
353 }
354
Colin Crossfc3674a2017-09-18 17:41:52 -0700355 toFile := func(v string) sdkDep {
356 dir := filepath.Join("prebuilts/sdk", v)
357 jar := filepath.Join(dir, "android.jar")
358 aidl := filepath.Join(dir, "framework.aidl")
359 jarPath := android.ExistentPathForSource(ctx, "sdkdir", jar)
360 aidlPath := android.ExistentPathForSource(ctx, "sdkdir", aidl)
Colin Cross47ff2522017-10-02 14:22:08 -0700361
Colin Cross6510f912017-11-29 00:27:14 -0800362 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
Sundong Ahn0926fae2017-10-17 16:34:51 +0900363 if strings.Contains(v, "system_") {
364 return sdkDep{
365 invalidVersion: true,
Sundong Ahnb5b5b262018-01-15 15:07:40 +0900366 module: "system_sdk_v" + strings.Replace(v, "system_", "", 1),
Sundong Ahn0926fae2017-10-17 16:34:51 +0900367 }
368 }
Colin Cross47ff2522017-10-02 14:22:08 -0700369 return sdkDep{
370 invalidVersion: true,
371 module: "sdk_v" + v,
372 }
373 }
374
Colin Crossfc3674a2017-09-18 17:41:52 -0700375 if !jarPath.Valid() {
376 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar)
377 return sdkDep{}
378 }
Colin Cross47ff2522017-10-02 14:22:08 -0700379
Colin Crossfc3674a2017-09-18 17:41:52 -0700380 if !aidlPath.Valid() {
381 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl)
382 return sdkDep{}
383 }
Colin Cross47ff2522017-10-02 14:22:08 -0700384
Colin Crossfc3674a2017-09-18 17:41:52 -0700385 return sdkDep{
386 useFiles: true,
387 jar: jarPath.Path(),
388 aidl: aidlPath.Path(),
389 }
390 }
391
Colin Cross2ebc4762017-10-20 14:00:31 -0700392 //toModule := func(m string) sdkDep {
393 // return sdkDep{
394 // useModule: true,
395 // module: m,
396 // systemModules: m + "_system_modules",
397 // }
398 //}
Colin Crossfc3674a2017-09-18 17:41:52 -0700399
Colin Cross6510f912017-11-29 00:27:14 -0800400 if ctx.Config().UnbundledBuild() && v != "" {
Colin Crossfc3674a2017-09-18 17:41:52 -0700401 return toFile(v)
402 }
403
404 switch v {
405 case "":
406 return sdkDep{
407 useDefaultLibs: true,
408 }
Colin Cross2ebc4762017-10-20 14:00:31 -0700409 // TODO(ccross): re-enable these once we generate stubs, until then
410 // use the stubs in prebuilts/sdk/*current
411 //case "current":
412 // return toModule("android_stubs_current")
413 //case "system_current":
414 // return toModule("android_system_stubs_current")
415 //case "test_current":
416 // return toModule("android_test_stubs_current")
Colin Crossfc3674a2017-09-18 17:41:52 -0700417 default:
418 return toFile(v)
419 }
420}
421
Colin Crossbe1da472017-07-07 15:59:46 -0700422func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700423 if ctx.Device() {
424 if !proptools.Bool(j.properties.No_standard_libs) {
Nan Zhangea568a42017-11-08 21:20:04 -0800425 sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
Colin Crossfc3674a2017-09-18 17:41:52 -0700426 if sdkDep.useDefaultLibs {
Colin Crosscb2c9292017-09-23 19:57:16 -0700427 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Colin Cross6510f912017-11-29 00:27:14 -0800428 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700429 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
430 }
Colin Crossfa5eb232017-10-01 20:33:03 -0700431 if !proptools.Bool(j.properties.No_framework_libs) {
432 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
433 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700434 } else if sdkDep.useModule {
Colin Cross6510f912017-11-29 00:27:14 -0800435 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700436 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
437 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700438 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800439 if Bool(j.deviceProperties.Optimize.Enabled) {
440 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultBootclasspathLibraries...)
441 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultLibraries...)
442 }
Colin Crossbe1da472017-07-07 15:59:46 -0700443 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700444 } else if j.deviceProperties.System_modules == nil {
445 ctx.PropertyErrorf("no_standard_libs",
446 "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 -0800447 } else if *j.deviceProperties.System_modules != "none" && ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700448 ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700449 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800450 if ctx.ModuleName() == "framework" {
451 ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res")
452 }
Colin Cross2fe66872015-03-30 17:20:39 -0700453 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700454
Colin Crossf506d872017-07-19 15:53:04 -0700455 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
456 ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
Colin Cross6ade34f2017-09-15 13:00:47 -0700457 ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...)
Colin Cross7f9036c2017-08-30 13:27:57 -0700458
459 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700460 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross366938f2017-12-11 16:29:02 -0800461 android.ExtractSourceDeps(ctx, j.properties.Manifest)
Colin Cross6af17aa2017-09-20 12:59:05 -0700462
463 if j.hasSrcExt(".proto") {
464 protoDeps(ctx, &j.protoProperties)
465 }
Colin Cross93e85952017-08-15 13:34:18 -0700466
467 if j.hasSrcExt(".kt") {
468 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
469 // Kotlin files
470 ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib")
471 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800472
473 if j.shouldInstrumentStatic(ctx) {
474 ctx.AddDependency(ctx.Module(), staticLibTag, "jacocoagent")
475 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700476}
477
478func hasSrcExt(srcs []string, ext string) bool {
479 for _, src := range srcs {
480 if filepath.Ext(src) == ext {
481 return true
482 }
483 }
484
485 return false
486}
487
Nan Zhang61eaedb2017-11-02 13:28:15 -0700488func shardPaths(paths android.Paths, shardSize int) []android.Paths {
489 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
490 for len(paths) > shardSize {
491 ret = append(ret, paths[0:shardSize])
492 paths = paths[shardSize:]
493 }
494 if len(paths) > 0 {
495 ret = append(ret, paths)
496 }
497 return ret
498}
499
Colin Cross6af17aa2017-09-20 12:59:05 -0700500func (j *Module) hasSrcExt(ext string) bool {
501 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700502}
503
Colin Cross46c9b8b2017-06-22 16:51:17 -0700504func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700505 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700506
Colin Crossebe1a512017-11-14 13:12:14 -0800507 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
508 aidlIncludes = append(aidlIncludes,
509 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
510 aidlIncludes = append(aidlIncludes,
511 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700512
513 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700514 if aidlPreprocess.Valid() {
515 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700516 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700517 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700518 }
519
Colin Cross635c3b02016-05-18 15:37:25 -0700520 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800521 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700522 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Crosse243c232017-10-21 15:16:37 -0700523 if src := android.ExistentPathForSource(ctx, "", ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700524 flags = append(flags, "-I"+src.String())
525 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700526
Colin Crossf03c82b2015-04-13 13:53:40 -0700527 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700528}
529
Colin Cross32f676a2017-09-06 13:41:06 -0700530type deps struct {
Colin Cross6ade34f2017-09-15 13:00:47 -0700531 classpath android.Paths
532 bootClasspath android.Paths
533 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700534 staticHeaderJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700535 staticJarResources android.Paths
536 aidlIncludeDirs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700537 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700538 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700539 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700540 kotlinStdlib android.Paths
Colin Cross32f676a2017-09-06 13:41:06 -0700541}
Colin Cross2fe66872015-03-30 17:20:39 -0700542
Colin Cross54250902017-12-05 09:28:08 -0800543func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
544 for _, f := range dep.Srcs() {
545 if f.Ext() != ".jar" {
546 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
547 ctx.OtherModuleName(dep.(blueprint.Module)))
548 }
549 }
550}
551
Colin Cross32f676a2017-09-06 13:41:06 -0700552func (j *Module) collectDeps(ctx android.ModuleContext) deps {
553 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700554
Nan Zhangea568a42017-11-08 21:20:04 -0800555 sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
Colin Cross47ff2522017-10-02 14:22:08 -0700556 if sdkDep.invalidVersion {
557 ctx.AddMissingDependencies([]string{sdkDep.module})
558 } else if sdkDep.useFiles {
Nan Zhanged19fc32017-10-19 13:06:22 -0700559 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Crossfc3674a2017-09-18 17:41:52 -0700560 deps.classpath = append(deps.classpath, sdkDep.jar)
561 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
562 }
563
Colin Crossd11fcda2017-10-23 17:59:01 -0700564 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700565 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700566 tag := ctx.OtherModuleDependencyTag(module)
567
Colin Cross54250902017-12-05 09:28:08 -0800568 switch dep := module.(type) {
569 case Dependency:
570 switch tag {
571 case bootClasspathTag:
572 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
573 case libTag:
574 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
575 case staticLibTag:
576 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
577 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
578 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
579 case frameworkResTag:
580 if ctx.ModuleName() == "framework" {
581 // framework.jar has a one-off dependency on the R.java and Manifest.java files
582 // generated by framework-res.apk
583 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
584 }
585 case kotlinStdlibTag:
586 deps.kotlinStdlib = dep.HeaderJars()
587 default:
588 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
589 }
590
591 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
592 case android.SourceFileProducer:
593 switch tag {
594 case libTag:
595 checkProducesJars(ctx, dep)
596 deps.classpath = append(deps.classpath, dep.Srcs()...)
597 case staticLibTag:
598 checkProducesJars(ctx, dep)
599 deps.classpath = append(deps.classpath, dep.Srcs()...)
600 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
601 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
602 case android.DefaultsDepTag, android.SourceDepTag:
603 // Nothing to do
604 default:
605 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
606 }
607 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700608 switch tag {
609 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700610 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700611 case systemModulesTag:
612 if deps.systemModules != nil {
613 panic("Found two system module dependencies")
614 }
615 sm := module.(*SystemModules)
616 if sm.outputFile == nil {
617 panic("Missing directory for system module dependency")
618 }
619 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700620 default:
621 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700622 }
Colin Crossec7a0422017-07-07 14:47:12 -0700623 }
Colin Cross2fe66872015-03-30 17:20:39 -0700624 })
625
Colin Cross32f676a2017-09-06 13:41:06 -0700626 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700627}
628
Nan Zhanged19fc32017-10-19 13:06:22 -0700629func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700630
Colin Crossf03c82b2015-04-13 13:53:40 -0700631 var flags javaBuilderFlags
632
Nan Zhanged19fc32017-10-19 13:06:22 -0700633 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700634 javacFlags := j.properties.Javacflags
Colin Cross6510f912017-11-29 00:27:14 -0800635 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700636 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700637 }
Colin Cross6510f912017-11-29 00:27:14 -0800638 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700639 // Override the -g flag passed globally to remove local variable debug info to reduce
640 // disk and memory usage.
641 javacFlags = append(javacFlags, "-g:source,lines")
642 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700643 if len(javacFlags) > 0 {
644 // optimization.
645 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
646 flags.javacFlags = "$javacFlags"
Colin Cross4f26bc02017-09-06 12:52:16 -0700647 }
Colin Cross64162712017-08-08 13:17:59 -0700648
Nan Zhanged19fc32017-10-19 13:06:22 -0700649 // javaVersion flag.
Nan Zhangea568a42017-11-08 21:20:04 -0800650 sdk := sdkStringToNumber(ctx, String(j.deviceProperties.Sdk_version))
Colin Cross64162712017-08-08 13:17:59 -0700651 if j.properties.Java_version != nil {
652 flags.javaVersion = *j.properties.Java_version
Colin Cross1369cdb2017-09-29 17:58:17 -0700653 } else if ctx.Device() && sdk <= 23 {
654 flags.javaVersion = "1.7"
Colin Cross6510f912017-11-29 00:27:14 -0800655 } else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700656 flags.javaVersion = "1.8"
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900657 } else if ctx.Device() && String(j.deviceProperties.Sdk_version) != "" && sdk == android.FutureApiLevel {
Colin Cross2ebc4762017-10-20 14:00:31 -0700658 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
659 flags.javaVersion = "1.8"
Colin Cross64162712017-08-08 13:17:59 -0700660 } else {
Colin Cross1369cdb2017-09-29 17:58:17 -0700661 flags.javaVersion = "1.9"
Colin Cross64162712017-08-08 13:17:59 -0700662 }
663
Nan Zhanged19fc32017-10-19 13:06:22 -0700664 // classpath
Colin Cross6ade34f2017-09-15 13:00:47 -0700665 flags.bootClasspath.AddPaths(deps.bootClasspath)
666 flags.classpath.AddPaths(deps.classpath)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800667
668 if len(flags.bootClasspath) == 0 && ctx.Host() && !ctx.Config().TargetOpenJDK9() &&
669 !Bool(j.properties.No_standard_libs) &&
670 inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
671 // Give host-side tools a version of OpenJDK's standard libraries
672 // close to what they're targeting. As of Dec 2017, AOSP is only
673 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
674 //
675 // When building with OpenJDK 8, the following should have no
676 // effect since those jars would be available by default.
677 //
678 // When building with OpenJDK 9 but targeting a version < 1.8,
679 // putting them on the bootclasspath means that:
680 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
681 // b) references to existing APIs are not reinterpreted in an
682 // OpenJDK 9-specific way, eg. calls to subclasses of
683 // java.nio.Buffer as in http://b/70862583
684 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
685 flags.bootClasspath = append(flags.bootClasspath,
686 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
687 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
688 }
689
Nan Zhanged19fc32017-10-19 13:06:22 -0700690 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700691 if deps.systemModules != nil {
692 flags.systemModules = append(flags.systemModules, deps.systemModules)
693 }
694
Nan Zhanged19fc32017-10-19 13:06:22 -0700695 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700696 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700697 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700698 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700699 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
700 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700701 }
702
Nan Zhanged19fc32017-10-19 13:06:22 -0700703 return flags
704}
Colin Crossc0b06f12015-04-08 13:03:43 -0700705
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800706func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700707
Colin Crossebe1a512017-11-14 13:12:14 -0800708 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700709
710 deps := j.collectDeps(ctx)
711 flags := j.collectBuilderFlags(ctx, deps)
712
Colin Cross6510f912017-11-29 00:27:14 -0800713 if ctx.Config().TargetOpenJDK9() {
Nan Zhanged19fc32017-10-19 13:06:22 -0700714 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
715 }
716 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700717 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -0800718 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700719 }
720
Colin Crossaf050172017-11-15 23:01:59 -0800721 srcFiles = j.genSources(ctx, srcFiles, flags)
722
723 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700724 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800725 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700726
Colin Cross0a6e0072017-08-30 14:24:55 -0700727 var jars android.Paths
728
Colin Cross1ee23172017-10-18 14:44:18 -0700729 jarName := ctx.ModuleName() + ".jar"
730
Colin Cross93e85952017-08-15 13:34:18 -0700731 if srcFiles.HasExt(".kt") {
732 // If there are kotlin files, compile them first but pass all the kotlin and java files
733 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
734 // won't emit any classes for them.
735
736 flags.kotlincFlags = "-no-stdlib"
737 if ctx.Device() {
738 flags.kotlincFlags += " -no-jdk"
739 }
740
741 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
742 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
743
Colin Cross1ee23172017-10-18 14:44:18 -0700744 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross93e85952017-08-15 13:34:18 -0700745 TransformKotlinToClasses(ctx, kotlinJar, srcFiles, srcJars, flags)
746 if ctx.Failed() {
747 return
748 }
749
750 // Make javac rule depend on the kotlinc rule
751 flags.classpath = append(flags.classpath, kotlinJar)
752 // Jar kotlin classes into the final jar after javac
753 jars = append(jars, kotlinJar)
754 jars = append(jars, deps.kotlinStdlib...)
755 }
756
Nan Zhanged19fc32017-10-19 13:06:22 -0700757 javaSrcFiles := srcFiles.FilterByExt(".java")
758 var uniqueSrcFiles android.Paths
759 set := make(map[string]bool)
760 for _, v := range javaSrcFiles {
761 if _, found := set[v.String()]; !found {
762 set[v.String()] = true
763 uniqueSrcFiles = append(uniqueSrcFiles, v)
764 }
765 }
766
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800767 // Store the list of .java files that was passed to javac
768 j.compiledJavaSrcs = uniqueSrcFiles
769 j.compiledSrcJars = srcJars
770
Nan Zhang61eaedb2017-11-02 13:28:15 -0700771 enable_sharding := false
Colin Cross6510f912017-11-29 00:27:14 -0800772 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") {
Nan Zhang61eaedb2017-11-02 13:28:15 -0700773 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
774 enable_sharding = true
775 if len(j.properties.Annotation_processors) != 0 ||
776 len(j.properties.Annotation_processor_classes) != 0 {
777 ctx.PropertyErrorf("javac_shard_size",
778 "%q cannot be set when annotation processors are enabled.",
779 j.properties.Javac_shard_size)
780 }
781 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700782 // If sdk jar is java module, then directly return classesJar as header.jar
783 if j.Name() != "android_stubs_current" && j.Name() != "android_system_stubs_current" &&
784 j.Name() != "android_test_stubs_current" {
785 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName)
786 if ctx.Failed() {
787 return
788 }
789 }
790 }
Colin Cross8eadbf02017-10-24 17:46:00 -0700791 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -0700792 var extraJarDeps android.Paths
Colin Cross6510f912017-11-29 00:27:14 -0800793 if ctx.Config().IsEnvTrue("RUN_ERROR_PRONE") {
Colin Crossc6bbef32017-08-14 14:16:06 -0700794 // If error-prone is enabled, add an additional rule to compile the java files into
795 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -0700796 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -0700797 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
798 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -0700799 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -0700800 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -0700801 extraJarDeps = append(extraJarDeps, errorprone)
802 }
803
Nan Zhang61eaedb2017-11-02 13:28:15 -0700804 if enable_sharding {
805 flags.classpath.AddPaths([]android.Path{j.headerJarFile})
806 shardSize := int(*(j.properties.Javac_shard_size))
807 var shardSrcs []android.Paths
808 if len(uniqueSrcFiles) > 0 {
809 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
810 for idx, shardSrc := range shardSrcs {
811 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
812 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
813 jars = append(jars, classes)
814 }
815 }
816 if len(srcJars) > 0 {
817 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
818 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
819 jars = append(jars, classes)
820 }
821 } else {
822 classes := android.PathForModuleOut(ctx, "javac", jarName)
823 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
824 jars = append(jars, classes)
825 }
Colin Crossd6891432017-09-27 17:39:56 -0700826 if ctx.Failed() {
827 return
828 }
Colin Cross2fe66872015-03-30 17:20:39 -0700829 }
830
Colin Cross0f37af02017-09-27 17:42:05 -0700831 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
832 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
833
834 var resArgs []string
835 var resDeps android.Paths
836
837 resArgs = append(resArgs, dirArgs...)
838 resDeps = append(resDeps, dirDeps...)
839
840 resArgs = append(resArgs, fileArgs...)
841 resDeps = append(resDeps, fileDeps...)
842
843 if proptools.Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -0700844 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700845 resArgs = append(resArgs, srcArgs...)
846 resDeps = append(resDeps, srcDeps...)
847 }
Colin Cross40a36712017-09-27 17:41:35 -0700848
849 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -0700850 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700851 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -0700852 if ctx.Failed() {
853 return
854 }
Colin Cross20978302015-04-10 17:05:07 -0700855
Colin Cross0a6e0072017-08-30 14:24:55 -0700856 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -0700857 }
858
Colin Cross6ade34f2017-09-15 13:00:47 -0700859 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -0700860 jars = append(jars, deps.staticJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -0700861
Colin Cross366938f2017-12-11 16:29:02 -0800862 var manifest android.OptionalPath
863 if j.properties.Manifest != nil {
864 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
865 }
Colin Cross635acc92017-09-12 22:50:46 -0700866
Colin Cross0a6e0072017-08-30 14:24:55 -0700867 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -0700868 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -0700869 var outputFile android.Path
870
871 if len(jars) == 1 && !manifest.Valid() {
872 // Optimization: skip the combine step if there is nothing to do
Colin Cross7b60cdd2017-12-21 13:52:58 -0800873 // TODO(ccross): this leaves any module-info.class files, but those should only come from
874 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
875 // any if len(jars) == 1.
Colin Crosse9a275b2017-10-16 17:09:48 -0700876 outputFile = jars[0]
877 } else {
Colin Cross1ee23172017-10-18 14:44:18 -0700878 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Nan Zhanged19fc32017-10-19 13:06:22 -0700879 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -0700880 outputFile = combinedJar
881 }
Colin Cross0a6e0072017-08-30 14:24:55 -0700882
883 if j.properties.Jarjar_rules != nil {
884 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -0700885 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -0700886 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700887 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
888 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -0700889 if ctx.Failed() {
890 return
891 }
892 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700893 j.implementationJarFile = outputFile
894 if j.headerJarFile == nil {
895 j.headerJarFile = j.implementationJarFile
896 }
Colin Cross2fe66872015-03-30 17:20:39 -0700897
Colin Cross6510f912017-11-29 00:27:14 -0800898 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -0800899 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
900 j.properties.Instrument = true
901 }
902 }
903
Colin Cross3144dfc2018-01-03 15:06:47 -0800904 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -0800905 outputFile = j.instrument(ctx, flags, outputFile, jarName)
906 }
907
908 if ctx.Device() && j.installable() {
Colin Crossf0056cb2017-12-22 15:56:08 -0800909 outputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -0700910 if ctx.Failed() {
911 return
912 }
Colin Cross2fe66872015-03-30 17:20:39 -0700913 }
Colin Crossb7a63242015-04-16 14:09:14 -0700914 ctx.CheckbuildFile(outputFile)
915 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700916}
917
Colin Cross8eadbf02017-10-24 17:46:00 -0700918func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Nan Zhanged19fc32017-10-19 13:06:22 -0700919 deps deps, flags javaBuilderFlags, jarName string) android.Path {
920
921 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -0700922 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700923 // Compile java sources into turbine.jar.
924 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
925 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
926 if ctx.Failed() {
927 return nil
928 }
929 jars = append(jars, turbineJar)
930 }
931
932 // Combine any static header libraries into classes-header.jar. If there is only
933 // one input jar this step will be skipped.
934 var headerJar android.Path
935 jars = append(jars, deps.staticHeaderJars...)
936
Colin Cross5c6ecc12017-10-23 18:12:27 -0700937 // we cannot skip the combine step for now if there is only one jar
938 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
939 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
940 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, false, []string{"META-INF"})
941 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -0700942
943 if j.properties.Jarjar_rules != nil {
944 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
945 // Transform classes.jar into classes-jarjar.jar
946 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
947 TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules)
948 headerJar = jarjarFile
949 if ctx.Failed() {
950 return nil
951 }
952 }
953
954 return headerJar
955}
956
Colin Crosscb933592017-11-22 13:49:43 -0800957func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
958 classesJar android.Path, jarName string) android.Path {
959
Colin Cross7a3139e2017-12-19 13:57:50 -0800960 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -0800961
Colin Cross84c38822018-01-03 15:59:46 -0800962 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -0800963 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
964
965 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
966
967 j.jacocoReportClassesFile = jacocoReportClassesFile
968
969 return instrumentedJar
970}
971
Colin Crosscb933592017-11-22 13:49:43 -0800972// Returns a sdk version as a string that is guaranteed to be a parseable as a number. For
973// modules targeting an unreleased SDK (meaning it does not yet have a number) it returns "10000".
974func (j *Module) minSdkVersionNumber(ctx android.ModuleContext) string {
975 switch String(j.deviceProperties.Sdk_version) {
976 case "", "current", "test_current", "system_current":
Colin Cross6510f912017-11-29 00:27:14 -0800977 return strconv.Itoa(ctx.Config().DefaultAppTargetSdkInt())
Colin Crosscb933592017-11-22 13:49:43 -0800978 default:
Sundong Ahn0926fae2017-10-17 16:34:51 +0900979 return android.GetNumericSdkVersion(String(j.deviceProperties.Sdk_version))
Colin Crosscb933592017-11-22 13:49:43 -0800980 }
981}
982
Colin Cross59f1bb62017-09-27 17:59:10 -0700983func (j *Module) installable() bool {
984 return j.properties.Installable == nil || *j.properties.Installable
985}
986
Colin Crossf506d872017-07-19 15:53:04 -0700987var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700988
Nan Zhanged19fc32017-10-19 13:06:22 -0700989func (j *Module) HeaderJars() android.Paths {
990 return android.Paths{j.headerJarFile}
991}
992
993func (j *Module) ImplementationJars() android.Paths {
994 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -0700995}
996
Colin Cross46c9b8b2017-06-22 16:51:17 -0700997func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700998 return j.exportAidlIncludeDirs
999}
1000
Colin Cross46c9b8b2017-06-22 16:51:17 -07001001var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001002
Colin Cross46c9b8b2017-06-22 16:51:17 -07001003func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001004 return j.logtagsSrcs
1005}
1006
Colin Cross2fe66872015-03-30 17:20:39 -07001007//
1008// Java libraries (.jar file)
1009//
1010
Colin Crossf506d872017-07-19 15:53:04 -07001011type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001012 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001013}
1014
Colin Crossf506d872017-07-19 15:53:04 -07001015func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001016 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001017
Colin Cross59f1bb62017-09-27 17:59:10 -07001018 if j.installable() {
Colin Cross2c429dc2017-08-31 16:45:16 -07001019 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1020 ctx.ModuleName()+".jar", j.outputFile)
1021 }
Colin Crossb7a63242015-04-16 14:09:14 -07001022}
1023
Colin Crossf506d872017-07-19 15:53:04 -07001024func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001025 j.deps(ctx)
1026}
1027
Colin Crossa60ead82017-10-02 18:10:21 -07001028func LibraryFactory(installable bool) func() android.Module {
1029 return func() android.Module {
1030 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001031
Colin Crossa60ead82017-10-02 18:10:21 -07001032 if !installable {
1033 module.properties.Installable = proptools.BoolPtr(false)
1034 }
Colin Cross2fe66872015-03-30 17:20:39 -07001035
Colin Crossa60ead82017-10-02 18:10:21 -07001036 module.AddProperties(
1037 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001038 &module.Module.deviceProperties,
1039 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001040
Colin Crossa60ead82017-10-02 18:10:21 -07001041 InitJavaModule(module, android.HostAndDeviceSupported)
1042 return module
1043 }
Colin Cross2fe66872015-03-30 17:20:39 -07001044}
1045
Colin Crossf506d872017-07-19 15:53:04 -07001046func LibraryHostFactory() android.Module {
1047 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001048
Colin Cross6af17aa2017-09-20 12:59:05 -07001049 module.AddProperties(
1050 &module.Module.properties,
1051 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001052
Colin Cross89536d42017-07-07 14:35:50 -07001053 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001054 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001055}
1056
1057//
1058// Java Binaries (.jar file plus wrapper script)
1059//
1060
Colin Crossf506d872017-07-19 15:53:04 -07001061type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001062 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001063 Wrapper *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001064}
1065
Colin Crossf506d872017-07-19 15:53:04 -07001066type Binary struct {
1067 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001068
Colin Crossf506d872017-07-19 15:53:04 -07001069 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001070
Colin Cross6b4a32d2017-12-05 13:42:45 -08001071 isWrapperVariant bool
1072
Colin Crossc3315992017-12-08 19:12:36 -08001073 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001074 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001075}
1076
Alex Light24237172017-10-26 09:46:21 -07001077func (j *Binary) HostToolPath() android.OptionalPath {
1078 return android.OptionalPathForPath(j.binaryFile)
1079}
1080
Colin Crossf506d872017-07-19 15:53:04 -07001081func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001082 if ctx.Arch().ArchType == android.Common {
1083 // Compile the jar
1084 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001085 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001086 // Handle the binary wrapper
1087 j.isWrapperVariant = true
1088
Colin Cross366938f2017-12-11 16:29:02 -08001089 if j.binaryProperties.Wrapper != nil {
1090 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001091 } else {
1092 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1093 }
1094
1095 // Depend on the installed jar so that the wrapper doesn't get executed by
1096 // another build rule before the jar has been installed.
1097 jarFile := ctx.PrimaryModule().(*Binary).installFile
1098
1099 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1100 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001101 }
Colin Cross2fe66872015-03-30 17:20:39 -07001102}
1103
Colin Crossf506d872017-07-19 15:53:04 -07001104func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001105 if ctx.Arch().ArchType == android.Common {
1106 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001107 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001108 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001109 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001110}
1111
Colin Crossf506d872017-07-19 15:53:04 -07001112func BinaryFactory() android.Module {
1113 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001114
Colin Cross36242852017-06-23 15:06:31 -07001115 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001116 &module.Module.properties,
1117 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001118 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001119 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001120
Colin Cross6b4a32d2017-12-05 13:42:45 -08001121 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1122 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001123 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001124}
1125
Colin Crossf506d872017-07-19 15:53:04 -07001126func BinaryHostFactory() android.Module {
1127 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001128
Colin Cross36242852017-06-23 15:06:31 -07001129 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001130 &module.Module.properties,
1131 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001132 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001133 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001134
Colin Cross6b4a32d2017-12-05 13:42:45 -08001135 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1136 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001137 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001138}
1139
1140//
1141// Java prebuilts
1142//
1143
Colin Cross74d73e22017-08-02 11:05:49 -07001144type ImportProperties struct {
1145 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001146
Nan Zhangea568a42017-11-08 21:20:04 -08001147 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001148
1149 Installable *bool
Colin Cross74d73e22017-08-02 11:05:49 -07001150}
1151
1152type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001153 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001154 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001155
Colin Cross74d73e22017-08-02 11:05:49 -07001156 properties ImportProperties
1157
Colin Cross0a6e0072017-08-30 14:24:55 -07001158 classpathFiles android.Paths
1159 combinedClasspathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -07001160}
1161
Colin Cross74d73e22017-08-02 11:05:49 -07001162func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001163 return &j.prebuilt
1164}
1165
Colin Cross74d73e22017-08-02 11:05:49 -07001166func (j *Import) PrebuiltSrcs() []string {
1167 return j.properties.Jars
1168}
1169
1170func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001171 return j.prebuilt.Name(j.ModuleBase.Name())
1172}
1173
Colin Cross74d73e22017-08-02 11:05:49 -07001174func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross1e676be2016-10-12 14:38:15 -07001175}
1176
Colin Cross74d73e22017-08-02 11:05:49 -07001177func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1178 j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07001179
Colin Crosse9a275b2017-10-16 17:09:48 -07001180 outputFile := android.PathForModuleOut(ctx, "classes.jar")
Nan Zhanged19fc32017-10-19 13:06:22 -07001181 TransformJarsToJar(ctx, outputFile, "for prebuilts", j.classpathFiles, android.OptionalPath{}, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001182 j.combinedClasspathFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -07001183}
1184
Colin Cross74d73e22017-08-02 11:05:49 -07001185var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001186
Nan Zhanged19fc32017-10-19 13:06:22 -07001187func (j *Import) HeaderJars() android.Paths {
1188 return j.classpathFiles
1189}
1190
1191func (j *Import) ImplementationJars() android.Paths {
Colin Cross74d73e22017-08-02 11:05:49 -07001192 return j.classpathFiles
Colin Cross2fe66872015-03-30 17:20:39 -07001193}
1194
Colin Cross74d73e22017-08-02 11:05:49 -07001195func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001196 return nil
1197}
1198
Colin Cross74d73e22017-08-02 11:05:49 -07001199var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001200
Colin Cross74d73e22017-08-02 11:05:49 -07001201func ImportFactory() android.Module {
1202 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001203
Colin Cross74d73e22017-08-02 11:05:49 -07001204 module.AddProperties(&module.properties)
1205
1206 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -07001207 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1208 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001209}
1210
Colin Cross74d73e22017-08-02 11:05:49 -07001211func ImportFactoryHost() android.Module {
1212 module := &Import{}
1213
1214 module.AddProperties(&module.properties)
1215
1216 android.InitPrebuiltModule(module, &module.properties.Jars)
1217 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
1218 return module
1219}
1220
Colin Cross2fe66872015-03-30 17:20:39 -07001221func inList(s string, l []string) bool {
1222 for _, e := range l {
1223 if e == s {
1224 return true
1225 }
1226 }
1227 return false
1228}
Colin Cross89536d42017-07-07 14:35:50 -07001229
1230//
1231// Defaults
1232//
1233type Defaults struct {
1234 android.ModuleBase
1235 android.DefaultsModuleBase
1236}
1237
1238func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1239}
1240
1241func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1242}
1243
1244func defaultsFactory() android.Module {
1245 return DefaultsFactory()
1246}
1247
1248func DefaultsFactory(props ...interface{}) android.Module {
1249 module := &Defaults{}
1250
1251 module.AddProperties(props...)
1252 module.AddProperties(
1253 &CompilerProperties{},
1254 &CompilerDeviceProperties{},
1255 )
1256
1257 android.InitDefaultsModule(module)
1258
1259 return module
1260}
Nan Zhangea568a42017-11-08 21:20:04 -08001261
1262var Bool = proptools.Bool
1263var String = proptools.String