Commit 80537336 authored by Tobias Sargeant's avatar Tobias Sargeant Committed by Commit Bot

Reland "[proguard] Include proguard info in sourcefile attribute."

This is a reland of 786379ee

Original change's description:
> [proguard] Include proguard info in sourcefile attribute.
>
> Instead of setting the sourcefile to PG when obfuscating Java, set it
> to chromium-{mapping file}-{channel}-{version code} so that
>
> a) We can recognise chrome/webview stack frames by this string
> b) The information required to uniquely identify the proguard mapping
>    file in question is directly available in stack traces.
>
> Bug: 1044585
> Change-Id: Ib4fabccfb7693e5e97edc6f29be1cd6cb61fa1e6
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2036091
> Commit-Queue: Tobias Sargeant <tobiasjs@chromium.org>
> Reviewed-by: Andrew Grieve <agrieve@chromium.org>
> Reviewed-by: Piotr Bialecki <bialpio@chromium.org>
> Reviewed-by: Richard Coles <torne@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#740625}

Bug: 1044585
Change-Id: Ib4f24fdd8a71e3048254000a525b82f5fbe3b4aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2054110Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarPiotr Bialecki <bialpio@chromium.org>
Commit-Queue: Tobias Sargeant <tobiasjs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741391}
parent 468d9a54
......@@ -3,7 +3,6 @@
# found in the LICENSE file.
import("//android_webview/variables.gni")
import("//base/android/proguard/proguard.gni")
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("//build/config/locales.gni")
......
......@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//chrome/android/channel.gni")
import("//build/config/android/channel.gni")
import("//weblayer/variables.gni")
declare_args() {
......
......@@ -4,5 +4,4 @@
# As of August 11, 2016, obfuscation was found to save 660kb on our .dex size
# and 53kb memory/process (through shrinking method/string counts).
-renamesourcefileattribute PG
-repackageclasses ''
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
declare_args() {
# Controls whether proguard obfuscation is enabled for targets
# configured to use it.
enable_proguard_obfuscation = true
}
......@@ -160,6 +160,7 @@ def _ParseOptions():
'--disable-checkdiscard',
action='store_true',
help='Disable -checkdiscard directives')
parser.add_argument('--sourcefile', help='Value for source file attribute')
options = parser.parse_args(args)
......@@ -380,6 +381,10 @@ def _CreateDynamicConfig(options):
public static final int SDK_INT return %s..9999;
}""" % options.min_api)
if options.sourcefile:
ret.append("-renamesourcefileattribute '%s' # OMIT FROM EXPECTATIONS" %
options.sourcefile)
if options.apply_mapping:
ret.append("-applymapping '%s'" % os.path.abspath(options.apply_mapping))
if options.repackage_classes:
......
......@@ -10,11 +10,24 @@ import difflib
from util import build_utils
def _SkipOmitted(line):
"""
Skip lines that are to be intentionally omitted from the expectations file.
This is required when the file to be compared against expectations contains
a line that changes from build to build because - for instance - it contains
version information.
"""
if line.endswith('# OMIT FROM EXPECTATIONS\n'):
return '# THIS LINE WAS OMITTED\n'
return line
def DiffFileContents(expected_path, actual_path):
"""Check file contents for equality and return the diff or None."""
with open(expected_path) as f_expected, open(actual_path) as f_actual:
expected_lines = f_expected.readlines()
actual_lines = f_actual.readlines()
actual_lines = [_SkipOmitted(line) for line in f_actual]
if expected_lines == actual_lines:
return None
......
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
declare_args() {
# The channel to build on Android: stable, beta, dev, canary, work, or
# default. "default" should be used on non-official builds.
android_channel = "default"
}
assert(android_channel == "default" || android_channel == "canary" ||
android_channel == "dev" || android_channel == "beta" ||
android_channel == "stable",
"Invalid channel: " + android_channel)
......@@ -200,6 +200,10 @@ if (is_android || is_chromeos) {
# Enable the chrome build for devices without touchscreens.
notouch_build = false
# Controls whether proguard obfuscation is enabled for targets
# configured to use it.
enable_proguard_obfuscation = true
}
assert(!(check_android_configuration && is_java_debug),
......
......@@ -968,6 +968,12 @@ if (enable_java_templates) {
if (defined(invoker.proguard_mapping_path)) {
_mapping_path = invoker.proguard_mapping_path
}
_proguard_sourcefile_suffix = ""
if (defined(invoker.proguard_sourcefile_suffix)) {
_proguard_sourcefile_suffix = "-${invoker.proguard_sourcefile_suffix}"
}
depfile = "${target_gen_dir}/${target_name}.d"
outputs = [
_output_path,
......@@ -987,6 +993,18 @@ if (enable_java_templates) {
"@FileArg($_rebased_build_config:android:sdk_jars)",
]
if (enable_proguard_obfuscation) {
# This is generally the apk name, and serves to identify the mapping
# file that would be required to deobfuscate a stacktrace.
_mapping_id = get_path_info(_mapping_path, "name")
args += [
"--sourcefile",
"chromium-${_mapping_id}${_proguard_sourcefile_suffix}",
]
} else {
not_needed([ "_proguard_sourcefile_suffix" ])
}
if (defined(invoker.disable_r8_outlining) &&
invoker.disable_r8_outlining) {
args += [ "--disable-outlining" ]
......@@ -1156,6 +1174,7 @@ if (enable_java_templates) {
"proguard_expectations_file",
"proguard_jar_path",
"proguard_mapping_path",
"proguard_sourcefile_suffix",
"is_static_library",
"testonly",
])
......
......@@ -5,6 +5,7 @@
# Do not add any imports to non-//build directories here.
# Some projects (e.g. V8) do not have non-build directories DEPS'ed in.
import("//build/config/android/channel.gni")
import("//build/config/android/config.gni")
import("//build/config/android/internal_rules.gni")
import("//build/config/clang/clang.gni")
......@@ -2335,6 +2336,7 @@ if (enable_java_templates) {
_proguard_enabled =
defined(invoker.proguard_enabled) && invoker.proguard_enabled
if (!_is_bundle_module && _proguard_enabled) {
_proguard_mapping_path = "$_final_apk_path.mapping"
}
......@@ -2931,6 +2933,7 @@ if (enable_java_templates) {
forward_variables_from(invoker, [ "proguard_jar_path" ])
deps += _deps + [ ":$_compile_resources_target" ]
proguard_mapping_path = _proguard_mapping_path
proguard_sourcefile_suffix = "$android_channel-$_version_code"
} else {
input_dex_filearg =
"@FileArg(${_rebased_build_config}:final_dex:all_dex_files)"
......@@ -4396,6 +4399,8 @@ if (enable_java_templates) {
# verify_proguard_flags: Enables verification of expected merged proguard
# flags based on a golden file.
#
# version_code: Optional. Version code of the target.
#
# is_multi_abi: If true will add a library placeholder for the missing ABI
# if either the primary or the secondary ABI has no native libraries set.
#
......@@ -4416,6 +4421,19 @@ if (enable_java_templates) {
_proguard_enabled =
defined(invoker.proguard_enabled) && invoker.proguard_enabled
if (defined(invoker.version_code)) {
_version_code = invoker.version_code
} else {
_version_code = android_default_version_code
}
if (android_override_version_code != "") {
_version_code = android_override_version_code
}
# Prevent "unused variable".
not_needed([ "_version_code" ])
_bundle_base_path = "$root_build_dir/apks"
if (defined(invoker.bundle_base_path)) {
_bundle_base_path = invoker.bundle_base_path
......@@ -4618,15 +4636,16 @@ if (enable_java_templates) {
"/java/$_target_name.proguard_flags.expected"
}
dex(_sync_dex_target) {
enable_multidex = _enable_multidex
proguard_enabled = true
proguard_mapping_path = _proguard_mapping_path
forward_variables_from(invoker,
[
"failed_proguard_expectation_file",
"proguard_jar_path",
"min_sdk_version",
])
enable_multidex = _enable_multidex
proguard_enabled = true
proguard_mapping_path = _proguard_mapping_path
proguard_sourcefile_suffix = "$android_channel-$_version_code"
build_config = _build_config
if (_verify_proguard_flags) {
......
# Copyright 2014 The Chromium Authors. All rights reserved.
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
declare_args() {
# The channel to build on Android: stable, beta, dev, canary, work, or
# default. "default" should be used on non-official builds.
android_channel = "default"
}
assert(android_channel == "default" || android_channel == "canary" ||
android_channel == "dev" || android_channel == "beta" ||
android_channel == "stable",
"Invalid channel: " + android_channel)
# Keep internal compiling
import("//build/config/android/channel.gni")
......@@ -4,7 +4,6 @@
import("//android_webview/variables.gni")
import("//base/android/linker/config.gni")
import("//base/android/proguard/proguard.gni")
import("//build/config/android/extract_unwind_tables.gni")
import("//build/config/android/rules.gni")
import("//build/config/compiler/compiler.gni")
......
......@@ -252,7 +252,6 @@
# As of August 11, 2016, obfuscation was found to save 660kb on our .dex size
# and 53kb memory/process (through shrinking method/string counts).
-renamesourcefileattribute PG
-repackageclasses ''
################################################################################
......@@ -750,6 +749,7 @@
################################################################################
# Dynamically generated from build/android/gyp/proguard.py
################################################################################
# THIS LINE WAS OMITTED
-keep @interface org.chromium.base.annotations.VerifiesOnNMR1
-keep,allowobfuscation,allowoptimization @org.chromium.base.annotations.VerifiesOnNMR1 class ** {
<methods>;
......
......@@ -2,8 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/android/channel.gni")
import("//build/config/android/config.gni")
import("//chrome/android/channel.gni")
declare_args() {
enable_usage_stats = android_channel == "default" ||
......
......@@ -79,6 +79,7 @@ template("chrome_bundle") {
"static_library_provider",
"static_library_synchronized_proguard",
"verify_proguard_flags",
"version_code",
])
command_line_flags_file = "chrome-command-line"
proguard_enabled = !is_java_debug
......
......@@ -2,7 +2,6 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//base/android/proguard/proguard.gni")
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("//build/util/version.gni")
......
......@@ -2,9 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/android/channel.gni")
import("//build/config/android/rules.gni")
import("//build/util/process_version.gni")
import("//chrome/android/channel.gni")
_version_constants_java_file = "$target_gen_dir/java/org/chromium/components/version_info/VersionConstants.java"
......
......@@ -5,7 +5,6 @@
import("//build/config/chrome_build.gni")
import("//build/config/chromecast_build.gni")
import("//build/config/gclient_args.gni")
import("//chrome/android/channel.gni")
declare_args() {
enable_gvr_services = is_android && !is_chromecast &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment