blob: 619ae75484ce6166ea4daa899f36b003a3706d15 [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 (
22 "fmt"
Colin Crossfc3674a2017-09-18 17:41:52 -070023 "path/filepath"
Colin Cross74d73e22017-08-02 11:05:49 -070024 "strconv"
Colin Cross2fe66872015-03-30 17:20:39 -070025 "strings"
26
27 "github.com/google/blueprint"
Colin Cross76b5f0c2017-08-29 16:02:06 -070028 "github.com/google/blueprint/proptools"
Colin Cross2fe66872015-03-30 17:20:39 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Cross3e3e72d2017-06-22 17:20:19 -070031 "android/soong/java/config"
Colin Cross2fe66872015-03-30 17:20:39 -070032)
33
Colin Cross463a90e2015-06-17 14:20:06 -070034func init() {
Colin Cross89536d42017-07-07 14:35:50 -070035 android.RegisterModuleType("java_defaults", defaultsFactory)
36
Colin Crossa60ead82017-10-02 18:10:21 -070037 android.RegisterModuleType("java_library", LibraryFactory(true))
38 android.RegisterModuleType("java_library_static", LibraryFactory(false))
Colin Crossf506d872017-07-19 15:53:04 -070039 android.RegisterModuleType("java_library_host", LibraryHostFactory)
40 android.RegisterModuleType("java_binary", BinaryFactory)
41 android.RegisterModuleType("java_binary_host", BinaryHostFactory)
Colin Cross74d73e22017-08-02 11:05:49 -070042 android.RegisterModuleType("java_import", ImportFactory)
43 android.RegisterModuleType("java_import_host", ImportFactoryHost)
Colin Cross463a90e2015-06-17 14:20:06 -070044
Colin Cross798bfce2016-10-12 14:28:16 -070045 android.RegisterSingletonType("logtags", LogtagsSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -070046}
47
Colin Cross2fe66872015-03-30 17:20:39 -070048// TODO:
49// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070050// Renderscript
51// Post-jar passes:
52// Proguard
Colin Cross2fe66872015-03-30 17:20:39 -070053// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -070054// DroidDoc
55// Findbugs
56
Colin Cross89536d42017-07-07 14:35:50 -070057type CompilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -070058 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
59 // or .aidl files.
Dan Willemsen2ef08f42015-06-30 18:15:24 -070060 Srcs []string `android:"arch_variant"`
61
62 // list of source files that should not be used to build the Java module.
63 // This is most useful in the arch/multilib variants to remove non-common files
64 Exclude_srcs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070065
66 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -070067 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070068
Colin Cross86a63ff2017-09-27 17:33:10 -070069 // list of directories that should be excluded from java_resource_dirs
70 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -070071
Colin Cross0f37af02017-09-27 17:42:05 -070072 // list of files to use as Java resources
73 Java_resources []string `android:"arch_variant"`
74
75 // list of files that should be excluded from java_resources
76 Exclude_java_resources []string `android:"arch_variant"`
77
Colin Crossfa5eb232017-10-01 20:33:03 -070078 // don't build against the default libraries (bootclasspath, legacy-test, core-junit,
Colin Cross7d5136f2015-05-11 13:39:40 -070079 // ext, and framework for device targets)
Colin Cross76b5f0c2017-08-29 16:02:06 -070080 No_standard_libs *bool
Colin Cross7d5136f2015-05-11 13:39:40 -070081
Colin Crossfa5eb232017-10-01 20:33:03 -070082 // don't build against the framework libraries (legacy-test, core-junit,
83 // ext, and framework for device targets)
84 No_framework_libs *bool
85
Colin Cross7d5136f2015-05-11 13:39:40 -070086 // list of module-specific flags that will be used for javac compiles
87 Javacflags []string `android:"arch_variant"`
88
Colin Cross7d5136f2015-05-11 13:39:40 -070089 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -070090 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070091
92 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -070093 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070094
95 // manifest file to be included in resulting jar
Dan Willemsen34cc69e2015-09-23 15:26:20 -070096 Manifest *string
Colin Cross7d5136f2015-05-11 13:39:40 -070097
Colin Cross540eff82017-06-22 17:01:52 -070098 // if not blank, run jarjar using the specified rules file
Colin Cross975f9f72017-10-17 13:55:55 -070099 Jarjar_rules *string `android:"arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700100
101 // If not blank, set the java version passed to javac as -source and -target
102 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700103
104 // If set to false, don't allow this module to be installed. Defaults to true.
105 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700106
Colin Cross0f37af02017-09-27 17:42:05 -0700107 // If set to true, include sources used to compile the module in to the final jar
108 Include_srcs *bool
109
Colin Cross32f676a2017-09-06 13:41:06 -0700110 // List of modules to use as annotation processors
111 Annotation_processors []string
112
113 // List of classes to pass to javac to use as annotation processors
114 Annotation_processor_classes []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700115
Nan Zhang61eaedb2017-11-02 13:28:15 -0700116 // The number of Java source entries each Javac instance can process
117 Javac_shard_size *int64
118
Nan Zhang5f8cb422018-02-06 10:34:32 -0800119 // Add host jdk tools.jar to bootclasspath
120 Use_tools_jar *bool
121
Colin Cross1369cdb2017-09-29 17:58:17 -0700122 Openjdk9 struct {
123 // List of source files that should only be used when passing -source 1.9
124 Srcs []string
125
126 // List of javac flags that should only be used when passing -source 1.9
127 Javacflags []string
128 }
Colin Crosscb933592017-11-22 13:49:43 -0800129
130 Jacoco struct {
131 // List of classes to include for instrumentation with jacoco to collect coverage
132 // information at runtime when building with coverage enabled. If unset defaults to all
133 // classes.
134 // Supports '*' as the last character of an entry in the list as a wildcard match.
135 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
136 // it matches classes in the package that have the class name as a prefix.
137 Include_filter []string
138
139 // List of classes to exclude from instrumentation with jacoco to collect coverage
140 // information at runtime when building with coverage enabled. Overrides classes selected
141 // by the include_filter property.
142 // Supports '*' as the last character of an entry in the list as a wildcard match.
143 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
144 // it matches classes in the package that have the class name as a prefix.
145 Exclude_filter []string
146 }
147
Andreas Gampef3e5b552018-01-22 21:27:21 -0800148 Errorprone struct {
149 // List of javac flags that should only be used when running errorprone.
150 Javacflags []string
151 }
152
Colin Cross0f2ee152017-12-14 15:22:43 -0800153 Proto struct {
154 // List of extra options that will be passed to the proto generator.
155 Output_params []string
156 }
157
Colin Crosscb933592017-11-22 13:49:43 -0800158 Instrument bool `blueprint:"mutated"`
Colin Cross540eff82017-06-22 17:01:52 -0700159}
160
Colin Cross89536d42017-07-07 14:35:50 -0700161type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700162 // list of module-specific flags that will be used for dex compiles
163 Dxflags []string `android:"arch_variant"`
164
Colin Cross7d5136f2015-05-11 13:39:40 -0700165 // if not blank, set to the version of the sdk to compile against
Nan Zhangea568a42017-11-08 21:20:04 -0800166 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700167
Colin Crossebe1a512017-11-14 13:12:14 -0800168 Aidl struct {
169 // Top level directories to pass to aidl tool
170 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700171
Colin Crossebe1a512017-11-14 13:12:14 -0800172 // Directories rooted at the Android.bp file to pass to aidl tool
173 Local_include_dirs []string
174
175 // directories that should be added as include directories for any aidl sources of modules
176 // that depend on this module, as well as to aidl for this module.
177 Export_include_dirs []string
Martijn Coenen22071ca2018-03-09 09:29:59 +0100178
179 // whether to generate traces (for systrace) for this interface
180 Generate_traces *bool
Colin Crossebe1a512017-11-14 13:12:14 -0800181 }
Colin Cross92430102017-10-09 14:59:32 -0700182
183 // If true, export a copy of the module as a -hostdex module for host testing.
184 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700185
Colin Cross1bd87802017-12-05 15:31:19 -0800186 Dex_preopt struct {
187 // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to
188 // true.
189 Enabled *bool
190
191 // If true, generate an app image (.art file) for this module.
192 App_image *bool
193
194 // If true, use a checked-in profile to guide optimization. Defaults to false unless
195 // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR
196 // that matches the name of this module, in which case it is defaulted to true.
197 Profile_guided *bool
198
199 // If set, provides the path to profile relative to the Android.bp file. If not set,
200 // defaults to searching for a file that matches the name of this module in the default
201 // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found.
202 Profile *string
203 }
Colin Crossa22116e2017-10-19 14:18:58 -0700204
Colin Cross66dbc0b2017-12-28 12:23:20 -0800205 Optimize struct {
206 // If false, disable all optimization. Defaults to true for apps, false for
207 // libraries and tests.
208 Enabled *bool
209
210 // If true, optimize for size by removing unused code. Defaults to true for apps,
211 // false for libraries and tests.
212 Shrink *bool
213
214 // If true, optimize bytecode. Defaults to false.
215 Optimize *bool
216
217 // If true, obfuscate bytecode. Defaults to false.
218 Obfuscate *bool
219
220 // If true, do not use the flag files generated by aapt that automatically keep
221 // classes referenced by the app manifest. Defaults to false.
222 No_aapt_flags *bool
223
224 // Flags to pass to proguard.
225 Proguard_flags []string
226
227 // Specifies the locations of files containing proguard flags.
228 Proguard_flags_files []string
229 }
230
Colin Cross1369cdb2017-09-29 17:58:17 -0700231 // When targeting 1.9, override the modules to use with --system
232 System_modules *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700233}
234
Colin Cross46c9b8b2017-06-22 16:51:17 -0700235// Module contains the properties and members used by all java module types
236type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700237 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700238 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700239
Colin Cross89536d42017-07-07 14:35:50 -0700240 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700241 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700242 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700243
Nan Zhanged19fc32017-10-19 13:06:22 -0700244 // header jar file suitable for inserting into the bootclasspath/classpath of another compile
245 headerJarFile android.Path
246
247 // full implementation jar file suitable for static dependency of another module compile
248 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700249
Colin Cross6ade34f2017-09-15 13:00:47 -0700250 // output file containing classes.dex
251 dexJarFile android.Path
252
Colin Crosscb933592017-11-22 13:49:43 -0800253 // output file containing uninstrumented classes that will be instrumented by jacoco
254 jacocoReportClassesFile android.Path
255
Colin Cross66dbc0b2017-12-28 12:23:20 -0800256 // output file containing mapping of obfuscated names
257 proguardDictionary android.Path
258
Colin Crossb7a63242015-04-16 14:09:14 -0700259 // output file suitable for installing or running
Colin Cross635c3b02016-05-18 15:37:25 -0700260 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700261
Colin Cross635c3b02016-05-18 15:37:25 -0700262 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700263
Colin Cross635c3b02016-05-18 15:37:25 -0700264 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700265
Colin Cross2fe66872015-03-30 17:20:39 -0700266 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700267 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800268
269 // list of .java files and srcjars that was passed to javac
270 compiledJavaSrcs android.Paths
271 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800272
273 // list of extra progurad flag files
274 extraProguardFlagFiles android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700275}
276
Colin Cross54250902017-12-05 09:28:08 -0800277func (j *Module) Srcs() android.Paths {
278 return android.Paths{j.implementationJarFile}
279}
280
281var _ android.SourceFileProducer = (*Module)(nil)
282
Colin Crossf506d872017-07-19 15:53:04 -0700283type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700284 HeaderJars() android.Paths
285 ImplementationJars() android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700286 AidlIncludeDirs() android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700287}
288
Colin Cross89536d42017-07-07 14:35:50 -0700289func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
290 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
291 android.InitDefaultableModule(module)
292}
293
Colin Crossbe1da472017-07-07 15:59:46 -0700294type dependencyTag struct {
295 blueprint.BaseDependencyTag
296 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700297}
298
Colin Crossbe1da472017-07-07 15:59:46 -0700299var (
Colin Cross6ade34f2017-09-15 13:00:47 -0700300 staticLibTag = dependencyTag{name: "staticlib"}
301 libTag = dependencyTag{name: "javalib"}
302 bootClasspathTag = dependencyTag{name: "bootclasspath"}
Colin Cross1369cdb2017-09-29 17:58:17 -0700303 systemModulesTag = dependencyTag{name: "system modules"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700304 frameworkResTag = dependencyTag{name: "framework-res"}
Colin Cross93e85952017-08-15 13:34:18 -0700305 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Cross66dbc0b2017-12-28 12:23:20 -0800306 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
Colin Crossbe1da472017-07-07 15:59:46 -0700307)
Colin Cross2fe66872015-03-30 17:20:39 -0700308
Colin Crossfc3674a2017-09-18 17:41:52 -0700309type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700310 useModule, useFiles, useDefaultLibs, invalidVersion bool
311
Colin Cross1369cdb2017-09-29 17:58:17 -0700312 module string
313 systemModules string
314
Colin Cross42b96642018-04-26 13:14:15 -0700315 frameworkResModule string
316
Colin Cross1369cdb2017-09-29 17:58:17 -0700317 jar android.Path
318 aidl android.Path
319}
320
321func sdkStringToNumber(ctx android.BaseContext, v string) int {
322 switch v {
Jiyong Park750e5572018-01-31 00:20:13 +0900323 case "", "current", "system_current", "test_current", "core_current":
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900324 return android.FutureApiLevel
Colin Cross1369cdb2017-09-29 17:58:17 -0700325 default:
Sundong Ahn0926fae2017-10-17 16:34:51 +0900326 if i, err := strconv.Atoi(android.GetNumericSdkVersion(v)); err != nil {
Colin Cross1369cdb2017-09-29 17:58:17 -0700327 ctx.PropertyErrorf("sdk_version", "invalid sdk version")
328 return -1
329 } else {
330 return i
331 }
332 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700333}
334
Colin Cross3144dfc2018-01-03 15:06:47 -0800335func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
336 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
337}
338
339func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
340 return j.shouldInstrument(ctx) &&
341 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
342 ctx.Config().UnbundledBuild())
343}
344
Colin Crossfc3674a2017-09-18 17:41:52 -0700345func decodeSdkDep(ctx android.BaseContext, v string) sdkDep {
Colin Cross1369cdb2017-09-29 17:58:17 -0700346 i := sdkStringToNumber(ctx, v)
347 if i == -1 {
348 // Invalid sdk version, error handled by sdkStringToNumber.
349 return sdkDep{}
Colin Crossfc3674a2017-09-18 17:41:52 -0700350 }
351
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900352 // Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks)
353 // or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set)
354 if strings.HasPrefix(v, "system_") && i != android.FutureApiLevel {
355 allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions()
356 if ctx.DeviceSpecific() || ctx.SocSpecific() {
357 if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 {
358 allowed_versions = ctx.DeviceConfig().SystemSdkVersions()
359 }
360 }
361 version := strings.TrimPrefix(v, "system_")
362 if len(allowed_versions) > 0 && !android.InList(version, allowed_versions) {
363 ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q",
364 v, allowed_versions)
365 }
366 }
367
Colin Crossfc3674a2017-09-18 17:41:52 -0700368 toFile := func(v string) sdkDep {
Jiyong Park750e5572018-01-31 00:20:13 +0900369 isCore := strings.HasPrefix(v, "core_")
370 if isCore {
371 v = strings.TrimPrefix(v, "core_")
372 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700373 dir := filepath.Join("prebuilts/sdk", v)
374 jar := filepath.Join(dir, "android.jar")
Jiyong Park750e5572018-01-31 00:20:13 +0900375 if isCore {
376 jar = filepath.Join(dir, "core.jar")
377 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700378 aidl := filepath.Join(dir, "framework.aidl")
Colin Cross32f38982018-02-22 11:47:25 -0800379 jarPath := android.ExistentPathForSource(ctx, jar)
380 aidlPath := android.ExistentPathForSource(ctx, aidl)
Colin Cross47ff2522017-10-02 14:22:08 -0700381
Colin Cross6510f912017-11-29 00:27:14 -0800382 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
Colin Cross47ff2522017-10-02 14:22:08 -0700383 return sdkDep{
384 invalidVersion: true,
385 module: "sdk_v" + v,
386 }
387 }
388
Colin Crossfc3674a2017-09-18 17:41:52 -0700389 if !jarPath.Valid() {
390 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar)
391 return sdkDep{}
392 }
Colin Cross47ff2522017-10-02 14:22:08 -0700393
Colin Crossfc3674a2017-09-18 17:41:52 -0700394 if !aidlPath.Valid() {
395 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl)
396 return sdkDep{}
397 }
Colin Cross47ff2522017-10-02 14:22:08 -0700398
Colin Crossfc3674a2017-09-18 17:41:52 -0700399 return sdkDep{
400 useFiles: true,
401 jar: jarPath.Path(),
402 aidl: aidlPath.Path(),
403 }
404 }
405
Colin Cross2ebc4762017-10-20 14:00:31 -0700406 //toModule := func(m string) sdkDep {
407 // return sdkDep{
408 // useModule: true,
409 // module: m,
410 // systemModules: m + "_system_modules",
Colin Cross42b96642018-04-26 13:14:15 -0700411 // frameworkResModule: r,
Colin Cross2ebc4762017-10-20 14:00:31 -0700412 // }
413 //}
Colin Crossfc3674a2017-09-18 17:41:52 -0700414
Colin Cross6510f912017-11-29 00:27:14 -0800415 if ctx.Config().UnbundledBuild() && v != "" {
Colin Crossfc3674a2017-09-18 17:41:52 -0700416 return toFile(v)
417 }
418
419 switch v {
420 case "":
421 return sdkDep{
Colin Cross42b96642018-04-26 13:14:15 -0700422 useDefaultLibs: true,
423 frameworkResModule: "framework-res",
Colin Crossfc3674a2017-09-18 17:41:52 -0700424 }
Colin Cross2ebc4762017-10-20 14:00:31 -0700425 // TODO(ccross): re-enable these once we generate stubs, until then
426 // use the stubs in prebuilts/sdk/*current
427 //case "current":
Colin Cross42b96642018-04-26 13:14:15 -0700428 // return toModule("android_stubs_current", "framework-res")
Colin Cross2ebc4762017-10-20 14:00:31 -0700429 //case "system_current":
Colin Cross42b96642018-04-26 13:14:15 -0700430 // return toModule("android_system_stubs_current", "framework-res")
Colin Cross2ebc4762017-10-20 14:00:31 -0700431 //case "test_current":
Colin Cross42b96642018-04-26 13:14:15 -0700432 // return toModule("android_test_stubs_current", "framework-res")
Colin Crossfc3674a2017-09-18 17:41:52 -0700433 default:
434 return toFile(v)
435 }
436}
437
Colin Crossbe1da472017-07-07 15:59:46 -0700438func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700439 if ctx.Device() {
440 if !proptools.Bool(j.properties.No_standard_libs) {
Nan Zhangea568a42017-11-08 21:20:04 -0800441 sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
Colin Crossfc3674a2017-09-18 17:41:52 -0700442 if sdkDep.useDefaultLibs {
Colin Crosscb2c9292017-09-23 19:57:16 -0700443 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Colin Cross6510f912017-11-29 00:27:14 -0800444 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700445 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
446 }
Colin Crossfa5eb232017-10-01 20:33:03 -0700447 if !proptools.Bool(j.properties.No_framework_libs) {
448 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
449 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700450 } else if sdkDep.useModule {
Colin Cross6510f912017-11-29 00:27:14 -0800451 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700452 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
453 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700454 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800455 if Bool(j.deviceProperties.Optimize.Enabled) {
456 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultBootclasspathLibraries...)
457 ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultLibraries...)
458 }
Colin Crossbe1da472017-07-07 15:59:46 -0700459 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700460 } else if j.deviceProperties.System_modules == nil {
461 ctx.PropertyErrorf("no_standard_libs",
462 "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 -0800463 } else if *j.deviceProperties.System_modules != "none" && ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700464 ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700465 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800466 if ctx.ModuleName() == "framework" {
467 ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res")
468 }
Colin Cross2fe66872015-03-30 17:20:39 -0700469 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700470
Colin Crossf506d872017-07-19 15:53:04 -0700471 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
472 ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
Colin Cross6ade34f2017-09-15 13:00:47 -0700473 ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...)
Colin Cross7f9036c2017-08-30 13:27:57 -0700474
475 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Nan Zhang27e284d2018-02-09 21:03:53 +0000476 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700477 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross366938f2017-12-11 16:29:02 -0800478 android.ExtractSourceDeps(ctx, j.properties.Manifest)
Colin Cross6af17aa2017-09-20 12:59:05 -0700479
480 if j.hasSrcExt(".proto") {
481 protoDeps(ctx, &j.protoProperties)
482 }
Colin Cross93e85952017-08-15 13:34:18 -0700483
484 if j.hasSrcExt(".kt") {
485 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
486 // Kotlin files
487 ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib")
488 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800489
490 if j.shouldInstrumentStatic(ctx) {
491 ctx.AddDependency(ctx.Module(), staticLibTag, "jacocoagent")
492 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700493}
494
495func hasSrcExt(srcs []string, ext string) bool {
496 for _, src := range srcs {
497 if filepath.Ext(src) == ext {
498 return true
499 }
500 }
501
502 return false
503}
504
Nan Zhang61eaedb2017-11-02 13:28:15 -0700505func shardPaths(paths android.Paths, shardSize int) []android.Paths {
506 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
507 for len(paths) > shardSize {
508 ret = append(ret, paths[0:shardSize])
509 paths = paths[shardSize:]
510 }
511 if len(paths) > 0 {
512 ret = append(ret, paths)
513 }
514 return ret
515}
516
Colin Cross6af17aa2017-09-20 12:59:05 -0700517func (j *Module) hasSrcExt(ext string) bool {
518 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700519}
520
Colin Cross46c9b8b2017-06-22 16:51:17 -0700521func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700522 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700523
Colin Crossebe1a512017-11-14 13:12:14 -0800524 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
525 aidlIncludes = append(aidlIncludes,
526 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
527 aidlIncludes = append(aidlIncludes,
528 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700529
530 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700531 if aidlPreprocess.Valid() {
532 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700533 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700534 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700535 }
536
Colin Cross635c3b02016-05-18 15:37:25 -0700537 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800538 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700539 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800540 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700541 flags = append(flags, "-I"+src.String())
542 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700543
Martijn Coenen22071ca2018-03-09 09:29:59 +0100544 if Bool(j.deviceProperties.Aidl.Generate_traces) {
545 flags = append(flags, "-t")
546 }
547
Colin Crossf03c82b2015-04-13 13:53:40 -0700548 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700549}
550
Colin Cross32f676a2017-09-06 13:41:06 -0700551type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800552 classpath classpath
553 bootClasspath classpath
Colin Cross6ade34f2017-09-15 13:00:47 -0700554 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700555 staticHeaderJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700556 staticJarResources android.Paths
557 aidlIncludeDirs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700558 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700559 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700560 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700561 kotlinStdlib android.Paths
Colin Cross32f676a2017-09-06 13:41:06 -0700562}
Colin Cross2fe66872015-03-30 17:20:39 -0700563
Colin Cross54250902017-12-05 09:28:08 -0800564func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
565 for _, f := range dep.Srcs() {
566 if f.Ext() != ".jar" {
567 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
568 ctx.OtherModuleName(dep.(blueprint.Module)))
569 }
570 }
571}
572
Jiyong Park750e5572018-01-31 00:20:13 +0900573func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) {
574 if strings.HasPrefix(String(from.deviceProperties.Sdk_version), "core_") {
575 if !strings.HasPrefix(String(to.deviceProperties.Sdk_version), "core_") {
576 ctx.ModuleErrorf("depends on other library %q using non-core Java APIs",
577 ctx.OtherModuleName(to))
578 }
579 }
580}
581
Colin Cross32f676a2017-09-06 13:41:06 -0700582func (j *Module) collectDeps(ctx android.ModuleContext) deps {
583 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700584
Nan Zhangea568a42017-11-08 21:20:04 -0800585 sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
Colin Cross47ff2522017-10-02 14:22:08 -0700586 if sdkDep.invalidVersion {
587 ctx.AddMissingDependencies([]string{sdkDep.module})
588 } else if sdkDep.useFiles {
Nan Zhanged19fc32017-10-19 13:06:22 -0700589 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Crossfc3674a2017-09-18 17:41:52 -0700590 deps.classpath = append(deps.classpath, sdkDep.jar)
591 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
592 }
593
Colin Crossd11fcda2017-10-23 17:59:01 -0700594 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700595 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700596 tag := ctx.OtherModuleDependencyTag(module)
597
Jiyong Park750e5572018-01-31 00:20:13 +0900598 if to, ok := module.(*Library); ok {
Colin Cross42b96642018-04-26 13:14:15 -0700599 switch tag {
600 case bootClasspathTag, libTag, staticLibTag:
601 checkLinkType(ctx, j, to, tag.(dependencyTag))
602 }
Jiyong Park750e5572018-01-31 00:20:13 +0900603 }
Colin Cross54250902017-12-05 09:28:08 -0800604 switch dep := module.(type) {
605 case Dependency:
606 switch tag {
607 case bootClasspathTag:
608 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
609 case libTag:
610 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
611 case staticLibTag:
612 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
613 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
614 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
615 case frameworkResTag:
616 if ctx.ModuleName() == "framework" {
617 // framework.jar has a one-off dependency on the R.java and Manifest.java files
618 // generated by framework-res.apk
619 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
620 }
621 case kotlinStdlibTag:
622 deps.kotlinStdlib = dep.HeaderJars()
623 default:
624 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
625 }
626
627 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
628 case android.SourceFileProducer:
629 switch tag {
630 case libTag:
631 checkProducesJars(ctx, dep)
632 deps.classpath = append(deps.classpath, dep.Srcs()...)
633 case staticLibTag:
634 checkProducesJars(ctx, dep)
635 deps.classpath = append(deps.classpath, dep.Srcs()...)
636 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
637 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
638 case android.DefaultsDepTag, android.SourceDepTag:
639 // Nothing to do
640 default:
641 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
642 }
643 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700644 switch tag {
645 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700646 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700647 case systemModulesTag:
648 if deps.systemModules != nil {
649 panic("Found two system module dependencies")
650 }
651 sm := module.(*SystemModules)
652 if sm.outputFile == nil {
653 panic("Missing directory for system module dependency")
654 }
655 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700656 default:
657 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700658 }
Colin Crossec7a0422017-07-07 14:47:12 -0700659 }
Colin Cross2fe66872015-03-30 17:20:39 -0700660 })
661
Colin Cross32f676a2017-09-06 13:41:06 -0700662 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700663}
664
Nan Zhanged19fc32017-10-19 13:06:22 -0700665func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700666
Colin Crossf03c82b2015-04-13 13:53:40 -0700667 var flags javaBuilderFlags
668
Nan Zhanged19fc32017-10-19 13:06:22 -0700669 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700670 javacFlags := j.properties.Javacflags
Colin Cross6510f912017-11-29 00:27:14 -0800671 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700672 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700673 }
Colin Cross6510f912017-11-29 00:27:14 -0800674 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700675 // Override the -g flag passed globally to remove local variable debug info to reduce
676 // disk and memory usage.
677 javacFlags = append(javacFlags, "-g:source,lines")
678 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700679 if len(javacFlags) > 0 {
680 // optimization.
681 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
682 flags.javacFlags = "$javacFlags"
Colin Cross4f26bc02017-09-06 12:52:16 -0700683 }
Colin Cross64162712017-08-08 13:17:59 -0700684
Andreas Gampef3e5b552018-01-22 21:27:21 -0800685 if len(j.properties.Errorprone.Javacflags) > 0 {
686 flags.errorProneExtraJavacFlags = strings.Join(j.properties.Errorprone.Javacflags, " ")
687 }
688
Nan Zhanged19fc32017-10-19 13:06:22 -0700689 // javaVersion flag.
Nan Zhangea568a42017-11-08 21:20:04 -0800690 sdk := sdkStringToNumber(ctx, String(j.deviceProperties.Sdk_version))
Colin Cross64162712017-08-08 13:17:59 -0700691 if j.properties.Java_version != nil {
692 flags.javaVersion = *j.properties.Java_version
Colin Cross1369cdb2017-09-29 17:58:17 -0700693 } else if ctx.Device() && sdk <= 23 {
694 flags.javaVersion = "1.7"
Colin Cross6510f912017-11-29 00:27:14 -0800695 } else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700696 flags.javaVersion = "1.8"
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900697 } else if ctx.Device() && String(j.deviceProperties.Sdk_version) != "" && sdk == android.FutureApiLevel {
Colin Cross2ebc4762017-10-20 14:00:31 -0700698 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
699 flags.javaVersion = "1.8"
Colin Cross64162712017-08-08 13:17:59 -0700700 } else {
Colin Cross1369cdb2017-09-29 17:58:17 -0700701 flags.javaVersion = "1.9"
Colin Cross64162712017-08-08 13:17:59 -0700702 }
703
Nan Zhanged19fc32017-10-19 13:06:22 -0700704 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800705 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
706 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800707
708 if len(flags.bootClasspath) == 0 && ctx.Host() && !ctx.Config().TargetOpenJDK9() &&
709 !Bool(j.properties.No_standard_libs) &&
710 inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
711 // Give host-side tools a version of OpenJDK's standard libraries
712 // close to what they're targeting. As of Dec 2017, AOSP is only
713 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
714 //
715 // When building with OpenJDK 8, the following should have no
716 // effect since those jars would be available by default.
717 //
718 // When building with OpenJDK 9 but targeting a version < 1.8,
719 // putting them on the bootclasspath means that:
720 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
721 // b) references to existing APIs are not reinterpreted in an
722 // OpenJDK 9-specific way, eg. calls to subclasses of
723 // java.nio.Buffer as in http://b/70862583
724 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
725 flags.bootClasspath = append(flags.bootClasspath,
726 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
727 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -0800728 if Bool(j.properties.Use_tools_jar) {
729 flags.bootClasspath = append(flags.bootClasspath,
730 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
731 }
Colin Cross7fdd2b72018-01-02 18:14:25 -0800732 }
733
Nan Zhanged19fc32017-10-19 13:06:22 -0700734 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700735 if deps.systemModules != nil {
736 flags.systemModules = append(flags.systemModules, deps.systemModules)
737 }
738
Nan Zhanged19fc32017-10-19 13:06:22 -0700739 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700740 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700741 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700742 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700743 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
744 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700745 }
746
Nan Zhanged19fc32017-10-19 13:06:22 -0700747 return flags
748}
Colin Crossc0b06f12015-04-08 13:03:43 -0700749
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800750func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700751
Colin Crossebe1a512017-11-14 13:12:14 -0800752 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700753
754 deps := j.collectDeps(ctx)
755 flags := j.collectBuilderFlags(ctx, deps)
756
Colin Cross6510f912017-11-29 00:27:14 -0800757 if ctx.Config().TargetOpenJDK9() {
Nan Zhanged19fc32017-10-19 13:06:22 -0700758 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
759 }
760 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700761 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -0800762 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700763 }
764
Colin Crossaf050172017-11-15 23:01:59 -0800765 srcFiles = j.genSources(ctx, srcFiles, flags)
766
767 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700768 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800769 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700770
Colin Cross0a6e0072017-08-30 14:24:55 -0700771 var jars android.Paths
772
Colin Cross1ee23172017-10-18 14:44:18 -0700773 jarName := ctx.ModuleName() + ".jar"
774
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000775 javaSrcFiles := srcFiles.FilterByExt(".java")
776 var uniqueSrcFiles android.Paths
777 set := make(map[string]bool)
778 for _, v := range javaSrcFiles {
779 if _, found := set[v.String()]; !found {
780 set[v.String()] = true
781 uniqueSrcFiles = append(uniqueSrcFiles, v)
782 }
783 }
784
Colin Cross93e85952017-08-15 13:34:18 -0700785 if srcFiles.HasExt(".kt") {
786 // If there are kotlin files, compile them first but pass all the kotlin and java files
787 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
788 // won't emit any classes for them.
789
790 flags.kotlincFlags = "-no-stdlib"
791 if ctx.Device() {
792 flags.kotlincFlags += " -no-jdk"
793 }
794
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000795 var kotlinSrcFiles android.Paths
796 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
797 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
798
Colin Cross93e85952017-08-15 13:34:18 -0700799 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
800 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
801
Colin Cross1ee23172017-10-18 14:44:18 -0700802 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000803 TransformKotlinToClasses(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -0700804 if ctx.Failed() {
805 return
806 }
807
808 // Make javac rule depend on the kotlinc rule
809 flags.classpath = append(flags.classpath, kotlinJar)
810 // Jar kotlin classes into the final jar after javac
811 jars = append(jars, kotlinJar)
812 jars = append(jars, deps.kotlinStdlib...)
813 }
814
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800815 // Store the list of .java files that was passed to javac
816 j.compiledJavaSrcs = uniqueSrcFiles
817 j.compiledSrcJars = srcJars
818
Nan Zhang61eaedb2017-11-02 13:28:15 -0700819 enable_sharding := false
Colin Cross6510f912017-11-29 00:27:14 -0800820 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") {
Nan Zhang61eaedb2017-11-02 13:28:15 -0700821 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
822 enable_sharding = true
823 if len(j.properties.Annotation_processors) != 0 ||
824 len(j.properties.Annotation_processor_classes) != 0 {
825 ctx.PropertyErrorf("javac_shard_size",
826 "%q cannot be set when annotation processors are enabled.",
827 j.properties.Javac_shard_size)
828 }
829 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700830 // If sdk jar is java module, then directly return classesJar as header.jar
831 if j.Name() != "android_stubs_current" && j.Name() != "android_system_stubs_current" &&
832 j.Name() != "android_test_stubs_current" {
833 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName)
834 if ctx.Failed() {
835 return
836 }
837 }
838 }
Colin Cross8eadbf02017-10-24 17:46:00 -0700839 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -0700840 var extraJarDeps android.Paths
Colin Cross6510f912017-11-29 00:27:14 -0800841 if ctx.Config().IsEnvTrue("RUN_ERROR_PRONE") {
Colin Crossc6bbef32017-08-14 14:16:06 -0700842 // If error-prone is enabled, add an additional rule to compile the java files into
843 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -0700844 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -0700845 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
846 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -0700847 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -0700848 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -0700849 extraJarDeps = append(extraJarDeps, errorprone)
850 }
851
Nan Zhang61eaedb2017-11-02 13:28:15 -0700852 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -0800853 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -0700854 shardSize := int(*(j.properties.Javac_shard_size))
855 var shardSrcs []android.Paths
856 if len(uniqueSrcFiles) > 0 {
857 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
858 for idx, shardSrc := range shardSrcs {
859 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
860 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
861 jars = append(jars, classes)
862 }
863 }
864 if len(srcJars) > 0 {
865 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
866 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
867 jars = append(jars, classes)
868 }
869 } else {
870 classes := android.PathForModuleOut(ctx, "javac", jarName)
871 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
872 jars = append(jars, classes)
873 }
Colin Crossd6891432017-09-27 17:39:56 -0700874 if ctx.Failed() {
875 return
876 }
Colin Cross2fe66872015-03-30 17:20:39 -0700877 }
878
Colin Cross0f37af02017-09-27 17:42:05 -0700879 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
880 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
881
882 var resArgs []string
883 var resDeps android.Paths
884
885 resArgs = append(resArgs, dirArgs...)
886 resDeps = append(resDeps, dirDeps...)
887
888 resArgs = append(resArgs, fileArgs...)
889 resDeps = append(resDeps, fileDeps...)
890
891 if proptools.Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -0700892 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700893 resArgs = append(resArgs, srcArgs...)
894 resDeps = append(resDeps, srcDeps...)
895 }
Colin Cross40a36712017-09-27 17:41:35 -0700896
897 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -0700898 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700899 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -0700900 if ctx.Failed() {
901 return
902 }
Colin Cross20978302015-04-10 17:05:07 -0700903
Colin Cross0a6e0072017-08-30 14:24:55 -0700904 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -0700905 }
906
Colin Cross6ade34f2017-09-15 13:00:47 -0700907 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -0700908 jars = append(jars, deps.staticJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -0700909
Colin Cross366938f2017-12-11 16:29:02 -0800910 var manifest android.OptionalPath
911 if j.properties.Manifest != nil {
912 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
913 }
Colin Cross635acc92017-09-12 22:50:46 -0700914
Colin Cross0a6e0072017-08-30 14:24:55 -0700915 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -0700916 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -0700917 var outputFile android.Path
918
919 if len(jars) == 1 && !manifest.Valid() {
920 // Optimization: skip the combine step if there is nothing to do
Colin Cross7b60cdd2017-12-21 13:52:58 -0800921 // TODO(ccross): this leaves any module-info.class files, but those should only come from
922 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
923 // any if len(jars) == 1.
Colin Crosse9a275b2017-10-16 17:09:48 -0700924 outputFile = jars[0]
925 } else {
Colin Cross1ee23172017-10-18 14:44:18 -0700926 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Nan Zhanged19fc32017-10-19 13:06:22 -0700927 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -0700928 outputFile = combinedJar
929 }
Colin Cross0a6e0072017-08-30 14:24:55 -0700930
931 if j.properties.Jarjar_rules != nil {
932 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -0700933 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -0700934 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700935 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
936 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -0700937 if ctx.Failed() {
938 return
939 }
940 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700941 j.implementationJarFile = outputFile
942 if j.headerJarFile == nil {
943 j.headerJarFile = j.implementationJarFile
944 }
Colin Cross2fe66872015-03-30 17:20:39 -0700945
Colin Cross6510f912017-11-29 00:27:14 -0800946 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -0800947 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
948 j.properties.Instrument = true
949 }
950 }
951
Colin Cross3144dfc2018-01-03 15:06:47 -0800952 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -0800953 outputFile = j.instrument(ctx, flags, outputFile, jarName)
954 }
955
956 if ctx.Device() && j.installable() {
Colin Crossf0056cb2017-12-22 15:56:08 -0800957 outputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -0700958 if ctx.Failed() {
959 return
960 }
Colin Cross2fe66872015-03-30 17:20:39 -0700961 }
Colin Crossb7a63242015-04-16 14:09:14 -0700962 ctx.CheckbuildFile(outputFile)
963 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700964}
965
Colin Cross8eadbf02017-10-24 17:46:00 -0700966func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Nan Zhanged19fc32017-10-19 13:06:22 -0700967 deps deps, flags javaBuilderFlags, jarName string) android.Path {
968
969 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -0700970 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700971 // Compile java sources into turbine.jar.
972 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
973 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
974 if ctx.Failed() {
975 return nil
976 }
977 jars = append(jars, turbineJar)
978 }
979
980 // Combine any static header libraries into classes-header.jar. If there is only
981 // one input jar this step will be skipped.
982 var headerJar android.Path
983 jars = append(jars, deps.staticHeaderJars...)
984
Colin Cross5c6ecc12017-10-23 18:12:27 -0700985 // we cannot skip the combine step for now if there is only one jar
986 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
987 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
988 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, false, []string{"META-INF"})
989 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -0700990
991 if j.properties.Jarjar_rules != nil {
992 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
993 // Transform classes.jar into classes-jarjar.jar
994 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
995 TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules)
996 headerJar = jarjarFile
997 if ctx.Failed() {
998 return nil
999 }
1000 }
1001
1002 return headerJar
1003}
1004
Colin Crosscb933592017-11-22 13:49:43 -08001005func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
1006 classesJar android.Path, jarName string) android.Path {
1007
Colin Cross7a3139e2017-12-19 13:57:50 -08001008 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001009
Colin Cross84c38822018-01-03 15:59:46 -08001010 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001011 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1012
1013 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1014
1015 j.jacocoReportClassesFile = jacocoReportClassesFile
1016
1017 return instrumentedJar
1018}
1019
Colin Crosscb933592017-11-22 13:49:43 -08001020// Returns a sdk version as a string that is guaranteed to be a parseable as a number. For
1021// modules targeting an unreleased SDK (meaning it does not yet have a number) it returns "10000".
1022func (j *Module) minSdkVersionNumber(ctx android.ModuleContext) string {
1023 switch String(j.deviceProperties.Sdk_version) {
Jiyong Park750e5572018-01-31 00:20:13 +09001024 case "", "current", "test_current", "system_current", "core_current":
Colin Cross6510f912017-11-29 00:27:14 -08001025 return strconv.Itoa(ctx.Config().DefaultAppTargetSdkInt())
Colin Crosscb933592017-11-22 13:49:43 -08001026 default:
Sundong Ahn0926fae2017-10-17 16:34:51 +09001027 return android.GetNumericSdkVersion(String(j.deviceProperties.Sdk_version))
Colin Crosscb933592017-11-22 13:49:43 -08001028 }
1029}
1030
Colin Cross59f1bb62017-09-27 17:59:10 -07001031func (j *Module) installable() bool {
1032 return j.properties.Installable == nil || *j.properties.Installable
1033}
1034
Colin Crossf506d872017-07-19 15:53:04 -07001035var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001036
Nan Zhanged19fc32017-10-19 13:06:22 -07001037func (j *Module) HeaderJars() android.Paths {
1038 return android.Paths{j.headerJarFile}
1039}
1040
1041func (j *Module) ImplementationJars() android.Paths {
1042 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001043}
1044
Colin Cross46c9b8b2017-06-22 16:51:17 -07001045func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001046 return j.exportAidlIncludeDirs
1047}
1048
Colin Cross46c9b8b2017-06-22 16:51:17 -07001049var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001050
Colin Cross46c9b8b2017-06-22 16:51:17 -07001051func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001052 return j.logtagsSrcs
1053}
1054
Colin Cross2fe66872015-03-30 17:20:39 -07001055//
1056// Java libraries (.jar file)
1057//
1058
Colin Crossf506d872017-07-19 15:53:04 -07001059type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001060 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001061}
1062
Colin Crossf506d872017-07-19 15:53:04 -07001063func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001064 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001065
Colin Cross59f1bb62017-09-27 17:59:10 -07001066 if j.installable() {
Colin Cross2c429dc2017-08-31 16:45:16 -07001067 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1068 ctx.ModuleName()+".jar", j.outputFile)
1069 }
Colin Crossb7a63242015-04-16 14:09:14 -07001070}
1071
Colin Crossf506d872017-07-19 15:53:04 -07001072func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001073 j.deps(ctx)
1074}
1075
Colin Crossa60ead82017-10-02 18:10:21 -07001076func LibraryFactory(installable bool) func() android.Module {
1077 return func() android.Module {
1078 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001079
Colin Crossa60ead82017-10-02 18:10:21 -07001080 if !installable {
1081 module.properties.Installable = proptools.BoolPtr(false)
1082 }
Colin Cross2fe66872015-03-30 17:20:39 -07001083
Colin Crossa60ead82017-10-02 18:10:21 -07001084 module.AddProperties(
1085 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001086 &module.Module.deviceProperties,
1087 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001088
Colin Crossa60ead82017-10-02 18:10:21 -07001089 InitJavaModule(module, android.HostAndDeviceSupported)
1090 return module
1091 }
Colin Cross2fe66872015-03-30 17:20:39 -07001092}
1093
Colin Crossf506d872017-07-19 15:53:04 -07001094func LibraryHostFactory() android.Module {
1095 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001096
Colin Cross6af17aa2017-09-20 12:59:05 -07001097 module.AddProperties(
1098 &module.Module.properties,
1099 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001100
Colin Cross89536d42017-07-07 14:35:50 -07001101 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001102 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001103}
1104
1105//
1106// Java Binaries (.jar file plus wrapper script)
1107//
1108
Colin Crossf506d872017-07-19 15:53:04 -07001109type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001110 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001111 Wrapper *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001112}
1113
Colin Crossf506d872017-07-19 15:53:04 -07001114type Binary struct {
1115 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001116
Colin Crossf506d872017-07-19 15:53:04 -07001117 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001118
Colin Cross6b4a32d2017-12-05 13:42:45 -08001119 isWrapperVariant bool
1120
Colin Crossc3315992017-12-08 19:12:36 -08001121 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001122 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001123}
1124
Alex Light24237172017-10-26 09:46:21 -07001125func (j *Binary) HostToolPath() android.OptionalPath {
1126 return android.OptionalPathForPath(j.binaryFile)
1127}
1128
Colin Crossf506d872017-07-19 15:53:04 -07001129func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001130 if ctx.Arch().ArchType == android.Common {
1131 // Compile the jar
1132 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001133 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001134 // Handle the binary wrapper
1135 j.isWrapperVariant = true
1136
Colin Cross366938f2017-12-11 16:29:02 -08001137 if j.binaryProperties.Wrapper != nil {
1138 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001139 } else {
1140 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1141 }
1142
1143 // Depend on the installed jar so that the wrapper doesn't get executed by
1144 // another build rule before the jar has been installed.
1145 jarFile := ctx.PrimaryModule().(*Binary).installFile
1146
1147 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1148 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001149 }
Colin Cross2fe66872015-03-30 17:20:39 -07001150}
1151
Colin Crossf506d872017-07-19 15:53:04 -07001152func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001153 if ctx.Arch().ArchType == android.Common {
1154 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001155 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001156 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001157 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001158}
1159
Colin Crossf506d872017-07-19 15:53:04 -07001160func BinaryFactory() android.Module {
1161 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001162
Colin Cross36242852017-06-23 15:06:31 -07001163 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001164 &module.Module.properties,
1165 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001166 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001167 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001168
Colin Cross6b4a32d2017-12-05 13:42:45 -08001169 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1170 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001171 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001172}
1173
Colin Crossf506d872017-07-19 15:53:04 -07001174func BinaryHostFactory() android.Module {
1175 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001176
Colin Cross36242852017-06-23 15:06:31 -07001177 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001178 &module.Module.properties,
1179 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001180 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001181 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001182
Colin Cross6b4a32d2017-12-05 13:42:45 -08001183 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1184 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001185 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001186}
1187
1188//
1189// Java prebuilts
1190//
1191
Colin Cross74d73e22017-08-02 11:05:49 -07001192type ImportProperties struct {
1193 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001194
Nan Zhangea568a42017-11-08 21:20:04 -08001195 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001196
1197 Installable *bool
Colin Cross74d73e22017-08-02 11:05:49 -07001198}
1199
1200type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001201 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001202 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001203
Colin Cross74d73e22017-08-02 11:05:49 -07001204 properties ImportProperties
1205
Colin Cross0a6e0072017-08-30 14:24:55 -07001206 classpathFiles android.Paths
1207 combinedClasspathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -07001208}
1209
Colin Cross74d73e22017-08-02 11:05:49 -07001210func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001211 return &j.prebuilt
1212}
1213
Colin Cross74d73e22017-08-02 11:05:49 -07001214func (j *Import) PrebuiltSrcs() []string {
1215 return j.properties.Jars
1216}
1217
1218func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001219 return j.prebuilt.Name(j.ModuleBase.Name())
1220}
1221
Colin Cross74d73e22017-08-02 11:05:49 -07001222func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross1e676be2016-10-12 14:38:15 -07001223}
1224
Colin Cross74d73e22017-08-02 11:05:49 -07001225func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1226 j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07001227
Colin Crosse9a275b2017-10-16 17:09:48 -07001228 outputFile := android.PathForModuleOut(ctx, "classes.jar")
Nan Zhanged19fc32017-10-19 13:06:22 -07001229 TransformJarsToJar(ctx, outputFile, "for prebuilts", j.classpathFiles, android.OptionalPath{}, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001230 j.combinedClasspathFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -07001231}
1232
Colin Cross74d73e22017-08-02 11:05:49 -07001233var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001234
Nan Zhanged19fc32017-10-19 13:06:22 -07001235func (j *Import) HeaderJars() android.Paths {
1236 return j.classpathFiles
1237}
1238
1239func (j *Import) ImplementationJars() android.Paths {
Colin Cross74d73e22017-08-02 11:05:49 -07001240 return j.classpathFiles
Colin Cross2fe66872015-03-30 17:20:39 -07001241}
1242
Colin Cross74d73e22017-08-02 11:05:49 -07001243func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001244 return nil
1245}
1246
Colin Cross74d73e22017-08-02 11:05:49 -07001247var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001248
Colin Cross74d73e22017-08-02 11:05:49 -07001249func ImportFactory() android.Module {
1250 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001251
Colin Cross74d73e22017-08-02 11:05:49 -07001252 module.AddProperties(&module.properties)
1253
1254 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -07001255 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1256 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001257}
1258
Colin Cross74d73e22017-08-02 11:05:49 -07001259func ImportFactoryHost() android.Module {
1260 module := &Import{}
1261
1262 module.AddProperties(&module.properties)
1263
1264 android.InitPrebuiltModule(module, &module.properties.Jars)
1265 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
1266 return module
1267}
1268
Colin Cross89536d42017-07-07 14:35:50 -07001269//
1270// Defaults
1271//
1272type Defaults struct {
1273 android.ModuleBase
1274 android.DefaultsModuleBase
1275}
1276
1277func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1278}
1279
1280func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1281}
1282
1283func defaultsFactory() android.Module {
1284 return DefaultsFactory()
1285}
1286
1287func DefaultsFactory(props ...interface{}) android.Module {
1288 module := &Defaults{}
1289
1290 module.AddProperties(props...)
1291 module.AddProperties(
1292 &CompilerProperties{},
1293 &CompilerDeviceProperties{},
Dan Willemsenb785b612018-03-08 13:27:59 -08001294 &android.ProtoProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07001295 )
1296
1297 android.InitDefaultsModule(module)
1298
1299 return module
1300}
Nan Zhangea568a42017-11-08 21:20:04 -08001301
1302var Bool = proptools.Bool
1303var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08001304var inList = android.InList