blob: 38c89f4c851af728096e4c9fed7b6b6bba0c1adb [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
Sundong Ahn241cd372018-07-13 16:16:44 +0900316 ImplementationJars(linkType linkType) android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900317}
318
Nan Zhangb2b33de2018-02-23 11:18:47 -0800319type SrcDependency interface {
320 CompiledSrcs() android.Paths
321 CompiledSrcJars() android.Paths
322}
323
324func (j *Module) CompiledSrcs() android.Paths {
325 return j.compiledJavaSrcs
326}
327
328func (j *Module) CompiledSrcJars() android.Paths {
329 return j.compiledSrcJars
330}
331
332var _ SrcDependency = (*Module)(nil)
333
Colin Cross89536d42017-07-07 14:35:50 -0700334func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
335 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
336 android.InitDefaultableModule(module)
337}
338
Colin Crossbe1da472017-07-07 15:59:46 -0700339type dependencyTag struct {
340 blueprint.BaseDependencyTag
341 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700342}
343
Colin Crossbe1da472017-07-07 15:59:46 -0700344var (
Colin Cross6ade34f2017-09-15 13:00:47 -0700345 staticLibTag = dependencyTag{name: "staticlib"}
346 libTag = dependencyTag{name: "javalib"}
Colin Cross6a77c982018-06-19 22:43:34 -0700347 annoTag = dependencyTag{name: "annotation processor"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700348 bootClasspathTag = dependencyTag{name: "bootclasspath"}
Colin Cross1369cdb2017-09-29 17:58:17 -0700349 systemModulesTag = dependencyTag{name: "system modules"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700350 frameworkResTag = dependencyTag{name: "framework-res"}
Nan Zhangb2b33de2018-02-23 11:18:47 -0800351 frameworkApkTag = dependencyTag{name: "framework-apk"}
Colin Cross93e85952017-08-15 13:34:18 -0700352 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Cross66dbc0b2017-12-28 12:23:20 -0800353 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
Colin Crossbe1da472017-07-07 15:59:46 -0700354)
Colin Cross2fe66872015-03-30 17:20:39 -0700355
Colin Crossfc3674a2017-09-18 17:41:52 -0700356type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700357 useModule, useFiles, useDefaultLibs, invalidVersion bool
358
Colin Cross86a60ae2018-05-29 14:44:55 -0700359 modules []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700360 systemModules string
361
Colin Crossa97c5d32018-03-28 14:58:31 -0700362 frameworkResModule string
363
Colin Cross86a60ae2018-05-29 14:44:55 -0700364 jars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700365 aidl android.Path
366}
367
Colin Cross3144dfc2018-01-03 15:06:47 -0800368func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
369 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
370}
371
372func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
373 return j.shouldInstrument(ctx) &&
374 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
375 ctx.Config().UnbundledBuild())
376}
377
Colin Cross83bb3162018-06-25 15:48:06 -0700378func (j *Module) sdkVersion() string {
379 return String(j.deviceProperties.Sdk_version)
380}
381
382func (j *Module) minSdkVersion() string {
383 if j.deviceProperties.Min_sdk_version != nil {
384 return *j.deviceProperties.Min_sdk_version
385 }
386 return j.sdkVersion()
387}
388
389type sdkContext interface {
390 // sdkVersion eturns the sdk_version property of the current module, or an empty string if it is not set.
391 sdkVersion() string
392 // minSdkVersion returns the min_sdk_version property of the current module, or sdkVersion() if it is not set.
393 minSdkVersion() string
394}
395
396func sdkVersionOrDefault(ctx android.BaseContext, v string) string {
397 switch v {
398 case "", "current", "system_current", "test_current", "core_current":
399 return ctx.Config().DefaultAppTargetSdk()
400 default:
401 return v
402 }
403}
404
405// Returns a sdk version as a number. For modules targeting an unreleased SDK (meaning it does not yet have a number)
406// it returns android.FutureApiLevel (10000).
407func sdkVersionToNumber(ctx android.BaseContext, v string) (int, error) {
408 switch v {
409 case "", "current", "test_current", "system_current", "core_current":
410 return ctx.Config().DefaultAppTargetSdkInt(), nil
411 default:
412 n := android.GetNumericSdkVersion(v)
413 if i, err := strconv.Atoi(n); err != nil {
414 return -1, fmt.Errorf("invalid sdk version %q", n)
415 } else {
416 return i, nil
417 }
418 }
419}
420
421func sdkVersionToNumberAsString(ctx android.BaseContext, v string) (string, error) {
422 n, err := sdkVersionToNumber(ctx, v)
423 if err != nil {
424 return "", err
425 }
426 return strconv.Itoa(n), nil
427}
428
429func decodeSdkDep(ctx android.BaseContext, sdkContext sdkContext) sdkDep {
430 v := sdkContext.sdkVersion()
431 i, err := sdkVersionToNumber(ctx, v)
432 if err != nil {
433 ctx.PropertyErrorf("sdk_version", "%s", err)
Colin Cross1369cdb2017-09-29 17:58:17 -0700434 return sdkDep{}
Colin Crossfc3674a2017-09-18 17:41:52 -0700435 }
436
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900437 // Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks)
438 // or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set)
439 if strings.HasPrefix(v, "system_") && i != android.FutureApiLevel {
440 allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions()
441 if ctx.DeviceSpecific() || ctx.SocSpecific() {
442 if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 {
443 allowed_versions = ctx.DeviceConfig().SystemSdkVersions()
444 }
445 }
446 version := strings.TrimPrefix(v, "system_")
447 if len(allowed_versions) > 0 && !android.InList(version, allowed_versions) {
448 ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q",
449 v, allowed_versions)
450 }
451 }
452
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100453 toPrebuilt := func(sdk string) sdkDep {
454 var api, v string
455 if strings.Contains(sdk, "_") {
456 t := strings.Split(sdk, "_")
457 api = t[0]
458 v = t[1]
459 } else {
460 api = "public"
461 v = sdk
Jiyong Park750e5572018-01-31 00:20:13 +0900462 }
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100463 dir := filepath.Join("prebuilts", "sdk", v, api)
Colin Crossfc3674a2017-09-18 17:41:52 -0700464 jar := filepath.Join(dir, "android.jar")
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100465 // There's no aidl for other SDKs yet.
466 // TODO(77525052): Add aidl files for other SDKs too.
467 public_dir := filepath.Join("prebuilts", "sdk", v, "public")
468 aidl := filepath.Join(public_dir, "framework.aidl")
Colin Cross32f38982018-02-22 11:47:25 -0800469 jarPath := android.ExistentPathForSource(ctx, jar)
470 aidlPath := android.ExistentPathForSource(ctx, aidl)
Colin Cross86a60ae2018-05-29 14:44:55 -0700471 lambdaStubsPath := android.PathForSource(ctx, config.SdkLambdaStubsPath)
Colin Cross47ff2522017-10-02 14:22:08 -0700472
Colin Cross6510f912017-11-29 00:27:14 -0800473 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
Colin Cross47ff2522017-10-02 14:22:08 -0700474 return sdkDep{
475 invalidVersion: true,
Colin Cross86a60ae2018-05-29 14:44:55 -0700476 modules: []string{fmt.Sprintf("sdk_%s_%s_android", api, v)},
Colin Cross47ff2522017-10-02 14:22:08 -0700477 }
478 }
479
Colin Crossfc3674a2017-09-18 17:41:52 -0700480 if !jarPath.Valid() {
481 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar)
482 return sdkDep{}
483 }
Colin Cross47ff2522017-10-02 14:22:08 -0700484
Colin Crossfc3674a2017-09-18 17:41:52 -0700485 if !aidlPath.Valid() {
486 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl)
487 return sdkDep{}
488 }
Colin Cross47ff2522017-10-02 14:22:08 -0700489
Colin Crossfc3674a2017-09-18 17:41:52 -0700490 return sdkDep{
491 useFiles: true,
Colin Cross86a60ae2018-05-29 14:44:55 -0700492 jars: android.Paths{jarPath.Path(), lambdaStubsPath},
Colin Crossfc3674a2017-09-18 17:41:52 -0700493 aidl: aidlPath.Path(),
494 }
495 }
496
Colin Crossa97c5d32018-03-28 14:58:31 -0700497 toModule := func(m, r string) sdkDep {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700498 ret := sdkDep{
Colin Crossa97c5d32018-03-28 14:58:31 -0700499 useModule: true,
Colin Cross86a60ae2018-05-29 14:44:55 -0700500 modules: []string{m, config.DefaultLambdaStubsLibrary},
Colin Crossa97c5d32018-03-28 14:58:31 -0700501 systemModules: m + "_system_modules",
502 frameworkResModule: r,
Colin Crossf19b9bb2018-03-26 14:42:44 -0700503 }
504 if m == "core.current.stubs" {
505 ret.systemModules = "core-system-modules"
506 }
507 return ret
508 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700509
Colin Cross6510f912017-11-29 00:27:14 -0800510 if ctx.Config().UnbundledBuild() && v != "" {
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100511 return toPrebuilt(v)
Colin Crossfc3674a2017-09-18 17:41:52 -0700512 }
513
514 switch v {
515 case "":
516 return sdkDep{
Colin Crossa97c5d32018-03-28 14:58:31 -0700517 useDefaultLibs: true,
518 frameworkResModule: "framework-res",
Colin Crossfc3674a2017-09-18 17:41:52 -0700519 }
Colin Crossf19b9bb2018-03-26 14:42:44 -0700520 case "current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700521 return toModule("android_stubs_current", "framework-res")
Colin Crossf19b9bb2018-03-26 14:42:44 -0700522 case "system_current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700523 return toModule("android_system_stubs_current", "framework-res")
Colin Crossf19b9bb2018-03-26 14:42:44 -0700524 case "test_current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700525 return toModule("android_test_stubs_current", "framework-res")
Colin Crossf19b9bb2018-03-26 14:42:44 -0700526 case "core_current":
Colin Crossa97c5d32018-03-28 14:58:31 -0700527 return toModule("core.current.stubs", "")
Colin Crossfc3674a2017-09-18 17:41:52 -0700528 default:
Anton Hanssonf66efeb2018-04-11 13:57:30 +0100529 return toPrebuilt(v)
Colin Crossfc3674a2017-09-18 17:41:52 -0700530 }
531}
532
Colin Crossbe1da472017-07-07 15:59:46 -0700533func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700534 if ctx.Device() {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700535 if !Bool(j.properties.No_standard_libs) {
Colin Cross83bb3162018-06-25 15:48:06 -0700536 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Crossfc3674a2017-09-18 17:41:52 -0700537 if sdkDep.useDefaultLibs {
Colin Crosscb2c9292017-09-23 19:57:16 -0700538 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Colin Cross6510f912017-11-29 00:27:14 -0800539 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700540 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
541 }
Colin Crossff3ae9d2018-04-10 16:15:18 -0700542 if !Bool(j.properties.No_framework_libs) {
Colin Crossfa5eb232017-10-01 20:33:03 -0700543 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
544 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700545 } else if sdkDep.useModule {
Colin Cross6510f912017-11-29 00:27:14 -0800546 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700547 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
548 }
Colin Cross86a60ae2018-05-29 14:44:55 -0700549 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800550 if Bool(j.deviceProperties.Optimize.Enabled) {
551 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultBootclasspathLibraries...)
552 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultLibraries...)
553 }
Colin Crossbe1da472017-07-07 15:59:46 -0700554 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700555 } else if j.deviceProperties.System_modules == nil {
556 ctx.PropertyErrorf("no_standard_libs",
557 "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 -0800558 } else if *j.deviceProperties.System_modules != "none" && ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700559 ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700560 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800561 if ctx.ModuleName() == "framework" {
562 ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res")
563 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800564 if ctx.ModuleName() == "android_stubs_current" ||
565 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang16c0a312018-06-13 17:42:48 -0700566 ctx.ModuleName() == "android_test_stubs_current" ||
567 ctx.ModuleName() == "metalava_android_stubs_current" ||
568 ctx.ModuleName() == "metalava_android_system_stubs_current" ||
569 ctx.ModuleName() == "metalava_android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800570 ctx.AddDependency(ctx.Module(), frameworkApkTag, "framework-res")
571 }
Colin Cross2fe66872015-03-30 17:20:39 -0700572 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700573
Colin Crossf506d872017-07-19 15:53:04 -0700574 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
575 ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
Mathew Inwood878c6622018-07-02 16:34:51 +0100576 ctx.AddFarVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -0700577 {Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant},
Mathew Inwood878c6622018-07-02 16:34:51 +0100578 }, annoTag, j.properties.Annotation_processors...)
Colin Cross7f9036c2017-08-30 13:27:57 -0700579 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Nan Zhang27e284d2018-02-09 21:03:53 +0000580 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700581 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross366938f2017-12-11 16:29:02 -0800582 android.ExtractSourceDeps(ctx, j.properties.Manifest)
Colin Cross6af17aa2017-09-20 12:59:05 -0700583
584 if j.hasSrcExt(".proto") {
585 protoDeps(ctx, &j.protoProperties)
586 }
Colin Cross93e85952017-08-15 13:34:18 -0700587
588 if j.hasSrcExt(".kt") {
589 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
590 // Kotlin files
591 ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib")
592 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800593
594 if j.shouldInstrumentStatic(ctx) {
595 ctx.AddDependency(ctx.Module(), staticLibTag, "jacocoagent")
596 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700597}
598
599func hasSrcExt(srcs []string, ext string) bool {
600 for _, src := range srcs {
601 if filepath.Ext(src) == ext {
602 return true
603 }
604 }
605
606 return false
607}
608
Nan Zhang61eaedb2017-11-02 13:28:15 -0700609func shardPaths(paths android.Paths, shardSize int) []android.Paths {
610 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
611 for len(paths) > shardSize {
612 ret = append(ret, paths[0:shardSize])
613 paths = paths[shardSize:]
614 }
615 if len(paths) > 0 {
616 ret = append(ret, paths)
617 }
618 return ret
619}
620
Colin Cross6af17aa2017-09-20 12:59:05 -0700621func (j *Module) hasSrcExt(ext string) bool {
622 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700623}
624
Colin Cross46c9b8b2017-06-22 16:51:17 -0700625func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700626 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700627
Colin Crossebe1a512017-11-14 13:12:14 -0800628 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
629 aidlIncludes = append(aidlIncludes,
630 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
631 aidlIncludes = append(aidlIncludes,
632 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700633
Steven Moreland667f6882018-07-26 12:55:08 -0700634 flags := []string{"-b"}
635
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700636 if aidlPreprocess.Valid() {
637 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700638 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700639 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700640 }
641
Colin Cross635c3b02016-05-18 15:37:25 -0700642 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800643 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700644 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800645 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700646 flags = append(flags, "-I"+src.String())
647 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700648
Martijn Coeneneab15642018-03-09 09:29:59 +0100649 if Bool(j.deviceProperties.Aidl.Generate_traces) {
650 flags = append(flags, "-t")
651 }
652
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100653 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
654 flags = append(flags, "--transaction_names")
655 }
656
Colin Crossf03c82b2015-04-13 13:53:40 -0700657 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700658}
659
Colin Cross32f676a2017-09-06 13:41:06 -0700660type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800661 classpath classpath
662 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700663 processorPath classpath
Colin Cross6ade34f2017-09-15 13:00:47 -0700664 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700665 staticHeaderJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700666 staticJarResources android.Paths
667 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800668 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700669 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700670 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700671 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700672 kotlinStdlib android.Paths
Colin Cross32f676a2017-09-06 13:41:06 -0700673}
Colin Cross2fe66872015-03-30 17:20:39 -0700674
Colin Cross54250902017-12-05 09:28:08 -0800675func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
676 for _, f := range dep.Srcs() {
677 if f.Ext() != ".jar" {
678 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
679 ctx.OtherModuleName(dep.(blueprint.Module)))
680 }
681 }
682}
683
Jiyong Park2d492942018-03-05 17:44:10 +0900684type linkType int
685
686const (
687 javaCore linkType = iota
688 javaSdk
689 javaSystem
690 javaPlatform
691)
692
Colin Crossf19b9bb2018-03-26 14:42:44 -0700693func getLinkType(m *Module, name string) linkType {
Colin Cross83bb3162018-06-25 15:48:06 -0700694 ver := m.sdkVersion()
Colin Cross86a60ae2018-05-29 14:44:55 -0700695 noStdLibs := Bool(m.properties.No_standard_libs)
Colin Crossf19b9bb2018-03-26 14:42:44 -0700696 switch {
Nan Zhangec93cd92018-07-13 16:36:04 -0700697 case name == "core.current.stubs" || ver == "core_current" || noStdLibs || name == "stub-annotations" ||
698 name == "private-stub-annotations-jar":
Jiyong Park2d492942018-03-05 17:44:10 +0900699 return javaCore
Nan Zhang16c0a312018-06-13 17:42:48 -0700700 case name == "android_system_stubs_current" || strings.HasPrefix(ver, "system_") || name == "metalava_android_system_stubs_current":
Jiyong Park2d492942018-03-05 17:44:10 +0900701 return javaSystem
Nan Zhang16c0a312018-06-13 17:42:48 -0700702 case name == "android_test_stubs_current" || strings.HasPrefix(ver, "test_") || name == "metalava_android_test_stubs_current":
Jiyong Park2d492942018-03-05 17:44:10 +0900703 return javaPlatform
Nan Zhang16c0a312018-06-13 17:42:48 -0700704 case name == "android_stubs_current" || ver == "current" || name == "metalava_android_stubs_current":
Colin Crossf19b9bb2018-03-26 14:42:44 -0700705 return javaSdk
706 case ver == "":
707 return javaPlatform
708 default:
709 if _, err := strconv.Atoi(ver); err != nil {
710 panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver))
711 }
712 return javaSdk
Jiyong Park2d492942018-03-05 17:44:10 +0900713 }
714}
715
Jiyong Park750e5572018-01-31 00:20:13 +0900716func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700717 if ctx.Host() {
718 return
719 }
720
721 myLinkType := getLinkType(from, ctx.ModuleName())
722 otherLinkType := getLinkType(&to.Module, ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900723 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."
724
725 switch myLinkType {
726 case javaCore:
727 if otherLinkType != javaCore {
728 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 +0900729 ctx.OtherModuleName(to))
730 }
Jiyong Park2d492942018-03-05 17:44:10 +0900731 break
732 case javaSdk:
733 if otherLinkType != javaCore && otherLinkType != javaSdk {
734 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
735 ctx.OtherModuleName(to))
736 }
737 break
738 case javaSystem:
739 if otherLinkType == javaPlatform {
740 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
741 ctx.OtherModuleName(to))
742 }
743 break
744 case javaPlatform:
745 // no restriction on link-type
746 break
Jiyong Park750e5572018-01-31 00:20:13 +0900747 }
748}
749
Colin Cross32f676a2017-09-06 13:41:06 -0700750func (j *Module) collectDeps(ctx android.ModuleContext) deps {
751 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700752
Colin Cross300f0382018-03-06 13:11:51 -0800753 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700754 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800755 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700756 ctx.AddMissingDependencies(sdkDep.modules)
Colin Cross300f0382018-03-06 13:11:51 -0800757 } else if sdkDep.useFiles {
758 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700759 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross300f0382018-03-06 13:11:51 -0800760 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
761 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700762 }
763
Colin Crossd11fcda2017-10-23 17:59:01 -0700764 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700765 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700766 tag := ctx.OtherModuleDependencyTag(module)
767
Jiyong Park750e5572018-01-31 00:20:13 +0900768 if to, ok := module.(*Library); ok {
Colin Crossa97c5d32018-03-28 14:58:31 -0700769 switch tag {
770 case bootClasspathTag, libTag, staticLibTag:
771 checkLinkType(ctx, j, to, tag.(dependencyTag))
772 }
Jiyong Park750e5572018-01-31 00:20:13 +0900773 }
Colin Cross54250902017-12-05 09:28:08 -0800774 switch dep := module.(type) {
775 case Dependency:
776 switch tag {
777 case bootClasspathTag:
778 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
779 case libTag:
780 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900781 // sdk lib names from dependencies are re-exported
782 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross54250902017-12-05 09:28:08 -0800783 case staticLibTag:
784 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
785 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
786 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900787 // sdk lib names from dependencies are re-exported
788 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross6a77c982018-06-19 22:43:34 -0700789 case annoTag:
790 deps.processorPath = append(deps.processorPath, dep.ImplementationJars()...)
Colin Cross54250902017-12-05 09:28:08 -0800791 case frameworkResTag:
792 if ctx.ModuleName() == "framework" {
793 // framework.jar has a one-off dependency on the R.java and Manifest.java files
794 // generated by framework-res.apk
795 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
796 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800797 case frameworkApkTag:
798 if ctx.ModuleName() == "android_stubs_current" ||
799 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang16c0a312018-06-13 17:42:48 -0700800 ctx.ModuleName() == "android_test_stubs_current" ||
801 ctx.ModuleName() == "metalava_android_stubs_current" ||
802 ctx.ModuleName() == "metalava_android_system_stubs_current" ||
803 ctx.ModuleName() == "metalava_android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800804 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
805 // resource files out of there for aapt.
806 //
807 // Normally the package rule runs aapt, which includes the resource,
808 // but we're not running that in our package rule so just copy in the
809 // resource files here.
810 deps.staticJarResources = append(deps.staticJarResources, dep.(*AndroidApp).exportPackage)
811 }
Colin Cross54250902017-12-05 09:28:08 -0800812 case kotlinStdlibTag:
813 deps.kotlinStdlib = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -0800814 }
815
816 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900817 case SdkLibraryDependency:
818 switch tag {
819 case libTag:
820 deps.classpath = append(deps.classpath, dep.HeaderJars(getLinkType(j, ctx.ModuleName()))...)
Jiyong Park1be96912018-05-28 18:02:19 +0900821 // names of sdk libs that are directly depended are exported
822 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900823 default:
824 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
825 }
Colin Cross54250902017-12-05 09:28:08 -0800826 case android.SourceFileProducer:
827 switch tag {
828 case libTag:
829 checkProducesJars(ctx, dep)
830 deps.classpath = append(deps.classpath, dep.Srcs()...)
831 case staticLibTag:
832 checkProducesJars(ctx, dep)
833 deps.classpath = append(deps.classpath, dep.Srcs()...)
834 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
835 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
836 case android.DefaultsDepTag, android.SourceDepTag:
837 // Nothing to do
838 default:
839 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
840 }
841 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700842 switch tag {
843 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700844 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700845 case systemModulesTag:
846 if deps.systemModules != nil {
847 panic("Found two system module dependencies")
848 }
849 sm := module.(*SystemModules)
850 if sm.outputFile == nil {
851 panic("Missing directory for system module dependency")
852 }
853 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700854 default:
855 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700856 }
Colin Crossec7a0422017-07-07 14:47:12 -0700857 }
Colin Cross2fe66872015-03-30 17:20:39 -0700858 })
859
Jiyong Park1be96912018-05-28 18:02:19 +0900860 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
861
Colin Cross32f676a2017-09-06 13:41:06 -0700862 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700863}
864
Colin Cross83bb3162018-06-25 15:48:06 -0700865func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string {
Nan Zhang357466b2018-04-17 17:38:36 -0700866 var ret string
Colin Cross83bb3162018-06-25 15:48:06 -0700867 sdk, err := sdkVersionToNumber(ctx, sdkContext.sdkVersion())
868 if err != nil {
869 ctx.PropertyErrorf("sdk_version", "%s", err)
870 }
Nan Zhang357466b2018-04-17 17:38:36 -0700871 if javaVersion != "" {
872 ret = javaVersion
873 } else if ctx.Device() && sdk <= 23 {
874 ret = "1.7"
875 } else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
876 ret = "1.8"
Colin Cross83bb3162018-06-25 15:48:06 -0700877 } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel {
Nan Zhang357466b2018-04-17 17:38:36 -0700878 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
879 ret = "1.8"
880 } else {
881 ret = "1.9"
882 }
883
884 return ret
885}
886
Nan Zhanged19fc32017-10-19 13:06:22 -0700887func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700888
Colin Crossf03c82b2015-04-13 13:53:40 -0700889 var flags javaBuilderFlags
890
Nan Zhanged19fc32017-10-19 13:06:22 -0700891 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700892 javacFlags := j.properties.Javacflags
Colin Cross6510f912017-11-29 00:27:14 -0800893 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700894 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700895 }
Colin Cross6510f912017-11-29 00:27:14 -0800896 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700897 // Override the -g flag passed globally to remove local variable debug info to reduce
898 // disk and memory usage.
899 javacFlags = append(javacFlags, "-g:source,lines")
900 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700901 if len(javacFlags) > 0 {
902 // optimization.
903 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
904 flags.javacFlags = "$javacFlags"
Colin Cross4f26bc02017-09-06 12:52:16 -0700905 }
Colin Cross64162712017-08-08 13:17:59 -0700906
Colin Cross66548102018-06-19 22:47:35 -0700907 if ctx.Config().RunErrorProne() {
908 if config.ErrorProneClasspath == nil {
909 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
910 }
911
912 errorProneFlags := []string{
913 "-Xplugin:ErrorProne",
914 "${config.ErrorProneChecks}",
915 }
916 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
917
918 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
919 "'" + strings.Join(errorProneFlags, " ") + "'"
920 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -0800921 }
922
Nan Zhanged19fc32017-10-19 13:06:22 -0700923 // javaVersion flag.
Colin Cross83bb3162018-06-25 15:48:06 -0700924 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross64162712017-08-08 13:17:59 -0700925
Nan Zhanged19fc32017-10-19 13:06:22 -0700926 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800927 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
928 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -0700929 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800930
931 if len(flags.bootClasspath) == 0 && ctx.Host() && !ctx.Config().TargetOpenJDK9() &&
932 !Bool(j.properties.No_standard_libs) &&
933 inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
934 // Give host-side tools a version of OpenJDK's standard libraries
935 // close to what they're targeting. As of Dec 2017, AOSP is only
936 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
937 //
938 // When building with OpenJDK 8, the following should have no
939 // effect since those jars would be available by default.
940 //
941 // When building with OpenJDK 9 but targeting a version < 1.8,
942 // putting them on the bootclasspath means that:
943 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
944 // b) references to existing APIs are not reinterpreted in an
945 // OpenJDK 9-specific way, eg. calls to subclasses of
946 // java.nio.Buffer as in http://b/70862583
947 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
948 flags.bootClasspath = append(flags.bootClasspath,
949 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
950 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -0800951 if Bool(j.properties.Use_tools_jar) {
952 flags.bootClasspath = append(flags.bootClasspath,
953 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
954 }
Colin Cross7fdd2b72018-01-02 18:14:25 -0800955 }
956
Nan Zhanged19fc32017-10-19 13:06:22 -0700957 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700958 if deps.systemModules != nil {
959 flags.systemModules = append(flags.systemModules, deps.systemModules)
960 }
961
Nan Zhanged19fc32017-10-19 13:06:22 -0700962 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700963 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700964 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700965 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700966 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
967 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700968 }
969
Nan Zhanged19fc32017-10-19 13:06:22 -0700970 return flags
971}
Colin Crossc0b06f12015-04-08 13:03:43 -0700972
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800973func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700974
Colin Crossebe1a512017-11-14 13:12:14 -0800975 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700976
977 deps := j.collectDeps(ctx)
978 flags := j.collectBuilderFlags(ctx, deps)
979
Colin Cross6510f912017-11-29 00:27:14 -0800980 if ctx.Config().TargetOpenJDK9() {
Nan Zhanged19fc32017-10-19 13:06:22 -0700981 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
982 }
983 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700984 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -0800985 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700986 }
987
Colin Crossaf050172017-11-15 23:01:59 -0800988 srcFiles = j.genSources(ctx, srcFiles, flags)
989
990 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700991 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800992 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700993
Colin Cross0a6e0072017-08-30 14:24:55 -0700994 var jars android.Paths
995
Colin Cross1ee23172017-10-18 14:44:18 -0700996 jarName := ctx.ModuleName() + ".jar"
997
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000998 javaSrcFiles := srcFiles.FilterByExt(".java")
999 var uniqueSrcFiles android.Paths
1000 set := make(map[string]bool)
1001 for _, v := range javaSrcFiles {
1002 if _, found := set[v.String()]; !found {
1003 set[v.String()] = true
1004 uniqueSrcFiles = append(uniqueSrcFiles, v)
1005 }
1006 }
1007
Colin Cross37f6d792018-07-12 12:28:41 -07001008 var stripFiles []string
1009
Colin Cross93e85952017-08-15 13:34:18 -07001010 if srcFiles.HasExt(".kt") {
1011 // If there are kotlin files, compile them first but pass all the kotlin and java files
1012 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1013 // won't emit any classes for them.
1014
1015 flags.kotlincFlags = "-no-stdlib"
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001016
Colin Cross93e85952017-08-15 13:34:18 -07001017 if ctx.Device() {
1018 flags.kotlincFlags += " -no-jdk"
1019 }
1020
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001021 var kotlinSrcFiles android.Paths
1022 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1023 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1024
Przemyslaw Szczepaniake3d26bf2018-03-05 16:06:42 +00001025 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.bootClasspath...)
Colin Cross93e85952017-08-15 13:34:18 -07001026 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
1027 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
1028
Colin Cross1ee23172017-10-18 14:44:18 -07001029 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001030 TransformKotlinToClasses(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001031 if ctx.Failed() {
1032 return
1033 }
1034
1035 // Make javac rule depend on the kotlinc rule
Colin Cross49da2752018-06-05 17:22:57 -07001036 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001037 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001038
Colin Cross93e85952017-08-15 13:34:18 -07001039 // Jar kotlin classes into the final jar after javac
1040 jars = append(jars, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001041
Colin Cross37f6d792018-07-12 12:28:41 -07001042 if Bool(j.properties.Renamed_kotlin_stdlib) {
1043 // Remove any kotlin-reflect related files
1044 // TODO(pszczepaniak): Support kotlin-reflect
Colin Cross4c03f682018-07-15 08:16:31 -07001045 stripFiles = append(stripFiles,
1046 "**/*.kotlin_module",
Colin Cross29788aa2018-07-13 21:23:59 -07001047 "**/*.kotlin_builtins")
Colin Cross37f6d792018-07-12 12:28:41 -07001048 } else {
1049 // Only add kotlin-stdlib if not using (on-device) renamed stdlib
1050 // (it's expected to be on device bootclasspath)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001051 jars = append(jars, deps.kotlinStdlib...)
1052 }
Colin Cross93e85952017-08-15 13:34:18 -07001053 }
1054
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001055 // Store the list of .java files that was passed to javac
1056 j.compiledJavaSrcs = uniqueSrcFiles
1057 j.compiledSrcJars = srcJars
1058
Nan Zhang61eaedb2017-11-02 13:28:15 -07001059 enable_sharding := false
Colin Cross6510f912017-11-29 00:27:14 -08001060 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001061 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1062 enable_sharding = true
1063 if len(j.properties.Annotation_processors) != 0 ||
1064 len(j.properties.Annotation_processor_classes) != 0 {
1065 ctx.PropertyErrorf("javac_shard_size",
1066 "%q cannot be set when annotation processors are enabled.",
1067 j.properties.Javac_shard_size)
1068 }
1069 }
Colin Crossf19b9bb2018-03-26 14:42:44 -07001070 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName)
1071 if ctx.Failed() {
1072 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001073 }
1074 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001075 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001076 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001077 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001078 // If error-prone is enabled, add an additional rule to compile the java files into
1079 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001080 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001081 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1082 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001083 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001084 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001085 extraJarDeps = append(extraJarDeps, errorprone)
1086 }
1087
Nan Zhang61eaedb2017-11-02 13:28:15 -07001088 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001089 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001090 shardSize := int(*(j.properties.Javac_shard_size))
1091 var shardSrcs []android.Paths
1092 if len(uniqueSrcFiles) > 0 {
1093 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
1094 for idx, shardSrc := range shardSrcs {
1095 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
1096 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
1097 jars = append(jars, classes)
1098 }
1099 }
1100 if len(srcJars) > 0 {
1101 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
1102 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
1103 jars = append(jars, classes)
1104 }
1105 } else {
1106 classes := android.PathForModuleOut(ctx, "javac", jarName)
1107 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
1108 jars = append(jars, classes)
1109 }
Colin Crossd6891432017-09-27 17:39:56 -07001110 if ctx.Failed() {
1111 return
1112 }
Colin Cross2fe66872015-03-30 17:20:39 -07001113 }
1114
Colin Cross0f37af02017-09-27 17:42:05 -07001115 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
1116 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
1117
1118 var resArgs []string
1119 var resDeps android.Paths
1120
1121 resArgs = append(resArgs, dirArgs...)
1122 resDeps = append(resDeps, dirDeps...)
1123
1124 resArgs = append(resArgs, fileArgs...)
1125 resDeps = append(resDeps, fileDeps...)
1126
Colin Crossff3ae9d2018-04-10 16:15:18 -07001127 if Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -07001128 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -07001129 resArgs = append(resArgs, srcArgs...)
1130 resDeps = append(resDeps, srcDeps...)
1131 }
Colin Cross40a36712017-09-27 17:41:35 -07001132
1133 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001134 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001135 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -07001136 if ctx.Failed() {
1137 return
1138 }
Colin Cross20978302015-04-10 17:05:07 -07001139
Colin Cross0a6e0072017-08-30 14:24:55 -07001140 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -07001141 }
1142
Colin Cross6ade34f2017-09-15 13:00:47 -07001143 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -07001144 jars = append(jars, deps.staticJars...)
Nan Zhangb2b33de2018-02-23 11:18:47 -08001145 jars = append(jars, deps.staticJarResources...)
Colin Cross0a6e0072017-08-30 14:24:55 -07001146
Colin Cross366938f2017-12-11 16:29:02 -08001147 var manifest android.OptionalPath
1148 if j.properties.Manifest != nil {
1149 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
1150 }
Colin Cross635acc92017-09-12 22:50:46 -07001151
Colin Cross0a6e0072017-08-30 14:24:55 -07001152 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001153 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -07001154 var outputFile android.Path
1155
1156 if len(jars) == 1 && !manifest.Valid() {
1157 // Optimization: skip the combine step if there is nothing to do
Colin Cross7b60cdd2017-12-21 13:52:58 -08001158 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1159 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1160 // any if len(jars) == 1.
Colin Crosse9a275b2017-10-16 17:09:48 -07001161 outputFile = jars[0]
1162 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001163 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001164 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
1165 false, stripFiles, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001166 outputFile = combinedJar
1167 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001168
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001169 // Use renamed kotlin standard library?
Colin Crossff3ae9d2018-04-10 16:15:18 -07001170 if srcFiles.HasExt(".kt") && Bool(j.properties.Renamed_kotlin_stdlib) {
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001171 jarjarFile := android.PathForModuleOut(ctx, "kotlin-renamed", jarName)
1172 TransformJarJar(ctx, jarjarFile, outputFile,
1173 android.PathForSource(ctx, "external/kotlinc/jarjar-rules.txt"))
1174 outputFile = jarjarFile
1175 if ctx.Failed() {
1176 return
1177 }
1178 }
1179
Colin Cross0a6e0072017-08-30 14:24:55 -07001180 if j.properties.Jarjar_rules != nil {
1181 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -07001182 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001183 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001184 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
1185 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -07001186 if ctx.Failed() {
1187 return
1188 }
1189 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001190 j.implementationJarFile = outputFile
1191 if j.headerJarFile == nil {
1192 j.headerJarFile = j.implementationJarFile
1193 }
Colin Cross2fe66872015-03-30 17:20:39 -07001194
Colin Cross6510f912017-11-29 00:27:14 -08001195 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -08001196 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
1197 j.properties.Instrument = true
1198 }
1199 }
1200
Colin Cross3144dfc2018-01-03 15:06:47 -08001201 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001202 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1203 }
1204
Colin Cross9ae1b922018-06-26 17:59:05 -07001205 if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
David Brazdil17ef5632018-06-27 10:27:45 +01001206 var dexOutputFile android.Path
1207 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001208 if ctx.Failed() {
1209 return
1210 }
Colin Cross9ae1b922018-06-26 17:59:05 -07001211 if Bool(j.properties.Installable) {
David Brazdil17ef5632018-06-27 10:27:45 +01001212 outputFile = dexOutputFile
1213 }
Colin Cross2fe66872015-03-30 17:20:39 -07001214 }
Colin Crossb7a63242015-04-16 14:09:14 -07001215 ctx.CheckbuildFile(outputFile)
1216 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -07001217}
1218
Colin Cross8eadbf02017-10-24 17:46:00 -07001219func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Nan Zhanged19fc32017-10-19 13:06:22 -07001220 deps deps, flags javaBuilderFlags, jarName string) android.Path {
1221
1222 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001223 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001224 // Compile java sources into turbine.jar.
1225 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1226 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1227 if ctx.Failed() {
1228 return nil
1229 }
1230 jars = append(jars, turbineJar)
1231 }
1232
1233 // Combine any static header libraries into classes-header.jar. If there is only
1234 // one input jar this step will be skipped.
1235 var headerJar android.Path
1236 jars = append(jars, deps.staticHeaderJars...)
1237
Colin Cross5c6ecc12017-10-23 18:12:27 -07001238 // we cannot skip the combine step for now if there is only one jar
1239 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1240 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001241 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
1242 false, nil, []string{"META-INF"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001243 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001244
1245 if j.properties.Jarjar_rules != nil {
1246 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
1247 // Transform classes.jar into classes-jarjar.jar
1248 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
1249 TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules)
1250 headerJar = jarjarFile
1251 if ctx.Failed() {
1252 return nil
1253 }
1254 }
1255
1256 return headerJar
1257}
1258
Colin Crosscb933592017-11-22 13:49:43 -08001259func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
1260 classesJar android.Path, jarName string) android.Path {
1261
Colin Cross7a3139e2017-12-19 13:57:50 -08001262 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001263
Colin Cross84c38822018-01-03 15:59:46 -08001264 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001265 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1266
1267 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1268
1269 j.jacocoReportClassesFile = jacocoReportClassesFile
1270
1271 return instrumentedJar
1272}
1273
Colin Crossf506d872017-07-19 15:53:04 -07001274var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001275
Nan Zhanged19fc32017-10-19 13:06:22 -07001276func (j *Module) HeaderJars() android.Paths {
1277 return android.Paths{j.headerJarFile}
1278}
1279
1280func (j *Module) ImplementationJars() android.Paths {
1281 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001282}
1283
Colin Cross46c9b8b2017-06-22 16:51:17 -07001284func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001285 return j.exportAidlIncludeDirs
1286}
1287
Jiyong Park1be96912018-05-28 18:02:19 +09001288func (j *Module) ExportedSdkLibs() []string {
1289 return j.exportedSdkLibs
1290}
1291
Colin Cross46c9b8b2017-06-22 16:51:17 -07001292var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001293
Colin Cross46c9b8b2017-06-22 16:51:17 -07001294func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001295 return j.logtagsSrcs
1296}
1297
Colin Cross2fe66872015-03-30 17:20:39 -07001298//
1299// Java libraries (.jar file)
1300//
1301
Colin Crossf506d872017-07-19 15:53:04 -07001302type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001303 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001304}
1305
Colin Crossf506d872017-07-19 15:53:04 -07001306func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001307 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001308
Colin Cross9ae1b922018-06-26 17:59:05 -07001309 if Bool(j.properties.Installable) || ctx.Host() {
Colin Cross2c429dc2017-08-31 16:45:16 -07001310 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1311 ctx.ModuleName()+".jar", j.outputFile)
1312 }
Colin Crossb7a63242015-04-16 14:09:14 -07001313}
1314
Colin Crossf506d872017-07-19 15:53:04 -07001315func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001316 j.deps(ctx)
1317}
1318
Colin Cross9ae1b922018-06-26 17:59:05 -07001319func LibraryFactory() android.Module {
1320 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001321
Colin Cross9ae1b922018-06-26 17:59:05 -07001322 module.AddProperties(
1323 &module.Module.properties,
1324 &module.Module.deviceProperties,
1325 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001326
Colin Cross9ae1b922018-06-26 17:59:05 -07001327 InitJavaModule(module, android.HostAndDeviceSupported)
1328 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001329}
1330
Colin Crossf506d872017-07-19 15:53:04 -07001331func LibraryHostFactory() android.Module {
1332 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001333
Colin Cross6af17aa2017-09-20 12:59:05 -07001334 module.AddProperties(
1335 &module.Module.properties,
1336 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001337
Colin Cross9ae1b922018-06-26 17:59:05 -07001338 module.Module.properties.Installable = proptools.BoolPtr(true)
1339
Colin Cross89536d42017-07-07 14:35:50 -07001340 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001341 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001342}
1343
1344//
Colin Cross05638fc2018-04-09 18:40:24 -07001345// Java Junit Tests
1346//
1347
1348type testProperties struct {
1349 // If true, add a static dependency on the platform junit library. Defaults to true.
1350 Junit *bool
1351
1352 // list of compatibility suites (for example "cts", "vts") that the module should be
1353 // installed into.
1354 Test_suites []string `android:"arch_variant"`
1355}
1356
1357type Test struct {
1358 Library
1359
1360 testProperties testProperties
1361}
1362
1363func (j *Test) DepsMutator(ctx android.BottomUpMutatorContext) {
1364 j.deps(ctx)
Colin Cross38b40df2018-04-10 16:14:46 -07001365 if BoolDefault(j.testProperties.Junit, true) {
Colin Cross05638fc2018-04-09 18:40:24 -07001366 ctx.AddDependency(ctx.Module(), staticLibTag, "junit")
1367 }
1368}
1369
1370func TestFactory() android.Module {
1371 module := &Test{}
1372
1373 module.AddProperties(
1374 &module.Module.properties,
1375 &module.Module.deviceProperties,
1376 &module.Module.protoProperties,
1377 &module.testProperties)
1378
Colin Cross9ae1b922018-06-26 17:59:05 -07001379 module.Module.properties.Installable = proptools.BoolPtr(true)
1380
Colin Cross05638fc2018-04-09 18:40:24 -07001381 InitJavaModule(module, android.HostAndDeviceSupported)
1382 android.InitDefaultableModule(module)
1383 return module
1384}
1385
1386func TestHostFactory() android.Module {
1387 module := &Test{}
1388
1389 module.AddProperties(
1390 &module.Module.properties,
1391 &module.Module.protoProperties,
1392 &module.testProperties)
1393
Colin Cross9ae1b922018-06-26 17:59:05 -07001394 module.Module.properties.Installable = proptools.BoolPtr(true)
1395
Colin Cross05638fc2018-04-09 18:40:24 -07001396 InitJavaModule(module, android.HostSupported)
1397 android.InitDefaultableModule(module)
1398 return module
1399}
1400
1401//
Colin Cross2fe66872015-03-30 17:20:39 -07001402// Java Binaries (.jar file plus wrapper script)
1403//
1404
Colin Crossf506d872017-07-19 15:53:04 -07001405type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001406 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001407 Wrapper *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001408}
1409
Colin Crossf506d872017-07-19 15:53:04 -07001410type Binary struct {
1411 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001412
Colin Crossf506d872017-07-19 15:53:04 -07001413 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001414
Colin Cross6b4a32d2017-12-05 13:42:45 -08001415 isWrapperVariant bool
1416
Colin Crossc3315992017-12-08 19:12:36 -08001417 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001418 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001419}
1420
Alex Light24237172017-10-26 09:46:21 -07001421func (j *Binary) HostToolPath() android.OptionalPath {
1422 return android.OptionalPathForPath(j.binaryFile)
1423}
1424
Colin Crossf506d872017-07-19 15:53:04 -07001425func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001426 if ctx.Arch().ArchType == android.Common {
1427 // Compile the jar
1428 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001429 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001430 // Handle the binary wrapper
1431 j.isWrapperVariant = true
1432
Colin Cross366938f2017-12-11 16:29:02 -08001433 if j.binaryProperties.Wrapper != nil {
1434 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001435 } else {
1436 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1437 }
1438
1439 // Depend on the installed jar so that the wrapper doesn't get executed by
1440 // another build rule before the jar has been installed.
1441 jarFile := ctx.PrimaryModule().(*Binary).installFile
1442
1443 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1444 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001445 }
Colin Cross2fe66872015-03-30 17:20:39 -07001446}
1447
Colin Crossf506d872017-07-19 15:53:04 -07001448func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001449 if ctx.Arch().ArchType == android.Common {
1450 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001451 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001452 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001453 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001454}
1455
Colin Crossf506d872017-07-19 15:53:04 -07001456func BinaryFactory() android.Module {
1457 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001458
Colin Cross36242852017-06-23 15:06:31 -07001459 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001460 &module.Module.properties,
1461 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001462 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001463 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001464
Colin Cross9ae1b922018-06-26 17:59:05 -07001465 module.Module.properties.Installable = proptools.BoolPtr(true)
1466
Colin Cross6b4a32d2017-12-05 13:42:45 -08001467 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1468 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001469 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001470}
1471
Colin Crossf506d872017-07-19 15:53:04 -07001472func BinaryHostFactory() android.Module {
1473 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001474
Colin Cross36242852017-06-23 15:06:31 -07001475 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001476 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001477 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001478 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001479
Colin Cross9ae1b922018-06-26 17:59:05 -07001480 module.Module.properties.Installable = proptools.BoolPtr(true)
1481
Colin Cross6b4a32d2017-12-05 13:42:45 -08001482 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1483 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001484 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001485}
1486
1487//
1488// Java prebuilts
1489//
1490
Colin Cross74d73e22017-08-02 11:05:49 -07001491type ImportProperties struct {
1492 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001493
Nan Zhangea568a42017-11-08 21:20:04 -08001494 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001495
1496 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001497
1498 // List of shared java libs that this module has dependencies to
1499 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07001500
1501 // List of files to remove from the jar file(s)
1502 Exclude_files []string
1503
1504 // List of directories to remove from the jar file(s)
1505 Exclude_dirs []string
Colin Cross74d73e22017-08-02 11:05:49 -07001506}
1507
1508type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001509 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001510 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001511
Colin Cross74d73e22017-08-02 11:05:49 -07001512 properties ImportProperties
1513
Colin Cross0a6e0072017-08-30 14:24:55 -07001514 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09001515 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07001516}
1517
Colin Cross83bb3162018-06-25 15:48:06 -07001518func (j *Import) sdkVersion() string {
1519 return String(j.properties.Sdk_version)
1520}
1521
1522func (j *Import) minSdkVersion() string {
1523 return j.sdkVersion()
1524}
1525
Colin Cross74d73e22017-08-02 11:05:49 -07001526func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001527 return &j.prebuilt
1528}
1529
Colin Cross74d73e22017-08-02 11:05:49 -07001530func (j *Import) PrebuiltSrcs() []string {
1531 return j.properties.Jars
1532}
1533
1534func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001535 return j.prebuilt.Name(j.ModuleBase.Name())
1536}
1537
Colin Cross74d73e22017-08-02 11:05:49 -07001538func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001539 android.ExtractSourcesDeps(ctx, j.properties.Jars)
Jiyong Park1be96912018-05-28 18:02:19 +09001540 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07001541}
1542
Colin Cross74d73e22017-08-02 11:05:49 -07001543func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001544 jars := ctx.ExpandSources(j.properties.Jars, nil)
Colin Crosse1d62a82015-04-03 16:53:05 -07001545
Colin Crosse9a275b2017-10-16 17:09:48 -07001546 outputFile := android.PathForModuleOut(ctx, "classes.jar")
Colin Cross37f6d792018-07-12 12:28:41 -07001547 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
1548 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Colin Crosse9a275b2017-10-16 17:09:48 -07001549 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09001550
1551 ctx.VisitDirectDeps(func(module android.Module) {
1552 otherName := ctx.OtherModuleName(module)
1553 tag := ctx.OtherModuleDependencyTag(module)
1554
1555 switch dep := module.(type) {
1556 case Dependency:
1557 switch tag {
1558 case libTag, staticLibTag:
1559 // sdk lib names from dependencies are re-exported
1560 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
1561 }
1562 case SdkLibraryDependency:
1563 switch tag {
1564 case libTag:
1565 // names of sdk libs that are directly depended are exported
1566 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
1567 }
1568 }
1569 })
1570
1571 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Colin Cross2fe66872015-03-30 17:20:39 -07001572}
1573
Colin Cross74d73e22017-08-02 11:05:49 -07001574var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001575
Nan Zhanged19fc32017-10-19 13:06:22 -07001576func (j *Import) HeaderJars() android.Paths {
Colin Cross37f6d792018-07-12 12:28:41 -07001577 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07001578}
1579
1580func (j *Import) ImplementationJars() android.Paths {
Colin Cross37f6d792018-07-12 12:28:41 -07001581 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001582}
1583
Colin Cross74d73e22017-08-02 11:05:49 -07001584func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001585 return nil
1586}
1587
Jiyong Park1be96912018-05-28 18:02:19 +09001588func (j *Import) ExportedSdkLibs() []string {
1589 return j.exportedSdkLibs
1590}
1591
Colin Cross74d73e22017-08-02 11:05:49 -07001592var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001593
Colin Cross74d73e22017-08-02 11:05:49 -07001594func ImportFactory() android.Module {
1595 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001596
Colin Cross74d73e22017-08-02 11:05:49 -07001597 module.AddProperties(&module.properties)
1598
1599 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -07001600 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1601 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001602}
1603
Colin Cross74d73e22017-08-02 11:05:49 -07001604func ImportFactoryHost() android.Module {
1605 module := &Import{}
1606
1607 module.AddProperties(&module.properties)
1608
1609 android.InitPrebuiltModule(module, &module.properties.Jars)
1610 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
1611 return module
1612}
1613
Colin Cross89536d42017-07-07 14:35:50 -07001614//
1615// Defaults
1616//
1617type Defaults struct {
1618 android.ModuleBase
1619 android.DefaultsModuleBase
1620}
1621
1622func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1623}
1624
1625func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1626}
1627
1628func defaultsFactory() android.Module {
1629 return DefaultsFactory()
1630}
1631
1632func DefaultsFactory(props ...interface{}) android.Module {
1633 module := &Defaults{}
1634
1635 module.AddProperties(props...)
1636 module.AddProperties(
1637 &CompilerProperties{},
1638 &CompilerDeviceProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001639 &android.ProtoProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07001640 )
1641
1642 android.InitDefaultsModule(module)
1643
1644 return module
1645}
Nan Zhangea568a42017-11-08 21:20:04 -08001646
1647var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001648var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08001649var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08001650var inList = android.InList