blob: 8b50eff48a3e5e03342928dd209953602b73e00b [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
148type JavaModuleType interface {
149 GenerateJavaBuildActions(ctx common.AndroidModuleContext)
Colin Crossb7a63242015-04-16 14:09:14 -0700150 JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string
Colin Cross2fe66872015-03-30 17:20:39 -0700151}
152
153type JavaDependency interface {
154 ClasspathFile() string
155 ClassJarSpecs() []jarSpec
156 ResourceJarSpecs() []jarSpec
Colin Crossc0b06f12015-04-08 13:03:43 -0700157 AidlIncludeDirs() []string
Colin Cross2fe66872015-03-30 17:20:39 -0700158}
159
160func NewJavaBase(base *javaBase, module JavaModuleType, hod common.HostOrDeviceSupported,
161 props ...interface{}) (blueprint.Module, []interface{}) {
162
163 base.module = module
164
165 props = append(props, &base.properties)
166
167 return common.InitAndroidArchModule(base, hod, common.MultilibCommon, props...)
168}
169
170func (j *javaBase) BootClasspath(ctx common.AndroidBaseContext) string {
171 if ctx.Device() {
172 if j.properties.Sdk_version == "" {
173 return "core-libart"
174 } else if j.properties.Sdk_version == "current" {
175 // TODO: !TARGET_BUILD_APPS
Colin Crossc0b06f12015-04-08 13:03:43 -0700176 // TODO: export preprocessed framework.aidl from android_stubs_current
Colin Cross2fe66872015-03-30 17:20:39 -0700177 return "android_stubs_current"
178 } else if j.properties.Sdk_version == "system_current" {
179 return "android_system_stubs_current"
180 } else {
181 return "sdk_v" + j.properties.Sdk_version
182 }
183 } else {
184 if j.properties.Dex {
185 return "core-libart"
186 } else {
187 return ""
188 }
189 }
190}
191
Colin Crossefb9ebe2015-04-16 14:08:06 -0700192var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"}
193
Colin Cross2fe66872015-03-30 17:20:39 -0700194func (j *javaBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
Colin Crossb7a63242015-04-16 14:09:14 -0700195 return j.module.JavaDynamicDependencies(ctx)
196}
197
198func (j *javaBase) JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
Colin Cross2fe66872015-03-30 17:20:39 -0700199 var deps []string
200
201 if !j.properties.No_standard_libraries {
202 bootClasspath := j.BootClasspath(ctx)
203 if bootClasspath != "" {
204 deps = append(deps, bootClasspath)
205 }
Colin Crossefb9ebe2015-04-16 14:08:06 -0700206 if ctx.Device() && j.properties.Sdk_version == "" {
207 deps = append(deps, defaultJavaLibraries...)
208 }
Colin Cross2fe66872015-03-30 17:20:39 -0700209 }
210 deps = append(deps, j.properties.Java_libs...)
211 deps = append(deps, j.properties.Java_static_libs...)
212
213 return deps
214}
215
Colin Crossc0b06f12015-04-08 13:03:43 -0700216func (j *javaBase) aidlFlags(ctx common.AndroidModuleContext, aidlPreprocess string,
Colin Crossf03c82b2015-04-13 13:53:40 -0700217 aidlIncludeDirs []string) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700218
219 localAidlIncludes := pathtools.PrefixPaths(j.properties.Aidl_includes, common.ModuleSrcDir(ctx))
220
221 var flags []string
222 if aidlPreprocess != "" {
223 flags = append(flags, "-p"+aidlPreprocess)
224 } else {
225 flags = append(flags, common.JoinWithPrefix(aidlIncludeDirs, "-I"))
226 }
227
228 flags = append(flags, common.JoinWithPrefix(j.exportAidlIncludeDirs, "-I"))
229 flags = append(flags, common.JoinWithPrefix(localAidlIncludes, "-I"))
230 flags = append(flags, "-I"+common.ModuleSrcDir(ctx))
231 flags = append(flags, "-I"+filepath.Join(common.ModuleSrcDir(ctx), "src"))
232
Colin Crossf03c82b2015-04-13 13:53:40 -0700233 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700234}
235
Colin Cross2fe66872015-03-30 17:20:39 -0700236func (j *javaBase) collectDeps(ctx common.AndroidModuleContext) (classpath []string,
Colin Crossc0b06f12015-04-08 13:03:43 -0700237 bootClasspath string, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess string,
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700238 aidlIncludeDirs []string, srcFileLists []string) {
Colin Cross2fe66872015-03-30 17:20:39 -0700239
240 ctx.VisitDirectDeps(func(module blueprint.Module) {
241 otherName := ctx.OtherModuleName(module)
242 if javaDep, ok := module.(JavaDependency); ok {
Colin Cross6cbb1272015-04-08 11:23:01 -0700243 if otherName == j.BootClasspath(ctx) {
244 bootClasspath = javaDep.ClasspathFile()
Colin Crossb7a63242015-04-16 14:09:14 -0700245 } else if inList(otherName, defaultJavaLibraries) {
246 classpath = append(classpath, javaDep.ClasspathFile())
Colin Cross6cbb1272015-04-08 11:23:01 -0700247 } else if inList(otherName, j.properties.Java_libs) {
Colin Cross2fe66872015-03-30 17:20:39 -0700248 classpath = append(classpath, javaDep.ClasspathFile())
249 } else if inList(otherName, j.properties.Java_static_libs) {
250 classpath = append(classpath, javaDep.ClasspathFile())
251 classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...)
252 resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...)
Colin Crossb7a63242015-04-16 14:09:14 -0700253 } else if otherName == "framework-res" {
254 if ctx.ModuleName() == "framework" {
255 // framework.jar has a one-off dependency on the R.java and Manifest.java files
256 // generated by framework-res.apk
257 srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).aaptJavaFileList)
258 }
Colin Cross2fe66872015-03-30 17:20:39 -0700259 } else {
260 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
261 }
Colin Crossaa8630b2015-04-13 13:52:22 -0700262 aidlIncludeDirs = append(aidlIncludeDirs, javaDep.AidlIncludeDirs()...)
263 if sdkDep, ok := module.(sdkDependency); ok {
264 if sdkDep.AidlPreprocessed() != "" {
265 if aidlPreprocess != "" {
266 ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q",
267 aidlPreprocess, sdkDep.AidlPreprocessed())
268 } else {
269 aidlPreprocess = sdkDep.AidlPreprocessed()
270 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700271 }
272 }
Colin Cross2fe66872015-03-30 17:20:39 -0700273 }
274 })
275
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700276 return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
277 aidlIncludeDirs, srcFileLists
Colin Cross2fe66872015-03-30 17:20:39 -0700278}
279
280func (j *javaBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
281 j.module.GenerateJavaBuildActions(ctx)
282}
283
284func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700285
286 j.exportAidlIncludeDirs = pathtools.PrefixPaths(j.properties.Export_aidl_include_dirs,
287 common.ModuleSrcDir(ctx))
288
289 classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700290 aidlIncludeDirs, srcFileLists := j.collectDeps(ctx)
Colin Crossc0b06f12015-04-08 13:03:43 -0700291
Colin Crossf03c82b2015-04-13 13:53:40 -0700292 var flags javaBuilderFlags
293
294 javacFlags := j.properties.Javacflags
295 if len(javacFlags) > 0 {
296 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
297 flags.javacFlags = "$javacFlags"
298 }
299
300 aidlFlags := j.aidlFlags(ctx, aidlPreprocess, aidlIncludeDirs)
301 if len(aidlFlags) > 0 {
302 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
303 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700304 }
305
306 var javacDeps []string
307
Colin Cross2fe66872015-03-30 17:20:39 -0700308 if bootClasspath != "" {
309 flags.bootClasspath = "-bootclasspath " + bootClasspath
310 javacDeps = append(javacDeps, bootClasspath)
311 }
312
313 if len(classpath) > 0 {
314 flags.classpath = "-classpath " + strings.Join(classpath, ":")
315 javacDeps = append(javacDeps, classpath...)
316 }
317
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700318 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700319
Colin Crossf05fe972015-04-10 17:45:20 -0700320 srcFiles = j.genSources(ctx, srcFiles, flags)
Colin Crossc0b06f12015-04-08 13:03:43 -0700321
Colin Cross0607cf72015-04-28 13:28:51 -0700322 ctx.VisitDirectDeps(func(module blueprint.Module) {
323 if gen, ok := module.(genrule.SourceFileGenerator); ok {
324 srcFiles = append(srcFiles, gen.GeneratedSourceFiles()...)
325 }
326 })
327
Colin Crossb7a63242015-04-16 14:09:14 -0700328 srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
329
Colin Cross8cf13342015-04-10 15:41:49 -0700330 if len(srcFiles) > 0 {
331 // Compile java sources into .class files
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700332 classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, javacDeps)
Colin Cross8cf13342015-04-10 15:41:49 -0700333 if ctx.Failed() {
334 return
335 }
336
337 classJarSpecs = append([]jarSpec{classes}, classJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700338 }
339
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700340 resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs),
Colin Cross276284f2015-04-20 13:51:48 -0700341 resourceJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700342
343 manifest := j.properties.Manifest
344 if manifest != "" {
345 manifest = filepath.Join(common.ModuleSrcDir(ctx), manifest)
346 }
347
348 allJarSpecs := append([]jarSpec(nil), classJarSpecs...)
349 allJarSpecs = append(allJarSpecs, resourceJarSpecs...)
350
351 // Combine classes + resources into classes-full-debug.jar
352 outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest)
353 if ctx.Failed() {
354 return
355 }
Colin Cross65bf4f22015-04-03 16:54:17 -0700356
Colin Cross65bf4f22015-04-03 16:54:17 -0700357 if j.properties.Jarjar_rules != "" {
358 jarjar_rules := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Jarjar_rules)
359 // Transform classes-full-debug.jar into classes-jarjar.jar
360 outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
361 if ctx.Failed() {
362 return
363 }
Colin Cross20978302015-04-10 17:05:07 -0700364
365 classes, _ := TransformPrebuiltJarToClasses(ctx, outputFile)
366 classJarSpecs = []jarSpec{classes}
Colin Cross65bf4f22015-04-03 16:54:17 -0700367 }
368
Colin Cross20978302015-04-10 17:05:07 -0700369 j.resourceJarSpecs = resourceJarSpecs
370 j.classJarSpecs = classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700371 j.classpathFile = outputFile
372
Colin Cross8cf13342015-04-10 15:41:49 -0700373 if j.properties.Dex && len(srcFiles) > 0 {
Colin Cross2fe66872015-03-30 17:20:39 -0700374 dxFlags := j.properties.Dxflags
375 if false /* emma enabled */ {
376 // If you instrument class files that have local variable debug information in
377 // them emma does not correctly maintain the local variable table.
378 // This will cause an error when you try to convert the class files for Android.
379 // The workaround here is to build different dex file here based on emma switch
380 // then later copy into classes.dex. When emma is on, dx is run with --no-locals
381 // option to remove local variable information
382 dxFlags = append(dxFlags, "--no-locals")
383 }
384
Colin Cross1332b002015-04-07 17:11:30 -0700385 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700386 dxFlags = append(dxFlags, "--no-optimize")
387 }
388
Colin Cross1332b002015-04-07 17:11:30 -0700389 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700390 dxFlags = append(dxFlags,
391 "--debug",
392 "--verbose",
393 "--dump-to="+filepath.Join(common.ModuleOutDir(ctx), "classes.lst"),
394 "--dump-width=1000")
395 }
396
397 flags.dxFlags = strings.Join(dxFlags, " ")
398
399 // Compile classes.jar into classes.dex
Colin Cross6d1e72d2015-04-10 17:44:24 -0700400 dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags)
Colin Cross2fe66872015-03-30 17:20:39 -0700401 if ctx.Failed() {
402 return
403 }
404
405 // Combine classes.dex + resources into javalib.jar
Colin Cross6d1e72d2015-04-10 17:44:24 -0700406 outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec)
Colin Cross2fe66872015-03-30 17:20:39 -0700407 }
Colin Crossb7a63242015-04-16 14:09:14 -0700408 ctx.CheckbuildFile(outputFile)
409 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700410}
411
412var _ JavaDependency = (*JavaLibrary)(nil)
413
414func (j *javaBase) ClasspathFile() string {
415 return j.classpathFile
416}
417
418func (j *javaBase) ClassJarSpecs() []jarSpec {
419 return j.classJarSpecs
420}
421
422func (j *javaBase) ResourceJarSpecs() []jarSpec {
423 return j.resourceJarSpecs
424}
425
Colin Crossc0b06f12015-04-08 13:03:43 -0700426func (j *javaBase) AidlIncludeDirs() []string {
427 return j.exportAidlIncludeDirs
428}
429
Colin Crossf05fe972015-04-10 17:45:20 -0700430var _ logtagsProducer = (*javaBase)(nil)
431
432func (j *javaBase) logtags() []string {
433 return j.logtagsSrcs
434}
435
Colin Cross2fe66872015-03-30 17:20:39 -0700436//
437// Java libraries (.jar file)
438//
439
440type JavaLibrary struct {
441 javaBase
442}
443
Colin Crossb7a63242015-04-16 14:09:14 -0700444func (j *JavaLibrary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
445 j.javaBase.GenerateJavaBuildActions(ctx)
446
447 j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.outputFile)
448}
449
Colin Cross2fe66872015-03-30 17:20:39 -0700450func JavaLibraryFactory() (blueprint.Module, []interface{}) {
451 module := &JavaLibrary{}
452
453 module.properties.Dex = true
454
455 return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported)
456}
457
458func JavaLibraryHostFactory() (blueprint.Module, []interface{}) {
459 module := &JavaLibrary{}
460
461 return NewJavaBase(&module.javaBase, module, common.HostSupported)
462}
463
464//
465// Java Binaries (.jar file plus wrapper script)
466//
467
Colin Cross7d5136f2015-05-11 13:39:40 -0700468type javaBinaryProperties struct {
469 // installable script to execute the resulting jar
470 Wrapper string
471}
472
Colin Cross2fe66872015-03-30 17:20:39 -0700473type JavaBinary struct {
474 JavaLibrary
475
Colin Cross7d5136f2015-05-11 13:39:40 -0700476 binaryProperties javaBinaryProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700477}
478
479func (j *JavaBinary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
480 j.JavaLibrary.GenerateJavaBuildActions(ctx)
481
482 // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
483 // another build rule before the jar has been installed.
484 ctx.InstallFile("bin", filepath.Join(common.ModuleSrcDir(ctx), j.binaryProperties.Wrapper),
485 j.installFile)
486}
487
488func JavaBinaryFactory() (blueprint.Module, []interface{}) {
489 module := &JavaBinary{}
490
491 module.properties.Dex = true
492
493 return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported, &module.binaryProperties)
494}
495
496func JavaBinaryHostFactory() (blueprint.Module, []interface{}) {
497 module := &JavaBinary{}
498
499 return NewJavaBase(&module.javaBase, module, common.HostSupported, &module.binaryProperties)
500}
501
502//
503// Java prebuilts
504//
505
Colin Cross7d5136f2015-05-11 13:39:40 -0700506type javaPrebuiltProperties struct {
507 Srcs []string
508}
509
Colin Cross2fe66872015-03-30 17:20:39 -0700510type JavaPrebuilt struct {
511 common.AndroidModuleBase
512
Colin Cross7d5136f2015-05-11 13:39:40 -0700513 properties javaPrebuiltProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700514
Colin Crosse1d62a82015-04-03 16:53:05 -0700515 classpathFile string
516 classJarSpecs, resourceJarSpecs []jarSpec
Colin Cross2fe66872015-03-30 17:20:39 -0700517}
518
519func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
520 if len(j.properties.Srcs) != 1 {
521 ctx.ModuleErrorf("expected exactly one jar in srcs")
522 return
523 }
Colin Crosse1d62a82015-04-03 16:53:05 -0700524 prebuilt := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Srcs[0])
525
526 classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt)
527
528 j.classpathFile = prebuilt
529 j.classJarSpecs = []jarSpec{classJarSpec}
530 j.resourceJarSpecs = []jarSpec{resourceJarSpec}
Colin Crosse1d62a82015-04-03 16:53:05 -0700531 ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.classpathFile)
Colin Cross2fe66872015-03-30 17:20:39 -0700532}
533
534var _ JavaDependency = (*JavaPrebuilt)(nil)
535
536func (j *JavaPrebuilt) ClasspathFile() string {
537 return j.classpathFile
538}
539
540func (j *JavaPrebuilt) ClassJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700541 return j.classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700542}
543
544func (j *JavaPrebuilt) ResourceJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700545 return j.resourceJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700546}
547
Colin Crossc0b06f12015-04-08 13:03:43 -0700548func (j *JavaPrebuilt) AidlIncludeDirs() []string {
549 return nil
550}
551
Colin Cross2fe66872015-03-30 17:20:39 -0700552func JavaPrebuiltFactory() (blueprint.Module, []interface{}) {
553 module := &JavaPrebuilt{}
554
555 return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
556 common.MultilibCommon, &module.properties)
557}
558
Colin Crossaa8630b2015-04-13 13:52:22 -0700559//
560// SDK java prebuilts (.jar containing resources plus framework.aidl)
561//
562
563type sdkDependency interface {
564 JavaDependency
565 AidlPreprocessed() string
566}
567
568var _ sdkDependency = (*sdkPrebuilt)(nil)
569
Colin Cross7d5136f2015-05-11 13:39:40 -0700570type sdkPrebuiltProperties struct {
571 Aidl_preprocessed string
572}
573
Colin Crossaa8630b2015-04-13 13:52:22 -0700574type sdkPrebuilt struct {
575 JavaPrebuilt
576
Colin Cross7d5136f2015-05-11 13:39:40 -0700577 sdkProperties sdkPrebuiltProperties
Colin Crossaa8630b2015-04-13 13:52:22 -0700578
579 aidlPreprocessed string
580}
581
582func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
583 j.JavaPrebuilt.GenerateAndroidBuildActions(ctx)
584
585 if j.sdkProperties.Aidl_preprocessed != "" {
586 j.aidlPreprocessed = filepath.Join(common.ModuleSrcDir(ctx), j.sdkProperties.Aidl_preprocessed)
587 }
588}
589
590func (j *sdkPrebuilt) AidlPreprocessed() string {
591 return j.aidlPreprocessed
592}
593
594func SdkPrebuiltFactory() (blueprint.Module, []interface{}) {
595 module := &sdkPrebuilt{}
596
597 return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
598 common.MultilibCommon, &module.properties, &module.sdkProperties)
599}
600
Colin Cross2fe66872015-03-30 17:20:39 -0700601func inList(s string, l []string) bool {
602 for _, e := range l {
603 if e == s {
604 return true
605 }
606 }
607 return false
608}