blob: 2bd5bffaac590d0c07503e110ae2bf601d4d1ed3 [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
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
22 "fmt"
23 "path/filepath"
24 "strings"
25
26 "github.com/google/blueprint"
Colin Crossc0b06f12015-04-08 13:03:43 -070027 "github.com/google/blueprint/pathtools"
Colin Cross2fe66872015-03-30 17:20:39 -070028
Colin Cross463a90e2015-06-17 14:20:06 -070029 "android/soong"
Colin Cross2fe66872015-03-30 17:20:39 -070030 "android/soong/common"
Colin Cross0607cf72015-04-28 13:28:51 -070031 "android/soong/genrule"
Colin Cross2fe66872015-03-30 17:20:39 -070032)
33
Colin Cross463a90e2015-06-17 14:20:06 -070034func init() {
35 soong.RegisterModuleType("java_library", JavaLibraryFactory)
36 soong.RegisterModuleType("java_library_static", JavaLibraryFactory)
37 soong.RegisterModuleType("java_library_host", JavaLibraryHostFactory)
38 soong.RegisterModuleType("java_binary", JavaBinaryFactory)
39 soong.RegisterModuleType("java_binary_host", JavaBinaryHostFactory)
40 soong.RegisterModuleType("prebuilt_java_library", JavaPrebuiltFactory)
41 soong.RegisterModuleType("prebuilt_sdk", SdkPrebuiltFactory)
42 soong.RegisterModuleType("android_app", AndroidAppFactory)
43
44 soong.RegisterSingletonType("logtags", LogtagsSingleton)
45}
46
Colin Cross2fe66872015-03-30 17:20:39 -070047// TODO:
48// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070049// Proto
50// Renderscript
51// Post-jar passes:
52// Proguard
53// Emma
54// Jarjar
55// Dex
56// Rmtypedefs
57// Jack
58// DroidDoc
59// Findbugs
60
Colin Cross7d5136f2015-05-11 13:39:40 -070061type javaBaseProperties struct {
62 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
63 // or .aidl files.
Dan Willemsen2ef08f42015-06-30 18:15:24 -070064 Srcs []string `android:"arch_variant"`
65
66 // list of source files that should not be used to build the Java module.
67 // This is most useful in the arch/multilib variants to remove non-common files
68 Exclude_srcs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070069
70 // list of directories containing Java resources
71 Java_resource_dirs []string `android:"arch_variant"`
72
Dan Willemsen2ef08f42015-06-30 18:15:24 -070073 // list of directories that should be excluded from java_resource_dirs
74 Exclude_java_resource_dirs []string `android:"arch_variant"`
75
Colin Cross7d5136f2015-05-11 13:39:40 -070076 // don't build against the default libraries (core-libart, core-junit,
77 // ext, and framework for device targets)
78 No_standard_libraries bool
79
80 // list of module-specific flags that will be used for javac compiles
81 Javacflags []string `android:"arch_variant"`
82
83 // list of module-specific flags that will be used for jack compiles
84 Jack_flags []string `android:"arch_variant"`
85
86 // list of module-specific flags that will be used for dex compiles
87 Dxflags []string `android:"arch_variant"`
88
89 // list of of java libraries that will be in the classpath
90 Java_libs []string `android:"arch_variant"`
91
92 // list of java libraries that will be compiled into the resulting jar
93 Java_static_libs []string `android:"arch_variant"`
94
95 // manifest file to be included in resulting jar
96 Manifest string
97
98 // if not blank, set to the version of the sdk to compile against
99 Sdk_version string
100
101 // Set for device java libraries, and for host versions of device java libraries
102 // built for testing
103 Dex bool `blueprint:"mutated"`
104
105 // if not blank, run jarjar using the specified rules file
106 Jarjar_rules string
107
108 // directories to pass to aidl tool
109 Aidl_includes []string
110
111 // directories that should be added as include directories
112 // for any aidl sources of modules that depend on this module
113 Export_aidl_include_dirs []string
114}
115
Colin Cross2fe66872015-03-30 17:20:39 -0700116// javaBase contains the properties and members used by all java module types, and implements
117// the blueprint.Module interface.
118type javaBase struct {
119 common.AndroidModuleBase
120 module JavaModuleType
121
Colin Cross7d5136f2015-05-11 13:39:40 -0700122 properties javaBaseProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700123
124 // output file suitable for inserting into the classpath of another compile
125 classpathFile string
126
Colin Crossb7a63242015-04-16 14:09:14 -0700127 // output file suitable for installing or running
128 outputFile string
129
Colin Cross2fe66872015-03-30 17:20:39 -0700130 // jarSpecs suitable for inserting classes from a static library into another jar
131 classJarSpecs []jarSpec
132
133 // jarSpecs suitable for inserting resources from a static library into another jar
134 resourceJarSpecs []jarSpec
135
Colin Crossc0b06f12015-04-08 13:03:43 -0700136 exportAidlIncludeDirs []string
137
Colin Crossf05fe972015-04-10 17:45:20 -0700138 logtagsSrcs []string
139
Colin Crossb7a63242015-04-16 14:09:14 -0700140 // filelists of extra source files that should be included in the javac command line,
141 // for example R.java generated by aapt for android apps
142 ExtraSrcLists []string
143
Colin Cross2fe66872015-03-30 17:20:39 -0700144 // installed file for binary dependency
145 installFile string
146}
147
Colin Cross6362e272015-10-29 15:25:03 -0700148type AndroidJavaModuleContext common.AndroidBaseContext
149
Colin Cross2fe66872015-03-30 17:20:39 -0700150type JavaModuleType interface {
151 GenerateJavaBuildActions(ctx common.AndroidModuleContext)
Colin Cross6362e272015-10-29 15:25:03 -0700152 JavaDependencies(ctx AndroidJavaModuleContext) []string
Colin Cross2fe66872015-03-30 17:20:39 -0700153}
154
155type JavaDependency interface {
156 ClasspathFile() string
157 ClassJarSpecs() []jarSpec
158 ResourceJarSpecs() []jarSpec
Colin Crossc0b06f12015-04-08 13:03:43 -0700159 AidlIncludeDirs() []string
Colin Cross2fe66872015-03-30 17:20:39 -0700160}
161
162func NewJavaBase(base *javaBase, module JavaModuleType, hod common.HostOrDeviceSupported,
163 props ...interface{}) (blueprint.Module, []interface{}) {
164
165 base.module = module
166
167 props = append(props, &base.properties)
168
169 return common.InitAndroidArchModule(base, hod, common.MultilibCommon, props...)
170}
171
172func (j *javaBase) BootClasspath(ctx common.AndroidBaseContext) string {
173 if ctx.Device() {
174 if j.properties.Sdk_version == "" {
175 return "core-libart"
176 } else if j.properties.Sdk_version == "current" {
177 // TODO: !TARGET_BUILD_APPS
Colin Crossc0b06f12015-04-08 13:03:43 -0700178 // TODO: export preprocessed framework.aidl from android_stubs_current
Colin Cross2fe66872015-03-30 17:20:39 -0700179 return "android_stubs_current"
180 } else if j.properties.Sdk_version == "system_current" {
181 return "android_system_stubs_current"
182 } else {
183 return "sdk_v" + j.properties.Sdk_version
184 }
185 } else {
186 if j.properties.Dex {
187 return "core-libart"
188 } else {
189 return ""
190 }
191 }
192}
193
Colin Crossefb9ebe2015-04-16 14:08:06 -0700194var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"}
195
Colin Cross6362e272015-10-29 15:25:03 -0700196func javaDepsMutator(ctx common.AndroidBottomUpMutatorContext) {
197 if j, ok := ctx.Module().(JavaModuleType); ok {
198 ctx.AddDependency(ctx.Module(), j.JavaDependencies(ctx)...)
199 }
Colin Crossb7a63242015-04-16 14:09:14 -0700200}
201
Colin Cross6362e272015-10-29 15:25:03 -0700202func (j *javaBase) JavaDependencies(ctx AndroidJavaModuleContext) []string {
Colin Cross2fe66872015-03-30 17:20:39 -0700203 var deps []string
204
205 if !j.properties.No_standard_libraries {
206 bootClasspath := j.BootClasspath(ctx)
207 if bootClasspath != "" {
208 deps = append(deps, bootClasspath)
209 }
Colin Crossefb9ebe2015-04-16 14:08:06 -0700210 if ctx.Device() && j.properties.Sdk_version == "" {
211 deps = append(deps, defaultJavaLibraries...)
212 }
Colin Cross2fe66872015-03-30 17:20:39 -0700213 }
214 deps = append(deps, j.properties.Java_libs...)
215 deps = append(deps, j.properties.Java_static_libs...)
216
217 return deps
218}
219
Colin Crossc0b06f12015-04-08 13:03:43 -0700220func (j *javaBase) aidlFlags(ctx common.AndroidModuleContext, aidlPreprocess string,
Colin Crossf03c82b2015-04-13 13:53:40 -0700221 aidlIncludeDirs []string) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700222
223 localAidlIncludes := pathtools.PrefixPaths(j.properties.Aidl_includes, common.ModuleSrcDir(ctx))
224
225 var flags []string
226 if aidlPreprocess != "" {
227 flags = append(flags, "-p"+aidlPreprocess)
228 } else {
229 flags = append(flags, common.JoinWithPrefix(aidlIncludeDirs, "-I"))
230 }
231
232 flags = append(flags, common.JoinWithPrefix(j.exportAidlIncludeDirs, "-I"))
233 flags = append(flags, common.JoinWithPrefix(localAidlIncludes, "-I"))
234 flags = append(flags, "-I"+common.ModuleSrcDir(ctx))
235 flags = append(flags, "-I"+filepath.Join(common.ModuleSrcDir(ctx), "src"))
236
Colin Crossf03c82b2015-04-13 13:53:40 -0700237 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700238}
239
Colin Cross2fe66872015-03-30 17:20:39 -0700240func (j *javaBase) collectDeps(ctx common.AndroidModuleContext) (classpath []string,
Colin Crossc0b06f12015-04-08 13:03:43 -0700241 bootClasspath string, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess string,
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700242 aidlIncludeDirs []string, srcFileLists []string) {
Colin Cross2fe66872015-03-30 17:20:39 -0700243
244 ctx.VisitDirectDeps(func(module blueprint.Module) {
245 otherName := ctx.OtherModuleName(module)
246 if javaDep, ok := module.(JavaDependency); ok {
Colin Cross6cbb1272015-04-08 11:23:01 -0700247 if otherName == j.BootClasspath(ctx) {
248 bootClasspath = javaDep.ClasspathFile()
Colin Crossb7a63242015-04-16 14:09:14 -0700249 } else if inList(otherName, defaultJavaLibraries) {
250 classpath = append(classpath, javaDep.ClasspathFile())
Colin Cross6cbb1272015-04-08 11:23:01 -0700251 } else if inList(otherName, j.properties.Java_libs) {
Colin Cross2fe66872015-03-30 17:20:39 -0700252 classpath = append(classpath, javaDep.ClasspathFile())
253 } else if inList(otherName, j.properties.Java_static_libs) {
254 classpath = append(classpath, javaDep.ClasspathFile())
255 classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...)
256 resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...)
Colin Crossb7a63242015-04-16 14:09:14 -0700257 } else if otherName == "framework-res" {
258 if ctx.ModuleName() == "framework" {
259 // framework.jar has a one-off dependency on the R.java and Manifest.java files
260 // generated by framework-res.apk
261 srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).aaptJavaFileList)
262 }
Colin Cross2fe66872015-03-30 17:20:39 -0700263 } else {
264 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
265 }
Colin Crossaa8630b2015-04-13 13:52:22 -0700266 aidlIncludeDirs = append(aidlIncludeDirs, javaDep.AidlIncludeDirs()...)
267 if sdkDep, ok := module.(sdkDependency); ok {
268 if sdkDep.AidlPreprocessed() != "" {
269 if aidlPreprocess != "" {
270 ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q",
271 aidlPreprocess, sdkDep.AidlPreprocessed())
272 } else {
273 aidlPreprocess = sdkDep.AidlPreprocessed()
274 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700275 }
276 }
Colin Cross2fe66872015-03-30 17:20:39 -0700277 }
278 })
279
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700280 return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
281 aidlIncludeDirs, srcFileLists
Colin Cross2fe66872015-03-30 17:20:39 -0700282}
283
284func (j *javaBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
285 j.module.GenerateJavaBuildActions(ctx)
286}
287
288func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700289
290 j.exportAidlIncludeDirs = pathtools.PrefixPaths(j.properties.Export_aidl_include_dirs,
291 common.ModuleSrcDir(ctx))
292
293 classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700294 aidlIncludeDirs, srcFileLists := j.collectDeps(ctx)
Colin Crossc0b06f12015-04-08 13:03:43 -0700295
Colin Crossf03c82b2015-04-13 13:53:40 -0700296 var flags javaBuilderFlags
297
298 javacFlags := j.properties.Javacflags
299 if len(javacFlags) > 0 {
300 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
301 flags.javacFlags = "$javacFlags"
302 }
303
304 aidlFlags := j.aidlFlags(ctx, aidlPreprocess, aidlIncludeDirs)
305 if len(aidlFlags) > 0 {
306 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
307 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700308 }
309
310 var javacDeps []string
311
Colin Cross2fe66872015-03-30 17:20:39 -0700312 if bootClasspath != "" {
313 flags.bootClasspath = "-bootclasspath " + bootClasspath
314 javacDeps = append(javacDeps, bootClasspath)
315 }
316
317 if len(classpath) > 0 {
318 flags.classpath = "-classpath " + strings.Join(classpath, ":")
319 javacDeps = append(javacDeps, classpath...)
320 }
321
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700322 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700323
Colin Crossf05fe972015-04-10 17:45:20 -0700324 srcFiles = j.genSources(ctx, srcFiles, flags)
Colin Crossc0b06f12015-04-08 13:03:43 -0700325
Colin Cross0607cf72015-04-28 13:28:51 -0700326 ctx.VisitDirectDeps(func(module blueprint.Module) {
327 if gen, ok := module.(genrule.SourceFileGenerator); ok {
328 srcFiles = append(srcFiles, gen.GeneratedSourceFiles()...)
329 }
330 })
331
Colin Crossb7a63242015-04-16 14:09:14 -0700332 srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
333
Colin Cross8cf13342015-04-10 15:41:49 -0700334 if len(srcFiles) > 0 {
335 // Compile java sources into .class files
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700336 classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, javacDeps)
Colin Cross8cf13342015-04-10 15:41:49 -0700337 if ctx.Failed() {
338 return
339 }
340
341 classJarSpecs = append([]jarSpec{classes}, classJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700342 }
343
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700344 resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs),
Colin Cross276284f2015-04-20 13:51:48 -0700345 resourceJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700346
347 manifest := j.properties.Manifest
348 if manifest != "" {
349 manifest = filepath.Join(common.ModuleSrcDir(ctx), manifest)
350 }
351
352 allJarSpecs := append([]jarSpec(nil), classJarSpecs...)
353 allJarSpecs = append(allJarSpecs, resourceJarSpecs...)
354
355 // Combine classes + resources into classes-full-debug.jar
356 outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest)
357 if ctx.Failed() {
358 return
359 }
Colin Cross65bf4f22015-04-03 16:54:17 -0700360
Colin Cross65bf4f22015-04-03 16:54:17 -0700361 if j.properties.Jarjar_rules != "" {
362 jarjar_rules := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Jarjar_rules)
363 // Transform classes-full-debug.jar into classes-jarjar.jar
364 outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
365 if ctx.Failed() {
366 return
367 }
Colin Cross20978302015-04-10 17:05:07 -0700368
369 classes, _ := TransformPrebuiltJarToClasses(ctx, outputFile)
370 classJarSpecs = []jarSpec{classes}
Colin Cross65bf4f22015-04-03 16:54:17 -0700371 }
372
Colin Cross20978302015-04-10 17:05:07 -0700373 j.resourceJarSpecs = resourceJarSpecs
374 j.classJarSpecs = classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700375 j.classpathFile = outputFile
376
Colin Cross8cf13342015-04-10 15:41:49 -0700377 if j.properties.Dex && len(srcFiles) > 0 {
Colin Cross2fe66872015-03-30 17:20:39 -0700378 dxFlags := j.properties.Dxflags
379 if false /* emma enabled */ {
380 // If you instrument class files that have local variable debug information in
381 // them emma does not correctly maintain the local variable table.
382 // This will cause an error when you try to convert the class files for Android.
383 // The workaround here is to build different dex file here based on emma switch
384 // then later copy into classes.dex. When emma is on, dx is run with --no-locals
385 // option to remove local variable information
386 dxFlags = append(dxFlags, "--no-locals")
387 }
388
Colin Cross1332b002015-04-07 17:11:30 -0700389 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700390 dxFlags = append(dxFlags, "--no-optimize")
391 }
392
Colin Cross1332b002015-04-07 17:11:30 -0700393 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700394 dxFlags = append(dxFlags,
395 "--debug",
396 "--verbose",
397 "--dump-to="+filepath.Join(common.ModuleOutDir(ctx), "classes.lst"),
398 "--dump-width=1000")
399 }
400
401 flags.dxFlags = strings.Join(dxFlags, " ")
402
403 // Compile classes.jar into classes.dex
Colin Cross6d1e72d2015-04-10 17:44:24 -0700404 dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags)
Colin Cross2fe66872015-03-30 17:20:39 -0700405 if ctx.Failed() {
406 return
407 }
408
409 // Combine classes.dex + resources into javalib.jar
Colin Cross6d1e72d2015-04-10 17:44:24 -0700410 outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec)
Colin Cross2fe66872015-03-30 17:20:39 -0700411 }
Colin Crossb7a63242015-04-16 14:09:14 -0700412 ctx.CheckbuildFile(outputFile)
413 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700414}
415
416var _ JavaDependency = (*JavaLibrary)(nil)
417
418func (j *javaBase) ClasspathFile() string {
419 return j.classpathFile
420}
421
422func (j *javaBase) ClassJarSpecs() []jarSpec {
423 return j.classJarSpecs
424}
425
426func (j *javaBase) ResourceJarSpecs() []jarSpec {
427 return j.resourceJarSpecs
428}
429
Colin Crossc0b06f12015-04-08 13:03:43 -0700430func (j *javaBase) AidlIncludeDirs() []string {
431 return j.exportAidlIncludeDirs
432}
433
Colin Crossf05fe972015-04-10 17:45:20 -0700434var _ logtagsProducer = (*javaBase)(nil)
435
436func (j *javaBase) logtags() []string {
437 return j.logtagsSrcs
438}
439
Colin Cross2fe66872015-03-30 17:20:39 -0700440//
441// Java libraries (.jar file)
442//
443
444type JavaLibrary struct {
445 javaBase
446}
447
Colin Crossb7a63242015-04-16 14:09:14 -0700448func (j *JavaLibrary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
449 j.javaBase.GenerateJavaBuildActions(ctx)
450
451 j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.outputFile)
452}
453
Colin Cross2fe66872015-03-30 17:20:39 -0700454func JavaLibraryFactory() (blueprint.Module, []interface{}) {
455 module := &JavaLibrary{}
456
457 module.properties.Dex = true
458
459 return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported)
460}
461
462func JavaLibraryHostFactory() (blueprint.Module, []interface{}) {
463 module := &JavaLibrary{}
464
465 return NewJavaBase(&module.javaBase, module, common.HostSupported)
466}
467
468//
469// Java Binaries (.jar file plus wrapper script)
470//
471
Colin Cross7d5136f2015-05-11 13:39:40 -0700472type javaBinaryProperties struct {
473 // installable script to execute the resulting jar
474 Wrapper string
475}
476
Colin Cross2fe66872015-03-30 17:20:39 -0700477type JavaBinary struct {
478 JavaLibrary
479
Colin Cross7d5136f2015-05-11 13:39:40 -0700480 binaryProperties javaBinaryProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700481}
482
483func (j *JavaBinary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
484 j.JavaLibrary.GenerateJavaBuildActions(ctx)
485
486 // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
487 // another build rule before the jar has been installed.
488 ctx.InstallFile("bin", filepath.Join(common.ModuleSrcDir(ctx), j.binaryProperties.Wrapper),
489 j.installFile)
490}
491
492func JavaBinaryFactory() (blueprint.Module, []interface{}) {
493 module := &JavaBinary{}
494
495 module.properties.Dex = true
496
497 return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported, &module.binaryProperties)
498}
499
500func JavaBinaryHostFactory() (blueprint.Module, []interface{}) {
501 module := &JavaBinary{}
502
503 return NewJavaBase(&module.javaBase, module, common.HostSupported, &module.binaryProperties)
504}
505
506//
507// Java prebuilts
508//
509
Colin Cross7d5136f2015-05-11 13:39:40 -0700510type javaPrebuiltProperties struct {
511 Srcs []string
512}
513
Colin Cross2fe66872015-03-30 17:20:39 -0700514type JavaPrebuilt struct {
515 common.AndroidModuleBase
516
Colin Cross7d5136f2015-05-11 13:39:40 -0700517 properties javaPrebuiltProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700518
Colin Crosse1d62a82015-04-03 16:53:05 -0700519 classpathFile string
520 classJarSpecs, resourceJarSpecs []jarSpec
Colin Cross2fe66872015-03-30 17:20:39 -0700521}
522
523func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
524 if len(j.properties.Srcs) != 1 {
525 ctx.ModuleErrorf("expected exactly one jar in srcs")
526 return
527 }
Colin Crosse1d62a82015-04-03 16:53:05 -0700528 prebuilt := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Srcs[0])
529
530 classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt)
531
532 j.classpathFile = prebuilt
533 j.classJarSpecs = []jarSpec{classJarSpec}
534 j.resourceJarSpecs = []jarSpec{resourceJarSpec}
Colin Crosse1d62a82015-04-03 16:53:05 -0700535 ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.classpathFile)
Colin Cross2fe66872015-03-30 17:20:39 -0700536}
537
538var _ JavaDependency = (*JavaPrebuilt)(nil)
539
540func (j *JavaPrebuilt) ClasspathFile() string {
541 return j.classpathFile
542}
543
544func (j *JavaPrebuilt) ClassJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700545 return j.classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700546}
547
548func (j *JavaPrebuilt) ResourceJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700549 return j.resourceJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700550}
551
Colin Crossc0b06f12015-04-08 13:03:43 -0700552func (j *JavaPrebuilt) AidlIncludeDirs() []string {
553 return nil
554}
555
Colin Cross2fe66872015-03-30 17:20:39 -0700556func JavaPrebuiltFactory() (blueprint.Module, []interface{}) {
557 module := &JavaPrebuilt{}
558
559 return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
560 common.MultilibCommon, &module.properties)
561}
562
Colin Crossaa8630b2015-04-13 13:52:22 -0700563//
564// SDK java prebuilts (.jar containing resources plus framework.aidl)
565//
566
567type sdkDependency interface {
568 JavaDependency
569 AidlPreprocessed() string
570}
571
572var _ sdkDependency = (*sdkPrebuilt)(nil)
573
Colin Cross7d5136f2015-05-11 13:39:40 -0700574type sdkPrebuiltProperties struct {
575 Aidl_preprocessed string
576}
577
Colin Crossaa8630b2015-04-13 13:52:22 -0700578type sdkPrebuilt struct {
579 JavaPrebuilt
580
Colin Cross7d5136f2015-05-11 13:39:40 -0700581 sdkProperties sdkPrebuiltProperties
Colin Crossaa8630b2015-04-13 13:52:22 -0700582
583 aidlPreprocessed string
584}
585
586func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
587 j.JavaPrebuilt.GenerateAndroidBuildActions(ctx)
588
589 if j.sdkProperties.Aidl_preprocessed != "" {
590 j.aidlPreprocessed = filepath.Join(common.ModuleSrcDir(ctx), j.sdkProperties.Aidl_preprocessed)
591 }
592}
593
594func (j *sdkPrebuilt) AidlPreprocessed() string {
595 return j.aidlPreprocessed
596}
597
598func SdkPrebuiltFactory() (blueprint.Module, []interface{}) {
599 module := &sdkPrebuilt{}
600
601 return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
602 common.MultilibCommon, &module.properties, &module.sdkProperties)
603}
604
Colin Cross2fe66872015-03-30 17:20:39 -0700605func inList(s string, l []string) bool {
606 for _, e := range l {
607 if e == s {
608 return true
609 }
610 }
611 return false
612}