blob: a16d1d67f132036b5d551ddcc972568ed95b5515 [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
Colin Cross7d5136f2015-05-11 13:39:40 -070047type javaBaseProperties struct {
48 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
49 // or .aidl files.
50 Srcs []string `android:"arch_variant,arch_subtract"`
51
52 // list of directories containing Java resources
53 Java_resource_dirs []string `android:"arch_variant"`
54
55 // don't build against the default libraries (core-libart, core-junit,
56 // ext, and framework for device targets)
57 No_standard_libraries bool
58
59 // list of module-specific flags that will be used for javac compiles
60 Javacflags []string `android:"arch_variant"`
61
62 // list of module-specific flags that will be used for jack compiles
63 Jack_flags []string `android:"arch_variant"`
64
65 // list of module-specific flags that will be used for dex compiles
66 Dxflags []string `android:"arch_variant"`
67
68 // list of of java libraries that will be in the classpath
69 Java_libs []string `android:"arch_variant"`
70
71 // list of java libraries that will be compiled into the resulting jar
72 Java_static_libs []string `android:"arch_variant"`
73
74 // manifest file to be included in resulting jar
75 Manifest string
76
77 // if not blank, set to the version of the sdk to compile against
78 Sdk_version string
79
80 // Set for device java libraries, and for host versions of device java libraries
81 // built for testing
82 Dex bool `blueprint:"mutated"`
83
84 // if not blank, run jarjar using the specified rules file
85 Jarjar_rules string
86
87 // directories to pass to aidl tool
88 Aidl_includes []string
89
90 // directories that should be added as include directories
91 // for any aidl sources of modules that depend on this module
92 Export_aidl_include_dirs []string
93}
94
Colin Cross2fe66872015-03-30 17:20:39 -070095// javaBase contains the properties and members used by all java module types, and implements
96// the blueprint.Module interface.
97type javaBase struct {
98 common.AndroidModuleBase
99 module JavaModuleType
100
Colin Cross7d5136f2015-05-11 13:39:40 -0700101 properties javaBaseProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700102
103 // output file suitable for inserting into the classpath of another compile
104 classpathFile string
105
Colin Crossb7a63242015-04-16 14:09:14 -0700106 // output file suitable for installing or running
107 outputFile string
108
Colin Cross2fe66872015-03-30 17:20:39 -0700109 // jarSpecs suitable for inserting classes from a static library into another jar
110 classJarSpecs []jarSpec
111
112 // jarSpecs suitable for inserting resources from a static library into another jar
113 resourceJarSpecs []jarSpec
114
Colin Crossc0b06f12015-04-08 13:03:43 -0700115 exportAidlIncludeDirs []string
116
Colin Crossf05fe972015-04-10 17:45:20 -0700117 logtagsSrcs []string
118
Colin Crossb7a63242015-04-16 14:09:14 -0700119 // filelists of extra source files that should be included in the javac command line,
120 // for example R.java generated by aapt for android apps
121 ExtraSrcLists []string
122
Colin Cross2fe66872015-03-30 17:20:39 -0700123 // installed file for binary dependency
124 installFile string
125}
126
127type JavaModuleType interface {
128 GenerateJavaBuildActions(ctx common.AndroidModuleContext)
Colin Crossb7a63242015-04-16 14:09:14 -0700129 JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string
Colin Cross2fe66872015-03-30 17:20:39 -0700130}
131
132type JavaDependency interface {
133 ClasspathFile() string
134 ClassJarSpecs() []jarSpec
135 ResourceJarSpecs() []jarSpec
Colin Crossc0b06f12015-04-08 13:03:43 -0700136 AidlIncludeDirs() []string
Colin Cross2fe66872015-03-30 17:20:39 -0700137}
138
139func NewJavaBase(base *javaBase, module JavaModuleType, hod common.HostOrDeviceSupported,
140 props ...interface{}) (blueprint.Module, []interface{}) {
141
142 base.module = module
143
144 props = append(props, &base.properties)
145
146 return common.InitAndroidArchModule(base, hod, common.MultilibCommon, props...)
147}
148
149func (j *javaBase) BootClasspath(ctx common.AndroidBaseContext) string {
150 if ctx.Device() {
151 if j.properties.Sdk_version == "" {
152 return "core-libart"
153 } else if j.properties.Sdk_version == "current" {
154 // TODO: !TARGET_BUILD_APPS
Colin Crossc0b06f12015-04-08 13:03:43 -0700155 // TODO: export preprocessed framework.aidl from android_stubs_current
Colin Cross2fe66872015-03-30 17:20:39 -0700156 return "android_stubs_current"
157 } else if j.properties.Sdk_version == "system_current" {
158 return "android_system_stubs_current"
159 } else {
160 return "sdk_v" + j.properties.Sdk_version
161 }
162 } else {
163 if j.properties.Dex {
164 return "core-libart"
165 } else {
166 return ""
167 }
168 }
169}
170
Colin Crossefb9ebe2015-04-16 14:08:06 -0700171var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"}
172
Colin Cross2fe66872015-03-30 17:20:39 -0700173func (j *javaBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
Colin Crossb7a63242015-04-16 14:09:14 -0700174 return j.module.JavaDynamicDependencies(ctx)
175}
176
177func (j *javaBase) JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
Colin Cross2fe66872015-03-30 17:20:39 -0700178 var deps []string
179
180 if !j.properties.No_standard_libraries {
181 bootClasspath := j.BootClasspath(ctx)
182 if bootClasspath != "" {
183 deps = append(deps, bootClasspath)
184 }
Colin Crossefb9ebe2015-04-16 14:08:06 -0700185 if ctx.Device() && j.properties.Sdk_version == "" {
186 deps = append(deps, defaultJavaLibraries...)
187 }
Colin Cross2fe66872015-03-30 17:20:39 -0700188 }
189 deps = append(deps, j.properties.Java_libs...)
190 deps = append(deps, j.properties.Java_static_libs...)
191
192 return deps
193}
194
Colin Crossc0b06f12015-04-08 13:03:43 -0700195func (j *javaBase) aidlFlags(ctx common.AndroidModuleContext, aidlPreprocess string,
Colin Crossf03c82b2015-04-13 13:53:40 -0700196 aidlIncludeDirs []string) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700197
198 localAidlIncludes := pathtools.PrefixPaths(j.properties.Aidl_includes, common.ModuleSrcDir(ctx))
199
200 var flags []string
201 if aidlPreprocess != "" {
202 flags = append(flags, "-p"+aidlPreprocess)
203 } else {
204 flags = append(flags, common.JoinWithPrefix(aidlIncludeDirs, "-I"))
205 }
206
207 flags = append(flags, common.JoinWithPrefix(j.exportAidlIncludeDirs, "-I"))
208 flags = append(flags, common.JoinWithPrefix(localAidlIncludes, "-I"))
209 flags = append(flags, "-I"+common.ModuleSrcDir(ctx))
210 flags = append(flags, "-I"+filepath.Join(common.ModuleSrcDir(ctx), "src"))
211
Colin Crossf03c82b2015-04-13 13:53:40 -0700212 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700213}
214
Colin Cross2fe66872015-03-30 17:20:39 -0700215func (j *javaBase) collectDeps(ctx common.AndroidModuleContext) (classpath []string,
Colin Crossc0b06f12015-04-08 13:03:43 -0700216 bootClasspath string, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess string,
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700217 aidlIncludeDirs []string, srcFileLists []string) {
Colin Cross2fe66872015-03-30 17:20:39 -0700218
219 ctx.VisitDirectDeps(func(module blueprint.Module) {
220 otherName := ctx.OtherModuleName(module)
221 if javaDep, ok := module.(JavaDependency); ok {
Colin Cross6cbb1272015-04-08 11:23:01 -0700222 if otherName == j.BootClasspath(ctx) {
223 bootClasspath = javaDep.ClasspathFile()
Colin Crossb7a63242015-04-16 14:09:14 -0700224 } else if inList(otherName, defaultJavaLibraries) {
225 classpath = append(classpath, javaDep.ClasspathFile())
Colin Cross6cbb1272015-04-08 11:23:01 -0700226 } else if inList(otherName, j.properties.Java_libs) {
Colin Cross2fe66872015-03-30 17:20:39 -0700227 classpath = append(classpath, javaDep.ClasspathFile())
228 } else if inList(otherName, j.properties.Java_static_libs) {
229 classpath = append(classpath, javaDep.ClasspathFile())
230 classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...)
231 resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...)
Colin Crossb7a63242015-04-16 14:09:14 -0700232 } else if otherName == "framework-res" {
233 if ctx.ModuleName() == "framework" {
234 // framework.jar has a one-off dependency on the R.java and Manifest.java files
235 // generated by framework-res.apk
236 srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).aaptJavaFileList)
237 }
Colin Cross2fe66872015-03-30 17:20:39 -0700238 } else {
239 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
240 }
Colin Crossaa8630b2015-04-13 13:52:22 -0700241 aidlIncludeDirs = append(aidlIncludeDirs, javaDep.AidlIncludeDirs()...)
242 if sdkDep, ok := module.(sdkDependency); ok {
243 if sdkDep.AidlPreprocessed() != "" {
244 if aidlPreprocess != "" {
245 ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q",
246 aidlPreprocess, sdkDep.AidlPreprocessed())
247 } else {
248 aidlPreprocess = sdkDep.AidlPreprocessed()
249 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700250 }
251 }
Colin Cross2fe66872015-03-30 17:20:39 -0700252 }
253 })
254
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700255 return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
256 aidlIncludeDirs, srcFileLists
Colin Cross2fe66872015-03-30 17:20:39 -0700257}
258
259func (j *javaBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
260 j.module.GenerateJavaBuildActions(ctx)
261}
262
263func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700264
265 j.exportAidlIncludeDirs = pathtools.PrefixPaths(j.properties.Export_aidl_include_dirs,
266 common.ModuleSrcDir(ctx))
267
268 classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700269 aidlIncludeDirs, srcFileLists := j.collectDeps(ctx)
Colin Crossc0b06f12015-04-08 13:03:43 -0700270
Colin Crossf03c82b2015-04-13 13:53:40 -0700271 var flags javaBuilderFlags
272
273 javacFlags := j.properties.Javacflags
274 if len(javacFlags) > 0 {
275 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
276 flags.javacFlags = "$javacFlags"
277 }
278
279 aidlFlags := j.aidlFlags(ctx, aidlPreprocess, aidlIncludeDirs)
280 if len(aidlFlags) > 0 {
281 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
282 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700283 }
284
285 var javacDeps []string
286
Colin Cross2fe66872015-03-30 17:20:39 -0700287 if bootClasspath != "" {
288 flags.bootClasspath = "-bootclasspath " + bootClasspath
289 javacDeps = append(javacDeps, bootClasspath)
290 }
291
292 if len(classpath) > 0 {
293 flags.classpath = "-classpath " + strings.Join(classpath, ":")
294 javacDeps = append(javacDeps, classpath...)
295 }
296
Colin Cross8f101b42015-06-17 15:09:06 -0700297 srcFiles := ctx.ExpandSources(j.properties.Srcs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700298
Colin Crossf05fe972015-04-10 17:45:20 -0700299 srcFiles = j.genSources(ctx, srcFiles, flags)
Colin Crossc0b06f12015-04-08 13:03:43 -0700300
Colin Cross0607cf72015-04-28 13:28:51 -0700301 ctx.VisitDirectDeps(func(module blueprint.Module) {
302 if gen, ok := module.(genrule.SourceFileGenerator); ok {
303 srcFiles = append(srcFiles, gen.GeneratedSourceFiles()...)
304 }
305 })
306
Colin Crossb7a63242015-04-16 14:09:14 -0700307 srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
308
Colin Cross8cf13342015-04-10 15:41:49 -0700309 if len(srcFiles) > 0 {
310 // Compile java sources into .class files
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700311 classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, javacDeps)
Colin Cross8cf13342015-04-10 15:41:49 -0700312 if ctx.Failed() {
313 return
314 }
315
316 classJarSpecs = append([]jarSpec{classes}, classJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700317 }
318
Colin Cross276284f2015-04-20 13:51:48 -0700319 resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Java_resource_dirs),
320 resourceJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700321
322 manifest := j.properties.Manifest
323 if manifest != "" {
324 manifest = filepath.Join(common.ModuleSrcDir(ctx), manifest)
325 }
326
327 allJarSpecs := append([]jarSpec(nil), classJarSpecs...)
328 allJarSpecs = append(allJarSpecs, resourceJarSpecs...)
329
330 // Combine classes + resources into classes-full-debug.jar
331 outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest)
332 if ctx.Failed() {
333 return
334 }
Colin Cross65bf4f22015-04-03 16:54:17 -0700335
Colin Cross65bf4f22015-04-03 16:54:17 -0700336 if j.properties.Jarjar_rules != "" {
337 jarjar_rules := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Jarjar_rules)
338 // Transform classes-full-debug.jar into classes-jarjar.jar
339 outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
340 if ctx.Failed() {
341 return
342 }
Colin Cross20978302015-04-10 17:05:07 -0700343
344 classes, _ := TransformPrebuiltJarToClasses(ctx, outputFile)
345 classJarSpecs = []jarSpec{classes}
Colin Cross65bf4f22015-04-03 16:54:17 -0700346 }
347
Colin Cross20978302015-04-10 17:05:07 -0700348 j.resourceJarSpecs = resourceJarSpecs
349 j.classJarSpecs = classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700350 j.classpathFile = outputFile
351
Colin Cross8cf13342015-04-10 15:41:49 -0700352 if j.properties.Dex && len(srcFiles) > 0 {
Colin Cross2fe66872015-03-30 17:20:39 -0700353 dxFlags := j.properties.Dxflags
354 if false /* emma enabled */ {
355 // If you instrument class files that have local variable debug information in
356 // them emma does not correctly maintain the local variable table.
357 // This will cause an error when you try to convert the class files for Android.
358 // The workaround here is to build different dex file here based on emma switch
359 // then later copy into classes.dex. When emma is on, dx is run with --no-locals
360 // option to remove local variable information
361 dxFlags = append(dxFlags, "--no-locals")
362 }
363
Colin Cross1332b002015-04-07 17:11:30 -0700364 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700365 dxFlags = append(dxFlags, "--no-optimize")
366 }
367
Colin Cross1332b002015-04-07 17:11:30 -0700368 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700369 dxFlags = append(dxFlags,
370 "--debug",
371 "--verbose",
372 "--dump-to="+filepath.Join(common.ModuleOutDir(ctx), "classes.lst"),
373 "--dump-width=1000")
374 }
375
376 flags.dxFlags = strings.Join(dxFlags, " ")
377
378 // Compile classes.jar into classes.dex
Colin Cross6d1e72d2015-04-10 17:44:24 -0700379 dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags)
Colin Cross2fe66872015-03-30 17:20:39 -0700380 if ctx.Failed() {
381 return
382 }
383
384 // Combine classes.dex + resources into javalib.jar
Colin Cross6d1e72d2015-04-10 17:44:24 -0700385 outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec)
Colin Cross2fe66872015-03-30 17:20:39 -0700386 }
Colin Crossb7a63242015-04-16 14:09:14 -0700387 ctx.CheckbuildFile(outputFile)
388 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700389}
390
391var _ JavaDependency = (*JavaLibrary)(nil)
392
393func (j *javaBase) ClasspathFile() string {
394 return j.classpathFile
395}
396
397func (j *javaBase) ClassJarSpecs() []jarSpec {
398 return j.classJarSpecs
399}
400
401func (j *javaBase) ResourceJarSpecs() []jarSpec {
402 return j.resourceJarSpecs
403}
404
Colin Crossc0b06f12015-04-08 13:03:43 -0700405func (j *javaBase) AidlIncludeDirs() []string {
406 return j.exportAidlIncludeDirs
407}
408
Colin Crossf05fe972015-04-10 17:45:20 -0700409var _ logtagsProducer = (*javaBase)(nil)
410
411func (j *javaBase) logtags() []string {
412 return j.logtagsSrcs
413}
414
Colin Cross2fe66872015-03-30 17:20:39 -0700415//
416// Java libraries (.jar file)
417//
418
419type JavaLibrary struct {
420 javaBase
421}
422
Colin Crossb7a63242015-04-16 14:09:14 -0700423func (j *JavaLibrary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
424 j.javaBase.GenerateJavaBuildActions(ctx)
425
426 j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.outputFile)
427}
428
Colin Cross2fe66872015-03-30 17:20:39 -0700429func JavaLibraryFactory() (blueprint.Module, []interface{}) {
430 module := &JavaLibrary{}
431
432 module.properties.Dex = true
433
434 return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported)
435}
436
437func JavaLibraryHostFactory() (blueprint.Module, []interface{}) {
438 module := &JavaLibrary{}
439
440 return NewJavaBase(&module.javaBase, module, common.HostSupported)
441}
442
443//
444// Java Binaries (.jar file plus wrapper script)
445//
446
Colin Cross7d5136f2015-05-11 13:39:40 -0700447type javaBinaryProperties struct {
448 // installable script to execute the resulting jar
449 Wrapper string
450}
451
Colin Cross2fe66872015-03-30 17:20:39 -0700452type JavaBinary struct {
453 JavaLibrary
454
Colin Cross7d5136f2015-05-11 13:39:40 -0700455 binaryProperties javaBinaryProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700456}
457
458func (j *JavaBinary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
459 j.JavaLibrary.GenerateJavaBuildActions(ctx)
460
461 // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
462 // another build rule before the jar has been installed.
463 ctx.InstallFile("bin", filepath.Join(common.ModuleSrcDir(ctx), j.binaryProperties.Wrapper),
464 j.installFile)
465}
466
467func JavaBinaryFactory() (blueprint.Module, []interface{}) {
468 module := &JavaBinary{}
469
470 module.properties.Dex = true
471
472 return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported, &module.binaryProperties)
473}
474
475func JavaBinaryHostFactory() (blueprint.Module, []interface{}) {
476 module := &JavaBinary{}
477
478 return NewJavaBase(&module.javaBase, module, common.HostSupported, &module.binaryProperties)
479}
480
481//
482// Java prebuilts
483//
484
Colin Cross7d5136f2015-05-11 13:39:40 -0700485type javaPrebuiltProperties struct {
486 Srcs []string
487}
488
Colin Cross2fe66872015-03-30 17:20:39 -0700489type JavaPrebuilt struct {
490 common.AndroidModuleBase
491
Colin Cross7d5136f2015-05-11 13:39:40 -0700492 properties javaPrebuiltProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700493
Colin Crosse1d62a82015-04-03 16:53:05 -0700494 classpathFile string
495 classJarSpecs, resourceJarSpecs []jarSpec
Colin Cross2fe66872015-03-30 17:20:39 -0700496}
497
498func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
499 if len(j.properties.Srcs) != 1 {
500 ctx.ModuleErrorf("expected exactly one jar in srcs")
501 return
502 }
Colin Crosse1d62a82015-04-03 16:53:05 -0700503 prebuilt := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Srcs[0])
504
505 classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt)
506
507 j.classpathFile = prebuilt
508 j.classJarSpecs = []jarSpec{classJarSpec}
509 j.resourceJarSpecs = []jarSpec{resourceJarSpec}
Colin Crosse1d62a82015-04-03 16:53:05 -0700510 ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.classpathFile)
Colin Cross2fe66872015-03-30 17:20:39 -0700511}
512
513var _ JavaDependency = (*JavaPrebuilt)(nil)
514
515func (j *JavaPrebuilt) ClasspathFile() string {
516 return j.classpathFile
517}
518
519func (j *JavaPrebuilt) ClassJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700520 return j.classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700521}
522
523func (j *JavaPrebuilt) ResourceJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700524 return j.resourceJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700525}
526
Colin Crossc0b06f12015-04-08 13:03:43 -0700527func (j *JavaPrebuilt) AidlIncludeDirs() []string {
528 return nil
529}
530
Colin Cross2fe66872015-03-30 17:20:39 -0700531func JavaPrebuiltFactory() (blueprint.Module, []interface{}) {
532 module := &JavaPrebuilt{}
533
534 return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
535 common.MultilibCommon, &module.properties)
536}
537
Colin Crossaa8630b2015-04-13 13:52:22 -0700538//
539// SDK java prebuilts (.jar containing resources plus framework.aidl)
540//
541
542type sdkDependency interface {
543 JavaDependency
544 AidlPreprocessed() string
545}
546
547var _ sdkDependency = (*sdkPrebuilt)(nil)
548
Colin Cross7d5136f2015-05-11 13:39:40 -0700549type sdkPrebuiltProperties struct {
550 Aidl_preprocessed string
551}
552
Colin Crossaa8630b2015-04-13 13:52:22 -0700553type sdkPrebuilt struct {
554 JavaPrebuilt
555
Colin Cross7d5136f2015-05-11 13:39:40 -0700556 sdkProperties sdkPrebuiltProperties
Colin Crossaa8630b2015-04-13 13:52:22 -0700557
558 aidlPreprocessed string
559}
560
561func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
562 j.JavaPrebuilt.GenerateAndroidBuildActions(ctx)
563
564 if j.sdkProperties.Aidl_preprocessed != "" {
565 j.aidlPreprocessed = filepath.Join(common.ModuleSrcDir(ctx), j.sdkProperties.Aidl_preprocessed)
566 }
567}
568
569func (j *sdkPrebuilt) AidlPreprocessed() string {
570 return j.aidlPreprocessed
571}
572
573func SdkPrebuiltFactory() (blueprint.Module, []interface{}) {
574 module := &sdkPrebuilt{}
575
576 return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
577 common.MultilibCommon, &module.properties, &module.sdkProperties)
578}
579
Colin Cross2fe66872015-03-30 17:20:39 -0700580func inList(s string, l []string) bool {
581 for _, e := range l {
582 if e == s {
583 return true
584 }
585 }
586 return false
587}