From 56bb083989739d3d3d17708667f3befe89ef3522 Mon Sep 17 00:00:00 2001 From: "Lukacs T. Berki" Date: Wed, 12 May 2021 12:36:45 +0200 Subject: [PATCH] Implement configured version_script. Bug: 186650430 Test: Presubmits. Change-Id: I3e363ea9254a859dc8f485c9f273f6b3677f7645 --- bp2build/cc_library_conversion_test.go | 37 ++++++++++++++++++++++++++ bp2build/configurability.go | 15 +++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 407073a85..3da3bd7bf 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -350,6 +350,43 @@ cc_library { copts = ["-Ifoo/bar"], srcs = ["a.cpp"], version_script = "v.map", +)`}, + }, + { + description: "cc_library configured version script", + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, + depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, + dir: "foo/bar", + filesystem: map[string]string{ + "foo/bar/Android.bp": ` + cc_library { + name: "a", + srcs: ["a.cpp"], + arch: { + arm: { + version_script: "arm.map", + }, + arm64: { + version_script: "arm64.map", + }, + }, + + bazel_module: { bp2build_available: true }, + } + `, + }, + bp: soongCcLibraryPreamble, + expectedBazelTargets: []string{`cc_library( + name = "a", + copts = ["-Ifoo/bar"], + srcs = ["a.cpp"], + version_script = select({ + "//build/bazel/platforms/arch:arm": "arm.map", + "//build/bazel/platforms/arch:arm64": "arm64.map", + "//conditions:default": None, + }), )`}, }, { diff --git a/bp2build/configurability.go b/bp2build/configurability.go index 95a2747d6..2b8f6cc2e 100644 --- a/bp2build/configurability.go +++ b/bp2build/configurability.go @@ -31,8 +31,19 @@ func getStringListValues(list bazel.StringListAttribute) (reflect.Value, selects } func getLabelValue(label bazel.LabelAttribute) (reflect.Value, selects, selects) { - value := reflect.ValueOf(label.Value) - return value, nil, nil + var value reflect.Value + var archSelects selects + + if label.HasConfigurableValues() { + archSelects = map[string]reflect.Value{} + for arch, selectKey := range bazel.PlatformArchMap { + archSelects[selectKey] = reflect.ValueOf(label.GetValueForArch(arch)) + } + } else { + value = reflect.ValueOf(label.Value) + } + + return value, archSelects, nil } func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, selects, selects) {