blob: 06d35644dffd5e850e0f9e53c8b0f0cd93816cc1 [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
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100196
197 // whether to generate Binder#GetTransaction name method.
198 Generate_get_transaction_name *bool
Colin Crossebe1a512017-11-14 13:12:14 -0800199 }
Colin Cross92430102017-10-09 14:59:32 -0700200
201 // If true, export a copy of the module as a -hostdex module for host testing.
202 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700203
David Brazdil17ef5632018-06-27 10:27:45 +0100204 // If set to true, compile dex regardless of installable. Defaults to false.
205 Compile_dex *bool
206
Colin Cross1bd87802017-12-05 15:31:19 -0800207 Dex_preopt struct {
208 // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to
209 // true.
210 Enabled *bool
211
212 // If true, generate an app image (.art file) for this module.
213 App_image *bool
214
215 // If true, use a checked-in profile to guide optimization. Defaults to false unless
216 // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR
217 // that matches the name of this module, in which case it is defaulted to true.
218 Profile_guided *bool
219
220 // If set, provides the path to profile relative to the Android.bp file. If not set,
221 // defaults to searching for a file that matches the name of this module in the default
222 // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found.
223 Profile *string
224 }
Colin Crossa22116e2017-10-19 14:18:58 -0700225
Colin Cross66dbc0b2017-12-28 12:23:20 -0800226 Optimize struct {
Colin Crossae5caf52018-05-22 11:11:52 -0700227 // If false, disable all optimization. Defaults to true for android_app and android_test
228 // modules, false for java_library and java_test modules.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800229 Enabled *bool
230
231 // If true, optimize for size by removing unused code. Defaults to true for apps,
232 // false for libraries and tests.
233 Shrink *bool
234
235 // If true, optimize bytecode. Defaults to false.
236 Optimize *bool
237
238 // If true, obfuscate bytecode. Defaults to false.
239 Obfuscate *bool
240
241 // If true, do not use the flag files generated by aapt that automatically keep
242 // classes referenced by the app manifest. Defaults to false.
243 No_aapt_flags *bool
244
245 // Flags to pass to proguard.
246 Proguard_flags []string
247
248 // Specifies the locations of files containing proguard flags.
249 Proguard_flags_files []string
250 }
251
Colin Cross1369cdb2017-09-29 17:58:17 -0700252 // When targeting 1.9, override the modules to use with --system
253 System_modules *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700254}
255
Colin Cross46c9b8b2017-06-22 16:51:17 -0700256// Module contains the properties and members used by all java module types
257type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700258 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700259 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700260
Colin Cross89536d42017-07-07 14:35:50 -0700261 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700262 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700263 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700264
Nan Zhanged19fc32017-10-19 13:06:22 -0700265 // header jar file suitable for inserting into the bootclasspath/classpath of another compile
266 headerJarFile android.Path
267
268 // full implementation jar file suitable for static dependency of another module compile
269 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700270
Colin Cross6ade34f2017-09-15 13:00:47 -0700271 // output file containing classes.dex
272 dexJarFile android.Path
273
Colin Crosscb933592017-11-22 13:49:43 -0800274 // output file containing uninstrumented classes that will be instrumented by jacoco
275 jacocoReportClassesFile android.Path
276
Colin Cross66dbc0b2017-12-28 12:23:20 -0800277 // output file containing mapping of obfuscated names
278 proguardDictionary android.Path
279
Colin Crossb7a63242015-04-16 14:09:14 -0700280 // output file suitable for installing or running
Colin Cross635c3b02016-05-18 15:37:25 -0700281 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700282
Colin Cross635c3b02016-05-18 15:37:25 -0700283 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700284
Colin Cross635c3b02016-05-18 15:37:25 -0700285 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700286
Colin Cross2fe66872015-03-30 17:20:39 -0700287 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700288 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800289
290 // list of .java files and srcjars that was passed to javac
291 compiledJavaSrcs android.Paths
292 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800293
294 // list of extra progurad flag files
295 extraProguardFlagFiles android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900296
297 // list of SDK lib names that this java moudule is exporting
298 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -0700299}
300
Colin Cross54250902017-12-05 09:28:08 -0800301func (j *Module) Srcs() android.Paths {
302 return android.Paths{j.implementationJarFile}
303}
304
305var _ android.SourceFileProducer = (*Module)(nil)
306
Colin Crossf506d872017-07-19 15:53:04 -0700307type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700308 HeaderJars() android.Paths
309 ImplementationJars() android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700310 AidlIncludeDirs() android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900311 ExportedSdkLibs() []string
Colin Cross2fe66872015-03-30 17:20:39 -0700312}
313
Jiyong Parkc678ad32018-04-10 13:07:10 +0900314type SdkLibraryDependency interface {
315 HeaderJars(linkType linkType) android.Paths
316}
317
Nan Zhangb2b33de2018-02-23 11:18:47 -0800318type SrcDependency interface {
319 CompiledSrcs() android.Paths
320 CompiledSrcJars() android.Paths
321}
322
323func (j *Module) CompiledSrcs() android.Paths {
324 return j.compiledJavaSrcs
325}
326
327func (j *Module) CompiledSrcJars() android.Paths {
328 return j.compiledSrcJars
329}
330
331var _ SrcDependency = (*Module)(nil)
332
Colin Cross89536d42017-07-07 14:35:50 -0700333func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
334 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
335 android.InitDefaultableModule(module)
336}
337
Colin Crossbe1da472017-07-07 15:59:46 -0700338type dependencyTag struct {
339 blueprint.BaseDependencyTag
340 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700341}
342
Colin Crossbe1da472017-07-07 15:59:46 -0700343var (
Colin Cross6ade34f2017-09-15 13:00:47 -0700344 staticLibTag = dependencyTag{name: "staticlib"}
345 libTag = dependencyTag{name: "javalib"}
Colin Cross6a77c982018-06-19 22:43:34 -0700346 annoTag = dependencyTag{name: "annotation processor"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700347 bootClasspathTag = dependencyTag{name: "bootclasspath"}
Colin Cross1369cdb2017-09-29 17:58:17 -0700348 systemModulesTag = dependencyTag{name: "system modules"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700349 frameworkResTag = dependencyTag{name: "framework-res"}
Nan Zhangb2b33de2018-02-23 11:18:47 -0800350 frameworkApkTag = dependencyTag{name: "framework-apk"}
Colin Cross93e85952017-08-15 13:34:18 -0700351 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Cross66dbc0b2017-12-28 12:23:20 -0800352 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
Colin Crossbe1da472017-07-07 15:59:46 -0700353)
Colin Cross2fe66872015-03-30 17:20:39 -0700354
Colin Crossfc3674a2017-09-18 17:41:52 -0700355type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700356 useModule, useFiles, useDefaultLibs, invalidVersion bool
357
Colin Cross86a60ae2018-05-29 14:44:55 -0700358 modules []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700359 systemModules string
360
Colin Crossa97c5d32018-03-28 14:58:31 -0700361 frameworkResModule string
362
Colin Cross86a60ae2018-05-29 14:44:55 -0700363 jars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700364 aidl android.Path
365}
366
Colin Cross3144dfc2018-01-03 15:06:47 -0800367func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
368 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
369}
370
371func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
372 return j.shouldInstrument(ctx) &&
373 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
374 ctx.Config().UnbundledBuild())
375}
376
Colin Cross83bb3162018-06-25 15:48:06 -0700377func (j *Module) sdkVersion() string {
378 return String(j.deviceProperties.Sdk_version)
379}
380
381func (j *Module) minSdkVersion() string {
382 if j.deviceProperties.Min_sdk_version != nil {
383 return *j.deviceProperties.Min_sdk_version
384 }
385 return j.sdkVersion()
386}
387
388type sdkContext interface {
389 // sdkVersion eturns the sdk_version property of the current module, or an empty string if it is not set.
390 sdkVersion() string
391 // minSdkVersion returns the min_sdk_version property of the current module, or sdkVersion() if it is not set.
392 minSdkVersion() string
393}
394
395func sdkVersionOrDefault(ctx android.BaseContext, v string) string {
396 switch v {
397 case "", "current", "system_current", "test_current", "core_current":
398 return ctx.Config().DefaultAppTargetSdk()
399 default:
400 return v
401 }
402}
403
404// Returns a sdk version as a number. For modules targeting an unreleased SDK (meaning it does not yet have a number)
405// it returns android.FutureApiLevel (10000).
406func sdkVersionToNumber(ctx android.BaseContext, v string) (int, error) {
407 switch v {
408 case "", "current", "test_current", "system_current", "core_current":
409 return ctx.Config().DefaultAppTargetSdkInt(), nil
410 default:
411 n := android.GetNumericSdkVersion(v)
412 if i, err := strconv.Atoi(n); err != nil {
413 return -1, fmt.Errorf("invalid sdk version %q", n)
414 } else {
415 return i, nil
416 }
417 }
418}
419
420func sdkVersionToNumberAsString(ctx android.BaseContext, v string) (string, error) {
421 n, err := sdkVersionToNumber(ctx, v)
422 if err != nil {
423 return "", err
424 }
425 return strconv.Itoa(n), nil
426}
427
428func decodeSdkDep(ctx android.BaseContext, sdkContext sdkContext) sdkDep {
429 v := sdkContext.sdkVersion()
430 i, err := sdkVersionToNumber(ctx, v)
431 if err != nil {
432 ctx.PropertyErrorf("sdk_version", "%s", err)
Colin Cross1369cdb2017-09-29 17:58:17 -0700433 return sdkDep{}
Colin Crossfc3674a2017-09-18 17:41:52 -0700434 }
435
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900436 // Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks)
437 // or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set)
438 if strings.HasPrefix(v, "system_") && i != android.FutureApiLevel {
439 allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions()
440 if ctx.DeviceSpecific() || ctx.SocSpecific() {
441 if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 {
442 allowed_versions = ctx.DeviceConfig().SystemSdkVersions()
443 }
444 }
445 version := strings.TrimPrefix(v, "system_")
446 if len(allowed_versions) > 0 && !android.InList(version, allowed_versions) {
447 ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q",
448 v, allowed_versions)
449 }
450 }
451
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100452 toPrebuilt := func(sdk string) sdkDep {
453 var api, v string
454 if strings.Contains(sdk, "_") {
455 t := strings.Split(sdk, "_")
456 api = t[0]
457 v = t[1]
458 } else {
459 api = "public"
460 v = sdk
Jiyong Park750e5572018-01-31 00:20:13 +0900461 }
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100462 dir := filepath.Join("prebuilts", "sdk", v, api)
Colin Crossfc3674a2017-09-18 17:41:52 -0700463 jar := filepath.Join(dir, "android.jar")
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100464 // There's no aidl for other SDKs yet.
465 // TODO(77525052): Add aidl files for other SDKs too.
466 public_dir := filepath.Join("prebuilts", "sdk", v, "public")
467 aidl := filepath.Join(public_dir, "framework.aidl")
Colin Cross32f38982018-02-22 11:47:25 -0800468 jarPath := android.ExistentPathForSource(ctx, jar)
469 aidlPath := android.ExistentPathForSource(ctx, aidl)
Colin Cross86a60ae2018-05-29 14:44:55 -0700470 lambdaStubsPath := android.PathForSource(ctx, config.SdkLambdaStubsPath)
Colin Cross47ff2522017-10-02 14:22:08 -0700471
Colin Cross6510f912017-11-29 00:27:14 -0800472 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
Colin Cross47ff2522017-10-02 14:22:08 -0700473 return sdkDep{
474 invalidVersion: true,
Colin Cross86a60ae2018-05-29 14:44:55 -0700475 modules: []string{fmt.Sprintf("sdk_%s_%s_android", api, v)},
Colin Cross47ff2522017-10-02 14:22:08 -0700476 }
477 }
478
Colin Crossfc3674a2017-09-18 17:41:52 -0700479 if !jarPath.Valid() {
480 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar)
481 return sdkDep{}
482 }
Colin Cross47ff2522017-10-02 14:22:08 -0700483
Colin Crossfc3674a2017-09-18 17:41:52 -0700484 if !aidlPath.Valid() {
485 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl)
486 return sdkDep{}
487 }
Colin Cross47ff2522017-10-02 14:22:08 -0700488
Colin Crossfc3674a2017-09-18 17:41:52 -0700489 return sdkDep{
490 useFiles: true,
Colin Cross86a60ae2018-05-29 14:44:55 -0700491 jars: android.Paths{jarPath.Path(), lambdaStubsPath},
Colin Crossfc3674a2017-09-18 17:41:52 -0700492 aidl: aidlPath.Path(),
493 }
494 }
495
Colin Crossa97c5d32018-03-28 14:58:31 -0700496 toModule := func(m, r string) sdkDep {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700497 ret := sdkDep{
Colin Crossa97c5d32018-03-28 14:58:31 -0700498 useModule: true,
Colin Cross86a60ae2018-05-29 14:44:55 -0700499 modules: []string{m, config.DefaultLambdaStubsLibrary},
Colin Crossa97c5d32018-03-28 14:58:31 -0700500 systemModules: m + "_system_modules",
501 frameworkResModule: r,
Colin Crossf19b9bb2018-03-26 14:42:44 -0700502 }
503 if m == "core.current.stubs" {
504 ret.systemModules = "core-system-modules"
505 }
506 return ret
507 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700508
Colin Cross6510f912017-11-29 00:27:14 -0800509 if ctx.Config().UnbundledBuild() && v != "" {
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100510 return toPrebuilt(v)
Colin Crossfc3674a2017-09-18 17:41:52 -0700511 }
512
513 switch v {
514 case "":
515 return sdkDep{
Colin Crossa97c5d32018-03-28 14:58:31 -0700516 useDefaultLibs: true,
517 frameworkResModule: "framework-res",
Colin Crossfc3674a2017-09-18 17:41:52 -0700518 }
Colin Crossf19b9bb2018-03-26 14:42:44 -0700519 case "current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700520 return toModule("android_stubs_current", "framework-res")
Colin Crossf19b9bb2018-03-26 14:42:44 -0700521 case "system_current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700522 return toModule("android_system_stubs_current", "framework-res")
Colin Crossf19b9bb2018-03-26 14:42:44 -0700523 case "test_current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700524 return toModule("android_test_stubs_current", "framework-res")
Colin Crossf19b9bb2018-03-26 14:42:44 -0700525 case "core_current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700526 return toModule("core.current.stubs", "")
Colin Crossfc3674a2017-09-18 17:41:52 -0700527 default:
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100528 return toPrebuilt(v)
Colin Crossfc3674a2017-09-18 17:41:52 -0700529 }
530}
531
Colin Crossbe1da472017-07-07 15:59:46 -0700532func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700533 if ctx.Device() {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700534 if !Bool(j.properties.No_standard_libs) {
Colin Cross83bb3162018-06-25 15:48:06 -0700535 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Crossfc3674a2017-09-18 17:41:52 -0700536 if sdkDep.useDefaultLibs {
Colin Crosscb2c9292017-09-23 19:57:16 -0700537 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Colin Cross6510f912017-11-29 00:27:14 -0800538 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700539 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
540 }
Colin Crossff3ae9d2018-04-10 16:15:18 -0700541 if !Bool(j.properties.No_framework_libs) {
Colin Crossfa5eb232017-10-01 20:33:03 -0700542 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
543 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700544 } else if sdkDep.useModule {
Colin Cross6510f912017-11-29 00:27:14 -0800545 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700546 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
547 }
Colin Cross86a60ae2018-05-29 14:44:55 -0700548 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800549 if Bool(j.deviceProperties.Optimize.Enabled) {
550 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultBootclasspathLibraries...)
551 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultLibraries...)
552 }
Colin Crossbe1da472017-07-07 15:59:46 -0700553 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700554 } else if j.deviceProperties.System_modules == nil {
555 ctx.PropertyErrorf("no_standard_libs",
556 "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 -0800557 } else if *j.deviceProperties.System_modules != "none" && ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700558 ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700559 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800560 if ctx.ModuleName() == "framework" {
561 ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res")
562 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800563 if ctx.ModuleName() == "android_stubs_current" ||
564 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang16c0a312018-06-13 17:42:48 -0700565 ctx.ModuleName() == "android_test_stubs_current" ||
566 ctx.ModuleName() == "metalava_android_stubs_current" ||
567 ctx.ModuleName() == "metalava_android_system_stubs_current" ||
568 ctx.ModuleName() == "metalava_android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800569 ctx.AddDependency(ctx.Module(), frameworkApkTag, "framework-res")
570 }
Colin Cross2fe66872015-03-30 17:20:39 -0700571 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700572
Colin Crossf506d872017-07-19 15:53:04 -0700573 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
574 ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
Mathew Inwood878c6622018-07-02 16:34:51 +0100575 ctx.AddFarVariationDependencies([]blueprint.Variation{
576 {"arch", ctx.Config().BuildOsCommonVariant},
577 }, annoTag, j.properties.Annotation_processors...)
Colin Cross7f9036c2017-08-30 13:27:57 -0700578 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Nan Zhang27e284d2018-02-09 21:03:53 +0000579 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700580 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross366938f2017-12-11 16:29:02 -0800581 android.ExtractSourceDeps(ctx, j.properties.Manifest)
Colin Cross6af17aa2017-09-20 12:59:05 -0700582
583 if j.hasSrcExt(".proto") {
584 protoDeps(ctx, &j.protoProperties)
585 }
Colin Cross93e85952017-08-15 13:34:18 -0700586
587 if j.hasSrcExt(".kt") {
588 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
589 // Kotlin files
590 ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib")
591 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800592
593 if j.shouldInstrumentStatic(ctx) {
594 ctx.AddDependency(ctx.Module(), staticLibTag, "jacocoagent")
595 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700596}
597
598func hasSrcExt(srcs []string, ext string) bool {
599 for _, src := range srcs {
600 if filepath.Ext(src) == ext {
601 return true
602 }
603 }
604
605 return false
606}
607
Nan Zhang61eaedb2017-11-02 13:28:15 -0700608func shardPaths(paths android.Paths, shardSize int) []android.Paths {
609 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
610 for len(paths) > shardSize {
611 ret = append(ret, paths[0:shardSize])
612 paths = paths[shardSize:]
613 }
614 if len(paths) > 0 {
615 ret = append(ret, paths)
616 }
617 return ret
618}
619
Colin Cross6af17aa2017-09-20 12:59:05 -0700620func (j *Module) hasSrcExt(ext string) bool {
621 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700622}
623
Colin Cross46c9b8b2017-06-22 16:51:17 -0700624func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700625 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700626
Colin Crossebe1a512017-11-14 13:12:14 -0800627 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
628 aidlIncludes = append(aidlIncludes,
629 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
630 aidlIncludes = append(aidlIncludes,
631 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700632
633 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700634 if aidlPreprocess.Valid() {
635 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700636 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700637 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700638 }
639
Colin Cross635c3b02016-05-18 15:37:25 -0700640 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800641 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700642 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800643 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700644 flags = append(flags, "-I"+src.String())
645 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700646
Martijn Coeneneab15642018-03-09 09:29:59 +0100647 if Bool(j.deviceProperties.Aidl.Generate_traces) {
648 flags = append(flags, "-t")
649 }
650
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100651 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
652 flags = append(flags, "--transaction_names")
653 }
654
Colin Crossf03c82b2015-04-13 13:53:40 -0700655 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700656}
657
Colin Cross32f676a2017-09-06 13:41:06 -0700658type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800659 classpath classpath
660 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700661 processorPath classpath
Colin Cross6ade34f2017-09-15 13:00:47 -0700662 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700663 staticHeaderJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700664 staticJarResources android.Paths
665 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800666 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700667 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700668 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700669 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700670 kotlinStdlib android.Paths
Colin Cross32f676a2017-09-06 13:41:06 -0700671}
Colin Cross2fe66872015-03-30 17:20:39 -0700672
Colin Cross54250902017-12-05 09:28:08 -0800673func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
674 for _, f := range dep.Srcs() {
675 if f.Ext() != ".jar" {
676 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
677 ctx.OtherModuleName(dep.(blueprint.Module)))
678 }
679 }
680}
681
Jiyong Park2d492942018-03-05 17:44:10 +0900682type linkType int
683
684const (
685 javaCore linkType = iota
686 javaSdk
687 javaSystem
688 javaPlatform
689)
690
Colin Crossf19b9bb2018-03-26 14:42:44 -0700691func getLinkType(m *Module, name string) linkType {
Colin Cross83bb3162018-06-25 15:48:06 -0700692 ver := m.sdkVersion()
Colin Cross86a60ae2018-05-29 14:44:55 -0700693 noStdLibs := Bool(m.properties.No_standard_libs)
Colin Crossf19b9bb2018-03-26 14:42:44 -0700694 switch {
Nan Zhang16c0a312018-06-13 17:42:48 -0700695 case name == "core.current.stubs" || ver == "core_current" || noStdLibs || name == "stub-annotations":
Jiyong Park2d492942018-03-05 17:44:10 +0900696 return javaCore
Nan Zhang16c0a312018-06-13 17:42:48 -0700697 case name == "android_system_stubs_current" || strings.HasPrefix(ver, "system_") || name == "metalava_android_system_stubs_current":
Jiyong Park2d492942018-03-05 17:44:10 +0900698 return javaSystem
Nan Zhang16c0a312018-06-13 17:42:48 -0700699 case name == "android_test_stubs_current" || strings.HasPrefix(ver, "test_") || name == "metalava_android_test_stubs_current":
Jiyong Park2d492942018-03-05 17:44:10 +0900700 return javaPlatform
Nan Zhang16c0a312018-06-13 17:42:48 -0700701 case name == "android_stubs_current" || ver == "current" || name == "metalava_android_stubs_current":
Colin Crossf19b9bb2018-03-26 14:42:44 -0700702 return javaSdk
703 case ver == "":
704 return javaPlatform
705 default:
706 if _, err := strconv.Atoi(ver); err != nil {
707 panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver))
708 }
709 return javaSdk
Jiyong Park2d492942018-03-05 17:44:10 +0900710 }
711}
712
Jiyong Park750e5572018-01-31 00:20:13 +0900713func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700714 if ctx.Host() {
715 return
716 }
717
718 myLinkType := getLinkType(from, ctx.ModuleName())
719 otherLinkType := getLinkType(&to.Module, ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900720 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."
721
722 switch myLinkType {
723 case javaCore:
724 if otherLinkType != javaCore {
725 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 +0900726 ctx.OtherModuleName(to))
727 }
Jiyong Park2d492942018-03-05 17:44:10 +0900728 break
729 case javaSdk:
730 if otherLinkType != javaCore && otherLinkType != javaSdk {
731 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
732 ctx.OtherModuleName(to))
733 }
734 break
735 case javaSystem:
736 if otherLinkType == javaPlatform {
737 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
738 ctx.OtherModuleName(to))
739 }
740 break
741 case javaPlatform:
742 // no restriction on link-type
743 break
Jiyong Park750e5572018-01-31 00:20:13 +0900744 }
745}
746
Colin Cross32f676a2017-09-06 13:41:06 -0700747func (j *Module) collectDeps(ctx android.ModuleContext) deps {
748 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700749
Colin Cross300f0382018-03-06 13:11:51 -0800750 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700751 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800752 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700753 ctx.AddMissingDependencies(sdkDep.modules)
Colin Cross300f0382018-03-06 13:11:51 -0800754 } else if sdkDep.useFiles {
755 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700756 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross300f0382018-03-06 13:11:51 -0800757 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
758 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700759 }
760
Colin Crossd11fcda2017-10-23 17:59:01 -0700761 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700762 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700763 tag := ctx.OtherModuleDependencyTag(module)
764
Jiyong Park750e5572018-01-31 00:20:13 +0900765 if to, ok := module.(*Library); ok {
Colin Crossa97c5d32018-03-28 14:58:31 -0700766 switch tag {
767 case bootClasspathTag, libTag, staticLibTag:
768 checkLinkType(ctx, j, to, tag.(dependencyTag))
769 }
Jiyong Park750e5572018-01-31 00:20:13 +0900770 }
Colin Cross54250902017-12-05 09:28:08 -0800771 switch dep := module.(type) {
772 case Dependency:
773 switch tag {
774 case bootClasspathTag:
775 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
776 case libTag:
777 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900778 // sdk lib names from dependencies are re-exported
779 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross54250902017-12-05 09:28:08 -0800780 case staticLibTag:
781 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
782 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
783 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900784 // sdk lib names from dependencies are re-exported
785 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross6a77c982018-06-19 22:43:34 -0700786 case annoTag:
787 deps.processorPath = append(deps.processorPath, dep.ImplementationJars()...)
Colin Cross54250902017-12-05 09:28:08 -0800788 case frameworkResTag:
789 if ctx.ModuleName() == "framework" {
790 // framework.jar has a one-off dependency on the R.java and Manifest.java files
791 // generated by framework-res.apk
792 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
793 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800794 case frameworkApkTag:
795 if ctx.ModuleName() == "android_stubs_current" ||
796 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang16c0a312018-06-13 17:42:48 -0700797 ctx.ModuleName() == "android_test_stubs_current" ||
798 ctx.ModuleName() == "metalava_android_stubs_current" ||
799 ctx.ModuleName() == "metalava_android_system_stubs_current" ||
800 ctx.ModuleName() == "metalava_android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800801 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
802 // resource files out of there for aapt.
803 //
804 // Normally the package rule runs aapt, which includes the resource,
805 // but we're not running that in our package rule so just copy in the
806 // resource files here.
807 deps.staticJarResources = append(deps.staticJarResources, dep.(*AndroidApp).exportPackage)
808 }
Colin Cross54250902017-12-05 09:28:08 -0800809 case kotlinStdlibTag:
810 deps.kotlinStdlib = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -0800811 }
812
813 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900814 case SdkLibraryDependency:
815 switch tag {
816 case libTag:
817 deps.classpath = append(deps.classpath, dep.HeaderJars(getLinkType(j, ctx.ModuleName()))...)
Jiyong Park1be96912018-05-28 18:02:19 +0900818 // names of sdk libs that are directly depended are exported
819 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900820 default:
821 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
822 }
Colin Cross54250902017-12-05 09:28:08 -0800823 case android.SourceFileProducer:
824 switch tag {
825 case libTag:
826 checkProducesJars(ctx, dep)
827 deps.classpath = append(deps.classpath, dep.Srcs()...)
828 case staticLibTag:
829 checkProducesJars(ctx, dep)
830 deps.classpath = append(deps.classpath, dep.Srcs()...)
831 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
832 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
833 case android.DefaultsDepTag, android.SourceDepTag:
834 // Nothing to do
835 default:
836 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
837 }
838 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700839 switch tag {
840 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700841 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700842 case systemModulesTag:
843 if deps.systemModules != nil {
844 panic("Found two system module dependencies")
845 }
846 sm := module.(*SystemModules)
847 if sm.outputFile == nil {
848 panic("Missing directory for system module dependency")
849 }
850 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700851 default:
852 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700853 }
Colin Crossec7a0422017-07-07 14:47:12 -0700854 }
Colin Cross2fe66872015-03-30 17:20:39 -0700855 })
856
Jiyong Park1be96912018-05-28 18:02:19 +0900857 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
858
Colin Cross32f676a2017-09-06 13:41:06 -0700859 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700860}
861
Colin Cross83bb3162018-06-25 15:48:06 -0700862func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string {
Nan Zhang357466b2018-04-17 17:38:36 -0700863 var ret string
Colin Cross83bb3162018-06-25 15:48:06 -0700864 sdk, err := sdkVersionToNumber(ctx, sdkContext.sdkVersion())
865 if err != nil {
866 ctx.PropertyErrorf("sdk_version", "%s", err)
867 }
Nan Zhang357466b2018-04-17 17:38:36 -0700868 if javaVersion != "" {
869 ret = javaVersion
870 } else if ctx.Device() && sdk <= 23 {
871 ret = "1.7"
872 } else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
873 ret = "1.8"
Colin Cross83bb3162018-06-25 15:48:06 -0700874 } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel {
Nan Zhang357466b2018-04-17 17:38:36 -0700875 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
876 ret = "1.8"
877 } else {
878 ret = "1.9"
879 }
880
881 return ret
882}
883
Nan Zhanged19fc32017-10-19 13:06:22 -0700884func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700885
Colin Crossf03c82b2015-04-13 13:53:40 -0700886 var flags javaBuilderFlags
887
Nan Zhanged19fc32017-10-19 13:06:22 -0700888 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700889 javacFlags := j.properties.Javacflags
Colin Cross6510f912017-11-29 00:27:14 -0800890 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700891 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700892 }
Colin Cross6510f912017-11-29 00:27:14 -0800893 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700894 // Override the -g flag passed globally to remove local variable debug info to reduce
895 // disk and memory usage.
896 javacFlags = append(javacFlags, "-g:source,lines")
897 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700898 if len(javacFlags) > 0 {
899 // optimization.
900 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
901 flags.javacFlags = "$javacFlags"
Colin Cross4f26bc02017-09-06 12:52:16 -0700902 }
Colin Cross64162712017-08-08 13:17:59 -0700903
Colin Cross66548102018-06-19 22:47:35 -0700904 if ctx.Config().RunErrorProne() {
905 if config.ErrorProneClasspath == nil {
906 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
907 }
908
909 errorProneFlags := []string{
910 "-Xplugin:ErrorProne",
911 "${config.ErrorProneChecks}",
912 }
913 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
914
915 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
916 "'" + strings.Join(errorProneFlags, " ") + "'"
917 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -0800918 }
919
Nan Zhanged19fc32017-10-19 13:06:22 -0700920 // javaVersion flag.
Colin Cross83bb3162018-06-25 15:48:06 -0700921 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross64162712017-08-08 13:17:59 -0700922
Nan Zhanged19fc32017-10-19 13:06:22 -0700923 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800924 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
925 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -0700926 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800927
928 if len(flags.bootClasspath) == 0 && ctx.Host() && !ctx.Config().TargetOpenJDK9() &&
929 !Bool(j.properties.No_standard_libs) &&
930 inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
931 // Give host-side tools a version of OpenJDK's standard libraries
932 // close to what they're targeting. As of Dec 2017, AOSP is only
933 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
934 //
935 // When building with OpenJDK 8, the following should have no
936 // effect since those jars would be available by default.
937 //
938 // When building with OpenJDK 9 but targeting a version < 1.8,
939 // putting them on the bootclasspath means that:
940 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
941 // b) references to existing APIs are not reinterpreted in an
942 // OpenJDK 9-specific way, eg. calls to subclasses of
943 // java.nio.Buffer as in http://b/70862583
944 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
945 flags.bootClasspath = append(flags.bootClasspath,
946 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
947 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -0800948 if Bool(j.properties.Use_tools_jar) {
949 flags.bootClasspath = append(flags.bootClasspath,
950 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
951 }
Colin Cross7fdd2b72018-01-02 18:14:25 -0800952 }
953
Nan Zhanged19fc32017-10-19 13:06:22 -0700954 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700955 if deps.systemModules != nil {
956 flags.systemModules = append(flags.systemModules, deps.systemModules)
957 }
958
Nan Zhanged19fc32017-10-19 13:06:22 -0700959 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700960 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700961 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700962 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700963 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
964 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700965 }
966
Nan Zhanged19fc32017-10-19 13:06:22 -0700967 return flags
968}
Colin Crossc0b06f12015-04-08 13:03:43 -0700969
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800970func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700971
Colin Crossebe1a512017-11-14 13:12:14 -0800972 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700973
974 deps := j.collectDeps(ctx)
975 flags := j.collectBuilderFlags(ctx, deps)
976
Colin Cross6510f912017-11-29 00:27:14 -0800977 if ctx.Config().TargetOpenJDK9() {
Nan Zhanged19fc32017-10-19 13:06:22 -0700978 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
979 }
980 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700981 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -0800982 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700983 }
984
Colin Crossaf050172017-11-15 23:01:59 -0800985 srcFiles = j.genSources(ctx, srcFiles, flags)
986
987 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700988 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800989 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700990
Colin Cross0a6e0072017-08-30 14:24:55 -0700991 var jars android.Paths
992
Colin Cross1ee23172017-10-18 14:44:18 -0700993 jarName := ctx.ModuleName() + ".jar"
994
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000995 javaSrcFiles := srcFiles.FilterByExt(".java")
996 var uniqueSrcFiles android.Paths
997 set := make(map[string]bool)
998 for _, v := range javaSrcFiles {
999 if _, found := set[v.String()]; !found {
1000 set[v.String()] = true
1001 uniqueSrcFiles = append(uniqueSrcFiles, v)
1002 }
1003 }
1004
Colin Cross37f6d792018-07-12 12:28:41 -07001005 var stripFiles []string
1006
Colin Cross93e85952017-08-15 13:34:18 -07001007 if srcFiles.HasExt(".kt") {
1008 // If there are kotlin files, compile them first but pass all the kotlin and java files
1009 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1010 // won't emit any classes for them.
1011
1012 flags.kotlincFlags = "-no-stdlib"
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001013
Colin Cross93e85952017-08-15 13:34:18 -07001014 if ctx.Device() {
1015 flags.kotlincFlags += " -no-jdk"
1016 }
1017
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001018 var kotlinSrcFiles android.Paths
1019 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1020 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1021
Przemyslaw Szczepaniake3d26bf2018-03-05 16:06:42 +00001022 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.bootClasspath...)
Colin Cross93e85952017-08-15 13:34:18 -07001023 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
1024 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
1025
Colin Cross1ee23172017-10-18 14:44:18 -07001026 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001027 TransformKotlinToClasses(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001028 if ctx.Failed() {
1029 return
1030 }
1031
1032 // Make javac rule depend on the kotlinc rule
Colin Cross49da2752018-06-05 17:22:57 -07001033 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001034 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001035
Colin Cross93e85952017-08-15 13:34:18 -07001036 // Jar kotlin classes into the final jar after javac
1037 jars = append(jars, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001038
Colin Cross37f6d792018-07-12 12:28:41 -07001039 if Bool(j.properties.Renamed_kotlin_stdlib) {
1040 // Remove any kotlin-reflect related files
1041 // TODO(pszczepaniak): Support kotlin-reflect
Colin Cross4c03f682018-07-15 08:16:31 -07001042 stripFiles = append(stripFiles,
1043 "**/*.kotlin_module",
Colin Cross29788aa2018-07-13 21:23:59 -07001044 "**/*.kotlin_builtins")
Colin Cross37f6d792018-07-12 12:28:41 -07001045 } else {
1046 // Only add kotlin-stdlib if not using (on-device) renamed stdlib
1047 // (it's expected to be on device bootclasspath)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001048 jars = append(jars, deps.kotlinStdlib...)
1049 }
Colin Cross93e85952017-08-15 13:34:18 -07001050 }
1051
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001052 // Store the list of .java files that was passed to javac
1053 j.compiledJavaSrcs = uniqueSrcFiles
1054 j.compiledSrcJars = srcJars
1055
Nan Zhang61eaedb2017-11-02 13:28:15 -07001056 enable_sharding := false
Colin Cross6510f912017-11-29 00:27:14 -08001057 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001058 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1059 enable_sharding = true
1060 if len(j.properties.Annotation_processors) != 0 ||
1061 len(j.properties.Annotation_processor_classes) != 0 {
1062 ctx.PropertyErrorf("javac_shard_size",
1063 "%q cannot be set when annotation processors are enabled.",
1064 j.properties.Javac_shard_size)
1065 }
1066 }
Colin Crossf19b9bb2018-03-26 14:42:44 -07001067 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName)
1068 if ctx.Failed() {
1069 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001070 }
1071 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001072 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001073 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001074 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001075 // If error-prone is enabled, add an additional rule to compile the java files into
1076 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001077 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001078 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1079 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001080 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001081 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001082 extraJarDeps = append(extraJarDeps, errorprone)
1083 }
1084
Nan Zhang61eaedb2017-11-02 13:28:15 -07001085 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001086 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001087 shardSize := int(*(j.properties.Javac_shard_size))
1088 var shardSrcs []android.Paths
1089 if len(uniqueSrcFiles) > 0 {
1090 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
1091 for idx, shardSrc := range shardSrcs {
1092 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
1093 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
1094 jars = append(jars, classes)
1095 }
1096 }
1097 if len(srcJars) > 0 {
1098 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
1099 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
1100 jars = append(jars, classes)
1101 }
1102 } else {
1103 classes := android.PathForModuleOut(ctx, "javac", jarName)
1104 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
1105 jars = append(jars, classes)
1106 }
Colin Crossd6891432017-09-27 17:39:56 -07001107 if ctx.Failed() {
1108 return
1109 }
Colin Cross2fe66872015-03-30 17:20:39 -07001110 }
1111
Colin Cross0f37af02017-09-27 17:42:05 -07001112 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
1113 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
1114
1115 var resArgs []string
1116 var resDeps android.Paths
1117
1118 resArgs = append(resArgs, dirArgs...)
1119 resDeps = append(resDeps, dirDeps...)
1120
1121 resArgs = append(resArgs, fileArgs...)
1122 resDeps = append(resDeps, fileDeps...)
1123
Colin Crossff3ae9d2018-04-10 16:15:18 -07001124 if Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -07001125 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -07001126 resArgs = append(resArgs, srcArgs...)
1127 resDeps = append(resDeps, srcDeps...)
1128 }
Colin Cross40a36712017-09-27 17:41:35 -07001129
1130 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001131 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001132 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -07001133 if ctx.Failed() {
1134 return
1135 }
Colin Cross20978302015-04-10 17:05:07 -07001136
Colin Cross0a6e0072017-08-30 14:24:55 -07001137 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -07001138 }
1139
Colin Cross6ade34f2017-09-15 13:00:47 -07001140 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -07001141 jars = append(jars, deps.staticJars...)
Nan Zhangb2b33de2018-02-23 11:18:47 -08001142 jars = append(jars, deps.staticJarResources...)
Colin Cross0a6e0072017-08-30 14:24:55 -07001143
Colin Cross366938f2017-12-11 16:29:02 -08001144 var manifest android.OptionalPath
1145 if j.properties.Manifest != nil {
1146 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
1147 }
Colin Cross635acc92017-09-12 22:50:46 -07001148
Colin Cross0a6e0072017-08-30 14:24:55 -07001149 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001150 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -07001151 var outputFile android.Path
1152
1153 if len(jars) == 1 && !manifest.Valid() {
1154 // Optimization: skip the combine step if there is nothing to do
Colin Cross7b60cdd2017-12-21 13:52:58 -08001155 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1156 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1157 // any if len(jars) == 1.
Colin Crosse9a275b2017-10-16 17:09:48 -07001158 outputFile = jars[0]
1159 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001160 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001161 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
1162 false, stripFiles, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001163 outputFile = combinedJar
1164 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001165
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001166 // Use renamed kotlin standard library?
Colin Crossff3ae9d2018-04-10 16:15:18 -07001167 if srcFiles.HasExt(".kt") && Bool(j.properties.Renamed_kotlin_stdlib) {
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001168 jarjarFile := android.PathForModuleOut(ctx, "kotlin-renamed", jarName)
1169 TransformJarJar(ctx, jarjarFile, outputFile,
1170 android.PathForSource(ctx, "external/kotlinc/jarjar-rules.txt"))
1171 outputFile = jarjarFile
1172 if ctx.Failed() {
1173 return
1174 }
1175 }
1176
Colin Cross0a6e0072017-08-30 14:24:55 -07001177 if j.properties.Jarjar_rules != nil {
1178 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -07001179 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001180 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001181 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
1182 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -07001183 if ctx.Failed() {
1184 return
1185 }
1186 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001187 j.implementationJarFile = outputFile
1188 if j.headerJarFile == nil {
1189 j.headerJarFile = j.implementationJarFile
1190 }
Colin Cross2fe66872015-03-30 17:20:39 -07001191
Colin Cross6510f912017-11-29 00:27:14 -08001192 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -08001193 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
1194 j.properties.Instrument = true
1195 }
1196 }
1197
Colin Cross3144dfc2018-01-03 15:06:47 -08001198 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001199 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1200 }
1201
Colin Cross9ae1b922018-06-26 17:59:05 -07001202 if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
David Brazdil17ef5632018-06-27 10:27:45 +01001203 var dexOutputFile android.Path
1204 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001205 if ctx.Failed() {
1206 return
1207 }
Colin Cross9ae1b922018-06-26 17:59:05 -07001208 if Bool(j.properties.Installable) {
David Brazdil17ef5632018-06-27 10:27:45 +01001209 outputFile = dexOutputFile
1210 }
Colin Cross2fe66872015-03-30 17:20:39 -07001211 }
Colin Crossb7a63242015-04-16 14:09:14 -07001212 ctx.CheckbuildFile(outputFile)
1213 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -07001214}
1215
Colin Cross8eadbf02017-10-24 17:46:00 -07001216func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Nan Zhanged19fc32017-10-19 13:06:22 -07001217 deps deps, flags javaBuilderFlags, jarName string) android.Path {
1218
1219 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001220 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001221 // Compile java sources into turbine.jar.
1222 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1223 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1224 if ctx.Failed() {
1225 return nil
1226 }
1227 jars = append(jars, turbineJar)
1228 }
1229
1230 // Combine any static header libraries into classes-header.jar. If there is only
1231 // one input jar this step will be skipped.
1232 var headerJar android.Path
1233 jars = append(jars, deps.staticHeaderJars...)
1234
Colin Cross5c6ecc12017-10-23 18:12:27 -07001235 // we cannot skip the combine step for now if there is only one jar
1236 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1237 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001238 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
1239 false, nil, []string{"META-INF"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001240 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001241
1242 if j.properties.Jarjar_rules != nil {
1243 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
1244 // Transform classes.jar into classes-jarjar.jar
1245 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
1246 TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules)
1247 headerJar = jarjarFile
1248 if ctx.Failed() {
1249 return nil
1250 }
1251 }
1252
1253 return headerJar
1254}
1255
Colin Crosscb933592017-11-22 13:49:43 -08001256func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
1257 classesJar android.Path, jarName string) android.Path {
1258
Colin Cross7a3139e2017-12-19 13:57:50 -08001259 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001260
Colin Cross84c38822018-01-03 15:59:46 -08001261 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001262 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1263
1264 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1265
1266 j.jacocoReportClassesFile = jacocoReportClassesFile
1267
1268 return instrumentedJar
1269}
1270
Colin Crossf506d872017-07-19 15:53:04 -07001271var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001272
Nan Zhanged19fc32017-10-19 13:06:22 -07001273func (j *Module) HeaderJars() android.Paths {
1274 return android.Paths{j.headerJarFile}
1275}
1276
1277func (j *Module) ImplementationJars() android.Paths {
1278 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001279}
1280
Colin Cross46c9b8b2017-06-22 16:51:17 -07001281func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001282 return j.exportAidlIncludeDirs
1283}
1284
Jiyong Park1be96912018-05-28 18:02:19 +09001285func (j *Module) ExportedSdkLibs() []string {
1286 return j.exportedSdkLibs
1287}
1288
Colin Cross46c9b8b2017-06-22 16:51:17 -07001289var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001290
Colin Cross46c9b8b2017-06-22 16:51:17 -07001291func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001292 return j.logtagsSrcs
1293}
1294
Colin Cross2fe66872015-03-30 17:20:39 -07001295//
1296// Java libraries (.jar file)
1297//
1298
Colin Crossf506d872017-07-19 15:53:04 -07001299type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001300 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001301}
1302
Colin Crossf506d872017-07-19 15:53:04 -07001303func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001304 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001305
Colin Cross9ae1b922018-06-26 17:59:05 -07001306 if Bool(j.properties.Installable) || ctx.Host() {
Colin Cross2c429dc2017-08-31 16:45:16 -07001307 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1308 ctx.ModuleName()+".jar", j.outputFile)
1309 }
Colin Crossb7a63242015-04-16 14:09:14 -07001310}
1311
Colin Crossf506d872017-07-19 15:53:04 -07001312func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001313 j.deps(ctx)
1314}
1315
Colin Cross9ae1b922018-06-26 17:59:05 -07001316func LibraryFactory() android.Module {
1317 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001318
Colin Cross9ae1b922018-06-26 17:59:05 -07001319 module.AddProperties(
1320 &module.Module.properties,
1321 &module.Module.deviceProperties,
1322 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001323
Colin Cross9ae1b922018-06-26 17:59:05 -07001324 InitJavaModule(module, android.HostAndDeviceSupported)
1325 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001326}
1327
Colin Crossf506d872017-07-19 15:53:04 -07001328func LibraryHostFactory() android.Module {
1329 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001330
Colin Cross6af17aa2017-09-20 12:59:05 -07001331 module.AddProperties(
1332 &module.Module.properties,
1333 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001334
Colin Cross9ae1b922018-06-26 17:59:05 -07001335 module.Module.properties.Installable = proptools.BoolPtr(true)
1336
Colin Cross89536d42017-07-07 14:35:50 -07001337 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001338 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001339}
1340
1341//
Colin Cross05638fc2018-04-09 18:40:24 -07001342// Java Junit Tests
1343//
1344
1345type testProperties struct {
1346 // If true, add a static dependency on the platform junit library. Defaults to true.
1347 Junit *bool
1348
1349 // list of compatibility suites (for example "cts", "vts") that the module should be
1350 // installed into.
1351 Test_suites []string `android:"arch_variant"`
1352}
1353
1354type Test struct {
1355 Library
1356
1357 testProperties testProperties
1358}
1359
1360func (j *Test) DepsMutator(ctx android.BottomUpMutatorContext) {
1361 j.deps(ctx)
Colin Cross38b40df2018-04-10 16:14:46 -07001362 if BoolDefault(j.testProperties.Junit, true) {
Colin Cross05638fc2018-04-09 18:40:24 -07001363 ctx.AddDependency(ctx.Module(), staticLibTag, "junit")
1364 }
1365}
1366
1367func TestFactory() android.Module {
1368 module := &Test{}
1369
1370 module.AddProperties(
1371 &module.Module.properties,
1372 &module.Module.deviceProperties,
1373 &module.Module.protoProperties,
1374 &module.testProperties)
1375
Colin Cross9ae1b922018-06-26 17:59:05 -07001376 module.Module.properties.Installable = proptools.BoolPtr(true)
1377
Colin Cross05638fc2018-04-09 18:40:24 -07001378 InitJavaModule(module, android.HostAndDeviceSupported)
1379 android.InitDefaultableModule(module)
1380 return module
1381}
1382
1383func TestHostFactory() android.Module {
1384 module := &Test{}
1385
1386 module.AddProperties(
1387 &module.Module.properties,
1388 &module.Module.protoProperties,
1389 &module.testProperties)
1390
Colin Cross9ae1b922018-06-26 17:59:05 -07001391 module.Module.properties.Installable = proptools.BoolPtr(true)
1392
Colin Cross05638fc2018-04-09 18:40:24 -07001393 InitJavaModule(module, android.HostSupported)
1394 android.InitDefaultableModule(module)
1395 return module
1396}
1397
1398//
Colin Cross2fe66872015-03-30 17:20:39 -07001399// Java Binaries (.jar file plus wrapper script)
1400//
1401
Colin Crossf506d872017-07-19 15:53:04 -07001402type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001403 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001404 Wrapper *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001405}
1406
Colin Crossf506d872017-07-19 15:53:04 -07001407type Binary struct {
1408 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001409
Colin Crossf506d872017-07-19 15:53:04 -07001410 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001411
Colin Cross6b4a32d2017-12-05 13:42:45 -08001412 isWrapperVariant bool
1413
Colin Crossc3315992017-12-08 19:12:36 -08001414 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001415 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001416}
1417
Alex Light24237172017-10-26 09:46:21 -07001418func (j *Binary) HostToolPath() android.OptionalPath {
1419 return android.OptionalPathForPath(j.binaryFile)
1420}
1421
Colin Crossf506d872017-07-19 15:53:04 -07001422func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001423 if ctx.Arch().ArchType == android.Common {
1424 // Compile the jar
1425 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001426 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001427 // Handle the binary wrapper
1428 j.isWrapperVariant = true
1429
Colin Cross366938f2017-12-11 16:29:02 -08001430 if j.binaryProperties.Wrapper != nil {
1431 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001432 } else {
1433 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1434 }
1435
1436 // Depend on the installed jar so that the wrapper doesn't get executed by
1437 // another build rule before the jar has been installed.
1438 jarFile := ctx.PrimaryModule().(*Binary).installFile
1439
1440 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1441 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001442 }
Colin Cross2fe66872015-03-30 17:20:39 -07001443}
1444
Colin Crossf506d872017-07-19 15:53:04 -07001445func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001446 if ctx.Arch().ArchType == android.Common {
1447 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001448 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001449 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001450 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001451}
1452
Colin Crossf506d872017-07-19 15:53:04 -07001453func BinaryFactory() android.Module {
1454 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001455
Colin Cross36242852017-06-23 15:06:31 -07001456 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001457 &module.Module.properties,
1458 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001459 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001460 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001461
Colin Cross9ae1b922018-06-26 17:59:05 -07001462 module.Module.properties.Installable = proptools.BoolPtr(true)
1463
Colin Cross6b4a32d2017-12-05 13:42:45 -08001464 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1465 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001466 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001467}
1468
Colin Crossf506d872017-07-19 15:53:04 -07001469func BinaryHostFactory() android.Module {
1470 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001471
Colin Cross36242852017-06-23 15:06:31 -07001472 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001473 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001474 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001475 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001476
Colin Cross9ae1b922018-06-26 17:59:05 -07001477 module.Module.properties.Installable = proptools.BoolPtr(true)
1478
Colin Cross6b4a32d2017-12-05 13:42:45 -08001479 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1480 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001481 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001482}
1483
1484//
1485// Java prebuilts
1486//
1487
Colin Cross74d73e22017-08-02 11:05:49 -07001488type ImportProperties struct {
1489 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001490
Nan Zhangea568a42017-11-08 21:20:04 -08001491 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001492
1493 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001494
1495 // List of shared java libs that this module has dependencies to
1496 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07001497
1498 // List of files to remove from the jar file(s)
1499 Exclude_files []string
1500
1501 // List of directories to remove from the jar file(s)
1502 Exclude_dirs []string
Colin Cross74d73e22017-08-02 11:05:49 -07001503}
1504
1505type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001506 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001507 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001508
Colin Cross74d73e22017-08-02 11:05:49 -07001509 properties ImportProperties
1510
Colin Cross0a6e0072017-08-30 14:24:55 -07001511 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09001512 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07001513}
1514
Colin Cross83bb3162018-06-25 15:48:06 -07001515func (j *Import) sdkVersion() string {
1516 return String(j.properties.Sdk_version)
1517}
1518
1519func (j *Import) minSdkVersion() string {
1520 return j.sdkVersion()
1521}
1522
Colin Cross74d73e22017-08-02 11:05:49 -07001523func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001524 return &j.prebuilt
1525}
1526
Colin Cross74d73e22017-08-02 11:05:49 -07001527func (j *Import) PrebuiltSrcs() []string {
1528 return j.properties.Jars
1529}
1530
1531func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001532 return j.prebuilt.Name(j.ModuleBase.Name())
1533}
1534
Colin Cross74d73e22017-08-02 11:05:49 -07001535func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001536 android.ExtractSourcesDeps(ctx, j.properties.Jars)
Jiyong Park1be96912018-05-28 18:02:19 +09001537 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07001538}
1539
Colin Cross74d73e22017-08-02 11:05:49 -07001540func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001541 jars := ctx.ExpandSources(j.properties.Jars, nil)
Colin Crosse1d62a82015-04-03 16:53:05 -07001542
Colin Crosse9a275b2017-10-16 17:09:48 -07001543 outputFile := android.PathForModuleOut(ctx, "classes.jar")
Colin Cross37f6d792018-07-12 12:28:41 -07001544 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
1545 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Colin Crosse9a275b2017-10-16 17:09:48 -07001546 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09001547
1548 ctx.VisitDirectDeps(func(module android.Module) {
1549 otherName := ctx.OtherModuleName(module)
1550 tag := ctx.OtherModuleDependencyTag(module)
1551
1552 switch dep := module.(type) {
1553 case Dependency:
1554 switch tag {
1555 case libTag, staticLibTag:
1556 // sdk lib names from dependencies are re-exported
1557 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
1558 }
1559 case SdkLibraryDependency:
1560 switch tag {
1561 case libTag:
1562 // names of sdk libs that are directly depended are exported
1563 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
1564 }
1565 }
1566 })
1567
1568 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Colin Cross2fe66872015-03-30 17:20:39 -07001569}
1570
Colin Cross74d73e22017-08-02 11:05:49 -07001571var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001572
Nan Zhanged19fc32017-10-19 13:06:22 -07001573func (j *Import) HeaderJars() android.Paths {
Colin Cross37f6d792018-07-12 12:28:41 -07001574 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07001575}
1576
1577func (j *Import) ImplementationJars() android.Paths {
Colin Cross37f6d792018-07-12 12:28:41 -07001578 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001579}
1580
Colin Cross74d73e22017-08-02 11:05:49 -07001581func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001582 return nil
1583}
1584
Jiyong Park1be96912018-05-28 18:02:19 +09001585func (j *Import) ExportedSdkLibs() []string {
1586 return j.exportedSdkLibs
1587}
1588
Colin Cross74d73e22017-08-02 11:05:49 -07001589var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001590
Colin Cross74d73e22017-08-02 11:05:49 -07001591func ImportFactory() android.Module {
1592 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001593
Colin Cross74d73e22017-08-02 11:05:49 -07001594 module.AddProperties(&module.properties)
1595
1596 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -07001597 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1598 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001599}
1600
Colin Cross74d73e22017-08-02 11:05:49 -07001601func ImportFactoryHost() android.Module {
1602 module := &Import{}
1603
1604 module.AddProperties(&module.properties)
1605
1606 android.InitPrebuiltModule(module, &module.properties.Jars)
1607 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
1608 return module
1609}
1610
Colin Cross89536d42017-07-07 14:35:50 -07001611//
1612// Defaults
1613//
1614type Defaults struct {
1615 android.ModuleBase
1616 android.DefaultsModuleBase
1617}
1618
1619func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1620}
1621
1622func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1623}
1624
1625func defaultsFactory() android.Module {
1626 return DefaultsFactory()
1627}
1628
1629func DefaultsFactory(props ...interface{}) android.Module {
1630 module := &Defaults{}
1631
1632 module.AddProperties(props...)
1633 module.AddProperties(
1634 &CompilerProperties{},
1635 &CompilerDeviceProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001636 &android.ProtoProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07001637 )
1638
1639 android.InitDefaultsModule(module)
1640
1641 return module
1642}
Nan Zhangea568a42017-11-08 21:20:04 -08001643
1644var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001645var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08001646var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08001647var inList = android.InList