Handle asflags with var expansion in cc_object
Bug: 181794963
Test: build/bazel/milestone2/demo.sh full
Test: build/bazel/milestone2/demo.sh generate &&
build/bazel/milestone2/demo.sh sync &&
USE_BAZEL_ANALYSIS=1 m droid
Change-Id: I7770fe82e72f552842b2462af709b86a4f40df9f
diff --git a/product_variables/BUILD.bazel b/product_variables/BUILD.bazel
new file mode 100644
index 0000000..f8462f5
--- /dev/null
+++ b/product_variables/BUILD.bazel
@@ -0,0 +1,8 @@
+# Hard-coded product_variables until product product_variables is available.
+load(":product_variables.bzl", "product_variables_providing_rule")
+
+package(default_visibility = ["//visibility:public"])
+
+product_variables_providing_rule(
+ name = "android_product_variables",
+)
diff --git a/product_variables/product_variables.bzl b/product_variables/product_variables.bzl
new file mode 100644
index 0000000..e9b59e8
--- /dev/null
+++ b/product_variables/product_variables.bzl
@@ -0,0 +1,29 @@
+"""Hard-coded rules for product variables until product config files are
+converted and available."""
+
+def _product_variables_providing_rule_impl(ctx):
+ return [
+ platform_common.TemplateVariableInfo({
+ "Platform_version_name": ctx.attr.platform_version_name,
+ "Platform_sdk_version": str(ctx.attr.platform_sdk_version),
+ "Platform_sdk_codename": ctx.attr.platform_sdk_codename,
+ "Platform_sdk_final": str(1 if ctx.attr.platform_sdk_final else 0),
+ "Platform_version_active_codenames": ",".join(ctx.attr.platform_version_active_codenames),
+ "Platform_vndk_version": ctx.attr.platform_vndk_version,
+ }),
+ ]
+
+# Values taken from https://cs.android.com/android/platform/superproject/+/master:build/soong/android/variable.go;l=412;drc=7b85eeb41ef3e6d2cf44558d3f54f9ed1b247036
+product_variables_providing_rule = rule(
+ implementation = _product_variables_providing_rule_impl,
+ attrs = {
+ "platform_version_name": attr.string(default="S"),
+ "platform_sdk_version": attr.int(default=30),
+ "platform_sdk_codename": attr.string(default="S"),
+ "platform_sdk_final": attr.bool(default=False),
+ "platform_version_active_codenames": attr.string_list(default=["S"]),
+ "platform_vndk_version": attr.string(default="S"),
+ },
+)
+
+
diff --git a/rules/cc_object.bzl b/rules/cc_object.bzl
index 9768751..1357ff0 100644
--- a/rules/cc_object.bzl
+++ b/rules/cc_object.bzl
@@ -40,6 +40,9 @@
for dep in ctx.attr.include_deps:
compilation_contexts.append(dep[CcInfo].compilation_context)
+ product_variables = ctx.attr._android_product_variables[platform_common.TemplateVariableInfo]
+ asflags = [flag.format(**product_variables.variables) for flag in ctx.attr.asflags]
+
(compilation_context, compilation_outputs) = cc_common.compile(
name = ctx.label.name,
actions = ctx.actions,
@@ -49,7 +52,7 @@
includes = ctx.attr.includes,
public_hdrs = ctx.files.hdrs,
private_hdrs = ctx.files.private_hdrs,
- user_compile_flags = ctx.attr.copts,
+ user_compile_flags = ctx.attr.copts + asflags,
compilation_contexts = compilation_contexts,
)
@@ -83,12 +86,17 @@
"private_hdrs": attr.label_list(allow_files = [".h"]),
"includes": attr.string_list(),
"copts": attr.string_list(),
+ "asflags": attr.string_list(),
"deps": attr.label_list(providers=[CcInfo, CcObjectInfo]),
"include_deps": attr.label_list(providers=[CcInfo]),
"_cc_toolchain": attr.label(
default = Label("@local_config_cc//:toolchain"),
providers = [cc_common.CcToolchainInfo],
),
+ "_android_product_variables": attr.label(
+ default = Label("//build/bazel/product_variables:android_product_variables"),
+ providers = [platform_common.TemplateVariableInfo],
+ ),
},
toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
fragments = ["cpp"],
@@ -97,6 +105,7 @@
def cc_object(
name,
copts = [],
+ asflags = [],
local_include_dirs = [],
srcs = [],
deps = [],
@@ -138,6 +147,7 @@
_cc_object(
name = name,
hdrs = hdrs,
+ asflags = asflags,
copts = _CC_OBJECT_COPTS + copts,
srcs = srcs,
include_deps = include_deps,