Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support overriding debuggable in AndroidManifest #13801 #238

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rules/android_binary/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ ATTRS = _attrs.replace(
Allow for the optimizer to process resources. This is not supported in proguard.
""",
),
_enable_debuggable_from_manifest_values = attr.label(
default = "//rules/flags:enable_debuggable_from_manifest_values",
doc = "Enables setting 'debuggable' of the app from android_binary#manifest_values.",
),
),
_attrs.compilation_attributes(apply_android_transition = True),
_attrs.DATA_CONTEXT,
Expand Down
4 changes: 4 additions & 0 deletions rules/android_library/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ ATTRS = _attrs.add(
_aidl_lib = attr.label(
default = Label("//rules:aidl_lib"),
),
_enable_debuggable_from_manifest_values = attr.label(
default = "//rules/flags:enable_debuggable_from_manifest_values",
doc = "Enables setting 'debuggable' of the app from android_binary#manifest_values.",
),
),
_attrs.compilation_attributes(),
_attrs.DATA_CONTEXT,
Expand Down
4 changes: 4 additions & 0 deletions rules/android_local_test/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ def make_attrs(additional_aspects = [], native_libs_transition = None):
_manifest_merge_order = attr.label(
default = "//rules/flags:manifest_merge_order",
),
_enable_debuggable_from_manifest_values = attr.label(
default = "//rules/flags:enable_debuggable_from_manifest_values",
doc = "Enables setting 'debuggable' of the app from android_binary#manifest_values.",
),
),
_attrs.compilation_attributes(),
_attrs.DATA_CONTEXT,
Expand Down
9 changes: 8 additions & 1 deletion rules/flags/additional_flags.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
"""Additional flag definitions."""

load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")

def additional_flags():

Expand All @@ -28,4 +28,11 @@ def additional_flags():
"dependency",
],
visibility = ["//visibility:public"],
)

# Enables setting 'debuggable' of the app from android_binary#manifest_values.
bool_flag(
name = "enable_debuggable_from_manifest_values",
build_setting_default = False,
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion rules/flags/flag_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ def define_flags():
name = "use_studio_deployer",
default = True,
description = "Use Studio Deployer to install apks",
)
)
7 changes: 1 addition & 6 deletions rules/flags/flags.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,7 @@ def native_bool_flag_macro(name, description):
)

def _get_bool(v):
v = v.lower()
if v == "true":
return True
if v == "false":
return False
fail("Unknown bool: " + v)
return utils.get_bool(v)

def _bool_impl(ctx):
if ctx.label.name in ctx.var:
Expand Down
13 changes: 10 additions & 3 deletions rules/resources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,13 @@ def _package(
resource_files_zip = ctx.actions.declare_file(
"_migrated/" + ctx.label.name + "_files/resource_files.zip",
)
manifest_debuggable = utils.get_bool(manifest_values["debuggable"]) if "debuggable" in manifest_values else None
# By default, the debug flag passed to AAPT2 should be the inverse of the OPT flag (i.e. -c opt --> debug disabled)
aapt2_debug_mode = compilation_mode != _compilation_mode.OPT
# If the --@rules_android//rules/flags:enable_debuggable_from_manifest_values flag is passed, then get
# the AAPT2 debug flag value from the Bazel/Blaze command line.
if ctx.attr._enable_debuggable_from_manifest_values[BuildSettingInfo].value and manifest_debuggable != None:
aapt2_debug_mode = manifest_debuggable
_busybox.package(
ctx,
out_file = resource_apk,
Expand Down Expand Up @@ -773,7 +780,7 @@ def _package(
aapt = aapt,
busybox = busybox,
host_javabase = host_javabase,
debug = compilation_mode != _compilation_mode.OPT,
debug = aapt2_debug_mode,
should_throw_on_conflict = should_throw_on_conflict,
)

Expand Down Expand Up @@ -1889,7 +1896,7 @@ def _shrink(
r_txt = r_txt,
shrunk_jar = shrunk_jar,
proguard_mapping = proguard_mapping,
debug = _compilation_mode.get(ctx) != _compilation_mode.OPT,
manifest_debuggable = _compilation_mode.get(ctx) != _compilation_mode.OPT,
busybox = busybox,
host_javabase = host_javabase,
)
Expand Down Expand Up @@ -1937,7 +1944,7 @@ def _convert_resources_to_apk(
resources_zip = resources_zip,
aapt = aapt,
android_jar = android_jar,
debug = _compilation_mode.get(ctx) != _compilation_mode.OPT,
manifest_debuggable = _compilation_mode.get(ctx) != _compilation_mode.OPT,
busybox = busybox,
host_javabase = host_javabase,
)
Expand Down
9 changes: 9 additions & 0 deletions rules/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,14 @@ def _get_compilation_mode(ctx):
"""
return ctx.var["COMPILATION_MODE"]

def _get_bool(v):
v = v.lower()
if v == "true":
return True
if v == "false":
return False
fail("Unknown bool: " + v)

compilation_mode = struct(
DBG = "dbg",
FASTBUILD = "fastbuild",
Expand All @@ -465,6 +473,7 @@ utils = struct(
list_or_depset_to_list = _list_or_depset_to_list,
add_cls_prefix = _add_cls_prefix,
get_cls = _get_cls,
get_bool = _get_bool
)

log = struct(
Expand Down