blob: 9787d60256cccfdc98fda4dddb9cf21bd0118fae [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
29 "android/soong/common"
Colin Cross0607cf72015-04-28 13:28:51 -070030 "android/soong/genrule"
Colin Cross2fe66872015-03-30 17:20:39 -070031)
32
Colin Cross2fe66872015-03-30 17:20:39 -070033// TODO:
34// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070035// Proto
36// Renderscript
37// Post-jar passes:
38// Proguard
39// Emma
40// Jarjar
41// Dex
42// Rmtypedefs
43// Jack
44// DroidDoc
45// Findbugs
46
47// javaBase contains the properties and members used by all java module types, and implements
48// the blueprint.Module interface.
49type javaBase struct {
50 common.AndroidModuleBase
51 module JavaModuleType
52
53 properties struct {
54 // srcs: list of source files used to compile the Java module. May be .java, .logtags, .proto,
55 // or .aidl files.
56 Srcs []string `android:"arch_variant,arch_subtract"`
57
Colin Cross276284f2015-04-20 13:51:48 -070058 // java_resource_dirs: list of directories containing Java resources
59 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross2fe66872015-03-30 17:20:39 -070060
61 // no_standard_libraries: don't build against the default libraries (core-libart, core-junit,
62 // ext, and framework for device targets)
63 No_standard_libraries bool
64
65 // javacflags: list of module-specific flags that will be used for javac compiles
66 Javacflags []string `android:"arch_variant"`
67
Colin Cross74d1ec02015-04-28 13:30:13 -070068 // jack_flags: list of module-specific flags that will be used for jack compiles
69 Jack_flags []string `android:"arch_variant"`
70
Colin Cross2fe66872015-03-30 17:20:39 -070071 // dxflags: list of module-specific flags that will be used for dex compiles
72 Dxflags []string `android:"arch_variant"`
73
74 // java_libs: list of of java libraries that will be in the classpath
75 Java_libs []string `android:"arch_variant"`
76
77 // java_static_libs: list of java libraries that will be compiled into the resulting jar
78 Java_static_libs []string `android:"arch_variant"`
79
80 // manifest: manifest file to be included in resulting jar
81 Manifest string
82
83 // sdk_version: if not blank, set to the version of the sdk to compile against
84 Sdk_version string
85
86 // Set for device java libraries, and for host versions of device java libraries
87 // built for testing
88 Dex bool `blueprint:"mutated"`
Colin Cross65bf4f22015-04-03 16:54:17 -070089
90 // jarjar_rules: if not blank, run jarjar using the specified rules file
91 Jarjar_rules string
Colin Crossc0b06f12015-04-08 13:03:43 -070092
93 // aidl_includes: directories to pass to aidl tool
94 Aidl_includes []string
95
96 // aidl_export_include_dirs: directories that should be added as include directories
97 // for any aidl sources of modules that depend on this module
98 Export_aidl_include_dirs []string
Colin Cross2fe66872015-03-30 17:20:39 -070099 }
100
101 // output file suitable for inserting into the classpath of another compile
102 classpathFile string
103
Colin Crossb7a63242015-04-16 14:09:14 -0700104 // output file suitable for installing or running
105 outputFile string
106
Colin Cross2fe66872015-03-30 17:20:39 -0700107 // jarSpecs suitable for inserting classes from a static library into another jar
108 classJarSpecs []jarSpec
109
110 // jarSpecs suitable for inserting resources from a static library into another jar
111 resourceJarSpecs []jarSpec
112
Colin Crossc0b06f12015-04-08 13:03:43 -0700113 exportAidlIncludeDirs []string
114
Colin Crossf05fe972015-04-10 17:45:20 -0700115 logtagsSrcs []string
116
Colin Crossb7a63242015-04-16 14:09:14 -0700117 // filelists of extra source files that should be included in the javac command line,
118 // for example R.java generated by aapt for android apps
119 ExtraSrcLists []string
120
Colin Cross2fe66872015-03-30 17:20:39 -0700121 // installed file for binary dependency
122 installFile string
123}
124
125type JavaModuleType interface {
126 GenerateJavaBuildActions(ctx common.AndroidModuleContext)
Colin Crossb7a63242015-04-16 14:09:14 -0700127 JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string
Colin Cross2fe66872015-03-30 17:20:39 -0700128}
129
130type JavaDependency interface {
131 ClasspathFile() string
132 ClassJarSpecs() []jarSpec
133 ResourceJarSpecs() []jarSpec
Colin Crossc0b06f12015-04-08 13:03:43 -0700134 AidlIncludeDirs() []string
Colin Cross2fe66872015-03-30 17:20:39 -0700135}
136
137func NewJavaBase(base *javaBase, module JavaModuleType, hod common.HostOrDeviceSupported,
138 props ...interface{}) (blueprint.Module, []interface{}) {
139
140 base.module = module
141
142 props = append(props, &base.properties)
143
144 return common.InitAndroidArchModule(base, hod, common.MultilibCommon, props...)
145}
146
147func (j *javaBase) BootClasspath(ctx common.AndroidBaseContext) string {
148 if ctx.Device() {
149 if j.properties.Sdk_version == "" {
150 return "core-libart"
151 } else if j.properties.Sdk_version == "current" {
152 // TODO: !TARGET_BUILD_APPS
Colin Crossc0b06f12015-04-08 13:03:43 -0700153 // TODO: export preprocessed framework.aidl from android_stubs_current
Colin Cross2fe66872015-03-30 17:20:39 -0700154 return "android_stubs_current"
155 } else if j.properties.Sdk_version == "system_current" {
156 return "android_system_stubs_current"
157 } else {
158 return "sdk_v" + j.properties.Sdk_version
159 }
160 } else {
161 if j.properties.Dex {
162 return "core-libart"
163 } else {
164 return ""
165 }
166 }
167}
168
Colin Crossefb9ebe2015-04-16 14:08:06 -0700169var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"}
170
Colin Cross2fe66872015-03-30 17:20:39 -0700171func (j *javaBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
Colin Crossb7a63242015-04-16 14:09:14 -0700172 return j.module.JavaDynamicDependencies(ctx)
173}
174
175func (j *javaBase) JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
Colin Cross2fe66872015-03-30 17:20:39 -0700176 var deps []string
177
178 if !j.properties.No_standard_libraries {
179 bootClasspath := j.BootClasspath(ctx)
180 if bootClasspath != "" {
181 deps = append(deps, bootClasspath)
182 }
Colin Crossefb9ebe2015-04-16 14:08:06 -0700183 if ctx.Device() && j.properties.Sdk_version == "" {
184 deps = append(deps, defaultJavaLibraries...)
185 }
Colin Cross2fe66872015-03-30 17:20:39 -0700186 }
187 deps = append(deps, j.properties.Java_libs...)
188 deps = append(deps, j.properties.Java_static_libs...)
189
190 return deps
191}
192
Colin Crossc0b06f12015-04-08 13:03:43 -0700193func (j *javaBase) aidlFlags(ctx common.AndroidModuleContext, aidlPreprocess string,
Colin Crossf03c82b2015-04-13 13:53:40 -0700194 aidlIncludeDirs []string) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700195
196 localAidlIncludes := pathtools.PrefixPaths(j.properties.Aidl_includes, common.ModuleSrcDir(ctx))
197
198 var flags []string
199 if aidlPreprocess != "" {
200 flags = append(flags, "-p"+aidlPreprocess)
201 } else {
202 flags = append(flags, common.JoinWithPrefix(aidlIncludeDirs, "-I"))
203 }
204
205 flags = append(flags, common.JoinWithPrefix(j.exportAidlIncludeDirs, "-I"))
206 flags = append(flags, common.JoinWithPrefix(localAidlIncludes, "-I"))
207 flags = append(flags, "-I"+common.ModuleSrcDir(ctx))
208 flags = append(flags, "-I"+filepath.Join(common.ModuleSrcDir(ctx), "src"))
209
Colin Crossf03c82b2015-04-13 13:53:40 -0700210 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700211}
212
Colin Cross2fe66872015-03-30 17:20:39 -0700213func (j *javaBase) collectDeps(ctx common.AndroidModuleContext) (classpath []string,
Colin Crossc0b06f12015-04-08 13:03:43 -0700214 bootClasspath string, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess string,
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700215 aidlIncludeDirs []string, srcFileLists []string) {
Colin Cross2fe66872015-03-30 17:20:39 -0700216
217 ctx.VisitDirectDeps(func(module blueprint.Module) {
218 otherName := ctx.OtherModuleName(module)
219 if javaDep, ok := module.(JavaDependency); ok {
Colin Cross6cbb1272015-04-08 11:23:01 -0700220 if otherName == j.BootClasspath(ctx) {
221 bootClasspath = javaDep.ClasspathFile()
Colin Crossb7a63242015-04-16 14:09:14 -0700222 } else if inList(otherName, defaultJavaLibraries) {
223 classpath = append(classpath, javaDep.ClasspathFile())
Colin Cross6cbb1272015-04-08 11:23:01 -0700224 } else if inList(otherName, j.properties.Java_libs) {
Colin Cross2fe66872015-03-30 17:20:39 -0700225 classpath = append(classpath, javaDep.ClasspathFile())
226 } else if inList(otherName, j.properties.Java_static_libs) {
227 classpath = append(classpath, javaDep.ClasspathFile())
228 classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...)
229 resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...)
Colin Crossb7a63242015-04-16 14:09:14 -0700230 } else if otherName == "framework-res" {
231 if ctx.ModuleName() == "framework" {
232 // framework.jar has a one-off dependency on the R.java and Manifest.java files
233 // generated by framework-res.apk
234 srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).aaptJavaFileList)
235 }
Colin Cross2fe66872015-03-30 17:20:39 -0700236 } else {
237 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
238 }
Colin Crossaa8630b2015-04-13 13:52:22 -0700239 aidlIncludeDirs = append(aidlIncludeDirs, javaDep.AidlIncludeDirs()...)
240 if sdkDep, ok := module.(sdkDependency); ok {
241 if sdkDep.AidlPreprocessed() != "" {
242 if aidlPreprocess != "" {
243 ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q",
244 aidlPreprocess, sdkDep.AidlPreprocessed())
245 } else {
246 aidlPreprocess = sdkDep.AidlPreprocessed()
247 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700248 }
249 }
Colin Cross2fe66872015-03-30 17:20:39 -0700250 }
251 })
252
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700253 return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
254 aidlIncludeDirs, srcFileLists
Colin Cross2fe66872015-03-30 17:20:39 -0700255}
256
257func (j *javaBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
258 j.module.GenerateJavaBuildActions(ctx)
259}
260
261func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700262
263 j.exportAidlIncludeDirs = pathtools.PrefixPaths(j.properties.Export_aidl_include_dirs,
264 common.ModuleSrcDir(ctx))
265
266 classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700267 aidlIncludeDirs, srcFileLists := j.collectDeps(ctx)
Colin Crossc0b06f12015-04-08 13:03:43 -0700268
Colin Crossf03c82b2015-04-13 13:53:40 -0700269 var flags javaBuilderFlags
270
271 javacFlags := j.properties.Javacflags
272 if len(javacFlags) > 0 {
273 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
274 flags.javacFlags = "$javacFlags"
275 }
276
277 aidlFlags := j.aidlFlags(ctx, aidlPreprocess, aidlIncludeDirs)
278 if len(aidlFlags) > 0 {
279 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
280 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700281 }
282
283 var javacDeps []string
284
Colin Cross2fe66872015-03-30 17:20:39 -0700285 if bootClasspath != "" {
286 flags.bootClasspath = "-bootclasspath " + bootClasspath
287 javacDeps = append(javacDeps, bootClasspath)
288 }
289
290 if len(classpath) > 0 {
291 flags.classpath = "-classpath " + strings.Join(classpath, ":")
292 javacDeps = append(javacDeps, classpath...)
293 }
294
Colin Cross8f101b42015-06-17 15:09:06 -0700295 srcFiles := ctx.ExpandSources(j.properties.Srcs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700296
Colin Crossf05fe972015-04-10 17:45:20 -0700297 srcFiles = j.genSources(ctx, srcFiles, flags)
Colin Crossc0b06f12015-04-08 13:03:43 -0700298
Colin Cross0607cf72015-04-28 13:28:51 -0700299 ctx.VisitDirectDeps(func(module blueprint.Module) {
300 if gen, ok := module.(genrule.SourceFileGenerator); ok {
301 srcFiles = append(srcFiles, gen.GeneratedSourceFiles()...)
302 }
303 })
304
Colin Crossb7a63242015-04-16 14:09:14 -0700305 srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
306
Colin Cross8cf13342015-04-10 15:41:49 -0700307 if len(srcFiles) > 0 {
308 // Compile java sources into .class files
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700309 classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, javacDeps)
Colin Cross8cf13342015-04-10 15:41:49 -0700310 if ctx.Failed() {
311 return
312 }
313
314 classJarSpecs = append([]jarSpec{classes}, classJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700315 }
316
Colin Cross276284f2015-04-20 13:51:48 -0700317 resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Java_resource_dirs),
318 resourceJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700319
320 manifest := j.properties.Manifest
321 if manifest != "" {
322 manifest = filepath.Join(common.ModuleSrcDir(ctx), manifest)
323 }
324
325 allJarSpecs := append([]jarSpec(nil), classJarSpecs...)
326 allJarSpecs = append(allJarSpecs, resourceJarSpecs...)
327
328 // Combine classes + resources into classes-full-debug.jar
329 outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest)
330 if ctx.Failed() {
331 return
332 }
Colin Cross65bf4f22015-04-03 16:54:17 -0700333
Colin Cross65bf4f22015-04-03 16:54:17 -0700334 if j.properties.Jarjar_rules != "" {
335 jarjar_rules := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Jarjar_rules)
336 // Transform classes-full-debug.jar into classes-jarjar.jar
337 outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
338 if ctx.Failed() {
339 return
340 }
Colin Cross20978302015-04-10 17:05:07 -0700341
342 classes, _ := TransformPrebuiltJarToClasses(ctx, outputFile)
343 classJarSpecs = []jarSpec{classes}
Colin Cross65bf4f22015-04-03 16:54:17 -0700344 }
345
Colin Cross20978302015-04-10 17:05:07 -0700346 j.resourceJarSpecs = resourceJarSpecs
347 j.classJarSpecs = classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700348 j.classpathFile = outputFile
349
Colin Cross8cf13342015-04-10 15:41:49 -0700350 if j.properties.Dex && len(srcFiles) > 0 {
Colin Cross2fe66872015-03-30 17:20:39 -0700351 dxFlags := j.properties.Dxflags
352 if false /* emma enabled */ {
353 // If you instrument class files that have local variable debug information in
354 // them emma does not correctly maintain the local variable table.
355 // This will cause an error when you try to convert the class files for Android.
356 // The workaround here is to build different dex file here based on emma switch
357 // then later copy into classes.dex. When emma is on, dx is run with --no-locals
358 // option to remove local variable information
359 dxFlags = append(dxFlags, "--no-locals")
360 }
361
Colin Cross1332b002015-04-07 17:11:30 -0700362 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700363 dxFlags = append(dxFlags, "--no-optimize")
364 }
365
Colin Cross1332b002015-04-07 17:11:30 -0700366 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700367 dxFlags = append(dxFlags,
368 "--debug",
369 "--verbose",
370 "--dump-to="+filepath.Join(common.ModuleOutDir(ctx), "classes.lst"),
371 "--dump-width=1000")
372 }
373
374 flags.dxFlags = strings.Join(dxFlags, " ")
375
376 // Compile classes.jar into classes.dex
Colin Cross6d1e72d2015-04-10 17:44:24 -0700377 dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags)
Colin Cross2fe66872015-03-30 17:20:39 -0700378 if ctx.Failed() {
379 return
380 }
381
382 // Combine classes.dex + resources into javalib.jar
Colin Cross6d1e72d2015-04-10 17:44:24 -0700383 outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec)
Colin Cross2fe66872015-03-30 17:20:39 -0700384 }
Colin Crossb7a63242015-04-16 14:09:14 -0700385 ctx.CheckbuildFile(outputFile)
386 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700387}
388
389var _ JavaDependency = (*JavaLibrary)(nil)
390
391func (j *javaBase) ClasspathFile() string {
392 return j.classpathFile
393}
394
395func (j *javaBase) ClassJarSpecs() []jarSpec {
396 return j.classJarSpecs
397}
398
399func (j *javaBase) ResourceJarSpecs() []jarSpec {
400 return j.resourceJarSpecs
401}
402
Colin Crossc0b06f12015-04-08 13:03:43 -0700403func (j *javaBase) AidlIncludeDirs() []string {
404 return j.exportAidlIncludeDirs
405}
406
Colin Crossf05fe972015-04-10 17:45:20 -0700407var _ logtagsProducer = (*javaBase)(nil)
408
409func (j *javaBase) logtags() []string {
410 return j.logtagsSrcs
411}
412
Colin Cross2fe66872015-03-30 17:20:39 -0700413//
414// Java libraries (.jar file)
415//
416
417type JavaLibrary struct {
418 javaBase
419}
420
Colin Crossb7a63242015-04-16 14:09:14 -0700421func (j *JavaLibrary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
422 j.javaBase.GenerateJavaBuildActions(ctx)
423
424 j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.outputFile)
425}
426
Colin Cross2fe66872015-03-30 17:20:39 -0700427func JavaLibraryFactory() (blueprint.Module, []interface{}) {
428 module := &JavaLibrary{}
429
430 module.properties.Dex = true
431
432 return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported)
433}
434
435func JavaLibraryHostFactory() (blueprint.Module, []interface{}) {
436 module := &JavaLibrary{}
437
438 return NewJavaBase(&module.javaBase, module, common.HostSupported)
439}
440
441//
442// Java Binaries (.jar file plus wrapper script)
443//
444
445type JavaBinary struct {
446 JavaLibrary
447
448 binaryProperties struct {
449 // wrapper: installable script to execute the resulting jar
450 Wrapper string
451 }
452}
453
454func (j *JavaBinary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
455 j.JavaLibrary.GenerateJavaBuildActions(ctx)
456
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.
459 ctx.InstallFile("bin", filepath.Join(common.ModuleSrcDir(ctx), j.binaryProperties.Wrapper),
460 j.installFile)
461}
462
463func JavaBinaryFactory() (blueprint.Module, []interface{}) {
464 module := &JavaBinary{}
465
466 module.properties.Dex = true
467
468 return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported, &module.binaryProperties)
469}
470
471func JavaBinaryHostFactory() (blueprint.Module, []interface{}) {
472 module := &JavaBinary{}
473
474 return NewJavaBase(&module.javaBase, module, common.HostSupported, &module.binaryProperties)
475}
476
477//
478// Java prebuilts
479//
480
481type JavaPrebuilt struct {
482 common.AndroidModuleBase
483
484 properties struct {
Colin Crossaa8630b2015-04-13 13:52:22 -0700485 Srcs []string
Colin Cross2fe66872015-03-30 17:20:39 -0700486 }
487
Colin Crosse1d62a82015-04-03 16:53:05 -0700488 classpathFile string
489 classJarSpecs, resourceJarSpecs []jarSpec
Colin Cross2fe66872015-03-30 17:20:39 -0700490}
491
492func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
493 if len(j.properties.Srcs) != 1 {
494 ctx.ModuleErrorf("expected exactly one jar in srcs")
495 return
496 }
Colin Crosse1d62a82015-04-03 16:53:05 -0700497 prebuilt := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Srcs[0])
498
499 classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt)
500
501 j.classpathFile = prebuilt
502 j.classJarSpecs = []jarSpec{classJarSpec}
503 j.resourceJarSpecs = []jarSpec{resourceJarSpec}
Colin Crosse1d62a82015-04-03 16:53:05 -0700504 ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.classpathFile)
Colin Cross2fe66872015-03-30 17:20:39 -0700505}
506
507var _ JavaDependency = (*JavaPrebuilt)(nil)
508
509func (j *JavaPrebuilt) ClasspathFile() string {
510 return j.classpathFile
511}
512
513func (j *JavaPrebuilt) ClassJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700514 return j.classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700515}
516
517func (j *JavaPrebuilt) ResourceJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700518 return j.resourceJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700519}
520
Colin Crossc0b06f12015-04-08 13:03:43 -0700521func (j *JavaPrebuilt) AidlIncludeDirs() []string {
522 return nil
523}
524
Colin Cross2fe66872015-03-30 17:20:39 -0700525func JavaPrebuiltFactory() (blueprint.Module, []interface{}) {
526 module := &JavaPrebuilt{}
527
528 return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
529 common.MultilibCommon, &module.properties)
530}
531
Colin Crossaa8630b2015-04-13 13:52:22 -0700532//
533// SDK java prebuilts (.jar containing resources plus framework.aidl)
534//
535
536type sdkDependency interface {
537 JavaDependency
538 AidlPreprocessed() string
539}
540
541var _ sdkDependency = (*sdkPrebuilt)(nil)
542
543type sdkPrebuilt struct {
544 JavaPrebuilt
545
546 sdkProperties struct {
547 Aidl_preprocessed string
548 }
549
550 aidlPreprocessed string
551}
552
553func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
554 j.JavaPrebuilt.GenerateAndroidBuildActions(ctx)
555
556 if j.sdkProperties.Aidl_preprocessed != "" {
557 j.aidlPreprocessed = filepath.Join(common.ModuleSrcDir(ctx), j.sdkProperties.Aidl_preprocessed)
558 }
559}
560
561func (j *sdkPrebuilt) AidlPreprocessed() string {
562 return j.aidlPreprocessed
563}
564
565func SdkPrebuiltFactory() (blueprint.Module, []interface{}) {
566 module := &sdkPrebuilt{}
567
568 return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
569 common.MultilibCommon, &module.properties, &module.sdkProperties)
570}
571
Colin Cross2fe66872015-03-30 17:20:39 -0700572func inList(s string, l []string) bool {
573 for _, e := range l {
574 if e == s {
575 return true
576 }
577 }
578 return false
579}