Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package 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 | |
| 21 | import ( |
| 22 | "fmt" |
| 23 | "path/filepath" |
| 24 | "strings" |
| 25 | |
| 26 | "github.com/google/blueprint" |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint/pathtools" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 28 | |
| 29 | "android/soong/common" |
| 30 | ) |
| 31 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 32 | // TODO: |
| 33 | // Autogenerated files: |
| 34 | // AIDL |
| 35 | // 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. |
| 49 | type 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 | |
| 58 | // resource_dirs: list of directories containing resources |
| 59 | Resource_dirs []string `android:"arch_variant"` |
| 60 | |
| 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 | |
| 68 | // dxflags: list of module-specific flags that will be used for dex compiles |
| 69 | Dxflags []string `android:"arch_variant"` |
| 70 | |
| 71 | // java_libs: list of of java libraries that will be in the classpath |
| 72 | Java_libs []string `android:"arch_variant"` |
| 73 | |
| 74 | // java_static_libs: list of java libraries that will be compiled into the resulting jar |
| 75 | Java_static_libs []string `android:"arch_variant"` |
| 76 | |
| 77 | // manifest: manifest file to be included in resulting jar |
| 78 | Manifest string |
| 79 | |
| 80 | // sdk_version: if not blank, set to the version of the sdk to compile against |
| 81 | Sdk_version string |
| 82 | |
| 83 | // Set for device java libraries, and for host versions of device java libraries |
| 84 | // built for testing |
| 85 | Dex bool `blueprint:"mutated"` |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 86 | |
| 87 | // jarjar_rules: if not blank, run jarjar using the specified rules file |
| 88 | Jarjar_rules string |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 89 | |
| 90 | // aidl_includes: directories to pass to aidl tool |
| 91 | Aidl_includes []string |
| 92 | |
| 93 | // aidl_export_include_dirs: directories that should be added as include directories |
| 94 | // for any aidl sources of modules that depend on this module |
| 95 | Export_aidl_include_dirs []string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | // output file suitable for inserting into the classpath of another compile |
| 99 | classpathFile string |
| 100 | |
| 101 | // jarSpecs suitable for inserting classes from a static library into another jar |
| 102 | classJarSpecs []jarSpec |
| 103 | |
| 104 | // jarSpecs suitable for inserting resources from a static library into another jar |
| 105 | resourceJarSpecs []jarSpec |
| 106 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 107 | exportAidlIncludeDirs []string |
| 108 | |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame^] | 109 | logtagsSrcs []string |
| 110 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 111 | // installed file for binary dependency |
| 112 | installFile string |
| 113 | } |
| 114 | |
| 115 | type JavaModuleType interface { |
| 116 | GenerateJavaBuildActions(ctx common.AndroidModuleContext) |
| 117 | } |
| 118 | |
| 119 | type JavaDependency interface { |
| 120 | ClasspathFile() string |
| 121 | ClassJarSpecs() []jarSpec |
| 122 | ResourceJarSpecs() []jarSpec |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 123 | AidlIncludeDirs() []string |
| 124 | AidlPreprocessed() string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | func NewJavaBase(base *javaBase, module JavaModuleType, hod common.HostOrDeviceSupported, |
| 128 | props ...interface{}) (blueprint.Module, []interface{}) { |
| 129 | |
| 130 | base.module = module |
| 131 | |
| 132 | props = append(props, &base.properties) |
| 133 | |
| 134 | return common.InitAndroidArchModule(base, hod, common.MultilibCommon, props...) |
| 135 | } |
| 136 | |
| 137 | func (j *javaBase) BootClasspath(ctx common.AndroidBaseContext) string { |
| 138 | if ctx.Device() { |
| 139 | if j.properties.Sdk_version == "" { |
| 140 | return "core-libart" |
| 141 | } else if j.properties.Sdk_version == "current" { |
| 142 | // TODO: !TARGET_BUILD_APPS |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 143 | // TODO: export preprocessed framework.aidl from android_stubs_current |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 144 | return "android_stubs_current" |
| 145 | } else if j.properties.Sdk_version == "system_current" { |
| 146 | return "android_system_stubs_current" |
| 147 | } else { |
| 148 | return "sdk_v" + j.properties.Sdk_version |
| 149 | } |
| 150 | } else { |
| 151 | if j.properties.Dex { |
| 152 | return "core-libart" |
| 153 | } else { |
| 154 | return "" |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | func (j *javaBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { |
| 160 | var deps []string |
| 161 | |
| 162 | if !j.properties.No_standard_libraries { |
| 163 | bootClasspath := j.BootClasspath(ctx) |
| 164 | if bootClasspath != "" { |
| 165 | deps = append(deps, bootClasspath) |
| 166 | } |
| 167 | } |
| 168 | deps = append(deps, j.properties.Java_libs...) |
| 169 | deps = append(deps, j.properties.Java_static_libs...) |
| 170 | |
| 171 | return deps |
| 172 | } |
| 173 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 174 | func (j *javaBase) aidlFlags(ctx common.AndroidModuleContext, aidlPreprocess string, |
| 175 | aidlIncludeDirs []string) string { |
| 176 | |
| 177 | localAidlIncludes := pathtools.PrefixPaths(j.properties.Aidl_includes, common.ModuleSrcDir(ctx)) |
| 178 | |
| 179 | var flags []string |
| 180 | if aidlPreprocess != "" { |
| 181 | flags = append(flags, "-p"+aidlPreprocess) |
| 182 | } else { |
| 183 | flags = append(flags, common.JoinWithPrefix(aidlIncludeDirs, "-I")) |
| 184 | } |
| 185 | |
| 186 | flags = append(flags, common.JoinWithPrefix(j.exportAidlIncludeDirs, "-I")) |
| 187 | flags = append(flags, common.JoinWithPrefix(localAidlIncludes, "-I")) |
| 188 | flags = append(flags, "-I"+common.ModuleSrcDir(ctx)) |
| 189 | flags = append(flags, "-I"+filepath.Join(common.ModuleSrcDir(ctx), "src")) |
| 190 | |
| 191 | return strings.Join(flags, " ") |
| 192 | } |
| 193 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 194 | func (j *javaBase) collectDeps(ctx common.AndroidModuleContext) (classpath []string, |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 195 | bootClasspath string, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess string, |
| 196 | aidlIncludeDirs []string) { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 197 | |
| 198 | ctx.VisitDirectDeps(func(module blueprint.Module) { |
| 199 | otherName := ctx.OtherModuleName(module) |
| 200 | if javaDep, ok := module.(JavaDependency); ok { |
Colin Cross | 6cbb127 | 2015-04-08 11:23:01 -0700 | [diff] [blame] | 201 | if otherName == j.BootClasspath(ctx) { |
| 202 | bootClasspath = javaDep.ClasspathFile() |
| 203 | } else if inList(otherName, j.properties.Java_libs) { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 204 | classpath = append(classpath, javaDep.ClasspathFile()) |
| 205 | } else if inList(otherName, j.properties.Java_static_libs) { |
| 206 | classpath = append(classpath, javaDep.ClasspathFile()) |
| 207 | classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...) |
| 208 | resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 209 | } else { |
| 210 | panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) |
| 211 | } |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 212 | aidlIncludeDirs = append(aidlIncludeDirs, j.AidlIncludeDirs()...) |
| 213 | if j.AidlPreprocessed() != "" { |
| 214 | if aidlPreprocess != "" { |
| 215 | ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q", |
| 216 | aidlPreprocess, j.AidlPreprocessed()) |
| 217 | } else { |
| 218 | aidlPreprocess = j.AidlPreprocessed() |
| 219 | } |
| 220 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 221 | } else { |
| 222 | ctx.ModuleErrorf("unknown dependency module type for %q", otherName) |
| 223 | } |
| 224 | }) |
| 225 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 226 | return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess, aidlIncludeDirs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | func (j *javaBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) { |
| 230 | j.module.GenerateJavaBuildActions(ctx) |
| 231 | } |
| 232 | |
| 233 | func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 234 | |
| 235 | j.exportAidlIncludeDirs = pathtools.PrefixPaths(j.properties.Export_aidl_include_dirs, |
| 236 | common.ModuleSrcDir(ctx)) |
| 237 | |
| 238 | classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess, |
| 239 | aidlIncludeDirs := j.collectDeps(ctx) |
| 240 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 241 | flags := javaBuilderFlags{ |
| 242 | javacFlags: strings.Join(j.properties.Javacflags, " "), |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 243 | aidlFlags: j.aidlFlags(ctx, aidlPreprocess, aidlIncludeDirs), |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | var javacDeps []string |
| 247 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 248 | if bootClasspath != "" { |
| 249 | flags.bootClasspath = "-bootclasspath " + bootClasspath |
| 250 | javacDeps = append(javacDeps, bootClasspath) |
| 251 | } |
| 252 | |
| 253 | if len(classpath) > 0 { |
| 254 | flags.classpath = "-classpath " + strings.Join(classpath, ":") |
| 255 | javacDeps = append(javacDeps, classpath...) |
| 256 | } |
| 257 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 258 | srcFiles := common.ExpandSources(ctx, j.properties.Srcs) |
| 259 | |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame^] | 260 | srcFiles = j.genSources(ctx, srcFiles, flags) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 261 | |
Colin Cross | 8cf1334 | 2015-04-10 15:41:49 -0700 | [diff] [blame] | 262 | if len(srcFiles) > 0 { |
| 263 | // Compile java sources into .class files |
| 264 | classes := TransformJavaToClasses(ctx, srcFiles, flags, javacDeps) |
| 265 | if ctx.Failed() { |
| 266 | return |
| 267 | } |
| 268 | |
| 269 | classJarSpecs = append([]jarSpec{classes}, classJarSpecs...) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Resource_dirs), resourceJarSpecs...) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 273 | |
| 274 | manifest := j.properties.Manifest |
| 275 | if manifest != "" { |
| 276 | manifest = filepath.Join(common.ModuleSrcDir(ctx), manifest) |
| 277 | } |
| 278 | |
| 279 | allJarSpecs := append([]jarSpec(nil), classJarSpecs...) |
| 280 | allJarSpecs = append(allJarSpecs, resourceJarSpecs...) |
| 281 | |
| 282 | // Combine classes + resources into classes-full-debug.jar |
| 283 | outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest) |
| 284 | if ctx.Failed() { |
| 285 | return |
| 286 | } |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 287 | |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 288 | if j.properties.Jarjar_rules != "" { |
| 289 | jarjar_rules := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Jarjar_rules) |
| 290 | // Transform classes-full-debug.jar into classes-jarjar.jar |
| 291 | outputFile = TransformJarJar(ctx, outputFile, jarjar_rules) |
| 292 | if ctx.Failed() { |
| 293 | return |
| 294 | } |
Colin Cross | 2097830 | 2015-04-10 17:05:07 -0700 | [diff] [blame] | 295 | |
| 296 | classes, _ := TransformPrebuiltJarToClasses(ctx, outputFile) |
| 297 | classJarSpecs = []jarSpec{classes} |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Colin Cross | 2097830 | 2015-04-10 17:05:07 -0700 | [diff] [blame] | 300 | j.resourceJarSpecs = resourceJarSpecs |
| 301 | j.classJarSpecs = classJarSpecs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 302 | j.classpathFile = outputFile |
| 303 | |
Colin Cross | 8cf1334 | 2015-04-10 15:41:49 -0700 | [diff] [blame] | 304 | if j.properties.Dex && len(srcFiles) > 0 { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 305 | dxFlags := j.properties.Dxflags |
| 306 | if false /* emma enabled */ { |
| 307 | // If you instrument class files that have local variable debug information in |
| 308 | // them emma does not correctly maintain the local variable table. |
| 309 | // This will cause an error when you try to convert the class files for Android. |
| 310 | // The workaround here is to build different dex file here based on emma switch |
| 311 | // then later copy into classes.dex. When emma is on, dx is run with --no-locals |
| 312 | // option to remove local variable information |
| 313 | dxFlags = append(dxFlags, "--no-locals") |
| 314 | } |
| 315 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 316 | if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 317 | dxFlags = append(dxFlags, "--no-optimize") |
| 318 | } |
| 319 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 320 | if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 321 | dxFlags = append(dxFlags, |
| 322 | "--debug", |
| 323 | "--verbose", |
| 324 | "--dump-to="+filepath.Join(common.ModuleOutDir(ctx), "classes.lst"), |
| 325 | "--dump-width=1000") |
| 326 | } |
| 327 | |
| 328 | flags.dxFlags = strings.Join(dxFlags, " ") |
| 329 | |
| 330 | // Compile classes.jar into classes.dex |
Colin Cross | 6d1e72d | 2015-04-10 17:44:24 -0700 | [diff] [blame] | 331 | dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 332 | if ctx.Failed() { |
| 333 | return |
| 334 | } |
| 335 | |
| 336 | // Combine classes.dex + resources into javalib.jar |
Colin Cross | 6d1e72d | 2015-04-10 17:44:24 -0700 | [diff] [blame] | 337 | outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", outputFile) |
| 341 | } |
| 342 | |
| 343 | var _ JavaDependency = (*JavaLibrary)(nil) |
| 344 | |
| 345 | func (j *javaBase) ClasspathFile() string { |
| 346 | return j.classpathFile |
| 347 | } |
| 348 | |
| 349 | func (j *javaBase) ClassJarSpecs() []jarSpec { |
| 350 | return j.classJarSpecs |
| 351 | } |
| 352 | |
| 353 | func (j *javaBase) ResourceJarSpecs() []jarSpec { |
| 354 | return j.resourceJarSpecs |
| 355 | } |
| 356 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 357 | func (j *javaBase) AidlIncludeDirs() []string { |
| 358 | return j.exportAidlIncludeDirs |
| 359 | } |
| 360 | |
| 361 | func (j *javaBase) AidlPreprocessed() string { |
| 362 | return "" |
| 363 | } |
| 364 | |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame^] | 365 | var _ logtagsProducer = (*javaBase)(nil) |
| 366 | |
| 367 | func (j *javaBase) logtags() []string { |
| 368 | return j.logtagsSrcs |
| 369 | } |
| 370 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 371 | // |
| 372 | // Java libraries (.jar file) |
| 373 | // |
| 374 | |
| 375 | type JavaLibrary struct { |
| 376 | javaBase |
| 377 | } |
| 378 | |
| 379 | func JavaLibraryFactory() (blueprint.Module, []interface{}) { |
| 380 | module := &JavaLibrary{} |
| 381 | |
| 382 | module.properties.Dex = true |
| 383 | |
| 384 | return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported) |
| 385 | } |
| 386 | |
| 387 | func JavaLibraryHostFactory() (blueprint.Module, []interface{}) { |
| 388 | module := &JavaLibrary{} |
| 389 | |
| 390 | return NewJavaBase(&module.javaBase, module, common.HostSupported) |
| 391 | } |
| 392 | |
| 393 | // |
| 394 | // Java Binaries (.jar file plus wrapper script) |
| 395 | // |
| 396 | |
| 397 | type JavaBinary struct { |
| 398 | JavaLibrary |
| 399 | |
| 400 | binaryProperties struct { |
| 401 | // wrapper: installable script to execute the resulting jar |
| 402 | Wrapper string |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | func (j *JavaBinary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) { |
| 407 | j.JavaLibrary.GenerateJavaBuildActions(ctx) |
| 408 | |
| 409 | // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by |
| 410 | // another build rule before the jar has been installed. |
| 411 | ctx.InstallFile("bin", filepath.Join(common.ModuleSrcDir(ctx), j.binaryProperties.Wrapper), |
| 412 | j.installFile) |
| 413 | } |
| 414 | |
| 415 | func JavaBinaryFactory() (blueprint.Module, []interface{}) { |
| 416 | module := &JavaBinary{} |
| 417 | |
| 418 | module.properties.Dex = true |
| 419 | |
| 420 | return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported, &module.binaryProperties) |
| 421 | } |
| 422 | |
| 423 | func JavaBinaryHostFactory() (blueprint.Module, []interface{}) { |
| 424 | module := &JavaBinary{} |
| 425 | |
| 426 | return NewJavaBase(&module.javaBase, module, common.HostSupported, &module.binaryProperties) |
| 427 | } |
| 428 | |
| 429 | // |
| 430 | // Java prebuilts |
| 431 | // |
| 432 | |
| 433 | type JavaPrebuilt struct { |
| 434 | common.AndroidModuleBase |
| 435 | |
| 436 | properties struct { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 437 | Srcs []string |
| 438 | Aidl_preprocessed string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 441 | aidlPreprocessed string |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 442 | classpathFile string |
| 443 | classJarSpecs, resourceJarSpecs []jarSpec |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) { |
| 447 | if len(j.properties.Srcs) != 1 { |
| 448 | ctx.ModuleErrorf("expected exactly one jar in srcs") |
| 449 | return |
| 450 | } |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 451 | prebuilt := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Srcs[0]) |
| 452 | |
| 453 | classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt) |
| 454 | |
| 455 | j.classpathFile = prebuilt |
| 456 | j.classJarSpecs = []jarSpec{classJarSpec} |
| 457 | j.resourceJarSpecs = []jarSpec{resourceJarSpec} |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 458 | if j.properties.Aidl_preprocessed != "" { |
| 459 | j.aidlPreprocessed = filepath.Join(common.ModuleSrcDir(ctx), j.properties.Aidl_preprocessed) |
| 460 | } |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 461 | ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.classpathFile) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | var _ JavaDependency = (*JavaPrebuilt)(nil) |
| 465 | |
| 466 | func (j *JavaPrebuilt) ClasspathFile() string { |
| 467 | return j.classpathFile |
| 468 | } |
| 469 | |
| 470 | func (j *JavaPrebuilt) ClassJarSpecs() []jarSpec { |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 471 | return j.classJarSpecs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | func (j *JavaPrebuilt) ResourceJarSpecs() []jarSpec { |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 475 | return j.resourceJarSpecs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 478 | func (j *JavaPrebuilt) AidlIncludeDirs() []string { |
| 479 | return nil |
| 480 | } |
| 481 | |
| 482 | func (j *JavaPrebuilt) AidlPreprocessed() string { |
| 483 | return j.aidlPreprocessed |
| 484 | } |
| 485 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 486 | func JavaPrebuiltFactory() (blueprint.Module, []interface{}) { |
| 487 | module := &JavaPrebuilt{} |
| 488 | |
| 489 | return common.InitAndroidArchModule(module, common.HostAndDeviceSupported, |
| 490 | common.MultilibCommon, &module.properties) |
| 491 | } |
| 492 | |
| 493 | func inList(s string, l []string) bool { |
| 494 | for _, e := range l { |
| 495 | if e == s { |
| 496 | return true |
| 497 | } |
| 498 | } |
| 499 | return false |
| 500 | } |