diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 134 |
1 files changed, 87 insertions, 47 deletions
diff --git a/java/java.go b/java/java.go index fa7c96eff..7258dcefd 100644 --- a/java/java.go +++ b/java/java.go @@ -27,6 +27,7 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" + "android/soong/cc" "android/soong/dexpreopt" "android/soong/java/config" "android/soong/tradefed" @@ -67,9 +68,32 @@ func registerJavaBuildComponents(ctx android.RegistrationContext) { func RegisterJavaSdkMemberTypes() { // Register sdk member types. android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType) + android.RegisterSdkMemberType(javaLibsSdkMemberType) + android.RegisterSdkMemberType(javaBootLibsSdkMemberType) + android.RegisterSdkMemberType(javaTestSdkMemberType) +} + +var ( + // Supports adding java header libraries to module_exports and sdk. + javaHeaderLibsSdkMemberType = &librarySdkMemberType{ + android.SdkMemberTypeBase{ + PropertyName: "java_header_libs", + SupportsSdk: true, + }, + func(_ android.SdkMemberContext, j *Library) android.Path { + headerJars := j.HeaderJars() + if len(headerJars) != 1 { + panic(fmt.Errorf("there must be only one header jar from %q", j.Name())) + } + + return headerJars[0] + }, + sdkSnapshotFilePathForJar, + copyEverythingToSnapshot, + } // Export implementation classes jar as part of the sdk. - exportImplementationClassesJar := func(_ android.SdkMemberContext, j *Library) android.Path { + exportImplementationClassesJar = func(_ android.SdkMemberContext, j *Library) android.Path { implementationJars := j.ImplementationAndResourcesJars() if len(implementationJars) != 1 { panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name())) @@ -77,17 +101,17 @@ func RegisterJavaSdkMemberTypes() { return implementationJars[0] } - // Register java implementation libraries for use only in module_exports (not sdk). - android.RegisterSdkMemberType(&librarySdkMemberType{ + // Supports adding java implementation libraries to module_exports but not sdk. + javaLibsSdkMemberType = &librarySdkMemberType{ android.SdkMemberTypeBase{ PropertyName: "java_libs", }, exportImplementationClassesJar, sdkSnapshotFilePathForJar, copyEverythingToSnapshot, - }) + } - // Register java boot libraries for use in sdk. + // Supports adding java boot libraries to module_exports and sdk. // // The build has some implicit dependencies (via the boot jars configuration) on a number of // modules, e.g. core-oj, apache-xml, that are part of the java boot class path and which are @@ -98,7 +122,7 @@ func RegisterJavaSdkMemberTypes() { // either java_libs, or java_header_libs would end up exporting more information than was strictly // necessary. The java_boot_libs property to allow those modules to be exported as part of the // sdk/module_exports without exposing any unnecessary information. - android.RegisterSdkMemberType(&librarySdkMemberType{ + javaBootLibsSdkMemberType = &librarySdkMemberType{ android.SdkMemberTypeBase{ PropertyName: "java_boot_libs", SupportsSdk: true, @@ -109,16 +133,15 @@ func RegisterJavaSdkMemberTypes() { exportImplementationClassesJar, sdkSnapshotFilePathForJar, onlyCopyJarToSnapshot, - }) + } - // Register java test libraries for use only in module_exports (not sdk). - android.RegisterSdkMemberType(&testSdkMemberType{ + // Supports adding java test libraries to module_exports but not sdk. + javaTestSdkMemberType = &testSdkMemberType{ SdkMemberTypeBase: android.SdkMemberTypeBase{ PropertyName: "java_tests", }, - }) - -} + } +) // JavaInfo contains information about a java module for use by modules that depend on it. type JavaInfo struct { @@ -356,7 +379,7 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext an if javaVersion != "" { return normalizeJavaVersion(ctx, javaVersion) } else if ctx.Device() { - return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion()) + return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx)) } else { return JAVA_VERSION_9 } @@ -463,6 +486,9 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { // would the <x> library if <x> was configured as a boot jar. j.initHiddenAPI(ctx, j.ConfigurationName()) + j.sdkVersion = j.SdkVersion(ctx) + j.minSdkVersion = j.MinSdkVersion(ctx) + apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) if !apexInfo.IsForPlatform() { j.hideApexVariantFromMake = true @@ -602,23 +628,6 @@ func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberConte } } -var javaHeaderLibsSdkMemberType android.SdkMemberType = &librarySdkMemberType{ - android.SdkMemberTypeBase{ - PropertyName: "java_header_libs", - SupportsSdk: true, - }, - func(_ android.SdkMemberContext, j *Library) android.Path { - headerJars := j.HeaderJars() - if len(headerJars) != 1 { - panic(fmt.Errorf("there must be only one header jar from %q", j.Name())) - } - - return headerJars[0] - }, - sdkSnapshotFilePathForJar, - copyEverythingToSnapshot, -} - // java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well. // // By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were @@ -705,6 +714,9 @@ type testProperties struct { // Test options. Test_options TestOptions + + // Names of modules containing JNI libraries that should be installed alongside the test. + Jni_libs []string } type hostTestProperties struct { @@ -766,6 +778,13 @@ func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) { } } + if len(j.testProperties.Jni_libs) > 0 { + for _, target := range ctx.MultiTargets() { + sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"}) + ctx.AddFarVariationDependencies(sharedLibVariations, jniLibTag, j.testProperties.Jni_libs...) + } + } + j.deps(ctx) } @@ -790,6 +809,29 @@ func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.data = append(j.data, android.OutputFileForModule(ctx, dep, "")) }) + ctx.VisitDirectDepsWithTag(jniLibTag, func(dep android.Module) { + sharedLibInfo := ctx.OtherModuleProvider(dep, cc.SharedLibraryInfoProvider).(cc.SharedLibraryInfo) + if sharedLibInfo.SharedLibrary != nil { + // Copy to an intermediate output directory to append "lib[64]" to the path, + // so that it's compatible with the default rpath values. + var relPath string + if sharedLibInfo.Target.Arch.ArchType.Multilib == "lib64" { + relPath = filepath.Join("lib64", sharedLibInfo.SharedLibrary.Base()) + } else { + relPath = filepath.Join("lib", sharedLibInfo.SharedLibrary.Base()) + } + relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath) + ctx.Build(pctx, android.BuildParams{ + Rule: android.Cp, + Input: sharedLibInfo.SharedLibrary, + Output: relocatedLib, + }) + j.data = append(j.data, relocatedLib) + } else { + ctx.PropertyErrorf("jni_libs", "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep)) + } + }) + j.Library.GenerateAndroidBuildActions(ctx) } @@ -1130,33 +1172,28 @@ type Import struct { exportAidlIncludeDirs android.Paths hideApexVariantFromMake bool -} -func (j *Import) SdkVersion() android.SdkSpec { - return android.SdkSpecFrom(String(j.properties.Sdk_version)) + sdkVersion android.SdkSpec + minSdkVersion android.SdkSpec } -func (j *Import) makeSdkVersion() string { - return j.SdkVersion().Raw +func (j *Import) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { + return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version)) } func (j *Import) SystemModules() string { return "none" } -func (j *Import) MinSdkVersion() android.SdkSpec { +func (j *Import) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { if j.properties.Min_sdk_version != nil { - return android.SdkSpecFrom(*j.properties.Min_sdk_version) + return android.SdkSpecFrom(ctx, *j.properties.Min_sdk_version) } - return j.SdkVersion() + return j.SdkVersion(ctx) } -func (j *Import) TargetSdkVersion() android.SdkSpec { - return j.SdkVersion() -} - -func (j *Import) MinSdkVersionString() string { - return j.MinSdkVersion().ApiLevel.String() +func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { + return j.SdkVersion(ctx) } func (j *Import) Prebuilt() *android.Prebuilt { @@ -1192,6 +1229,9 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { } func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { + j.sdkVersion = j.SdkVersion(ctx) + j.minSdkVersion = j.MinSdkVersion(ctx) + // Initialize the hiddenapi structure. j.initHiddenAPI(ctx, j.BaseModuleName()) @@ -1230,7 +1270,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { } else if dep, ok := module.(SdkLibraryDependency); ok { switch tag { case libTag: - flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion())...) + flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...) } } @@ -1291,7 +1331,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex var dexOutputFile android.OutputPath - dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(), outputFile, jarName) + dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), outputFile, jarName) if ctx.Failed() { return } @@ -1359,7 +1399,7 @@ func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu // Implements android.ApexModule func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { - sdkSpec := j.MinSdkVersion() + sdkSpec := j.MinSdkVersion(ctx) if !sdkSpec.Specified() { return fmt.Errorf("min_sdk_version is not specified") } |