2015-03-31 08:20:39 +08:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
// This file contains the module types for compiling Java for Android, and converts the properties
|
|
|
|
// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
|
|
|
|
// is handled in builder.go
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2015-04-09 04:03:43 +08:00
|
|
|
"github.com/google/blueprint/pathtools"
|
2015-03-31 08:20:39 +08:00
|
|
|
|
|
|
|
"android/soong/common"
|
2015-04-29 04:28:51 +08:00
|
|
|
"android/soong/genrule"
|
2015-03-31 08:20:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// Autogenerated files:
|
|
|
|
// Proto
|
|
|
|
// Renderscript
|
|
|
|
// Post-jar passes:
|
|
|
|
// Proguard
|
|
|
|
// Emma
|
|
|
|
// Jarjar
|
|
|
|
// Dex
|
|
|
|
// Rmtypedefs
|
|
|
|
// Jack
|
|
|
|
// DroidDoc
|
|
|
|
// Findbugs
|
|
|
|
|
|
|
|
// javaBase contains the properties and members used by all java module types, and implements
|
|
|
|
// the blueprint.Module interface.
|
|
|
|
type javaBase struct {
|
|
|
|
common.AndroidModuleBase
|
|
|
|
module JavaModuleType
|
|
|
|
|
|
|
|
properties struct {
|
|
|
|
// srcs: list of source files used to compile the Java module. May be .java, .logtags, .proto,
|
|
|
|
// or .aidl files.
|
|
|
|
Srcs []string `android:"arch_variant,arch_subtract"`
|
|
|
|
|
2015-04-21 04:51:48 +08:00
|
|
|
// java_resource_dirs: list of directories containing Java resources
|
|
|
|
Java_resource_dirs []string `android:"arch_variant"`
|
2015-03-31 08:20:39 +08:00
|
|
|
|
|
|
|
// no_standard_libraries: don't build against the default libraries (core-libart, core-junit,
|
|
|
|
// ext, and framework for device targets)
|
|
|
|
No_standard_libraries bool
|
|
|
|
|
|
|
|
// javacflags: list of module-specific flags that will be used for javac compiles
|
|
|
|
Javacflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// dxflags: list of module-specific flags that will be used for dex compiles
|
|
|
|
Dxflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// java_libs: list of of java libraries that will be in the classpath
|
|
|
|
Java_libs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// java_static_libs: list of java libraries that will be compiled into the resulting jar
|
|
|
|
Java_static_libs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// manifest: manifest file to be included in resulting jar
|
|
|
|
Manifest string
|
|
|
|
|
|
|
|
// sdk_version: if not blank, set to the version of the sdk to compile against
|
|
|
|
Sdk_version string
|
|
|
|
|
|
|
|
// Set for device java libraries, and for host versions of device java libraries
|
|
|
|
// built for testing
|
|
|
|
Dex bool `blueprint:"mutated"`
|
2015-04-04 07:54:17 +08:00
|
|
|
|
|
|
|
// jarjar_rules: if not blank, run jarjar using the specified rules file
|
|
|
|
Jarjar_rules string
|
2015-04-09 04:03:43 +08:00
|
|
|
|
|
|
|
// aidl_includes: directories to pass to aidl tool
|
|
|
|
Aidl_includes []string
|
|
|
|
|
|
|
|
// aidl_export_include_dirs: directories that should be added as include directories
|
|
|
|
// for any aidl sources of modules that depend on this module
|
|
|
|
Export_aidl_include_dirs []string
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// output file suitable for inserting into the classpath of another compile
|
|
|
|
classpathFile string
|
|
|
|
|
2015-04-17 05:09:14 +08:00
|
|
|
// output file suitable for installing or running
|
|
|
|
outputFile string
|
|
|
|
|
2015-03-31 08:20:39 +08:00
|
|
|
// jarSpecs suitable for inserting classes from a static library into another jar
|
|
|
|
classJarSpecs []jarSpec
|
|
|
|
|
|
|
|
// jarSpecs suitable for inserting resources from a static library into another jar
|
|
|
|
resourceJarSpecs []jarSpec
|
|
|
|
|
2015-04-09 04:03:43 +08:00
|
|
|
exportAidlIncludeDirs []string
|
|
|
|
|
2015-04-11 08:45:20 +08:00
|
|
|
logtagsSrcs []string
|
|
|
|
|
2015-04-17 05:09:14 +08:00
|
|
|
// filelists of extra source files that should be included in the javac command line,
|
|
|
|
// for example R.java generated by aapt for android apps
|
|
|
|
ExtraSrcLists []string
|
|
|
|
|
2015-03-31 08:20:39 +08:00
|
|
|
// installed file for binary dependency
|
|
|
|
installFile string
|
|
|
|
}
|
|
|
|
|
|
|
|
type JavaModuleType interface {
|
|
|
|
GenerateJavaBuildActions(ctx common.AndroidModuleContext)
|
2015-04-17 05:09:14 +08:00
|
|
|
JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type JavaDependency interface {
|
|
|
|
ClasspathFile() string
|
|
|
|
ClassJarSpecs() []jarSpec
|
|
|
|
ResourceJarSpecs() []jarSpec
|
2015-04-09 04:03:43 +08:00
|
|
|
AidlIncludeDirs() []string
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewJavaBase(base *javaBase, module JavaModuleType, hod common.HostOrDeviceSupported,
|
|
|
|
props ...interface{}) (blueprint.Module, []interface{}) {
|
|
|
|
|
|
|
|
base.module = module
|
|
|
|
|
|
|
|
props = append(props, &base.properties)
|
|
|
|
|
|
|
|
return common.InitAndroidArchModule(base, hod, common.MultilibCommon, props...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *javaBase) BootClasspath(ctx common.AndroidBaseContext) string {
|
|
|
|
if ctx.Device() {
|
|
|
|
if j.properties.Sdk_version == "" {
|
|
|
|
return "core-libart"
|
|
|
|
} else if j.properties.Sdk_version == "current" {
|
|
|
|
// TODO: !TARGET_BUILD_APPS
|
2015-04-09 04:03:43 +08:00
|
|
|
// TODO: export preprocessed framework.aidl from android_stubs_current
|
2015-03-31 08:20:39 +08:00
|
|
|
return "android_stubs_current"
|
|
|
|
} else if j.properties.Sdk_version == "system_current" {
|
|
|
|
return "android_system_stubs_current"
|
|
|
|
} else {
|
|
|
|
return "sdk_v" + j.properties.Sdk_version
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if j.properties.Dex {
|
|
|
|
return "core-libart"
|
|
|
|
} else {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-17 05:08:06 +08:00
|
|
|
var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"}
|
|
|
|
|
2015-03-31 08:20:39 +08:00
|
|
|
func (j *javaBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
|
2015-04-17 05:09:14 +08:00
|
|
|
return j.module.JavaDynamicDependencies(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *javaBase) JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
|
2015-03-31 08:20:39 +08:00
|
|
|
var deps []string
|
|
|
|
|
|
|
|
if !j.properties.No_standard_libraries {
|
|
|
|
bootClasspath := j.BootClasspath(ctx)
|
|
|
|
if bootClasspath != "" {
|
|
|
|
deps = append(deps, bootClasspath)
|
|
|
|
}
|
2015-04-17 05:08:06 +08:00
|
|
|
if ctx.Device() && j.properties.Sdk_version == "" {
|
|
|
|
deps = append(deps, defaultJavaLibraries...)
|
|
|
|
}
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
deps = append(deps, j.properties.Java_libs...)
|
|
|
|
deps = append(deps, j.properties.Java_static_libs...)
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2015-04-09 04:03:43 +08:00
|
|
|
func (j *javaBase) aidlFlags(ctx common.AndroidModuleContext, aidlPreprocess string,
|
2015-04-14 04:53:40 +08:00
|
|
|
aidlIncludeDirs []string) []string {
|
2015-04-09 04:03:43 +08:00
|
|
|
|
|
|
|
localAidlIncludes := pathtools.PrefixPaths(j.properties.Aidl_includes, common.ModuleSrcDir(ctx))
|
|
|
|
|
|
|
|
var flags []string
|
|
|
|
if aidlPreprocess != "" {
|
|
|
|
flags = append(flags, "-p"+aidlPreprocess)
|
|
|
|
} else {
|
|
|
|
flags = append(flags, common.JoinWithPrefix(aidlIncludeDirs, "-I"))
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = append(flags, common.JoinWithPrefix(j.exportAidlIncludeDirs, "-I"))
|
|
|
|
flags = append(flags, common.JoinWithPrefix(localAidlIncludes, "-I"))
|
|
|
|
flags = append(flags, "-I"+common.ModuleSrcDir(ctx))
|
|
|
|
flags = append(flags, "-I"+filepath.Join(common.ModuleSrcDir(ctx), "src"))
|
|
|
|
|
2015-04-14 04:53:40 +08:00
|
|
|
return flags
|
2015-04-09 04:03:43 +08:00
|
|
|
}
|
|
|
|
|
2015-03-31 08:20:39 +08:00
|
|
|
func (j *javaBase) collectDeps(ctx common.AndroidModuleContext) (classpath []string,
|
2015-04-09 04:03:43 +08:00
|
|
|
bootClasspath string, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess string,
|
2015-04-14 05:02:52 +08:00
|
|
|
aidlIncludeDirs []string, srcFileLists []string) {
|
2015-03-31 08:20:39 +08:00
|
|
|
|
|
|
|
ctx.VisitDirectDeps(func(module blueprint.Module) {
|
|
|
|
otherName := ctx.OtherModuleName(module)
|
|
|
|
if javaDep, ok := module.(JavaDependency); ok {
|
2015-04-09 02:23:01 +08:00
|
|
|
if otherName == j.BootClasspath(ctx) {
|
|
|
|
bootClasspath = javaDep.ClasspathFile()
|
2015-04-17 05:09:14 +08:00
|
|
|
} else if inList(otherName, defaultJavaLibraries) {
|
|
|
|
classpath = append(classpath, javaDep.ClasspathFile())
|
2015-04-09 02:23:01 +08:00
|
|
|
} else if inList(otherName, j.properties.Java_libs) {
|
2015-03-31 08:20:39 +08:00
|
|
|
classpath = append(classpath, javaDep.ClasspathFile())
|
|
|
|
} else if inList(otherName, j.properties.Java_static_libs) {
|
|
|
|
classpath = append(classpath, javaDep.ClasspathFile())
|
|
|
|
classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...)
|
|
|
|
resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...)
|
2015-04-17 05:09:14 +08:00
|
|
|
} else if otherName == "framework-res" {
|
|
|
|
if ctx.ModuleName() == "framework" {
|
|
|
|
// framework.jar has a one-off dependency on the R.java and Manifest.java files
|
|
|
|
// generated by framework-res.apk
|
|
|
|
srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).aaptJavaFileList)
|
|
|
|
}
|
2015-03-31 08:20:39 +08:00
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
|
|
|
|
}
|
2015-04-14 04:52:22 +08:00
|
|
|
aidlIncludeDirs = append(aidlIncludeDirs, javaDep.AidlIncludeDirs()...)
|
|
|
|
if sdkDep, ok := module.(sdkDependency); ok {
|
|
|
|
if sdkDep.AidlPreprocessed() != "" {
|
|
|
|
if aidlPreprocess != "" {
|
|
|
|
ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q",
|
|
|
|
aidlPreprocess, sdkDep.AidlPreprocessed())
|
|
|
|
} else {
|
|
|
|
aidlPreprocess = sdkDep.AidlPreprocessed()
|
|
|
|
}
|
2015-04-09 04:03:43 +08:00
|
|
|
}
|
|
|
|
}
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-04-14 05:02:52 +08:00
|
|
|
return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
|
|
|
|
aidlIncludeDirs, srcFileLists
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (j *javaBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
|
|
|
j.module.GenerateJavaBuildActions(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
|
2015-04-09 04:03:43 +08:00
|
|
|
|
|
|
|
j.exportAidlIncludeDirs = pathtools.PrefixPaths(j.properties.Export_aidl_include_dirs,
|
|
|
|
common.ModuleSrcDir(ctx))
|
|
|
|
|
|
|
|
classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
|
2015-04-14 05:02:52 +08:00
|
|
|
aidlIncludeDirs, srcFileLists := j.collectDeps(ctx)
|
2015-04-09 04:03:43 +08:00
|
|
|
|
2015-04-14 04:53:40 +08:00
|
|
|
var flags javaBuilderFlags
|
|
|
|
|
|
|
|
javacFlags := j.properties.Javacflags
|
|
|
|
if len(javacFlags) > 0 {
|
|
|
|
ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
|
|
|
|
flags.javacFlags = "$javacFlags"
|
|
|
|
}
|
|
|
|
|
|
|
|
aidlFlags := j.aidlFlags(ctx, aidlPreprocess, aidlIncludeDirs)
|
|
|
|
if len(aidlFlags) > 0 {
|
|
|
|
ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
|
|
|
|
flags.aidlFlags = "$aidlFlags"
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var javacDeps []string
|
|
|
|
|
|
|
|
if bootClasspath != "" {
|
|
|
|
flags.bootClasspath = "-bootclasspath " + bootClasspath
|
|
|
|
javacDeps = append(javacDeps, bootClasspath)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(classpath) > 0 {
|
|
|
|
flags.classpath = "-classpath " + strings.Join(classpath, ":")
|
|
|
|
javacDeps = append(javacDeps, classpath...)
|
|
|
|
}
|
|
|
|
|
2015-04-09 04:03:43 +08:00
|
|
|
srcFiles := common.ExpandSources(ctx, j.properties.Srcs)
|
|
|
|
|
2015-04-11 08:45:20 +08:00
|
|
|
srcFiles = j.genSources(ctx, srcFiles, flags)
|
2015-04-09 04:03:43 +08:00
|
|
|
|
2015-04-29 04:28:51 +08:00
|
|
|
ctx.VisitDirectDeps(func(module blueprint.Module) {
|
|
|
|
if gen, ok := module.(genrule.SourceFileGenerator); ok {
|
|
|
|
srcFiles = append(srcFiles, gen.GeneratedSourceFiles()...)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-04-17 05:09:14 +08:00
|
|
|
srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
|
|
|
|
|
2015-04-11 06:41:49 +08:00
|
|
|
if len(srcFiles) > 0 {
|
|
|
|
// Compile java sources into .class files
|
2015-04-14 05:02:52 +08:00
|
|
|
classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, javacDeps)
|
2015-04-11 06:41:49 +08:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
classJarSpecs = append([]jarSpec{classes}, classJarSpecs...)
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2015-04-21 04:51:48 +08:00
|
|
|
resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Java_resource_dirs),
|
|
|
|
resourceJarSpecs...)
|
2015-03-31 08:20:39 +08:00
|
|
|
|
|
|
|
manifest := j.properties.Manifest
|
|
|
|
if manifest != "" {
|
|
|
|
manifest = filepath.Join(common.ModuleSrcDir(ctx), manifest)
|
|
|
|
}
|
|
|
|
|
|
|
|
allJarSpecs := append([]jarSpec(nil), classJarSpecs...)
|
|
|
|
allJarSpecs = append(allJarSpecs, resourceJarSpecs...)
|
|
|
|
|
|
|
|
// Combine classes + resources into classes-full-debug.jar
|
|
|
|
outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2015-04-04 07:54:17 +08:00
|
|
|
|
|
|
|
if j.properties.Jarjar_rules != "" {
|
|
|
|
jarjar_rules := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Jarjar_rules)
|
|
|
|
// Transform classes-full-debug.jar into classes-jarjar.jar
|
|
|
|
outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2015-04-11 08:05:07 +08:00
|
|
|
|
|
|
|
classes, _ := TransformPrebuiltJarToClasses(ctx, outputFile)
|
|
|
|
classJarSpecs = []jarSpec{classes}
|
2015-04-04 07:54:17 +08:00
|
|
|
}
|
|
|
|
|
2015-04-11 08:05:07 +08:00
|
|
|
j.resourceJarSpecs = resourceJarSpecs
|
|
|
|
j.classJarSpecs = classJarSpecs
|
2015-03-31 08:20:39 +08:00
|
|
|
j.classpathFile = outputFile
|
|
|
|
|
2015-04-11 06:41:49 +08:00
|
|
|
if j.properties.Dex && len(srcFiles) > 0 {
|
2015-03-31 08:20:39 +08:00
|
|
|
dxFlags := j.properties.Dxflags
|
|
|
|
if false /* emma enabled */ {
|
|
|
|
// If you instrument class files that have local variable debug information in
|
|
|
|
// them emma does not correctly maintain the local variable table.
|
|
|
|
// This will cause an error when you try to convert the class files for Android.
|
|
|
|
// The workaround here is to build different dex file here based on emma switch
|
|
|
|
// then later copy into classes.dex. When emma is on, dx is run with --no-locals
|
|
|
|
// option to remove local variable information
|
|
|
|
dxFlags = append(dxFlags, "--no-locals")
|
|
|
|
}
|
|
|
|
|
2015-04-08 08:11:30 +08:00
|
|
|
if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
|
2015-03-31 08:20:39 +08:00
|
|
|
dxFlags = append(dxFlags, "--no-optimize")
|
|
|
|
}
|
|
|
|
|
2015-04-08 08:11:30 +08:00
|
|
|
if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
|
2015-03-31 08:20:39 +08:00
|
|
|
dxFlags = append(dxFlags,
|
|
|
|
"--debug",
|
|
|
|
"--verbose",
|
|
|
|
"--dump-to="+filepath.Join(common.ModuleOutDir(ctx), "classes.lst"),
|
|
|
|
"--dump-width=1000")
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.dxFlags = strings.Join(dxFlags, " ")
|
|
|
|
|
|
|
|
// Compile classes.jar into classes.dex
|
2015-04-11 08:44:24 +08:00
|
|
|
dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags)
|
2015-03-31 08:20:39 +08:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Combine classes.dex + resources into javalib.jar
|
2015-04-11 08:44:24 +08:00
|
|
|
outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec)
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
2015-04-17 05:09:14 +08:00
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
j.outputFile = outputFile
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ JavaDependency = (*JavaLibrary)(nil)
|
|
|
|
|
|
|
|
func (j *javaBase) ClasspathFile() string {
|
|
|
|
return j.classpathFile
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *javaBase) ClassJarSpecs() []jarSpec {
|
|
|
|
return j.classJarSpecs
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *javaBase) ResourceJarSpecs() []jarSpec {
|
|
|
|
return j.resourceJarSpecs
|
|
|
|
}
|
|
|
|
|
2015-04-09 04:03:43 +08:00
|
|
|
func (j *javaBase) AidlIncludeDirs() []string {
|
|
|
|
return j.exportAidlIncludeDirs
|
|
|
|
}
|
|
|
|
|
2015-04-11 08:45:20 +08:00
|
|
|
var _ logtagsProducer = (*javaBase)(nil)
|
|
|
|
|
|
|
|
func (j *javaBase) logtags() []string {
|
|
|
|
return j.logtagsSrcs
|
|
|
|
}
|
|
|
|
|
2015-03-31 08:20:39 +08:00
|
|
|
//
|
|
|
|
// Java libraries (.jar file)
|
|
|
|
//
|
|
|
|
|
|
|
|
type JavaLibrary struct {
|
|
|
|
javaBase
|
|
|
|
}
|
|
|
|
|
2015-04-17 05:09:14 +08:00
|
|
|
func (j *JavaLibrary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
|
|
|
|
j.javaBase.GenerateJavaBuildActions(ctx)
|
|
|
|
|
|
|
|
j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.outputFile)
|
|
|
|
}
|
|
|
|
|
2015-03-31 08:20:39 +08:00
|
|
|
func JavaLibraryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &JavaLibrary{}
|
|
|
|
|
|
|
|
module.properties.Dex = true
|
|
|
|
|
|
|
|
return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported)
|
|
|
|
}
|
|
|
|
|
|
|
|
func JavaLibraryHostFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &JavaLibrary{}
|
|
|
|
|
|
|
|
return NewJavaBase(&module.javaBase, module, common.HostSupported)
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Java Binaries (.jar file plus wrapper script)
|
|
|
|
//
|
|
|
|
|
|
|
|
type JavaBinary struct {
|
|
|
|
JavaLibrary
|
|
|
|
|
|
|
|
binaryProperties struct {
|
|
|
|
// wrapper: installable script to execute the resulting jar
|
|
|
|
Wrapper string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *JavaBinary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
|
|
|
|
j.JavaLibrary.GenerateJavaBuildActions(ctx)
|
|
|
|
|
|
|
|
// Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
|
|
|
|
// another build rule before the jar has been installed.
|
|
|
|
ctx.InstallFile("bin", filepath.Join(common.ModuleSrcDir(ctx), j.binaryProperties.Wrapper),
|
|
|
|
j.installFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
func JavaBinaryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &JavaBinary{}
|
|
|
|
|
|
|
|
module.properties.Dex = true
|
|
|
|
|
|
|
|
return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported, &module.binaryProperties)
|
|
|
|
}
|
|
|
|
|
|
|
|
func JavaBinaryHostFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &JavaBinary{}
|
|
|
|
|
|
|
|
return NewJavaBase(&module.javaBase, module, common.HostSupported, &module.binaryProperties)
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Java prebuilts
|
|
|
|
//
|
|
|
|
|
|
|
|
type JavaPrebuilt struct {
|
|
|
|
common.AndroidModuleBase
|
|
|
|
|
|
|
|
properties struct {
|
2015-04-14 04:52:22 +08:00
|
|
|
Srcs []string
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2015-04-04 07:53:05 +08:00
|
|
|
classpathFile string
|
|
|
|
classJarSpecs, resourceJarSpecs []jarSpec
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
|
|
|
if len(j.properties.Srcs) != 1 {
|
|
|
|
ctx.ModuleErrorf("expected exactly one jar in srcs")
|
|
|
|
return
|
|
|
|
}
|
2015-04-04 07:53:05 +08:00
|
|
|
prebuilt := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Srcs[0])
|
|
|
|
|
|
|
|
classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt)
|
|
|
|
|
|
|
|
j.classpathFile = prebuilt
|
|
|
|
j.classJarSpecs = []jarSpec{classJarSpec}
|
|
|
|
j.resourceJarSpecs = []jarSpec{resourceJarSpec}
|
|
|
|
ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.classpathFile)
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ JavaDependency = (*JavaPrebuilt)(nil)
|
|
|
|
|
|
|
|
func (j *JavaPrebuilt) ClasspathFile() string {
|
|
|
|
return j.classpathFile
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *JavaPrebuilt) ClassJarSpecs() []jarSpec {
|
2015-04-04 07:53:05 +08:00
|
|
|
return j.classJarSpecs
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (j *JavaPrebuilt) ResourceJarSpecs() []jarSpec {
|
2015-04-04 07:53:05 +08:00
|
|
|
return j.resourceJarSpecs
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2015-04-09 04:03:43 +08:00
|
|
|
func (j *JavaPrebuilt) AidlIncludeDirs() []string {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-03-31 08:20:39 +08:00
|
|
|
func JavaPrebuiltFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &JavaPrebuilt{}
|
|
|
|
|
|
|
|
return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
|
|
|
|
common.MultilibCommon, &module.properties)
|
|
|
|
}
|
|
|
|
|
2015-04-14 04:52:22 +08:00
|
|
|
//
|
|
|
|
// SDK java prebuilts (.jar containing resources plus framework.aidl)
|
|
|
|
//
|
|
|
|
|
|
|
|
type sdkDependency interface {
|
|
|
|
JavaDependency
|
|
|
|
AidlPreprocessed() string
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ sdkDependency = (*sdkPrebuilt)(nil)
|
|
|
|
|
|
|
|
type sdkPrebuilt struct {
|
|
|
|
JavaPrebuilt
|
|
|
|
|
|
|
|
sdkProperties struct {
|
|
|
|
Aidl_preprocessed string
|
|
|
|
}
|
|
|
|
|
|
|
|
aidlPreprocessed string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
|
|
|
j.JavaPrebuilt.GenerateAndroidBuildActions(ctx)
|
|
|
|
|
|
|
|
if j.sdkProperties.Aidl_preprocessed != "" {
|
|
|
|
j.aidlPreprocessed = filepath.Join(common.ModuleSrcDir(ctx), j.sdkProperties.Aidl_preprocessed)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *sdkPrebuilt) AidlPreprocessed() string {
|
|
|
|
return j.aidlPreprocessed
|
|
|
|
}
|
|
|
|
|
|
|
|
func SdkPrebuiltFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &sdkPrebuilt{}
|
|
|
|
|
|
|
|
return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
|
|
|
|
common.MultilibCommon, &module.properties, &module.sdkProperties)
|
|
|
|
}
|
|
|
|
|
2015-03-31 08:20:39 +08:00
|
|
|
func inList(s string, l []string) bool {
|
|
|
|
for _, e := range l {
|
|
|
|
if e == s {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|