blob: 9ae05f3ca855bae6369af7cd4a36d18db3ddecdf [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 Cross9ae1b922018-06-26 17:59:05 -070037 android.RegisterModuleType("java_library", LibraryFactory)
38 android.RegisterModuleType("java_library_static", LibraryFactory)
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
Colin Cross9ae1b922018-06-26 17:59:05 -0700110 // If set to true, allow this module to be dexed and installed on devices. Has no
111 // effect on host modules, which are always considered installable.
Colin Cross2c429dc2017-08-31 16:45:16 -0700112 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700113
Colin Cross0f37af02017-09-27 17:42:05 -0700114 // If set to true, include sources used to compile the module in to the final jar
115 Include_srcs *bool
116
Colin Cross32f676a2017-09-06 13:41:06 -0700117 // List of modules to use as annotation processors
118 Annotation_processors []string
119
120 // List of classes to pass to javac to use as annotation processors
121 Annotation_processor_classes []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700122
Nan Zhang61eaedb2017-11-02 13:28:15 -0700123 // The number of Java source entries each Javac instance can process
124 Javac_shard_size *int64
125
Nan Zhang5f8cb422018-02-06 10:34:32 -0800126 // Add host jdk tools.jar to bootclasspath
127 Use_tools_jar *bool
128
Colin Cross1369cdb2017-09-29 17:58:17 -0700129 Openjdk9 struct {
130 // List of source files that should only be used when passing -source 1.9
131 Srcs []string
132
133 // List of javac flags that should only be used when passing -source 1.9
134 Javacflags []string
135 }
Colin Crosscb933592017-11-22 13:49:43 -0800136
137 Jacoco struct {
138 // List of classes to include for instrumentation with jacoco to collect coverage
139 // information at runtime when building with coverage enabled. If unset defaults to all
140 // classes.
141 // Supports '*' as the last character of an entry in the list as a wildcard match.
142 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
143 // it matches classes in the package that have the class name as a prefix.
144 Include_filter []string
145
146 // List of classes to exclude from instrumentation with jacoco to collect coverage
147 // information at runtime when building with coverage enabled. Overrides classes selected
148 // by the include_filter property.
149 // Supports '*' as the last character of an entry in the list as a wildcard match.
150 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
151 // it matches classes in the package that have the class name as a prefix.
152 Exclude_filter []string
153 }
154
Andreas Gampef3e5b552018-01-22 21:27:21 -0800155 Errorprone struct {
156 // List of javac flags that should only be used when running errorprone.
157 Javacflags []string
158 }
159
Colin Cross0f2ee152017-12-14 15:22:43 -0800160 Proto struct {
161 // List of extra options that will be passed to the proto generator.
162 Output_params []string
163 }
164
Colin Crosscb933592017-11-22 13:49:43 -0800165 Instrument bool `blueprint:"mutated"`
Colin Cross540eff82017-06-22 17:01:52 -0700166}
167
Colin Cross89536d42017-07-07 14:35:50 -0700168type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700169 // list of module-specific flags that will be used for dex compiles
170 Dxflags []string `android:"arch_variant"`
171
Colin Cross83bb3162018-06-25 15:48:06 -0700172 // if not blank, set to the version of the sdk to compile against. Defaults to compiling against the current
173 // sdk if platform_apis is not set.
Nan Zhangea568a42017-11-08 21:20:04 -0800174 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700175
Colin Cross83bb3162018-06-25 15:48:06 -0700176 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
177 // Defaults to sdk_version if not set.
178 Min_sdk_version *string
179
Colin Cross6af2e492018-05-22 11:12:33 -0700180 // if true, compile against the platform APIs instead of an SDK.
181 Platform_apis *bool
182
Colin Crossebe1a512017-11-14 13:12:14 -0800183 Aidl struct {
184 // Top level directories to pass to aidl tool
185 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700186
Colin Crossebe1a512017-11-14 13:12:14 -0800187 // Directories rooted at the Android.bp file to pass to aidl tool
188 Local_include_dirs []string
189
190 // directories that should be added as include directories for any aidl sources of modules
191 // that depend on this module, as well as to aidl for this module.
192 Export_include_dirs []string
Martijn Coeneneab15642018-03-09 09:29:59 +0100193
194 // whether to generate traces (for systrace) for this interface
195 Generate_traces *bool
Colin Crossebe1a512017-11-14 13:12:14 -0800196 }
Colin Cross92430102017-10-09 14:59:32 -0700197
198 // If true, export a copy of the module as a -hostdex module for host testing.
199 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700200
David Brazdil17ef5632018-06-27 10:27:45 +0100201 // If set to true, compile dex regardless of installable. Defaults to false.
202 Compile_dex *bool
203
Colin Cross1bd87802017-12-05 15:31:19 -0800204 Dex_preopt struct {
205 // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to
206 // true.
207 Enabled *bool
208
209 // If true, generate an app image (.art file) for this module.
210 App_image *bool
211
212 // If true, use a checked-in profile to guide optimization. Defaults to false unless
213 // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR
214 // that matches the name of this module, in which case it is defaulted to true.
215 Profile_guided *bool
216
217 // If set, provides the path to profile relative to the Android.bp file. If not set,
218 // defaults to searching for a file that matches the name of this module in the default
219 // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found.
220 Profile *string
221 }
Colin Crossa22116e2017-10-19 14:18:58 -0700222
Colin Cross66dbc0b2017-12-28 12:23:20 -0800223 Optimize struct {
Colin Crossae5caf52018-05-22 11:11:52 -0700224 // If false, disable all optimization. Defaults to true for android_app and android_test
225 // modules, false for java_library and java_test modules.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800226 Enabled *bool
227
228 // If true, optimize for size by removing unused code. Defaults to true for apps,
229 // false for libraries and tests.
230 Shrink *bool
231
232 // If true, optimize bytecode. Defaults to false.
233 Optimize *bool
234
235 // If true, obfuscate bytecode. Defaults to false.
236 Obfuscate *bool
237
238 // If true, do not use the flag files generated by aapt that automatically keep
239 // classes referenced by the app manifest. Defaults to false.
240 No_aapt_flags *bool
241
242 // Flags to pass to proguard.
243 Proguard_flags []string
244
245 // Specifies the locations of files containing proguard flags.
246 Proguard_flags_files []string
247 }
248
Colin Cross1369cdb2017-09-29 17:58:17 -0700249 // When targeting 1.9, override the modules to use with --system
250 System_modules *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700251}
252
Colin Cross46c9b8b2017-06-22 16:51:17 -0700253// Module contains the properties and members used by all java module types
254type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700255 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700256 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700257
Colin Cross89536d42017-07-07 14:35:50 -0700258 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700259 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700260 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700261
Nan Zhanged19fc32017-10-19 13:06:22 -0700262 // header jar file suitable for inserting into the bootclasspath/classpath of another compile
263 headerJarFile android.Path
264
265 // full implementation jar file suitable for static dependency of another module compile
266 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700267
Colin Cross6ade34f2017-09-15 13:00:47 -0700268 // output file containing classes.dex
269 dexJarFile android.Path
270
Colin Crosscb933592017-11-22 13:49:43 -0800271 // output file containing uninstrumented classes that will be instrumented by jacoco
272 jacocoReportClassesFile android.Path
273
Colin Cross66dbc0b2017-12-28 12:23:20 -0800274 // output file containing mapping of obfuscated names
275 proguardDictionary android.Path
276
Colin Crossb7a63242015-04-16 14:09:14 -0700277 // output file suitable for installing or running
Colin Cross635c3b02016-05-18 15:37:25 -0700278 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700279
Colin Cross635c3b02016-05-18 15:37:25 -0700280 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700281
Colin Cross635c3b02016-05-18 15:37:25 -0700282 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700283
Colin Cross2fe66872015-03-30 17:20:39 -0700284 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700285 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800286
287 // list of .java files and srcjars that was passed to javac
288 compiledJavaSrcs android.Paths
289 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800290
291 // list of extra progurad flag files
292 extraProguardFlagFiles android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900293
294 // list of SDK lib names that this java moudule is exporting
295 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -0700296}
297
Colin Cross54250902017-12-05 09:28:08 -0800298func (j *Module) Srcs() android.Paths {
299 return android.Paths{j.implementationJarFile}
300}
301
302var _ android.SourceFileProducer = (*Module)(nil)
303
Colin Crossf506d872017-07-19 15:53:04 -0700304type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700305 HeaderJars() android.Paths
306 ImplementationJars() android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700307 AidlIncludeDirs() android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900308 ExportedSdkLibs() []string
Colin Cross2fe66872015-03-30 17:20:39 -0700309}
310
Jiyong Parkc678ad32018-04-10 13:07:10 +0900311type SdkLibraryDependency interface {
312 HeaderJars(linkType linkType) android.Paths
313}
314
Nan Zhangb2b33de2018-02-23 11:18:47 -0800315type SrcDependency interface {
316 CompiledSrcs() android.Paths
317 CompiledSrcJars() android.Paths
318}
319
320func (j *Module) CompiledSrcs() android.Paths {
321 return j.compiledJavaSrcs
322}
323
324func (j *Module) CompiledSrcJars() android.Paths {
325 return j.compiledSrcJars
326}
327
328var _ SrcDependency = (*Module)(nil)
329
Colin Cross89536d42017-07-07 14:35:50 -0700330func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
331 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
332 android.InitDefaultableModule(module)
333}
334
Colin Crossbe1da472017-07-07 15:59:46 -0700335type dependencyTag struct {
336 blueprint.BaseDependencyTag
337 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700338}
339
Colin Crossbe1da472017-07-07 15:59:46 -0700340var (
Colin Cross6ade34f2017-09-15 13:00:47 -0700341 staticLibTag = dependencyTag{name: "staticlib"}
342 libTag = dependencyTag{name: "javalib"}
Colin Cross6a77c982018-06-19 22:43:34 -0700343 annoTag = dependencyTag{name: "annotation processor"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700344 bootClasspathTag = dependencyTag{name: "bootclasspath"}
Colin Cross1369cdb2017-09-29 17:58:17 -0700345 systemModulesTag = dependencyTag{name: "system modules"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700346 frameworkResTag = dependencyTag{name: "framework-res"}
Nan Zhangb2b33de2018-02-23 11:18:47 -0800347 frameworkApkTag = dependencyTag{name: "framework-apk"}
Colin Cross93e85952017-08-15 13:34:18 -0700348 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Cross66dbc0b2017-12-28 12:23:20 -0800349 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
Colin Crossbe1da472017-07-07 15:59:46 -0700350)
Colin Cross2fe66872015-03-30 17:20:39 -0700351
Colin Crossfc3674a2017-09-18 17:41:52 -0700352type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700353 useModule, useFiles, useDefaultLibs, invalidVersion bool
354
Colin Cross86a60ae2018-05-29 14:44:55 -0700355 modules []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700356 systemModules string
357
Colin Crossa97c5d32018-03-28 14:58:31 -0700358 frameworkResModule string
359
Colin Cross86a60ae2018-05-29 14:44:55 -0700360 jars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700361 aidl android.Path
362}
363
Colin Cross3144dfc2018-01-03 15:06:47 -0800364func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
365 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
366}
367
368func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
369 return j.shouldInstrument(ctx) &&
370 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
371 ctx.Config().UnbundledBuild())
372}
373
Colin Cross83bb3162018-06-25 15:48:06 -0700374func (j *Module) sdkVersion() string {
375 return String(j.deviceProperties.Sdk_version)
376}
377
378func (j *Module) minSdkVersion() string {
379 if j.deviceProperties.Min_sdk_version != nil {
380 return *j.deviceProperties.Min_sdk_version
381 }
382 return j.sdkVersion()
383}
384
385type sdkContext interface {
386 // sdkVersion eturns the sdk_version property of the current module, or an empty string if it is not set.
387 sdkVersion() string
388 // minSdkVersion returns the min_sdk_version property of the current module, or sdkVersion() if it is not set.
389 minSdkVersion() string
390}
391
392func sdkVersionOrDefault(ctx android.BaseContext, v string) string {
393 switch v {
394 case "", "current", "system_current", "test_current", "core_current":
395 return ctx.Config().DefaultAppTargetSdk()
396 default:
397 return v
398 }
399}
400
401// Returns a sdk version as a number. For modules targeting an unreleased SDK (meaning it does not yet have a number)
402// it returns android.FutureApiLevel (10000).
403func sdkVersionToNumber(ctx android.BaseContext, v string) (int, error) {
404 switch v {
405 case "", "current", "test_current", "system_current", "core_current":
406 return ctx.Config().DefaultAppTargetSdkInt(), nil
407 default:
408 n := android.GetNumericSdkVersion(v)
409 if i, err := strconv.Atoi(n); err != nil {
410 return -1, fmt.Errorf("invalid sdk version %q", n)
411 } else {
412 return i, nil
413 }
414 }
415}
416
417func sdkVersionToNumberAsString(ctx android.BaseContext, v string) (string, error) {
418 n, err := sdkVersionToNumber(ctx, v)
419 if err != nil {
420 return "", err
421 }
422 return strconv.Itoa(n), nil
423}
424
425func decodeSdkDep(ctx android.BaseContext, sdkContext sdkContext) sdkDep {
426 v := sdkContext.sdkVersion()
427 i, err := sdkVersionToNumber(ctx, v)
428 if err != nil {
429 ctx.PropertyErrorf("sdk_version", "%s", err)
Colin Cross1369cdb2017-09-29 17:58:17 -0700430 return sdkDep{}
Colin Crossfc3674a2017-09-18 17:41:52 -0700431 }
432
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900433 // Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks)
434 // or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set)
435 if strings.HasPrefix(v, "system_") && i != android.FutureApiLevel {
436 allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions()
437 if ctx.DeviceSpecific() || ctx.SocSpecific() {
438 if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 {
439 allowed_versions = ctx.DeviceConfig().SystemSdkVersions()
440 }
441 }
442 version := strings.TrimPrefix(v, "system_")
443 if len(allowed_versions) > 0 && !android.InList(version, allowed_versions) {
444 ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q",
445 v, allowed_versions)
446 }
447 }
448
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100449 toPrebuilt := func(sdk string) sdkDep {
450 var api, v string
451 if strings.Contains(sdk, "_") {
452 t := strings.Split(sdk, "_")
453 api = t[0]
454 v = t[1]
455 } else {
456 api = "public"
457 v = sdk
Jiyong Park750e5572018-01-31 00:20:13 +0900458 }
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100459 dir := filepath.Join("prebuilts", "sdk", v, api)
Colin Crossfc3674a2017-09-18 17:41:52 -0700460 jar := filepath.Join(dir, "android.jar")
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100461 // There's no aidl for other SDKs yet.
462 // TODO(77525052): Add aidl files for other SDKs too.
463 public_dir := filepath.Join("prebuilts", "sdk", v, "public")
464 aidl := filepath.Join(public_dir, "framework.aidl")
Colin Cross32f38982018-02-22 11:47:25 -0800465 jarPath := android.ExistentPathForSource(ctx, jar)
466 aidlPath := android.ExistentPathForSource(ctx, aidl)
Colin Cross86a60ae2018-05-29 14:44:55 -0700467 lambdaStubsPath := android.PathForSource(ctx, config.SdkLambdaStubsPath)
Colin Cross47ff2522017-10-02 14:22:08 -0700468
Colin Cross6510f912017-11-29 00:27:14 -0800469 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
Colin Cross47ff2522017-10-02 14:22:08 -0700470 return sdkDep{
471 invalidVersion: true,
Colin Cross86a60ae2018-05-29 14:44:55 -0700472 modules: []string{fmt.Sprintf("sdk_%s_%s_android", api, v)},
Colin Cross47ff2522017-10-02 14:22:08 -0700473 }
474 }
475
Colin Crossfc3674a2017-09-18 17:41:52 -0700476 if !jarPath.Valid() {
477 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar)
478 return sdkDep{}
479 }
Colin Cross47ff2522017-10-02 14:22:08 -0700480
Colin Crossfc3674a2017-09-18 17:41:52 -0700481 if !aidlPath.Valid() {
482 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl)
483 return sdkDep{}
484 }
Colin Cross47ff2522017-10-02 14:22:08 -0700485
Colin Crossfc3674a2017-09-18 17:41:52 -0700486 return sdkDep{
487 useFiles: true,
Colin Cross86a60ae2018-05-29 14:44:55 -0700488 jars: android.Paths{jarPath.Path(), lambdaStubsPath},
Colin Crossfc3674a2017-09-18 17:41:52 -0700489 aidl: aidlPath.Path(),
490 }
491 }
492
Colin Crossa97c5d32018-03-28 14:58:31 -0700493 toModule := func(m, r string) sdkDep {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700494 ret := sdkDep{
Colin Crossa97c5d32018-03-28 14:58:31 -0700495 useModule: true,
Colin Cross86a60ae2018-05-29 14:44:55 -0700496 modules: []string{m, config.DefaultLambdaStubsLibrary},
Colin Crossa97c5d32018-03-28 14:58:31 -0700497 systemModules: m + "_system_modules",
498 frameworkResModule: r,
Colin Crossf19b9bb2018-03-26 14:42:44 -0700499 }
500 if m == "core.current.stubs" {
501 ret.systemModules = "core-system-modules"
502 }
503 return ret
504 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700505
Colin Cross6510f912017-11-29 00:27:14 -0800506 if ctx.Config().UnbundledBuild() && v != "" {
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100507 return toPrebuilt(v)
Colin Crossfc3674a2017-09-18 17:41:52 -0700508 }
509
510 switch v {
511 case "":
512 return sdkDep{
Colin Crossa97c5d32018-03-28 14:58:31 -0700513 useDefaultLibs: true,
514 frameworkResModule: "framework-res",
Colin Crossfc3674a2017-09-18 17:41:52 -0700515 }
Colin Crossf19b9bb2018-03-26 14:42:44 -0700516 case "current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700517 return toModule("android_stubs_current", "framework-res")
Colin Crossf19b9bb2018-03-26 14:42:44 -0700518 case "system_current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700519 return toModule("android_system_stubs_current", "framework-res")
Colin Crossf19b9bb2018-03-26 14:42:44 -0700520 case "test_current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700521 return toModule("android_test_stubs_current", "framework-res")
Colin Crossf19b9bb2018-03-26 14:42:44 -0700522 case "core_current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700523 return toModule("core.current.stubs", "")
Colin Crossfc3674a2017-09-18 17:41:52 -0700524 default:
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100525 return toPrebuilt(v)
Colin Crossfc3674a2017-09-18 17:41:52 -0700526 }
527}
528
Colin Crossbe1da472017-07-07 15:59:46 -0700529func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700530 if ctx.Device() {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700531 if !Bool(j.properties.No_standard_libs) {
Colin Cross83bb3162018-06-25 15:48:06 -0700532 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Crossfc3674a2017-09-18 17:41:52 -0700533 if sdkDep.useDefaultLibs {
Colin Crosscb2c9292017-09-23 19:57:16 -0700534 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Colin Cross6510f912017-11-29 00:27:14 -0800535 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700536 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
537 }
Colin Crossff3ae9d2018-04-10 16:15:18 -0700538 if !Bool(j.properties.No_framework_libs) {
Colin Crossfa5eb232017-10-01 20:33:03 -0700539 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
540 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700541 } else if sdkDep.useModule {
Colin Cross6510f912017-11-29 00:27:14 -0800542 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700543 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
544 }
Colin Cross86a60ae2018-05-29 14:44:55 -0700545 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800546 if Bool(j.deviceProperties.Optimize.Enabled) {
547 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultBootclasspathLibraries...)
548 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultLibraries...)
549 }
Colin Crossbe1da472017-07-07 15:59:46 -0700550 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700551 } else if j.deviceProperties.System_modules == nil {
552 ctx.PropertyErrorf("no_standard_libs",
553 "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 -0800554 } else if *j.deviceProperties.System_modules != "none" && ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700555 ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700556 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800557 if ctx.ModuleName() == "framework" {
558 ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res")
559 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800560 if ctx.ModuleName() == "android_stubs_current" ||
561 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang16c0a312018-06-13 17:42:48 -0700562 ctx.ModuleName() == "android_test_stubs_current" ||
563 ctx.ModuleName() == "metalava_android_stubs_current" ||
564 ctx.ModuleName() == "metalava_android_system_stubs_current" ||
565 ctx.ModuleName() == "metalava_android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800566 ctx.AddDependency(ctx.Module(), frameworkApkTag, "framework-res")
567 }
Colin Cross2fe66872015-03-30 17:20:39 -0700568 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700569
Colin Crossf506d872017-07-19 15:53:04 -0700570 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
571 ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
Mathew Inwood878c6622018-07-02 16:34:51 +0100572 ctx.AddFarVariationDependencies([]blueprint.Variation{
573 {"arch", ctx.Config().BuildOsCommonVariant},
574 }, annoTag, j.properties.Annotation_processors...)
Colin Cross7f9036c2017-08-30 13:27:57 -0700575 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Nan Zhang27e284d2018-02-09 21:03:53 +0000576 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700577 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross366938f2017-12-11 16:29:02 -0800578 android.ExtractSourceDeps(ctx, j.properties.Manifest)
Colin Cross6af17aa2017-09-20 12:59:05 -0700579
580 if j.hasSrcExt(".proto") {
581 protoDeps(ctx, &j.protoProperties)
582 }
Colin Cross93e85952017-08-15 13:34:18 -0700583
584 if j.hasSrcExt(".kt") {
585 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
586 // Kotlin files
587 ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib")
588 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800589
590 if j.shouldInstrumentStatic(ctx) {
591 ctx.AddDependency(ctx.Module(), staticLibTag, "jacocoagent")
592 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700593}
594
595func hasSrcExt(srcs []string, ext string) bool {
596 for _, src := range srcs {
597 if filepath.Ext(src) == ext {
598 return true
599 }
600 }
601
602 return false
603}
604
Nan Zhang61eaedb2017-11-02 13:28:15 -0700605func shardPaths(paths android.Paths, shardSize int) []android.Paths {
606 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
607 for len(paths) > shardSize {
608 ret = append(ret, paths[0:shardSize])
609 paths = paths[shardSize:]
610 }
611 if len(paths) > 0 {
612 ret = append(ret, paths)
613 }
614 return ret
615}
616
Colin Cross6af17aa2017-09-20 12:59:05 -0700617func (j *Module) hasSrcExt(ext string) bool {
618 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700619}
620
Colin Cross46c9b8b2017-06-22 16:51:17 -0700621func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700622 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700623
Colin Crossebe1a512017-11-14 13:12:14 -0800624 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
625 aidlIncludes = append(aidlIncludes,
626 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
627 aidlIncludes = append(aidlIncludes,
628 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700629
630 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700631 if aidlPreprocess.Valid() {
632 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700633 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700634 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700635 }
636
Colin Cross635c3b02016-05-18 15:37:25 -0700637 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800638 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700639 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800640 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700641 flags = append(flags, "-I"+src.String())
642 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700643
Martijn Coeneneab15642018-03-09 09:29:59 +0100644 if Bool(j.deviceProperties.Aidl.Generate_traces) {
645 flags = append(flags, "-t")
646 }
647
Colin Crossf03c82b2015-04-13 13:53:40 -0700648 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700649}
650
Colin Cross32f676a2017-09-06 13:41:06 -0700651type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800652 classpath classpath
653 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700654 processorPath classpath
Colin Cross6ade34f2017-09-15 13:00:47 -0700655 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700656 staticHeaderJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700657 staticJarResources android.Paths
658 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800659 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700660 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700661 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700662 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700663 kotlinStdlib android.Paths
Colin Cross32f676a2017-09-06 13:41:06 -0700664}
Colin Cross2fe66872015-03-30 17:20:39 -0700665
Colin Cross54250902017-12-05 09:28:08 -0800666func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
667 for _, f := range dep.Srcs() {
668 if f.Ext() != ".jar" {
669 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
670 ctx.OtherModuleName(dep.(blueprint.Module)))
671 }
672 }
673}
674
Jiyong Park2d492942018-03-05 17:44:10 +0900675type linkType int
676
677const (
678 javaCore linkType = iota
679 javaSdk
680 javaSystem
681 javaPlatform
682)
683
Colin Crossf19b9bb2018-03-26 14:42:44 -0700684func getLinkType(m *Module, name string) linkType {
Colin Cross83bb3162018-06-25 15:48:06 -0700685 ver := m.sdkVersion()
Colin Cross86a60ae2018-05-29 14:44:55 -0700686 noStdLibs := Bool(m.properties.No_standard_libs)
Colin Crossf19b9bb2018-03-26 14:42:44 -0700687 switch {
Nan Zhang16c0a312018-06-13 17:42:48 -0700688 case name == "core.current.stubs" || ver == "core_current" || noStdLibs || name == "stub-annotations":
Jiyong Park2d492942018-03-05 17:44:10 +0900689 return javaCore
Nan Zhang16c0a312018-06-13 17:42:48 -0700690 case name == "android_system_stubs_current" || strings.HasPrefix(ver, "system_") || name == "metalava_android_system_stubs_current":
Jiyong Park2d492942018-03-05 17:44:10 +0900691 return javaSystem
Nan Zhang16c0a312018-06-13 17:42:48 -0700692 case name == "android_test_stubs_current" || strings.HasPrefix(ver, "test_") || name == "metalava_android_test_stubs_current":
Jiyong Park2d492942018-03-05 17:44:10 +0900693 return javaPlatform
Nan Zhang16c0a312018-06-13 17:42:48 -0700694 case name == "android_stubs_current" || ver == "current" || name == "metalava_android_stubs_current":
Colin Crossf19b9bb2018-03-26 14:42:44 -0700695 return javaSdk
696 case ver == "":
697 return javaPlatform
698 default:
699 if _, err := strconv.Atoi(ver); err != nil {
700 panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver))
701 }
702 return javaSdk
Jiyong Park2d492942018-03-05 17:44:10 +0900703 }
704}
705
Jiyong Park750e5572018-01-31 00:20:13 +0900706func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700707 if ctx.Host() {
708 return
709 }
710
711 myLinkType := getLinkType(from, ctx.ModuleName())
712 otherLinkType := getLinkType(&to.Module, ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900713 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."
714
715 switch myLinkType {
716 case javaCore:
717 if otherLinkType != javaCore {
718 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 +0900719 ctx.OtherModuleName(to))
720 }
Jiyong Park2d492942018-03-05 17:44:10 +0900721 break
722 case javaSdk:
723 if otherLinkType != javaCore && otherLinkType != javaSdk {
724 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
725 ctx.OtherModuleName(to))
726 }
727 break
728 case javaSystem:
729 if otherLinkType == javaPlatform {
730 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
731 ctx.OtherModuleName(to))
732 }
733 break
734 case javaPlatform:
735 // no restriction on link-type
736 break
Jiyong Park750e5572018-01-31 00:20:13 +0900737 }
738}
739
Colin Cross32f676a2017-09-06 13:41:06 -0700740func (j *Module) collectDeps(ctx android.ModuleContext) deps {
741 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700742
Colin Cross300f0382018-03-06 13:11:51 -0800743 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700744 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800745 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700746 ctx.AddMissingDependencies(sdkDep.modules)
Colin Cross300f0382018-03-06 13:11:51 -0800747 } else if sdkDep.useFiles {
748 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700749 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross300f0382018-03-06 13:11:51 -0800750 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
751 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700752 }
753
Colin Crossd11fcda2017-10-23 17:59:01 -0700754 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700755 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700756 tag := ctx.OtherModuleDependencyTag(module)
757
Jiyong Park750e5572018-01-31 00:20:13 +0900758 if to, ok := module.(*Library); ok {
Colin Crossa97c5d32018-03-28 14:58:31 -0700759 switch tag {
760 case bootClasspathTag, libTag, staticLibTag:
761 checkLinkType(ctx, j, to, tag.(dependencyTag))
762 }
Jiyong Park750e5572018-01-31 00:20:13 +0900763 }
Colin Cross54250902017-12-05 09:28:08 -0800764 switch dep := module.(type) {
765 case Dependency:
766 switch tag {
767 case bootClasspathTag:
768 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
769 case libTag:
770 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900771 // sdk lib names from dependencies are re-exported
772 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross54250902017-12-05 09:28:08 -0800773 case staticLibTag:
774 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
775 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
776 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900777 // sdk lib names from dependencies are re-exported
778 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross6a77c982018-06-19 22:43:34 -0700779 case annoTag:
780 deps.processorPath = append(deps.processorPath, dep.ImplementationJars()...)
Colin Cross54250902017-12-05 09:28:08 -0800781 case frameworkResTag:
782 if ctx.ModuleName() == "framework" {
783 // framework.jar has a one-off dependency on the R.java and Manifest.java files
784 // generated by framework-res.apk
785 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
786 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800787 case frameworkApkTag:
788 if ctx.ModuleName() == "android_stubs_current" ||
789 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang16c0a312018-06-13 17:42:48 -0700790 ctx.ModuleName() == "android_test_stubs_current" ||
791 ctx.ModuleName() == "metalava_android_stubs_current" ||
792 ctx.ModuleName() == "metalava_android_system_stubs_current" ||
793 ctx.ModuleName() == "metalava_android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800794 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
795 // resource files out of there for aapt.
796 //
797 // Normally the package rule runs aapt, which includes the resource,
798 // but we're not running that in our package rule so just copy in the
799 // resource files here.
800 deps.staticJarResources = append(deps.staticJarResources, dep.(*AndroidApp).exportPackage)
801 }
Colin Cross54250902017-12-05 09:28:08 -0800802 case kotlinStdlibTag:
803 deps.kotlinStdlib = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -0800804 }
805
806 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900807 case SdkLibraryDependency:
808 switch tag {
809 case libTag:
810 deps.classpath = append(deps.classpath, dep.HeaderJars(getLinkType(j, ctx.ModuleName()))...)
Jiyong Park1be96912018-05-28 18:02:19 +0900811 // names of sdk libs that are directly depended are exported
812 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900813 default:
814 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
815 }
Colin Cross54250902017-12-05 09:28:08 -0800816 case android.SourceFileProducer:
817 switch tag {
818 case libTag:
819 checkProducesJars(ctx, dep)
820 deps.classpath = append(deps.classpath, dep.Srcs()...)
821 case staticLibTag:
822 checkProducesJars(ctx, dep)
823 deps.classpath = append(deps.classpath, dep.Srcs()...)
824 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
825 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
826 case android.DefaultsDepTag, android.SourceDepTag:
827 // Nothing to do
828 default:
829 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
830 }
831 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700832 switch tag {
833 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700834 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700835 case systemModulesTag:
836 if deps.systemModules != nil {
837 panic("Found two system module dependencies")
838 }
839 sm := module.(*SystemModules)
840 if sm.outputFile == nil {
841 panic("Missing directory for system module dependency")
842 }
843 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700844 default:
845 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700846 }
Colin Crossec7a0422017-07-07 14:47:12 -0700847 }
Colin Cross2fe66872015-03-30 17:20:39 -0700848 })
849
Jiyong Park1be96912018-05-28 18:02:19 +0900850 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
851
Colin Cross32f676a2017-09-06 13:41:06 -0700852 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700853}
854
Colin Cross83bb3162018-06-25 15:48:06 -0700855func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string {
Nan Zhang357466b2018-04-17 17:38:36 -0700856 var ret string
Colin Cross83bb3162018-06-25 15:48:06 -0700857 sdk, err := sdkVersionToNumber(ctx, sdkContext.sdkVersion())
858 if err != nil {
859 ctx.PropertyErrorf("sdk_version", "%s", err)
860 }
Nan Zhang357466b2018-04-17 17:38:36 -0700861 if javaVersion != "" {
862 ret = javaVersion
863 } else if ctx.Device() && sdk <= 23 {
864 ret = "1.7"
865 } else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
866 ret = "1.8"
Colin Cross83bb3162018-06-25 15:48:06 -0700867 } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel {
Nan Zhang357466b2018-04-17 17:38:36 -0700868 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
869 ret = "1.8"
870 } else {
871 ret = "1.9"
872 }
873
874 return ret
875}
876
Nan Zhanged19fc32017-10-19 13:06:22 -0700877func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700878
Colin Crossf03c82b2015-04-13 13:53:40 -0700879 var flags javaBuilderFlags
880
Nan Zhanged19fc32017-10-19 13:06:22 -0700881 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700882 javacFlags := j.properties.Javacflags
Colin Cross6510f912017-11-29 00:27:14 -0800883 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700884 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700885 }
Colin Cross6510f912017-11-29 00:27:14 -0800886 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700887 // Override the -g flag passed globally to remove local variable debug info to reduce
888 // disk and memory usage.
889 javacFlags = append(javacFlags, "-g:source,lines")
890 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700891 if len(javacFlags) > 0 {
892 // optimization.
893 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
894 flags.javacFlags = "$javacFlags"
Colin Cross4f26bc02017-09-06 12:52:16 -0700895 }
Colin Cross64162712017-08-08 13:17:59 -0700896
Colin Cross66548102018-06-19 22:47:35 -0700897 if ctx.Config().RunErrorProne() {
898 if config.ErrorProneClasspath == nil {
899 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
900 }
901
902 errorProneFlags := []string{
903 "-Xplugin:ErrorProne",
904 "${config.ErrorProneChecks}",
905 }
906 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
907
908 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
909 "'" + strings.Join(errorProneFlags, " ") + "'"
910 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -0800911 }
912
Nan Zhanged19fc32017-10-19 13:06:22 -0700913 // javaVersion flag.
Colin Cross83bb3162018-06-25 15:48:06 -0700914 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross64162712017-08-08 13:17:59 -0700915
Nan Zhanged19fc32017-10-19 13:06:22 -0700916 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800917 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
918 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -0700919 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800920
921 if len(flags.bootClasspath) == 0 && ctx.Host() && !ctx.Config().TargetOpenJDK9() &&
922 !Bool(j.properties.No_standard_libs) &&
923 inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
924 // Give host-side tools a version of OpenJDK's standard libraries
925 // close to what they're targeting. As of Dec 2017, AOSP is only
926 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
927 //
928 // When building with OpenJDK 8, the following should have no
929 // effect since those jars would be available by default.
930 //
931 // When building with OpenJDK 9 but targeting a version < 1.8,
932 // putting them on the bootclasspath means that:
933 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
934 // b) references to existing APIs are not reinterpreted in an
935 // OpenJDK 9-specific way, eg. calls to subclasses of
936 // java.nio.Buffer as in http://b/70862583
937 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
938 flags.bootClasspath = append(flags.bootClasspath,
939 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
940 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -0800941 if Bool(j.properties.Use_tools_jar) {
942 flags.bootClasspath = append(flags.bootClasspath,
943 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
944 }
Colin Cross7fdd2b72018-01-02 18:14:25 -0800945 }
946
Nan Zhanged19fc32017-10-19 13:06:22 -0700947 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700948 if deps.systemModules != nil {
949 flags.systemModules = append(flags.systemModules, deps.systemModules)
950 }
951
Nan Zhanged19fc32017-10-19 13:06:22 -0700952 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700953 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700954 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700955 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700956 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
957 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700958 }
959
Nan Zhanged19fc32017-10-19 13:06:22 -0700960 return flags
961}
Colin Crossc0b06f12015-04-08 13:03:43 -0700962
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800963func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700964
Colin Crossebe1a512017-11-14 13:12:14 -0800965 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700966
967 deps := j.collectDeps(ctx)
968 flags := j.collectBuilderFlags(ctx, deps)
969
Colin Cross6510f912017-11-29 00:27:14 -0800970 if ctx.Config().TargetOpenJDK9() {
Nan Zhanged19fc32017-10-19 13:06:22 -0700971 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
972 }
973 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700974 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -0800975 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700976 }
977
Colin Crossaf050172017-11-15 23:01:59 -0800978 srcFiles = j.genSources(ctx, srcFiles, flags)
979
980 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700981 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800982 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700983
Colin Cross0a6e0072017-08-30 14:24:55 -0700984 var jars android.Paths
985
Colin Cross1ee23172017-10-18 14:44:18 -0700986 jarName := ctx.ModuleName() + ".jar"
987
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000988 javaSrcFiles := srcFiles.FilterByExt(".java")
989 var uniqueSrcFiles android.Paths
990 set := make(map[string]bool)
991 for _, v := range javaSrcFiles {
992 if _, found := set[v.String()]; !found {
993 set[v.String()] = true
994 uniqueSrcFiles = append(uniqueSrcFiles, v)
995 }
996 }
997
Colin Cross93e85952017-08-15 13:34:18 -0700998 if srcFiles.HasExt(".kt") {
999 // If there are kotlin files, compile them first but pass all the kotlin and java files
1000 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1001 // won't emit any classes for them.
1002
1003 flags.kotlincFlags = "-no-stdlib"
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001004
Colin Cross93e85952017-08-15 13:34:18 -07001005 if ctx.Device() {
1006 flags.kotlincFlags += " -no-jdk"
1007 }
1008
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001009 var kotlinSrcFiles android.Paths
1010 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1011 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1012
Przemyslaw Szczepaniake3d26bf2018-03-05 16:06:42 +00001013 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.bootClasspath...)
Colin Cross93e85952017-08-15 13:34:18 -07001014 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
1015 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
1016
Colin Cross1ee23172017-10-18 14:44:18 -07001017 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001018 TransformKotlinToClasses(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001019 if ctx.Failed() {
1020 return
1021 }
1022
1023 // Make javac rule depend on the kotlinc rule
Colin Cross49da2752018-06-05 17:22:57 -07001024 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001025 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001026
Colin Cross93e85952017-08-15 13:34:18 -07001027 // Jar kotlin classes into the final jar after javac
1028 jars = append(jars, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001029
1030 // Don't add kotlin-stdlib if using (on-device) renamed stdlib
1031 // (it's expected to be on device bootclasspath)
Colin Crossff3ae9d2018-04-10 16:15:18 -07001032 if !Bool(j.properties.Renamed_kotlin_stdlib) {
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001033 jars = append(jars, deps.kotlinStdlib...)
1034 }
Colin Cross93e85952017-08-15 13:34:18 -07001035 }
1036
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001037 // Store the list of .java files that was passed to javac
1038 j.compiledJavaSrcs = uniqueSrcFiles
1039 j.compiledSrcJars = srcJars
1040
Nan Zhang61eaedb2017-11-02 13:28:15 -07001041 enable_sharding := false
Colin Cross6510f912017-11-29 00:27:14 -08001042 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001043 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1044 enable_sharding = true
1045 if len(j.properties.Annotation_processors) != 0 ||
1046 len(j.properties.Annotation_processor_classes) != 0 {
1047 ctx.PropertyErrorf("javac_shard_size",
1048 "%q cannot be set when annotation processors are enabled.",
1049 j.properties.Javac_shard_size)
1050 }
1051 }
Colin Crossf19b9bb2018-03-26 14:42:44 -07001052 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName)
1053 if ctx.Failed() {
1054 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001055 }
1056 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001057 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001058 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001059 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001060 // If error-prone is enabled, add an additional rule to compile the java files into
1061 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001062 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001063 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1064 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001065 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001066 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001067 extraJarDeps = append(extraJarDeps, errorprone)
1068 }
1069
Nan Zhang61eaedb2017-11-02 13:28:15 -07001070 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001071 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001072 shardSize := int(*(j.properties.Javac_shard_size))
1073 var shardSrcs []android.Paths
1074 if len(uniqueSrcFiles) > 0 {
1075 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
1076 for idx, shardSrc := range shardSrcs {
1077 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
1078 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
1079 jars = append(jars, classes)
1080 }
1081 }
1082 if len(srcJars) > 0 {
1083 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
1084 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
1085 jars = append(jars, classes)
1086 }
1087 } else {
1088 classes := android.PathForModuleOut(ctx, "javac", jarName)
1089 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
1090 jars = append(jars, classes)
1091 }
Colin Crossd6891432017-09-27 17:39:56 -07001092 if ctx.Failed() {
1093 return
1094 }
Colin Cross2fe66872015-03-30 17:20:39 -07001095 }
1096
Colin Cross0f37af02017-09-27 17:42:05 -07001097 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
1098 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
1099
1100 var resArgs []string
1101 var resDeps android.Paths
1102
1103 resArgs = append(resArgs, dirArgs...)
1104 resDeps = append(resDeps, dirDeps...)
1105
1106 resArgs = append(resArgs, fileArgs...)
1107 resDeps = append(resDeps, fileDeps...)
1108
Colin Crossff3ae9d2018-04-10 16:15:18 -07001109 if Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -07001110 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -07001111 resArgs = append(resArgs, srcArgs...)
1112 resDeps = append(resDeps, srcDeps...)
1113 }
Colin Cross40a36712017-09-27 17:41:35 -07001114
1115 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001116 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001117 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -07001118 if ctx.Failed() {
1119 return
1120 }
Colin Cross20978302015-04-10 17:05:07 -07001121
Colin Cross0a6e0072017-08-30 14:24:55 -07001122 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -07001123 }
1124
Colin Cross6ade34f2017-09-15 13:00:47 -07001125 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -07001126 jars = append(jars, deps.staticJars...)
Nan Zhangb2b33de2018-02-23 11:18:47 -08001127 jars = append(jars, deps.staticJarResources...)
Colin Cross0a6e0072017-08-30 14:24:55 -07001128
Colin Cross366938f2017-12-11 16:29:02 -08001129 var manifest android.OptionalPath
1130 if j.properties.Manifest != nil {
1131 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
1132 }
Colin Cross635acc92017-09-12 22:50:46 -07001133
Colin Cross0a6e0072017-08-30 14:24:55 -07001134 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001135 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -07001136 var outputFile android.Path
1137
1138 if len(jars) == 1 && !manifest.Valid() {
1139 // Optimization: skip the combine step if there is nothing to do
Colin Cross7b60cdd2017-12-21 13:52:58 -08001140 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1141 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1142 // any if len(jars) == 1.
Colin Crosse9a275b2017-10-16 17:09:48 -07001143 outputFile = jars[0]
1144 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001145 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Nan Zhanged19fc32017-10-19 13:06:22 -07001146 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001147 outputFile = combinedJar
1148 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001149
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001150 // Use renamed kotlin standard library?
Colin Crossff3ae9d2018-04-10 16:15:18 -07001151 if srcFiles.HasExt(".kt") && Bool(j.properties.Renamed_kotlin_stdlib) {
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001152 jarjarFile := android.PathForModuleOut(ctx, "kotlin-renamed", jarName)
1153 TransformJarJar(ctx, jarjarFile, outputFile,
1154 android.PathForSource(ctx, "external/kotlinc/jarjar-rules.txt"))
1155 outputFile = jarjarFile
1156 if ctx.Failed() {
1157 return
1158 }
1159 }
1160
Colin Cross0a6e0072017-08-30 14:24:55 -07001161 if j.properties.Jarjar_rules != nil {
1162 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -07001163 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001164 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001165 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
1166 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -07001167 if ctx.Failed() {
1168 return
1169 }
1170 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001171 j.implementationJarFile = outputFile
1172 if j.headerJarFile == nil {
1173 j.headerJarFile = j.implementationJarFile
1174 }
Colin Cross2fe66872015-03-30 17:20:39 -07001175
Colin Cross6510f912017-11-29 00:27:14 -08001176 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -08001177 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
1178 j.properties.Instrument = true
1179 }
1180 }
1181
Colin Cross3144dfc2018-01-03 15:06:47 -08001182 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001183 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1184 }
1185
Colin Cross9ae1b922018-06-26 17:59:05 -07001186 if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
David Brazdil17ef5632018-06-27 10:27:45 +01001187 var dexOutputFile android.Path
1188 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001189 if ctx.Failed() {
1190 return
1191 }
Colin Cross9ae1b922018-06-26 17:59:05 -07001192 if Bool(j.properties.Installable) {
David Brazdil17ef5632018-06-27 10:27:45 +01001193 outputFile = dexOutputFile
1194 }
Colin Cross2fe66872015-03-30 17:20:39 -07001195 }
Colin Crossb7a63242015-04-16 14:09:14 -07001196 ctx.CheckbuildFile(outputFile)
1197 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -07001198}
1199
Colin Cross8eadbf02017-10-24 17:46:00 -07001200func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Nan Zhanged19fc32017-10-19 13:06:22 -07001201 deps deps, flags javaBuilderFlags, jarName string) android.Path {
1202
1203 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001204 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001205 // Compile java sources into turbine.jar.
1206 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1207 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1208 if ctx.Failed() {
1209 return nil
1210 }
1211 jars = append(jars, turbineJar)
1212 }
1213
1214 // Combine any static header libraries into classes-header.jar. If there is only
1215 // one input jar this step will be skipped.
1216 var headerJar android.Path
1217 jars = append(jars, deps.staticHeaderJars...)
1218
Colin Cross5c6ecc12017-10-23 18:12:27 -07001219 // we cannot skip the combine step for now if there is only one jar
1220 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1221 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
1222 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, false, []string{"META-INF"})
1223 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001224
1225 if j.properties.Jarjar_rules != nil {
1226 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
1227 // Transform classes.jar into classes-jarjar.jar
1228 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
1229 TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules)
1230 headerJar = jarjarFile
1231 if ctx.Failed() {
1232 return nil
1233 }
1234 }
1235
1236 return headerJar
1237}
1238
Colin Crosscb933592017-11-22 13:49:43 -08001239func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
1240 classesJar android.Path, jarName string) android.Path {
1241
Colin Cross7a3139e2017-12-19 13:57:50 -08001242 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001243
Colin Cross84c38822018-01-03 15:59:46 -08001244 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001245 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1246
1247 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1248
1249 j.jacocoReportClassesFile = jacocoReportClassesFile
1250
1251 return instrumentedJar
1252}
1253
Colin Crossf506d872017-07-19 15:53:04 -07001254var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001255
Nan Zhanged19fc32017-10-19 13:06:22 -07001256func (j *Module) HeaderJars() android.Paths {
1257 return android.Paths{j.headerJarFile}
1258}
1259
1260func (j *Module) ImplementationJars() android.Paths {
1261 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001262}
1263
Colin Cross46c9b8b2017-06-22 16:51:17 -07001264func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001265 return j.exportAidlIncludeDirs
1266}
1267
Jiyong Park1be96912018-05-28 18:02:19 +09001268func (j *Module) ExportedSdkLibs() []string {
1269 return j.exportedSdkLibs
1270}
1271
Colin Cross46c9b8b2017-06-22 16:51:17 -07001272var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001273
Colin Cross46c9b8b2017-06-22 16:51:17 -07001274func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001275 return j.logtagsSrcs
1276}
1277
Colin Cross2fe66872015-03-30 17:20:39 -07001278//
1279// Java libraries (.jar file)
1280//
1281
Colin Crossf506d872017-07-19 15:53:04 -07001282type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001283 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001284}
1285
Colin Crossf506d872017-07-19 15:53:04 -07001286func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001287 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001288
Colin Cross9ae1b922018-06-26 17:59:05 -07001289 if Bool(j.properties.Installable) || ctx.Host() {
Colin Cross2c429dc2017-08-31 16:45:16 -07001290 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1291 ctx.ModuleName()+".jar", j.outputFile)
1292 }
Colin Crossb7a63242015-04-16 14:09:14 -07001293}
1294
Colin Crossf506d872017-07-19 15:53:04 -07001295func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001296 j.deps(ctx)
1297}
1298
Colin Cross9ae1b922018-06-26 17:59:05 -07001299func LibraryFactory() android.Module {
1300 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001301
Colin Cross9ae1b922018-06-26 17:59:05 -07001302 module.AddProperties(
1303 &module.Module.properties,
1304 &module.Module.deviceProperties,
1305 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001306
Colin Cross9ae1b922018-06-26 17:59:05 -07001307 InitJavaModule(module, android.HostAndDeviceSupported)
1308 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001309}
1310
Colin Crossf506d872017-07-19 15:53:04 -07001311func LibraryHostFactory() android.Module {
1312 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001313
Colin Cross6af17aa2017-09-20 12:59:05 -07001314 module.AddProperties(
1315 &module.Module.properties,
1316 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001317
Colin Cross9ae1b922018-06-26 17:59:05 -07001318 module.Module.properties.Installable = proptools.BoolPtr(true)
1319
Colin Cross89536d42017-07-07 14:35:50 -07001320 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001321 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001322}
1323
1324//
Colin Cross05638fc2018-04-09 18:40:24 -07001325// Java Junit Tests
1326//
1327
1328type testProperties struct {
1329 // If true, add a static dependency on the platform junit library. Defaults to true.
1330 Junit *bool
1331
1332 // list of compatibility suites (for example "cts", "vts") that the module should be
1333 // installed into.
1334 Test_suites []string `android:"arch_variant"`
1335}
1336
1337type Test struct {
1338 Library
1339
1340 testProperties testProperties
1341}
1342
1343func (j *Test) DepsMutator(ctx android.BottomUpMutatorContext) {
1344 j.deps(ctx)
Colin Cross38b40df2018-04-10 16:14:46 -07001345 if BoolDefault(j.testProperties.Junit, true) {
Colin Cross05638fc2018-04-09 18:40:24 -07001346 ctx.AddDependency(ctx.Module(), staticLibTag, "junit")
1347 }
1348}
1349
1350func TestFactory() android.Module {
1351 module := &Test{}
1352
1353 module.AddProperties(
1354 &module.Module.properties,
1355 &module.Module.deviceProperties,
1356 &module.Module.protoProperties,
1357 &module.testProperties)
1358
Colin Cross9ae1b922018-06-26 17:59:05 -07001359 module.Module.properties.Installable = proptools.BoolPtr(true)
1360
Colin Cross05638fc2018-04-09 18:40:24 -07001361 InitJavaModule(module, android.HostAndDeviceSupported)
1362 android.InitDefaultableModule(module)
1363 return module
1364}
1365
1366func TestHostFactory() android.Module {
1367 module := &Test{}
1368
1369 module.AddProperties(
1370 &module.Module.properties,
1371 &module.Module.protoProperties,
1372 &module.testProperties)
1373
Colin Cross9ae1b922018-06-26 17:59:05 -07001374 module.Module.properties.Installable = proptools.BoolPtr(true)
1375
Colin Cross05638fc2018-04-09 18:40:24 -07001376 InitJavaModule(module, android.HostSupported)
1377 android.InitDefaultableModule(module)
1378 return module
1379}
1380
1381//
Colin Cross2fe66872015-03-30 17:20:39 -07001382// Java Binaries (.jar file plus wrapper script)
1383//
1384
Colin Crossf506d872017-07-19 15:53:04 -07001385type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001386 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001387 Wrapper *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001388}
1389
Colin Crossf506d872017-07-19 15:53:04 -07001390type Binary struct {
1391 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001392
Colin Crossf506d872017-07-19 15:53:04 -07001393 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001394
Colin Cross6b4a32d2017-12-05 13:42:45 -08001395 isWrapperVariant bool
1396
Colin Crossc3315992017-12-08 19:12:36 -08001397 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001398 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001399}
1400
Alex Light24237172017-10-26 09:46:21 -07001401func (j *Binary) HostToolPath() android.OptionalPath {
1402 return android.OptionalPathForPath(j.binaryFile)
1403}
1404
Colin Crossf506d872017-07-19 15:53:04 -07001405func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001406 if ctx.Arch().ArchType == android.Common {
1407 // Compile the jar
1408 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001409 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001410 // Handle the binary wrapper
1411 j.isWrapperVariant = true
1412
Colin Cross366938f2017-12-11 16:29:02 -08001413 if j.binaryProperties.Wrapper != nil {
1414 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001415 } else {
1416 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1417 }
1418
1419 // Depend on the installed jar so that the wrapper doesn't get executed by
1420 // another build rule before the jar has been installed.
1421 jarFile := ctx.PrimaryModule().(*Binary).installFile
1422
1423 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1424 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001425 }
Colin Cross2fe66872015-03-30 17:20:39 -07001426}
1427
Colin Crossf506d872017-07-19 15:53:04 -07001428func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001429 if ctx.Arch().ArchType == android.Common {
1430 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001431 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001432 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001433 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001434}
1435
Colin Crossf506d872017-07-19 15:53:04 -07001436func BinaryFactory() android.Module {
1437 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001438
Colin Cross36242852017-06-23 15:06:31 -07001439 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001440 &module.Module.properties,
1441 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001442 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001443 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001444
Colin Cross9ae1b922018-06-26 17:59:05 -07001445 module.Module.properties.Installable = proptools.BoolPtr(true)
1446
Colin Cross6b4a32d2017-12-05 13:42:45 -08001447 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1448 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001449 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001450}
1451
Colin Crossf506d872017-07-19 15:53:04 -07001452func BinaryHostFactory() android.Module {
1453 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001454
Colin Cross36242852017-06-23 15:06:31 -07001455 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001456 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001457 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001458 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001459
Colin Cross9ae1b922018-06-26 17:59:05 -07001460 module.Module.properties.Installable = proptools.BoolPtr(true)
1461
Colin Cross6b4a32d2017-12-05 13:42:45 -08001462 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1463 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001464 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001465}
1466
1467//
1468// Java prebuilts
1469//
1470
Colin Cross74d73e22017-08-02 11:05:49 -07001471type ImportProperties struct {
1472 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001473
Nan Zhangea568a42017-11-08 21:20:04 -08001474 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001475
1476 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001477
1478 // List of shared java libs that this module has dependencies to
1479 Libs []string
Colin Cross74d73e22017-08-02 11:05:49 -07001480}
1481
1482type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001483 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001484 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001485
Colin Cross74d73e22017-08-02 11:05:49 -07001486 properties ImportProperties
1487
Colin Cross0a6e0072017-08-30 14:24:55 -07001488 classpathFiles android.Paths
1489 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09001490 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07001491}
1492
Colin Cross83bb3162018-06-25 15:48:06 -07001493func (j *Import) sdkVersion() string {
1494 return String(j.properties.Sdk_version)
1495}
1496
1497func (j *Import) minSdkVersion() string {
1498 return j.sdkVersion()
1499}
1500
Colin Cross74d73e22017-08-02 11:05:49 -07001501func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001502 return &j.prebuilt
1503}
1504
Colin Cross74d73e22017-08-02 11:05:49 -07001505func (j *Import) PrebuiltSrcs() []string {
1506 return j.properties.Jars
1507}
1508
1509func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001510 return j.prebuilt.Name(j.ModuleBase.Name())
1511}
1512
Colin Cross74d73e22017-08-02 11:05:49 -07001513func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park1be96912018-05-28 18:02:19 +09001514 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07001515}
1516
Colin Cross74d73e22017-08-02 11:05:49 -07001517func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1518 j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07001519
Colin Crosse9a275b2017-10-16 17:09:48 -07001520 outputFile := android.PathForModuleOut(ctx, "classes.jar")
Nan Zhanged19fc32017-10-19 13:06:22 -07001521 TransformJarsToJar(ctx, outputFile, "for prebuilts", j.classpathFiles, android.OptionalPath{}, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001522 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09001523
1524 ctx.VisitDirectDeps(func(module android.Module) {
1525 otherName := ctx.OtherModuleName(module)
1526 tag := ctx.OtherModuleDependencyTag(module)
1527
1528 switch dep := module.(type) {
1529 case Dependency:
1530 switch tag {
1531 case libTag, staticLibTag:
1532 // sdk lib names from dependencies are re-exported
1533 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
1534 }
1535 case SdkLibraryDependency:
1536 switch tag {
1537 case libTag:
1538 // names of sdk libs that are directly depended are exported
1539 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
1540 }
1541 }
1542 })
1543
1544 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Colin Cross2fe66872015-03-30 17:20:39 -07001545}
1546
Colin Cross74d73e22017-08-02 11:05:49 -07001547var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001548
Nan Zhanged19fc32017-10-19 13:06:22 -07001549func (j *Import) HeaderJars() android.Paths {
1550 return j.classpathFiles
1551}
1552
1553func (j *Import) ImplementationJars() android.Paths {
Colin Cross74d73e22017-08-02 11:05:49 -07001554 return j.classpathFiles
Colin Cross2fe66872015-03-30 17:20:39 -07001555}
1556
Colin Cross74d73e22017-08-02 11:05:49 -07001557func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001558 return nil
1559}
1560
Jiyong Park1be96912018-05-28 18:02:19 +09001561func (j *Import) ExportedSdkLibs() []string {
1562 return j.exportedSdkLibs
1563}
1564
Colin Cross74d73e22017-08-02 11:05:49 -07001565var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001566
Colin Cross74d73e22017-08-02 11:05:49 -07001567func ImportFactory() android.Module {
1568 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001569
Colin Cross74d73e22017-08-02 11:05:49 -07001570 module.AddProperties(&module.properties)
1571
1572 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -07001573 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1574 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001575}
1576
Colin Cross74d73e22017-08-02 11:05:49 -07001577func ImportFactoryHost() android.Module {
1578 module := &Import{}
1579
1580 module.AddProperties(&module.properties)
1581
1582 android.InitPrebuiltModule(module, &module.properties.Jars)
1583 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
1584 return module
1585}
1586
Colin Cross89536d42017-07-07 14:35:50 -07001587//
1588// Defaults
1589//
1590type Defaults struct {
1591 android.ModuleBase
1592 android.DefaultsModuleBase
1593}
1594
1595func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1596}
1597
1598func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1599}
1600
1601func defaultsFactory() android.Module {
1602 return DefaultsFactory()
1603}
1604
1605func DefaultsFactory(props ...interface{}) android.Module {
1606 module := &Defaults{}
1607
1608 module.AddProperties(props...)
1609 module.AddProperties(
1610 &CompilerProperties{},
1611 &CompilerDeviceProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001612 &android.ProtoProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07001613 )
1614
1615 android.InitDefaultsModule(module)
1616
1617 return module
1618}
Nan Zhangea568a42017-11-08 21:20:04 -08001619
1620var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001621var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08001622var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08001623var inList = android.InList