Gen a header library when genrules export includes
Embedding multiple includes from a genrule may be difficult to read,
instead we generate a header library that contains the headers and all
include dirs that Soong generates.
Test: go test bp2build tests
Change-Id: I590c74c133f015f27cccf5a2fd916153ad9c125e
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 9895a20..9e485d6 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -22,6 +22,7 @@
"android/soong/android"
"android/soong/bazel"
"android/soong/cc/config"
+ "android/soong/genrule"
"github.com/google/blueprint"
@@ -45,6 +46,8 @@
xsdSrcPartition = "xsd"
+ genrulePartition = "genrule"
+
hdrPartition = "hdr"
stubsSuffix = "_stub_libs_current"
@@ -172,8 +175,9 @@
func partitionHeaders(ctx android.BazelConversionPathContext, hdrs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute {
labels := bazel.LabelPartitions{
- xsdSrcPartition: bazel.LabelPartition{LabelMapper: android.XsdLabelMapper(xsdConfigCppTarget)},
- hdrPartition: bazel.LabelPartition{Keep_remainder: true},
+ xsdSrcPartition: bazel.LabelPartition{LabelMapper: android.XsdLabelMapper(xsdConfigCppTarget)},
+ genrulePartition: bazel.LabelPartition{LabelMapper: genrule.GenruleCcHeaderLabelMapper},
+ hdrPartition: bazel.LabelPartition{Keep_remainder: true},
}
return bazel.PartitionLabelListAttribute(ctx, &hdrs, labels)
}
@@ -419,6 +423,10 @@
xsdSrcs bazel.LabelListAttribute
exportXsdSrcs bazel.LabelListAttribute
+ // genrule headers
+ genruleHeaders bazel.LabelListAttribute
+ exportGenruleHeaders bazel.LabelListAttribute
+
// Lex sources and options
lSrcs bazel.LabelListAttribute
llSrcs bazel.LabelListAttribute
@@ -606,6 +614,9 @@
ca.exportXsdSrcs = partitionedHdrs[xsdSrcPartition]
ca.xsdSrcs = bazel.FirstUniqueBazelLabelListAttribute(xsdSrcs)
+ ca.genruleHeaders = partitionedImplHdrs[genrulePartition]
+ ca.exportGenruleHeaders = partitionedHdrs[genrulePartition]
+
ca.srcs = partitionedSrcs[cppSrcPartition]
ca.cSrcs = partitionedSrcs[cSrcPartition]
ca.asSrcs = partitionedSrcs[asSrcPartition]
@@ -900,6 +911,9 @@
(&compilerAttrs.srcs).Add(bp2BuildYasm(ctx, module, compilerAttrs))
+ (&linkerAttrs).deps.Append(compilerAttrs.exportGenruleHeaders)
+ (&linkerAttrs).implementationDeps.Append(compilerAttrs.genruleHeaders)
+
(&linkerAttrs).wholeArchiveDeps.Append(compilerAttrs.exportXsdSrcs)
(&linkerAttrs).implementationWholeArchiveDeps.Append(compilerAttrs.xsdSrcs)