blob: 01a05f0777274ce8a04c271efec7c06d02e0992b [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 Cross2fe66872015-03-30 17:20:39 -070023 "strings"
24
25 "github.com/google/blueprint"
Colin Cross2fe66872015-03-30 17:20:39 -070026
Colin Cross635c3b02016-05-18 15:37:25 -070027 "android/soong/android"
Colin Cross0607cf72015-04-28 13:28:51 -070028 "android/soong/genrule"
Colin Cross2fe66872015-03-30 17:20:39 -070029)
30
Colin Cross463a90e2015-06-17 14:20:06 -070031func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070032 android.RegisterModuleType("java_library", JavaLibraryFactory)
33 android.RegisterModuleType("java_library_static", JavaLibraryFactory)
34 android.RegisterModuleType("java_library_host", JavaLibraryHostFactory)
35 android.RegisterModuleType("java_binary", JavaBinaryFactory)
36 android.RegisterModuleType("java_binary_host", JavaBinaryHostFactory)
37 android.RegisterModuleType("prebuilt_java_library", JavaPrebuiltFactory)
38 android.RegisterModuleType("prebuilt_sdk", SdkPrebuiltFactory)
39 android.RegisterModuleType("android_app", AndroidAppFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070040
Colin Cross798bfce2016-10-12 14:28:16 -070041 android.RegisterSingletonType("logtags", LogtagsSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -070042}
43
Colin Cross2fe66872015-03-30 17:20:39 -070044// TODO:
45// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070046// Proto
47// Renderscript
48// Post-jar passes:
49// Proguard
Colin Crossba211132017-06-22 15:36:39 -070050// Jacoco
Colin Cross2fe66872015-03-30 17:20:39 -070051// Jarjar
52// Dex
53// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -070054// DroidDoc
55// Findbugs
56
Colin Cross46c9b8b2017-06-22 16:51:17 -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
67 Java_resource_dirs []string `android:"arch_variant"`
68
Dan Willemsen2ef08f42015-06-30 18:15:24 -070069 // list of directories that should be excluded from java_resource_dirs
70 Exclude_java_resource_dirs []string `android:"arch_variant"`
71
Paul Duffin2b67e3b2016-11-30 16:13:09 +000072 // don't build against the default libraries (legacy-test, core-junit,
Colin Cross7d5136f2015-05-11 13:39:40 -070073 // ext, and framework for device targets)
74 No_standard_libraries bool
75
76 // list of module-specific flags that will be used for javac compiles
77 Javacflags []string `android:"arch_variant"`
78
Colin Cross7d5136f2015-05-11 13:39:40 -070079 // list of of java libraries that will be in the classpath
80 Java_libs []string `android:"arch_variant"`
81
82 // list of java libraries that will be compiled into the resulting jar
83 Java_static_libs []string `android:"arch_variant"`
84
85 // manifest file to be included in resulting jar
Dan Willemsen34cc69e2015-09-23 15:26:20 -070086 Manifest *string
Colin Cross7d5136f2015-05-11 13:39:40 -070087
Colin Cross540eff82017-06-22 17:01:52 -070088 // if not blank, run jarjar using the specified rules file
89 Jarjar_rules *string
90}
91
92type compilerDeviceProperties struct {
93 // list of module-specific flags that will be used for dex compiles
94 Dxflags []string `android:"arch_variant"`
95
Colin Cross7d5136f2015-05-11 13:39:40 -070096 // if not blank, set to the version of the sdk to compile against
97 Sdk_version string
98
99 // Set for device java libraries, and for host versions of device java libraries
100 // built for testing
101 Dex bool `blueprint:"mutated"`
102
Colin Cross7d5136f2015-05-11 13:39:40 -0700103 // directories to pass to aidl tool
104 Aidl_includes []string
105
106 // directories that should be added as include directories
107 // for any aidl sources of modules that depend on this module
108 Export_aidl_include_dirs []string
109}
110
Colin Cross46c9b8b2017-06-22 16:51:17 -0700111// Module contains the properties and members used by all java module types
112type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700113 android.ModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700114
Colin Cross540eff82017-06-22 17:01:52 -0700115 properties compilerProperties
116 deviceProperties compilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700117
118 // output file suitable for inserting into the classpath of another compile
Colin Cross635c3b02016-05-18 15:37:25 -0700119 classpathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700120
Colin Crossb7a63242015-04-16 14:09:14 -0700121 // output file suitable for installing or running
Colin Cross635c3b02016-05-18 15:37:25 -0700122 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700123
Colin Cross2fe66872015-03-30 17:20:39 -0700124 // jarSpecs suitable for inserting classes from a static library into another jar
125 classJarSpecs []jarSpec
126
127 // jarSpecs suitable for inserting resources from a static library into another jar
128 resourceJarSpecs []jarSpec
129
Colin Cross635c3b02016-05-18 15:37:25 -0700130 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700131
Colin Cross635c3b02016-05-18 15:37:25 -0700132 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700133
Colin Crossb7a63242015-04-16 14:09:14 -0700134 // filelists of extra source files that should be included in the javac command line,
135 // for example R.java generated by aapt for android apps
Colin Cross635c3b02016-05-18 15:37:25 -0700136 ExtraSrcLists android.Paths
Colin Crossb7a63242015-04-16 14:09:14 -0700137
Colin Cross2fe66872015-03-30 17:20:39 -0700138 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700139 installFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700140}
141
Colin Cross2fe66872015-03-30 17:20:39 -0700142type JavaDependency interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700143 ClasspathFile() android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700144 ClassJarSpecs() []jarSpec
145 ResourceJarSpecs() []jarSpec
Colin Cross635c3b02016-05-18 15:37:25 -0700146 AidlIncludeDirs() android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700147}
148
Colin Cross46c9b8b2017-06-22 16:51:17 -0700149func (j *Module) BootClasspath(ctx android.BaseContext) string {
Colin Cross2fe66872015-03-30 17:20:39 -0700150 if ctx.Device() {
Colin Cross540eff82017-06-22 17:01:52 -0700151 switch j.deviceProperties.Sdk_version {
152 case "":
Colin Cross2fe66872015-03-30 17:20:39 -0700153 return "core-libart"
Colin Cross540eff82017-06-22 17:01:52 -0700154 case "current":
Colin Cross2fe66872015-03-30 17:20:39 -0700155 // TODO: !TARGET_BUILD_APPS
Colin Crossc0b06f12015-04-08 13:03:43 -0700156 // TODO: export preprocessed framework.aidl from android_stubs_current
Colin Cross2fe66872015-03-30 17:20:39 -0700157 return "android_stubs_current"
Colin Cross540eff82017-06-22 17:01:52 -0700158 case "system_current":
Colin Cross2fe66872015-03-30 17:20:39 -0700159 return "android_system_stubs_current"
Colin Cross540eff82017-06-22 17:01:52 -0700160 default:
161 return "sdk_v" + j.deviceProperties.Sdk_version
Colin Cross2fe66872015-03-30 17:20:39 -0700162 }
163 } else {
Colin Cross540eff82017-06-22 17:01:52 -0700164 if j.deviceProperties.Dex {
Colin Cross2fe66872015-03-30 17:20:39 -0700165 return "core-libart"
166 } else {
167 return ""
168 }
169 }
170}
171
Paul Duffin2b67e3b2016-11-30 16:13:09 +0000172var defaultJavaLibraries = []string{"core-libart", "legacy-test", "ext", "framework"}
Colin Crossefb9ebe2015-04-16 14:08:06 -0700173
Colin Cross46c9b8b2017-06-22 16:51:17 -0700174func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross2fe66872015-03-30 17:20:39 -0700175 var deps []string
176
177 if !j.properties.No_standard_libraries {
178 bootClasspath := j.BootClasspath(ctx)
179 if bootClasspath != "" {
180 deps = append(deps, bootClasspath)
181 }
Colin Cross540eff82017-06-22 17:01:52 -0700182 if ctx.Device() && j.deviceProperties.Sdk_version == "" {
Colin Crossefb9ebe2015-04-16 14:08:06 -0700183 deps = append(deps, defaultJavaLibraries...)
184 }
Colin Cross2fe66872015-03-30 17:20:39 -0700185 }
186 deps = append(deps, j.properties.Java_libs...)
187 deps = append(deps, j.properties.Java_static_libs...)
188
Colin Cross46c9b8b2017-06-22 16:51:17 -0700189 ctx.AddDependency(ctx.Module(), nil, deps...)
Colin Cross2fe66872015-03-30 17:20:39 -0700190}
191
Colin Cross46c9b8b2017-06-22 16:51:17 -0700192func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700193 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700194
Colin Cross540eff82017-06-22 17:01:52 -0700195 localAidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl_includes)
Colin Crossc0b06f12015-04-08 13:03:43 -0700196
197 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700198 if aidlPreprocess.Valid() {
199 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700200 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700201 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700202 }
203
Colin Cross635c3b02016-05-18 15:37:25 -0700204 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
205 flags = append(flags, android.JoinWithPrefix(localAidlIncludes.Strings(), "-I"))
206 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
207 flags = append(flags, "-I"+android.PathForModuleSrc(ctx, "src").String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700208
Colin Crossf03c82b2015-04-13 13:53:40 -0700209 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700210}
211
Colin Cross46c9b8b2017-06-22 16:51:17 -0700212func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths,
Colin Cross635c3b02016-05-18 15:37:25 -0700213 bootClasspath android.OptionalPath, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess android.OptionalPath,
214 aidlIncludeDirs android.Paths, srcFileLists android.Paths) {
Colin Cross2fe66872015-03-30 17:20:39 -0700215
216 ctx.VisitDirectDeps(func(module blueprint.Module) {
217 otherName := ctx.OtherModuleName(module)
218 if javaDep, ok := module.(JavaDependency); ok {
Colin Cross6cbb1272015-04-08 11:23:01 -0700219 if otherName == j.BootClasspath(ctx) {
Colin Cross635c3b02016-05-18 15:37:25 -0700220 bootClasspath = android.OptionalPathForPath(javaDep.ClasspathFile())
Colin Crossb7a63242015-04-16 14:09:14 -0700221 } else if inList(otherName, defaultJavaLibraries) {
222 classpath = append(classpath, javaDep.ClasspathFile())
Colin Cross6cbb1272015-04-08 11:23:01 -0700223 } else if inList(otherName, j.properties.Java_libs) {
Colin Cross2fe66872015-03-30 17:20:39 -0700224 classpath = append(classpath, javaDep.ClasspathFile())
225 } else if inList(otherName, j.properties.Java_static_libs) {
226 classpath = append(classpath, javaDep.ClasspathFile())
227 classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...)
228 resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...)
Colin Crossb7a63242015-04-16 14:09:14 -0700229 } else if otherName == "framework-res" {
230 if ctx.ModuleName() == "framework" {
231 // framework.jar has a one-off dependency on the R.java and Manifest.java files
232 // generated by framework-res.apk
Colin Cross46c9b8b2017-06-22 16:51:17 -0700233 srcFileLists = append(srcFileLists, module.(*AndroidApp).aaptJavaFileList)
Colin Crossb7a63242015-04-16 14:09:14 -0700234 }
Colin Cross2fe66872015-03-30 17:20:39 -0700235 } else {
236 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
237 }
Colin Crossaa8630b2015-04-13 13:52:22 -0700238 aidlIncludeDirs = append(aidlIncludeDirs, javaDep.AidlIncludeDirs()...)
239 if sdkDep, ok := module.(sdkDependency); ok {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700240 if sdkDep.AidlPreprocessed().Valid() {
241 if aidlPreprocess.Valid() {
Colin Crossaa8630b2015-04-13 13:52:22 -0700242 ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q",
243 aidlPreprocess, sdkDep.AidlPreprocessed())
244 } else {
245 aidlPreprocess = sdkDep.AidlPreprocessed()
246 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700247 }
248 }
Colin Cross2fe66872015-03-30 17:20:39 -0700249 }
250 })
251
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700252 return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
253 aidlIncludeDirs, srcFileLists
Colin Cross2fe66872015-03-30 17:20:39 -0700254}
255
Colin Cross46c9b8b2017-06-22 16:51:17 -0700256func (j *Module) compile(ctx android.ModuleContext) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700257
Colin Cross540eff82017-06-22 17:01:52 -0700258 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Export_aidl_include_dirs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700259
260 classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700261 aidlIncludeDirs, srcFileLists := j.collectDeps(ctx)
Colin Crossc0b06f12015-04-08 13:03:43 -0700262
Colin Crossf03c82b2015-04-13 13:53:40 -0700263 var flags javaBuilderFlags
264
265 javacFlags := j.properties.Javacflags
266 if len(javacFlags) > 0 {
267 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
268 flags.javacFlags = "$javacFlags"
269 }
270
271 aidlFlags := j.aidlFlags(ctx, aidlPreprocess, aidlIncludeDirs)
272 if len(aidlFlags) > 0 {
273 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
274 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700275 }
276
Colin Cross635c3b02016-05-18 15:37:25 -0700277 var javacDeps android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700278
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700279 if bootClasspath.Valid() {
280 flags.bootClasspath = "-bootclasspath " + bootClasspath.String()
281 javacDeps = append(javacDeps, bootClasspath.Path())
Colin Cross2fe66872015-03-30 17:20:39 -0700282 }
283
284 if len(classpath) > 0 {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700285 flags.classpath = "-classpath " + strings.Join(classpath.Strings(), ":")
Colin Cross2fe66872015-03-30 17:20:39 -0700286 javacDeps = append(javacDeps, classpath...)
287 }
288
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700289 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700290
Colin Crossf05fe972015-04-10 17:45:20 -0700291 srcFiles = j.genSources(ctx, srcFiles, flags)
Colin Crossc0b06f12015-04-08 13:03:43 -0700292
Colin Cross0607cf72015-04-28 13:28:51 -0700293 ctx.VisitDirectDeps(func(module blueprint.Module) {
294 if gen, ok := module.(genrule.SourceFileGenerator); ok {
295 srcFiles = append(srcFiles, gen.GeneratedSourceFiles()...)
296 }
297 })
298
Colin Crossb7a63242015-04-16 14:09:14 -0700299 srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
300
Colin Cross8cf13342015-04-10 15:41:49 -0700301 if len(srcFiles) > 0 {
302 // Compile java sources into .class files
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700303 classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, javacDeps)
Colin Cross8cf13342015-04-10 15:41:49 -0700304 if ctx.Failed() {
305 return
306 }
307
308 classJarSpecs = append([]jarSpec{classes}, classJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700309 }
310
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700311 resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs),
Colin Cross276284f2015-04-20 13:51:48 -0700312 resourceJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700313
Colin Cross635c3b02016-05-18 15:37:25 -0700314 manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
Colin Cross2fe66872015-03-30 17:20:39 -0700315
316 allJarSpecs := append([]jarSpec(nil), classJarSpecs...)
317 allJarSpecs = append(allJarSpecs, resourceJarSpecs...)
318
319 // Combine classes + resources into classes-full-debug.jar
320 outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest)
321 if ctx.Failed() {
322 return
323 }
Colin Cross65bf4f22015-04-03 16:54:17 -0700324
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700325 if j.properties.Jarjar_rules != nil {
Colin Cross635c3b02016-05-18 15:37:25 -0700326 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross65bf4f22015-04-03 16:54:17 -0700327 // Transform classes-full-debug.jar into classes-jarjar.jar
328 outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
329 if ctx.Failed() {
330 return
331 }
Colin Cross20978302015-04-10 17:05:07 -0700332
333 classes, _ := TransformPrebuiltJarToClasses(ctx, outputFile)
334 classJarSpecs = []jarSpec{classes}
Colin Cross65bf4f22015-04-03 16:54:17 -0700335 }
336
Colin Cross20978302015-04-10 17:05:07 -0700337 j.resourceJarSpecs = resourceJarSpecs
338 j.classJarSpecs = classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700339 j.classpathFile = outputFile
340
Colin Cross540eff82017-06-22 17:01:52 -0700341 if j.deviceProperties.Dex && len(srcFiles) > 0 {
342 dxFlags := j.deviceProperties.Dxflags
Colin Cross2fe66872015-03-30 17:20:39 -0700343 if false /* emma enabled */ {
344 // If you instrument class files that have local variable debug information in
345 // them emma does not correctly maintain the local variable table.
346 // This will cause an error when you try to convert the class files for Android.
347 // The workaround here is to build different dex file here based on emma switch
348 // then later copy into classes.dex. When emma is on, dx is run with --no-locals
349 // option to remove local variable information
350 dxFlags = append(dxFlags, "--no-locals")
351 }
352
Colin Cross1332b002015-04-07 17:11:30 -0700353 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700354 dxFlags = append(dxFlags, "--no-optimize")
355 }
356
Colin Cross1332b002015-04-07 17:11:30 -0700357 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700358 dxFlags = append(dxFlags,
359 "--debug",
360 "--verbose",
Colin Cross635c3b02016-05-18 15:37:25 -0700361 "--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(),
Colin Cross2fe66872015-03-30 17:20:39 -0700362 "--dump-width=1000")
363 }
364
365 flags.dxFlags = strings.Join(dxFlags, " ")
366
367 // Compile classes.jar into classes.dex
Colin Cross6d1e72d2015-04-10 17:44:24 -0700368 dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags)
Colin Cross2fe66872015-03-30 17:20:39 -0700369 if ctx.Failed() {
370 return
371 }
372
373 // Combine classes.dex + resources into javalib.jar
Colin Cross6d1e72d2015-04-10 17:44:24 -0700374 outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec)
Colin Cross2fe66872015-03-30 17:20:39 -0700375 }
Colin Crossb7a63242015-04-16 14:09:14 -0700376 ctx.CheckbuildFile(outputFile)
377 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700378}
379
380var _ JavaDependency = (*JavaLibrary)(nil)
381
Colin Cross46c9b8b2017-06-22 16:51:17 -0700382func (j *Module) ClasspathFile() android.Path {
Colin Cross2fe66872015-03-30 17:20:39 -0700383 return j.classpathFile
384}
385
Colin Cross46c9b8b2017-06-22 16:51:17 -0700386func (j *Module) ClassJarSpecs() []jarSpec {
Colin Cross2fe66872015-03-30 17:20:39 -0700387 return j.classJarSpecs
388}
389
Colin Cross46c9b8b2017-06-22 16:51:17 -0700390func (j *Module) ResourceJarSpecs() []jarSpec {
Colin Cross2fe66872015-03-30 17:20:39 -0700391 return j.resourceJarSpecs
392}
393
Colin Cross46c9b8b2017-06-22 16:51:17 -0700394func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700395 return j.exportAidlIncludeDirs
396}
397
Colin Cross46c9b8b2017-06-22 16:51:17 -0700398var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -0700399
Colin Cross46c9b8b2017-06-22 16:51:17 -0700400func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -0700401 return j.logtagsSrcs
402}
403
Colin Cross2fe66872015-03-30 17:20:39 -0700404//
405// Java libraries (.jar file)
406//
407
408type JavaLibrary struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700409 Module
Colin Cross2fe66872015-03-30 17:20:39 -0700410}
411
Colin Cross46c9b8b2017-06-22 16:51:17 -0700412func (j *JavaLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
413 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -0700414
Colin Cross635c3b02016-05-18 15:37:25 -0700415 j.installFile = ctx.InstallFileName(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.outputFile)
Colin Crossb7a63242015-04-16 14:09:14 -0700416}
417
Colin Cross46c9b8b2017-06-22 16:51:17 -0700418func (j *JavaLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
419 j.deps(ctx)
420}
421
Colin Cross2fe66872015-03-30 17:20:39 -0700422func JavaLibraryFactory() (blueprint.Module, []interface{}) {
423 module := &JavaLibrary{}
424
Colin Cross540eff82017-06-22 17:01:52 -0700425 module.deviceProperties.Dex = true
Colin Cross2fe66872015-03-30 17:20:39 -0700426
Colin Cross540eff82017-06-22 17:01:52 -0700427 return android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon,
428 &module.Module.properties,
429 &module.Module.deviceProperties)
Colin Cross2fe66872015-03-30 17:20:39 -0700430}
431
432func JavaLibraryHostFactory() (blueprint.Module, []interface{}) {
433 module := &JavaLibrary{}
434
Colin Cross540eff82017-06-22 17:01:52 -0700435 return android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon,
436 &module.Module.properties)
Colin Cross2fe66872015-03-30 17:20:39 -0700437}
438
439//
440// Java Binaries (.jar file plus wrapper script)
441//
442
Colin Cross7d5136f2015-05-11 13:39:40 -0700443type javaBinaryProperties struct {
444 // installable script to execute the resulting jar
445 Wrapper string
446}
447
Colin Cross2fe66872015-03-30 17:20:39 -0700448type JavaBinary struct {
449 JavaLibrary
450
Colin Cross7d5136f2015-05-11 13:39:40 -0700451 binaryProperties javaBinaryProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700452}
453
Colin Cross46c9b8b2017-06-22 16:51:17 -0700454func (j *JavaBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
455 j.JavaLibrary.GenerateAndroidBuildActions(ctx)
Colin Cross2fe66872015-03-30 17:20:39 -0700456
457 // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
458 // another build rule before the jar has been installed.
Colin Cross635c3b02016-05-18 15:37:25 -0700459 ctx.InstallFile(android.PathForModuleInstall(ctx, "bin"), android.PathForModuleSrc(ctx, j.binaryProperties.Wrapper),
Colin Cross2fe66872015-03-30 17:20:39 -0700460 j.installFile)
461}
462
Colin Cross46c9b8b2017-06-22 16:51:17 -0700463func (j *JavaBinary) DepsMutator(ctx android.BottomUpMutatorContext) {
464 j.deps(ctx)
465}
466
Colin Cross2fe66872015-03-30 17:20:39 -0700467func JavaBinaryFactory() (blueprint.Module, []interface{}) {
468 module := &JavaBinary{}
469
Colin Cross540eff82017-06-22 17:01:52 -0700470 module.deviceProperties.Dex = true
Colin Cross2fe66872015-03-30 17:20:39 -0700471
Colin Cross540eff82017-06-22 17:01:52 -0700472 return android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon,
473 &module.Module.properties,
474 &module.Module.deviceProperties,
475 &module.binaryProperties)
Colin Cross2fe66872015-03-30 17:20:39 -0700476}
477
478func JavaBinaryHostFactory() (blueprint.Module, []interface{}) {
479 module := &JavaBinary{}
480
Colin Cross540eff82017-06-22 17:01:52 -0700481 return android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon,
482 &module.Module.properties,
483 &module.Module.deviceProperties,
484 &module.binaryProperties)
Colin Cross2fe66872015-03-30 17:20:39 -0700485}
486
487//
488// Java prebuilts
489//
490
Colin Cross7d5136f2015-05-11 13:39:40 -0700491type javaPrebuiltProperties struct {
492 Srcs []string
493}
494
Colin Cross2fe66872015-03-30 17:20:39 -0700495type JavaPrebuilt struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700496 android.ModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700497
Colin Cross7d5136f2015-05-11 13:39:40 -0700498 properties javaPrebuiltProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700499
Colin Cross635c3b02016-05-18 15:37:25 -0700500 classpathFile android.Path
Colin Crosse1d62a82015-04-03 16:53:05 -0700501 classJarSpecs, resourceJarSpecs []jarSpec
Colin Cross2fe66872015-03-30 17:20:39 -0700502}
503
Colin Cross1e676be2016-10-12 14:38:15 -0700504func (j *JavaPrebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
505}
506
Colin Cross635c3b02016-05-18 15:37:25 -0700507func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross2fe66872015-03-30 17:20:39 -0700508 if len(j.properties.Srcs) != 1 {
509 ctx.ModuleErrorf("expected exactly one jar in srcs")
510 return
511 }
Colin Cross635c3b02016-05-18 15:37:25 -0700512 prebuilt := android.PathForModuleSrc(ctx, j.properties.Srcs[0])
Colin Crosse1d62a82015-04-03 16:53:05 -0700513
514 classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt)
515
516 j.classpathFile = prebuilt
517 j.classJarSpecs = []jarSpec{classJarSpec}
518 j.resourceJarSpecs = []jarSpec{resourceJarSpec}
Colin Cross635c3b02016-05-18 15:37:25 -0700519 ctx.InstallFileName(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.classpathFile)
Colin Cross2fe66872015-03-30 17:20:39 -0700520}
521
522var _ JavaDependency = (*JavaPrebuilt)(nil)
523
Colin Cross635c3b02016-05-18 15:37:25 -0700524func (j *JavaPrebuilt) ClasspathFile() android.Path {
Colin Cross2fe66872015-03-30 17:20:39 -0700525 return j.classpathFile
526}
527
528func (j *JavaPrebuilt) ClassJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700529 return j.classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700530}
531
532func (j *JavaPrebuilt) ResourceJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700533 return j.resourceJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700534}
535
Colin Cross635c3b02016-05-18 15:37:25 -0700536func (j *JavaPrebuilt) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700537 return nil
538}
539
Colin Cross2fe66872015-03-30 17:20:39 -0700540func JavaPrebuiltFactory() (blueprint.Module, []interface{}) {
541 module := &JavaPrebuilt{}
542
Colin Cross635c3b02016-05-18 15:37:25 -0700543 return android.InitAndroidArchModule(module, android.HostAndDeviceSupported,
544 android.MultilibCommon, &module.properties)
Colin Cross2fe66872015-03-30 17:20:39 -0700545}
546
Colin Crossaa8630b2015-04-13 13:52:22 -0700547//
548// SDK java prebuilts (.jar containing resources plus framework.aidl)
549//
550
551type sdkDependency interface {
552 JavaDependency
Colin Cross635c3b02016-05-18 15:37:25 -0700553 AidlPreprocessed() android.OptionalPath
Colin Crossaa8630b2015-04-13 13:52:22 -0700554}
555
556var _ sdkDependency = (*sdkPrebuilt)(nil)
557
Colin Cross7d5136f2015-05-11 13:39:40 -0700558type sdkPrebuiltProperties struct {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700559 Aidl_preprocessed *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700560}
561
Colin Crossaa8630b2015-04-13 13:52:22 -0700562type sdkPrebuilt struct {
563 JavaPrebuilt
564
Colin Cross7d5136f2015-05-11 13:39:40 -0700565 sdkProperties sdkPrebuiltProperties
Colin Crossaa8630b2015-04-13 13:52:22 -0700566
Colin Cross635c3b02016-05-18 15:37:25 -0700567 aidlPreprocessed android.OptionalPath
Colin Crossaa8630b2015-04-13 13:52:22 -0700568}
569
Colin Cross635c3b02016-05-18 15:37:25 -0700570func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crossaa8630b2015-04-13 13:52:22 -0700571 j.JavaPrebuilt.GenerateAndroidBuildActions(ctx)
572
Colin Cross635c3b02016-05-18 15:37:25 -0700573 j.aidlPreprocessed = android.OptionalPathForModuleSrc(ctx, j.sdkProperties.Aidl_preprocessed)
Colin Crossaa8630b2015-04-13 13:52:22 -0700574}
575
Colin Cross635c3b02016-05-18 15:37:25 -0700576func (j *sdkPrebuilt) AidlPreprocessed() android.OptionalPath {
Colin Crossaa8630b2015-04-13 13:52:22 -0700577 return j.aidlPreprocessed
578}
579
580func SdkPrebuiltFactory() (blueprint.Module, []interface{}) {
581 module := &sdkPrebuilt{}
582
Colin Cross635c3b02016-05-18 15:37:25 -0700583 return android.InitAndroidArchModule(module, android.HostAndDeviceSupported,
584 android.MultilibCommon, &module.properties, &module.sdkProperties)
Colin Crossaa8630b2015-04-13 13:52:22 -0700585}
586
Colin Cross2fe66872015-03-30 17:20:39 -0700587func inList(s string, l []string) bool {
588 for _, e := range l {
589 if e == s {
590 return true
591 }
592 }
593 return false
594}