blob: 94f6914ed47a9b8f52d8ebacce3895cd82fe09d7 [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.
Dan Willemsen2ef08f42015-06-30 18:15:24 -070050 Srcs []string `android:"arch_variant"`
51
52 // list of source files that should not be used to build the Java module.
53 // This is most useful in the arch/multilib variants to remove non-common files
54 Exclude_srcs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070055
56 // list of directories containing Java resources
57 Java_resource_dirs []string `android:"arch_variant"`
58
Dan Willemsen2ef08f42015-06-30 18:15:24 -070059 // list of directories that should be excluded from java_resource_dirs
60 Exclude_java_resource_dirs []string `android:"arch_variant"`
61
Colin Cross7d5136f2015-05-11 13:39:40 -070062 // don't build against the default libraries (core-libart, core-junit,
63 // ext, and framework for device targets)
64 No_standard_libraries bool
65
66 // list of module-specific flags that will be used for javac compiles
67 Javacflags []string `android:"arch_variant"`
68
69 // list of module-specific flags that will be used for jack compiles
70 Jack_flags []string `android:"arch_variant"`
71
72 // list of module-specific flags that will be used for dex compiles
73 Dxflags []string `android:"arch_variant"`
74
75 // list of of java libraries that will be in the classpath
76 Java_libs []string `android:"arch_variant"`
77
78 // list of java libraries that will be compiled into the resulting jar
79 Java_static_libs []string `android:"arch_variant"`
80
81 // manifest file to be included in resulting jar
82 Manifest string
83
84 // if not blank, set to the version of the sdk to compile against
85 Sdk_version string
86
87 // Set for device java libraries, and for host versions of device java libraries
88 // built for testing
89 Dex bool `blueprint:"mutated"`
90
91 // if not blank, run jarjar using the specified rules file
92 Jarjar_rules string
93
94 // directories to pass to aidl tool
95 Aidl_includes []string
96
97 // directories that should be added as include directories
98 // for any aidl sources of modules that depend on this module
99 Export_aidl_include_dirs []string
100}
101
Colin Cross2fe66872015-03-30 17:20:39 -0700102// javaBase contains the properties and members used by all java module types, and implements
103// the blueprint.Module interface.
104type javaBase struct {
105 common.AndroidModuleBase
106 module JavaModuleType
107
Colin Cross7d5136f2015-05-11 13:39:40 -0700108 properties javaBaseProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700109
110 // output file suitable for inserting into the classpath of another compile
111 classpathFile string
112
Colin Crossb7a63242015-04-16 14:09:14 -0700113 // output file suitable for installing or running
114 outputFile string
115
Colin Cross2fe66872015-03-30 17:20:39 -0700116 // jarSpecs suitable for inserting classes from a static library into another jar
117 classJarSpecs []jarSpec
118
119 // jarSpecs suitable for inserting resources from a static library into another jar
120 resourceJarSpecs []jarSpec
121
Colin Crossc0b06f12015-04-08 13:03:43 -0700122 exportAidlIncludeDirs []string
123
Colin Crossf05fe972015-04-10 17:45:20 -0700124 logtagsSrcs []string
125
Colin Crossb7a63242015-04-16 14:09:14 -0700126 // filelists of extra source files that should be included in the javac command line,
127 // for example R.java generated by aapt for android apps
128 ExtraSrcLists []string
129
Colin Cross2fe66872015-03-30 17:20:39 -0700130 // installed file for binary dependency
131 installFile string
132}
133
134type JavaModuleType interface {
135 GenerateJavaBuildActions(ctx common.AndroidModuleContext)
Colin Crossb7a63242015-04-16 14:09:14 -0700136 JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string
Colin Cross2fe66872015-03-30 17:20:39 -0700137}
138
139type JavaDependency interface {
140 ClasspathFile() string
141 ClassJarSpecs() []jarSpec
142 ResourceJarSpecs() []jarSpec
Colin Crossc0b06f12015-04-08 13:03:43 -0700143 AidlIncludeDirs() []string
Colin Cross2fe66872015-03-30 17:20:39 -0700144}
145
146func NewJavaBase(base *javaBase, module JavaModuleType, hod common.HostOrDeviceSupported,
147 props ...interface{}) (blueprint.Module, []interface{}) {
148
149 base.module = module
150
151 props = append(props, &base.properties)
152
153 return common.InitAndroidArchModule(base, hod, common.MultilibCommon, props...)
154}
155
156func (j *javaBase) BootClasspath(ctx common.AndroidBaseContext) string {
157 if ctx.Device() {
158 if j.properties.Sdk_version == "" {
159 return "core-libart"
160 } else if j.properties.Sdk_version == "current" {
161 // TODO: !TARGET_BUILD_APPS
Colin Crossc0b06f12015-04-08 13:03:43 -0700162 // TODO: export preprocessed framework.aidl from android_stubs_current
Colin Cross2fe66872015-03-30 17:20:39 -0700163 return "android_stubs_current"
164 } else if j.properties.Sdk_version == "system_current" {
165 return "android_system_stubs_current"
166 } else {
167 return "sdk_v" + j.properties.Sdk_version
168 }
169 } else {
170 if j.properties.Dex {
171 return "core-libart"
172 } else {
173 return ""
174 }
175 }
176}
177
Colin Crossefb9ebe2015-04-16 14:08:06 -0700178var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"}
179
Colin Cross2fe66872015-03-30 17:20:39 -0700180func (j *javaBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
Colin Crossb7a63242015-04-16 14:09:14 -0700181 return j.module.JavaDynamicDependencies(ctx)
182}
183
184func (j *javaBase) JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
Colin Cross2fe66872015-03-30 17:20:39 -0700185 var deps []string
186
187 if !j.properties.No_standard_libraries {
188 bootClasspath := j.BootClasspath(ctx)
189 if bootClasspath != "" {
190 deps = append(deps, bootClasspath)
191 }
Colin Crossefb9ebe2015-04-16 14:08:06 -0700192 if ctx.Device() && j.properties.Sdk_version == "" {
193 deps = append(deps, defaultJavaLibraries...)
194 }
Colin Cross2fe66872015-03-30 17:20:39 -0700195 }
196 deps = append(deps, j.properties.Java_libs...)
197 deps = append(deps, j.properties.Java_static_libs...)
198
199 return deps
200}
201
Colin Crossc0b06f12015-04-08 13:03:43 -0700202func (j *javaBase) aidlFlags(ctx common.AndroidModuleContext, aidlPreprocess string,
Colin Crossf03c82b2015-04-13 13:53:40 -0700203 aidlIncludeDirs []string) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700204
205 localAidlIncludes := pathtools.PrefixPaths(j.properties.Aidl_includes, common.ModuleSrcDir(ctx))
206
207 var flags []string
208 if aidlPreprocess != "" {
209 flags = append(flags, "-p"+aidlPreprocess)
210 } else {
211 flags = append(flags, common.JoinWithPrefix(aidlIncludeDirs, "-I"))
212 }
213
214 flags = append(flags, common.JoinWithPrefix(j.exportAidlIncludeDirs, "-I"))
215 flags = append(flags, common.JoinWithPrefix(localAidlIncludes, "-I"))
216 flags = append(flags, "-I"+common.ModuleSrcDir(ctx))
217 flags = append(flags, "-I"+filepath.Join(common.ModuleSrcDir(ctx), "src"))
218
Colin Crossf03c82b2015-04-13 13:53:40 -0700219 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700220}
221
Colin Cross2fe66872015-03-30 17:20:39 -0700222func (j *javaBase) collectDeps(ctx common.AndroidModuleContext) (classpath []string,
Colin Crossc0b06f12015-04-08 13:03:43 -0700223 bootClasspath string, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess string,
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700224 aidlIncludeDirs []string, srcFileLists []string) {
Colin Cross2fe66872015-03-30 17:20:39 -0700225
226 ctx.VisitDirectDeps(func(module blueprint.Module) {
227 otherName := ctx.OtherModuleName(module)
228 if javaDep, ok := module.(JavaDependency); ok {
Colin Cross6cbb1272015-04-08 11:23:01 -0700229 if otherName == j.BootClasspath(ctx) {
230 bootClasspath = javaDep.ClasspathFile()
Colin Crossb7a63242015-04-16 14:09:14 -0700231 } else if inList(otherName, defaultJavaLibraries) {
232 classpath = append(classpath, javaDep.ClasspathFile())
Colin Cross6cbb1272015-04-08 11:23:01 -0700233 } else if inList(otherName, j.properties.Java_libs) {
Colin Cross2fe66872015-03-30 17:20:39 -0700234 classpath = append(classpath, javaDep.ClasspathFile())
235 } else if inList(otherName, j.properties.Java_static_libs) {
236 classpath = append(classpath, javaDep.ClasspathFile())
237 classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...)
238 resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...)
Colin Crossb7a63242015-04-16 14:09:14 -0700239 } else if otherName == "framework-res" {
240 if ctx.ModuleName() == "framework" {
241 // framework.jar has a one-off dependency on the R.java and Manifest.java files
242 // generated by framework-res.apk
243 srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).aaptJavaFileList)
244 }
Colin Cross2fe66872015-03-30 17:20:39 -0700245 } else {
246 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
247 }
Colin Crossaa8630b2015-04-13 13:52:22 -0700248 aidlIncludeDirs = append(aidlIncludeDirs, javaDep.AidlIncludeDirs()...)
249 if sdkDep, ok := module.(sdkDependency); ok {
250 if sdkDep.AidlPreprocessed() != "" {
251 if aidlPreprocess != "" {
252 ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q",
253 aidlPreprocess, sdkDep.AidlPreprocessed())
254 } else {
255 aidlPreprocess = sdkDep.AidlPreprocessed()
256 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700257 }
258 }
Colin Cross2fe66872015-03-30 17:20:39 -0700259 }
260 })
261
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700262 return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
263 aidlIncludeDirs, srcFileLists
Colin Cross2fe66872015-03-30 17:20:39 -0700264}
265
266func (j *javaBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
267 j.module.GenerateJavaBuildActions(ctx)
268}
269
270func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700271
272 j.exportAidlIncludeDirs = pathtools.PrefixPaths(j.properties.Export_aidl_include_dirs,
273 common.ModuleSrcDir(ctx))
274
275 classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700276 aidlIncludeDirs, srcFileLists := j.collectDeps(ctx)
Colin Crossc0b06f12015-04-08 13:03:43 -0700277
Colin Crossf03c82b2015-04-13 13:53:40 -0700278 var flags javaBuilderFlags
279
280 javacFlags := j.properties.Javacflags
281 if len(javacFlags) > 0 {
282 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
283 flags.javacFlags = "$javacFlags"
284 }
285
286 aidlFlags := j.aidlFlags(ctx, aidlPreprocess, aidlIncludeDirs)
287 if len(aidlFlags) > 0 {
288 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
289 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700290 }
291
292 var javacDeps []string
293
Colin Cross2fe66872015-03-30 17:20:39 -0700294 if bootClasspath != "" {
295 flags.bootClasspath = "-bootclasspath " + bootClasspath
296 javacDeps = append(javacDeps, bootClasspath)
297 }
298
299 if len(classpath) > 0 {
300 flags.classpath = "-classpath " + strings.Join(classpath, ":")
301 javacDeps = append(javacDeps, classpath...)
302 }
303
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700304 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Crossc0b06f12015-04-08 13:03:43 -0700305
Colin Crossf05fe972015-04-10 17:45:20 -0700306 srcFiles = j.genSources(ctx, srcFiles, flags)
Colin Crossc0b06f12015-04-08 13:03:43 -0700307
Colin Cross0607cf72015-04-28 13:28:51 -0700308 ctx.VisitDirectDeps(func(module blueprint.Module) {
309 if gen, ok := module.(genrule.SourceFileGenerator); ok {
310 srcFiles = append(srcFiles, gen.GeneratedSourceFiles()...)
311 }
312 })
313
Colin Crossb7a63242015-04-16 14:09:14 -0700314 srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
315
Colin Cross8cf13342015-04-10 15:41:49 -0700316 if len(srcFiles) > 0 {
317 // Compile java sources into .class files
Colin Crosse7a9f3f2015-04-13 14:02:52 -0700318 classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, javacDeps)
Colin Cross8cf13342015-04-10 15:41:49 -0700319 if ctx.Failed() {
320 return
321 }
322
323 classJarSpecs = append([]jarSpec{classes}, classJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700324 }
325
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700326 resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs),
Colin Cross276284f2015-04-20 13:51:48 -0700327 resourceJarSpecs...)
Colin Cross2fe66872015-03-30 17:20:39 -0700328
329 manifest := j.properties.Manifest
330 if manifest != "" {
331 manifest = filepath.Join(common.ModuleSrcDir(ctx), manifest)
332 }
333
334 allJarSpecs := append([]jarSpec(nil), classJarSpecs...)
335 allJarSpecs = append(allJarSpecs, resourceJarSpecs...)
336
337 // Combine classes + resources into classes-full-debug.jar
338 outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest)
339 if ctx.Failed() {
340 return
341 }
Colin Cross65bf4f22015-04-03 16:54:17 -0700342
Colin Cross65bf4f22015-04-03 16:54:17 -0700343 if j.properties.Jarjar_rules != "" {
344 jarjar_rules := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Jarjar_rules)
345 // Transform classes-full-debug.jar into classes-jarjar.jar
346 outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
347 if ctx.Failed() {
348 return
349 }
Colin Cross20978302015-04-10 17:05:07 -0700350
351 classes, _ := TransformPrebuiltJarToClasses(ctx, outputFile)
352 classJarSpecs = []jarSpec{classes}
Colin Cross65bf4f22015-04-03 16:54:17 -0700353 }
354
Colin Cross20978302015-04-10 17:05:07 -0700355 j.resourceJarSpecs = resourceJarSpecs
356 j.classJarSpecs = classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700357 j.classpathFile = outputFile
358
Colin Cross8cf13342015-04-10 15:41:49 -0700359 if j.properties.Dex && len(srcFiles) > 0 {
Colin Cross2fe66872015-03-30 17:20:39 -0700360 dxFlags := j.properties.Dxflags
361 if false /* emma enabled */ {
362 // If you instrument class files that have local variable debug information in
363 // them emma does not correctly maintain the local variable table.
364 // This will cause an error when you try to convert the class files for Android.
365 // The workaround here is to build different dex file here based on emma switch
366 // then later copy into classes.dex. When emma is on, dx is run with --no-locals
367 // option to remove local variable information
368 dxFlags = append(dxFlags, "--no-locals")
369 }
370
Colin Cross1332b002015-04-07 17:11:30 -0700371 if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700372 dxFlags = append(dxFlags, "--no-optimize")
373 }
374
Colin Cross1332b002015-04-07 17:11:30 -0700375 if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
Colin Cross2fe66872015-03-30 17:20:39 -0700376 dxFlags = append(dxFlags,
377 "--debug",
378 "--verbose",
379 "--dump-to="+filepath.Join(common.ModuleOutDir(ctx), "classes.lst"),
380 "--dump-width=1000")
381 }
382
383 flags.dxFlags = strings.Join(dxFlags, " ")
384
385 // Compile classes.jar into classes.dex
Colin Cross6d1e72d2015-04-10 17:44:24 -0700386 dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags)
Colin Cross2fe66872015-03-30 17:20:39 -0700387 if ctx.Failed() {
388 return
389 }
390
391 // Combine classes.dex + resources into javalib.jar
Colin Cross6d1e72d2015-04-10 17:44:24 -0700392 outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec)
Colin Cross2fe66872015-03-30 17:20:39 -0700393 }
Colin Crossb7a63242015-04-16 14:09:14 -0700394 ctx.CheckbuildFile(outputFile)
395 j.outputFile = outputFile
Colin Cross2fe66872015-03-30 17:20:39 -0700396}
397
398var _ JavaDependency = (*JavaLibrary)(nil)
399
400func (j *javaBase) ClasspathFile() string {
401 return j.classpathFile
402}
403
404func (j *javaBase) ClassJarSpecs() []jarSpec {
405 return j.classJarSpecs
406}
407
408func (j *javaBase) ResourceJarSpecs() []jarSpec {
409 return j.resourceJarSpecs
410}
411
Colin Crossc0b06f12015-04-08 13:03:43 -0700412func (j *javaBase) AidlIncludeDirs() []string {
413 return j.exportAidlIncludeDirs
414}
415
Colin Crossf05fe972015-04-10 17:45:20 -0700416var _ logtagsProducer = (*javaBase)(nil)
417
418func (j *javaBase) logtags() []string {
419 return j.logtagsSrcs
420}
421
Colin Cross2fe66872015-03-30 17:20:39 -0700422//
423// Java libraries (.jar file)
424//
425
426type JavaLibrary struct {
427 javaBase
428}
429
Colin Crossb7a63242015-04-16 14:09:14 -0700430func (j *JavaLibrary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
431 j.javaBase.GenerateJavaBuildActions(ctx)
432
433 j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.outputFile)
434}
435
Colin Cross2fe66872015-03-30 17:20:39 -0700436func JavaLibraryFactory() (blueprint.Module, []interface{}) {
437 module := &JavaLibrary{}
438
439 module.properties.Dex = true
440
441 return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported)
442}
443
444func JavaLibraryHostFactory() (blueprint.Module, []interface{}) {
445 module := &JavaLibrary{}
446
447 return NewJavaBase(&module.javaBase, module, common.HostSupported)
448}
449
450//
451// Java Binaries (.jar file plus wrapper script)
452//
453
Colin Cross7d5136f2015-05-11 13:39:40 -0700454type javaBinaryProperties struct {
455 // installable script to execute the resulting jar
456 Wrapper string
457}
458
Colin Cross2fe66872015-03-30 17:20:39 -0700459type JavaBinary struct {
460 JavaLibrary
461
Colin Cross7d5136f2015-05-11 13:39:40 -0700462 binaryProperties javaBinaryProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700463}
464
465func (j *JavaBinary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
466 j.JavaLibrary.GenerateJavaBuildActions(ctx)
467
468 // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
469 // another build rule before the jar has been installed.
470 ctx.InstallFile("bin", filepath.Join(common.ModuleSrcDir(ctx), j.binaryProperties.Wrapper),
471 j.installFile)
472}
473
474func JavaBinaryFactory() (blueprint.Module, []interface{}) {
475 module := &JavaBinary{}
476
477 module.properties.Dex = true
478
479 return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported, &module.binaryProperties)
480}
481
482func JavaBinaryHostFactory() (blueprint.Module, []interface{}) {
483 module := &JavaBinary{}
484
485 return NewJavaBase(&module.javaBase, module, common.HostSupported, &module.binaryProperties)
486}
487
488//
489// Java prebuilts
490//
491
Colin Cross7d5136f2015-05-11 13:39:40 -0700492type javaPrebuiltProperties struct {
493 Srcs []string
494}
495
Colin Cross2fe66872015-03-30 17:20:39 -0700496type JavaPrebuilt struct {
497 common.AndroidModuleBase
498
Colin Cross7d5136f2015-05-11 13:39:40 -0700499 properties javaPrebuiltProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700500
Colin Crosse1d62a82015-04-03 16:53:05 -0700501 classpathFile string
502 classJarSpecs, resourceJarSpecs []jarSpec
Colin Cross2fe66872015-03-30 17:20:39 -0700503}
504
505func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
506 if len(j.properties.Srcs) != 1 {
507 ctx.ModuleErrorf("expected exactly one jar in srcs")
508 return
509 }
Colin Crosse1d62a82015-04-03 16:53:05 -0700510 prebuilt := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Srcs[0])
511
512 classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt)
513
514 j.classpathFile = prebuilt
515 j.classJarSpecs = []jarSpec{classJarSpec}
516 j.resourceJarSpecs = []jarSpec{resourceJarSpec}
Colin Crosse1d62a82015-04-03 16:53:05 -0700517 ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.classpathFile)
Colin Cross2fe66872015-03-30 17:20:39 -0700518}
519
520var _ JavaDependency = (*JavaPrebuilt)(nil)
521
522func (j *JavaPrebuilt) ClasspathFile() string {
523 return j.classpathFile
524}
525
526func (j *JavaPrebuilt) ClassJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700527 return j.classJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700528}
529
530func (j *JavaPrebuilt) ResourceJarSpecs() []jarSpec {
Colin Crosse1d62a82015-04-03 16:53:05 -0700531 return j.resourceJarSpecs
Colin Cross2fe66872015-03-30 17:20:39 -0700532}
533
Colin Crossc0b06f12015-04-08 13:03:43 -0700534func (j *JavaPrebuilt) AidlIncludeDirs() []string {
535 return nil
536}
537
Colin Cross2fe66872015-03-30 17:20:39 -0700538func JavaPrebuiltFactory() (blueprint.Module, []interface{}) {
539 module := &JavaPrebuilt{}
540
541 return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
542 common.MultilibCommon, &module.properties)
543}
544
Colin Crossaa8630b2015-04-13 13:52:22 -0700545//
546// SDK java prebuilts (.jar containing resources plus framework.aidl)
547//
548
549type sdkDependency interface {
550 JavaDependency
551 AidlPreprocessed() string
552}
553
554var _ sdkDependency = (*sdkPrebuilt)(nil)
555
Colin Cross7d5136f2015-05-11 13:39:40 -0700556type sdkPrebuiltProperties struct {
557 Aidl_preprocessed string
558}
559
Colin Crossaa8630b2015-04-13 13:52:22 -0700560type sdkPrebuilt struct {
561 JavaPrebuilt
562
Colin Cross7d5136f2015-05-11 13:39:40 -0700563 sdkProperties sdkPrebuiltProperties
Colin Crossaa8630b2015-04-13 13:52:22 -0700564
565 aidlPreprocessed string
566}
567
568func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
569 j.JavaPrebuilt.GenerateAndroidBuildActions(ctx)
570
571 if j.sdkProperties.Aidl_preprocessed != "" {
572 j.aidlPreprocessed = filepath.Join(common.ModuleSrcDir(ctx), j.sdkProperties.Aidl_preprocessed)
573 }
574}
575
576func (j *sdkPrebuilt) AidlPreprocessed() string {
577 return j.aidlPreprocessed
578}
579
580func SdkPrebuiltFactory() (blueprint.Module, []interface{}) {
581 module := &sdkPrebuilt{}
582
583 return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
584 common.MultilibCommon, &module.properties, &module.sdkProperties)
585}
586
Colin Cross2fe66872015-03-30 17:20:39 -0700587func inList(s string, l []string) bool {
588 for _, e := range l {
589 if e == s {
590 return true
591 }
592 }
593 return false
594}