Skip to content

Commit

Permalink
Use ajava files (SRI-CSL#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwaataja authored Jun 24, 2021
1 parent 06f3e77 commit 4a78794
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ mechanism; from the javac documentation:
This tool also supports some other tool-specific optional arguments:
* `--stubs /path/to/stubs` tells the checker to run with the specified stub files.
* `--ajava /path/to/ajava` tells the checker to run with the specified ajava files.
* `--jdkVersion 8/11` tells the Checker Framework to run using JDK8 or JDK11.
* `--quals /path/to/qual.jar` tells the Checker Framework where to find qualifiers (annotations) to put on the classpath.
* `--extraJavacArgs='-AcustomArg1 -AcustomArg2'` passes the given arguments to invocations of `javac` that run
Expand Down
4 changes: 4 additions & 0 deletions do_like_javac/arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def __call__(self, parser, namespace, values, option_string=None):
action=AbsolutePathAction,
help='Location of stub files to use for the Checker Framework')

base_group.add_argument('--ajava', metavar='<ajava>',
action=AbsolutePathAction,
help='Location of ajava files to use for the Checker Framework')

base_group.add_argument('-l', '--lib', metavar='<lib_dir>',
action='store',dest='lib_dir',
help='Library directory with JARs for tools that need them.')
Expand Down
10 changes: 8 additions & 2 deletions do_like_javac/tools/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ def run(args, javac_commands, jars):
# checker-framework javac.
javacheck = os.environ['CHECKERFRAMEWORK']+"/checker/bin/javac"
if args.checker is not None:
checker_command = [javacheck, "-processor", args.checker, "-Astubs=" + str(args.stubs)]
checker_command = [
javacheck,
"-processor", args.checker,
"-Astubs=" + str(args.stubs),
"-Aajava=" + str(args.ajava)
]
else:
# checker should run via auto-discovery
checker_command = [javacheck, "-Astubs=" + str(args.stubs)]
checker_command = [javacheck, "-Astubs=" + str(args.stubs),
"-Aajava=" + str(args.ajava)]

checker_command += getArgumentsByVersion(args.jdkVersion)

Expand Down
48 changes: 25 additions & 23 deletions do_like_javac/tools/wpi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
from filecmp import dircmp

from datetime import datetime
Expand Down Expand Up @@ -52,10 +53,10 @@ def run(args, javac_commands, jars):

iteration = 0
diffResult = True
stubDirs = []
resultsDir = tempfile.mkdtemp(prefix="wpi-stubs-" + datetime.now().strftime("%Y%m%d%H%M%S") + "-")
ajavaDirs = []
resultsDir = tempfile.mkdtemp(prefix="wpi-ajava-" + datetime.now().strftime("%Y%m%d%H%M%S") + "-")

print("Directory for generated stub files: " + str(resultsDir))
print("Directory for generated annotation files: " + str(resultsDir))

javac_switches = jc['javac_switches']
cp = javac_switches['classpath']
Expand Down Expand Up @@ -149,19 +150,19 @@ def run(args, javac_commands, jars):
other_args = [arg for arg in other_args if not arg.startswith("--add-opens")]

while diffResult:

iterationStubs = ':'.join(stubDirs)
stubArg = None

iterationCheckerCmd = checker_command
# TODO: the switch to ajava files instead of stub files should make the separate stubs argument
# to dljc unnecessary, as there's no longer any need to combine stub lists.
# TODO: do we need to treat the -Aajava argument the same way? I.e., will this work if the user
# supplies their own -Aajava= argument as part of the extraJavacArgs argument?
if args.stubs:
stubArg = "-Astubs=" + str(args.stubs) + ":" + iterationStubs
elif iterationStubs != "":
stubArg = "-Astubs=" + iterationStubs

if stubArg is not None:
iterationCheckerCmd = checker_command + [stubArg]
else:
iterationCheckerCmd = checker_command
iterationCheckerCmd.append("-Astubs=" + str(args.stubs))
iterationAjavaDirs = ajavaDirs.copy()
if args.ajava:
iterationAjavaDirs.append(str(args.ajava))
if iterationAjavaDirs:
iterationCheckerCmd.append(
"-Aajava=" + ":".join(iterationAjavaDirs))

# suppress all type.anno.before.modifier warnings, because delombok
# prints annotations in the wrong place
Expand All @@ -171,27 +172,28 @@ def run(args, javac_commands, jars):
pprint.pformat(jc)

cmd = iterationCheckerCmd + ["-classpath", cp] + processorArg + other_args + java_files
stats = common.run_cmd(cmd + ["-Ainfer=stubs", "-Awarns"], args, 'wpi')
stats = common.run_cmd(cmd + ["-Ainfer=ajava", "-Awarns"], args, 'wpi')

# process outputs
# move the old wpi files, add them to stub path
# move the old wpi files, add them to ajava path
previousIterationDir = os.path.join(resultsDir, "iteration" + str(iteration))
os.mkdir(previousIterationDir)
iteration += 1
try:
stubs = os.listdir(wpiDir)
ajavaFiles = os.listdir(wpiDir)
except OSError as e:
print("No WPI outputs were discovered; it is likely that WPI failed or the Checker Framework crashed.")
print("Check the file " + os.path.join(os.getcwd(), 'dljc-out', 'wpi.log') + " for more information.")
raise e

for stub in stubs:
shutil.move(os.path.join(wpiDir, stub), previousIterationDir)
for ajavaFile in ajavaFiles:
shutil.move(os.path.join(wpiDir, ajavaFile),
previousIterationDir)

stubDirs.append(previousIterationDir)
ajavaDirs.append(previousIterationDir)

if len(stubDirs) > 1:
dcmp = dircmp(stubDirs[-1], stubDirs[-2])
if len(ajavaDirs) > 1:
dcmp = dircmp(ajavaDirs[-1], ajavaDirs[-2])
diffResult = has_differing_files(dcmp)

# Run one final time without "-Awarns", for the final user output.
Expand Down

0 comments on commit 4a78794

Please sign in to comment.