Support tailoring clang --target flag based on min sdk version.
Bug: 215748260
Test: Tested using aquery to verify the --target flag; add added unit
Change-Id: Ifb13509db7d1e110316aa44d55ec9cccaa4b83d1
diff --git a/cc/binary.go b/cc/binary.go
index 9262f21..89e7262 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -630,6 +630,8 @@
},
Features: baseAttrs.features,
+
+ sdkAttributes: bp2BuildParseSdkAttributes(m),
}
ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
@@ -673,4 +675,6 @@
Strip stripAttributes
Features bazel.StringListAttribute
+
+ sdkAttributes
}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 379d6f2..93d11c7 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -52,6 +52,8 @@
System_dynamic_deps bazel.LabelListAttribute
Enabled bazel.BoolAttribute
+
+ sdkAttributes
}
// groupSrcsByExtension partitions `srcs` into groups based on file extension.
@@ -539,6 +541,18 @@
}
}
+func bp2BuildParseSdkAttributes(module *Module) sdkAttributes {
+ return sdkAttributes {
+ Sdk_version: module.Properties.Sdk_version,
+ Min_sdk_version: module.Properties.Min_sdk_version,
+ }
+}
+
+type sdkAttributes struct {
+ Sdk_version *string
+ Min_sdk_version *string
+}
+
// Convenience struct to hold all attributes parsed from linker properties.
type linkerAttributes struct {
deps bazel.LabelListAttribute
diff --git a/cc/library.go b/cc/library.go
index 5fa3471..035a90e 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -316,6 +316,7 @@
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
Whole_archive_deps: *linkerAttrs.wholeArchiveDeps.Clone().Append(staticAttrs.Whole_archive_deps),
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(staticAttrs.System_dynamic_deps),
+ sdkAttributes: bp2BuildParseSdkAttributes(m),
}
sharedCommonAttrs := staticOrSharedAttributes{
@@ -331,6 +332,7 @@
Implementation_dynamic_deps: *linkerAttrs.implementationDynamicDeps.Clone().Append(sharedAttrs.Implementation_dynamic_deps),
Whole_archive_deps: *linkerAttrs.wholeArchiveDeps.Clone().Append(sharedAttrs.Whole_archive_deps),
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(sharedAttrs.System_dynamic_deps),
+ sdkAttributes: bp2BuildParseSdkAttributes(m),
}
staticTargetAttrs := &bazelCcLibraryStaticAttributes{
@@ -2481,6 +2483,7 @@
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
+ sdkAttributes: bp2BuildParseSdkAttributes(module),
}
var attrs interface{}
diff --git a/cc/library_headers.go b/cc/library_headers.go
index 5d38fba..41ebcc7 100644
--- a/cc/library_headers.go
+++ b/cc/library_headers.go
@@ -117,6 +117,7 @@
Deps bazel.LabelListAttribute
Implementation_deps bazel.LabelListAttribute
System_dynamic_deps bazel.LabelListAttribute
+ sdkAttributes
}
func libraryHeadersBp2Build(ctx android.TopDownMutatorContext, module *Module) {
@@ -132,6 +133,7 @@
Deps: linkerAttrs.deps,
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
Hdrs: baseAttributes.hdrs,
+ sdkAttributes: bp2BuildParseSdkAttributes(module),
}
props := bazel.BazelTargetModuleProperties{
diff --git a/cc/object.go b/cc/object.go
index fdd0b11..bd5bd45 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -133,6 +133,7 @@
Absolute_includes bazel.StringListAttribute
Stl *string
Linker_script bazel.LabelAttribute
+ sdkAttributes
}
// objectBp2Build is the bp2build converter from cc_object modules to the
@@ -191,6 +192,7 @@
Absolute_includes: compilerAttrs.absoluteIncludes,
Stl: compilerAttrs.stl,
Linker_script: linkerScript,
+ sdkAttributes: bp2BuildParseSdkAttributes(m),
}
props := bazel.BazelTargetModuleProperties{