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

Java9 update #16

Merged
merged 3 commits into from
Nov 6, 2019
Merged
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
19 changes: 19 additions & 0 deletions do_like_javac/tools/infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os,sys
import argparse
import subprocess
import common

argparser = argparse.ArgumentParser(add_help=False)
Expand Down Expand Up @@ -42,6 +43,24 @@ def get_tool_command(args, target_classpath, java_files, jaif_file="default.jaif
CFI_dist = os.path.join(os.environ['JSR308'], 'checker-framework-inference', 'dist')
CFI_command = ['java']

java_version = subprocess.check_output(["java", "-version"], stderr=subprocess.STDOUT)
# Compatible with Python3. In Python 2.7, type(java_version) == str; but in Python3, type(java_version) == bytes.
# After do-like-javac updates to Python 3, this code can still work.
if isinstance(java_version, bytes):
java_version = java_version.decode("utf-8")
# java_version is a String like this:
# 'openjdk version "1.8.0_222"
# OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~19.04.1-b10)
# OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
# '
# We need to extract the version number from this String.
# split_version_number is a list of split version numbers in String type, e.g., ["1", "8", "0_222"].
# For Java 9+, it can simply be ["9"]. So in this case we should compare the first element directly.
split_version_number = java_version.splitlines()[0].split()[2].strip('"').split(".")
is_jvm8 = split_version_number[0] == "8" if len(split_version_number) == 1 else split_version_number[1] == "8"
if is_jvm8:
CFI_command += ['-DInferenceLauncher.runtime.bcp=' + os.path.join(CFI_dist, "javac.jar")]

cp = target_classpath + \
':' + os.path.join(CFI_dist, 'checker.jar') + \
':' + os.path.join(CFI_dist, 'plume.jar') + \
Expand Down