Merge changes Ib004c2c3,I6b63d9d0
* changes: Create aliases for stubs in build/bazel/api_surfaces Add a method in bp2build to create aliases in another directory
This commit is contained in:
@@ -1837,3 +1837,14 @@ func (c *config) LogMixedBuild(ctx BaseModuleContext, useBazel bool) {
|
||||
c.mixedBuildDisabledModules[moduleName] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// ApiSurfaces directory returns the source path inside the api_surfaces repo
|
||||
// (relative to workspace root).
|
||||
func (c *config) ApiSurfacesDir(s ApiSurface, version string) string {
|
||||
return filepath.Join(
|
||||
"build",
|
||||
"bazel",
|
||||
"api_surfaces",
|
||||
s.String(),
|
||||
version)
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
@@ -60,6 +60,15 @@ func (t BazelTarget) Label() string {
|
||||
}
|
||||
}
|
||||
|
||||
// PackageName returns the package of the Bazel target.
|
||||
// Defaults to root of tree.
|
||||
func (t BazelTarget) PackageName() string {
|
||||
if t.packageName == "" {
|
||||
return "."
|
||||
}
|
||||
return t.packageName
|
||||
}
|
||||
|
||||
// BazelTargets is a typedef for a slice of BazelTarget objects.
|
||||
type BazelTargets []BazelTarget
|
||||
|
||||
@@ -337,7 +346,10 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers
|
||||
return
|
||||
}
|
||||
|
||||
buildFileToTargets[dir] = append(buildFileToTargets[dir], targets...)
|
||||
for _, target := range targets {
|
||||
targetDir := target.PackageName()
|
||||
buildFileToTargets[targetDir] = append(buildFileToTargets[targetDir], target)
|
||||
}
|
||||
})
|
||||
|
||||
if len(errs) > 0 {
|
||||
@@ -454,7 +466,8 @@ func generateSoongModuleTarget(ctx bpToBuildContext, m blueprint.Module) (BazelT
|
||||
|
||||
targetName := targetNameWithVariant(ctx, m)
|
||||
return BazelTarget{
|
||||
name: targetName,
|
||||
name: targetName,
|
||||
packageName: ctx.ModuleDir(m),
|
||||
content: fmt.Sprintf(
|
||||
soongModuleTargetTemplate,
|
||||
targetName,
|
||||
|
@@ -464,6 +464,21 @@ func createStubsBazelTargetIfNeeded(ctx android.TopDownMutatorContext, m *Module
|
||||
ctx.CreateBazelTargetModule(stubSuitesProps,
|
||||
android.CommonAttributes{Name: m.Name() + "_stub_libs"},
|
||||
stubSuitesAttrs)
|
||||
|
||||
// Add alias for the stub shared_library in @api_surfaces repository
|
||||
currentModuleLibApiDir := ctx.Config().ApiSurfacesDir(android.ModuleLibApi, "current")
|
||||
actualLabelInMainWorkspace := bazel.Label{
|
||||
Label: fmt.Sprintf("@//%s:%s_stub_libs_current", ctx.ModuleDir(), m.Name()),
|
||||
}
|
||||
ctx.CreateBazelTargetAliasInDir(currentModuleLibApiDir, m.Name(), actualLabelInMainWorkspace)
|
||||
|
||||
// Add alias for headers exported by the stub library
|
||||
headerLabelInMainWorkspace := bazel.Label{
|
||||
// This label is generated from cc_stub_suite macro
|
||||
Label: fmt.Sprintf("@//%s:%s_stub_libs_%s_headers", ctx.ModuleDir(), m.Name(), android.ModuleLibApi.String()),
|
||||
}
|
||||
headerAlias := m.Name() + "_headers"
|
||||
ctx.CreateBazelTargetAliasInDir(currentModuleLibApiDir, headerAlias, headerLabelInMainWorkspace)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user