Loading aidl_library/aidl_library.go +50 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package aidl_library import ( "android/soong/android" "android/soong/bazel" "github.com/google/blueprint" "github.com/google/blueprint/proptools" Loading Loading @@ -48,9 +49,57 @@ type aidlLibraryProperties struct { type AidlLibrary struct { android.ModuleBase android.BazelModuleBase properties aidlLibraryProperties } type bazelAidlLibraryAttributes struct { Srcs bazel.LabelListAttribute Hdrs bazel.LabelListAttribute Strip_import_prefix *string Deps bazel.LabelListAttribute } func (lib *AidlLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) { srcs := bazel.MakeLabelListAttribute( android.BazelLabelForModuleSrc( ctx, lib.properties.Srcs, ), ) hdrs := bazel.MakeLabelListAttribute( android.BazelLabelForModuleSrc( ctx, lib.properties.Hdrs, ), ) tags := []string{"apex_available=//apex_available:anyapex"} deps := bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, lib.properties.Deps)) attrs := &bazelAidlLibraryAttributes{ Srcs: srcs, Hdrs: hdrs, Strip_import_prefix: lib.properties.Strip_import_prefix, Deps: deps, } props := bazel.BazelTargetModuleProperties{ Rule_class: "aidl_library", Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl", } ctx.CreateBazelTargetModule( props, android.CommonAttributes{ Name: lib.Name(), Tags: bazel.MakeStringListAttribute(tags), }, attrs, ) } type AidlLibraryInfo struct { // The direct aidl files of the module Srcs android.Paths Loading Loading @@ -104,6 +153,7 @@ func AidlLibraryFactory() android.Module { module := &AidlLibrary{} module.AddProperties(&module.properties) android.InitAndroidModule(module) android.InitBazelModule(module) return module } Loading bp2build/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ bootstrap_go_package { "testing.go", ], deps: [ "soong-aidl-library", "soong-android", "soong-android-allowlists", "soong-android-soongconfig", Loading @@ -37,6 +38,7 @@ bootstrap_go_package { ], testSrcs: [ "aar_conversion_test.go", "aidl_library_conversion_test.go", "android_app_certificate_conversion_test.go", "android_app_conversion_test.go", "apex_conversion_test.go", Loading bp2build/aidl_library_conversion_test.go 0 → 100644 +119 −0 Original line number Diff line number Diff line // Copyright 2023 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 ( "testing" "android/soong/aidl_library" "android/soong/android" ) func runAidlLibraryTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() (&tc).ModuleTypeUnderTest = "aidl_library" (&tc).ModuleTypeUnderTestFactory = aidl_library.AidlLibraryFactory RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) } func TestAidlLibrary(t *testing.T) { testcases := []struct { name string bp string expectedBazelAttrs AttrNameToString }{ { name: "aidl_library with strip_import_prefix", bp: ` aidl_library { name: "foo", srcs: ["aidl/foo.aidl"], hdrs: ["aidl/header.aidl"], strip_import_prefix: "aidl", }`, expectedBazelAttrs: AttrNameToString{ "srcs": `["aidl/foo.aidl"]`, "hdrs": `["aidl/header.aidl"]`, "strip_import_prefix": `"aidl"`, "tags": `["apex_available=//apex_available:anyapex"]`, }, }, { name: "aidl_library without strip_import_prefix", bp: ` aidl_library { name: "foo", srcs: ["aidl/foo.aidl"], hdrs: ["aidl/header.aidl"], }`, expectedBazelAttrs: AttrNameToString{ "srcs": `["aidl/foo.aidl"]`, "hdrs": `["aidl/header.aidl"]`, "tags": `["apex_available=//apex_available:anyapex"]`, }, }, } for _, test := range testcases { t.Run(test.name, func(t *testing.T) { expectedBazelTargets := []string{ MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs), } runAidlLibraryTestCase(t, Bp2buildTestCase{ Description: test.name, Blueprint: test.bp, ExpectedBazelTargets: expectedBazelTargets, }) }) } } func TestAidlLibraryWithDeps(t *testing.T) { bp := ` aidl_library { name: "bar", srcs: ["Bar.aidl"], hdrs: ["aidl/BarHeader.aidl"], } aidl_library { name: "foo", srcs: ["aidl/Foo.aidl"], hdrs: ["aidl/FooHeader.aidl"], strip_import_prefix: "aidl", deps: ["bar"], }` t.Run("aidl_library with deps", func(t *testing.T) { expectedBazelTargets := []string{ MakeBazelTargetNoRestrictions("aidl_library", "bar", AttrNameToString{ "srcs": `["Bar.aidl"]`, "hdrs": `["aidl/BarHeader.aidl"]`, "tags": `["apex_available=//apex_available:anyapex"]`, }), MakeBazelTargetNoRestrictions("aidl_library", "foo", AttrNameToString{ "srcs": `["aidl/Foo.aidl"]`, "hdrs": `["aidl/FooHeader.aidl"]`, "strip_import_prefix": `"aidl"`, "deps": `[":bar"]`, "tags": `["apex_available=//apex_available:anyapex"]`, }), } runAidlLibraryTestCase(t, Bp2buildTestCase{ Description: "aidl_library with deps", Blueprint: bp, ExpectedBazelTargets: expectedBazelTargets, }) }) } Loading
aidl_library/aidl_library.go +50 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package aidl_library import ( "android/soong/android" "android/soong/bazel" "github.com/google/blueprint" "github.com/google/blueprint/proptools" Loading Loading @@ -48,9 +49,57 @@ type aidlLibraryProperties struct { type AidlLibrary struct { android.ModuleBase android.BazelModuleBase properties aidlLibraryProperties } type bazelAidlLibraryAttributes struct { Srcs bazel.LabelListAttribute Hdrs bazel.LabelListAttribute Strip_import_prefix *string Deps bazel.LabelListAttribute } func (lib *AidlLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) { srcs := bazel.MakeLabelListAttribute( android.BazelLabelForModuleSrc( ctx, lib.properties.Srcs, ), ) hdrs := bazel.MakeLabelListAttribute( android.BazelLabelForModuleSrc( ctx, lib.properties.Hdrs, ), ) tags := []string{"apex_available=//apex_available:anyapex"} deps := bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, lib.properties.Deps)) attrs := &bazelAidlLibraryAttributes{ Srcs: srcs, Hdrs: hdrs, Strip_import_prefix: lib.properties.Strip_import_prefix, Deps: deps, } props := bazel.BazelTargetModuleProperties{ Rule_class: "aidl_library", Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl", } ctx.CreateBazelTargetModule( props, android.CommonAttributes{ Name: lib.Name(), Tags: bazel.MakeStringListAttribute(tags), }, attrs, ) } type AidlLibraryInfo struct { // The direct aidl files of the module Srcs android.Paths Loading Loading @@ -104,6 +153,7 @@ func AidlLibraryFactory() android.Module { module := &AidlLibrary{} module.AddProperties(&module.properties) android.InitAndroidModule(module) android.InitBazelModule(module) return module } Loading
bp2build/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ bootstrap_go_package { "testing.go", ], deps: [ "soong-aidl-library", "soong-android", "soong-android-allowlists", "soong-android-soongconfig", Loading @@ -37,6 +38,7 @@ bootstrap_go_package { ], testSrcs: [ "aar_conversion_test.go", "aidl_library_conversion_test.go", "android_app_certificate_conversion_test.go", "android_app_conversion_test.go", "apex_conversion_test.go", Loading
bp2build/aidl_library_conversion_test.go 0 → 100644 +119 −0 Original line number Diff line number Diff line // Copyright 2023 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 ( "testing" "android/soong/aidl_library" "android/soong/android" ) func runAidlLibraryTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() (&tc).ModuleTypeUnderTest = "aidl_library" (&tc).ModuleTypeUnderTestFactory = aidl_library.AidlLibraryFactory RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) } func TestAidlLibrary(t *testing.T) { testcases := []struct { name string bp string expectedBazelAttrs AttrNameToString }{ { name: "aidl_library with strip_import_prefix", bp: ` aidl_library { name: "foo", srcs: ["aidl/foo.aidl"], hdrs: ["aidl/header.aidl"], strip_import_prefix: "aidl", }`, expectedBazelAttrs: AttrNameToString{ "srcs": `["aidl/foo.aidl"]`, "hdrs": `["aidl/header.aidl"]`, "strip_import_prefix": `"aidl"`, "tags": `["apex_available=//apex_available:anyapex"]`, }, }, { name: "aidl_library without strip_import_prefix", bp: ` aidl_library { name: "foo", srcs: ["aidl/foo.aidl"], hdrs: ["aidl/header.aidl"], }`, expectedBazelAttrs: AttrNameToString{ "srcs": `["aidl/foo.aidl"]`, "hdrs": `["aidl/header.aidl"]`, "tags": `["apex_available=//apex_available:anyapex"]`, }, }, } for _, test := range testcases { t.Run(test.name, func(t *testing.T) { expectedBazelTargets := []string{ MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs), } runAidlLibraryTestCase(t, Bp2buildTestCase{ Description: test.name, Blueprint: test.bp, ExpectedBazelTargets: expectedBazelTargets, }) }) } } func TestAidlLibraryWithDeps(t *testing.T) { bp := ` aidl_library { name: "bar", srcs: ["Bar.aidl"], hdrs: ["aidl/BarHeader.aidl"], } aidl_library { name: "foo", srcs: ["aidl/Foo.aidl"], hdrs: ["aidl/FooHeader.aidl"], strip_import_prefix: "aidl", deps: ["bar"], }` t.Run("aidl_library with deps", func(t *testing.T) { expectedBazelTargets := []string{ MakeBazelTargetNoRestrictions("aidl_library", "bar", AttrNameToString{ "srcs": `["Bar.aidl"]`, "hdrs": `["aidl/BarHeader.aidl"]`, "tags": `["apex_available=//apex_available:anyapex"]`, }), MakeBazelTargetNoRestrictions("aidl_library", "foo", AttrNameToString{ "srcs": `["aidl/Foo.aidl"]`, "hdrs": `["aidl/FooHeader.aidl"]`, "strip_import_prefix": `"aidl"`, "deps": `[":bar"]`, "tags": `["apex_available=//apex_available:anyapex"]`, }), } runAidlLibraryTestCase(t, Bp2buildTestCase{ Description: "aidl_library with deps", Blueprint: bp, ExpectedBazelTargets: expectedBazelTargets, }) }) }