From 05b0ba6d1c9d5b71a8c6252e4a04897e4a0c62ed Mon Sep 17 00:00:00 2001 From: Sasha Smundak Date: Mon, 26 Sep 2022 18:15:45 -0700 Subject: [PATCH] Convert Soong `licenses` attribute to Bazel's `applicable_licenses` attribute Add it to the `CommonAttributes` struct and handle it in fillCommonBp2BuildModuleAttrs Bug: 190817312 Test: treehugger Change-Id: I7b21056e680384d4046372ee844512029721026e --- android/module.go | 4 ++++ bp2build/build_conversion_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/android/module.go b/android/module.go index 16172591b..f63a06dfb 100644 --- a/android/module.go +++ b/android/module.go @@ -919,6 +919,8 @@ type CommonAttributes struct { Data bazel.LabelListAttribute Tags bazel.StringListAttribute + + Applicable_licenses bazel.LabelListAttribute } // constraintAttributes represents Bazel attributes pertaining to build constraints, @@ -1231,6 +1233,8 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator } } + attrs.Applicable_licenses = bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, mod.commonProperties.Licenses)) + // The required property can contain the module itself. This causes a cycle // when generated as the 'data' label list attribute in Bazel. Remove it if // it exists. See b/247985196. diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go index d29eb9cd3..d513d04d9 100644 --- a/bp2build/build_conversion_test.go +++ b/bp2build/build_conversion_test.go @@ -1821,3 +1821,30 @@ filegroup { }) } } + +func TestLicensesAttrConversion(t *testing.T) { + RunBp2BuildTestCase(t, + func(ctx android.RegistrationContext) { + ctx.RegisterModuleType("license", android.LicenseFactory) + }, + Bp2buildTestCase{ + Description: "Test that licenses: attribute is converted", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: ` +license { + name: "my_license", +} +filegroup { + name: "my_filegroup", + licenses: ["my_license"], +} +`, + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "my_filegroup", AttrNameToString{ + "applicable_licenses": `[":my_license"]`, + }), + MakeBazelTargetNoRestrictions("android_license", "my_license", AttrNameToString{}), + }, + }) +}