From 4517075ff64fcac79d4dc92d2f4b79ff16ecd2db Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sat, 8 May 2021 03:20:40 -0700 Subject: [PATCH] Don't supply `--release 8` and `--add-opens` together --- do_like_javac/command.py | 2 ++ do_like_javac/tools/check.py | 12 ++++++++++-- do_like_javac/tools/common.py | 3 ++- do_like_javac/tools/wpi.py | 12 ++++++++++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/do_like_javac/command.py b/do_like_javac/command.py index 253b027..1cbd67f 100644 --- a/do_like_javac/command.py +++ b/do_like_javac/command.py @@ -24,6 +24,8 @@ def main(): sys.exit(1) javac_commands, jars, stats = result + if len(javac_commands) == 0: + raise Exception("command.main: no javac commands found by capturer:\n cmd = {}\n args = {}".format(cmd, args)) log.info('Results: %s', pprint.pformat(javac_commands)) output_json(os.path.join(args.output_directory, 'javac.json'), javac_commands) diff --git a/do_like_javac/tools/check.py b/do_like_javac/tools/check.py index 1a809e4..a58f071 100644 --- a/do_like_javac/tools/check.py +++ b/do_like_javac/tools/check.py @@ -16,6 +16,7 @@ def run(args, javac_commands, jars): checker_command += getArgumentsByVersion(args.jdkVersion) for jc in javac_commands: + ## What is the point of this pprint command, whose result is not used? pprint.pformat(jc) javac_switches = jc['javac_switches'] cp = javac_switches['classpath'] @@ -31,7 +32,8 @@ def run(args, javac_commands, jars): cmd = checker_command + ["-classpath", cp] + java_files common.run_cmd(cmd, args, 'check') -def getArgumentsByVersion(jdkVersion): +## other_args is other command-line arguments to javac +def getArgumentsByVersion(jdkVersion, other_args=[]): if jdkVersion is not None: version = int(jdkVersion) else: @@ -41,7 +43,13 @@ def getArgumentsByVersion(jdkVersion): if version == 8: result += ['-J-Xbootclasspath/p:' + os.environ['CHECKERFRAMEWORK'] + '/checker/dist/javac.jar'] elif version == 11: - result += ['-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED'] + release_8 = False + for i, str in enumerate(other_args): + if str == '--release' and other_args[i+1] == "8": + release_8 = True + if not release_8: + # Avoid javac "error: option --add-opens not allowed with target 1.8" + result += ['-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED'] else: raise ValueError("the Checker Framework only supports Java versions 8 and 11") diff --git a/do_like_javac/tools/common.py b/do_like_javac/tools/common.py index 2a7c5d2..ade95c3 100644 --- a/do_like_javac/tools/common.py +++ b/do_like_javac/tools/common.py @@ -56,7 +56,8 @@ def run_cmd(cmd, args=None, tool=None): timer = None out = None out_file = None - friendly_cmd = ' '.join(cmd) + # Without quoting, empty arguments don't appear in friendly_cmd + friendly_cmd = ' '.join("'" + elt + "'" for elt in cmd) if args and args.verbose and args.log_to_stderr: out = sys.stderr diff --git a/do_like_javac/tools/wpi.py b/do_like_javac/tools/wpi.py index 04a3f4c..ab5e5f6 100644 --- a/do_like_javac/tools/wpi.py +++ b/do_like_javac/tools/wpi.py @@ -36,8 +36,6 @@ def run(args, javac_commands, jars): else: jdkVersion = 8 - checker_command += check.getArgumentsByVersion(jdkVersion) - if args.extraJavacArgs is not None: checker_command += args.extraJavacArgs.split() @@ -114,6 +112,7 @@ def run(args, javac_commands, jars): if args.lib_dir: cp += pp + args.lib_dir + ':' + release8 = False other_args = [] for k, v in javac_switches.items(): if k not in ignored_options and not k.startswith(ignored_options_prefixes): @@ -125,6 +124,8 @@ def run(args, javac_commands, jars): # the build, and this is the best that DLJC can do in this situation. if v in ["1.5", "5", "1.6", "6", "1.7", "7", "1.8"]: v = "8" + if v == "8": + release8 = True # Do not use source/target, because Java 11 JVMs will # crash on some classes, e.g. # https://bugs.openjdk.java.net/browse/JDK-8212636. @@ -139,6 +140,13 @@ def run(args, javac_commands, jars): if v is not None and v is not True: other_args.append(str(v)) + checker_command += check.getArgumentsByVersion(jdkVersion, other_args) + + if release8: + # Avoid javac "error: option --add-opens not allowed with target 1.8" + checker_command = [arg for arg in checker_command if not arg.startswith("--add-opens")] + other_args = [arg for arg in other_args if not arg.startswith("--add-opens")] + while diffResult != 0: iterationStubs = ':'.join(stubDirs)