Handle the version_script property.
Doesn't work when depends on arch/target/etc., but good enough for libdl_android. Bug: 186650430 Test: Presubmits. Change-Id: Ib0facb41a89454717c74663e5e078aedd33d1b9c
This commit is contained in:
@@ -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 (":<module>") 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
|
||||
|
@@ -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 {
|
||||
|
@@ -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:
|
||||
|
@@ -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",
|
||||
)`},
|
||||
},
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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,
|
||||
}
|
||||
|
Reference in New Issue
Block a user