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
|
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
|
// 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
|
// 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
|
// 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
|
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
|
// Arch-specific label_list typed Bazel attribute values. This should correspond
|
||||||
// to the types of architectures supported for compilation in arch.go.
|
// to the types of architectures supported for compilation in arch.go.
|
||||||
type labelListArchValues struct {
|
type labelListArchValues struct {
|
||||||
|
@@ -519,9 +519,7 @@ func isZero(value reflect.Value) bool {
|
|||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
valueIsZero := true
|
valueIsZero := true
|
||||||
for i := 0; i < value.NumField(); i++ {
|
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
|
return valueIsZero
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
|
@@ -275,6 +275,31 @@ cc_library_static { name: "b" }
|
|||||||
copts = ["-Ifoo/bar"],
|
copts = ["-Ifoo/bar"],
|
||||||
srcs = ["a.cpp"],
|
srcs = ["a.cpp"],
|
||||||
static_deps_for_shared = [":b"],
|
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
|
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) {
|
func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, selects, selects) {
|
||||||
value := reflect.ValueOf(list.Value.Includes)
|
value := reflect.ValueOf(list.Value.Includes)
|
||||||
if !list.HasConfigurableValues() {
|
if !list.HasConfigurableValues() {
|
||||||
@@ -54,12 +59,13 @@ func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, selects,
|
|||||||
func prettyPrintAttribute(v bazel.Attribute, indent int) (string, error) {
|
func prettyPrintAttribute(v bazel.Attribute, indent int) (string, error) {
|
||||||
var value reflect.Value
|
var value reflect.Value
|
||||||
var archSelects, osSelects selects
|
var archSelects, osSelects selects
|
||||||
|
|
||||||
switch list := v.(type) {
|
switch list := v.(type) {
|
||||||
case bazel.StringListAttribute:
|
case bazel.StringListAttribute:
|
||||||
value, archSelects, osSelects = getStringListValues(list)
|
value, archSelects, osSelects = getStringListValues(list)
|
||||||
case bazel.LabelListAttribute:
|
case bazel.LabelListAttribute:
|
||||||
value, archSelects, osSelects = getLabelListValues(list)
|
value, archSelects, osSelects = getLabelListValues(list)
|
||||||
|
case bazel.LabelAttribute:
|
||||||
|
value, archSelects, osSelects = getLabelValue(list)
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("Not a supported Bazel attribute type: %s", v)
|
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.
|
// Convenience struct to hold all attributes parsed from linker properties.
|
||||||
type linkerAttributes struct {
|
type linkerAttributes struct {
|
||||||
deps bazel.LabelListAttribute
|
deps bazel.LabelListAttribute
|
||||||
linkopts bazel.StringListAttribute
|
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.
|
// configurable attribute values.
|
||||||
func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {
|
func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {
|
||||||
var deps bazel.LabelListAttribute
|
var deps bazel.LabelListAttribute
|
||||||
var linkopts bazel.StringListAttribute
|
var linkopts bazel.StringListAttribute
|
||||||
|
var versionScript bazel.LabelAttribute
|
||||||
|
|
||||||
for _, linkerProps := range module.linker.linkerProps() {
|
for _, linkerProps := range module.linker.linkerProps() {
|
||||||
if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {
|
if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {
|
||||||
@@ -265,6 +267,12 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
|
|||||||
libs = android.SortedUniqueStrings(libs)
|
libs = android.SortedUniqueStrings(libs)
|
||||||
deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs))
|
deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs))
|
||||||
linkopts.Value = baseLinkerProps.Ldflags
|
linkopts.Value = baseLinkerProps.Ldflags
|
||||||
|
|
||||||
|
if baseLinkerProps.Version_script != nil {
|
||||||
|
versionScript = bazel.LabelAttribute{
|
||||||
|
Value: android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script),
|
||||||
|
}
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,8 +302,9 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return linkerAttributes{
|
return linkerAttributes{
|
||||||
deps: deps,
|
deps: deps,
|
||||||
linkopts: linkopts,
|
linkopts: linkopts,
|
||||||
|
versionScript: versionScript,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -228,6 +228,7 @@ type bazelCcLibraryAttributes struct {
|
|||||||
User_link_flags bazel.StringListAttribute
|
User_link_flags bazel.StringListAttribute
|
||||||
Includes bazel.StringListAttribute
|
Includes bazel.StringListAttribute
|
||||||
Static_deps_for_shared bazel.LabelListAttribute
|
Static_deps_for_shared bazel.LabelListAttribute
|
||||||
|
Version_script bazel.LabelAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
type bazelCcLibrary struct {
|
type bazelCcLibrary struct {
|
||||||
@@ -273,6 +274,7 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
|
|||||||
Copts: compilerAttrs.copts,
|
Copts: compilerAttrs.copts,
|
||||||
Linkopts: linkerAttrs.linkopts,
|
Linkopts: linkerAttrs.linkopts,
|
||||||
Deps: linkerAttrs.deps,
|
Deps: linkerAttrs.deps,
|
||||||
|
Version_script: linkerAttrs.versionScript,
|
||||||
Static_deps_for_shared: sharedAttrs.staticDeps,
|
Static_deps_for_shared: sharedAttrs.staticDeps,
|
||||||
Includes: exportedIncludes,
|
Includes: exportedIncludes,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user