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
|
2017-06-23 07:51:17 +08:00
|
|
|
// into the flags and filenames necessary to pass to the Module. The final creation of the rules
|
2015-03-31 08:20:39 +08:00
|
|
|
// is handled in builder.go
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
"android/soong/android"
|
2015-04-29 04:28:51 +08:00
|
|
|
"android/soong/genrule"
|
2017-06-23 08:20:19 +08:00
|
|
|
"android/soong/java/config"
|
2015-03-31 08:20:39 +08:00
|
|
|
)
|
|
|
|
|
2015-06-18 05:20:06 +08:00
|
|
|
func init() {
|
2017-07-08 05:35:50 +08:00
|
|
|
android.RegisterModuleType("java_defaults", defaultsFactory)
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
android.RegisterModuleType("java_library", LibraryFactory)
|
|
|
|
android.RegisterModuleType("java_library_static", LibraryFactory)
|
|
|
|
android.RegisterModuleType("java_library_host", LibraryHostFactory)
|
|
|
|
android.RegisterModuleType("java_binary", BinaryFactory)
|
|
|
|
android.RegisterModuleType("java_binary_host", BinaryHostFactory)
|
|
|
|
android.RegisterModuleType("java_prebuilt_library", PrebuiltFactory)
|
2017-07-20 02:22:16 +08:00
|
|
|
android.RegisterModuleType("android_prebuilt_sdk", SdkPrebuiltFactory)
|
2016-10-13 05:28:16 +08:00
|
|
|
android.RegisterModuleType("android_app", AndroidAppFactory)
|
|
|
|
|
|
|
|
android.RegisterSingletonType("logtags", LogtagsSingleton)
|
2015-06-18 05:20:06 +08:00
|
|
|
}
|
|
|
|
|
2015-03-31 08:20:39 +08:00
|
|
|
// TODO:
|
|
|
|
// Autogenerated files:
|
|
|
|
// Proto
|
|
|
|
// Renderscript
|
|
|
|
// Post-jar passes:
|
|
|
|
// Proguard
|
2017-06-23 06:36:39 +08:00
|
|
|
// Jacoco
|
2015-03-31 08:20:39 +08:00
|
|
|
// Jarjar
|
|
|
|
// Dex
|
|
|
|
// Rmtypedefs
|
|
|
|
// DroidDoc
|
|
|
|
// Findbugs
|
|
|
|
|
2017-07-08 05:35:50 +08:00
|
|
|
type CompilerProperties struct {
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of source files used to compile the Java module. May be .java, .logtags, .proto,
|
|
|
|
// or .aidl files.
|
2015-07-01 09:15:24 +08:00
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of source files that should not be used to build the Java module.
|
|
|
|
// This is most useful in the arch/multilib variants to remove non-common files
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of directories containing Java resources
|
2017-07-20 02:22:16 +08:00
|
|
|
Resource_dirs []string `android:"arch_variant"`
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-07-20 02:22:16 +08:00
|
|
|
// list of directories that should be excluded from resource_dirs
|
|
|
|
Exclude_resource_dirs []string `android:"arch_variant"`
|
2015-07-01 09:15:24 +08:00
|
|
|
|
2016-12-01 00:13:09 +08:00
|
|
|
// don't build against the default libraries (legacy-test, core-junit,
|
2015-05-12 04:39:40 +08:00
|
|
|
// ext, and framework for device targets)
|
|
|
|
No_standard_libraries bool
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of module-specific flags that will be used for javac compiles
|
|
|
|
Javacflags []string `android:"arch_variant"`
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of of java libraries that will be in the classpath
|
2017-07-20 02:22:16 +08:00
|
|
|
Libs []string `android:"arch_variant"`
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of java libraries that will be compiled into the resulting jar
|
2017-07-20 02:22:16 +08:00
|
|
|
Static_libs []string `android:"arch_variant"`
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// manifest file to be included in resulting jar
|
2015-09-24 06:26:20 +08:00
|
|
|
Manifest *string
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-06-23 08:01:52 +08:00
|
|
|
// if not blank, run jarjar using the specified rules file
|
|
|
|
Jarjar_rules *string
|
|
|
|
}
|
|
|
|
|
2017-07-08 05:35:50 +08:00
|
|
|
type CompilerDeviceProperties struct {
|
2017-06-23 08:01:52 +08:00
|
|
|
// list of module-specific flags that will be used for dex compiles
|
|
|
|
Dxflags []string `android:"arch_variant"`
|
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// if not blank, set to the version of the sdk to compile against
|
|
|
|
Sdk_version string
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// Set for device java libraries, and for host versions of device java libraries
|
|
|
|
// built for testing
|
|
|
|
Dex bool `blueprint:"mutated"`
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// directories to pass to aidl tool
|
|
|
|
Aidl_includes []string
|
2015-04-09 04:03:43 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// 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-04-09 04:03:43 +08:00
|
|
|
|
2017-06-23 07:51:17 +08:00
|
|
|
// Module contains the properties and members used by all java module types
|
|
|
|
type Module struct {
|
2016-05-19 06:37:25 +08:00
|
|
|
android.ModuleBase
|
2017-07-08 05:35:50 +08:00
|
|
|
android.DefaultableModuleBase
|
2015-05-12 04:39:40 +08:00
|
|
|
|
2017-07-08 05:35:50 +08:00
|
|
|
properties CompilerProperties
|
|
|
|
deviceProperties CompilerDeviceProperties
|
2015-03-31 08:20:39 +08:00
|
|
|
|
|
|
|
// output file suitable for inserting into the classpath of another compile
|
2016-05-19 06:37:25 +08:00
|
|
|
classpathFile android.Path
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2015-04-17 05:09:14 +08:00
|
|
|
// output file suitable for installing or running
|
2016-05-19 06:37:25 +08:00
|
|
|
outputFile android.Path
|
2015-04-17 05:09:14 +08:00
|
|
|
|
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
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
exportAidlIncludeDirs android.Paths
|
2015-04-09 04:03:43 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
logtagsSrcs android.Paths
|
2015-04-11 08:45:20 +08:00
|
|
|
|
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
|
2016-05-19 06:37:25 +08:00
|
|
|
ExtraSrcLists android.Paths
|
2015-04-17 05:09:14 +08:00
|
|
|
|
2015-03-31 08:20:39 +08:00
|
|
|
// installed file for binary dependency
|
2016-05-19 06:37:25 +08:00
|
|
|
installFile android.Path
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
type Dependency interface {
|
2016-05-19 06:37:25 +08:00
|
|
|
ClasspathFile() android.Path
|
2015-03-31 08:20:39 +08:00
|
|
|
ClassJarSpecs() []jarSpec
|
|
|
|
ResourceJarSpecs() []jarSpec
|
2016-05-19 06:37:25 +08:00
|
|
|
AidlIncludeDirs() android.Paths
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-08 05:35:50 +08:00
|
|
|
func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
|
|
|
|
android.InitAndroidArchModule(module, hod, android.MultilibCommon)
|
|
|
|
android.InitDefaultableModule(module)
|
|
|
|
}
|
|
|
|
|
2017-07-08 06:59:46 +08:00
|
|
|
type dependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-08 06:59:46 +08:00
|
|
|
var (
|
2017-07-20 06:53:04 +08:00
|
|
|
staticLibTag = dependencyTag{name: "staticlib"}
|
|
|
|
libTag = dependencyTag{name: "javalib"}
|
2017-07-08 06:59:46 +08:00
|
|
|
bootClasspathTag = dependencyTag{name: "bootclasspath"}
|
|
|
|
frameworkResTag = dependencyTag{name: "framework-res"}
|
|
|
|
sdkDependencyTag = dependencyTag{name: "sdk"}
|
|
|
|
)
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-07-08 06:59:46 +08:00
|
|
|
func (j *Module) deps(ctx android.BottomUpMutatorContext) {
|
2015-03-31 08:20:39 +08:00
|
|
|
if !j.properties.No_standard_libraries {
|
2017-07-08 06:59:46 +08:00
|
|
|
if ctx.Device() {
|
|
|
|
switch j.deviceProperties.Sdk_version {
|
|
|
|
case "":
|
|
|
|
ctx.AddDependency(ctx.Module(), bootClasspathTag, "core-libart")
|
|
|
|
case "current":
|
|
|
|
// TODO: !TARGET_BUILD_APPS
|
|
|
|
// TODO: export preprocessed framework.aidl from android_stubs_current
|
|
|
|
ctx.AddDependency(ctx.Module(), bootClasspathTag, "android_stubs_current")
|
|
|
|
case "system_current":
|
|
|
|
ctx.AddDependency(ctx.Module(), bootClasspathTag, "android_system_stubs_current")
|
|
|
|
default:
|
|
|
|
ctx.AddDependency(ctx.Module(), sdkDependencyTag, "sdk_v"+j.deviceProperties.Sdk_version)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if j.deviceProperties.Dex {
|
|
|
|
ctx.AddDependency(ctx.Module(), bootClasspathTag, "core-libart")
|
|
|
|
}
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
2017-07-08 06:59:46 +08:00
|
|
|
|
2017-06-23 08:01:52 +08:00
|
|
|
if ctx.Device() && j.deviceProperties.Sdk_version == "" {
|
2017-07-20 06:53:04 +08:00
|
|
|
ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
|
2015-04-17 05:08:06 +08:00
|
|
|
}
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
2017-07-20 06:53:04 +08:00
|
|
|
ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
|
|
|
|
ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 07:51:17 +08:00
|
|
|
func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
|
2016-05-19 06:37:25 +08:00
|
|
|
aidlIncludeDirs android.Paths) []string {
|
2015-04-09 04:03:43 +08:00
|
|
|
|
2017-06-23 08:01:52 +08:00
|
|
|
localAidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl_includes)
|
2015-04-09 04:03:43 +08:00
|
|
|
|
|
|
|
var flags []string
|
2015-09-24 06:26:20 +08:00
|
|
|
if aidlPreprocess.Valid() {
|
|
|
|
flags = append(flags, "-p"+aidlPreprocess.String())
|
2015-04-09 04:03:43 +08:00
|
|
|
} else {
|
2016-05-19 06:37:25 +08:00
|
|
|
flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
|
2015-04-09 04:03:43 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
|
|
|
|
flags = append(flags, android.JoinWithPrefix(localAidlIncludes.Strings(), "-I"))
|
|
|
|
flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
|
2017-07-14 05:41:17 +08:00
|
|
|
if src := android.ExistentPathForSource(ctx, "", "src"); src.Valid() {
|
|
|
|
flags = append(flags, "-I"+src.String())
|
|
|
|
}
|
2015-04-09 04:03:43 +08:00
|
|
|
|
2015-04-14 04:53:40 +08:00
|
|
|
return flags
|
2015-04-09 04:03:43 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 07:51:17 +08:00
|
|
|
func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths,
|
2016-05-19 06:37:25 +08:00
|
|
|
bootClasspath android.OptionalPath, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess android.OptionalPath,
|
|
|
|
aidlIncludeDirs android.Paths, srcFileLists android.Paths) {
|
2015-03-31 08:20:39 +08:00
|
|
|
|
|
|
|
ctx.VisitDirectDeps(func(module blueprint.Module) {
|
|
|
|
otherName := ctx.OtherModuleName(module)
|
2017-07-08 05:47:12 +08:00
|
|
|
tag := ctx.OtherModuleDependencyTag(module)
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
dep, _ := module.(Dependency)
|
|
|
|
if dep == nil {
|
2017-07-08 05:47:12 +08:00
|
|
|
switch tag {
|
|
|
|
case android.DefaultsDepTag, android.SourceDepTag:
|
|
|
|
default:
|
|
|
|
ctx.ModuleErrorf("depends on non-java module %q", otherName)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-07-08 06:59:46 +08:00
|
|
|
switch tag {
|
|
|
|
case bootClasspathTag:
|
2017-07-20 06:53:04 +08:00
|
|
|
bootClasspath = android.OptionalPathForPath(dep.ClasspathFile())
|
|
|
|
case libTag:
|
|
|
|
classpath = append(classpath, dep.ClasspathFile())
|
|
|
|
case staticLibTag:
|
|
|
|
classpath = append(classpath, dep.ClasspathFile())
|
|
|
|
classJarSpecs = append(classJarSpecs, dep.ClassJarSpecs()...)
|
|
|
|
resourceJarSpecs = append(resourceJarSpecs, dep.ResourceJarSpecs()...)
|
2017-07-08 06:59:46 +08:00
|
|
|
case frameworkResTag:
|
2017-07-08 05:47:12 +08:00
|
|
|
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.(*AndroidApp).aaptJavaFileList)
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
2017-07-08 06:59:46 +08:00
|
|
|
case sdkDependencyTag:
|
|
|
|
sdkDep := module.(sdkDependency)
|
2017-07-08 05:47:12 +08:00
|
|
|
if sdkDep.AidlPreprocessed().Valid() {
|
|
|
|
if aidlPreprocess.Valid() {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2017-07-08 06:59:46 +08:00
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
2017-07-08 06:59:46 +08:00
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
aidlIncludeDirs = append(aidlIncludeDirs, dep.AidlIncludeDirs()...)
|
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
|
|
|
}
|
|
|
|
|
2017-06-23 07:51:17 +08:00
|
|
|
func (j *Module) compile(ctx android.ModuleContext) {
|
2015-04-09 04:03:43 +08:00
|
|
|
|
2017-06-23 08:01:52 +08:00
|
|
|
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Export_aidl_include_dirs)
|
2015-04-09 04:03:43 +08:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
var deps android.Paths
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
if bootClasspath.Valid() {
|
|
|
|
flags.bootClasspath = "-bootclasspath " + bootClasspath.String()
|
2017-07-20 06:53:04 +08:00
|
|
|
deps = append(deps, bootClasspath.Path())
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(classpath) > 0 {
|
2015-09-24 06:26:20 +08:00
|
|
|
flags.classpath = "-classpath " + strings.Join(classpath.Strings(), ":")
|
2017-07-20 06:53:04 +08:00
|
|
|
deps = append(deps, classpath...)
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2015-07-01 09:15:24 +08:00
|
|
|
srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
|
2015-04-09 04:03:43 +08:00
|
|
|
|
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
|
2017-07-20 06:53:04 +08:00
|
|
|
classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, deps)
|
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
|
|
|
}
|
|
|
|
|
2017-07-20 02:22:16 +08:00
|
|
|
resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Resource_dirs, j.properties.Exclude_resource_dirs),
|
2015-04-21 04:51:48 +08:00
|
|
|
resourceJarSpecs...)
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
|
2015-03-31 08:20:39 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
if j.properties.Jarjar_rules != nil {
|
2016-05-19 06:37:25 +08:00
|
|
|
jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
|
2015-04-04 07:54:17 +08:00
|
|
|
// 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
|
|
|
|
|
2017-06-23 08:01:52 +08:00
|
|
|
if j.deviceProperties.Dex && len(srcFiles) > 0 {
|
|
|
|
dxFlags := j.deviceProperties.Dxflags
|
2015-03-31 08:20:39 +08:00
|
|
|
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",
|
2016-05-19 06:37:25 +08:00
|
|
|
"--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(),
|
2015-03-31 08:20:39 +08:00
|
|
|
"--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
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
var _ Dependency = (*Library)(nil)
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-06-23 07:51:17 +08:00
|
|
|
func (j *Module) ClasspathFile() android.Path {
|
2015-03-31 08:20:39 +08:00
|
|
|
return j.classpathFile
|
|
|
|
}
|
|
|
|
|
2017-06-23 07:51:17 +08:00
|
|
|
func (j *Module) ClassJarSpecs() []jarSpec {
|
2015-03-31 08:20:39 +08:00
|
|
|
return j.classJarSpecs
|
|
|
|
}
|
|
|
|
|
2017-06-23 07:51:17 +08:00
|
|
|
func (j *Module) ResourceJarSpecs() []jarSpec {
|
2015-03-31 08:20:39 +08:00
|
|
|
return j.resourceJarSpecs
|
|
|
|
}
|
|
|
|
|
2017-06-23 07:51:17 +08:00
|
|
|
func (j *Module) AidlIncludeDirs() android.Paths {
|
2015-04-09 04:03:43 +08:00
|
|
|
return j.exportAidlIncludeDirs
|
|
|
|
}
|
|
|
|
|
2017-06-23 07:51:17 +08:00
|
|
|
var _ logtagsProducer = (*Module)(nil)
|
2015-04-11 08:45:20 +08:00
|
|
|
|
2017-06-23 07:51:17 +08:00
|
|
|
func (j *Module) logtags() android.Paths {
|
2015-04-11 08:45:20 +08:00
|
|
|
return j.logtagsSrcs
|
|
|
|
}
|
|
|
|
|
2015-03-31 08:20:39 +08:00
|
|
|
//
|
|
|
|
// Java libraries (.jar file)
|
|
|
|
//
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
type Library struct {
|
2017-06-23 07:51:17 +08:00
|
|
|
Module
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2017-06-23 07:51:17 +08:00
|
|
|
j.compile(ctx)
|
2015-04-17 05:09:14 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
j.installFile = ctx.InstallFileName(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.outputFile)
|
2015-04-17 05:09:14 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2017-06-23 07:51:17 +08:00
|
|
|
j.deps(ctx)
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func LibraryFactory() android.Module {
|
|
|
|
module := &Library{}
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-06-23 08:01:52 +08:00
|
|
|
module.deviceProperties.Dex = true
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-06-24 06:06:31 +08:00
|
|
|
module.AddProperties(
|
2017-06-23 08:01:52 +08:00
|
|
|
&module.Module.properties,
|
|
|
|
&module.Module.deviceProperties)
|
2017-06-24 06:06:31 +08:00
|
|
|
|
2017-07-08 05:35:50 +08:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
2017-06-24 06:06:31 +08:00
|
|
|
return module
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func LibraryHostFactory() android.Module {
|
|
|
|
module := &Library{}
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-06-24 06:06:31 +08:00
|
|
|
module.AddProperties(&module.Module.properties)
|
|
|
|
|
2017-07-08 05:35:50 +08:00
|
|
|
InitJavaModule(module, android.HostSupported)
|
2017-06-24 06:06:31 +08:00
|
|
|
return module
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Java Binaries (.jar file plus wrapper script)
|
|
|
|
//
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
type binaryProperties struct {
|
2015-05-12 04:39:40 +08:00
|
|
|
// installable script to execute the resulting jar
|
|
|
|
Wrapper string
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
type Binary struct {
|
|
|
|
Library
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
binaryProperties binaryProperties
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
j.Library.GenerateAndroidBuildActions(ctx)
|
2015-03-31 08:20:39 +08:00
|
|
|
|
|
|
|
// 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.
|
2016-05-19 06:37:25 +08:00
|
|
|
ctx.InstallFile(android.PathForModuleInstall(ctx, "bin"), android.PathForModuleSrc(ctx, j.binaryProperties.Wrapper),
|
2015-03-31 08:20:39 +08:00
|
|
|
j.installFile)
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2017-06-23 07:51:17 +08:00
|
|
|
j.deps(ctx)
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func BinaryFactory() android.Module {
|
|
|
|
module := &Binary{}
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-06-23 08:01:52 +08:00
|
|
|
module.deviceProperties.Dex = true
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-06-24 06:06:31 +08:00
|
|
|
module.AddProperties(
|
2017-06-23 08:01:52 +08:00
|
|
|
&module.Module.properties,
|
|
|
|
&module.Module.deviceProperties,
|
|
|
|
&module.binaryProperties)
|
2017-06-24 06:06:31 +08:00
|
|
|
|
2017-07-08 05:35:50 +08:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
2017-06-24 06:06:31 +08:00
|
|
|
return module
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func BinaryHostFactory() android.Module {
|
|
|
|
module := &Binary{}
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-06-24 06:06:31 +08:00
|
|
|
module.AddProperties(
|
2017-06-23 08:01:52 +08:00
|
|
|
&module.Module.properties,
|
|
|
|
&module.Module.deviceProperties,
|
|
|
|
&module.binaryProperties)
|
2017-06-24 06:06:31 +08:00
|
|
|
|
2017-07-08 05:35:50 +08:00
|
|
|
InitJavaModule(module, android.HostSupported)
|
2017-06-24 06:06:31 +08:00
|
|
|
return module
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Java prebuilts
|
|
|
|
//
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
type Prebuilt struct {
|
2016-05-19 06:37:25 +08:00
|
|
|
android.ModuleBase
|
2017-07-08 05:47:12 +08:00
|
|
|
prebuilt android.Prebuilt
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
classpathFile android.Path
|
2015-04-04 07:53:05 +08:00
|
|
|
classJarSpecs, resourceJarSpecs []jarSpec
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Prebuilt) Prebuilt() *android.Prebuilt {
|
2017-07-08 05:47:12 +08:00
|
|
|
return &j.prebuilt
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2016-10-13 05:38:15 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2017-07-08 06:59:46 +08:00
|
|
|
prebuilt := j.prebuilt.Path(ctx)
|
2015-04-04 07:53:05 +08:00
|
|
|
|
|
|
|
classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt)
|
|
|
|
|
|
|
|
j.classpathFile = prebuilt
|
|
|
|
j.classJarSpecs = []jarSpec{classJarSpec}
|
|
|
|
j.resourceJarSpecs = []jarSpec{resourceJarSpec}
|
2016-05-19 06:37:25 +08:00
|
|
|
ctx.InstallFileName(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.classpathFile)
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
var _ Dependency = (*Prebuilt)(nil)
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Prebuilt) ClasspathFile() android.Path {
|
2015-03-31 08:20:39 +08:00
|
|
|
return j.classpathFile
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Prebuilt) ClassJarSpecs() []jarSpec {
|
2015-04-04 07:53:05 +08:00
|
|
|
return j.classJarSpecs
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Prebuilt) ResourceJarSpecs() []jarSpec {
|
2015-04-04 07:53:05 +08:00
|
|
|
return j.resourceJarSpecs
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Prebuilt) AidlIncludeDirs() android.Paths {
|
2015-04-09 04:03:43 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func PrebuiltFactory() android.Module {
|
|
|
|
module := &Prebuilt{}
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-07-08 06:59:46 +08:00
|
|
|
module.AddProperties(&module.prebuilt.Properties)
|
2017-06-24 06:06:31 +08:00
|
|
|
|
|
|
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
|
|
|
|
return module
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2015-04-14 04:52:22 +08:00
|
|
|
//
|
|
|
|
// SDK java prebuilts (.jar containing resources plus framework.aidl)
|
|
|
|
//
|
|
|
|
|
|
|
|
type sdkDependency interface {
|
2017-07-20 06:53:04 +08:00
|
|
|
Dependency
|
2016-05-19 06:37:25 +08:00
|
|
|
AidlPreprocessed() android.OptionalPath
|
2015-04-14 04:52:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ sdkDependency = (*sdkPrebuilt)(nil)
|
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
type sdkPrebuiltProperties struct {
|
2015-09-24 06:26:20 +08:00
|
|
|
Aidl_preprocessed *string
|
2015-05-12 04:39:40 +08:00
|
|
|
}
|
|
|
|
|
2015-04-14 04:52:22 +08:00
|
|
|
type sdkPrebuilt struct {
|
2017-07-20 06:53:04 +08:00
|
|
|
Prebuilt
|
2015-04-14 04:52:22 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
sdkProperties sdkPrebuiltProperties
|
2015-04-14 04:52:22 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
aidlPreprocessed android.OptionalPath
|
2015-04-14 04:52:22 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2017-07-20 06:53:04 +08:00
|
|
|
j.Prebuilt.GenerateAndroidBuildActions(ctx)
|
2015-04-14 04:52:22 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
j.aidlPreprocessed = android.OptionalPathForModuleSrc(ctx, j.sdkProperties.Aidl_preprocessed)
|
2015-04-14 04:52:22 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func (j *sdkPrebuilt) AidlPreprocessed() android.OptionalPath {
|
2015-04-14 04:52:22 +08:00
|
|
|
return j.aidlPreprocessed
|
|
|
|
}
|
|
|
|
|
2017-06-24 06:06:31 +08:00
|
|
|
func SdkPrebuiltFactory() android.Module {
|
2015-04-14 04:52:22 +08:00
|
|
|
module := &sdkPrebuilt{}
|
|
|
|
|
2017-06-24 06:06:31 +08:00
|
|
|
module.AddProperties(
|
2017-07-08 06:59:46 +08:00
|
|
|
&module.prebuilt.Properties,
|
2017-06-24 06:06:31 +08:00
|
|
|
&module.sdkProperties)
|
|
|
|
|
|
|
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
|
|
|
|
return module
|
2015-04-14 04:52:22 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
2017-07-08 05:35:50 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Defaults
|
|
|
|
//
|
|
|
|
type Defaults struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultsModuleBase
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultsFactory() android.Module {
|
|
|
|
return DefaultsFactory()
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultsFactory(props ...interface{}) android.Module {
|
|
|
|
module := &Defaults{}
|
|
|
|
|
|
|
|
module.AddProperties(props...)
|
|
|
|
module.AddProperties(
|
|
|
|
&CompilerProperties{},
|
|
|
|
&CompilerDeviceProperties{},
|
|
|
|
)
|
|
|
|
|
|
|
|
android.InitDefaultsModule(module)
|
|
|
|
|
|
|
|
return module
|
|
|
|
}
|