blob: e6ed931fe226da94704191bcb9b9de424a8e142c [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
Colin Cross1369cdb2017-09-29 17:58:17 -0700119 Openjdk9 struct {
120 // List of source files that should only be used when passing -source 1.9
121 Srcs []string
122
123 // List of javac flags that should only be used when passing -source 1.9
124 Javacflags []string
125 }
Colin Crosscb933592017-11-22 13:49:43 -0800126
127 Jacoco struct {
128 // List of classes to include for instrumentation with jacoco to collect coverage
129 // information at runtime when building with coverage enabled. If unset defaults to all
130 // classes.
131 // Supports '*' as the last character of an entry in the list as a wildcard match.
132 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
133 // it matches classes in the package that have the class name as a prefix.
134 Include_filter []string
135
136 // List of classes to exclude from instrumentation with jacoco to collect coverage
137 // information at runtime when building with coverage enabled. Overrides classes selected
138 // by the include_filter property.
139 // Supports '*' as the last character of an entry in the list as a wildcard match.
140 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
141 // it matches classes in the package that have the class name as a prefix.
142 Exclude_filter []string
143 }
144
Colin Cross0f2ee152017-12-14 15:22:43 -0800145 Proto struct {
146 // List of extra options that will be passed to the proto generator.
147 Output_params []string
148 }
149
Colin Crosscb933592017-11-22 13:49:43 -0800150 Instrument bool `blueprint:"mutated"`
Colin Cross540eff82017-06-22 17:01:52 -0700151}
152
Colin Cross89536d42017-07-07 14:35:50 -0700153type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700154 // list of module-specific flags that will be used for dex compiles
155 Dxflags []string `android:"arch_variant"`
156
Colin Cross7d5136f2015-05-11 13:39:40 -0700157 // if not blank, set to the version of the sdk to compile against
Nan Zhangea568a42017-11-08 21:20:04 -0800158 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700159
Colin Crossebe1a512017-11-14 13:12:14 -0800160 Aidl struct {
161 // Top level directories to pass to aidl tool
162 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700163
Colin Crossebe1a512017-11-14 13:12:14 -0800164 // Directories rooted at the Android.bp file to pass to aidl tool
165 Local_include_dirs []string
166
167 // directories that should be added as include directories for any aidl sources of modules
168 // that depend on this module, as well as to aidl for this module.
169 Export_include_dirs []string
170 }
Colin Cross92430102017-10-09 14:59:32 -0700171
172 // If true, export a copy of the module as a -hostdex module for host testing.
173 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700174
Colin Cross1bd87802017-12-05 15:31:19 -0800175 Dex_preopt struct {
176 // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to
177 // true.
178 Enabled *bool
179
180 // If true, generate an app image (.art file) for this module.
181 App_image *bool
182
183 // If true, use a checked-in profile to guide optimization. Defaults to false unless
184 // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR
185 // that matches the name of this module, in which case it is defaulted to true.
186 Profile_guided *bool
187
188 // If set, provides the path to profile relative to the Android.bp file. If not set,
189 // defaults to searching for a file that matches the name of this module in the default
190 // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found.
191 Profile *string
192 }
Colin Crossa22116e2017-10-19 14:18:58 -0700193
Colin Cross1369cdb2017-09-29 17:58:17 -0700194 // When targeting 1.9, override the modules to use with --system
195 System_modules *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700196}
197
Colin Cross46c9b8b2017-06-22 16:51:17 -0700198// Module contains the properties and members used by all java module types
199type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700200 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700201 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700202
Colin Cross89536d42017-07-07 14:35:50 -0700203 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700204 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700205 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700206
Nan Zhanged19fc32017-10-19 13:06:22 -0700207 // header jar file suitable for inserting into the bootclasspath/classpath of another compile
208 headerJarFile android.Path
209
210 // full implementation jar file suitable for static dependency of another module compile
211 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700212
Colin Cross6ade34f2017-09-15 13:00:47 -0700213 // output file containing classes.dex
214 dexJarFile android.Path
215
Colin Crosscb933592017-11-22 13:49:43 -0800216 // output file containing uninstrumented classes that will be instrumented by jacoco
217 jacocoReportClassesFile android.Path
218
Colin Crossb7a63242015-04-16 14:09:14 -0700219 // output file suitable for installing or running
Colin Cross635c3b02016-05-18 15:37:25 -0700220 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700221
Colin Cross635c3b02016-05-18 15:37:25 -0700222 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700223
Colin Cross635c3b02016-05-18 15:37:25 -0700224 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700225
Colin Cross2fe66872015-03-30 17:20:39 -0700226 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700227 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800228
229 // list of .java files and srcjars that was passed to javac
230 compiledJavaSrcs android.Paths
231 compiledSrcJars android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700232}
233
Colin Cross54250902017-12-05 09:28:08 -0800234func (j *Module) Srcs() android.Paths {
235 return android.Paths{j.implementationJarFile}
236}
237
238var _ android.SourceFileProducer = (*Module)(nil)
239
Colin Crossf506d872017-07-19 15:53:04 -0700240type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700241 HeaderJars() android.Paths
242 ImplementationJars() android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700243 AidlIncludeDirs() android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700244}
245
Colin Cross89536d42017-07-07 14:35:50 -0700246func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
247 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
248 android.InitDefaultableModule(module)
249}
250
Colin Crossbe1da472017-07-07 15:59:46 -0700251type dependencyTag struct {
252 blueprint.BaseDependencyTag
253 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700254}
255
Colin Crossbe1da472017-07-07 15:59:46 -0700256var (
Colin Cross6ade34f2017-09-15 13:00:47 -0700257 staticLibTag = dependencyTag{name: "staticlib"}
258 libTag = dependencyTag{name: "javalib"}
259 bootClasspathTag = dependencyTag{name: "bootclasspath"}
Colin Cross1369cdb2017-09-29 17:58:17 -0700260 systemModulesTag = dependencyTag{name: "system modules"}
Colin Cross6ade34f2017-09-15 13:00:47 -0700261 frameworkResTag = dependencyTag{name: "framework-res"}
Colin Cross93e85952017-08-15 13:34:18 -0700262 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossbe1da472017-07-07 15:59:46 -0700263)
Colin Cross2fe66872015-03-30 17:20:39 -0700264
Colin Crossfc3674a2017-09-18 17:41:52 -0700265type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700266 useModule, useFiles, useDefaultLibs, invalidVersion bool
267
Colin Cross1369cdb2017-09-29 17:58:17 -0700268 module string
269 systemModules string
270
271 jar android.Path
272 aidl android.Path
273}
274
275func sdkStringToNumber(ctx android.BaseContext, v string) int {
276 switch v {
277 case "", "current", "system_current", "test_current":
278 return 10000
279 default:
Sundong Ahn0926fae2017-10-17 16:34:51 +0900280 if i, err := strconv.Atoi(android.GetNumericSdkVersion(v)); err != nil {
Colin Cross1369cdb2017-09-29 17:58:17 -0700281 ctx.PropertyErrorf("sdk_version", "invalid sdk version")
282 return -1
283 } else {
284 return i
285 }
286 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700287}
288
289func decodeSdkDep(ctx android.BaseContext, v string) sdkDep {
Colin Cross1369cdb2017-09-29 17:58:17 -0700290 i := sdkStringToNumber(ctx, v)
291 if i == -1 {
292 // Invalid sdk version, error handled by sdkStringToNumber.
293 return sdkDep{}
Colin Crossfc3674a2017-09-18 17:41:52 -0700294 }
295
296 toFile := func(v string) sdkDep {
297 dir := filepath.Join("prebuilts/sdk", v)
298 jar := filepath.Join(dir, "android.jar")
299 aidl := filepath.Join(dir, "framework.aidl")
300 jarPath := android.ExistentPathForSource(ctx, "sdkdir", jar)
301 aidlPath := android.ExistentPathForSource(ctx, "sdkdir", aidl)
Colin Cross47ff2522017-10-02 14:22:08 -0700302
Colin Cross6510f912017-11-29 00:27:14 -0800303 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
Sundong Ahn0926fae2017-10-17 16:34:51 +0900304 if strings.Contains(v, "system_") {
305 return sdkDep{
306 invalidVersion: true,
307 module: "vsdk_v" + strings.Replace(v, "system_", "", 1),
308 }
309 }
Colin Cross47ff2522017-10-02 14:22:08 -0700310 return sdkDep{
311 invalidVersion: true,
312 module: "sdk_v" + v,
313 }
314 }
315
Colin Crossfc3674a2017-09-18 17:41:52 -0700316 if !jarPath.Valid() {
317 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar)
318 return sdkDep{}
319 }
Colin Cross47ff2522017-10-02 14:22:08 -0700320
Colin Crossfc3674a2017-09-18 17:41:52 -0700321 if !aidlPath.Valid() {
322 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl)
323 return sdkDep{}
324 }
Colin Cross47ff2522017-10-02 14:22:08 -0700325
Colin Crossfc3674a2017-09-18 17:41:52 -0700326 return sdkDep{
327 useFiles: true,
328 jar: jarPath.Path(),
329 aidl: aidlPath.Path(),
330 }
331 }
332
Colin Cross2ebc4762017-10-20 14:00:31 -0700333 //toModule := func(m string) sdkDep {
334 // return sdkDep{
335 // useModule: true,
336 // module: m,
337 // systemModules: m + "_system_modules",
338 // }
339 //}
Colin Crossfc3674a2017-09-18 17:41:52 -0700340
Colin Cross6510f912017-11-29 00:27:14 -0800341 if ctx.Config().UnbundledBuild() && v != "" {
Colin Crossfc3674a2017-09-18 17:41:52 -0700342 return toFile(v)
343 }
344
345 switch v {
346 case "":
347 return sdkDep{
348 useDefaultLibs: true,
349 }
Colin Cross2ebc4762017-10-20 14:00:31 -0700350 // TODO(ccross): re-enable these once we generate stubs, until then
351 // use the stubs in prebuilts/sdk/*current
352 //case "current":
353 // return toModule("android_stubs_current")
354 //case "system_current":
355 // return toModule("android_system_stubs_current")
356 //case "test_current":
357 // return toModule("android_test_stubs_current")
Colin Crossfc3674a2017-09-18 17:41:52 -0700358 default:
359 return toFile(v)
360 }
361}
362
Colin Crossbe1da472017-07-07 15:59:46 -0700363func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700364 if ctx.Device() {
365 if !proptools.Bool(j.properties.No_standard_libs) {
Nan Zhangea568a42017-11-08 21:20:04 -0800366 sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
Colin Crossfc3674a2017-09-18 17:41:52 -0700367 if sdkDep.useDefaultLibs {
Colin Crosscb2c9292017-09-23 19:57:16 -0700368 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Colin Cross6510f912017-11-29 00:27:14 -0800369 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700370 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
371 }
Colin Crossfa5eb232017-10-01 20:33:03 -0700372 if !proptools.Bool(j.properties.No_framework_libs) {
373 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
374 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700375 } else if sdkDep.useModule {
Colin Cross6510f912017-11-29 00:27:14 -0800376 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700377 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
378 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700379 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module)
Colin Crossbe1da472017-07-07 15:59:46 -0700380 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700381 } else if j.deviceProperties.System_modules == nil {
382 ctx.PropertyErrorf("no_standard_libs",
383 "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 -0800384 } else if *j.deviceProperties.System_modules != "none" && ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700385 ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700386 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800387 if ctx.ModuleName() == "framework" {
388 ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res")
389 }
Colin Cross2fe66872015-03-30 17:20:39 -0700390 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700391
Colin Crossf506d872017-07-19 15:53:04 -0700392 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
393 ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
Colin Cross6ade34f2017-09-15 13:00:47 -0700394 ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...)
Colin Cross7f9036c2017-08-30 13:27:57 -0700395
396 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700397 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross366938f2017-12-11 16:29:02 -0800398 android.ExtractSourceDeps(ctx, j.properties.Manifest)
Colin Cross6af17aa2017-09-20 12:59:05 -0700399
400 if j.hasSrcExt(".proto") {
401 protoDeps(ctx, &j.protoProperties)
402 }
Colin Cross93e85952017-08-15 13:34:18 -0700403
404 if j.hasSrcExt(".kt") {
405 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
406 // Kotlin files
407 ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib")
408 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700409}
410
411func hasSrcExt(srcs []string, ext string) bool {
412 for _, src := range srcs {
413 if filepath.Ext(src) == ext {
414 return true
415 }
416 }
417
418 return false
419}
420
Nan Zhang61eaedb2017-11-02 13:28:15 -0700421func shardPaths(paths android.Paths, shardSize int) []android.Paths {
422 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
423 for len(paths) > shardSize {
424 ret = append(ret, paths[0:shardSize])
425 paths = paths[shardSize:]
426 }
427 if len(paths) > 0 {
428 ret = append(ret, paths)
429 }
430 return ret
431}
432
Colin Cross6af17aa2017-09-20 12:59:05 -0700433func (j *Module) hasSrcExt(ext string) bool {
434 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700435}
436
Colin Cross46c9b8b2017-06-22 16:51:17 -0700437func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700438 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700439
Colin Crossebe1a512017-11-14 13:12:14 -0800440 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
441 aidlIncludes = append(aidlIncludes,
442 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
443 aidlIncludes = append(aidlIncludes,
444 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700445
446 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700447 if aidlPreprocess.Valid() {
448 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700449 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700450 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700451 }
452
Colin Cross635c3b02016-05-18 15:37:25 -0700453 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800454 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700455 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Crosse243c232017-10-21 15:16:37 -0700456 if src := android.ExistentPathForSource(ctx, "", ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700457 flags = append(flags, "-I"+src.String())
458 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700459
Colin Crossf03c82b2015-04-13 13:53:40 -0700460 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700461}
462
Colin Cross32f676a2017-09-06 13:41:06 -0700463type deps struct {
Colin Cross6ade34f2017-09-15 13:00:47 -0700464 classpath android.Paths
465 bootClasspath android.Paths
466 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700467 staticHeaderJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700468 staticJarResources android.Paths
469 aidlIncludeDirs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700470 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700471 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700472 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700473 kotlinStdlib android.Paths
Colin Cross32f676a2017-09-06 13:41:06 -0700474}
Colin Cross2fe66872015-03-30 17:20:39 -0700475
Colin Cross54250902017-12-05 09:28:08 -0800476func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
477 for _, f := range dep.Srcs() {
478 if f.Ext() != ".jar" {
479 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
480 ctx.OtherModuleName(dep.(blueprint.Module)))
481 }
482 }
483}
484
Colin Cross32f676a2017-09-06 13:41:06 -0700485func (j *Module) collectDeps(ctx android.ModuleContext) deps {
486 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700487
Nan Zhangea568a42017-11-08 21:20:04 -0800488 sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
Colin Cross47ff2522017-10-02 14:22:08 -0700489 if sdkDep.invalidVersion {
490 ctx.AddMissingDependencies([]string{sdkDep.module})
491 } else if sdkDep.useFiles {
Nan Zhanged19fc32017-10-19 13:06:22 -0700492 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Crossfc3674a2017-09-18 17:41:52 -0700493 deps.classpath = append(deps.classpath, sdkDep.jar)
494 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
495 }
496
Colin Crossd11fcda2017-10-23 17:59:01 -0700497 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700498 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700499 tag := ctx.OtherModuleDependencyTag(module)
500
Colin Cross54250902017-12-05 09:28:08 -0800501 switch dep := module.(type) {
502 case Dependency:
503 switch tag {
504 case bootClasspathTag:
505 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
506 case libTag:
507 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
508 case staticLibTag:
509 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
510 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
511 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
512 case frameworkResTag:
513 if ctx.ModuleName() == "framework" {
514 // framework.jar has a one-off dependency on the R.java and Manifest.java files
515 // generated by framework-res.apk
516 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
517 }
518 case kotlinStdlibTag:
519 deps.kotlinStdlib = dep.HeaderJars()
520 default:
521 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
522 }
523
524 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
525 case android.SourceFileProducer:
526 switch tag {
527 case libTag:
528 checkProducesJars(ctx, dep)
529 deps.classpath = append(deps.classpath, dep.Srcs()...)
530 case staticLibTag:
531 checkProducesJars(ctx, dep)
532 deps.classpath = append(deps.classpath, dep.Srcs()...)
533 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
534 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
535 case android.DefaultsDepTag, android.SourceDepTag:
536 // Nothing to do
537 default:
538 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
539 }
540 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700541 switch tag {
542 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700543 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700544 case systemModulesTag:
545 if deps.systemModules != nil {
546 panic("Found two system module dependencies")
547 }
548 sm := module.(*SystemModules)
549 if sm.outputFile == nil {
550 panic("Missing directory for system module dependency")
551 }
552 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700553 default:
554 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700555 }
Colin Crossec7a0422017-07-07 14:47:12 -0700556 }
Colin Cross2fe66872015-03-30 17:20:39 -0700557 })
558
Colin Cross32f676a2017-09-06 13:41:06 -0700559 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700560}
561
Nan Zhanged19fc32017-10-19 13:06:22 -0700562func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700563
Colin Crossf03c82b2015-04-13 13:53:40 -0700564 var flags javaBuilderFlags
565
Nan Zhanged19fc32017-10-19 13:06:22 -0700566 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700567 javacFlags := j.properties.Javacflags
Colin Cross6510f912017-11-29 00:27:14 -0800568 if ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700569 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700570 }
Colin Cross6510f912017-11-29 00:27:14 -0800571 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700572 // Override the -g flag passed globally to remove local variable debug info to reduce
573 // disk and memory usage.
574 javacFlags = append(javacFlags, "-g:source,lines")
575 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700576 if len(javacFlags) > 0 {
577 // optimization.
578 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
579 flags.javacFlags = "$javacFlags"
Colin Cross4f26bc02017-09-06 12:52:16 -0700580 }
Colin Cross64162712017-08-08 13:17:59 -0700581
Nan Zhanged19fc32017-10-19 13:06:22 -0700582 // javaVersion flag.
Nan Zhangea568a42017-11-08 21:20:04 -0800583 sdk := sdkStringToNumber(ctx, String(j.deviceProperties.Sdk_version))
Colin Cross64162712017-08-08 13:17:59 -0700584 if j.properties.Java_version != nil {
585 flags.javaVersion = *j.properties.Java_version
Colin Cross1369cdb2017-09-29 17:58:17 -0700586 } else if ctx.Device() && sdk <= 23 {
587 flags.javaVersion = "1.7"
Colin Cross6510f912017-11-29 00:27:14 -0800588 } else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700589 flags.javaVersion = "1.8"
Nan Zhangea568a42017-11-08 21:20:04 -0800590 } else if ctx.Device() && String(j.deviceProperties.Sdk_version) != "" && sdk == 10000 {
Colin Cross2ebc4762017-10-20 14:00:31 -0700591 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
592 flags.javaVersion = "1.8"
Colin Cross64162712017-08-08 13:17:59 -0700593 } else {
Colin Cross1369cdb2017-09-29 17:58:17 -0700594 flags.javaVersion = "1.9"
Colin Cross64162712017-08-08 13:17:59 -0700595 }
596
Nan Zhanged19fc32017-10-19 13:06:22 -0700597 // classpath
Colin Cross6ade34f2017-09-15 13:00:47 -0700598 flags.bootClasspath.AddPaths(deps.bootClasspath)
599 flags.classpath.AddPaths(deps.classpath)
Nan Zhanged19fc32017-10-19 13:06:22 -0700600 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700601 if deps.systemModules != nil {
602 flags.systemModules = append(flags.systemModules, deps.systemModules)
603 }
604
Nan Zhanged19fc32017-10-19 13:06:22 -0700605 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700606 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700607 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700608 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700609 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
610 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700611 }
612
Nan Zhanged19fc32017-10-19 13:06:22 -0700613 return flags
614}
Colin Crossc0b06f12015-04-08 13:03:43 -0700615
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800616func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700617
Colin Crossebe1a512017-11-14 13:12:14 -0800618 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700619
620 deps := j.collectDeps(ctx)
621 flags := j.collectBuilderFlags(ctx, deps)
622
Colin Cross6510f912017-11-29 00:27:14 -0800623 if ctx.Config().TargetOpenJDK9() {
Nan Zhanged19fc32017-10-19 13:06:22 -0700624 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
625 }
626 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700627 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -0800628 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700629 }
630
Colin Crossaf050172017-11-15 23:01:59 -0800631 srcFiles = j.genSources(ctx, srcFiles, flags)
632
633 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700634 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800635 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700636
Colin Cross0a6e0072017-08-30 14:24:55 -0700637 var jars android.Paths
638
Colin Cross1ee23172017-10-18 14:44:18 -0700639 jarName := ctx.ModuleName() + ".jar"
640
Colin Cross93e85952017-08-15 13:34:18 -0700641 if srcFiles.HasExt(".kt") {
642 // If there are kotlin files, compile them first but pass all the kotlin and java files
643 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
644 // won't emit any classes for them.
645
646 flags.kotlincFlags = "-no-stdlib"
647 if ctx.Device() {
648 flags.kotlincFlags += " -no-jdk"
649 }
650
651 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
652 flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
653
Colin Cross1ee23172017-10-18 14:44:18 -0700654 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross93e85952017-08-15 13:34:18 -0700655 TransformKotlinToClasses(ctx, kotlinJar, srcFiles, srcJars, flags)
656 if ctx.Failed() {
657 return
658 }
659
660 // Make javac rule depend on the kotlinc rule
661 flags.classpath = append(flags.classpath, kotlinJar)
662 // Jar kotlin classes into the final jar after javac
663 jars = append(jars, kotlinJar)
664 jars = append(jars, deps.kotlinStdlib...)
665 }
666
Nan Zhanged19fc32017-10-19 13:06:22 -0700667 javaSrcFiles := srcFiles.FilterByExt(".java")
668 var uniqueSrcFiles android.Paths
669 set := make(map[string]bool)
670 for _, v := range javaSrcFiles {
671 if _, found := set[v.String()]; !found {
672 set[v.String()] = true
673 uniqueSrcFiles = append(uniqueSrcFiles, v)
674 }
675 }
676
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800677 // Store the list of .java files that was passed to javac
678 j.compiledJavaSrcs = uniqueSrcFiles
679 j.compiledSrcJars = srcJars
Alan Leungc37c6342017-12-13 00:28:49 -0800680 fullD8 := ctx.Config().UseD8Desugar()
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800681
Nan Zhang61eaedb2017-11-02 13:28:15 -0700682 enable_sharding := false
Colin Cross6510f912017-11-29 00:27:14 -0800683 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") {
Nan Zhang61eaedb2017-11-02 13:28:15 -0700684 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
685 enable_sharding = true
686 if len(j.properties.Annotation_processors) != 0 ||
687 len(j.properties.Annotation_processor_classes) != 0 {
688 ctx.PropertyErrorf("javac_shard_size",
689 "%q cannot be set when annotation processors are enabled.",
690 j.properties.Javac_shard_size)
691 }
692 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700693 // If sdk jar is java module, then directly return classesJar as header.jar
694 if j.Name() != "android_stubs_current" && j.Name() != "android_system_stubs_current" &&
695 j.Name() != "android_test_stubs_current" {
696 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName)
697 if ctx.Failed() {
698 return
699 }
700 }
701 }
Colin Cross8eadbf02017-10-24 17:46:00 -0700702 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -0700703 var extraJarDeps android.Paths
Colin Cross6510f912017-11-29 00:27:14 -0800704 if ctx.Config().IsEnvTrue("RUN_ERROR_PRONE") {
Colin Crossc6bbef32017-08-14 14:16:06 -0700705 // If error-prone is enabled, add an additional rule to compile the java files into
706 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -0700707 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -0700708 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
709 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -0700710 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -0700711 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -0700712 extraJarDeps = append(extraJarDeps, errorprone)
713 }
714
Nan Zhang61eaedb2017-11-02 13:28:15 -0700715 if enable_sharding {
716 flags.classpath.AddPaths([]android.Path{j.headerJarFile})
717 shardSize := int(*(j.properties.Javac_shard_size))
718 var shardSrcs []android.Paths
719 if len(uniqueSrcFiles) > 0 {
720 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
721 for idx, shardSrc := range shardSrcs {
722 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
723 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
724 jars = append(jars, classes)
725 }
726 }
727 if len(srcJars) > 0 {
728 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
729 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
730 jars = append(jars, classes)
731 }
732 } else {
733 classes := android.PathForModuleOut(ctx, "javac", jarName)
734 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
735 jars = append(jars, classes)
736 }
Colin Crossd6891432017-09-27 17:39:56 -0700737 if ctx.Failed() {
738 return
739 }
Colin Cross2fe66872015-03-30 17:20:39 -0700740 }
741
Colin Cross0f37af02017-09-27 17:42:05 -0700742 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
743 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
744
745 var resArgs []string
746 var resDeps android.Paths
747
748 resArgs = append(resArgs, dirArgs...)
749 resDeps = append(resDeps, dirDeps...)
750
751 resArgs = append(resArgs, fileArgs...)
752 resDeps = append(resDeps, fileDeps...)
753
754 if proptools.Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -0700755 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700756 resArgs = append(resArgs, srcArgs...)
757 resDeps = append(resDeps, srcDeps...)
758 }
Colin Cross40a36712017-09-27 17:41:35 -0700759
760 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -0700761 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700762 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross65bf4f22015-04-03 16:54:17 -0700763 if ctx.Failed() {
764 return
765 }
Colin Cross20978302015-04-10 17:05:07 -0700766
Colin Cross0a6e0072017-08-30 14:24:55 -0700767 jars = append(jars, resourceJar)
Colin Cross65bf4f22015-04-03 16:54:17 -0700768 }
769
Colin Cross6ade34f2017-09-15 13:00:47 -0700770 // static classpath jars have the resources in them, so the resource jars aren't necessary here
Colin Cross32f676a2017-09-06 13:41:06 -0700771 jars = append(jars, deps.staticJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -0700772
Colin Cross366938f2017-12-11 16:29:02 -0800773 var manifest android.OptionalPath
774 if j.properties.Manifest != nil {
775 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
776 }
Colin Cross635acc92017-09-12 22:50:46 -0700777
Colin Cross0a6e0072017-08-30 14:24:55 -0700778 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -0700779 // classes.jar. If there is only one input jar this step will be skipped.
Colin Crosse9a275b2017-10-16 17:09:48 -0700780 var outputFile android.Path
781
782 if len(jars) == 1 && !manifest.Valid() {
783 // Optimization: skip the combine step if there is nothing to do
784 outputFile = jars[0]
785 } else {
Colin Cross1ee23172017-10-18 14:44:18 -0700786 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Nan Zhanged19fc32017-10-19 13:06:22 -0700787 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -0700788 outputFile = combinedJar
789 }
Colin Cross0a6e0072017-08-30 14:24:55 -0700790
791 if j.properties.Jarjar_rules != nil {
792 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross8649b262017-09-27 18:03:17 -0700793 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -0700794 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -0700795 TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
796 outputFile = jarjarFile
Colin Cross0a6e0072017-08-30 14:24:55 -0700797 if ctx.Failed() {
798 return
799 }
800 }
Nan Zhanged19fc32017-10-19 13:06:22 -0700801 j.implementationJarFile = outputFile
802 if j.headerJarFile == nil {
803 j.headerJarFile = j.implementationJarFile
804 }
Colin Cross2fe66872015-03-30 17:20:39 -0700805
Alan Leung9f319112017-11-30 15:50:39 -0800806 if !fullD8 && ctx.Device() && j.installable() {
Colin Crosscb933592017-11-22 13:49:43 -0800807 outputFile = j.desugar(ctx, flags, outputFile, jarName)
808 }
809
Colin Cross6510f912017-11-29 00:27:14 -0800810 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -0800811 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
812 j.properties.Instrument = true
813 }
814 }
815
Colin Cross6510f912017-11-29 00:27:14 -0800816 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") && j.properties.Instrument {
Colin Crosscb933592017-11-22 13:49:43 -0800817 outputFile = j.instrument(ctx, flags, outputFile, jarName)
818 }
819
820 if ctx.Device() && j.installable() {
Alan Leung9f319112017-11-30 15:50:39 -0800821 if fullD8 {
822 outputFile = j.compileDexFullD8(ctx, flags, outputFile, jarName)
823 } else {
824 outputFile = j.compileDex(ctx, flags, outputFile, jarName)
825 }
Colin Cross2fe66872015-03-30 17:20:39 -0700826 if ctx.Failed() {
827 return
828 }
Colin Cross2fe66872015-03-30 17:20:39 -0700829 }
Colin Crossb7a63242015-04-16 14:09:14 -0700830 ctx.CheckbuildFile(outputFile)
831 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700832}
833
Colin Cross8eadbf02017-10-24 17:46:00 -0700834func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Nan Zhanged19fc32017-10-19 13:06:22 -0700835 deps deps, flags javaBuilderFlags, jarName string) android.Path {
836
837 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -0700838 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700839 // Compile java sources into turbine.jar.
840 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
841 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
842 if ctx.Failed() {
843 return nil
844 }
845 jars = append(jars, turbineJar)
846 }
847
848 // Combine any static header libraries into classes-header.jar. If there is only
849 // one input jar this step will be skipped.
850 var headerJar android.Path
851 jars = append(jars, deps.staticHeaderJars...)
852
Colin Cross5c6ecc12017-10-23 18:12:27 -0700853 // we cannot skip the combine step for now if there is only one jar
854 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
855 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
856 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, false, []string{"META-INF"})
857 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -0700858
859 if j.properties.Jarjar_rules != nil {
860 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
861 // Transform classes.jar into classes-jarjar.jar
862 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
863 TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules)
864 headerJar = jarjarFile
865 if ctx.Failed() {
866 return nil
867 }
868 }
869
870 return headerJar
871}
872
Colin Crosscb933592017-11-22 13:49:43 -0800873func (j *Module) desugar(ctx android.ModuleContext, flags javaBuilderFlags,
874 classesJar android.Path, jarName string) android.Path {
875
876 desugarFlags := []string{
877 "--min_sdk_version " + j.minSdkVersionNumber(ctx),
878 "--desugar_try_with_resources_if_needed=false",
879 "--allow_empty_bootclasspath",
880 }
881
882 if inList("--core-library", j.deviceProperties.Dxflags) {
883 desugarFlags = append(desugarFlags, "--core_library")
884 }
885
886 flags.desugarFlags = strings.Join(desugarFlags, " ")
887
888 desugarJar := android.PathForModuleOut(ctx, "desugar", jarName)
889 TransformDesugar(ctx, desugarJar, classesJar, flags)
890
891 return desugarJar
892}
893
894func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
895 classesJar android.Path, jarName string) android.Path {
896
Colin Cross7a3139e2017-12-19 13:57:50 -0800897 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -0800898
899 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco", "jacoco-report-classes.jar")
900 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
901
902 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
903
904 j.jacocoReportClassesFile = jacocoReportClassesFile
905
906 return instrumentedJar
907}
908
Nan Zhanged19fc32017-10-19 13:06:22 -0700909func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
910 classesJar android.Path, jarName string) android.Path {
911
912 dxFlags := j.deviceProperties.Dxflags
Nan Zhanged19fc32017-10-19 13:06:22 -0700913
Colin Cross6510f912017-11-29 00:27:14 -0800914 if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" {
Nan Zhanged19fc32017-10-19 13:06:22 -0700915 dxFlags = append(dxFlags, "--no-optimize")
916 }
917
Colin Cross6510f912017-11-29 00:27:14 -0800918 if ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" {
Nan Zhanged19fc32017-10-19 13:06:22 -0700919 dxFlags = append(dxFlags,
920 "--debug",
921 "--verbose",
922 "--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(),
923 "--dump-width=1000")
924 }
925
Colin Crosscb933592017-11-22 13:49:43 -0800926 dxFlags = append(dxFlags, "--min-sdk-version="+j.minSdkVersionNumber(ctx))
Nan Zhanged19fc32017-10-19 13:06:22 -0700927
928 flags.dxFlags = strings.Join(dxFlags, " ")
929
Nan Zhanged19fc32017-10-19 13:06:22 -0700930 // Compile classes.jar into classes.dex and then javalib.jar
931 javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
Colin Crosscb933592017-11-22 13:49:43 -0800932 TransformClassesJarToDexJar(ctx, javalibJar, classesJar, flags)
Nan Zhanged19fc32017-10-19 13:06:22 -0700933
934 j.dexJarFile = javalibJar
935 return javalibJar
936}
937
Alan Leung9f319112017-11-30 15:50:39 -0800938func (j *Module) compileDexFullD8(ctx android.ModuleContext, flags javaBuilderFlags,
939 classesJar android.Path, jarName string) android.Path {
940
941 // Translate all the DX flags to D8 ones until all the build files have been migrated
942 // to D8 flags. See: b/69377755
943 var dxFlags []string
944 for _, x := range j.deviceProperties.Dxflags {
945 if x == "--core-library" {
946 continue
947 }
948 if x == "--dex" {
949 continue
950 }
951 if x == "--multi-dex" {
952 continue
953 }
954 if x == "--no-locals" {
955 dxFlags = append(dxFlags, "--release")
956 continue
957 }
958 dxFlags = append(dxFlags, x)
959 }
960
961 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
962 dxFlags = append(dxFlags, "--debug")
963 }
964
965 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
966 dxFlags = append(dxFlags,
967 "--debug",
968 "--verbose")
969 }
970
971 dxFlags = append(dxFlags, "--min-api "+j.minSdkVersionNumber(ctx))
972
973 flags.dxFlags = strings.Join(dxFlags, " ")
974
975 // Compile classes.jar into classes.dex and then javalib.jar
976 javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
977 TransformClassesJarToDexJar(ctx, javalibJar, classesJar, flags)
978
979 j.dexJarFile = javalibJar
980 return javalibJar
981}
982
Colin Crosscb933592017-11-22 13:49:43 -0800983// Returns a sdk version as a string that is guaranteed to be a parseable as a number. For
984// modules targeting an unreleased SDK (meaning it does not yet have a number) it returns "10000".
985func (j *Module) minSdkVersionNumber(ctx android.ModuleContext) string {
986 switch String(j.deviceProperties.Sdk_version) {
987 case "", "current", "test_current", "system_current":
Colin Cross6510f912017-11-29 00:27:14 -0800988 return strconv.Itoa(ctx.Config().DefaultAppTargetSdkInt())
Colin Crosscb933592017-11-22 13:49:43 -0800989 default:
Sundong Ahn0926fae2017-10-17 16:34:51 +0900990 return android.GetNumericSdkVersion(String(j.deviceProperties.Sdk_version))
Colin Crosscb933592017-11-22 13:49:43 -0800991 }
992}
993
Colin Cross59f1bb62017-09-27 17:59:10 -0700994func (j *Module) installable() bool {
995 return j.properties.Installable == nil || *j.properties.Installable
996}
997
Colin Crossf506d872017-07-19 15:53:04 -0700998var _ Dependency = (*Library)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -0700999
Nan Zhanged19fc32017-10-19 13:06:22 -07001000func (j *Module) HeaderJars() android.Paths {
1001 return android.Paths{j.headerJarFile}
1002}
1003
1004func (j *Module) ImplementationJars() android.Paths {
1005 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001006}
1007
Colin Cross46c9b8b2017-06-22 16:51:17 -07001008func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001009 return j.exportAidlIncludeDirs
1010}
1011
Colin Cross46c9b8b2017-06-22 16:51:17 -07001012var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001013
Colin Cross46c9b8b2017-06-22 16:51:17 -07001014func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001015 return j.logtagsSrcs
1016}
1017
Colin Cross2fe66872015-03-30 17:20:39 -07001018//
1019// Java libraries (.jar file)
1020//
1021
Colin Crossf506d872017-07-19 15:53:04 -07001022type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001023 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001024}
1025
Colin Crossf506d872017-07-19 15:53:04 -07001026func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001027 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001028
Colin Cross59f1bb62017-09-27 17:59:10 -07001029 if j.installable() {
Colin Cross2c429dc2017-08-31 16:45:16 -07001030 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1031 ctx.ModuleName()+".jar", j.outputFile)
1032 }
Colin Crossb7a63242015-04-16 14:09:14 -07001033}
1034
Colin Crossf506d872017-07-19 15:53:04 -07001035func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001036 j.deps(ctx)
1037}
1038
Colin Crossa60ead82017-10-02 18:10:21 -07001039func LibraryFactory(installable bool) func() android.Module {
1040 return func() android.Module {
1041 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001042
Colin Crossa60ead82017-10-02 18:10:21 -07001043 if !installable {
1044 module.properties.Installable = proptools.BoolPtr(false)
1045 }
Colin Cross2fe66872015-03-30 17:20:39 -07001046
Colin Crossa60ead82017-10-02 18:10:21 -07001047 module.AddProperties(
1048 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001049 &module.Module.deviceProperties,
1050 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001051
Colin Crossa60ead82017-10-02 18:10:21 -07001052 InitJavaModule(module, android.HostAndDeviceSupported)
1053 return module
1054 }
Colin Cross2fe66872015-03-30 17:20:39 -07001055}
1056
Colin Crossf506d872017-07-19 15:53:04 -07001057func LibraryHostFactory() android.Module {
1058 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001059
Colin Cross6af17aa2017-09-20 12:59:05 -07001060 module.AddProperties(
1061 &module.Module.properties,
1062 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001063
Colin Cross89536d42017-07-07 14:35:50 -07001064 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001065 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001066}
1067
1068//
1069// Java Binaries (.jar file plus wrapper script)
1070//
1071
Colin Crossf506d872017-07-19 15:53:04 -07001072type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001073 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001074 Wrapper *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001075}
1076
Colin Crossf506d872017-07-19 15:53:04 -07001077type Binary struct {
1078 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001079
Colin Crossf506d872017-07-19 15:53:04 -07001080 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001081
Colin Cross6b4a32d2017-12-05 13:42:45 -08001082 isWrapperVariant bool
1083
Colin Crossc3315992017-12-08 19:12:36 -08001084 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001085 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001086}
1087
Alex Light24237172017-10-26 09:46:21 -07001088func (j *Binary) HostToolPath() android.OptionalPath {
1089 return android.OptionalPathForPath(j.binaryFile)
1090}
1091
Colin Crossf506d872017-07-19 15:53:04 -07001092func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001093 if ctx.Arch().ArchType == android.Common {
1094 // Compile the jar
1095 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001096 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001097 // Handle the binary wrapper
1098 j.isWrapperVariant = true
1099
Colin Cross366938f2017-12-11 16:29:02 -08001100 if j.binaryProperties.Wrapper != nil {
1101 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001102 } else {
1103 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1104 }
1105
1106 // Depend on the installed jar so that the wrapper doesn't get executed by
1107 // another build rule before the jar has been installed.
1108 jarFile := ctx.PrimaryModule().(*Binary).installFile
1109
1110 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1111 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001112 }
Colin Cross2fe66872015-03-30 17:20:39 -07001113}
1114
Colin Crossf506d872017-07-19 15:53:04 -07001115func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001116 if ctx.Arch().ArchType == android.Common {
1117 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001118 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001119 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001120 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001121}
1122
Colin Crossf506d872017-07-19 15:53:04 -07001123func BinaryFactory() android.Module {
1124 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001125
Colin Cross36242852017-06-23 15:06:31 -07001126 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001127 &module.Module.properties,
1128 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001129 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001130 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001131
Colin Cross6b4a32d2017-12-05 13:42:45 -08001132 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1133 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001134 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001135}
1136
Colin Crossf506d872017-07-19 15:53:04 -07001137func BinaryHostFactory() android.Module {
1138 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001139
Colin Cross36242852017-06-23 15:06:31 -07001140 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001141 &module.Module.properties,
1142 &module.Module.deviceProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001143 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001144 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001145
Colin Cross6b4a32d2017-12-05 13:42:45 -08001146 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1147 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001148 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001149}
1150
1151//
1152// Java prebuilts
1153//
1154
Colin Cross74d73e22017-08-02 11:05:49 -07001155type ImportProperties struct {
1156 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001157
Nan Zhangea568a42017-11-08 21:20:04 -08001158 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001159
1160 Installable *bool
Colin Cross74d73e22017-08-02 11:05:49 -07001161}
1162
1163type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001164 android.ModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001165 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001166
Colin Cross74d73e22017-08-02 11:05:49 -07001167 properties ImportProperties
1168
Colin Cross0a6e0072017-08-30 14:24:55 -07001169 classpathFiles android.Paths
1170 combinedClasspathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -07001171}
1172
Colin Cross74d73e22017-08-02 11:05:49 -07001173func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001174 return &j.prebuilt
1175}
1176
Colin Cross74d73e22017-08-02 11:05:49 -07001177func (j *Import) PrebuiltSrcs() []string {
1178 return j.properties.Jars
1179}
1180
1181func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001182 return j.prebuilt.Name(j.ModuleBase.Name())
1183}
1184
Colin Cross74d73e22017-08-02 11:05:49 -07001185func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross1e676be2016-10-12 14:38:15 -07001186}
1187
Colin Cross74d73e22017-08-02 11:05:49 -07001188func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1189 j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07001190
Colin Crosse9a275b2017-10-16 17:09:48 -07001191 outputFile := android.PathForModuleOut(ctx, "classes.jar")
Nan Zhanged19fc32017-10-19 13:06:22 -07001192 TransformJarsToJar(ctx, outputFile, "for prebuilts", j.classpathFiles, android.OptionalPath{}, false, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001193 j.combinedClasspathFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -07001194}
1195
Colin Cross74d73e22017-08-02 11:05:49 -07001196var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001197
Nan Zhanged19fc32017-10-19 13:06:22 -07001198func (j *Import) HeaderJars() android.Paths {
1199 return j.classpathFiles
1200}
1201
1202func (j *Import) ImplementationJars() android.Paths {
Colin Cross74d73e22017-08-02 11:05:49 -07001203 return j.classpathFiles
Colin Cross2fe66872015-03-30 17:20:39 -07001204}
1205
Colin Cross74d73e22017-08-02 11:05:49 -07001206func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001207 return nil
1208}
1209
Colin Cross74d73e22017-08-02 11:05:49 -07001210var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001211
Colin Cross74d73e22017-08-02 11:05:49 -07001212func ImportFactory() android.Module {
1213 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001214
Colin Cross74d73e22017-08-02 11:05:49 -07001215 module.AddProperties(&module.properties)
1216
1217 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross36242852017-06-23 15:06:31 -07001218 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1219 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001220}
1221
Colin Cross74d73e22017-08-02 11:05:49 -07001222func ImportFactoryHost() android.Module {
1223 module := &Import{}
1224
1225 module.AddProperties(&module.properties)
1226
1227 android.InitPrebuiltModule(module, &module.properties.Jars)
1228 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
1229 return module
1230}
1231
Colin Cross2fe66872015-03-30 17:20:39 -07001232func inList(s string, l []string) bool {
1233 for _, e := range l {
1234 if e == s {
1235 return true
1236 }
1237 }
1238 return false
1239}
Colin Cross89536d42017-07-07 14:35:50 -07001240
1241//
1242// Defaults
1243//
1244type Defaults struct {
1245 android.ModuleBase
1246 android.DefaultsModuleBase
1247}
1248
1249func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1250}
1251
1252func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1253}
1254
1255func defaultsFactory() android.Module {
1256 return DefaultsFactory()
1257}
1258
1259func DefaultsFactory(props ...interface{}) android.Module {
1260 module := &Defaults{}
1261
1262 module.AddProperties(props...)
1263 module.AddProperties(
1264 &CompilerProperties{},
1265 &CompilerDeviceProperties{},
1266 )
1267
1268 android.InitDefaultsModule(module)
1269
1270 return module
1271}
Nan Zhangea568a42017-11-08 21:20:04 -08001272
1273var Bool = proptools.Bool
1274var String = proptools.String