summaryrefslogtreecommitdiff
path: root/genrule/genrule.go
diff options
context:
space:
mode:
Diffstat (limited to 'genrule/genrule.go')
-rw-r--r--genrule/genrule.go54
1 files changed, 53 insertions, 1 deletions
diff --git a/genrule/genrule.go b/genrule/genrule.go
index a470c5e8a..69ba1e94e 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -296,6 +296,9 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) {
for _, dir := range g.properties.Export_include_dirs {
g.exportedIncludeDirs = append(g.exportedIncludeDirs,
android.PathForModuleGen(ctx, g.subDir, ctx.ModuleDir(), dir))
+ // Also export without ModuleDir for consistency with Export_include_dirs not being set
+ g.exportedIncludeDirs = append(g.exportedIncludeDirs,
+ android.PathForModuleGen(ctx, g.subDir, dir))
}
} else {
g.exportedIncludeDirs = append(g.exportedIncludeDirs, android.PathForModuleGen(ctx, g.subDir))
@@ -991,6 +994,7 @@ func (m *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, m)
+ bazelName := m.Name()
if ctx.ModuleType() == "gensrcs" {
props := bazel.BazelTargetModuleProperties{
Rule_class: "gensrcs",
@@ -1018,7 +1022,6 @@ func (m *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
break
}
}
- bazelName := m.Name()
for _, out := range outs {
if out == bazelName {
// This is a workaround to circumvent a Bazel warning where a genrule's
@@ -1043,6 +1046,54 @@ func (m *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
Tags: tags,
}, attrs)
}
+
+ if m.needsCcLibraryHeadersBp2build() {
+ includeDirs := make([]string, len(m.properties.Export_include_dirs)*2)
+ for i, dir := range m.properties.Export_include_dirs {
+ includeDirs[i*2] = dir
+ includeDirs[i*2+1] = filepath.Clean(filepath.Join(ctx.ModuleDir(), dir))
+ }
+ attrs := &ccHeaderLibraryAttrs{
+ Hdrs: []string{":" + bazelName},
+ Export_includes: includeDirs,
+ }
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "cc_library_headers",
+ Bzl_load_location: "//build/bazel/rules/cc:cc_library_headers.bzl",
+ }
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{
+ Name: m.Name() + genruleHeaderLibrarySuffix,
+ Tags: tags,
+ }, attrs)
+
+ }
+}
+
+const genruleHeaderLibrarySuffix = "__header_library"
+
+func (m *Module) needsCcLibraryHeadersBp2build() bool {
+ return len(m.properties.Export_include_dirs) > 0
+}
+
+// GenruleCcHeaderMapper is a bazel.LabelMapper function to map genrules to a cc_library_headers
+// target when they export multiple include directories.
+func GenruleCcHeaderLabelMapper(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
+ mod, exists := ctx.ModuleFromName(label.OriginalModuleName)
+ if !exists {
+ return label.Label, false
+ }
+ if m, ok := mod.(*Module); ok {
+ if m.needsCcLibraryHeadersBp2build() {
+ return label.Label + genruleHeaderLibrarySuffix, true
+ }
+ }
+ return label.Label, false
+}
+
+type ccHeaderLibraryAttrs struct {
+ Hdrs []string
+
+ Export_includes []string
}
var Bool = proptools.Bool
@@ -1096,6 +1147,7 @@ func getSandboxingAllowlistSets(ctx android.PathContext) *sandboxingAllowlistSet
}
}).(*sandboxingAllowlistSets)
}
+
func getSandboxedRuleBuilder(ctx android.ModuleContext, r *android.RuleBuilder) *android.RuleBuilder {
if !ctx.DeviceConfig().GenruleSandboxing() {
return r.SandboxTools()