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