Merge "Basic bp2build converter for java_import." am: ea64e62dab
am: bf670bc2c5
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1965379 Change-Id: Icf0c6922b31df1127c56a86b865f65c906bd8311
This commit is contained in:
@@ -217,7 +217,6 @@ var (
|
|||||||
"external/bazelbuild-rules_android":/* recursive = */ true,
|
"external/bazelbuild-rules_android":/* recursive = */ true,
|
||||||
"external/bazel-skylib":/* recursive = */ true,
|
"external/bazel-skylib":/* recursive = */ true,
|
||||||
"external/guava":/* recursive = */ true,
|
"external/guava":/* recursive = */ true,
|
||||||
"external/error_prone":/* recursive = */ true,
|
|
||||||
"external/jsr305":/* recursive = */ true,
|
"external/jsr305":/* recursive = */ true,
|
||||||
"frameworks/ex/common":/* recursive = */ true,
|
"frameworks/ex/common":/* recursive = */ true,
|
||||||
|
|
||||||
@@ -292,6 +291,7 @@ var (
|
|||||||
"external/bouncycastle": Bp2BuildDefaultTrue,
|
"external/bouncycastle": Bp2BuildDefaultTrue,
|
||||||
"external/brotli": Bp2BuildDefaultTrue,
|
"external/brotli": Bp2BuildDefaultTrue,
|
||||||
"external/conscrypt": Bp2BuildDefaultTrue,
|
"external/conscrypt": Bp2BuildDefaultTrue,
|
||||||
|
"external/error_prone": Bp2BuildDefaultTrue,
|
||||||
"external/fmtlib": Bp2BuildDefaultTrueRecursively,
|
"external/fmtlib": Bp2BuildDefaultTrueRecursively,
|
||||||
"external/google-benchmark": Bp2BuildDefaultTrueRecursively,
|
"external/google-benchmark": Bp2BuildDefaultTrueRecursively,
|
||||||
"external/googletest": Bp2BuildDefaultTrueRecursively,
|
"external/googletest": Bp2BuildDefaultTrueRecursively,
|
||||||
@@ -341,6 +341,7 @@ var (
|
|||||||
"packages/screensavers/Basic": Bp2BuildDefaultTrue,
|
"packages/screensavers/Basic": Bp2BuildDefaultTrue,
|
||||||
"packages/services/Car/tests/SampleRearViewCamera": Bp2BuildDefaultTrue,
|
"packages/services/Car/tests/SampleRearViewCamera": Bp2BuildDefaultTrue,
|
||||||
"prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively,
|
"prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively,
|
||||||
|
"prebuilts/tools/common/m2": Bp2BuildDefaultTrue,
|
||||||
"system/apex": Bp2BuildDefaultFalse, // TODO(b/207466993): flaky failures
|
"system/apex": Bp2BuildDefaultFalse, // TODO(b/207466993): flaky failures
|
||||||
"system/apex/proto": Bp2BuildDefaultTrueRecursively,
|
"system/apex/proto": Bp2BuildDefaultTrueRecursively,
|
||||||
"system/apex/libs": Bp2BuildDefaultTrueRecursively,
|
"system/apex/libs": Bp2BuildDefaultTrueRecursively,
|
||||||
@@ -471,6 +472,7 @@ var (
|
|||||||
// go deps:
|
// go deps:
|
||||||
"apex-protos", // depends on soong_zip, a go binary
|
"apex-protos", // depends on soong_zip, a go binary
|
||||||
"robolectric_tzdata", // depends on soong_zip, a go binary
|
"robolectric_tzdata", // depends on soong_zip, a go binary
|
||||||
|
"robolectric-sqlite4java-native", // depends on soong_zip, a go binary
|
||||||
"host_bionic_linker_asm", // depends on extract_linker, a go binary.
|
"host_bionic_linker_asm", // depends on extract_linker, a go binary.
|
||||||
"host_bionic_linker_script", // depends on extract_linker, a go binary.
|
"host_bionic_linker_script", // depends on extract_linker, a go binary.
|
||||||
|
|
||||||
|
52
bp2build/java_import_conversion_test.go
Normal file
52
bp2build/java_import_conversion_test.go
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
// Copyright 2022 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 bp2build
|
||||||
|
|
||||||
|
import (
|
||||||
|
"android/soong/android"
|
||||||
|
"android/soong/java"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func runJavaImportTestCase(t *testing.T, tc bp2buildTestCase) {
|
||||||
|
t.Helper()
|
||||||
|
runBp2BuildTestCase(t, registerJavaImportModuleTypes, tc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func registerJavaImportModuleTypes(ctx android.RegistrationContext) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMinimalJavaImport(t *testing.T) {
|
||||||
|
runJavaImportTestCase(t, bp2buildTestCase{
|
||||||
|
description: "Java import - simple example",
|
||||||
|
moduleTypeUnderTest: "java_import",
|
||||||
|
moduleTypeUnderTestFactory: java.ImportFactory,
|
||||||
|
filesystem: map[string]string{
|
||||||
|
"import.jar": "",
|
||||||
|
},
|
||||||
|
blueprint: `
|
||||||
|
java_import {
|
||||||
|
name: "example_import",
|
||||||
|
jars: ["import.jar"],
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
expectedBazelTargets: []string{
|
||||||
|
makeBazelTarget("java_import", "example_import", attrNameToString{
|
||||||
|
"jars": `["import.jar"]`,
|
||||||
|
}),
|
||||||
|
}})
|
||||||
|
}
|
20
java/java.go
20
java/java.go
@@ -1328,6 +1328,7 @@ type Import struct {
|
|||||||
android.ModuleBase
|
android.ModuleBase
|
||||||
android.DefaultableModuleBase
|
android.DefaultableModuleBase
|
||||||
android.ApexModuleBase
|
android.ApexModuleBase
|
||||||
|
android.BazelModuleBase
|
||||||
prebuilt android.Prebuilt
|
prebuilt android.Prebuilt
|
||||||
android.SdkBase
|
android.SdkBase
|
||||||
|
|
||||||
@@ -1683,6 +1684,7 @@ func ImportFactory() android.Module {
|
|||||||
android.InitPrebuiltModule(module, &module.properties.Jars)
|
android.InitPrebuiltModule(module, &module.properties.Jars)
|
||||||
android.InitApexModule(module)
|
android.InitApexModule(module)
|
||||||
android.InitSdkAwareModule(module)
|
android.InitSdkAwareModule(module)
|
||||||
|
android.InitBazelModule(module)
|
||||||
InitJavaModule(module, android.HostAndDeviceSupported)
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
@@ -2101,3 +2103,21 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
|
|||||||
// Create the BazelTargetModule.
|
// Create the BazelTargetModule.
|
||||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type bazelJavaImportAttributes struct {
|
||||||
|
Jars bazel.LabelListAttribute
|
||||||
|
}
|
||||||
|
|
||||||
|
// java_import bp2Build converter.
|
||||||
|
func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||||
|
//TODO(b/209577426): Support multiple arch variants
|
||||||
|
jars := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, i.properties.Jars, []string(nil)))
|
||||||
|
|
||||||
|
attrs := &bazelJavaImportAttributes{
|
||||||
|
Jars: jars,
|
||||||
|
}
|
||||||
|
props := bazel.BazelTargetModuleProperties{Rule_class: "java_import"}
|
||||||
|
|
||||||
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: android.RemoveOptionalPrebuiltPrefix(i.Name())}, attrs)
|
||||||
|
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user