blob: 89aa0e14fb0467697d5f80872b55eca69ffdae5a [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 Cross37f6d792018-07-12 12:28:41 -0700998 var stripFiles []string
999
Colin Cross93e85952017-08-15 13:34:18 -07001000 if srcFiles.HasExt(".kt") {
1001 // If there are kotlin files, compile them first but pass all the kotlin and java files
1002 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1003 // won't emit any classes for them.
1004
1005 flags.kotlincFlags = "-no-stdlib"
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001006
Colin Cross93e85952017-08-15 13:34:18 -07001007 if ctx.Device() {
1008 flags.kotlincFlags += " -no-jdk"
1009 }
1010
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001011 var kotlinSrcFiles android.Paths
1012 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1013 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1014
Przemyslaw Szczepaniake3d26bf2018-03-05 16:06:42 +00001015 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.bootClasspath...)
Colin Cross93e85952017-08-15 13:34:18 -07001016 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
1017 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
1018
Colin Cross1ee23172017-10-18 14:44:18 -07001019 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001020 TransformKotlinToClasses(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001021 if ctx.Failed() {
1022 return
1023 }
1024
1025 // Make javac rule depend on the kotlinc rule
Colin Cross49da2752018-06-05 17:22:57 -07001026 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001027 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001028
Colin Cross93e85952017-08-15 13:34:18 -07001029 // Jar kotlin classes into the final jar after javac
1030 jars = append(jars, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001031
Colin Cross37f6d792018-07-12 12:28:41 -07001032 if Bool(j.properties.Renamed_kotlin_stdlib) {
1033 // Remove any kotlin-reflect related files
1034 // TODO(pszczepaniak): Support kotlin-reflect
Colin Cross4c03f682018-07-15 08:16:31 -07001035 stripFiles = append(stripFiles,
1036 "**/*.kotlin_module",
1037 "**/*.kotlin_builtin")
Colin Cross37f6d792018-07-12 12:28:41 -07001038 } else {
1039 // Only add kotlin-stdlib if not using (on-device) renamed stdlib
1040 // (it's expected to be on device bootclasspath)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001041 jars = append(jars, deps.kotlinStdlib...)
1042 }
Colin Cross93e85952017-08-15 13:34:18 -07001043 }
1044
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001045 // Store the list of .java files that was passed to javac
1046 j.compiledJavaSrcs = uniqueSrcFiles
1047 j.compiledSrcJars = srcJars
1048
Nan Zhang61eaedb2017-11-02 13:28:15 -07001049 enable_sharding := false
Colin Cross6510f912017-11-29 00:27:14 -08001050 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001051 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1052 enable_sharding = true
1053 if len(j.properties.Annotation_processors) != 0 ||
1054 len(j.properties.Annotation_processor_classes) != 0 {
1055 ctx.PropertyErrorf("javac_shard_size",
1056 "%q cannot be set when annotation processors are enabled.",
1057 j.properties.Javac_shard_size)
1058 }
1059 }
Colin Crossf19b9bb2018-03-26 14:42:44 -07001060 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName)
1061 if ctx.Failed() {
1062 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001063 }
1064 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001065 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001066 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001067 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001068 // If error-prone is enabled, add an additional rule to compile the java files into
1069 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001070 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001071 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1072 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001073 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001074 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001075 extraJarDeps = append(extraJarDeps, errorprone)
1076 }
1077
Nan Zhang61eaedb2017-11-02 13:28:15 -07001078 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001079 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001080 shardSize := int(*(j.properties.Javac_shard_size))
1081 var shardSrcs []android.Paths
1082 if len(uniqueSrcFiles) > 0 {
1083 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
1084 for idx, shardSrc := range shardSrcs {
1085 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
1086 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
1087 jars = append(jars, classes)
1088 }
1089 }
1090 if len(srcJars) > 0 {
1091 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
1092 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
1093 jars = append(jars, classes)
1094 }
1095 } else {
1096 classes := android.PathForModuleOut(ctx, "javac", jarName)
1097 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
1098 jars = append(jars, classes)
1099 }
Colin Crossd6891432017-09-27 17:39:56 -07001100 if ctx.Failed() {
1101 return
1102 }
Colin Cross2fe66872015-03-30 17:20:39 -07001103 }
1104
Colin Cross0f37af02017-09-27 17:42:05 -07001105 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
1106 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
1107
1108 var resArgs []string
1109 var resDeps android.Paths
1110
1111 resArgs = append(resArgs, dirArgs...)
1112 resDeps = append(resDeps, dirDeps...)
1113
1114 resArgs = append(resArgs, fileArgs...)
1115 resDeps = append(resDeps, fileDeps...)
1116
Colin Crossff3ae9d2018-04-10 16:15:18 -07001117 if Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -07001118 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -07001119 resArgs = append(resArgs, srcArgs...)
1120 resDeps = append(resDeps, srcDeps...)
1121 }
Colin Cross40a36712017-09-27 17:41:35 -07001122
1123 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001124 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001125 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -07001126 if ctx.Failed() {
1127 return
1128 }
Colin Cross20978302015-04-10 17:05:07 -07001129
Colin Cross0a6e0072017-08-30 14:24:55 -07001130 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -07001131 }
1132
Colin Cross6ade34f2017-09-15 13:00:47 -07001133 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -07001134 jars = append(jars, deps.staticJars...)
Nan Zhangb2b33de2018-02-23 11:18:47 -08001135 jars = append(jars, deps.staticJarResources...)
Colin Cross0a6e0072017-08-30 14:24:55 -07001136
Colin Cross366938f2017-12-11 16:29:02 -08001137 var manifest android.OptionalPath
1138 if j.properties.Manifest != nil {
1139 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
1140 }
Colin Cross635acc92017-09-12 22:50:46 -07001141
Colin Cross0a6e0072017-08-30 14:24:55 -07001142 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001143 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -07001144 var outputFile android.Path
1145
1146 if len(jars) == 1 && !manifest.Valid() {
1147 // Optimization: skip the combine step if there is nothing to do
Colin Cross7b60cdd2017-12-21 13:52:58 -08001148 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1149 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1150 // any if len(jars) == 1.
Colin Crosse9a275b2017-10-16 17:09:48 -07001151 outputFile = jars[0]
1152 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001153 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001154 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
1155 false, stripFiles, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001156 outputFile = combinedJar
1157 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001158
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001159 // Use renamed kotlin standard library?
Colin Crossff3ae9d2018-04-10 16:15:18 -07001160 if srcFiles.HasExt(".kt") && Bool(j.properties.Renamed_kotlin_stdlib) {
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001161 jarjarFile := android.PathForModuleOut(ctx, "kotlin-renamed", jarName)
1162 TransformJarJar(ctx, jarjarFile, outputFile,
1163 android.PathForSource(ctx, "external/kotlinc/jarjar-rules.txt"))
1164 outputFile = jarjarFile
1165 if ctx.Failed() {
1166 return
1167 }
1168 }
1169
Colin Cross0a6e0072017-08-30 14:24:55 -07001170 if j.properties.Jarjar_rules != nil {
1171 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -07001172 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001173 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001174 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
1175 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -07001176 if ctx.Failed() {
1177 return
1178 }
1179 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001180 j.implementationJarFile = outputFile
1181 if j.headerJarFile == nil {
1182 j.headerJarFile = j.implementationJarFile
1183 }
Colin Cross2fe66872015-03-30 17:20:39 -07001184
Colin Cross6510f912017-11-29 00:27:14 -08001185 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -08001186 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
1187 j.properties.Instrument = true
1188 }
1189 }
1190
Colin Cross3144dfc2018-01-03 15:06:47 -08001191 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001192 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1193 }
1194
Colin Cross9ae1b922018-06-26 17:59:05 -07001195 if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
David Brazdil17ef5632018-06-27 10:27:45 +01001196 var dexOutputFile android.Path
1197 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001198 if ctx.Failed() {
1199 return
1200 }
Colin Cross9ae1b922018-06-26 17:59:05 -07001201 if Bool(j.properties.Installable) {
David Brazdil17ef5632018-06-27 10:27:45 +01001202 outputFile = dexOutputFile
1203 }
Colin Cross2fe66872015-03-30 17:20:39 -07001204 }
Colin Crossb7a63242015-04-16 14:09:14 -07001205 ctx.CheckbuildFile(outputFile)
1206 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -07001207}
1208
Colin Cross8eadbf02017-10-24 17:46:00 -07001209func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Nan Zhanged19fc32017-10-19 13:06:22 -07001210 deps deps, flags javaBuilderFlags, jarName string) android.Path {
1211
1212 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001213 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001214 // Compile java sources into turbine.jar.
1215 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1216 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1217 if ctx.Failed() {
1218 return nil
1219 }
1220 jars = append(jars, turbineJar)
1221 }
1222
1223 // Combine any static header libraries into classes-header.jar. If there is only
1224 // one input jar this step will be skipped.
1225 var headerJar android.Path
1226 jars = append(jars, deps.staticHeaderJars...)
1227
Colin Cross5c6ecc12017-10-23 18:12:27 -07001228 // we cannot skip the combine step for now if there is only one jar
1229 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1230 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001231 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
1232 false, nil, []string{"META-INF"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001233 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001234
1235 if j.properties.Jarjar_rules != nil {
1236 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
1237 // Transform classes.jar into classes-jarjar.jar
1238 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
1239 TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules)
1240 headerJar = jarjarFile
1241 if ctx.Failed() {
1242 return nil
1243 }
1244 }
1245
1246 return headerJar
1247}
1248
Colin Crosscb933592017-11-22 13:49:43 -08001249func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
1250 classesJar android.Path, jarName string) android.Path {
1251
Colin Cross7a3139e2017-12-19 13:57:50 -08001252 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001253
Colin Cross84c38822018-01-03 15:59:46 -08001254 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001255 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1256
1257 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1258
1259 j.jacocoReportClassesFile = jacocoReportClassesFile
1260
1261 return instrumentedJar
1262}
1263
Colin Crossf506d872017-07-19 15:53:04 -07001264var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001265
Nan Zhanged19fc32017-10-19 13:06:22 -07001266func (j *Module) HeaderJars() android.Paths {
1267 return android.Paths{j.headerJarFile}
1268}
1269
1270func (j *Module) ImplementationJars() android.Paths {
1271 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001272}
1273
Colin Cross46c9b8b2017-06-22 16:51:17 -07001274func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001275 return j.exportAidlIncludeDirs
1276}
1277
Jiyong Park1be96912018-05-28 18:02:19 +09001278func (j *Module) ExportedSdkLibs() []string {
1279 return j.exportedSdkLibs
1280}
1281
Colin Cross46c9b8b2017-06-22 16:51:17 -07001282var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001283
Colin Cross46c9b8b2017-06-22 16:51:17 -07001284func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001285 return j.logtagsSrcs
1286}
1287
Colin Cross2fe66872015-03-30 17:20:39 -07001288//
1289// Java libraries (.jar file)
1290//
1291
Colin Crossf506d872017-07-19 15:53:04 -07001292type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001293 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001294}
1295
Colin Crossf506d872017-07-19 15:53:04 -07001296func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001297 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001298
Colin Cross9ae1b922018-06-26 17:59:05 -07001299 if Bool(j.properties.Installable) || ctx.Host() {
Colin Cross2c429dc2017-08-31 16:45:16 -07001300 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1301 ctx.ModuleName()+".jar", j.outputFile)
1302 }
Colin Crossb7a63242015-04-16 14:09:14 -07001303}
1304
Colin Crossf506d872017-07-19 15:53:04 -07001305func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001306 j.deps(ctx)
1307}
1308
Colin Cross9ae1b922018-06-26 17:59:05 -07001309func LibraryFactory() android.Module {
1310 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001311
Colin Cross9ae1b922018-06-26 17:59:05 -07001312 module.AddProperties(
1313 &module.Module.properties,
1314 &module.Module.deviceProperties,
1315 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001316
Colin Cross9ae1b922018-06-26 17:59:05 -07001317 InitJavaModule(module, android.HostAndDeviceSupported)
1318 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001319}
1320
Colin Crossf506d872017-07-19 15:53:04 -07001321func LibraryHostFactory() android.Module {
1322 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001323
Colin Cross6af17aa2017-09-20 12:59:05 -07001324 module.AddProperties(
1325 &module.Module.properties,
1326 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001327
Colin Cross9ae1b922018-06-26 17:59:05 -07001328 module.Module.properties.Installable = proptools.BoolPtr(true)
1329
Colin Cross89536d42017-07-07 14:35:50 -07001330 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001331 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001332}
1333
1334//
Colin Cross05638fc2018-04-09 18:40:24 -07001335// Java Junit Tests
1336//
1337
1338type testProperties struct {
1339 // If true, add a static dependency on the platform junit library. Defaults to true.
1340 Junit *bool
1341
1342 // list of compatibility suites (for example "cts", "vts") that the module should be
1343 // installed into.
1344 Test_suites []string `android:"arch_variant"`
1345}
1346
1347type Test struct {
1348 Library
1349
1350 testProperties testProperties
1351}
1352
1353func (j *Test) DepsMutator(ctx android.BottomUpMutatorContext) {
1354 j.deps(ctx)
Colin Cross38b40df2018-04-10 16:14:46 -07001355 if BoolDefault(j.testProperties.Junit, true) {
Colin Cross05638fc2018-04-09 18:40:24 -07001356 ctx.AddDependency(ctx.Module(), staticLibTag, "junit")
1357 }
1358}
1359
1360func TestFactory() android.Module {
1361 module := &Test{}
1362
1363 module.AddProperties(
1364 &module.Module.properties,
1365 &module.Module.deviceProperties,
1366 &module.Module.protoProperties,
1367 &module.testProperties)
1368
Colin Cross9ae1b922018-06-26 17:59:05 -07001369 module.Module.properties.Installable = proptools.BoolPtr(true)
1370
Colin Cross05638fc2018-04-09 18:40:24 -07001371 InitJavaModule(module, android.HostAndDeviceSupported)
1372 android.InitDefaultableModule(module)
1373 return module
1374}
1375
1376func TestHostFactory() android.Module {
1377 module := &Test{}
1378
1379 module.AddProperties(
1380 &module.Module.properties,
1381 &module.Module.protoProperties,
1382 &module.testProperties)
1383
Colin Cross9ae1b922018-06-26 17:59:05 -07001384 module.Module.properties.Installable = proptools.BoolPtr(true)
1385
Colin Cross05638fc2018-04-09 18:40:24 -07001386 InitJavaModule(module, android.HostSupported)
1387 android.InitDefaultableModule(module)
1388 return module
1389}
1390
1391//
Colin Cross2fe66872015-03-30 17:20:39 -07001392// Java Binaries (.jar file plus wrapper script)
1393//
1394
Colin Crossf506d872017-07-19 15:53:04 -07001395type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001396 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001397 Wrapper *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001398}
1399
Colin Crossf506d872017-07-19 15:53:04 -07001400type Binary struct {
1401 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001402
Colin Crossf506d872017-07-19 15:53:04 -07001403 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001404
Colin Cross6b4a32d2017-12-05 13:42:45 -08001405 isWrapperVariant bool
1406
Colin Crossc3315992017-12-08 19:12:36 -08001407 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001408 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001409}
1410
Alex Light24237172017-10-26 09:46:21 -07001411func (j *Binary) HostToolPath() android.OptionalPath {
1412 return android.OptionalPathForPath(j.binaryFile)
1413}
1414
Colin Crossf506d872017-07-19 15:53:04 -07001415func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001416 if ctx.Arch().ArchType == android.Common {
1417 // Compile the jar
1418 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001419 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001420 // Handle the binary wrapper
1421 j.isWrapperVariant = true
1422
Colin Cross366938f2017-12-11 16:29:02 -08001423 if j.binaryProperties.Wrapper != nil {
1424 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001425 } else {
1426 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1427 }
1428
1429 // Depend on the installed jar so that the wrapper doesn't get executed by
1430 // another build rule before the jar has been installed.
1431 jarFile := ctx.PrimaryModule().(*Binary).installFile
1432
1433 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1434 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001435 }
Colin Cross2fe66872015-03-30 17:20:39 -07001436}
1437
Colin Crossf506d872017-07-19 15:53:04 -07001438func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001439 if ctx.Arch().ArchType == android.Common {
1440 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001441 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001442 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001443 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001444}
1445
Colin Crossf506d872017-07-19 15:53:04 -07001446func BinaryFactory() android.Module {
1447 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001448
Colin Cross36242852017-06-23 15:06:31 -07001449 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001450 &module.Module.properties,
1451 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001452 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001453 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001454
Colin Cross9ae1b922018-06-26 17:59:05 -07001455 module.Module.properties.Installable = proptools.BoolPtr(true)
1456
Colin Cross6b4a32d2017-12-05 13:42:45 -08001457 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1458 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001459 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001460}
1461
Colin Crossf506d872017-07-19 15:53:04 -07001462func BinaryHostFactory() android.Module {
1463 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001464
Colin Cross36242852017-06-23 15:06:31 -07001465 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001466 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001467 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001468 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001469
Colin Cross9ae1b922018-06-26 17:59:05 -07001470 module.Module.properties.Installable = proptools.BoolPtr(true)
1471
Colin Cross6b4a32d2017-12-05 13:42:45 -08001472 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1473 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001474 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001475}
1476
1477//
1478// Java prebuilts
1479//
1480
Colin Cross74d73e22017-08-02 11:05:49 -07001481type ImportProperties struct {
1482 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001483
Nan Zhangea568a42017-11-08 21:20:04 -08001484 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001485
1486 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001487
1488 // List of shared java libs that this module has dependencies to
1489 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07001490
1491 // List of files to remove from the jar file(s)
1492 Exclude_files []string
1493
1494 // List of directories to remove from the jar file(s)
1495 Exclude_dirs []string
Colin Cross74d73e22017-08-02 11:05:49 -07001496}
1497
1498type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001499 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001500 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001501
Colin Cross74d73e22017-08-02 11:05:49 -07001502 properties ImportProperties
1503
Colin Cross0a6e0072017-08-30 14:24:55 -07001504 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09001505 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07001506}
1507
Colin Cross83bb3162018-06-25 15:48:06 -07001508func (j *Import) sdkVersion() string {
1509 return String(j.properties.Sdk_version)
1510}
1511
1512func (j *Import) minSdkVersion() string {
1513 return j.sdkVersion()
1514}
1515
Colin Cross74d73e22017-08-02 11:05:49 -07001516func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001517 return &j.prebuilt
1518}
1519
Colin Cross74d73e22017-08-02 11:05:49 -07001520func (j *Import) PrebuiltSrcs() []string {
1521 return j.properties.Jars
1522}
1523
1524func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001525 return j.prebuilt.Name(j.ModuleBase.Name())
1526}
1527
Colin Cross74d73e22017-08-02 11:05:49 -07001528func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001529 android.ExtractSourcesDeps(ctx, j.properties.Jars)
Jiyong Park1be96912018-05-28 18:02:19 +09001530 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07001531}
1532
Colin Cross74d73e22017-08-02 11:05:49 -07001533func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001534 jars := ctx.ExpandSources(j.properties.Jars, nil)
Colin Crosse1d62a82015-04-03 16:53:05 -07001535
Colin Crosse9a275b2017-10-16 17:09:48 -07001536 outputFile := android.PathForModuleOut(ctx, "classes.jar")
Colin Cross37f6d792018-07-12 12:28:41 -07001537 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
1538 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Colin Crosse9a275b2017-10-16 17:09:48 -07001539 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09001540
1541 ctx.VisitDirectDeps(func(module android.Module) {
1542 otherName := ctx.OtherModuleName(module)
1543 tag := ctx.OtherModuleDependencyTag(module)
1544
1545 switch dep := module.(type) {
1546 case Dependency:
1547 switch tag {
1548 case libTag, staticLibTag:
1549 // sdk lib names from dependencies are re-exported
1550 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
1551 }
1552 case SdkLibraryDependency:
1553 switch tag {
1554 case libTag:
1555 // names of sdk libs that are directly depended are exported
1556 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
1557 }
1558 }
1559 })
1560
1561 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Colin Cross2fe66872015-03-30 17:20:39 -07001562}
1563
Colin Cross74d73e22017-08-02 11:05:49 -07001564var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001565
Nan Zhanged19fc32017-10-19 13:06:22 -07001566func (j *Import) HeaderJars() android.Paths {
Colin Cross37f6d792018-07-12 12:28:41 -07001567 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07001568}
1569
1570func (j *Import) ImplementationJars() android.Paths {
Colin Cross37f6d792018-07-12 12:28:41 -07001571 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001572}
1573
Colin Cross74d73e22017-08-02 11:05:49 -07001574func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001575 return nil
1576}
1577
Jiyong Park1be96912018-05-28 18:02:19 +09001578func (j *Import) ExportedSdkLibs() []string {
1579 return j.exportedSdkLibs
1580}
1581
Colin Cross74d73e22017-08-02 11:05:49 -07001582var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001583
Colin Cross74d73e22017-08-02 11:05:49 -07001584func ImportFactory() android.Module {
1585 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001586
Colin Cross74d73e22017-08-02 11:05:49 -07001587 module.AddProperties(&module.properties)
1588
1589 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -07001590 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1591 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001592}
1593
Colin Cross74d73e22017-08-02 11:05:49 -07001594func ImportFactoryHost() android.Module {
1595 module := &Import{}
1596
1597 module.AddProperties(&module.properties)
1598
1599 android.InitPrebuiltModule(module, &module.properties.Jars)
1600 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
1601 return module
1602}
1603
Colin Cross89536d42017-07-07 14:35:50 -07001604//
1605// Defaults
1606//
1607type Defaults struct {
1608 android.ModuleBase
1609 android.DefaultsModuleBase
1610}
1611
1612func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1613}
1614
1615func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1616}
1617
1618func defaultsFactory() android.Module {
1619 return DefaultsFactory()
1620}
1621
1622func DefaultsFactory(props ...interface{}) android.Module {
1623 module := &Defaults{}
1624
1625 module.AddProperties(props...)
1626 module.AddProperties(
1627 &CompilerProperties{},
1628 &CompilerDeviceProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001629 &android.ProtoProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07001630 )
1631
1632 android.InitDefaultsModule(module)
1633
1634 return module
1635}
Nan Zhangea568a42017-11-08 21:20:04 -08001636
1637var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001638var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08001639var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08001640var inList = android.InList