Loading bazel/properties.go +1 −1 Original line number Diff line number Diff line Loading @@ -993,6 +993,6 @@ func TryVariableSubstitutions(slice []string, productVariable string) ([]string, // TryVariableSubstitution, replace string substitution formatting within s with Starlark // string.format compatible tag for productVariable. func TryVariableSubstitution(s string, productVariable string) (string, bool) { sub := productVariableSubstitutionPattern.ReplaceAllString(s, "{"+productVariable+"}") sub := productVariableSubstitutionPattern.ReplaceAllString(s, "$("+productVariable+")") return sub, s != sub } bp2build/cc_library_static_conversion_test.go +34 −0 Original line number Diff line number Diff line Loading @@ -1412,3 +1412,37 @@ cc_library_static { )`}, }) } func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) { runCcLibraryStaticTestCase(t, bp2buildTestCase{ description: "cc_library_static product variable selects", moduleTypeUnderTest: "cc_library_static", moduleTypeUnderTestFactory: cc.LibraryStaticFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, filesystem: map[string]string{}, blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.c"], product_variables: { platform_sdk_version: { asflags: ["-DPLATFORM_SDK_VERSION=%d"], }, }, } `, expectedBazelTargets: []string{`cc_library_static( name = "foo_static", asflags = select({ "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"], "//conditions:default": [], }), copts = [ "-I.", "-I$(BINDIR)/.", ], linkstatic = True, srcs_c = ["common.c"], )`}, }) } bp2build/cc_object_conversion_test.go +1 −1 Original line number Diff line number Diff line Loading @@ -210,7 +210,7 @@ func TestCcObjectProductVariable(t *testing.T) { expectedBazelTargets: []string{`cc_object( name = "foo", asflags = select({ "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION={Platform_sdk_version}"], "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"], "//conditions:default": [], }), copts = ["-fno-addrsig"], Loading cc/bp2build.go +19 −10 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ import ( "android/soong/android" "android/soong/bazel" "github.com/google/blueprint/proptools" ) // bp2build functions and helpers for converting cc_* modules to Bazel. Loading Loading @@ -504,20 +506,27 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul } } productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{ "Cflags": &copts, "Asflags": &asFlags, "CppFlags": &cppFlags, } productVariableProps := android.ProductVariableProperties(ctx) if props, exists := productVariableProps["Cflags"]; exists { for propName, attr := range productVarPropNameToAttribute { if props, exists := productVariableProps[propName]; exists { for _, prop := range props { flags, ok := prop.Property.([]string) if !ok { ctx.ModuleErrorf("Could not convert product variable cflag property") ctx.ModuleErrorf("Could not convert product variable %s property", proptools.PropertyNameForField(propName)) } newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable) copts.ProductValues = append(copts.ProductValues, bazel.ProductVariableValues{ attr.ProductValues = append(attr.ProductValues, bazel.ProductVariableValues{ ProductVariable: prop.ProductConfigVariable, Values: newFlags, }) } } } // Branch srcs into three language-specific groups. // C++ is the "catch-all" group, and comprises generated sources because we don't Loading cc/object.go +1 −21 Original line number Diff line number Diff line Loading @@ -157,8 +157,6 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) { // Set arch-specific configurable attributes compilerAttrs := bp2BuildParseCompilerProps(ctx, m) var asFlags bazel.StringListAttribute var deps bazel.LabelListAttribute for _, props := range m.linker.linkerProps() { if objectLinkerProps, ok := props.(*ObjectLinkerProperties); ok { Loading @@ -167,24 +165,6 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) { } } productVariableProps := android.ProductVariableProperties(ctx) if props, exists := productVariableProps["Asflags"]; exists { // TODO(b/183595873): consider deduplicating handling of product variable properties for _, prop := range props { flags, ok := prop.Property.([]string) if !ok { ctx.ModuleErrorf("Could not convert product variable asflag property") return } newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable) asFlags.ProductValues = append(asFlags.ProductValues, bazel.ProductVariableValues{ ProductVariable: prop.ProductConfigVariable, Values: newFlags, }) } } // TODO(b/183595872) warn/error if we're not handling product variables // Don't split cc_object srcs across languages. Doing so would add complexity, // and this isn't typically done for cc_object. srcs := compilerAttrs.srcs Loading @@ -195,7 +175,7 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) { Srcs: srcs, Deps: deps, Copts: compilerAttrs.copts, Asflags: asFlags, Asflags: compilerAttrs.asFlags, } props := bazel.BazelTargetModuleProperties{ Loading Loading
bazel/properties.go +1 −1 Original line number Diff line number Diff line Loading @@ -993,6 +993,6 @@ func TryVariableSubstitutions(slice []string, productVariable string) ([]string, // TryVariableSubstitution, replace string substitution formatting within s with Starlark // string.format compatible tag for productVariable. func TryVariableSubstitution(s string, productVariable string) (string, bool) { sub := productVariableSubstitutionPattern.ReplaceAllString(s, "{"+productVariable+"}") sub := productVariableSubstitutionPattern.ReplaceAllString(s, "$("+productVariable+")") return sub, s != sub }
bp2build/cc_library_static_conversion_test.go +34 −0 Original line number Diff line number Diff line Loading @@ -1412,3 +1412,37 @@ cc_library_static { )`}, }) } func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) { runCcLibraryStaticTestCase(t, bp2buildTestCase{ description: "cc_library_static product variable selects", moduleTypeUnderTest: "cc_library_static", moduleTypeUnderTestFactory: cc.LibraryStaticFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, filesystem: map[string]string{}, blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.c"], product_variables: { platform_sdk_version: { asflags: ["-DPLATFORM_SDK_VERSION=%d"], }, }, } `, expectedBazelTargets: []string{`cc_library_static( name = "foo_static", asflags = select({ "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"], "//conditions:default": [], }), copts = [ "-I.", "-I$(BINDIR)/.", ], linkstatic = True, srcs_c = ["common.c"], )`}, }) }
bp2build/cc_object_conversion_test.go +1 −1 Original line number Diff line number Diff line Loading @@ -210,7 +210,7 @@ func TestCcObjectProductVariable(t *testing.T) { expectedBazelTargets: []string{`cc_object( name = "foo", asflags = select({ "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION={Platform_sdk_version}"], "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"], "//conditions:default": [], }), copts = ["-fno-addrsig"], Loading
cc/bp2build.go +19 −10 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ import ( "android/soong/android" "android/soong/bazel" "github.com/google/blueprint/proptools" ) // bp2build functions and helpers for converting cc_* modules to Bazel. Loading Loading @@ -504,20 +506,27 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul } } productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{ "Cflags": &copts, "Asflags": &asFlags, "CppFlags": &cppFlags, } productVariableProps := android.ProductVariableProperties(ctx) if props, exists := productVariableProps["Cflags"]; exists { for propName, attr := range productVarPropNameToAttribute { if props, exists := productVariableProps[propName]; exists { for _, prop := range props { flags, ok := prop.Property.([]string) if !ok { ctx.ModuleErrorf("Could not convert product variable cflag property") ctx.ModuleErrorf("Could not convert product variable %s property", proptools.PropertyNameForField(propName)) } newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable) copts.ProductValues = append(copts.ProductValues, bazel.ProductVariableValues{ attr.ProductValues = append(attr.ProductValues, bazel.ProductVariableValues{ ProductVariable: prop.ProductConfigVariable, Values: newFlags, }) } } } // Branch srcs into three language-specific groups. // C++ is the "catch-all" group, and comprises generated sources because we don't Loading
cc/object.go +1 −21 Original line number Diff line number Diff line Loading @@ -157,8 +157,6 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) { // Set arch-specific configurable attributes compilerAttrs := bp2BuildParseCompilerProps(ctx, m) var asFlags bazel.StringListAttribute var deps bazel.LabelListAttribute for _, props := range m.linker.linkerProps() { if objectLinkerProps, ok := props.(*ObjectLinkerProperties); ok { Loading @@ -167,24 +165,6 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) { } } productVariableProps := android.ProductVariableProperties(ctx) if props, exists := productVariableProps["Asflags"]; exists { // TODO(b/183595873): consider deduplicating handling of product variable properties for _, prop := range props { flags, ok := prop.Property.([]string) if !ok { ctx.ModuleErrorf("Could not convert product variable asflag property") return } newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable) asFlags.ProductValues = append(asFlags.ProductValues, bazel.ProductVariableValues{ ProductVariable: prop.ProductConfigVariable, Values: newFlags, }) } } // TODO(b/183595872) warn/error if we're not handling product variables // Don't split cc_object srcs across languages. Doing so would add complexity, // and this isn't typically done for cc_object. srcs := compilerAttrs.srcs Loading @@ -195,7 +175,7 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) { Srcs: srcs, Deps: deps, Copts: compilerAttrs.copts, Asflags: asFlags, Asflags: compilerAttrs.asFlags, } props := bazel.BazelTargetModuleProperties{ Loading