From f38a8379ffbc007567052c4949fbb9b5ffed91de Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Fri, 4 Feb 2022 15:39:00 -0500 Subject: [PATCH] Escape cc ldflags in bp2build conversion Bug: 217757720 Test: bp2build.sh Change-Id: I704acfb01527f15ff762afeaaf4e0e328e4737d8 --- bp2build/cc_library_conversion_test.go | 15 +++++++++++++++ cc/bp2build.go | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index ee1978320..17212b838 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -2409,3 +2409,18 @@ cc_library { }, ) } + +func TestCcLibraryEscapeLdflags(t *testing.T) { + runCcLibraryTestCase(t, bp2buildTestCase{ + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + blueprint: soongCcProtoPreamble + `cc_library { + name: "foo", + ldflags: ["-Wl,--rpath,${ORIGIN}"], + include_build_directory: false, +}`, + expectedBazelTargets: makeCcLibraryTargets("foo", attrNameToString{ + "linkopts": `["-Wl,--rpath,$${ORIGIN}"]`, + }), + }) +} diff --git a/cc/bp2build.go b/cc/bp2build.go index 30c3c509b..42fc0e494 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -644,7 +644,7 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion var linkerFlags []string if len(props.Ldflags) > 0 { - linkerFlags = append(linkerFlags, props.Ldflags...) + linkerFlags = append(linkerFlags, proptools.NinjaEscapeList(props.Ldflags)...) // binaries remove static flag if -shared is in the linker flags if isBinary && android.InList("-shared", linkerFlags) { axisFeatures = append(axisFeatures, "-static_flag")