From 7f5dd0a439fdf927853b219f9a8c267223f3bdd2 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 7 Dec 2022 13:40:20 -0800 Subject: [PATCH] Stop using absl flags in proguard_whitelister. https://github.com/bazelbuild/bazel/issues/16882 PiperOrigin-RevId: 493696178 Change-Id: I61dbfb6f35fd5be77aa97f579d69b26bf8b01f89 --- tools/jdk/BUILD.tools | 3 --- tools/jdk/proguard_whitelister.py | 34 +++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/tools/jdk/BUILD.tools b/tools/jdk/BUILD.tools index 375c2d4f91d1a0..42dbbb3ce73864 100644 --- a/tools/jdk/BUILD.tools +++ b/tools/jdk/BUILD.tools @@ -395,9 +395,6 @@ py_binary( srcs = [ "proguard_whitelister.py", ], - deps = [ - "//third_party/py/abseil", - ], ) py_test( diff --git a/tools/jdk/proguard_whitelister.py b/tools/jdk/proguard_whitelister.py index b123d7a6d2b36e..c5e18d5a9ac50c 100644 --- a/tools/jdk/proguard_whitelister.py +++ b/tools/jdk/proguard_whitelister.py @@ -21,17 +21,10 @@ binary through a library dependency. """ +import argparse import re from typing import Sequence -# Do not edit this line. Copybara replaces it with PY2 migration helper. -from absl import app -from absl import flags - -flags.DEFINE_string('path', None, 'Path to the proguard config to validate') -flags.DEFINE_string('output', None, 'Where to put the validated config') - -FLAGS = flags.FLAGS PROGUARD_COMMENTS_PATTERN = '#.*(\n|$)' @@ -83,10 +76,29 @@ def _ValidateArg(self, arg: str) -> bool: return False -def main(unused_argv: Sequence[str]): - validator = ProguardConfigValidator(FLAGS.path, FLAGS.output) +def ParseCommandLine() -> Sequence[str]: + """Parses the command line and returns a flags block.""" + parser = argparse.ArgumentParser( + description="""Checks for proguard configuration rules that cannot be combined across libs. + +The only valid proguard arguments for a library are -keep, -assumenosideeffects, +-assumevalues and -dontnote and -dontwarn when they are provided with arguments. +Limiting libraries to using these flags prevents drastic, sweeping effects +(such as obfuscation being disabled) from being inadvertently applied to a +binary through a library dependency.""") + parser.add_argument('--path', required=True, + help='Path to the proguard config to validate') + parser.add_argument('--output', required=True, + help='Where to put the validated config') + flags = parser.parse_args() + return flags + + +def main(): + flags = ParseCommandLine() + validator = ProguardConfigValidator(flags.path, flags.output) validator.ValidateAndWriteOutput() if __name__ == '__main__': - app.run(main) + main()