summaryrefslogtreecommitdiff
path: root/java/java.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/java.go')
-rw-r--r--java/java.go205
1 files changed, 108 insertions, 97 deletions
diff --git a/java/java.go b/java/java.go
index 135ae514c..0188cf1a2 100644
--- a/java/java.go
+++ b/java/java.go
@@ -23,14 +23,12 @@ import (
"path/filepath"
"strconv"
"strings"
- "sync"
"github.com/google/blueprint"
"github.com/google/blueprint/pathtools"
"github.com/google/blueprint/proptools"
"android/soong/android"
- "android/soong/dexpreopt"
"android/soong/java/config"
"android/soong/tradefed"
)
@@ -60,8 +58,6 @@ func init() {
PropertyName: "java_tests",
},
})
-
- android.PostDepsMutators(RegisterPostDepsMutators)
}
func RegisterJavaBuildComponents(ctx android.RegistrationContext) {
@@ -90,44 +86,6 @@ func RegisterJavaBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
}
-func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
- ctx.BottomUp("ordered_system_server_jars", systemServerJarsDepsMutator)
-}
-
-var (
- dexpreoptedSystemServerJarsKey = android.NewOnceKey("dexpreoptedSystemServerJars")
- dexpreoptedSystemServerJarsLock sync.Mutex
-)
-
-func DexpreoptedSystemServerJars(config android.Config) *[]string {
- return config.Once(dexpreoptedSystemServerJarsKey, func() interface{} {
- return &[]string{}
- }).(*[]string)
-}
-
-// A PostDepsMutator pass that enforces total order on non-updatable system server jars. A total
-// order is neededed because such jars must be dexpreopted together (each jar on the list must have
-// all preceding jars in its class loader context). The total order must be compatible with the
-// partial order imposed by genuine dependencies between system server jars (which is not always
-// respected by the PRODUCT_SYSTEM_SERVER_JARS variable).
-//
-// An earlier mutator pass creates genuine dependencies, and this pass traverses the jars in that
-// order (which is partial and non-deterministic). This pass adds additional dependencies between
-// jars, making the order total and deterministic. It also constructs a global ordered list.
-func systemServerJarsDepsMutator(ctx android.BottomUpMutatorContext) {
- jars := dexpreopt.NonUpdatableSystemServerJars(ctx, dexpreopt.GetGlobalConfig(ctx))
- name := ctx.ModuleName()
- if android.InList(name, jars) {
- dexpreoptedSystemServerJarsLock.Lock()
- defer dexpreoptedSystemServerJarsLock.Unlock()
- jars := DexpreoptedSystemServerJars(ctx.Config())
- for _, dep := range *jars {
- ctx.AddDependency(ctx.Module(), dexpreopt.SystemServerDepTag, dep)
- }
- *jars = append(*jars, name)
- }
-}
-
func (j *Module) checkSdkVersion(ctx android.ModuleContext) {
if j.SocSpecific() || j.DeviceSpecific() ||
(j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
@@ -711,11 +669,6 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
} else if j.shouldInstrumentStatic(ctx) {
ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
}
-
- // services depend on com.android.location.provider, but dependency in not registered in a Blueprint file
- if ctx.ModuleName() == "services" {
- ctx.AddDependency(ctx.Module(), dexpreopt.SystemServerForcedDepTag, "com.android.location.provider")
- }
}
func hasSrcExt(srcs []string, ext string) bool {
@@ -847,7 +800,7 @@ func (m *Module) getLinkType(name string) (ret linkType, stubs bool) {
return javaModule, true
case ver.kind == sdkModule:
return javaModule, false
- case name == "services-stubs":
+ case name == "android_system_server_stubs_current":
return javaSystemServer, true
case ver.kind == sdkSystemServer:
return javaSystemServer, false
@@ -1796,11 +1749,16 @@ func (j *Module) hasCode(ctx android.ModuleContext) bool {
}
func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
- depTag := ctx.OtherModuleDependencyTag(dep)
// Dependencies other than the static linkage are all considered crossing APEX boundary
+ if staticLibTag == ctx.OtherModuleDependencyTag(dep) {
+ return true
+ }
// Also, a dependency to an sdk member is also considered as such. This is required because
// sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator.
- return depTag == staticLibTag || j.IsInAnySdk()
+ if sa, ok := dep.(android.SdkAware); ok && sa.IsInAnySdk() {
+ return true
+ }
+ return false
}
func (j *Module) Stem() string {
@@ -1879,12 +1837,12 @@ const (
)
// path to the jar file of a java library. Relative to <sdk_root>/<api_dir>
-func sdkSnapshotFilePathForJar(member android.SdkMember) string {
- return sdkSnapshotFilePathForMember(member, jarFileSuffix)
+func sdkSnapshotFilePathForJar(osPrefix, name string) string {
+ return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix)
}
-func sdkSnapshotFilePathForMember(member android.SdkMember, suffix string) string {
- return filepath.Join(javaDir, member.Name()+suffix)
+func sdkSnapshotFilePathForMember(osPrefix, name string, suffix string) string {
+ return filepath.Join(javaDir, osPrefix, name+suffix)
}
type librarySdkMemberType struct {
@@ -1904,32 +1862,52 @@ func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
return ok
}
-func (mt *librarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
+func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
+ return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import")
+}
+
+func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
+ return &librarySdkMemberProperties{}
+}
- variants := member.Variants()
- if len(variants) != 1 {
- sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
- for _, variant := range variants {
- sdkModuleContext.ModuleErrorf(" %q", variant)
- }
- }
- variant := variants[0]
+type librarySdkMemberProperties struct {
+ android.SdkMemberPropertiesBase
+
+ JarToExport android.Path
+ AidlIncludeDirs android.Paths
+}
+
+func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
j := variant.(*Library)
- exportedJar := mt.jarToExportGetter(j)
- snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member)
- builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
+ p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(j)
+ p.AidlIncludeDirs = j.AidlIncludeDirs()
+}
+
+func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
+ builder := ctx.SnapshotBuilder()
- for _, dir := range j.AidlIncludeDirs() {
- // TODO(jiyong): copy parcelable declarations only
- aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil)
- for _, file := range aidlFiles {
- builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file))
- }
+ exportedJar := p.JarToExport
+ if exportedJar != nil {
+ snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name())
+ builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
+
+ propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
}
- module := builder.AddPrebuiltModule(member, "java_import")
- module.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
+ aidlIncludeDirs := p.AidlIncludeDirs
+ if len(aidlIncludeDirs) != 0 {
+ sdkModuleContext := ctx.SdkModuleContext()
+ for _, dir := range aidlIncludeDirs {
+ // TODO(jiyong): copy parcelable declarations only
+ aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil)
+ for _, file := range aidlFiles {
+ builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file))
+ }
+ }
+
+ // TODO(b/151933053) - add aidl include dirs property
+ }
}
var javaHeaderLibsSdkMemberType android.SdkMemberType = &librarySdkMemberType{
@@ -2094,31 +2072,50 @@ func (mt *testSdkMemberType) IsInstance(module android.Module) bool {
return ok
}
-func (mt *testSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
- variants := member.Variants()
- if len(variants) != 1 {
- sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
- for _, variant := range variants {
- sdkModuleContext.ModuleErrorf(" %q", variant)
- }
- }
- variant := variants[0]
- j := variant.(*Test)
+func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
+ return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import")
+}
+
+func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
+ return &testSdkMemberProperties{}
+}
+
+type testSdkMemberProperties struct {
+ android.SdkMemberPropertiesBase
- implementationJars := j.ImplementationJars()
+ JarToExport android.Path
+ TestConfig android.Path
+}
+
+func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
+ test := variant.(*Test)
+
+ implementationJars := test.ImplementationJars()
if len(implementationJars) != 1 {
- panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
+ panic(fmt.Errorf("there must be only one implementation jar from %q", test.Name()))
}
- snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member)
- builder.CopyToSnapshot(implementationJars[0], snapshotRelativeJavaLibPath)
+ p.JarToExport = implementationJars[0]
+ p.TestConfig = test.testConfig
+}
+
+func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
+ builder := ctx.SnapshotBuilder()
+
+ exportedJar := p.JarToExport
+ if exportedJar != nil {
+ snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name())
+ builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
- snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(member, testConfigSuffix)
- builder.CopyToSnapshot(j.testConfig, snapshotRelativeTestConfigPath)
+ propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
+ }
- module := builder.AddPrebuiltModule(member, "java_test_import")
- module.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
- module.AddProperty("test_config", snapshotRelativeTestConfigPath)
+ testConfig := p.TestConfig
+ if testConfig != nil {
+ snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), ctx.Name(), testConfigSuffix)
+ builder.CopyToSnapshot(testConfig, snapshotRelativeTestConfigPath)
+ propertySet.AddProperty("test_config", snapshotRelativeTestConfigPath)
+ }
}
// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
@@ -2321,7 +2318,7 @@ func BinaryHostFactory() android.Module {
//
type ImportProperties struct {
- Jars []string `android:"path"`
+ Jars []string `android:"path,arch_variant"`
Sdk_version *string
@@ -2341,6 +2338,12 @@ type ImportProperties struct {
// set the name of the output
Stem *string
+
+ Aidl struct {
+ // directories that should be added as include directories for any aidl sources of modules
+ // that depend on this module, as well as to aidl for this module.
+ Export_include_dirs []string
+ }
}
type Import struct {
@@ -2354,6 +2357,7 @@ type Import struct {
combinedClasspathFile android.Path
exportedSdkLibs []string
+ exportAidlIncludeDirs android.Paths
}
func (j *Import) sdkVersion() sdkSpec {
@@ -2427,6 +2431,8 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
jarName, outputFile)
}
+
+ j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs)
}
var _ Dependency = (*Import)(nil)
@@ -2461,7 +2467,7 @@ func (j *Import) DexJar() android.Path {
}
func (j *Import) AidlIncludeDirs() android.Paths {
- return nil
+ return j.exportAidlIncludeDirs
}
func (j *Import) ExportedSdkLibs() []string {
@@ -2477,11 +2483,16 @@ func (j *Import) SrcJarArgs() ([]string, android.Paths) {
}
func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
- depTag := ctx.OtherModuleDependencyTag(dep)
// dependencies other than the static linkage are all considered crossing APEX boundary
+ if staticLibTag == ctx.OtherModuleDependencyTag(dep) {
+ return true
+ }
// Also, a dependency to an sdk member is also considered as such. This is required because
// sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator.
- return depTag == staticLibTag || j.IsInAnySdk()
+ if sa, ok := dep.(android.SdkAware); ok && sa.IsInAnySdk() {
+ return true
+ }
+ return false
}
// Add compile time check for interface implementation