blob: 20661c47997c571e6b5b37191befa6ac3788b657 [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 Cross3e3e72d2017-06-22 17:20:19 -070029 "android/soong/java/config"
Colin Cross2fe66872015-03-30 17:20:39 -070030)
31
Colin Cross463a90e2015-06-17 14:20:06 -070032func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070033 android.RegisterModuleType("java_library", JavaLibraryFactory)
34 android.RegisterModuleType("java_library_static", JavaLibraryFactory)
35 android.RegisterModuleType("java_library_host", JavaLibraryHostFactory)
36 android.RegisterModuleType("java_binary", JavaBinaryFactory)
37 android.RegisterModuleType("java_binary_host", JavaBinaryHostFactory)
38 android.RegisterModuleType("prebuilt_java_library", JavaPrebuiltFactory)
39 android.RegisterModuleType("prebuilt_sdk", SdkPrebuiltFactory)
40 android.RegisterModuleType("android_app", AndroidAppFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070041
Colin Cross798bfce2016-10-12 14:28:16 -070042 android.RegisterSingletonType("logtags", LogtagsSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -070043}
44
Colin Cross2fe66872015-03-30 17:20:39 -070045// TODO:
46// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070047// Proto
48// Renderscript
49// Post-jar passes:
50// Proguard
Colin Crossba211132017-06-22 15:36:39 -070051// Jacoco
Colin Cross2fe66872015-03-30 17:20:39 -070052// Jarjar
53// Dex
54// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -070055// DroidDoc
56// Findbugs
57
Colin Cross46c9b8b2017-06-22 16:51:17 -070058type compilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -070059 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
60 // or .aidl files.
Dan Willemsen2ef08f42015-06-30 18:15:24 -070061 Srcs []string `android:"arch_variant"`
62
63 // list of source files that should not be used to build the Java module.
64 // This is most useful in the arch/multilib variants to remove non-common files
65 Exclude_srcs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070066
67 // list of directories containing Java resources
68 Java_resource_dirs []string `android:"arch_variant"`
69
Dan Willemsen2ef08f42015-06-30 18:15:24 -070070 // list of directories that should be excluded from java_resource_dirs
71 Exclude_java_resource_dirs []string `android:"arch_variant"`
72
Paul Duffin2b67e3b2016-11-30 16:13:09 +000073 // don't build against the default libraries (legacy-test, core-junit,
Colin Cross7d5136f2015-05-11 13:39:40 -070074 // ext, and framework for device targets)
75 No_standard_libraries bool
76
77 // list of module-specific flags that will be used for javac compiles
78 Javacflags []string `android:"arch_variant"`
79
Colin Cross7d5136f2015-05-11 13:39:40 -070080 // list of of java libraries that will be in the classpath
81 Java_libs []string `android:"arch_variant"`
82
83 // list of java libraries that will be compiled into the resulting jar
84 Java_static_libs []string `android:"arch_variant"`
85
86 // manifest file to be included in resulting jar
Dan Willemsen34cc69e2015-09-23 15:26:20 -070087 Manifest *string
Colin Cross7d5136f2015-05-11 13:39:40 -070088
Colin Cross540eff82017-06-22 17:01:52 -070089 // if not blank, run jarjar using the specified rules file
90 Jarjar_rules *string
91}
92
93type compilerDeviceProperties struct {
94 // list of module-specific flags that will be used for dex compiles
95 Dxflags []string `android:"arch_variant"`
96
Colin Cross7d5136f2015-05-11 13:39:40 -070097 // if not blank, set to the version of the sdk to compile against
98 Sdk_version string
99
100 // Set for device java libraries, and for host versions of device java libraries
101 // built for testing
102 Dex bool `blueprint:"mutated"`
103
Colin Cross7d5136f2015-05-11 13:39:40 -0700104 // directories to pass to aidl tool
105 Aidl_includes []string
106
107 // directories that should be added as include directories
108 // for any aidl sources of modules that depend on this module
109 Export_aidl_include_dirs []string
110}
111
Colin Cross46c9b8b2017-06-22 16:51:17 -0700112// Module contains the properties and members used by all java module types
113type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700114 android.ModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700115
Colin Cross540eff82017-06-22 17:01:52 -0700116 properties compilerProperties
117 deviceProperties compilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700118
119 // output file suitable for inserting into the classpath of another compile
Colin Cross635c3b02016-05-18 15:37:25 -0700120 classpathFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700121
Colin Crossb7a63242015-04-16 14:09:14 -0700122 // output file suitable for installing or running
Colin Cross635c3b02016-05-18 15:37:25 -0700123 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700124
Colin Cross2fe66872015-03-30 17:20:39 -0700125 // jarSpecs suitable for inserting classes from a static library into another jar
126 classJarSpecs []jarSpec
127
128 // jarSpecs suitable for inserting resources from a static library into another jar
129 resourceJarSpecs []jarSpec
130
Colin Cross635c3b02016-05-18 15:37:25 -0700131 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700132
Colin Cross635c3b02016-05-18 15:37:25 -0700133 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700134
Colin Crossb7a63242015-04-16 14:09:14 -0700135 // filelists of extra source files that should be included in the javac command line,
136 // for example R.java generated by aapt for android apps
Colin Cross635c3b02016-05-18 15:37:25 -0700137 ExtraSrcLists android.Paths
Colin Crossb7a63242015-04-16 14:09:14 -0700138
Colin Cross2fe66872015-03-30 17:20:39 -0700139 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700140 installFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700141}
142
Colin Cross2fe66872015-03-30 17:20:39 -0700143type JavaDependency interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700144 ClasspathFile() android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700145 ClassJarSpecs() []jarSpec
146 ResourceJarSpecs() []jarSpec
Colin Cross635c3b02016-05-18 15:37:25 -0700147 AidlIncludeDirs() android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700148}
149
Colin Cross46c9b8b2017-06-22 16:51:17 -0700150func (j *Module) BootClasspath(ctx android.BaseContext) string {
Colin Cross2fe66872015-03-30 17:20:39 -0700151 if ctx.Device() {
Colin Cross540eff82017-06-22 17:01:52 -0700152 switch j.deviceProperties.Sdk_version {
153 case "":
Colin Cross2fe66872015-03-30 17:20:39 -0700154 return "core-libart"
Colin Cross540eff82017-06-22 17:01:52 -0700155 case "current":
Colin Cross2fe66872015-03-30 17:20:39 -0700156 // TODO: !TARGET_BUILD_APPS
Colin Crossc0b06f12015-04-08 13:03:43 -0700157 // TODO: export preprocessed framework.aidl from android_stubs_current
Colin Cross2fe66872015-03-30 17:20:39 -0700158 return "android_stubs_current"
Colin Cross540eff82017-06-22 17:01:52 -0700159 case "system_current":
Colin Cross2fe66872015-03-30 17:20:39 -0700160 return "android_system_stubs_current"
Colin Cross540eff82017-06-22 17:01:52 -0700161 default:
162 return "sdk_v" + j.deviceProperties.Sdk_version
Colin Cross2fe66872015-03-30 17:20:39 -0700163 }
164 } else {
Colin Cross540eff82017-06-22 17:01:52 -0700165 if j.deviceProperties.Dex {
Colin Cross2fe66872015-03-30 17:20:39 -0700166 return "core-libart"
167 } else {
168 return ""
169 }
170 }
171}
172
Colin Cross46c9b8b2017-06-22 16:51:17 -0700173func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross2fe66872015-03-30 17:20:39 -0700174 var deps []string
175
176 if !j.properties.No_standard_libraries {
177 bootClasspath := j.BootClasspath(ctx)
178 if bootClasspath != "" {
179 deps = append(deps, bootClasspath)
180 }
Colin Cross540eff82017-06-22 17:01:52 -0700181 if ctx.Device() && j.deviceProperties.Sdk_version == "" {
Colin Cross3e3e72d2017-06-22 17:20:19 -0700182 deps = append(deps, config.DefaultLibraries...)
Colin Crossefb9ebe2015-04-16 14:08:06 -0700183 }
Colin Cross2fe66872015-03-30 17:20:39 -0700184 }
185 deps = append(deps, j.properties.Java_libs...)
186 deps = append(deps, j.properties.Java_static_libs...)
187
Colin Cross46c9b8b2017-06-22 16:51:17 -0700188 ctx.AddDependency(ctx.Module(), nil, deps...)
Colin Cross2fe66872015-03-30 17:20:39 -0700189}
190
Colin Cross46c9b8b2017-06-22 16:51:17 -0700191func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700192 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700193
Colin Cross540eff82017-06-22 17:01:52 -0700194 localAidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl_includes)
Colin Crossc0b06f12015-04-08 13:03:43 -0700195
196 var flags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700197 if aidlPreprocess.Valid() {
198 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700199 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700200 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700201 }
202
Colin Cross635c3b02016-05-18 15:37:25 -0700203 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
204 flags = append(flags, android.JoinWithPrefix(localAidlIncludes.Strings(), "-I"))
205 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
206 flags = append(flags, "-I"+android.PathForModuleSrc(ctx, "src").String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700207
Colin Crossf03c82b2015-04-13 13:53:40 -0700208 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700209}
210
Colin Cross46c9b8b2017-06-22 16:51:17 -0700211func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths,
Colin Cross635c3b02016-05-18 15:37:25 -0700212 bootClasspath android.OptionalPath, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess android.OptionalPath,
213 aidlIncludeDirs android.Paths, srcFileLists android.Paths) {
Colin Cross2fe66872015-03-30 17:20:39 -0700214
215 ctx.VisitDirectDeps(func(module blueprint.Module) {
216 otherName := ctx.OtherModuleName(module)
217 if javaDep, ok := module.(JavaDependency); ok {
Colin Cross6cbb1272015-04-08 11:23:01 -0700218 if otherName == j.BootClasspath(ctx) {
Colin Cross635c3b02016-05-18 15:37:25 -0700219 bootClasspath = android.OptionalPathForPath(javaDep.ClasspathFile())
Colin Cross3e3e72d2017-06-22 17:20:19 -0700220 } else if inList(otherName, config.DefaultLibraries) {
Colin Crossb7a63242015-04-16 14:09:14 -0700221 classpath = append(classpath, javaDep.ClasspathFile())
Colin Cross6cbb1272015-04-08 11:23:01 -0700222 } else if inList(otherName, j.properties.Java_libs) {
Colin Cross2fe66872015-03-30 17:20:39 -0700223 classpath = append(classpath, javaDep.ClasspathFile())
224 } else if inList(otherName, j.properties.Java_static_libs) {
225 classpath = append(classpath, javaDep.ClasspathFile())
226 classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...)
227 resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...)
Colin Crossb7a63242015-04-16 14:09:14 -0700228 } else if otherName == "framework-res" {
229 if ctx.ModuleName() == "framework" {
230 // framework.jar has a one-off dependency on the R.java and Manifest.java files
231 // generated by framework-res.apk
Colin Cross46c9b8b2017-06-22 16:51:17 -0700232 srcFileLists = append(srcFileLists, module.(*AndroidApp).aaptJavaFileList)
Colin Crossb7a63242015-04-16 14:09:14 -0700233 }
Colin Cross2fe66872015-03-30 17:20:39 -0700234 } else {
235 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
236 }
Colin Crossaa8630b2015-04-13 13:52:22 -0700237 aidlIncludeDirs = append(aidlIncludeDirs, javaDep.AidlIncludeDirs()...)
238 if sdkDep, ok := module.(sdkDependency); ok {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700239 if sdkDep.AidlPreprocessed().Valid() {
240 if aidlPreprocess.Valid() {
Colin Crossaa8630b2015-04-13 13:52:22 -0700241 ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q",
242 aidlPreprocess, sdkDep.AidlPreprocessed())
243 } else {
244 aidlPreprocess = sdkDep.AidlPreprocessed()
245 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700246 }
247 }
Colin Cross2fe66872015-03-30 17:20:39 -0700248 }
249 })
250
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700251 return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
252 aidlIncludeDirs, srcFileLists
Colin Cross2fe66872015-03-30 17:20:39 -0700253}
254
Colin Cross46c9b8b2017-06-22 16:51:17 -0700255func (j *Module) compile(ctx android.ModuleContext) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700256
Colin Cross540eff82017-06-22 17:01:52 -0700257 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Export_aidl_include_dirs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700258
259 classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700260 aidlIncludeDirs, srcFileLists := j.collectDeps(ctx)
Colin Crossc0b06f12015-04-08 13:03:43 -0700261
Colin Crossf03c82b2015-04-13 13:53:40 -0700262 var flags javaBuilderFlags
263
264 javacFlags := j.properties.Javacflags
265 if len(javacFlags) > 0 {
266 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
267 flags.javacFlags = "$javacFlags"
268 }
269
270 aidlFlags := j.aidlFlags(ctx, aidlPreprocess, aidlIncludeDirs)
271 if len(aidlFlags) > 0 {
272 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
273 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700274 }
275
Colin Cross635c3b02016-05-18 15:37:25 -0700276 var javacDeps android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700277
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700278 if bootClasspath.Valid() {
279 flags.bootClasspath = "-bootclasspath " + bootClasspath.String()
280 javacDeps = append(javacDeps, bootClasspath.Path())
Colin Cross2fe66872015-03-30 17:20:39 -0700281 }
282
283 if len(classpath) > 0 {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700284 flags.classpath = "-classpath " + strings.Join(classpath.Strings(), ":")
Colin Cross2fe66872015-03-30 17:20:39 -0700285 javacDeps = append(javacDeps, classpath...)
286 }
287
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700288 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700289
Colin Crossf05fe972015-04-10 17:45:20 -0700290 srcFiles = j.genSources(ctx, srcFiles, flags)
Colin Crossc0b06f12015-04-08 13:03:43 -0700291
Colin Cross0607cf72015-04-28 13:28:51 -0700292 ctx.VisitDirectDeps(func(module blueprint.Module) {
293 if gen, ok := module.(genrule.SourceFileGenerator); ok {
294 srcFiles = append(srcFiles, gen.GeneratedSourceFiles()...)
295 }
296 })
297
Colin Crossb7a63242015-04-16 14:09:14 -0700298 srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
299
Colin Cross8cf13342015-04-10 15:41:49 -0700300 if len(srcFiles) > 0 {
301 // Compile java sources into .class files
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700302 classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, javacDeps)
Colin Cross8cf13342015-04-10 15:41:49 -0700303 if ctx.Failed() {
304 return
305 }
306
307 classJarSpecs = append([]jarSpec{classes}, classJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700308 }
309
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700310 resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs),
Colin Cross276284f2015-04-20 13:51:48 -0700311 resourceJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700312
Colin Cross635c3b02016-05-18 15:37:25 -0700313 manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
Colin Cross2fe66872015-03-30 17:20:39 -0700314
315 allJarSpecs := append([]jarSpec(nil), classJarSpecs...)
316 allJarSpecs = append(allJarSpecs, resourceJarSpecs...)
317
318 // Combine classes + resources into classes-full-debug.jar
319 outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest)
320 if ctx.Failed() {
321 return
322 }
Colin Cross65bf4f22015-04-03 16:54:17 -0700323
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700324 if j.properties.Jarjar_rules != nil {
Colin Cross635c3b02016-05-18 15:37:25 -0700325 jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Colin Cross65bf4f22015-04-03 16:54:17 -0700326 // Transform classes-full-debug.jar into classes-jarjar.jar
327 outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
328 if ctx.Failed() {
329 return
330 }
Colin Cross20978302015-04-10 17:05:07 -0700331
332 classes, _ := TransformPrebuiltJarToClasses(ctx, outputFile)
333 classJarSpecs = []jarSpec{classes}
Colin Cross65bf4f22015-04-03 16:54:17 -0700334 }
335
Colin Cross20978302015-04-10 17:05:07 -0700336 j.resourceJarSpecs = resourceJarSpecs
337 j.classJarSpecs = classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700338 j.classpathFile = outputFile
339
Colin Cross540eff82017-06-22 17:01:52 -0700340 if j.deviceProperties.Dex && len(srcFiles) > 0 {
341 dxFlags := j.deviceProperties.Dxflags
Colin Cross2fe66872015-03-30 17:20:39 -0700342 if false /* emma enabled */ {
343 // If you instrument class files that have local variable debug information in
344 // them emma does not correctly maintain the local variable table.
345 // This will cause an error when you try to convert the class files for Android.
346 // The workaround here is to build different dex file here based on emma switch
347 // then later copy into classes.dex. When emma is on, dx is run with --no-locals
348 // option to remove local variable information
349 dxFlags = append(dxFlags, "--no-locals")
350 }
351
Colin Cross1332b002015-04-07 17:11:30 -0700352 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700353 dxFlags = append(dxFlags, "--no-optimize")
354 }
355
Colin Cross1332b002015-04-07 17:11:30 -0700356 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700357 dxFlags = append(dxFlags,
358 "--debug",
359 "--verbose",
Colin Cross635c3b02016-05-18 15:37:25 -0700360 "--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(),
Colin Cross2fe66872015-03-30 17:20:39 -0700361 "--dump-width=1000")
362 }
363
364 flags.dxFlags = strings.Join(dxFlags, " ")
365
366 // Compile classes.jar into classes.dex
Colin Cross6d1e72d2015-04-10 17:44:24 -0700367 dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags)
Colin Cross2fe66872015-03-30 17:20:39 -0700368 if ctx.Failed() {
369 return
370 }
371
372 // Combine classes.dex + resources into javalib.jar
Colin Cross6d1e72d2015-04-10 17:44:24 -0700373 outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec)
Colin Cross2fe66872015-03-30 17:20:39 -0700374 }
Colin Crossb7a63242015-04-16 14:09:14 -0700375 ctx.CheckbuildFile(outputFile)
376 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700377}
378
379var _ JavaDependency = (*JavaLibrary)(nil)
380
Colin Cross46c9b8b2017-06-22 16:51:17 -0700381func (j *Module) ClasspathFile() android.Path {
Colin Cross2fe66872015-03-30 17:20:39 -0700382 return j.classpathFile
383}
384
Colin Cross46c9b8b2017-06-22 16:51:17 -0700385func (j *Module) ClassJarSpecs() []jarSpec {
Colin Cross2fe66872015-03-30 17:20:39 -0700386 return j.classJarSpecs
387}
388
Colin Cross46c9b8b2017-06-22 16:51:17 -0700389func (j *Module) ResourceJarSpecs() []jarSpec {
Colin Cross2fe66872015-03-30 17:20:39 -0700390 return j.resourceJarSpecs
391}
392
Colin Cross46c9b8b2017-06-22 16:51:17 -0700393func (j *Module) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700394 return j.exportAidlIncludeDirs
395}
396
Colin Cross46c9b8b2017-06-22 16:51:17 -0700397var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -0700398
Colin Cross46c9b8b2017-06-22 16:51:17 -0700399func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -0700400 return j.logtagsSrcs
401}
402
Colin Cross2fe66872015-03-30 17:20:39 -0700403//
404// Java libraries (.jar file)
405//
406
407type JavaLibrary struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700408 Module
Colin Cross2fe66872015-03-30 17:20:39 -0700409}
410
Colin Cross46c9b8b2017-06-22 16:51:17 -0700411func (j *JavaLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
412 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -0700413
Colin Cross635c3b02016-05-18 15:37:25 -0700414 j.installFile = ctx.InstallFileName(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.outputFile)
Colin Crossb7a63242015-04-16 14:09:14 -0700415}
416
Colin Cross46c9b8b2017-06-22 16:51:17 -0700417func (j *JavaLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
418 j.deps(ctx)
419}
420
Colin Cross2fe66872015-03-30 17:20:39 -0700421func JavaLibraryFactory() (blueprint.Module, []interface{}) {
422 module := &JavaLibrary{}
423
Colin Cross540eff82017-06-22 17:01:52 -0700424 module.deviceProperties.Dex = true
Colin Cross2fe66872015-03-30 17:20:39 -0700425
Colin Cross540eff82017-06-22 17:01:52 -0700426 return android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon,
427 &module.Module.properties,
428 &module.Module.deviceProperties)
Colin Cross2fe66872015-03-30 17:20:39 -0700429}
430
431func JavaLibraryHostFactory() (blueprint.Module, []interface{}) {
432 module := &JavaLibrary{}
433
Colin Cross540eff82017-06-22 17:01:52 -0700434 return android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon,
435 &module.Module.properties)
Colin Cross2fe66872015-03-30 17:20:39 -0700436}
437
438//
439// Java Binaries (.jar file plus wrapper script)
440//
441
Colin Cross7d5136f2015-05-11 13:39:40 -0700442type javaBinaryProperties struct {
443 // installable script to execute the resulting jar
444 Wrapper string
445}
446
Colin Cross2fe66872015-03-30 17:20:39 -0700447type JavaBinary struct {
448 JavaLibrary
449
Colin Cross7d5136f2015-05-11 13:39:40 -0700450 binaryProperties javaBinaryProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700451}
452
Colin Cross46c9b8b2017-06-22 16:51:17 -0700453func (j *JavaBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
454 j.JavaLibrary.GenerateAndroidBuildActions(ctx)
Colin Cross2fe66872015-03-30 17:20:39 -0700455
456 // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
457 // another build rule before the jar has been installed.
Colin Cross635c3b02016-05-18 15:37:25 -0700458 ctx.InstallFile(android.PathForModuleInstall(ctx, "bin"), android.PathForModuleSrc(ctx, j.binaryProperties.Wrapper),
Colin Cross2fe66872015-03-30 17:20:39 -0700459 j.installFile)
460}
461
Colin Cross46c9b8b2017-06-22 16:51:17 -0700462func (j *JavaBinary) DepsMutator(ctx android.BottomUpMutatorContext) {
463 j.deps(ctx)
464}
465
Colin Cross2fe66872015-03-30 17:20:39 -0700466func JavaBinaryFactory() (blueprint.Module, []interface{}) {
467 module := &JavaBinary{}
468
Colin Cross540eff82017-06-22 17:01:52 -0700469 module.deviceProperties.Dex = true
Colin Cross2fe66872015-03-30 17:20:39 -0700470
Colin Cross540eff82017-06-22 17:01:52 -0700471 return android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon,
472 &module.Module.properties,
473 &module.Module.deviceProperties,
474 &module.binaryProperties)
Colin Cross2fe66872015-03-30 17:20:39 -0700475}
476
477func JavaBinaryHostFactory() (blueprint.Module, []interface{}) {
478 module := &JavaBinary{}
479
Colin Cross540eff82017-06-22 17:01:52 -0700480 return android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon,
481 &module.Module.properties,
482 &module.Module.deviceProperties,
483 &module.binaryProperties)
Colin Cross2fe66872015-03-30 17:20:39 -0700484}
485
486//
487// Java prebuilts
488//
489
Colin Cross7d5136f2015-05-11 13:39:40 -0700490type javaPrebuiltProperties struct {
491 Srcs []string
492}
493
Colin Cross2fe66872015-03-30 17:20:39 -0700494type JavaPrebuilt struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700495 android.ModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700496
Colin Cross7d5136f2015-05-11 13:39:40 -0700497 properties javaPrebuiltProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700498
Colin Cross635c3b02016-05-18 15:37:25 -0700499 classpathFile android.Path
Colin Crosse1d62a82015-04-03 16:53:05 -0700500 classJarSpecs, resourceJarSpecs []jarSpec
Colin Cross2fe66872015-03-30 17:20:39 -0700501}
502
Colin Cross1e676be2016-10-12 14:38:15 -0700503func (j *JavaPrebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
504}
505
Colin Cross635c3b02016-05-18 15:37:25 -0700506func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross2fe66872015-03-30 17:20:39 -0700507 if len(j.properties.Srcs) != 1 {
508 ctx.ModuleErrorf("expected exactly one jar in srcs")
509 return
510 }
Colin Cross635c3b02016-05-18 15:37:25 -0700511 prebuilt := android.PathForModuleSrc(ctx, j.properties.Srcs[0])
Colin Crosse1d62a82015-04-03 16:53:05 -0700512
513 classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt)
514
515 j.classpathFile = prebuilt
516 j.classJarSpecs = []jarSpec{classJarSpec}
517 j.resourceJarSpecs = []jarSpec{resourceJarSpec}
Colin Cross635c3b02016-05-18 15:37:25 -0700518 ctx.InstallFileName(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.classpathFile)
Colin Cross2fe66872015-03-30 17:20:39 -0700519}
520
521var _ JavaDependency = (*JavaPrebuilt)(nil)
522
Colin Cross635c3b02016-05-18 15:37:25 -0700523func (j *JavaPrebuilt) ClasspathFile() android.Path {
Colin Cross2fe66872015-03-30 17:20:39 -0700524 return j.classpathFile
525}
526
527func (j *JavaPrebuilt) ClassJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700528 return j.classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700529}
530
531func (j *JavaPrebuilt) ResourceJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700532 return j.resourceJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700533}
534
Colin Cross635c3b02016-05-18 15:37:25 -0700535func (j *JavaPrebuilt) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700536 return nil
537}
538
Colin Cross2fe66872015-03-30 17:20:39 -0700539func JavaPrebuiltFactory() (blueprint.Module, []interface{}) {
540 module := &JavaPrebuilt{}
541
Colin Cross635c3b02016-05-18 15:37:25 -0700542 return android.InitAndroidArchModule(module, android.HostAndDeviceSupported,
543 android.MultilibCommon, &module.properties)
Colin Cross2fe66872015-03-30 17:20:39 -0700544}
545
Colin Crossaa8630b2015-04-13 13:52:22 -0700546//
547// SDK java prebuilts (.jar containing resources plus framework.aidl)
548//
549
550type sdkDependency interface {
551 JavaDependency
Colin Cross635c3b02016-05-18 15:37:25 -0700552 AidlPreprocessed() android.OptionalPath
Colin Crossaa8630b2015-04-13 13:52:22 -0700553}
554
555var _ sdkDependency = (*sdkPrebuilt)(nil)
556
Colin Cross7d5136f2015-05-11 13:39:40 -0700557type sdkPrebuiltProperties struct {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700558 Aidl_preprocessed *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700559}
560
Colin Crossaa8630b2015-04-13 13:52:22 -0700561type sdkPrebuilt struct {
562 JavaPrebuilt
563
Colin Cross7d5136f2015-05-11 13:39:40 -0700564 sdkProperties sdkPrebuiltProperties
Colin Crossaa8630b2015-04-13 13:52:22 -0700565
Colin Cross635c3b02016-05-18 15:37:25 -0700566 aidlPreprocessed android.OptionalPath
Colin Crossaa8630b2015-04-13 13:52:22 -0700567}
568
Colin Cross635c3b02016-05-18 15:37:25 -0700569func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crossaa8630b2015-04-13 13:52:22 -0700570 j.JavaPrebuilt.GenerateAndroidBuildActions(ctx)
571
Colin Cross635c3b02016-05-18 15:37:25 -0700572 j.aidlPreprocessed = android.OptionalPathForModuleSrc(ctx, j.sdkProperties.Aidl_preprocessed)
Colin Crossaa8630b2015-04-13 13:52:22 -0700573}
574
Colin Cross635c3b02016-05-18 15:37:25 -0700575func (j *sdkPrebuilt) AidlPreprocessed() android.OptionalPath {
Colin Crossaa8630b2015-04-13 13:52:22 -0700576 return j.aidlPreprocessed
577}
578
579func SdkPrebuiltFactory() (blueprint.Module, []interface{}) {
580 module := &sdkPrebuilt{}
581
Colin Cross635c3b02016-05-18 15:37:25 -0700582 return android.InitAndroidArchModule(module, android.HostAndDeviceSupported,
583 android.MultilibCommon, &module.properties, &module.sdkProperties)
Colin Crossaa8630b2015-04-13 13:52:22 -0700584}
585
Colin Cross2fe66872015-03-30 17:20:39 -0700586func inList(s string, l []string) bool {
587 for _, e := range l {
588 if e == s {
589 return true
590 }
591 }
592 return false
593}