blob: 5d75b1fc08c9d23500e7cad1c4d8cfb488583867 [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 (
Colin Crossf19b9bb2018-03-26 14:42:44 -070022 "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 Cross05638fc2018-04-09 18:40:24 -070042 android.RegisterModuleType("java_test", TestFactory)
43 android.RegisterModuleType("java_test_host", TestHostFactory)
Colin Cross74d73e22017-08-02 11:05:49 -070044 android.RegisterModuleType("java_import", ImportFactory)
45 android.RegisterModuleType("java_import_host", ImportFactoryHost)
Colin Cross463a90e2015-06-17 14:20:06 -070046
Colin Cross798bfce2016-10-12 14:28:16 -070047 android.RegisterSingletonType("logtags", LogtagsSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -070048}
49
Colin Cross2fe66872015-03-30 17:20:39 -070050// TODO:
51// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070052// Renderscript
53// Post-jar passes:
54// Proguard
Colin Cross2fe66872015-03-30 17:20:39 -070055// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -070056// DroidDoc
57// Findbugs
58
Colin Cross89536d42017-07-07 14:35:50 -070059type CompilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -070060 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
61 // or .aidl files.
Dan Willemsen2ef08f42015-06-30 18:15:24 -070062 Srcs []string `android:"arch_variant"`
63
64 // list of source files that should not be used to build the Java module.
65 // This is most useful in the arch/multilib variants to remove non-common files
66 Exclude_srcs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070067
68 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -070069 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070070
Colin Cross86a63ff2017-09-27 17:33:10 -070071 // list of directories that should be excluded from java_resource_dirs
72 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -070073
Colin Cross0f37af02017-09-27 17:42:05 -070074 // list of files to use as Java resources
75 Java_resources []string `android:"arch_variant"`
76
77 // list of files that should be excluded from java_resources
78 Exclude_java_resources []string `android:"arch_variant"`
79
Colin Crossfa5eb232017-10-01 20:33:03 -070080 // don't build against the default libraries (bootclasspath, legacy-test, core-junit,
Colin Cross7d5136f2015-05-11 13:39:40 -070081 // ext, and framework for device targets)
Colin Cross76b5f0c2017-08-29 16:02:06 -070082 No_standard_libs *bool
Colin Cross7d5136f2015-05-11 13:39:40 -070083
Colin Crossfa5eb232017-10-01 20:33:03 -070084 // don't build against the framework libraries (legacy-test, core-junit,
85 // ext, and framework for device targets)
86 No_framework_libs *bool
87
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +000088 // Use renamed kotlin stdlib (com.android.kotlin.*). This allows kotlin usage without colliding
89 // with app-provided kotlin stdlib.
90 Renamed_kotlin_stdlib *bool
91
Colin Cross7d5136f2015-05-11 13:39:40 -070092 // list of module-specific flags that will be used for javac compiles
93 Javacflags []string `android:"arch_variant"`
94
Colin Cross7d5136f2015-05-11 13:39:40 -070095 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -070096 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070097
98 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -070099 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700100
101 // manifest file to be included in resulting jar
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700102 Manifest *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700103
Colin Cross540eff82017-06-22 17:01:52 -0700104 // if not blank, run jarjar using the specified rules file
Colin Cross975f9f72017-10-17 13:55:55 -0700105 Jarjar_rules *string `android:"arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700106
107 // If not blank, set the java version passed to javac as -source and -target
108 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700109
110 // If set to false, don't allow this module to be installed. Defaults to true.
111 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700112
Colin Cross0f37af02017-09-27 17:42:05 -0700113 // If set to true, include sources used to compile the module in to the final jar
114 Include_srcs *bool
115
Colin Cross32f676a2017-09-06 13:41:06 -0700116 // List of modules to use as annotation processors
117 Annotation_processors []string
118
119 // List of classes to pass to javac to use as annotation processors
120 Annotation_processor_classes []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700121
Nan Zhang61eaedb2017-11-02 13:28:15 -0700122 // The number of Java source entries each Javac instance can process
123 Javac_shard_size *int64
124
Nan Zhang5f8cb422018-02-06 10:34:32 -0800125 // Add host jdk tools.jar to bootclasspath
126 Use_tools_jar *bool
127
Colin Cross1369cdb2017-09-29 17:58:17 -0700128 Openjdk9 struct {
129 // List of source files that should only be used when passing -source 1.9
130 Srcs []string
131
132 // List of javac flags that should only be used when passing -source 1.9
133 Javacflags []string
134 }
Colin Crosscb933592017-11-22 13:49:43 -0800135
136 Jacoco struct {
137 // List of classes to include for instrumentation with jacoco to collect coverage
138 // information at runtime when building with coverage enabled. If unset defaults to all
139 // classes.
140 // Supports '*' as the last character of an entry in the list as a wildcard match.
141 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
142 // it matches classes in the package that have the class name as a prefix.
143 Include_filter []string
144
145 // List of classes to exclude from instrumentation with jacoco to collect coverage
146 // information at runtime when building with coverage enabled. Overrides classes selected
147 // by the include_filter property.
148 // Supports '*' as the last character of an entry in the list as a wildcard match.
149 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
150 // it matches classes in the package that have the class name as a prefix.
151 Exclude_filter []string
152 }
153
Andreas Gampef3e5b552018-01-22 21:27:21 -0800154 Errorprone struct {
155 // List of javac flags that should only be used when running errorprone.
156 Javacflags []string
157 }
158
Colin Cross0f2ee152017-12-14 15:22:43 -0800159 Proto struct {
160 // List of extra options that will be passed to the proto generator.
161 Output_params []string
162 }
163
Colin Crosscb933592017-11-22 13:49:43 -0800164 Instrument bool `blueprint:"mutated"`
Colin Cross540eff82017-06-22 17:01:52 -0700165}
166
Colin Cross89536d42017-07-07 14:35:50 -0700167type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700168 // list of module-specific flags that will be used for dex compiles
169 Dxflags []string `android:"arch_variant"`
170
Colin Cross83bb3162018-06-25 15:48:06 -0700171 // if not blank, set to the version of the sdk to compile against. Defaults to compiling against the current
172 // sdk if platform_apis is not set.
Nan Zhangea568a42017-11-08 21:20:04 -0800173 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700174
Colin Cross83bb3162018-06-25 15:48:06 -0700175 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
176 // Defaults to sdk_version if not set.
177 Min_sdk_version *string
178
Colin Cross6af2e492018-05-22 11:12:33 -0700179 // if true, compile against the platform APIs instead of an SDK.
180 Platform_apis *bool
181
Colin Crossebe1a512017-11-14 13:12:14 -0800182 Aidl struct {
183 // Top level directories to pass to aidl tool
184 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700185
Colin Crossebe1a512017-11-14 13:12:14 -0800186 // Directories rooted at the Android.bp file to pass to aidl tool
187 Local_include_dirs []string
188
189 // directories that should be added as include directories for any aidl sources of modules
190 // that depend on this module, as well as to aidl for this module.
191 Export_include_dirs []string
Martijn Coeneneab15642018-03-09 09:29:59 +0100192
193 // whether to generate traces (for systrace) for this interface
194 Generate_traces *bool
Colin Crossebe1a512017-11-14 13:12:14 -0800195 }
Colin Cross92430102017-10-09 14:59:32 -0700196
197 // If true, export a copy of the module as a -hostdex module for host testing.
198 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700199
David Brazdil17ef5632018-06-27 10:27:45 +0100200 // If set to true, compile dex regardless of installable. Defaults to false.
201 Compile_dex *bool
202
Colin Cross1bd87802017-12-05 15:31:19 -0800203 Dex_preopt struct {
204 // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to
205 // true.
206 Enabled *bool
207
208 // If true, generate an app image (.art file) for this module.
209 App_image *bool
210
211 // If true, use a checked-in profile to guide optimization. Defaults to false unless
212 // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR
213 // that matches the name of this module, in which case it is defaulted to true.
214 Profile_guided *bool
215
216 // If set, provides the path to profile relative to the Android.bp file. If not set,
217 // defaults to searching for a file that matches the name of this module in the default
218 // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found.
219 Profile *string
220 }
Colin Crossa22116e2017-10-19 14:18:58 -0700221
Colin Cross66dbc0b2017-12-28 12:23:20 -0800222 Optimize struct {
Colin Crossae5caf52018-05-22 11:11:52 -0700223 // If false, disable all optimization. Defaults to true for android_app and android_test
224 // modules, false for java_library and java_test modules.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800225 Enabled *bool
226
227 // If true, optimize for size by removing unused code. Defaults to true for apps,
228 // false for libraries and tests.
229 Shrink *bool
230
231 // If true, optimize bytecode. Defaults to false.
232 Optimize *bool
233
234 // If true, obfuscate bytecode. Defaults to false.
235 Obfuscate *bool
236
237 // If true, do not use the flag files generated by aapt that automatically keep
238 // classes referenced by the app manifest. Defaults to false.
239 No_aapt_flags *bool
240
241 // Flags to pass to proguard.
242 Proguard_flags []string
243
244 // Specifies the locations of files containing proguard flags.
245 Proguard_flags_files []string
246 }
247
Colin Cross1369cdb2017-09-29 17:58:17 -0700248 // When targeting 1.9, override the modules to use with --system
249 System_modules *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700250}
251
Colin Cross46c9b8b2017-06-22 16:51:17 -0700252// Module contains the properties and members used by all java module types
253type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700254 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700255 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700256
Colin Cross89536d42017-07-07 14:35:50 -0700257 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700258 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700259 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700260
Nan Zhanged19fc32017-10-19 13:06:22 -0700261 // header jar file suitable for inserting into the bootclasspath/classpath of another compile
262 headerJarFile android.Path
263
264 // full implementation jar file suitable for static dependency of another module compile
265 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700266
Colin Cross6ade34f2017-09-15 13:00:47 -0700267 // output file containing classes.dex
268 dexJarFile android.Path
269
Colin Crosscb933592017-11-22 13:49:43 -0800270 // output file containing uninstrumented classes that will be instrumented by jacoco
271 jacocoReportClassesFile android.Path
272
Colin Cross66dbc0b2017-12-28 12:23:20 -0800273 // output file containing mapping of obfuscated names
274 proguardDictionary android.Path
275
Colin Crossb7a63242015-04-16 14:09:14 -0700276 // output file suitable for installing or running
Colin Cross635c3b02016-05-18 15:37:25 -0700277 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700278
Colin Cross635c3b02016-05-18 15:37:25 -0700279 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700280
Colin Cross635c3b02016-05-18 15:37:25 -0700281 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700282
Colin Cross2fe66872015-03-30 17:20:39 -0700283 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700284 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800285
286 // list of .java files and srcjars that was passed to javac
287 compiledJavaSrcs android.Paths
288 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800289
290 // list of extra progurad flag files
291 extraProguardFlagFiles android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900292
293 // list of SDK lib names that this java moudule is exporting
294 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -0700295}
296
Colin Cross54250902017-12-05 09:28:08 -0800297func (j *Module) Srcs() android.Paths {
298 return android.Paths{j.implementationJarFile}
299}
300
301var _ android.SourceFileProducer = (*Module)(nil)
302
Colin Crossf506d872017-07-19 15:53:04 -0700303type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700304 HeaderJars() android.Paths
305 ImplementationJars() android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700306 AidlIncludeDirs() android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900307 ExportedSdkLibs() []string
Colin Cross2fe66872015-03-30 17:20:39 -0700308}
309
Jiyong Parkc678ad32018-04-10 13:07:10 +0900310type SdkLibraryDependency interface {
311 HeaderJars(linkType linkType) android.Paths
312}
313
Nan Zhangb2b33de2018-02-23 11:18:47 -0800314type SrcDependency interface {
315 CompiledSrcs() android.Paths
316 CompiledSrcJars() android.Paths
317}
318
319func (j *Module) CompiledSrcs() android.Paths {
320 return j.compiledJavaSrcs
321}
322
323func (j *Module) CompiledSrcJars() android.Paths {
324 return j.compiledSrcJars
325}
326
327var _ SrcDependency = (*Module)(nil)
328
Colin Cross89536d42017-07-07 14:35:50 -0700329func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
330 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
331 android.InitDefaultableModule(module)
332}
333
Colin Crossbe1da472017-07-07 15:59:46 -0700334type dependencyTag struct {
335 blueprint.BaseDependencyTag
336 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700337}
338
Colin Crossbe1da472017-07-07 15:59:46 -0700339var (
Colin Cross6ade34f2017-09-15 13:00:47 -0700340 staticLibTag = dependencyTag{name: "staticlib"}
341 libTag = dependencyTag{name: "javalib"}
Colin Cross6a77c982018-06-19 22:43:34 -0700342 annoTag = dependencyTag{name: "annotation processor"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700343 bootClasspathTag = dependencyTag{name: "bootclasspath"}
Colin Cross1369cdb2017-09-29 17:58:17 -0700344 systemModulesTag = dependencyTag{name: "system modules"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700345 frameworkResTag = dependencyTag{name: "framework-res"}
Nan Zhangb2b33de2018-02-23 11:18:47 -0800346 frameworkApkTag = dependencyTag{name: "framework-apk"}
Colin Cross93e85952017-08-15 13:34:18 -0700347 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Cross66dbc0b2017-12-28 12:23:20 -0800348 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
Colin Crossbe1da472017-07-07 15:59:46 -0700349)
Colin Cross2fe66872015-03-30 17:20:39 -0700350
Colin Crossfc3674a2017-09-18 17:41:52 -0700351type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700352 useModule, useFiles, useDefaultLibs, invalidVersion bool
353
Colin Cross86a60ae2018-05-29 14:44:55 -0700354 modules []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700355 systemModules string
356
Colin Crossa97c5d32018-03-28 14:58:31 -0700357 frameworkResModule string
358
Colin Cross86a60ae2018-05-29 14:44:55 -0700359 jars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700360 aidl android.Path
361}
362
Colin Cross3144dfc2018-01-03 15:06:47 -0800363func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
364 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
365}
366
367func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
368 return j.shouldInstrument(ctx) &&
369 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
370 ctx.Config().UnbundledBuild())
371}
372
Colin Cross83bb3162018-06-25 15:48:06 -0700373func (j *Module) sdkVersion() string {
374 return String(j.deviceProperties.Sdk_version)
375}
376
377func (j *Module) minSdkVersion() string {
378 if j.deviceProperties.Min_sdk_version != nil {
379 return *j.deviceProperties.Min_sdk_version
380 }
381 return j.sdkVersion()
382}
383
384type sdkContext interface {
385 // sdkVersion eturns the sdk_version property of the current module, or an empty string if it is not set.
386 sdkVersion() string
387 // minSdkVersion returns the min_sdk_version property of the current module, or sdkVersion() if it is not set.
388 minSdkVersion() string
389}
390
391func sdkVersionOrDefault(ctx android.BaseContext, v string) string {
392 switch v {
393 case "", "current", "system_current", "test_current", "core_current":
394 return ctx.Config().DefaultAppTargetSdk()
395 default:
396 return v
397 }
398}
399
400// Returns a sdk version as a number. For modules targeting an unreleased SDK (meaning it does not yet have a number)
401// it returns android.FutureApiLevel (10000).
402func sdkVersionToNumber(ctx android.BaseContext, v string) (int, error) {
403 switch v {
404 case "", "current", "test_current", "system_current", "core_current":
405 return ctx.Config().DefaultAppTargetSdkInt(), nil
406 default:
407 n := android.GetNumericSdkVersion(v)
408 if i, err := strconv.Atoi(n); err != nil {
409 return -1, fmt.Errorf("invalid sdk version %q", n)
410 } else {
411 return i, nil
412 }
413 }
414}
415
416func sdkVersionToNumberAsString(ctx android.BaseContext, v string) (string, error) {
417 n, err := sdkVersionToNumber(ctx, v)
418 if err != nil {
419 return "", err
420 }
421 return strconv.Itoa(n), nil
422}
423
424func decodeSdkDep(ctx android.BaseContext, sdkContext sdkContext) sdkDep {
425 v := sdkContext.sdkVersion()
426 i, err := sdkVersionToNumber(ctx, v)
427 if err != nil {
428 ctx.PropertyErrorf("sdk_version", "%s", err)
Colin Cross1369cdb2017-09-29 17:58:17 -0700429 return sdkDep{}
Colin Crossfc3674a2017-09-18 17:41:52 -0700430 }
431
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900432 // Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks)
433 // or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set)
434 if strings.HasPrefix(v, "system_") && i != android.FutureApiLevel {
435 allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions()
436 if ctx.DeviceSpecific() || ctx.SocSpecific() {
437 if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 {
438 allowed_versions = ctx.DeviceConfig().SystemSdkVersions()
439 }
440 }
441 version := strings.TrimPrefix(v, "system_")
442 if len(allowed_versions) > 0 && !android.InList(version, allowed_versions) {
443 ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q",
444 v, allowed_versions)
445 }
446 }
447
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100448 toPrebuilt := func(sdk string) sdkDep {
449 var api, v string
450 if strings.Contains(sdk, "_") {
451 t := strings.Split(sdk, "_")
452 api = t[0]
453 v = t[1]
454 } else {
455 api = "public"
456 v = sdk
Jiyong Park750e5572018-01-31 00:20:13 +0900457 }
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100458 dir := filepath.Join("prebuilts", "sdk", v, api)
Colin Crossfc3674a2017-09-18 17:41:52 -0700459 jar := filepath.Join(dir, "android.jar")
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100460 // There's no aidl for other SDKs yet.
461 // TODO(77525052): Add aidl files for other SDKs too.
462 public_dir := filepath.Join("prebuilts", "sdk", v, "public")
463 aidl := filepath.Join(public_dir, "framework.aidl")
Colin Cross32f38982018-02-22 11:47:25 -0800464 jarPath := android.ExistentPathForSource(ctx, jar)
465 aidlPath := android.ExistentPathForSource(ctx, aidl)
Colin Cross86a60ae2018-05-29 14:44:55 -0700466 lambdaStubsPath := android.PathForSource(ctx, config.SdkLambdaStubsPath)
Colin Cross47ff2522017-10-02 14:22:08 -0700467
Colin Cross6510f912017-11-29 00:27:14 -0800468 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
Colin Cross47ff2522017-10-02 14:22:08 -0700469 return sdkDep{
470 invalidVersion: true,
Colin Cross86a60ae2018-05-29 14:44:55 -0700471 modules: []string{fmt.Sprintf("sdk_%s_%s_android", api, v)},
Colin Cross47ff2522017-10-02 14:22:08 -0700472 }
473 }
474
Colin Crossfc3674a2017-09-18 17:41:52 -0700475 if !jarPath.Valid() {
476 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar)
477 return sdkDep{}
478 }
Colin Cross47ff2522017-10-02 14:22:08 -0700479
Colin Crossfc3674a2017-09-18 17:41:52 -0700480 if !aidlPath.Valid() {
481 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl)
482 return sdkDep{}
483 }
Colin Cross47ff2522017-10-02 14:22:08 -0700484
Colin Crossfc3674a2017-09-18 17:41:52 -0700485 return sdkDep{
486 useFiles: true,
Colin Cross86a60ae2018-05-29 14:44:55 -0700487 jars: android.Paths{jarPath.Path(), lambdaStubsPath},
Colin Crossfc3674a2017-09-18 17:41:52 -0700488 aidl: aidlPath.Path(),
489 }
490 }
491
Colin Crossa97c5d32018-03-28 14:58:31 -0700492 toModule := func(m, r string) sdkDep {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700493 ret := sdkDep{
Colin Crossa97c5d32018-03-28 14:58:31 -0700494 useModule: true,
Colin Cross86a60ae2018-05-29 14:44:55 -0700495 modules: []string{m, config.DefaultLambdaStubsLibrary},
Colin Crossa97c5d32018-03-28 14:58:31 -0700496 systemModules: m + "_system_modules",
497 frameworkResModule: r,
Colin Crossf19b9bb2018-03-26 14:42:44 -0700498 }
499 if m == "core.current.stubs" {
500 ret.systemModules = "core-system-modules"
501 }
502 return ret
503 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700504
Colin Cross6510f912017-11-29 00:27:14 -0800505 if ctx.Config().UnbundledBuild() && v != "" {
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100506 return toPrebuilt(v)
Colin Crossfc3674a2017-09-18 17:41:52 -0700507 }
508
509 switch v {
510 case "":
511 return sdkDep{
Colin Crossa97c5d32018-03-28 14:58:31 -0700512 useDefaultLibs: true,
513 frameworkResModule: "framework-res",
Colin Crossfc3674a2017-09-18 17:41:52 -0700514 }
Colin Crossf19b9bb2018-03-26 14:42:44 -0700515 case "current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700516 return toModule("android_stubs_current", "framework-res")
Colin Crossf19b9bb2018-03-26 14:42:44 -0700517 case "system_current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700518 return toModule("android_system_stubs_current", "framework-res")
Colin Crossf19b9bb2018-03-26 14:42:44 -0700519 case "test_current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700520 return toModule("android_test_stubs_current", "framework-res")
Colin Crossf19b9bb2018-03-26 14:42:44 -0700521 case "core_current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700522 return toModule("core.current.stubs", "")
Colin Crossfc3674a2017-09-18 17:41:52 -0700523 default:
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100524 return toPrebuilt(v)
Colin Crossfc3674a2017-09-18 17:41:52 -0700525 }
526}
527
Colin Crossbe1da472017-07-07 15:59:46 -0700528func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700529 if ctx.Device() {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700530 if !Bool(j.properties.No_standard_libs) {
Colin Cross83bb3162018-06-25 15:48:06 -0700531 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Crossfc3674a2017-09-18 17:41:52 -0700532 if sdkDep.useDefaultLibs {
Colin Crosscb2c9292017-09-23 19:57:16 -0700533 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Colin Cross6510f912017-11-29 00:27:14 -0800534 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700535 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
536 }
Colin Crossff3ae9d2018-04-10 16:15:18 -0700537 if !Bool(j.properties.No_framework_libs) {
Colin Crossfa5eb232017-10-01 20:33:03 -0700538 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
539 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700540 } else if sdkDep.useModule {
Colin Cross6510f912017-11-29 00:27:14 -0800541 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700542 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
543 }
Colin Cross86a60ae2018-05-29 14:44:55 -0700544 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800545 if Bool(j.deviceProperties.Optimize.Enabled) {
546 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultBootclasspathLibraries...)
547 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultLibraries...)
548 }
Colin Crossbe1da472017-07-07 15:59:46 -0700549 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700550 } else if j.deviceProperties.System_modules == nil {
551 ctx.PropertyErrorf("no_standard_libs",
552 "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 -0800553 } else if *j.deviceProperties.System_modules != "none" && ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700554 ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700555 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800556 if ctx.ModuleName() == "framework" {
557 ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res")
558 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800559 if ctx.ModuleName() == "android_stubs_current" ||
560 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang16c0a312018-06-13 17:42:48 -0700561 ctx.ModuleName() == "android_test_stubs_current" ||
562 ctx.ModuleName() == "metalava_android_stubs_current" ||
563 ctx.ModuleName() == "metalava_android_system_stubs_current" ||
564 ctx.ModuleName() == "metalava_android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800565 ctx.AddDependency(ctx.Module(), frameworkApkTag, "framework-res")
566 }
Colin Cross2fe66872015-03-30 17:20:39 -0700567 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700568
Colin Crossf506d872017-07-19 15:53:04 -0700569 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
570 ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
Mathew Inwood878c6622018-07-02 16:34:51 +0100571 ctx.AddFarVariationDependencies([]blueprint.Variation{
572 {"arch", ctx.Config().BuildOsCommonVariant},
573 }, annoTag, j.properties.Annotation_processors...)
Colin Cross7f9036c2017-08-30 13:27:57 -0700574 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Nan Zhang27e284d2018-02-09 21:03:53 +0000575 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700576 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross366938f2017-12-11 16:29:02 -0800577 android.ExtractSourceDeps(ctx, j.properties.Manifest)
Colin Cross6af17aa2017-09-20 12:59:05 -0700578
579 if j.hasSrcExt(".proto") {
580 protoDeps(ctx, &j.protoProperties)
581 }
Colin Cross93e85952017-08-15 13:34:18 -0700582
583 if j.hasSrcExt(".kt") {
584 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
585 // Kotlin files
586 ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib")
587 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800588
589 if j.shouldInstrumentStatic(ctx) {
590 ctx.AddDependency(ctx.Module(), staticLibTag, "jacocoagent")
591 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700592}
593
594func hasSrcExt(srcs []string, ext string) bool {
595 for _, src := range srcs {
596 if filepath.Ext(src) == ext {
597 return true
598 }
599 }
600
601 return false
602}
603
Nan Zhang61eaedb2017-11-02 13:28:15 -0700604func shardPaths(paths android.Paths, shardSize int) []android.Paths {
605 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
606 for len(paths) > shardSize {
607 ret = append(ret, paths[0:shardSize])
608 paths = paths[shardSize:]
609 }
610 if len(paths) > 0 {
611 ret = append(ret, paths)
612 }
613 return ret
614}
615
Colin Cross6af17aa2017-09-20 12:59:05 -0700616func (j *Module) hasSrcExt(ext string) bool {
617 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700618}
619
Colin Cross46c9b8b2017-06-22 16:51:17 -0700620func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700621 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700622
Colin Crossebe1a512017-11-14 13:12:14 -0800623 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
624 aidlIncludes = append(aidlIncludes,
625 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
626 aidlIncludes = append(aidlIncludes,
627 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700628
629 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700630 if aidlPreprocess.Valid() {
631 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700632 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700633 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700634 }
635
Colin Cross635c3b02016-05-18 15:37:25 -0700636 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800637 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700638 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800639 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700640 flags = append(flags, "-I"+src.String())
641 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700642
Martijn Coeneneab15642018-03-09 09:29:59 +0100643 if Bool(j.deviceProperties.Aidl.Generate_traces) {
644 flags = append(flags, "-t")
645 }
646
Colin Crossf03c82b2015-04-13 13:53:40 -0700647 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700648}
649
Colin Cross32f676a2017-09-06 13:41:06 -0700650type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800651 classpath classpath
652 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700653 processorPath classpath
Colin Cross6ade34f2017-09-15 13:00:47 -0700654 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700655 staticHeaderJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700656 staticJarResources android.Paths
657 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800658 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700659 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700660 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700661 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700662 kotlinStdlib android.Paths
Colin Cross32f676a2017-09-06 13:41:06 -0700663}
Colin Cross2fe66872015-03-30 17:20:39 -0700664
Colin Cross54250902017-12-05 09:28:08 -0800665func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
666 for _, f := range dep.Srcs() {
667 if f.Ext() != ".jar" {
668 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
669 ctx.OtherModuleName(dep.(blueprint.Module)))
670 }
671 }
672}
673
Jiyong Park2d492942018-03-05 17:44:10 +0900674type linkType int
675
676const (
677 javaCore linkType = iota
678 javaSdk
679 javaSystem
680 javaPlatform
681)
682
Colin Crossf19b9bb2018-03-26 14:42:44 -0700683func getLinkType(m *Module, name string) linkType {
Colin Cross83bb3162018-06-25 15:48:06 -0700684 ver := m.sdkVersion()
Colin Cross86a60ae2018-05-29 14:44:55 -0700685 noStdLibs := Bool(m.properties.No_standard_libs)
Colin Crossf19b9bb2018-03-26 14:42:44 -0700686 switch {
Nan Zhang16c0a312018-06-13 17:42:48 -0700687 case name == "core.current.stubs" || ver == "core_current" || noStdLibs || name == "stub-annotations":
Jiyong Park2d492942018-03-05 17:44:10 +0900688 return javaCore
Nan Zhang16c0a312018-06-13 17:42:48 -0700689 case name == "android_system_stubs_current" || strings.HasPrefix(ver, "system_") || name == "metalava_android_system_stubs_current":
Jiyong Park2d492942018-03-05 17:44:10 +0900690 return javaSystem
Nan Zhang16c0a312018-06-13 17:42:48 -0700691 case name == "android_test_stubs_current" || strings.HasPrefix(ver, "test_") || name == "metalava_android_test_stubs_current":
Jiyong Park2d492942018-03-05 17:44:10 +0900692 return javaPlatform
Nan Zhang16c0a312018-06-13 17:42:48 -0700693 case name == "android_stubs_current" || ver == "current" || name == "metalava_android_stubs_current":
Colin Crossf19b9bb2018-03-26 14:42:44 -0700694 return javaSdk
695 case ver == "":
696 return javaPlatform
697 default:
698 if _, err := strconv.Atoi(ver); err != nil {
699 panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver))
700 }
701 return javaSdk
Jiyong Park2d492942018-03-05 17:44:10 +0900702 }
703}
704
Jiyong Park750e5572018-01-31 00:20:13 +0900705func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700706 if ctx.Host() {
707 return
708 }
709
710 myLinkType := getLinkType(from, ctx.ModuleName())
711 otherLinkType := getLinkType(&to.Module, ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900712 commonMessage := "Adjust sdk_version: property of the source or target module so that target module is built with the same or smaller API set than the source."
713
714 switch myLinkType {
715 case javaCore:
716 if otherLinkType != javaCore {
717 ctx.ModuleErrorf("compiles against core Java API, but dependency %q is compiling against non-core Java APIs."+commonMessage,
Jiyong Park750e5572018-01-31 00:20:13 +0900718 ctx.OtherModuleName(to))
719 }
Jiyong Park2d492942018-03-05 17:44:10 +0900720 break
721 case javaSdk:
722 if otherLinkType != javaCore && otherLinkType != javaSdk {
723 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
724 ctx.OtherModuleName(to))
725 }
726 break
727 case javaSystem:
728 if otherLinkType == javaPlatform {
729 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
730 ctx.OtherModuleName(to))
731 }
732 break
733 case javaPlatform:
734 // no restriction on link-type
735 break
Jiyong Park750e5572018-01-31 00:20:13 +0900736 }
737}
738
Colin Cross32f676a2017-09-06 13:41:06 -0700739func (j *Module) collectDeps(ctx android.ModuleContext) deps {
740 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700741
Colin Cross300f0382018-03-06 13:11:51 -0800742 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700743 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800744 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700745 ctx.AddMissingDependencies(sdkDep.modules)
Colin Cross300f0382018-03-06 13:11:51 -0800746 } else if sdkDep.useFiles {
747 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700748 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross300f0382018-03-06 13:11:51 -0800749 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
750 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700751 }
752
Colin Crossd11fcda2017-10-23 17:59:01 -0700753 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700754 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700755 tag := ctx.OtherModuleDependencyTag(module)
756
Jiyong Park750e5572018-01-31 00:20:13 +0900757 if to, ok := module.(*Library); ok {
Colin Crossa97c5d32018-03-28 14:58:31 -0700758 switch tag {
759 case bootClasspathTag, libTag, staticLibTag:
760 checkLinkType(ctx, j, to, tag.(dependencyTag))
761 }
Jiyong Park750e5572018-01-31 00:20:13 +0900762 }
Colin Cross54250902017-12-05 09:28:08 -0800763 switch dep := module.(type) {
764 case Dependency:
765 switch tag {
766 case bootClasspathTag:
767 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
768 case libTag:
769 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900770 // sdk lib names from dependencies are re-exported
771 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross54250902017-12-05 09:28:08 -0800772 case staticLibTag:
773 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
774 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
775 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900776 // sdk lib names from dependencies are re-exported
777 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross6a77c982018-06-19 22:43:34 -0700778 case annoTag:
779 deps.processorPath = append(deps.processorPath, dep.ImplementationJars()...)
Colin Cross54250902017-12-05 09:28:08 -0800780 case frameworkResTag:
781 if ctx.ModuleName() == "framework" {
782 // framework.jar has a one-off dependency on the R.java and Manifest.java files
783 // generated by framework-res.apk
784 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
785 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800786 case frameworkApkTag:
787 if ctx.ModuleName() == "android_stubs_current" ||
788 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang16c0a312018-06-13 17:42:48 -0700789 ctx.ModuleName() == "android_test_stubs_current" ||
790 ctx.ModuleName() == "metalava_android_stubs_current" ||
791 ctx.ModuleName() == "metalava_android_system_stubs_current" ||
792 ctx.ModuleName() == "metalava_android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800793 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
794 // resource files out of there for aapt.
795 //
796 // Normally the package rule runs aapt, which includes the resource,
797 // but we're not running that in our package rule so just copy in the
798 // resource files here.
799 deps.staticJarResources = append(deps.staticJarResources, dep.(*AndroidApp).exportPackage)
800 }
Colin Cross54250902017-12-05 09:28:08 -0800801 case kotlinStdlibTag:
802 deps.kotlinStdlib = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -0800803 }
804
805 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900806 case SdkLibraryDependency:
807 switch tag {
808 case libTag:
809 deps.classpath = append(deps.classpath, dep.HeaderJars(getLinkType(j, ctx.ModuleName()))...)
Jiyong Park1be96912018-05-28 18:02:19 +0900810 // names of sdk libs that are directly depended are exported
811 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900812 default:
813 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
814 }
Colin Cross54250902017-12-05 09:28:08 -0800815 case android.SourceFileProducer:
816 switch tag {
817 case libTag:
818 checkProducesJars(ctx, dep)
819 deps.classpath = append(deps.classpath, dep.Srcs()...)
820 case staticLibTag:
821 checkProducesJars(ctx, dep)
822 deps.classpath = append(deps.classpath, dep.Srcs()...)
823 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
824 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
825 case android.DefaultsDepTag, android.SourceDepTag:
826 // Nothing to do
827 default:
828 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
829 }
830 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700831 switch tag {
832 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700833 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700834 case systemModulesTag:
835 if deps.systemModules != nil {
836 panic("Found two system module dependencies")
837 }
838 sm := module.(*SystemModules)
839 if sm.outputFile == nil {
840 panic("Missing directory for system module dependency")
841 }
842 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700843 default:
844 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700845 }
Colin Crossec7a0422017-07-07 14:47:12 -0700846 }
Colin Cross2fe66872015-03-30 17:20:39 -0700847 })
848
Jiyong Park1be96912018-05-28 18:02:19 +0900849 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
850
Colin Cross32f676a2017-09-06 13:41:06 -0700851 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700852}
853
Colin Cross83bb3162018-06-25 15:48:06 -0700854func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string {
Nan Zhang357466b2018-04-17 17:38:36 -0700855 var ret string
Colin Cross83bb3162018-06-25 15:48:06 -0700856 sdk, err := sdkVersionToNumber(ctx, sdkContext.sdkVersion())
857 if err != nil {
858 ctx.PropertyErrorf("sdk_version", "%s", err)
859 }
Nan Zhang357466b2018-04-17 17:38:36 -0700860 if javaVersion != "" {
861 ret = javaVersion
862 } else if ctx.Device() && sdk <= 23 {
863 ret = "1.7"
864 } else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
865 ret = "1.8"
Colin Cross83bb3162018-06-25 15:48:06 -0700866 } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel {
Nan Zhang357466b2018-04-17 17:38:36 -0700867 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
868 ret = "1.8"
869 } else {
870 ret = "1.9"
871 }
872
873 return ret
874}
875
Nan Zhanged19fc32017-10-19 13:06:22 -0700876func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700877
Colin Crossf03c82b2015-04-13 13:53:40 -0700878 var flags javaBuilderFlags
879
Nan Zhanged19fc32017-10-19 13:06:22 -0700880 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700881 javacFlags := j.properties.Javacflags
Colin Cross6510f912017-11-29 00:27:14 -0800882 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700883 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700884 }
Colin Cross6510f912017-11-29 00:27:14 -0800885 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700886 // Override the -g flag passed globally to remove local variable debug info to reduce
887 // disk and memory usage.
888 javacFlags = append(javacFlags, "-g:source,lines")
889 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700890 if len(javacFlags) > 0 {
891 // optimization.
892 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
893 flags.javacFlags = "$javacFlags"
Colin Cross4f26bc02017-09-06 12:52:16 -0700894 }
Colin Cross64162712017-08-08 13:17:59 -0700895
Colin Cross66548102018-06-19 22:47:35 -0700896 if ctx.Config().RunErrorProne() {
897 if config.ErrorProneClasspath == nil {
898 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
899 }
900
901 errorProneFlags := []string{
902 "-Xplugin:ErrorProne",
903 "${config.ErrorProneChecks}",
904 }
905 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
906
907 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
908 "'" + strings.Join(errorProneFlags, " ") + "'"
909 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -0800910 }
911
Nan Zhanged19fc32017-10-19 13:06:22 -0700912 // javaVersion flag.
Colin Cross83bb3162018-06-25 15:48:06 -0700913 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross64162712017-08-08 13:17:59 -0700914
Nan Zhanged19fc32017-10-19 13:06:22 -0700915 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800916 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
917 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -0700918 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800919
920 if len(flags.bootClasspath) == 0 && ctx.Host() && !ctx.Config().TargetOpenJDK9() &&
921 !Bool(j.properties.No_standard_libs) &&
922 inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
923 // Give host-side tools a version of OpenJDK's standard libraries
924 // close to what they're targeting. As of Dec 2017, AOSP is only
925 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
926 //
927 // When building with OpenJDK 8, the following should have no
928 // effect since those jars would be available by default.
929 //
930 // When building with OpenJDK 9 but targeting a version < 1.8,
931 // putting them on the bootclasspath means that:
932 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
933 // b) references to existing APIs are not reinterpreted in an
934 // OpenJDK 9-specific way, eg. calls to subclasses of
935 // java.nio.Buffer as in http://b/70862583
936 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
937 flags.bootClasspath = append(flags.bootClasspath,
938 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
939 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -0800940 if Bool(j.properties.Use_tools_jar) {
941 flags.bootClasspath = append(flags.bootClasspath,
942 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
943 }
Colin Cross7fdd2b72018-01-02 18:14:25 -0800944 }
945
Nan Zhanged19fc32017-10-19 13:06:22 -0700946 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700947 if deps.systemModules != nil {
948 flags.systemModules = append(flags.systemModules, deps.systemModules)
949 }
950
Nan Zhanged19fc32017-10-19 13:06:22 -0700951 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700952 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700953 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700954 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700955 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
956 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700957 }
958
Nan Zhanged19fc32017-10-19 13:06:22 -0700959 return flags
960}
Colin Crossc0b06f12015-04-08 13:03:43 -0700961
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800962func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700963
Colin Crossebe1a512017-11-14 13:12:14 -0800964 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700965
966 deps := j.collectDeps(ctx)
967 flags := j.collectBuilderFlags(ctx, deps)
968
Colin Cross6510f912017-11-29 00:27:14 -0800969 if ctx.Config().TargetOpenJDK9() {
Nan Zhanged19fc32017-10-19 13:06:22 -0700970 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
971 }
972 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700973 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -0800974 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700975 }
976
Colin Crossaf050172017-11-15 23:01:59 -0800977 srcFiles = j.genSources(ctx, srcFiles, flags)
978
979 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700980 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800981 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700982
Colin Cross0a6e0072017-08-30 14:24:55 -0700983 var jars android.Paths
984
Colin Cross1ee23172017-10-18 14:44:18 -0700985 jarName := ctx.ModuleName() + ".jar"
986
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000987 javaSrcFiles := srcFiles.FilterByExt(".java")
988 var uniqueSrcFiles android.Paths
989 set := make(map[string]bool)
990 for _, v := range javaSrcFiles {
991 if _, found := set[v.String()]; !found {
992 set[v.String()] = true
993 uniqueSrcFiles = append(uniqueSrcFiles, v)
994 }
995 }
996
Colin Cross93e85952017-08-15 13:34:18 -0700997 if srcFiles.HasExt(".kt") {
998 // If there are kotlin files, compile them first but pass all the kotlin and java files
999 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1000 // won't emit any classes for them.
1001
1002 flags.kotlincFlags = "-no-stdlib"
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001003
Colin Cross93e85952017-08-15 13:34:18 -07001004 if ctx.Device() {
1005 flags.kotlincFlags += " -no-jdk"
1006 }
1007
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001008 var kotlinSrcFiles android.Paths
1009 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1010 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1011
Przemyslaw Szczepaniake3d26bf2018-03-05 16:06:42 +00001012 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.bootClasspath...)
Colin Cross93e85952017-08-15 13:34:18 -07001013 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
1014 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
1015
Colin Cross1ee23172017-10-18 14:44:18 -07001016 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001017 TransformKotlinToClasses(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001018 if ctx.Failed() {
1019 return
1020 }
1021
1022 // Make javac rule depend on the kotlinc rule
Colin Cross49da2752018-06-05 17:22:57 -07001023 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001024 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001025
Colin Cross93e85952017-08-15 13:34:18 -07001026 // Jar kotlin classes into the final jar after javac
1027 jars = append(jars, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001028
1029 // Don't add kotlin-stdlib if using (on-device) renamed stdlib
1030 // (it's expected to be on device bootclasspath)
Colin Crossff3ae9d2018-04-10 16:15:18 -07001031 if !Bool(j.properties.Renamed_kotlin_stdlib) {
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001032 jars = append(jars, deps.kotlinStdlib...)
1033 }
Colin Cross93e85952017-08-15 13:34:18 -07001034 }
1035
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001036 // Store the list of .java files that was passed to javac
1037 j.compiledJavaSrcs = uniqueSrcFiles
1038 j.compiledSrcJars = srcJars
1039
Nan Zhang61eaedb2017-11-02 13:28:15 -07001040 enable_sharding := false
Colin Cross6510f912017-11-29 00:27:14 -08001041 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001042 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1043 enable_sharding = true
1044 if len(j.properties.Annotation_processors) != 0 ||
1045 len(j.properties.Annotation_processor_classes) != 0 {
1046 ctx.PropertyErrorf("javac_shard_size",
1047 "%q cannot be set when annotation processors are enabled.",
1048 j.properties.Javac_shard_size)
1049 }
1050 }
Colin Crossf19b9bb2018-03-26 14:42:44 -07001051 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName)
1052 if ctx.Failed() {
1053 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001054 }
1055 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001056 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001057 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001058 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001059 // If error-prone is enabled, add an additional rule to compile the java files into
1060 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001061 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001062 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1063 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001064 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001065 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001066 extraJarDeps = append(extraJarDeps, errorprone)
1067 }
1068
Nan Zhang61eaedb2017-11-02 13:28:15 -07001069 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001070 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001071 shardSize := int(*(j.properties.Javac_shard_size))
1072 var shardSrcs []android.Paths
1073 if len(uniqueSrcFiles) > 0 {
1074 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
1075 for idx, shardSrc := range shardSrcs {
1076 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
1077 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
1078 jars = append(jars, classes)
1079 }
1080 }
1081 if len(srcJars) > 0 {
1082 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
1083 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
1084 jars = append(jars, classes)
1085 }
1086 } else {
1087 classes := android.PathForModuleOut(ctx, "javac", jarName)
1088 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
1089 jars = append(jars, classes)
1090 }
Colin Crossd6891432017-09-27 17:39:56 -07001091 if ctx.Failed() {
1092 return
1093 }
Colin Cross2fe66872015-03-30 17:20:39 -07001094 }
1095
Colin Cross0f37af02017-09-27 17:42:05 -07001096 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
1097 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
1098
1099 var resArgs []string
1100 var resDeps android.Paths
1101
1102 resArgs = append(resArgs, dirArgs...)
1103 resDeps = append(resDeps, dirDeps...)
1104
1105 resArgs = append(resArgs, fileArgs...)
1106 resDeps = append(resDeps, fileDeps...)
1107
Colin Crossff3ae9d2018-04-10 16:15:18 -07001108 if Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -07001109 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -07001110 resArgs = append(resArgs, srcArgs...)
1111 resDeps = append(resDeps, srcDeps...)
1112 }
Colin Cross40a36712017-09-27 17:41:35 -07001113
1114 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001115 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001116 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -07001117 if ctx.Failed() {
1118 return
1119 }
Colin Cross20978302015-04-10 17:05:07 -07001120
Colin Cross0a6e0072017-08-30 14:24:55 -07001121 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -07001122 }
1123
Colin Cross6ade34f2017-09-15 13:00:47 -07001124 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -07001125 jars = append(jars, deps.staticJars...)
Nan Zhangb2b33de2018-02-23 11:18:47 -08001126 jars = append(jars, deps.staticJarResources...)
Colin Cross0a6e0072017-08-30 14:24:55 -07001127
Colin Cross366938f2017-12-11 16:29:02 -08001128 var manifest android.OptionalPath
1129 if j.properties.Manifest != nil {
1130 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
1131 }
Colin Cross635acc92017-09-12 22:50:46 -07001132
Colin Cross0a6e0072017-08-30 14:24:55 -07001133 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001134 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -07001135 var outputFile android.Path
1136
1137 if len(jars) == 1 && !manifest.Valid() {
1138 // Optimization: skip the combine step if there is nothing to do
Colin Cross7b60cdd2017-12-21 13:52:58 -08001139 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1140 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1141 // any if len(jars) == 1.
Colin Crosse9a275b2017-10-16 17:09:48 -07001142 outputFile = jars[0]
1143 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001144 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Nan Zhanged19fc32017-10-19 13:06:22 -07001145 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001146 outputFile = combinedJar
1147 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001148
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001149 // Use renamed kotlin standard library?
Colin Crossff3ae9d2018-04-10 16:15:18 -07001150 if srcFiles.HasExt(".kt") && Bool(j.properties.Renamed_kotlin_stdlib) {
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001151 jarjarFile := android.PathForModuleOut(ctx, "kotlin-renamed", jarName)
1152 TransformJarJar(ctx, jarjarFile, outputFile,
1153 android.PathForSource(ctx, "external/kotlinc/jarjar-rules.txt"))
1154 outputFile = jarjarFile
1155 if ctx.Failed() {
1156 return
1157 }
1158 }
1159
Colin Cross0a6e0072017-08-30 14:24:55 -07001160 if j.properties.Jarjar_rules != nil {
1161 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -07001162 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001163 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001164 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
1165 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -07001166 if ctx.Failed() {
1167 return
1168 }
1169 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001170 j.implementationJarFile = outputFile
1171 if j.headerJarFile == nil {
1172 j.headerJarFile = j.implementationJarFile
1173 }
Colin Cross2fe66872015-03-30 17:20:39 -07001174
Colin Cross6510f912017-11-29 00:27:14 -08001175 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -08001176 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
1177 j.properties.Instrument = true
1178 }
1179 }
1180
Colin Cross3144dfc2018-01-03 15:06:47 -08001181 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001182 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1183 }
1184
David Brazdil17ef5632018-06-27 10:27:45 +01001185 if ctx.Device() && j.createDexRule() {
1186 var dexOutputFile android.Path
1187 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001188 if ctx.Failed() {
1189 return
1190 }
David Brazdil17ef5632018-06-27 10:27:45 +01001191 if j.installable() {
1192 outputFile = dexOutputFile
1193 }
Colin Cross2fe66872015-03-30 17:20:39 -07001194 }
Colin Crossb7a63242015-04-16 14:09:14 -07001195 ctx.CheckbuildFile(outputFile)
1196 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -07001197}
1198
Colin Cross8eadbf02017-10-24 17:46:00 -07001199func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Nan Zhanged19fc32017-10-19 13:06:22 -07001200 deps deps, flags javaBuilderFlags, jarName string) android.Path {
1201
1202 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001203 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001204 // Compile java sources into turbine.jar.
1205 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1206 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1207 if ctx.Failed() {
1208 return nil
1209 }
1210 jars = append(jars, turbineJar)
1211 }
1212
1213 // Combine any static header libraries into classes-header.jar. If there is only
1214 // one input jar this step will be skipped.
1215 var headerJar android.Path
1216 jars = append(jars, deps.staticHeaderJars...)
1217
Colin Cross5c6ecc12017-10-23 18:12:27 -07001218 // we cannot skip the combine step for now if there is only one jar
1219 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1220 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
1221 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, false, []string{"META-INF"})
1222 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001223
1224 if j.properties.Jarjar_rules != nil {
1225 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
1226 // Transform classes.jar into classes-jarjar.jar
1227 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
1228 TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules)
1229 headerJar = jarjarFile
1230 if ctx.Failed() {
1231 return nil
1232 }
1233 }
1234
1235 return headerJar
1236}
1237
Colin Crosscb933592017-11-22 13:49:43 -08001238func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
1239 classesJar android.Path, jarName string) android.Path {
1240
Colin Cross7a3139e2017-12-19 13:57:50 -08001241 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001242
Colin Cross84c38822018-01-03 15:59:46 -08001243 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001244 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1245
1246 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1247
1248 j.jacocoReportClassesFile = jacocoReportClassesFile
1249
1250 return instrumentedJar
1251}
1252
Colin Cross59f1bb62017-09-27 17:59:10 -07001253func (j *Module) installable() bool {
Colin Cross38b40df2018-04-10 16:14:46 -07001254 return BoolDefault(j.properties.Installable, true)
Colin Cross59f1bb62017-09-27 17:59:10 -07001255}
1256
David Brazdil17ef5632018-06-27 10:27:45 +01001257func (j *Module) createDexRule() bool {
1258 return Bool(j.deviceProperties.Compile_dex) || j.installable()
1259}
1260
Colin Crossf506d872017-07-19 15:53:04 -07001261var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001262
Nan Zhanged19fc32017-10-19 13:06:22 -07001263func (j *Module) HeaderJars() android.Paths {
1264 return android.Paths{j.headerJarFile}
1265}
1266
1267func (j *Module) ImplementationJars() android.Paths {
1268 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001269}
1270
Colin Cross46c9b8b2017-06-22 16:51:17 -07001271func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001272 return j.exportAidlIncludeDirs
1273}
1274
Jiyong Park1be96912018-05-28 18:02:19 +09001275func (j *Module) ExportedSdkLibs() []string {
1276 return j.exportedSdkLibs
1277}
1278
Colin Cross46c9b8b2017-06-22 16:51:17 -07001279var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001280
Colin Cross46c9b8b2017-06-22 16:51:17 -07001281func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001282 return j.logtagsSrcs
1283}
1284
Colin Cross2fe66872015-03-30 17:20:39 -07001285//
1286// Java libraries (.jar file)
1287//
1288
Colin Crossf506d872017-07-19 15:53:04 -07001289type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001290 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001291}
1292
Colin Crossf506d872017-07-19 15:53:04 -07001293func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001294 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001295
Colin Cross59f1bb62017-09-27 17:59:10 -07001296 if j.installable() {
Colin Cross2c429dc2017-08-31 16:45:16 -07001297 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1298 ctx.ModuleName()+".jar", j.outputFile)
1299 }
Colin Crossb7a63242015-04-16 14:09:14 -07001300}
1301
Colin Crossf506d872017-07-19 15:53:04 -07001302func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001303 j.deps(ctx)
1304}
1305
Colin Crossa60ead82017-10-02 18:10:21 -07001306func LibraryFactory(installable bool) func() android.Module {
1307 return func() android.Module {
1308 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001309
Colin Crossa60ead82017-10-02 18:10:21 -07001310 if !installable {
1311 module.properties.Installable = proptools.BoolPtr(false)
1312 }
Colin Cross2fe66872015-03-30 17:20:39 -07001313
Colin Crossa60ead82017-10-02 18:10:21 -07001314 module.AddProperties(
1315 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001316 &module.Module.deviceProperties,
1317 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001318
Colin Crossa60ead82017-10-02 18:10:21 -07001319 InitJavaModule(module, android.HostAndDeviceSupported)
1320 return module
1321 }
Colin Cross2fe66872015-03-30 17:20:39 -07001322}
1323
Colin Crossf506d872017-07-19 15:53:04 -07001324func LibraryHostFactory() android.Module {
1325 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001326
Colin Cross6af17aa2017-09-20 12:59:05 -07001327 module.AddProperties(
1328 &module.Module.properties,
1329 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001330
Colin Cross89536d42017-07-07 14:35:50 -07001331 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001332 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001333}
1334
1335//
Colin Cross05638fc2018-04-09 18:40:24 -07001336// Java Junit Tests
1337//
1338
1339type testProperties struct {
1340 // If true, add a static dependency on the platform junit library. Defaults to true.
1341 Junit *bool
1342
1343 // list of compatibility suites (for example "cts", "vts") that the module should be
1344 // installed into.
1345 Test_suites []string `android:"arch_variant"`
1346}
1347
1348type Test struct {
1349 Library
1350
1351 testProperties testProperties
1352}
1353
1354func (j *Test) DepsMutator(ctx android.BottomUpMutatorContext) {
1355 j.deps(ctx)
Colin Cross38b40df2018-04-10 16:14:46 -07001356 if BoolDefault(j.testProperties.Junit, true) {
Colin Cross05638fc2018-04-09 18:40:24 -07001357 ctx.AddDependency(ctx.Module(), staticLibTag, "junit")
1358 }
1359}
1360
1361func TestFactory() android.Module {
1362 module := &Test{}
1363
1364 module.AddProperties(
1365 &module.Module.properties,
1366 &module.Module.deviceProperties,
1367 &module.Module.protoProperties,
1368 &module.testProperties)
1369
1370 InitJavaModule(module, android.HostAndDeviceSupported)
1371 android.InitDefaultableModule(module)
1372 return module
1373}
1374
1375func TestHostFactory() android.Module {
1376 module := &Test{}
1377
1378 module.AddProperties(
1379 &module.Module.properties,
1380 &module.Module.protoProperties,
1381 &module.testProperties)
1382
1383 InitJavaModule(module, android.HostSupported)
1384 android.InitDefaultableModule(module)
1385 return module
1386}
1387
1388//
Colin Cross2fe66872015-03-30 17:20:39 -07001389// Java Binaries (.jar file plus wrapper script)
1390//
1391
Colin Crossf506d872017-07-19 15:53:04 -07001392type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001393 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001394 Wrapper *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001395}
1396
Colin Crossf506d872017-07-19 15:53:04 -07001397type Binary struct {
1398 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001399
Colin Crossf506d872017-07-19 15:53:04 -07001400 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001401
Colin Cross6b4a32d2017-12-05 13:42:45 -08001402 isWrapperVariant bool
1403
Colin Crossc3315992017-12-08 19:12:36 -08001404 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001405 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001406}
1407
Alex Light24237172017-10-26 09:46:21 -07001408func (j *Binary) HostToolPath() android.OptionalPath {
1409 return android.OptionalPathForPath(j.binaryFile)
1410}
1411
Colin Crossf506d872017-07-19 15:53:04 -07001412func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001413 if ctx.Arch().ArchType == android.Common {
1414 // Compile the jar
1415 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001416 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001417 // Handle the binary wrapper
1418 j.isWrapperVariant = true
1419
Colin Cross366938f2017-12-11 16:29:02 -08001420 if j.binaryProperties.Wrapper != nil {
1421 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001422 } else {
1423 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1424 }
1425
1426 // Depend on the installed jar so that the wrapper doesn't get executed by
1427 // another build rule before the jar has been installed.
1428 jarFile := ctx.PrimaryModule().(*Binary).installFile
1429
1430 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1431 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001432 }
Colin Cross2fe66872015-03-30 17:20:39 -07001433}
1434
Colin Crossf506d872017-07-19 15:53:04 -07001435func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001436 if ctx.Arch().ArchType == android.Common {
1437 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001438 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001439 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001440 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001441}
1442
Colin Crossf506d872017-07-19 15:53:04 -07001443func BinaryFactory() android.Module {
1444 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001445
Colin Cross36242852017-06-23 15:06:31 -07001446 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001447 &module.Module.properties,
1448 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001449 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001450 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001451
Colin Cross6b4a32d2017-12-05 13:42:45 -08001452 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1453 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001454 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001455}
1456
Colin Crossf506d872017-07-19 15:53:04 -07001457func BinaryHostFactory() android.Module {
1458 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001459
Colin Cross36242852017-06-23 15:06:31 -07001460 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001461 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001462 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001463 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001464
Colin Cross6b4a32d2017-12-05 13:42:45 -08001465 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1466 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001467 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001468}
1469
1470//
1471// Java prebuilts
1472//
1473
Colin Cross74d73e22017-08-02 11:05:49 -07001474type ImportProperties struct {
1475 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001476
Nan Zhangea568a42017-11-08 21:20:04 -08001477 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001478
1479 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001480
1481 // List of shared java libs that this module has dependencies to
1482 Libs []string
Colin Cross74d73e22017-08-02 11:05:49 -07001483}
1484
1485type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001486 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001487 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001488
Colin Cross74d73e22017-08-02 11:05:49 -07001489 properties ImportProperties
1490
Colin Cross0a6e0072017-08-30 14:24:55 -07001491 classpathFiles android.Paths
1492 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09001493 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07001494}
1495
Colin Cross83bb3162018-06-25 15:48:06 -07001496func (j *Import) sdkVersion() string {
1497 return String(j.properties.Sdk_version)
1498}
1499
1500func (j *Import) minSdkVersion() string {
1501 return j.sdkVersion()
1502}
1503
Colin Cross74d73e22017-08-02 11:05:49 -07001504func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001505 return &j.prebuilt
1506}
1507
Colin Cross74d73e22017-08-02 11:05:49 -07001508func (j *Import) PrebuiltSrcs() []string {
1509 return j.properties.Jars
1510}
1511
1512func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001513 return j.prebuilt.Name(j.ModuleBase.Name())
1514}
1515
Colin Cross74d73e22017-08-02 11:05:49 -07001516func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park1be96912018-05-28 18:02:19 +09001517 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07001518}
1519
Colin Cross74d73e22017-08-02 11:05:49 -07001520func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1521 j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07001522
Colin Crosse9a275b2017-10-16 17:09:48 -07001523 outputFile := android.PathForModuleOut(ctx, "classes.jar")
Nan Zhanged19fc32017-10-19 13:06:22 -07001524 TransformJarsToJar(ctx, outputFile, "for prebuilts", j.classpathFiles, android.OptionalPath{}, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001525 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09001526
1527 ctx.VisitDirectDeps(func(module android.Module) {
1528 otherName := ctx.OtherModuleName(module)
1529 tag := ctx.OtherModuleDependencyTag(module)
1530
1531 switch dep := module.(type) {
1532 case Dependency:
1533 switch tag {
1534 case libTag, staticLibTag:
1535 // sdk lib names from dependencies are re-exported
1536 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
1537 }
1538 case SdkLibraryDependency:
1539 switch tag {
1540 case libTag:
1541 // names of sdk libs that are directly depended are exported
1542 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
1543 }
1544 }
1545 })
1546
1547 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Colin Cross2fe66872015-03-30 17:20:39 -07001548}
1549
Colin Cross74d73e22017-08-02 11:05:49 -07001550var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001551
Nan Zhanged19fc32017-10-19 13:06:22 -07001552func (j *Import) HeaderJars() android.Paths {
1553 return j.classpathFiles
1554}
1555
1556func (j *Import) ImplementationJars() android.Paths {
Colin Cross74d73e22017-08-02 11:05:49 -07001557 return j.classpathFiles
Colin Cross2fe66872015-03-30 17:20:39 -07001558}
1559
Colin Cross74d73e22017-08-02 11:05:49 -07001560func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001561 return nil
1562}
1563
Jiyong Park1be96912018-05-28 18:02:19 +09001564func (j *Import) ExportedSdkLibs() []string {
1565 return j.exportedSdkLibs
1566}
1567
Colin Cross74d73e22017-08-02 11:05:49 -07001568var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001569
Colin Cross74d73e22017-08-02 11:05:49 -07001570func ImportFactory() android.Module {
1571 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001572
Colin Cross74d73e22017-08-02 11:05:49 -07001573 module.AddProperties(&module.properties)
1574
1575 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -07001576 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1577 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001578}
1579
Colin Cross74d73e22017-08-02 11:05:49 -07001580func ImportFactoryHost() android.Module {
1581 module := &Import{}
1582
1583 module.AddProperties(&module.properties)
1584
1585 android.InitPrebuiltModule(module, &module.properties.Jars)
1586 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
1587 return module
1588}
1589
Colin Cross89536d42017-07-07 14:35:50 -07001590//
1591// Defaults
1592//
1593type Defaults struct {
1594 android.ModuleBase
1595 android.DefaultsModuleBase
1596}
1597
1598func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1599}
1600
1601func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1602}
1603
1604func defaultsFactory() android.Module {
1605 return DefaultsFactory()
1606}
1607
1608func DefaultsFactory(props ...interface{}) android.Module {
1609 module := &Defaults{}
1610
1611 module.AddProperties(props...)
1612 module.AddProperties(
1613 &CompilerProperties{},
1614 &CompilerDeviceProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001615 &android.ProtoProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07001616 )
1617
1618 android.InitDefaultsModule(module)
1619
1620 return module
1621}
Nan Zhangea568a42017-11-08 21:20:04 -08001622
1623var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001624var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08001625var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08001626var inList = android.InList