Skip to content

Commit

Permalink
Java9 update (#16)
Browse files Browse the repository at this point in the history
If using jvm8, add runtimeBCP to CFI command.
  • Loading branch information
xingweitian authored Nov 6, 2019
1 parent 8de65ad commit b4ece23
Showing 1 changed file with 19 additions and 0 deletions.
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

0 comments on commit b4ece23

Please sign in to comment.