Implement bp2build converter for fdo_profile
Ignore-AOSP-First: ag/24746588, in the same topic, is in an internal repo. This CL will be cherry-picked to AOSP afterward.
Test: go test
Bug: 277091218
Change-Id: I389d9535ea176991a1faa9beb46352b93363acd2
Merged-In: I389d9535ea176991a1faa9beb46352b93363acd2
diff --git a/bp2build/fdo_profile_conversion_test.go b/bp2build/fdo_profile_conversion_test.go
new file mode 100644
index 0000000..4d04283
--- /dev/null
+++ b/bp2build/fdo_profile_conversion_test.go
@@ -0,0 +1,85 @@
+// 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/android"
+ "android/soong/cc"
+)
+
+func runFdoProfileTestCase(t *testing.T, tc Bp2buildTestCase) {
+ t.Helper()
+ (&tc).ModuleTypeUnderTest = "fdo_profile"
+ (&tc).ModuleTypeUnderTestFactory = cc.FdoProfileFactory
+ RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
+}
+
+func TestFdoProfile(t *testing.T) {
+ testcases := []struct {
+ name string
+ bp string
+ expectedBazelAttrs AttrNameToString
+ }{
+ {
+ name: "fdo_profile with arch-specific profiles",
+ bp: `
+fdo_profile {
+ name: "foo",
+ arch: {
+ arm: {
+ profile: "foo_arm.afdo",
+ },
+ arm64: {
+ profile: "foo_arm64.afdo",
+ }
+ }
+}`,
+ expectedBazelAttrs: AttrNameToString{
+ "profile": `select({
+ "//build/bazel/platforms/arch:arm": "foo_arm.afdo",
+ "//build/bazel/platforms/arch:arm64": "foo_arm64.afdo",
+ "//conditions:default": None,
+ })`,
+ },
+ },
+ {
+ name: "fdo_profile with arch-agnostic profile",
+ bp: `
+fdo_profile {
+ name: "foo",
+ profile: "foo.afdo",
+}`,
+ expectedBazelAttrs: AttrNameToString{
+ "profile": `"foo.afdo"`,
+ },
+ },
+ }
+
+ for _, test := range testcases {
+ t.Run(test.name, func(t *testing.T) {
+ expectedBazelTargets := []string{
+ // TODO(b/276287371): Add device-only restriction back to fdo_profile targets
+ MakeBazelTargetNoRestrictions("fdo_profile", "foo", test.expectedBazelAttrs),
+ }
+ runFdoProfileTestCase(t, Bp2buildTestCase{
+ Description: test.name,
+ Blueprint: test.bp,
+ ExpectedBazelTargets: expectedBazelTargets,
+ })
+ })
+ }
+}