Merge "add java_import to mixed build"
This commit is contained in:
@@ -217,6 +217,7 @@ var (
|
|||||||
"system/unwinding/libunwindstack": Bp2BuildDefaultTrueRecursively,
|
"system/unwinding/libunwindstack": Bp2BuildDefaultTrueRecursively,
|
||||||
"tools/apksig": Bp2BuildDefaultTrue,
|
"tools/apksig": Bp2BuildDefaultTrue,
|
||||||
"tools/platform-compat/java/android/compat": Bp2BuildDefaultTrueRecursively,
|
"tools/platform-compat/java/android/compat": Bp2BuildDefaultTrueRecursively,
|
||||||
|
"tools/tradefederation/prebuilts/filegroups": Bp2BuildDefaultTrueRecursively,
|
||||||
}
|
}
|
||||||
|
|
||||||
Bp2buildKeepExistingBuildFile = map[string]bool{
|
Bp2buildKeepExistingBuildFile = map[string]bool{
|
||||||
@@ -526,5 +527,20 @@ var (
|
|||||||
"simpleperf_ndk",
|
"simpleperf_ndk",
|
||||||
"toybox-static",
|
"toybox-static",
|
||||||
"zlib_bench",
|
"zlib_bench",
|
||||||
|
|
||||||
|
// java_import[_host] issues
|
||||||
|
// tradefed prebuilts depend on libprotobuf
|
||||||
|
"prebuilt_tradefed",
|
||||||
|
"prebuilt_tradefed-test-framework",
|
||||||
|
// handcrafted BUILD.bazel files in //prebuilts/...
|
||||||
|
"prebuilt_r8lib-prebuilt",
|
||||||
|
"prebuilt_sdk-core-lambda-stubs",
|
||||||
|
"prebuilt_android-support-collections-nodeps",
|
||||||
|
"prebuilt_android-arch-core-common-nodeps",
|
||||||
|
"prebuilt_android-arch-lifecycle-common-java8-nodeps",
|
||||||
|
"prebuilt_android-arch-lifecycle-common-nodeps",
|
||||||
|
"prebuilt_android-support-annotations-nodeps",
|
||||||
|
"prebuilt_android-arch-paging-common-nodeps",
|
||||||
|
"prebuilt_android-arch-room-common-nodeps",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
93
java/java.go
93
java/java.go
@@ -24,6 +24,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"android/soong/bazel"
|
"android/soong/bazel"
|
||||||
|
"android/soong/bazel/cquery"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
@@ -1610,7 +1611,8 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (j *Import) commonBuildActions(ctx android.ModuleContext) {
|
||||||
|
//TODO(b/231322772) these should come from Bazel once available
|
||||||
j.sdkVersion = j.SdkVersion(ctx)
|
j.sdkVersion = j.SdkVersion(ctx)
|
||||||
j.minSdkVersion = j.MinSdkVersion(ctx)
|
j.minSdkVersion = j.MinSdkVersion(ctx)
|
||||||
|
|
||||||
@@ -1621,6 +1623,10 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
if ctx.Windows() {
|
if ctx.Windows() {
|
||||||
j.HideFromMake()
|
j.HideFromMake()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
|
j.commonBuildActions(ctx)
|
||||||
|
|
||||||
jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
|
jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
|
||||||
|
|
||||||
@@ -1662,19 +1668,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
addCLCFromDep(ctx, module, j.classLoaderContexts)
|
addCLCFromDep(ctx, module, j.classLoaderContexts)
|
||||||
})
|
})
|
||||||
|
|
||||||
if Bool(j.properties.Installable) {
|
j.maybeInstall(ctx, jarName, outputFile)
|
||||||
var installDir android.InstallPath
|
|
||||||
if ctx.InstallInTestcases() {
|
|
||||||
var archDir string
|
|
||||||
if !ctx.Host() {
|
|
||||||
archDir = ctx.DeviceConfig().DeviceArch()
|
|
||||||
}
|
|
||||||
installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir)
|
|
||||||
} else {
|
|
||||||
installDir = android.PathForModuleInstall(ctx, "framework")
|
|
||||||
}
|
|
||||||
ctx.InstallFile(installDir, jarName, outputFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs)
|
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs)
|
||||||
|
|
||||||
@@ -1748,6 +1742,24 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *Import) maybeInstall(ctx android.ModuleContext, jarName string, outputFile android.Path) {
|
||||||
|
if !Bool(j.properties.Installable) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var installDir android.InstallPath
|
||||||
|
if ctx.InstallInTestcases() {
|
||||||
|
var archDir string
|
||||||
|
if !ctx.Host() {
|
||||||
|
archDir = ctx.DeviceConfig().DeviceArch()
|
||||||
|
}
|
||||||
|
installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir)
|
||||||
|
} else {
|
||||||
|
installDir = android.PathForModuleInstall(ctx, "framework")
|
||||||
|
}
|
||||||
|
ctx.InstallFile(installDir, jarName, outputFile)
|
||||||
|
}
|
||||||
|
|
||||||
func (j *Import) OutputFiles(tag string) (android.Paths, error) {
|
func (j *Import) OutputFiles(tag string) (android.Paths, error) {
|
||||||
switch tag {
|
switch tag {
|
||||||
case "", ".jar":
|
case "", ".jar":
|
||||||
@@ -2046,9 +2058,7 @@ func DexImportFactory() android.Module {
|
|||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Defaults
|
// Defaults
|
||||||
//
|
|
||||||
type Defaults struct {
|
type Defaults struct {
|
||||||
android.ModuleBase
|
android.ModuleBase
|
||||||
android.DefaultsModuleBase
|
android.DefaultsModuleBase
|
||||||
@@ -2483,5 +2493,54 @@ func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
|||||||
props := bazel.BazelTargetModuleProperties{Rule_class: "java_import"}
|
props := bazel.BazelTargetModuleProperties{Rule_class: "java_import"}
|
||||||
|
|
||||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: android.RemoveOptionalPrebuiltPrefix(i.Name())}, attrs)
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: android.RemoveOptionalPrebuiltPrefix(i.Name())}, attrs)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ android.MixedBuildBuildable = (*Import)(nil)
|
||||||
|
|
||||||
|
func (i *Import) getBazelModuleLabel(ctx android.BaseModuleContext) string {
|
||||||
|
return android.RemoveOptionalPrebuiltPrefixFromBazelLabel(i.GetBazelLabel(ctx, i))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Import) ProcessBazelQueryResponse(ctx android.ModuleContext) {
|
||||||
|
i.commonBuildActions(ctx)
|
||||||
|
|
||||||
|
bazelCtx := ctx.Config().BazelContext
|
||||||
|
filePaths, err := bazelCtx.GetOutputFiles(i.getBazelModuleLabel(ctx), android.GetConfigKey(ctx))
|
||||||
|
if err != nil {
|
||||||
|
ctx.ModuleErrorf(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bazelJars := android.Paths{}
|
||||||
|
for _, bazelOutputFile := range filePaths {
|
||||||
|
bazelJars = append(bazelJars, android.PathForBazelOut(ctx, bazelOutputFile))
|
||||||
|
}
|
||||||
|
|
||||||
|
jarName := android.RemoveOptionalPrebuiltPrefix(i.Name()) + ".jar"
|
||||||
|
outputFile := android.PathForModuleOut(ctx, "bazelCombined", jarName)
|
||||||
|
TransformJarsToJar(ctx, outputFile, "combine prebuilt jars", bazelJars,
|
||||||
|
android.OptionalPath{}, // manifest
|
||||||
|
false, // stripDirEntries
|
||||||
|
[]string{}, // filesToStrip
|
||||||
|
[]string{}, // dirsToStrip
|
||||||
|
)
|
||||||
|
i.combinedClasspathFile = outputFile
|
||||||
|
|
||||||
|
ctx.SetProvider(JavaInfoProvider, JavaInfo{
|
||||||
|
HeaderJars: android.PathsIfNonNil(i.combinedClasspathFile),
|
||||||
|
ImplementationAndResourcesJars: android.PathsIfNonNil(i.combinedClasspathFile),
|
||||||
|
ImplementationJars: android.PathsIfNonNil(i.combinedClasspathFile),
|
||||||
|
//TODO(b/240308299) include AIDL information from Bazel
|
||||||
|
})
|
||||||
|
|
||||||
|
i.maybeInstall(ctx, jarName, outputFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Import) QueueBazelCall(ctx android.BaseModuleContext) {
|
||||||
|
bazelCtx := ctx.Config().BazelContext
|
||||||
|
bazelCtx.QueueBazelRequest(i.getBazelModuleLabel(ctx), cquery.GetOutputFiles, android.GetConfigKey(ctx))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Import) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
@@ -1667,3 +1667,48 @@ func TestDataDeviceBinsBuildsDeviceBinary(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestImportMixedBuild(t *testing.T) {
|
||||||
|
bp := `
|
||||||
|
java_import {
|
||||||
|
name: "baz",
|
||||||
|
jars: [
|
||||||
|
"test1.jar",
|
||||||
|
"test2.jar",
|
||||||
|
],
|
||||||
|
bazel_module: { label: "//foo/bar:baz" },
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
ctx := android.GroupFixturePreparers(
|
||||||
|
prepareForJavaTest,
|
||||||
|
android.FixtureModifyConfig(func(config android.Config) {
|
||||||
|
config.BazelContext = android.MockBazelContext{
|
||||||
|
OutputBaseDir: "outputbase",
|
||||||
|
LabelToOutputFiles: map[string][]string{
|
||||||
|
"//foo/bar:baz": []string{"test1.jar", "test2.jar"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
).RunTestWithBp(t, bp)
|
||||||
|
|
||||||
|
bazMod := ctx.ModuleForTests("baz", "android_common").Module()
|
||||||
|
producer := bazMod.(android.OutputFileProducer)
|
||||||
|
expectedOutputFiles := []string{".intermediates/baz/android_common/bazelCombined/baz.jar"}
|
||||||
|
|
||||||
|
outputFiles, err := producer.OutputFiles("")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error getting java_import outputfiles %s", err)
|
||||||
|
}
|
||||||
|
actualOutputFiles := android.NormalizePathsForTesting(outputFiles)
|
||||||
|
android.AssertDeepEquals(t, "Output files are produced", expectedOutputFiles, actualOutputFiles)
|
||||||
|
|
||||||
|
javaInfoProvider := ctx.ModuleProvider(bazMod, JavaInfoProvider)
|
||||||
|
javaInfo, ok := javaInfoProvider.(JavaInfo)
|
||||||
|
if !ok {
|
||||||
|
t.Error("could not get JavaInfo from java_import module")
|
||||||
|
}
|
||||||
|
android.AssertDeepEquals(t, "Header JARs are produced", expectedOutputFiles, android.NormalizePathsForTesting(javaInfo.HeaderJars))
|
||||||
|
android.AssertDeepEquals(t, "Implementation/Resources JARs are produced", expectedOutputFiles, android.NormalizePathsForTesting(javaInfo.ImplementationAndResourcesJars))
|
||||||
|
android.AssertDeepEquals(t, "Implementation JARs are produced", expectedOutputFiles, android.NormalizePathsForTesting(javaInfo.ImplementationJars))
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user