Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 428a3667 authored by Romain Jobredeaux's avatar Romain Jobredeaux
Browse files

Basic bp2build converter for java_import.

This only supports the `jars` property/attribute.

Test: b build external/error_prone:error_prone_core_jars
Bug: 215229744
Change-Id: If0d9c8c4e9c1c560d35a501c20bef9361ef45e15
parent 0107901d
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -217,7 +217,6 @@ var (
		"external/bazelbuild-rules_android":/* recursive = */ true,
		"external/bazel-skylib":/* recursive = */ true,
		"external/guava":/* recursive = */ true,
		"external/error_prone":/* recursive = */ true,
		"external/jsr305":/* recursive = */ true,
		"frameworks/ex/common":/* recursive = */ true,

@@ -292,6 +291,7 @@ var (
		"external/bouncycastle":                              Bp2BuildDefaultTrue,
		"external/brotli":                                    Bp2BuildDefaultTrue,
		"external/conscrypt":                                 Bp2BuildDefaultTrue,
		"external/error_prone":                               Bp2BuildDefaultTrue,
		"external/fmtlib":                                    Bp2BuildDefaultTrueRecursively,
		"external/google-benchmark":                          Bp2BuildDefaultTrueRecursively,
		"external/googletest":                                Bp2BuildDefaultTrueRecursively,
@@ -341,6 +341,7 @@ var (
		"packages/screensavers/Basic":                        Bp2BuildDefaultTrue,
		"packages/services/Car/tests/SampleRearViewCamera":   Bp2BuildDefaultTrue,
		"prebuilts/clang/host/linux-x86":                     Bp2BuildDefaultTrueRecursively,
		"prebuilts/tools/common/m2":                          Bp2BuildDefaultTrue,
		"system/apex":                                        Bp2BuildDefaultFalse, // TODO(b/207466993): flaky failures
		"system/apex/proto":                                  Bp2BuildDefaultTrueRecursively,
		"system/apex/libs":                                   Bp2BuildDefaultTrueRecursively,
@@ -471,6 +472,7 @@ var (
		// go deps:
		"apex-protos",                    // 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_script",      // depends on extract_linker, a go binary.

+52 −0
Original line number Diff line number Diff line
// 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 −0
Original line number Diff line number Diff line
@@ -1328,6 +1328,7 @@ type Import struct {
	android.ModuleBase
	android.DefaultableModuleBase
	android.ApexModuleBase
	android.BazelModuleBase
	prebuilt android.Prebuilt
	android.SdkBase

@@ -1683,6 +1684,7 @@ func ImportFactory() android.Module {
	android.InitPrebuiltModule(module, &module.properties.Jars)
	android.InitApexModule(module)
	android.InitSdkAwareModule(module)
	android.InitBazelModule(module)
	InitJavaModule(module, android.HostAndDeviceSupported)
	return module
}
@@ -2101,3 +2103,21 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
	// Create the BazelTargetModule.
	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)

}