Add a method in bp2build to create aliases in another directory
The expected use case for this is to create aliases for stub libraries in the @api_surfaces repository in build/bazel/api_surfaces. This restricts the scope to just aliases. If we have a use case for generating actual Bazel targets in another directory, a workaround could be to generate the targets in the current directory (via CreateBazelTargetModule) and aliases to it in the other directory Test: go test ./bp2build Change-Id: I6b63d9d018618d447fc7c260a2a94aaa00e57a4d
This commit is contained in:
@@ -268,6 +268,11 @@ type TopDownMutatorContext interface {
|
||||
// platforms, as dictated by a given bool attribute: the target will not be buildable in
|
||||
// any platform for which this bool attribute is false.
|
||||
CreateBazelTargetModuleWithRestrictions(bazel.BazelTargetModuleProperties, CommonAttributes, interface{}, bazel.BoolAttribute)
|
||||
|
||||
// CreateBazelTargetAliasInDir creates an alias definition in `dir` directory.
|
||||
// This function can be used to create alias definitions in a directory that is different
|
||||
// from the directory of the visited Soong module.
|
||||
CreateBazelTargetAliasInDir(dir string, name string, actual bazel.Label)
|
||||
}
|
||||
|
||||
type topDownMutatorContext struct {
|
||||
@@ -705,6 +710,34 @@ func (t *topDownMutatorContext) CreateBazelTargetModuleWithRestrictions(
|
||||
t.createBazelTargetModule(bazelProps, commonAttrs, attrs, enabledProperty)
|
||||
}
|
||||
|
||||
var (
|
||||
bazelAliasModuleProperties = bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "alias",
|
||||
}
|
||||
)
|
||||
|
||||
type bazelAliasAttributes struct {
|
||||
Actual *bazel.LabelAttribute
|
||||
}
|
||||
|
||||
func (t *topDownMutatorContext) CreateBazelTargetAliasInDir(
|
||||
dir string,
|
||||
name string,
|
||||
actual bazel.Label) {
|
||||
mod := t.Module()
|
||||
attrs := &bazelAliasAttributes{
|
||||
Actual: bazel.MakeLabelAttribute(actual.Label),
|
||||
}
|
||||
info := bp2buildInfo{
|
||||
Dir: dir,
|
||||
BazelProps: bazelAliasModuleProperties,
|
||||
CommonAttrs: CommonAttributes{Name: name},
|
||||
ConstraintAttrs: constraintAttributes{},
|
||||
Attrs: attrs,
|
||||
}
|
||||
mod.base().addBp2buildInfo(info)
|
||||
}
|
||||
|
||||
// ApexAvailableTags converts the apex_available property value of an ApexModule
|
||||
// module and returns it as a list of keyed tags.
|
||||
func ApexAvailableTags(mod Module) bazel.StringListAttribute {
|
||||
|
Reference in New Issue
Block a user