blob: a6769e7595fb2a1a089a660b34a5ef292c40f4f0 [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
Andreas Gampef3e5b552018-01-22 21:27:21 -0800145 Errorprone struct {
146 // List of javac flags that should only be used when running errorprone.
147 Javacflags []string
148 }
149
Colin Cross0f2ee152017-12-14 15:22:43 -0800150 Proto struct {
151 // List of extra options that will be passed to the proto generator.
152 Output_params []string
153 }
154
Colin Crosscb933592017-11-22 13:49:43 -0800155 Instrument bool `blueprint:"mutated"`
Colin Cross540eff82017-06-22 17:01:52 -0700156}
157
Colin Cross89536d42017-07-07 14:35:50 -0700158type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700159 // list of module-specific flags that will be used for dex compiles
160 Dxflags []string `android:"arch_variant"`
161
Colin Cross7d5136f2015-05-11 13:39:40 -0700162 // if not blank, set to the version of the sdk to compile against
Nan Zhangea568a42017-11-08 21:20:04 -0800163 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700164
Colin Crossebe1a512017-11-14 13:12:14 -0800165 Aidl struct {
166 // Top level directories to pass to aidl tool
167 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700168
Colin Crossebe1a512017-11-14 13:12:14 -0800169 // Directories rooted at the Android.bp file to pass to aidl tool
170 Local_include_dirs []string
171
172 // directories that should be added as include directories for any aidl sources of modules
173 // that depend on this module, as well as to aidl for this module.
174 Export_include_dirs []string
175 }
Colin Cross92430102017-10-09 14:59:32 -0700176
177 // If true, export a copy of the module as a -hostdex module for host testing.
178 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700179
Colin Cross1bd87802017-12-05 15:31:19 -0800180 Dex_preopt struct {
181 // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to
182 // true.
183 Enabled *bool
184
185 // If true, generate an app image (.art file) for this module.
186 App_image *bool
187
188 // If true, use a checked-in profile to guide optimization. Defaults to false unless
189 // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR
190 // that matches the name of this module, in which case it is defaulted to true.
191 Profile_guided *bool
192
193 // If set, provides the path to profile relative to the Android.bp file. If not set,
194 // defaults to searching for a file that matches the name of this module in the default
195 // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found.
196 Profile *string
197 }
Colin Crossa22116e2017-10-19 14:18:58 -0700198
Colin Cross66dbc0b2017-12-28 12:23:20 -0800199 Optimize struct {
200 // If false, disable all optimization. Defaults to true for apps, false for
201 // libraries and tests.
202 Enabled *bool
203
204 // If true, optimize for size by removing unused code. Defaults to true for apps,
205 // false for libraries and tests.
206 Shrink *bool
207
208 // If true, optimize bytecode. Defaults to false.
209 Optimize *bool
210
211 // If true, obfuscate bytecode. Defaults to false.
212 Obfuscate *bool
213
214 // If true, do not use the flag files generated by aapt that automatically keep
215 // classes referenced by the app manifest. Defaults to false.
216 No_aapt_flags *bool
217
218 // Flags to pass to proguard.
219 Proguard_flags []string
220
221 // Specifies the locations of files containing proguard flags.
222 Proguard_flags_files []string
223 }
224
Colin Cross1369cdb2017-09-29 17:58:17 -0700225 // When targeting 1.9, override the modules to use with --system
226 System_modules *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700227}
228
Colin Cross46c9b8b2017-06-22 16:51:17 -0700229// Module contains the properties and members used by all java module types
230type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700231 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700232 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700233
Colin Cross89536d42017-07-07 14:35:50 -0700234 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700235 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700236 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700237
Nan Zhanged19fc32017-10-19 13:06:22 -0700238 // header jar file suitable for inserting into the bootclasspath/classpath of another compile
239 headerJarFile android.Path
240
241 // full implementation jar file suitable for static dependency of another module compile
242 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700243
Colin Cross6ade34f2017-09-15 13:00:47 -0700244 // output file containing classes.dex
245 dexJarFile android.Path
246
Colin Crosscb933592017-11-22 13:49:43 -0800247 // output file containing uninstrumented classes that will be instrumented by jacoco
248 jacocoReportClassesFile android.Path
249
Colin Cross66dbc0b2017-12-28 12:23:20 -0800250 // output file containing mapping of obfuscated names
251 proguardDictionary android.Path
252
Colin Crossb7a63242015-04-16 14:09:14 -0700253 // output file suitable for installing or running
Colin Cross635c3b02016-05-18 15:37:25 -0700254 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700255
Colin Cross635c3b02016-05-18 15:37:25 -0700256 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700257
Colin Cross635c3b02016-05-18 15:37:25 -0700258 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700259
Colin Cross2fe66872015-03-30 17:20:39 -0700260 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700261 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800262
263 // list of .java files and srcjars that was passed to javac
264 compiledJavaSrcs android.Paths
265 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800266
267 // list of extra progurad flag files
268 extraProguardFlagFiles android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700269}
270
Colin Cross54250902017-12-05 09:28:08 -0800271func (j *Module) Srcs() android.Paths {
272 return android.Paths{j.implementationJarFile}
273}
274
275var _ android.SourceFileProducer = (*Module)(nil)
276
Colin Crossf506d872017-07-19 15:53:04 -0700277type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700278 HeaderJars() android.Paths
279 ImplementationJars() android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700280 AidlIncludeDirs() android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700281}
282
Colin Cross89536d42017-07-07 14:35:50 -0700283func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
284 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
285 android.InitDefaultableModule(module)
286}
287
Colin Crossbe1da472017-07-07 15:59:46 -0700288type dependencyTag struct {
289 blueprint.BaseDependencyTag
290 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700291}
292
Colin Crossbe1da472017-07-07 15:59:46 -0700293var (
Colin Cross6ade34f2017-09-15 13:00:47 -0700294 staticLibTag = dependencyTag{name: "staticlib"}
295 libTag = dependencyTag{name: "javalib"}
296 bootClasspathTag = dependencyTag{name: "bootclasspath"}
Colin Cross1369cdb2017-09-29 17:58:17 -0700297 systemModulesTag = dependencyTag{name: "system modules"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700298 frameworkResTag = dependencyTag{name: "framework-res"}
Colin Cross93e85952017-08-15 13:34:18 -0700299 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Cross66dbc0b2017-12-28 12:23:20 -0800300 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
Colin Crossbe1da472017-07-07 15:59:46 -0700301)
Colin Cross2fe66872015-03-30 17:20:39 -0700302
Colin Crossfc3674a2017-09-18 17:41:52 -0700303type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700304 useModule, useFiles, useDefaultLibs, invalidVersion bool
305
Colin Cross1369cdb2017-09-29 17:58:17 -0700306 module string
307 systemModules string
308
309 jar android.Path
310 aidl android.Path
311}
312
313func sdkStringToNumber(ctx android.BaseContext, v string) int {
314 switch v {
315 case "", "current", "system_current", "test_current":
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900316 return android.FutureApiLevel
Colin Cross1369cdb2017-09-29 17:58:17 -0700317 default:
Sundong Ahn0926fae2017-10-17 16:34:51 +0900318 if i, err := strconv.Atoi(android.GetNumericSdkVersion(v)); err != nil {
Colin Cross1369cdb2017-09-29 17:58:17 -0700319 ctx.PropertyErrorf("sdk_version", "invalid sdk version")
320 return -1
321 } else {
322 return i
323 }
324 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700325}
326
Colin Cross3144dfc2018-01-03 15:06:47 -0800327func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
328 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
329}
330
331func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
332 return j.shouldInstrument(ctx) &&
333 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
334 ctx.Config().UnbundledBuild())
335}
336
Colin Crossfc3674a2017-09-18 17:41:52 -0700337func decodeSdkDep(ctx android.BaseContext, v string) sdkDep {
Colin Cross1369cdb2017-09-29 17:58:17 -0700338 i := sdkStringToNumber(ctx, v)
339 if i == -1 {
340 // Invalid sdk version, error handled by sdkStringToNumber.
341 return sdkDep{}
Colin Crossfc3674a2017-09-18 17:41:52 -0700342 }
343
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900344 // Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks)
345 // or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set)
346 if strings.HasPrefix(v, "system_") && i != android.FutureApiLevel {
347 allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions()
348 if ctx.DeviceSpecific() || ctx.SocSpecific() {
349 if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 {
350 allowed_versions = ctx.DeviceConfig().SystemSdkVersions()
351 }
352 }
353 version := strings.TrimPrefix(v, "system_")
354 if len(allowed_versions) > 0 && !android.InList(version, allowed_versions) {
355 ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q",
356 v, allowed_versions)
357 }
358 }
359
Colin Crossfc3674a2017-09-18 17:41:52 -0700360 toFile := func(v string) sdkDep {
361 dir := filepath.Join("prebuilts/sdk", v)
362 jar := filepath.Join(dir, "android.jar")
363 aidl := filepath.Join(dir, "framework.aidl")
364 jarPath := android.ExistentPathForSource(ctx, "sdkdir", jar)
365 aidlPath := android.ExistentPathForSource(ctx, "sdkdir", aidl)
Colin Cross47ff2522017-10-02 14:22:08 -0700366
Colin Cross6510f912017-11-29 00:27:14 -0800367 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
Sundong Ahn0926fae2017-10-17 16:34:51 +0900368 if strings.Contains(v, "system_") {
369 return sdkDep{
370 invalidVersion: true,
Sundong Ahnb5b5b262018-01-15 15:07:40 +0900371 module: "system_sdk_v" + strings.Replace(v, "system_", "", 1),
Sundong Ahn0926fae2017-10-17 16:34:51 +0900372 }
373 }
Colin Cross47ff2522017-10-02 14:22:08 -0700374 return sdkDep{
375 invalidVersion: true,
376 module: "sdk_v" + v,
377 }
378 }
379
Colin Crossfc3674a2017-09-18 17:41:52 -0700380 if !jarPath.Valid() {
381 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar)
382 return sdkDep{}
383 }
Colin Cross47ff2522017-10-02 14:22:08 -0700384
Colin Crossfc3674a2017-09-18 17:41:52 -0700385 if !aidlPath.Valid() {
386 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl)
387 return sdkDep{}
388 }
Colin Cross47ff2522017-10-02 14:22:08 -0700389
Colin Crossfc3674a2017-09-18 17:41:52 -0700390 return sdkDep{
391 useFiles: true,
392 jar: jarPath.Path(),
393 aidl: aidlPath.Path(),
394 }
395 }
396
Colin Cross2ebc4762017-10-20 14:00:31 -0700397 //toModule := func(m string) sdkDep {
398 // return sdkDep{
399 // useModule: true,
400 // module: m,
401 // systemModules: m + "_system_modules",
402 // }
403 //}
Colin Crossfc3674a2017-09-18 17:41:52 -0700404
Colin Cross6510f912017-11-29 00:27:14 -0800405 if ctx.Config().UnbundledBuild() && v != "" {
Colin Crossfc3674a2017-09-18 17:41:52 -0700406 return toFile(v)
407 }
408
409 switch v {
410 case "":
411 return sdkDep{
412 useDefaultLibs: true,
413 }
Colin Cross2ebc4762017-10-20 14:00:31 -0700414 // TODO(ccross): re-enable these once we generate stubs, until then
415 // use the stubs in prebuilts/sdk/*current
416 //case "current":
417 // return toModule("android_stubs_current")
418 //case "system_current":
419 // return toModule("android_system_stubs_current")
420 //case "test_current":
421 // return toModule("android_test_stubs_current")
Colin Crossfc3674a2017-09-18 17:41:52 -0700422 default:
423 return toFile(v)
424 }
425}
426
Colin Crossbe1da472017-07-07 15:59:46 -0700427func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700428 if ctx.Device() {
429 if !proptools.Bool(j.properties.No_standard_libs) {
Nan Zhangea568a42017-11-08 21:20:04 -0800430 sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
Colin Crossfc3674a2017-09-18 17:41:52 -0700431 if sdkDep.useDefaultLibs {
Colin Crosscb2c9292017-09-23 19:57:16 -0700432 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Colin Cross6510f912017-11-29 00:27:14 -0800433 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700434 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
435 }
Colin Crossfa5eb232017-10-01 20:33:03 -0700436 if !proptools.Bool(j.properties.No_framework_libs) {
437 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
438 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700439 } else if sdkDep.useModule {
Colin Cross6510f912017-11-29 00:27:14 -0800440 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700441 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
442 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700443 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800444 if Bool(j.deviceProperties.Optimize.Enabled) {
445 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultBootclasspathLibraries...)
446 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultLibraries...)
447 }
Colin Crossbe1da472017-07-07 15:59:46 -0700448 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700449 } else if j.deviceProperties.System_modules == nil {
450 ctx.PropertyErrorf("no_standard_libs",
451 "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 -0800452 } else if *j.deviceProperties.System_modules != "none" && ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700453 ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700454 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800455 if ctx.ModuleName() == "framework" {
456 ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res")
457 }
Colin Cross2fe66872015-03-30 17:20:39 -0700458 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700459
Colin Crossf506d872017-07-19 15:53:04 -0700460 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
461 ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
Colin Cross6ade34f2017-09-15 13:00:47 -0700462 ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...)
Colin Cross7f9036c2017-08-30 13:27:57 -0700463
464 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700465 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross366938f2017-12-11 16:29:02 -0800466 android.ExtractSourceDeps(ctx, j.properties.Manifest)
Colin Cross6af17aa2017-09-20 12:59:05 -0700467
468 if j.hasSrcExt(".proto") {
469 protoDeps(ctx, &j.protoProperties)
470 }
Colin Cross93e85952017-08-15 13:34:18 -0700471
472 if j.hasSrcExt(".kt") {
473 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
474 // Kotlin files
475 ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib")
476 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800477
478 if j.shouldInstrumentStatic(ctx) {
479 ctx.AddDependency(ctx.Module(), staticLibTag, "jacocoagent")
480 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700481}
482
483func hasSrcExt(srcs []string, ext string) bool {
484 for _, src := range srcs {
485 if filepath.Ext(src) == ext {
486 return true
487 }
488 }
489
490 return false
491}
492
Nan Zhang61eaedb2017-11-02 13:28:15 -0700493func shardPaths(paths android.Paths, shardSize int) []android.Paths {
494 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
495 for len(paths) > shardSize {
496 ret = append(ret, paths[0:shardSize])
497 paths = paths[shardSize:]
498 }
499 if len(paths) > 0 {
500 ret = append(ret, paths)
501 }
502 return ret
503}
504
Colin Cross6af17aa2017-09-20 12:59:05 -0700505func (j *Module) hasSrcExt(ext string) bool {
506 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700507}
508
Colin Cross46c9b8b2017-06-22 16:51:17 -0700509func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700510 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700511
Colin Crossebe1a512017-11-14 13:12:14 -0800512 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
513 aidlIncludes = append(aidlIncludes,
514 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
515 aidlIncludes = append(aidlIncludes,
516 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700517
518 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700519 if aidlPreprocess.Valid() {
520 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700521 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700522 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700523 }
524
Colin Cross635c3b02016-05-18 15:37:25 -0700525 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800526 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700527 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Crosse243c232017-10-21 15:16:37 -0700528 if src := android.ExistentPathForSource(ctx, "", ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700529 flags = append(flags, "-I"+src.String())
530 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700531
Colin Crossf03c82b2015-04-13 13:53:40 -0700532 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700533}
534
Colin Cross32f676a2017-09-06 13:41:06 -0700535type deps struct {
Colin Cross6ade34f2017-09-15 13:00:47 -0700536 classpath android.Paths
537 bootClasspath android.Paths
538 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700539 staticHeaderJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700540 staticJarResources android.Paths
541 aidlIncludeDirs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700542 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700543 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700544 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700545 kotlinStdlib android.Paths
Colin Cross32f676a2017-09-06 13:41:06 -0700546}
Colin Cross2fe66872015-03-30 17:20:39 -0700547
Colin Cross54250902017-12-05 09:28:08 -0800548func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
549 for _, f := range dep.Srcs() {
550 if f.Ext() != ".jar" {
551 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
552 ctx.OtherModuleName(dep.(blueprint.Module)))
553 }
554 }
555}
556
Colin Cross32f676a2017-09-06 13:41:06 -0700557func (j *Module) collectDeps(ctx android.ModuleContext) deps {
558 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700559
Nan Zhangea568a42017-11-08 21:20:04 -0800560 sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
Colin Cross47ff2522017-10-02 14:22:08 -0700561 if sdkDep.invalidVersion {
562 ctx.AddMissingDependencies([]string{sdkDep.module})
563 } else if sdkDep.useFiles {
Nan Zhanged19fc32017-10-19 13:06:22 -0700564 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Crossfc3674a2017-09-18 17:41:52 -0700565 deps.classpath = append(deps.classpath, sdkDep.jar)
566 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
567 }
568
Colin Crossd11fcda2017-10-23 17:59:01 -0700569 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700570 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700571 tag := ctx.OtherModuleDependencyTag(module)
572
Colin Cross54250902017-12-05 09:28:08 -0800573 switch dep := module.(type) {
574 case Dependency:
575 switch tag {
576 case bootClasspathTag:
577 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
578 case libTag:
579 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
580 case staticLibTag:
581 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
582 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
583 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
584 case frameworkResTag:
585 if ctx.ModuleName() == "framework" {
586 // framework.jar has a one-off dependency on the R.java and Manifest.java files
587 // generated by framework-res.apk
588 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
589 }
590 case kotlinStdlibTag:
591 deps.kotlinStdlib = dep.HeaderJars()
592 default:
593 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
594 }
595
596 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
597 case android.SourceFileProducer:
598 switch tag {
599 case libTag:
600 checkProducesJars(ctx, dep)
601 deps.classpath = append(deps.classpath, dep.Srcs()...)
602 case staticLibTag:
603 checkProducesJars(ctx, dep)
604 deps.classpath = append(deps.classpath, dep.Srcs()...)
605 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
606 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
607 case android.DefaultsDepTag, android.SourceDepTag:
608 // Nothing to do
609 default:
610 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
611 }
612 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700613 switch tag {
614 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700615 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700616 case systemModulesTag:
617 if deps.systemModules != nil {
618 panic("Found two system module dependencies")
619 }
620 sm := module.(*SystemModules)
621 if sm.outputFile == nil {
622 panic("Missing directory for system module dependency")
623 }
624 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700625 default:
626 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700627 }
Colin Crossec7a0422017-07-07 14:47:12 -0700628 }
Colin Cross2fe66872015-03-30 17:20:39 -0700629 })
630
Colin Cross32f676a2017-09-06 13:41:06 -0700631 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700632}
633
Nan Zhanged19fc32017-10-19 13:06:22 -0700634func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700635
Colin Crossf03c82b2015-04-13 13:53:40 -0700636 var flags javaBuilderFlags
637
Nan Zhanged19fc32017-10-19 13:06:22 -0700638 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700639 javacFlags := j.properties.Javacflags
Colin Cross6510f912017-11-29 00:27:14 -0800640 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700641 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700642 }
Colin Cross6510f912017-11-29 00:27:14 -0800643 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700644 // Override the -g flag passed globally to remove local variable debug info to reduce
645 // disk and memory usage.
646 javacFlags = append(javacFlags, "-g:source,lines")
647 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700648 if len(javacFlags) > 0 {
649 // optimization.
650 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
651 flags.javacFlags = "$javacFlags"
Colin Cross4f26bc02017-09-06 12:52:16 -0700652 }
Colin Cross64162712017-08-08 13:17:59 -0700653
Andreas Gampef3e5b552018-01-22 21:27:21 -0800654 if len(j.properties.Errorprone.Javacflags) > 0 {
655 flags.errorProneExtraJavacFlags = strings.Join(j.properties.Errorprone.Javacflags, " ")
656 }
657
Nan Zhanged19fc32017-10-19 13:06:22 -0700658 // javaVersion flag.
Nan Zhangea568a42017-11-08 21:20:04 -0800659 sdk := sdkStringToNumber(ctx, String(j.deviceProperties.Sdk_version))
Colin Cross64162712017-08-08 13:17:59 -0700660 if j.properties.Java_version != nil {
661 flags.javaVersion = *j.properties.Java_version
Colin Cross1369cdb2017-09-29 17:58:17 -0700662 } else if ctx.Device() && sdk <= 23 {
663 flags.javaVersion = "1.7"
Colin Cross6510f912017-11-29 00:27:14 -0800664 } else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700665 flags.javaVersion = "1.8"
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900666 } else if ctx.Device() && String(j.deviceProperties.Sdk_version) != "" && sdk == android.FutureApiLevel {
Colin Cross2ebc4762017-10-20 14:00:31 -0700667 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
668 flags.javaVersion = "1.8"
Colin Cross64162712017-08-08 13:17:59 -0700669 } else {
Colin Cross1369cdb2017-09-29 17:58:17 -0700670 flags.javaVersion = "1.9"
Colin Cross64162712017-08-08 13:17:59 -0700671 }
672
Nan Zhanged19fc32017-10-19 13:06:22 -0700673 // classpath
Colin Cross6ade34f2017-09-15 13:00:47 -0700674 flags.bootClasspath.AddPaths(deps.bootClasspath)
675 flags.classpath.AddPaths(deps.classpath)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800676
677 if len(flags.bootClasspath) == 0 && ctx.Host() && !ctx.Config().TargetOpenJDK9() &&
678 !Bool(j.properties.No_standard_libs) &&
679 inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
680 // Give host-side tools a version of OpenJDK's standard libraries
681 // close to what they're targeting. As of Dec 2017, AOSP is only
682 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
683 //
684 // When building with OpenJDK 8, the following should have no
685 // effect since those jars would be available by default.
686 //
687 // When building with OpenJDK 9 but targeting a version < 1.8,
688 // putting them on the bootclasspath means that:
689 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
690 // b) references to existing APIs are not reinterpreted in an
691 // OpenJDK 9-specific way, eg. calls to subclasses of
692 // java.nio.Buffer as in http://b/70862583
693 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
694 flags.bootClasspath = append(flags.bootClasspath,
695 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
696 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
697 }
698
Nan Zhanged19fc32017-10-19 13:06:22 -0700699 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700700 if deps.systemModules != nil {
701 flags.systemModules = append(flags.systemModules, deps.systemModules)
702 }
703
Nan Zhanged19fc32017-10-19 13:06:22 -0700704 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700705 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700706 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700707 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700708 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
709 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700710 }
711
Nan Zhanged19fc32017-10-19 13:06:22 -0700712 return flags
713}
Colin Crossc0b06f12015-04-08 13:03:43 -0700714
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800715func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700716
Colin Crossebe1a512017-11-14 13:12:14 -0800717 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700718
719 deps := j.collectDeps(ctx)
720 flags := j.collectBuilderFlags(ctx, deps)
721
Colin Cross6510f912017-11-29 00:27:14 -0800722 if ctx.Config().TargetOpenJDK9() {
Nan Zhanged19fc32017-10-19 13:06:22 -0700723 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
724 }
725 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700726 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -0800727 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700728 }
729
Colin Crossaf050172017-11-15 23:01:59 -0800730 srcFiles = j.genSources(ctx, srcFiles, flags)
731
732 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700733 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800734 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700735
Colin Cross0a6e0072017-08-30 14:24:55 -0700736 var jars android.Paths
737
Colin Cross1ee23172017-10-18 14:44:18 -0700738 jarName := ctx.ModuleName() + ".jar"
739
Colin Cross93e85952017-08-15 13:34:18 -0700740 if srcFiles.HasExt(".kt") {
741 // If there are kotlin files, compile them first but pass all the kotlin and java files
742 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
743 // won't emit any classes for them.
744
745 flags.kotlincFlags = "-no-stdlib"
746 if ctx.Device() {
747 flags.kotlincFlags += " -no-jdk"
748 }
749
750 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
751 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
752
Colin Cross1ee23172017-10-18 14:44:18 -0700753 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross93e85952017-08-15 13:34:18 -0700754 TransformKotlinToClasses(ctx, kotlinJar, srcFiles, srcJars, flags)
755 if ctx.Failed() {
756 return
757 }
758
759 // Make javac rule depend on the kotlinc rule
760 flags.classpath = append(flags.classpath, kotlinJar)
761 // Jar kotlin classes into the final jar after javac
762 jars = append(jars, kotlinJar)
763 jars = append(jars, deps.kotlinStdlib...)
764 }
765
Nan Zhanged19fc32017-10-19 13:06:22 -0700766 javaSrcFiles := srcFiles.FilterByExt(".java")
767 var uniqueSrcFiles android.Paths
768 set := make(map[string]bool)
769 for _, v := range javaSrcFiles {
770 if _, found := set[v.String()]; !found {
771 set[v.String()] = true
772 uniqueSrcFiles = append(uniqueSrcFiles, v)
773 }
774 }
775
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800776 // Store the list of .java files that was passed to javac
777 j.compiledJavaSrcs = uniqueSrcFiles
778 j.compiledSrcJars = srcJars
779
Nan Zhang61eaedb2017-11-02 13:28:15 -0700780 enable_sharding := false
Colin Cross6510f912017-11-29 00:27:14 -0800781 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") {
Nan Zhang61eaedb2017-11-02 13:28:15 -0700782 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
783 enable_sharding = true
784 if len(j.properties.Annotation_processors) != 0 ||
785 len(j.properties.Annotation_processor_classes) != 0 {
786 ctx.PropertyErrorf("javac_shard_size",
787 "%q cannot be set when annotation processors are enabled.",
788 j.properties.Javac_shard_size)
789 }
790 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700791 // If sdk jar is java module, then directly return classesJar as header.jar
792 if j.Name() != "android_stubs_current" && j.Name() != "android_system_stubs_current" &&
793 j.Name() != "android_test_stubs_current" {
794 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName)
795 if ctx.Failed() {
796 return
797 }
798 }
799 }
Colin Cross8eadbf02017-10-24 17:46:00 -0700800 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -0700801 var extraJarDeps android.Paths
Colin Cross6510f912017-11-29 00:27:14 -0800802 if ctx.Config().IsEnvTrue("RUN_ERROR_PRONE") {
Colin Crossc6bbef32017-08-14 14:16:06 -0700803 // If error-prone is enabled, add an additional rule to compile the java files into
804 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -0700805 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -0700806 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
807 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -0700808 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -0700809 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -0700810 extraJarDeps = append(extraJarDeps, errorprone)
811 }
812
Nan Zhang61eaedb2017-11-02 13:28:15 -0700813 if enable_sharding {
814 flags.classpath.AddPaths([]android.Path{j.headerJarFile})
815 shardSize := int(*(j.properties.Javac_shard_size))
816 var shardSrcs []android.Paths
817 if len(uniqueSrcFiles) > 0 {
818 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
819 for idx, shardSrc := range shardSrcs {
820 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
821 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
822 jars = append(jars, classes)
823 }
824 }
825 if len(srcJars) > 0 {
826 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
827 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
828 jars = append(jars, classes)
829 }
830 } else {
831 classes := android.PathForModuleOut(ctx, "javac", jarName)
832 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
833 jars = append(jars, classes)
834 }
Colin Crossd6891432017-09-27 17:39:56 -0700835 if ctx.Failed() {
836 return
837 }
Colin Cross2fe66872015-03-30 17:20:39 -0700838 }
839
Colin Cross0f37af02017-09-27 17:42:05 -0700840 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
841 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
842
843 var resArgs []string
844 var resDeps android.Paths
845
846 resArgs = append(resArgs, dirArgs...)
847 resDeps = append(resDeps, dirDeps...)
848
849 resArgs = append(resArgs, fileArgs...)
850 resDeps = append(resDeps, fileDeps...)
851
852 if proptools.Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -0700853 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700854 resArgs = append(resArgs, srcArgs...)
855 resDeps = append(resDeps, srcDeps...)
856 }
Colin Cross40a36712017-09-27 17:41:35 -0700857
858 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -0700859 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700860 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -0700861 if ctx.Failed() {
862 return
863 }
Colin Cross20978302015-04-10 17:05:07 -0700864
Colin Cross0a6e0072017-08-30 14:24:55 -0700865 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -0700866 }
867
Colin Cross6ade34f2017-09-15 13:00:47 -0700868 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -0700869 jars = append(jars, deps.staticJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -0700870
Colin Cross366938f2017-12-11 16:29:02 -0800871 var manifest android.OptionalPath
872 if j.properties.Manifest != nil {
873 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
874 }
Colin Cross635acc92017-09-12 22:50:46 -0700875
Colin Cross0a6e0072017-08-30 14:24:55 -0700876 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -0700877 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -0700878 var outputFile android.Path
879
880 if len(jars) == 1 && !manifest.Valid() {
881 // Optimization: skip the combine step if there is nothing to do
Colin Cross7b60cdd2017-12-21 13:52:58 -0800882 // TODO(ccross): this leaves any module-info.class files, but those should only come from
883 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
884 // any if len(jars) == 1.
Colin Crosse9a275b2017-10-16 17:09:48 -0700885 outputFile = jars[0]
886 } else {
Colin Cross1ee23172017-10-18 14:44:18 -0700887 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Nan Zhanged19fc32017-10-19 13:06:22 -0700888 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -0700889 outputFile = combinedJar
890 }
Colin Cross0a6e0072017-08-30 14:24:55 -0700891
892 if j.properties.Jarjar_rules != nil {
893 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -0700894 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -0700895 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700896 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
897 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -0700898 if ctx.Failed() {
899 return
900 }
901 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700902 j.implementationJarFile = outputFile
903 if j.headerJarFile == nil {
904 j.headerJarFile = j.implementationJarFile
905 }
Colin Cross2fe66872015-03-30 17:20:39 -0700906
Colin Cross6510f912017-11-29 00:27:14 -0800907 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -0800908 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
909 j.properties.Instrument = true
910 }
911 }
912
Colin Cross3144dfc2018-01-03 15:06:47 -0800913 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -0800914 outputFile = j.instrument(ctx, flags, outputFile, jarName)
915 }
916
917 if ctx.Device() && j.installable() {
Colin Crossf0056cb2017-12-22 15:56:08 -0800918 outputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -0700919 if ctx.Failed() {
920 return
921 }
Colin Cross2fe66872015-03-30 17:20:39 -0700922 }
Colin Crossb7a63242015-04-16 14:09:14 -0700923 ctx.CheckbuildFile(outputFile)
924 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700925}
926
Colin Cross8eadbf02017-10-24 17:46:00 -0700927func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Nan Zhanged19fc32017-10-19 13:06:22 -0700928 deps deps, flags javaBuilderFlags, jarName string) android.Path {
929
930 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -0700931 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700932 // Compile java sources into turbine.jar.
933 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
934 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
935 if ctx.Failed() {
936 return nil
937 }
938 jars = append(jars, turbineJar)
939 }
940
941 // Combine any static header libraries into classes-header.jar. If there is only
942 // one input jar this step will be skipped.
943 var headerJar android.Path
944 jars = append(jars, deps.staticHeaderJars...)
945
Colin Cross5c6ecc12017-10-23 18:12:27 -0700946 // we cannot skip the combine step for now if there is only one jar
947 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
948 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
949 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, false, []string{"META-INF"})
950 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -0700951
952 if j.properties.Jarjar_rules != nil {
953 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
954 // Transform classes.jar into classes-jarjar.jar
955 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
956 TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules)
957 headerJar = jarjarFile
958 if ctx.Failed() {
959 return nil
960 }
961 }
962
963 return headerJar
964}
965
Colin Crosscb933592017-11-22 13:49:43 -0800966func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
967 classesJar android.Path, jarName string) android.Path {
968
Colin Cross7a3139e2017-12-19 13:57:50 -0800969 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -0800970
Colin Cross84c38822018-01-03 15:59:46 -0800971 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -0800972 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
973
974 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
975
976 j.jacocoReportClassesFile = jacocoReportClassesFile
977
978 return instrumentedJar
979}
980
Colin Crosscb933592017-11-22 13:49:43 -0800981// Returns a sdk version as a string that is guaranteed to be a parseable as a number. For
982// modules targeting an unreleased SDK (meaning it does not yet have a number) it returns "10000".
983func (j *Module) minSdkVersionNumber(ctx android.ModuleContext) string {
984 switch String(j.deviceProperties.Sdk_version) {
985 case "", "current", "test_current", "system_current":
Colin Cross6510f912017-11-29 00:27:14 -0800986 return strconv.Itoa(ctx.Config().DefaultAppTargetSdkInt())
Colin Crosscb933592017-11-22 13:49:43 -0800987 default:
Sundong Ahn0926fae2017-10-17 16:34:51 +0900988 return android.GetNumericSdkVersion(String(j.deviceProperties.Sdk_version))
Colin Crosscb933592017-11-22 13:49:43 -0800989 }
990}
991
Colin Cross59f1bb62017-09-27 17:59:10 -0700992func (j *Module) installable() bool {
993 return j.properties.Installable == nil || *j.properties.Installable
994}
995
Colin Crossf506d872017-07-19 15:53:04 -0700996var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700997
Nan Zhanged19fc32017-10-19 13:06:22 -0700998func (j *Module) HeaderJars() android.Paths {
999 return android.Paths{j.headerJarFile}
1000}
1001
1002func (j *Module) ImplementationJars() android.Paths {
1003 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001004}
1005
Colin Cross46c9b8b2017-06-22 16:51:17 -07001006func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001007 return j.exportAidlIncludeDirs
1008}
1009
Colin Cross46c9b8b2017-06-22 16:51:17 -07001010var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001011
Colin Cross46c9b8b2017-06-22 16:51:17 -07001012func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001013 return j.logtagsSrcs
1014}
1015
Colin Cross2fe66872015-03-30 17:20:39 -07001016//
1017// Java libraries (.jar file)
1018//
1019
Colin Crossf506d872017-07-19 15:53:04 -07001020type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001021 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001022}
1023
Colin Crossf506d872017-07-19 15:53:04 -07001024func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001025 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001026
Colin Cross59f1bb62017-09-27 17:59:10 -07001027 if j.installable() {
Colin Cross2c429dc2017-08-31 16:45:16 -07001028 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1029 ctx.ModuleName()+".jar", j.outputFile)
1030 }
Colin Crossb7a63242015-04-16 14:09:14 -07001031}
1032
Colin Crossf506d872017-07-19 15:53:04 -07001033func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001034 j.deps(ctx)
1035}
1036
Colin Crossa60ead82017-10-02 18:10:21 -07001037func LibraryFactory(installable bool) func() android.Module {
1038 return func() android.Module {
1039 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001040
Colin Crossa60ead82017-10-02 18:10:21 -07001041 if !installable {
1042 module.properties.Installable = proptools.BoolPtr(false)
1043 }
Colin Cross2fe66872015-03-30 17:20:39 -07001044
Colin Crossa60ead82017-10-02 18:10:21 -07001045 module.AddProperties(
1046 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001047 &module.Module.deviceProperties,
1048 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001049
Colin Crossa60ead82017-10-02 18:10:21 -07001050 InitJavaModule(module, android.HostAndDeviceSupported)
1051 return module
1052 }
Colin Cross2fe66872015-03-30 17:20:39 -07001053}
1054
Colin Crossf506d872017-07-19 15:53:04 -07001055func LibraryHostFactory() android.Module {
1056 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001057
Colin Cross6af17aa2017-09-20 12:59:05 -07001058 module.AddProperties(
1059 &module.Module.properties,
1060 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001061
Colin Cross89536d42017-07-07 14:35:50 -07001062 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001063 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001064}
1065
1066//
1067// Java Binaries (.jar file plus wrapper script)
1068//
1069
Colin Crossf506d872017-07-19 15:53:04 -07001070type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001071 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001072 Wrapper *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001073}
1074
Colin Crossf506d872017-07-19 15:53:04 -07001075type Binary struct {
1076 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001077
Colin Crossf506d872017-07-19 15:53:04 -07001078 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001079
Colin Cross6b4a32d2017-12-05 13:42:45 -08001080 isWrapperVariant bool
1081
Colin Crossc3315992017-12-08 19:12:36 -08001082 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001083 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001084}
1085
Alex Light24237172017-10-26 09:46:21 -07001086func (j *Binary) HostToolPath() android.OptionalPath {
1087 return android.OptionalPathForPath(j.binaryFile)
1088}
1089
Colin Crossf506d872017-07-19 15:53:04 -07001090func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001091 if ctx.Arch().ArchType == android.Common {
1092 // Compile the jar
1093 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001094 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001095 // Handle the binary wrapper
1096 j.isWrapperVariant = true
1097
Colin Cross366938f2017-12-11 16:29:02 -08001098 if j.binaryProperties.Wrapper != nil {
1099 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001100 } else {
1101 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1102 }
1103
1104 // Depend on the installed jar so that the wrapper doesn't get executed by
1105 // another build rule before the jar has been installed.
1106 jarFile := ctx.PrimaryModule().(*Binary).installFile
1107
1108 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1109 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001110 }
Colin Cross2fe66872015-03-30 17:20:39 -07001111}
1112
Colin Crossf506d872017-07-19 15:53:04 -07001113func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001114 if ctx.Arch().ArchType == android.Common {
1115 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001116 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001117 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001118 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001119}
1120
Colin Crossf506d872017-07-19 15:53:04 -07001121func BinaryFactory() android.Module {
1122 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001123
Colin Cross36242852017-06-23 15:06:31 -07001124 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001125 &module.Module.properties,
1126 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001127 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001128 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001129
Colin Cross6b4a32d2017-12-05 13:42:45 -08001130 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1131 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001132 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001133}
1134
Colin Crossf506d872017-07-19 15:53:04 -07001135func BinaryHostFactory() android.Module {
1136 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001137
Colin Cross36242852017-06-23 15:06:31 -07001138 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001139 &module.Module.properties,
1140 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001141 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001142 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001143
Colin Cross6b4a32d2017-12-05 13:42:45 -08001144 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1145 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001146 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001147}
1148
1149//
1150// Java prebuilts
1151//
1152
Colin Cross74d73e22017-08-02 11:05:49 -07001153type ImportProperties struct {
1154 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001155
Nan Zhangea568a42017-11-08 21:20:04 -08001156 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001157
1158 Installable *bool
Colin Cross74d73e22017-08-02 11:05:49 -07001159}
1160
1161type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001162 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001163 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001164
Colin Cross74d73e22017-08-02 11:05:49 -07001165 properties ImportProperties
1166
Colin Cross0a6e0072017-08-30 14:24:55 -07001167 classpathFiles android.Paths
1168 combinedClasspathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -07001169}
1170
Colin Cross74d73e22017-08-02 11:05:49 -07001171func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001172 return &j.prebuilt
1173}
1174
Colin Cross74d73e22017-08-02 11:05:49 -07001175func (j *Import) PrebuiltSrcs() []string {
1176 return j.properties.Jars
1177}
1178
1179func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001180 return j.prebuilt.Name(j.ModuleBase.Name())
1181}
1182
Colin Cross74d73e22017-08-02 11:05:49 -07001183func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross1e676be2016-10-12 14:38:15 -07001184}
1185
Colin Cross74d73e22017-08-02 11:05:49 -07001186func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1187 j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07001188
Colin Crosse9a275b2017-10-16 17:09:48 -07001189 outputFile := android.PathForModuleOut(ctx, "classes.jar")
Nan Zhanged19fc32017-10-19 13:06:22 -07001190 TransformJarsToJar(ctx, outputFile, "for prebuilts", j.classpathFiles, android.OptionalPath{}, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001191 j.combinedClasspathFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -07001192}
1193
Colin Cross74d73e22017-08-02 11:05:49 -07001194var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001195
Nan Zhanged19fc32017-10-19 13:06:22 -07001196func (j *Import) HeaderJars() android.Paths {
1197 return j.classpathFiles
1198}
1199
1200func (j *Import) ImplementationJars() android.Paths {
Colin Cross74d73e22017-08-02 11:05:49 -07001201 return j.classpathFiles
Colin Cross2fe66872015-03-30 17:20:39 -07001202}
1203
Colin Cross74d73e22017-08-02 11:05:49 -07001204func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001205 return nil
1206}
1207
Colin Cross74d73e22017-08-02 11:05:49 -07001208var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001209
Colin Cross74d73e22017-08-02 11:05:49 -07001210func ImportFactory() android.Module {
1211 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001212
Colin Cross74d73e22017-08-02 11:05:49 -07001213 module.AddProperties(&module.properties)
1214
1215 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -07001216 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1217 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001218}
1219
Colin Cross74d73e22017-08-02 11:05:49 -07001220func ImportFactoryHost() android.Module {
1221 module := &Import{}
1222
1223 module.AddProperties(&module.properties)
1224
1225 android.InitPrebuiltModule(module, &module.properties.Jars)
1226 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
1227 return module
1228}
1229
Colin Cross2fe66872015-03-30 17:20:39 -07001230func inList(s string, l []string) bool {
1231 for _, e := range l {
1232 if e == s {
1233 return true
1234 }
1235 }
1236 return false
1237}
Colin Cross89536d42017-07-07 14:35:50 -07001238
1239//
1240// Defaults
1241//
1242type Defaults struct {
1243 android.ModuleBase
1244 android.DefaultsModuleBase
1245}
1246
1247func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1248}
1249
1250func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1251}
1252
1253func defaultsFactory() android.Module {
1254 return DefaultsFactory()
1255}
1256
1257func DefaultsFactory(props ...interface{}) android.Module {
1258 module := &Defaults{}
1259
1260 module.AddProperties(props...)
1261 module.AddProperties(
1262 &CompilerProperties{},
1263 &CompilerDeviceProperties{},
1264 )
1265
1266 android.InitDefaultsModule(module)
1267
1268 return module
1269}
Nan Zhangea568a42017-11-08 21:20:04 -08001270
1271var Bool = proptools.Bool
1272var String = proptools.String