diff --git a/android/bazel_paths.go b/android/bazel_paths.go index 4280bc3a5..f4b2a7caf 100644 --- a/android/bazel_paths.go +++ b/android/bazel_paths.go @@ -100,6 +100,10 @@ func BazelLabelForModuleDeps(ctx BazelConversionPathContext, modules []string) b return labels } +func BazelLabelForModuleSrcSingle(ctx BazelConversionPathContext, path string) bazel.Label { + return BazelLabelForModuleSrcExcludes(ctx, []string{path}, []string(nil)).Includes[0] +} + // BazelLabelForModuleSrc expects a list of path (relative to local module directory) and module // references (":") and returns a bazel.LabelList{} containing the resolved references in // paths, relative to the local module, or Bazel-labels (absolute if in a different package or diff --git a/bazel/properties.go b/bazel/properties.go index 037150dbb..12dfcaff8 100644 --- a/bazel/properties.go +++ b/bazel/properties.go @@ -227,6 +227,15 @@ type Attribute interface { HasConfigurableValues() bool } +// Represents an attribute whose value is a single label +type LabelAttribute struct { + Value Label +} + +func (LabelAttribute) HasConfigurableValues() bool { + return false +} + // Arch-specific label_list typed Bazel attribute values. This should correspond // to the types of architectures supported for compilation in arch.go. type labelListArchValues struct { diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go index 08790d13e..bddc524cd 100644 --- a/bp2build/build_conversion.go +++ b/bp2build/build_conversion.go @@ -519,9 +519,7 @@ func isZero(value reflect.Value) bool { case reflect.Struct: valueIsZero := true for i := 0; i < value.NumField(); i++ { - if value.Field(i).CanSet() { - valueIsZero = valueIsZero && isZero(value.Field(i)) - } + valueIsZero = valueIsZero && isZero(value.Field(i)) } return valueIsZero case reflect.Ptr: diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index aa8200b96..0551a18f1 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -275,6 +275,31 @@ cc_library_static { name: "b" } copts = ["-Ifoo/bar"], srcs = ["a.cpp"], static_deps_for_shared = [":b"], +)`}, + }, + { + description: "cc_library non-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"], + version_script: "v.map", + bazel_module: { bp2build_available: true }, +} +`, + }, + bp: soongCcLibraryPreamble, + expectedBazelTargets: []string{`cc_library( + name = "a", + copts = ["-Ifoo/bar"], + srcs = ["a.cpp"], + version_script = "v.map", )`}, }, } diff --git a/bp2build/configurability.go b/bp2build/configurability.go index 52afb556d..050679b53 100644 --- a/bp2build/configurability.go +++ b/bp2build/configurability.go @@ -30,6 +30,11 @@ func getStringListValues(list bazel.StringListAttribute) (reflect.Value, selects return value, archSelects, osSelects } +func getLabelValue(label bazel.LabelAttribute) (reflect.Value, selects, selects) { + value := reflect.ValueOf(label.Value) + return value, nil, nil +} + func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, selects, selects) { value := reflect.ValueOf(list.Value.Includes) if !list.HasConfigurableValues() { @@ -54,12 +59,13 @@ func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, selects, func prettyPrintAttribute(v bazel.Attribute, indent int) (string, error) { var value reflect.Value var archSelects, osSelects selects - switch list := v.(type) { case bazel.StringListAttribute: value, archSelects, osSelects = getStringListValues(list) case bazel.LabelListAttribute: value, archSelects, osSelects = getLabelListValues(list) + case bazel.LabelAttribute: + value, archSelects, osSelects = getLabelValue(list) default: return "", fmt.Errorf("Not a supported Bazel attribute type: %s", v) } diff --git a/cc/bp2build.go b/cc/bp2build.go index a4db79ff0..d52b817b2 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -246,15 +246,17 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul // Convenience struct to hold all attributes parsed from linker properties. type linkerAttributes struct { - deps bazel.LabelListAttribute - linkopts bazel.StringListAttribute + deps bazel.LabelListAttribute + linkopts bazel.StringListAttribute + versionScript bazel.LabelAttribute } -// bp2BuildParseLinkerProps creates a label list attribute containing the header library deps of a module, including +// bp2BuildParseLinkerProps parses the linker properties of a module, including // configurable attribute values. func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes { var deps bazel.LabelListAttribute var linkopts bazel.StringListAttribute + var versionScript bazel.LabelAttribute for _, linkerProps := range module.linker.linkerProps() { if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok { @@ -265,6 +267,12 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs = android.SortedUniqueStrings(libs) deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs)) linkopts.Value = baseLinkerProps.Ldflags + + if baseLinkerProps.Version_script != nil { + versionScript = bazel.LabelAttribute{ + Value: android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script), + } + } break } } @@ -294,8 +302,9 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) } return linkerAttributes{ - deps: deps, - linkopts: linkopts, + deps: deps, + linkopts: linkopts, + versionScript: versionScript, } } diff --git a/cc/library.go b/cc/library.go index 3b65d8d9e..50d3f67fe 100644 --- a/cc/library.go +++ b/cc/library.go @@ -228,6 +228,7 @@ type bazelCcLibraryAttributes struct { User_link_flags bazel.StringListAttribute Includes bazel.StringListAttribute Static_deps_for_shared bazel.LabelListAttribute + Version_script bazel.LabelAttribute } type bazelCcLibrary struct { @@ -273,6 +274,7 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) { Copts: compilerAttrs.copts, Linkopts: linkerAttrs.linkopts, Deps: linkerAttrs.deps, + Version_script: linkerAttrs.versionScript, Static_deps_for_shared: sharedAttrs.staticDeps, Includes: exportedIncludes, }