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 |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | func NewJavaBase(base *javaBase, module JavaModuleType, hod common.HostOrDeviceSupported, |
| 127 | props ...interface{}) (blueprint.Module, []interface{}) { |
| 128 | |
| 129 | base.module = module |
| 130 | |
| 131 | props = append(props, &base.properties) |
| 132 | |
| 133 | return common.InitAndroidArchModule(base, hod, common.MultilibCommon, props...) |
| 134 | } |
| 135 | |
| 136 | func (j *javaBase) BootClasspath(ctx common.AndroidBaseContext) string { |
| 137 | if ctx.Device() { |
| 138 | if j.properties.Sdk_version == "" { |
| 139 | return "core-libart" |
| 140 | } else if j.properties.Sdk_version == "current" { |
| 141 | // TODO: !TARGET_BUILD_APPS |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 142 | // TODO: export preprocessed framework.aidl from android_stubs_current |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 143 | return "android_stubs_current" |
| 144 | } else if j.properties.Sdk_version == "system_current" { |
| 145 | return "android_system_stubs_current" |
| 146 | } else { |
| 147 | return "sdk_v" + j.properties.Sdk_version |
| 148 | } |
| 149 | } else { |
| 150 | if j.properties.Dex { |
| 151 | return "core-libart" |
| 152 | } else { |
| 153 | return "" |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | func (j *javaBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { |
| 159 | var deps []string |
| 160 | |
| 161 | if !j.properties.No_standard_libraries { |
| 162 | bootClasspath := j.BootClasspath(ctx) |
| 163 | if bootClasspath != "" { |
| 164 | deps = append(deps, bootClasspath) |
| 165 | } |
| 166 | } |
| 167 | deps = append(deps, j.properties.Java_libs...) |
| 168 | deps = append(deps, j.properties.Java_static_libs...) |
| 169 | |
| 170 | return deps |
| 171 | } |
| 172 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 173 | func (j *javaBase) aidlFlags(ctx common.AndroidModuleContext, aidlPreprocess string, |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 174 | aidlIncludeDirs []string) []string { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 175 | |
| 176 | localAidlIncludes := pathtools.PrefixPaths(j.properties.Aidl_includes, common.ModuleSrcDir(ctx)) |
| 177 | |
| 178 | var flags []string |
| 179 | if aidlPreprocess != "" { |
| 180 | flags = append(flags, "-p"+aidlPreprocess) |
| 181 | } else { |
| 182 | flags = append(flags, common.JoinWithPrefix(aidlIncludeDirs, "-I")) |
| 183 | } |
| 184 | |
| 185 | flags = append(flags, common.JoinWithPrefix(j.exportAidlIncludeDirs, "-I")) |
| 186 | flags = append(flags, common.JoinWithPrefix(localAidlIncludes, "-I")) |
| 187 | flags = append(flags, "-I"+common.ModuleSrcDir(ctx)) |
| 188 | flags = append(flags, "-I"+filepath.Join(common.ModuleSrcDir(ctx), "src")) |
| 189 | |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 190 | return flags |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 193 | func (j *javaBase) collectDeps(ctx common.AndroidModuleContext) (classpath []string, |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 194 | bootClasspath string, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess string, |
| 195 | aidlIncludeDirs []string) { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 196 | |
| 197 | ctx.VisitDirectDeps(func(module blueprint.Module) { |
| 198 | otherName := ctx.OtherModuleName(module) |
| 199 | if javaDep, ok := module.(JavaDependency); ok { |
Colin Cross | 6cbb127 | 2015-04-08 11:23:01 -0700 | [diff] [blame] | 200 | if otherName == j.BootClasspath(ctx) { |
| 201 | bootClasspath = javaDep.ClasspathFile() |
| 202 | } else if inList(otherName, j.properties.Java_libs) { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 203 | classpath = append(classpath, javaDep.ClasspathFile()) |
| 204 | } else if inList(otherName, j.properties.Java_static_libs) { |
| 205 | classpath = append(classpath, javaDep.ClasspathFile()) |
| 206 | classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...) |
| 207 | resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 208 | } else { |
| 209 | panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) |
| 210 | } |
Colin Cross | aa8630b | 2015-04-13 13:52:22 -0700 | [diff] [blame] | 211 | aidlIncludeDirs = append(aidlIncludeDirs, javaDep.AidlIncludeDirs()...) |
| 212 | if sdkDep, ok := module.(sdkDependency); ok { |
| 213 | if sdkDep.AidlPreprocessed() != "" { |
| 214 | if aidlPreprocess != "" { |
| 215 | ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q", |
| 216 | aidlPreprocess, sdkDep.AidlPreprocessed()) |
| 217 | } else { |
| 218 | aidlPreprocess = sdkDep.AidlPreprocessed() |
| 219 | } |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 220 | } |
| 221 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 222 | } else { |
| 223 | ctx.ModuleErrorf("unknown dependency module type for %q", otherName) |
| 224 | } |
| 225 | }) |
| 226 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 227 | return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess, aidlIncludeDirs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | func (j *javaBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) { |
| 231 | j.module.GenerateJavaBuildActions(ctx) |
| 232 | } |
| 233 | |
| 234 | func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 235 | |
| 236 | j.exportAidlIncludeDirs = pathtools.PrefixPaths(j.properties.Export_aidl_include_dirs, |
| 237 | common.ModuleSrcDir(ctx)) |
| 238 | |
| 239 | classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess, |
| 240 | aidlIncludeDirs := j.collectDeps(ctx) |
| 241 | |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 242 | var flags javaBuilderFlags |
| 243 | |
| 244 | javacFlags := j.properties.Javacflags |
| 245 | if len(javacFlags) > 0 { |
| 246 | ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " ")) |
| 247 | flags.javacFlags = "$javacFlags" |
| 248 | } |
| 249 | |
| 250 | aidlFlags := j.aidlFlags(ctx, aidlPreprocess, aidlIncludeDirs) |
| 251 | if len(aidlFlags) > 0 { |
| 252 | ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " ")) |
| 253 | flags.aidlFlags = "$aidlFlags" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | var javacDeps []string |
| 257 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 258 | if bootClasspath != "" { |
| 259 | flags.bootClasspath = "-bootclasspath " + bootClasspath |
| 260 | javacDeps = append(javacDeps, bootClasspath) |
| 261 | } |
| 262 | |
| 263 | if len(classpath) > 0 { |
| 264 | flags.classpath = "-classpath " + strings.Join(classpath, ":") |
| 265 | javacDeps = append(javacDeps, classpath...) |
| 266 | } |
| 267 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 268 | srcFiles := common.ExpandSources(ctx, j.properties.Srcs) |
| 269 | |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 270 | srcFiles = j.genSources(ctx, srcFiles, flags) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 271 | |
Colin Cross | 8cf1334 | 2015-04-10 15:41:49 -0700 | [diff] [blame] | 272 | if len(srcFiles) > 0 { |
| 273 | // Compile java sources into .class files |
| 274 | classes := TransformJavaToClasses(ctx, srcFiles, flags, javacDeps) |
| 275 | if ctx.Failed() { |
| 276 | return |
| 277 | } |
| 278 | |
| 279 | classJarSpecs = append([]jarSpec{classes}, classJarSpecs...) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Resource_dirs), resourceJarSpecs...) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 283 | |
| 284 | manifest := j.properties.Manifest |
| 285 | if manifest != "" { |
| 286 | manifest = filepath.Join(common.ModuleSrcDir(ctx), manifest) |
| 287 | } |
| 288 | |
| 289 | allJarSpecs := append([]jarSpec(nil), classJarSpecs...) |
| 290 | allJarSpecs = append(allJarSpecs, resourceJarSpecs...) |
| 291 | |
| 292 | // Combine classes + resources into classes-full-debug.jar |
| 293 | outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest) |
| 294 | if ctx.Failed() { |
| 295 | return |
| 296 | } |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 297 | |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 298 | if j.properties.Jarjar_rules != "" { |
| 299 | jarjar_rules := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Jarjar_rules) |
| 300 | // Transform classes-full-debug.jar into classes-jarjar.jar |
| 301 | outputFile = TransformJarJar(ctx, outputFile, jarjar_rules) |
| 302 | if ctx.Failed() { |
| 303 | return |
| 304 | } |
Colin Cross | 2097830 | 2015-04-10 17:05:07 -0700 | [diff] [blame] | 305 | |
| 306 | classes, _ := TransformPrebuiltJarToClasses(ctx, outputFile) |
| 307 | classJarSpecs = []jarSpec{classes} |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Colin Cross | 2097830 | 2015-04-10 17:05:07 -0700 | [diff] [blame] | 310 | j.resourceJarSpecs = resourceJarSpecs |
| 311 | j.classJarSpecs = classJarSpecs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 312 | j.classpathFile = outputFile |
| 313 | |
Colin Cross | 8cf1334 | 2015-04-10 15:41:49 -0700 | [diff] [blame] | 314 | if j.properties.Dex && len(srcFiles) > 0 { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 315 | dxFlags := j.properties.Dxflags |
| 316 | if false /* emma enabled */ { |
| 317 | // If you instrument class files that have local variable debug information in |
| 318 | // them emma does not correctly maintain the local variable table. |
| 319 | // This will cause an error when you try to convert the class files for Android. |
| 320 | // The workaround here is to build different dex file here based on emma switch |
| 321 | // then later copy into classes.dex. When emma is on, dx is run with --no-locals |
| 322 | // option to remove local variable information |
| 323 | dxFlags = append(dxFlags, "--no-locals") |
| 324 | } |
| 325 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 326 | if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 327 | dxFlags = append(dxFlags, "--no-optimize") |
| 328 | } |
| 329 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 330 | if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 331 | dxFlags = append(dxFlags, |
| 332 | "--debug", |
| 333 | "--verbose", |
| 334 | "--dump-to="+filepath.Join(common.ModuleOutDir(ctx), "classes.lst"), |
| 335 | "--dump-width=1000") |
| 336 | } |
| 337 | |
| 338 | flags.dxFlags = strings.Join(dxFlags, " ") |
| 339 | |
| 340 | // Compile classes.jar into classes.dex |
Colin Cross | 6d1e72d | 2015-04-10 17:44:24 -0700 | [diff] [blame] | 341 | dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 342 | if ctx.Failed() { |
| 343 | return |
| 344 | } |
| 345 | |
| 346 | // Combine classes.dex + resources into javalib.jar |
Colin Cross | 6d1e72d | 2015-04-10 17:44:24 -0700 | [diff] [blame] | 347 | outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", outputFile) |
| 351 | } |
| 352 | |
| 353 | var _ JavaDependency = (*JavaLibrary)(nil) |
| 354 | |
| 355 | func (j *javaBase) ClasspathFile() string { |
| 356 | return j.classpathFile |
| 357 | } |
| 358 | |
| 359 | func (j *javaBase) ClassJarSpecs() []jarSpec { |
| 360 | return j.classJarSpecs |
| 361 | } |
| 362 | |
| 363 | func (j *javaBase) ResourceJarSpecs() []jarSpec { |
| 364 | return j.resourceJarSpecs |
| 365 | } |
| 366 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 367 | func (j *javaBase) AidlIncludeDirs() []string { |
| 368 | return j.exportAidlIncludeDirs |
| 369 | } |
| 370 | |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 371 | var _ logtagsProducer = (*javaBase)(nil) |
| 372 | |
| 373 | func (j *javaBase) logtags() []string { |
| 374 | return j.logtagsSrcs |
| 375 | } |
| 376 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 377 | // |
| 378 | // Java libraries (.jar file) |
| 379 | // |
| 380 | |
| 381 | type JavaLibrary struct { |
| 382 | javaBase |
| 383 | } |
| 384 | |
| 385 | func JavaLibraryFactory() (blueprint.Module, []interface{}) { |
| 386 | module := &JavaLibrary{} |
| 387 | |
| 388 | module.properties.Dex = true |
| 389 | |
| 390 | return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported) |
| 391 | } |
| 392 | |
| 393 | func JavaLibraryHostFactory() (blueprint.Module, []interface{}) { |
| 394 | module := &JavaLibrary{} |
| 395 | |
| 396 | return NewJavaBase(&module.javaBase, module, common.HostSupported) |
| 397 | } |
| 398 | |
| 399 | // |
| 400 | // Java Binaries (.jar file plus wrapper script) |
| 401 | // |
| 402 | |
| 403 | type JavaBinary struct { |
| 404 | JavaLibrary |
| 405 | |
| 406 | binaryProperties struct { |
| 407 | // wrapper: installable script to execute the resulting jar |
| 408 | Wrapper string |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | func (j *JavaBinary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) { |
| 413 | j.JavaLibrary.GenerateJavaBuildActions(ctx) |
| 414 | |
| 415 | // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by |
| 416 | // another build rule before the jar has been installed. |
| 417 | ctx.InstallFile("bin", filepath.Join(common.ModuleSrcDir(ctx), j.binaryProperties.Wrapper), |
| 418 | j.installFile) |
| 419 | } |
| 420 | |
| 421 | func JavaBinaryFactory() (blueprint.Module, []interface{}) { |
| 422 | module := &JavaBinary{} |
| 423 | |
| 424 | module.properties.Dex = true |
| 425 | |
| 426 | return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported, &module.binaryProperties) |
| 427 | } |
| 428 | |
| 429 | func JavaBinaryHostFactory() (blueprint.Module, []interface{}) { |
| 430 | module := &JavaBinary{} |
| 431 | |
| 432 | return NewJavaBase(&module.javaBase, module, common.HostSupported, &module.binaryProperties) |
| 433 | } |
| 434 | |
| 435 | // |
| 436 | // Java prebuilts |
| 437 | // |
| 438 | |
| 439 | type JavaPrebuilt struct { |
| 440 | common.AndroidModuleBase |
| 441 | |
| 442 | properties struct { |
Colin Cross | aa8630b | 2015-04-13 13:52:22 -0700 | [diff] [blame] | 443 | Srcs []string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 446 | classpathFile string |
| 447 | classJarSpecs, resourceJarSpecs []jarSpec |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) { |
| 451 | if len(j.properties.Srcs) != 1 { |
| 452 | ctx.ModuleErrorf("expected exactly one jar in srcs") |
| 453 | return |
| 454 | } |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 455 | prebuilt := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Srcs[0]) |
| 456 | |
| 457 | classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt) |
| 458 | |
| 459 | j.classpathFile = prebuilt |
| 460 | j.classJarSpecs = []jarSpec{classJarSpec} |
| 461 | j.resourceJarSpecs = []jarSpec{resourceJarSpec} |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 462 | ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.classpathFile) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | var _ JavaDependency = (*JavaPrebuilt)(nil) |
| 466 | |
| 467 | func (j *JavaPrebuilt) ClasspathFile() string { |
| 468 | return j.classpathFile |
| 469 | } |
| 470 | |
| 471 | func (j *JavaPrebuilt) ClassJarSpecs() []jarSpec { |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 472 | return j.classJarSpecs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | func (j *JavaPrebuilt) ResourceJarSpecs() []jarSpec { |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 476 | return j.resourceJarSpecs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 479 | func (j *JavaPrebuilt) AidlIncludeDirs() []string { |
| 480 | return nil |
| 481 | } |
| 482 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 483 | func JavaPrebuiltFactory() (blueprint.Module, []interface{}) { |
| 484 | module := &JavaPrebuilt{} |
| 485 | |
| 486 | return common.InitAndroidArchModule(module, common.HostAndDeviceSupported, |
| 487 | common.MultilibCommon, &module.properties) |
| 488 | } |
| 489 | |
Colin Cross | aa8630b | 2015-04-13 13:52:22 -0700 | [diff] [blame] | 490 | // |
| 491 | // SDK java prebuilts (.jar containing resources plus framework.aidl) |
| 492 | // |
| 493 | |
| 494 | type sdkDependency interface { |
| 495 | JavaDependency |
| 496 | AidlPreprocessed() string |
| 497 | } |
| 498 | |
| 499 | var _ sdkDependency = (*sdkPrebuilt)(nil) |
| 500 | |
| 501 | type sdkPrebuilt struct { |
| 502 | JavaPrebuilt |
| 503 | |
| 504 | sdkProperties struct { |
| 505 | Aidl_preprocessed string |
| 506 | } |
| 507 | |
| 508 | aidlPreprocessed string |
| 509 | } |
| 510 | |
| 511 | func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) { |
| 512 | j.JavaPrebuilt.GenerateAndroidBuildActions(ctx) |
| 513 | |
| 514 | if j.sdkProperties.Aidl_preprocessed != "" { |
| 515 | j.aidlPreprocessed = filepath.Join(common.ModuleSrcDir(ctx), j.sdkProperties.Aidl_preprocessed) |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | func (j *sdkPrebuilt) AidlPreprocessed() string { |
| 520 | return j.aidlPreprocessed |
| 521 | } |
| 522 | |
| 523 | func SdkPrebuiltFactory() (blueprint.Module, []interface{}) { |
| 524 | module := &sdkPrebuilt{} |
| 525 | |
| 526 | return common.InitAndroidArchModule(module, common.HostAndDeviceSupported, |
| 527 | common.MultilibCommon, &module.properties, &module.sdkProperties) |
| 528 | } |
| 529 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 530 | func inList(s string, l []string) bool { |
| 531 | for _, e := range l { |
| 532 | if e == s { |
| 533 | return true |
| 534 | } |
| 535 | } |
| 536 | return false |
| 537 | } |