Using -processorpath and -processor flags correctly

Reviewed By: jeremydubreil

Differential Revision: D2847834

fb-gh-sync-id: 1e3b230
master
Sam Blackshear 9 years ago committed by facebook-github-bot-5
parent ec2a1e2130
commit 9c03a6b14c

@ -30,6 +30,7 @@ BIN_DIRECTORY = os.path.join(INFER_INFER_DIRECTORY, 'bin')
JAVA_LIB_DIRECTORY = os.path.join(LIB_DIRECTORY, 'java') JAVA_LIB_DIRECTORY = os.path.join(LIB_DIRECTORY, 'java')
MODELS_JAR = os.path.join(JAVA_LIB_DIRECTORY, 'models.jar') MODELS_JAR = os.path.join(JAVA_LIB_DIRECTORY, 'models.jar')
ANNOT_PROCESSOR_JAR = os.path.join(JAVA_LIB_DIRECTORY, 'processor.jar') ANNOT_PROCESSOR_JAR = os.path.join(JAVA_LIB_DIRECTORY, 'processor.jar')
ANNOT_PROCESSOR_NAMES = 'com.facebook.infer.annotprocess.CollectSuppressWarnings'
WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'wrappers') WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'wrappers')
XCODE_WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'xcode_wrappers') XCODE_WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'xcode_wrappers')

@ -26,6 +26,8 @@ parser.add_argument('-deprecation', action='store_true')
parser.add_argument('-cp', '-classpath', type=str, dest='classpath') parser.add_argument('-cp', '-classpath', type=str, dest='classpath')
parser.add_argument('-bootclasspath', type=str) parser.add_argument('-bootclasspath', type=str)
parser.add_argument('-d', dest='classes_out', default=current_directory) parser.add_argument('-d', dest='classes_out', default=current_directory)
parser.add_argument('-processorpath', type=str, dest='processorpath')
parser.add_argument('-processor', type=str, dest='processor')
class AnnotationProcessorNotFound(Exception): class AnnotationProcessorNotFound(Exception):
@ -57,20 +59,38 @@ class CompilerCall:
if not os.path.isfile(config.ANNOT_PROCESSOR_JAR): if not os.path.isfile(config.ANNOT_PROCESSOR_JAR):
raise AnnotationProcessorNotFound(config.ANNOT_PROCESSOR_JAR) raise AnnotationProcessorNotFound(config.ANNOT_PROCESSOR_JAR)
if self.args.classpath is None:
classpath = config.ANNOT_PROCESSOR_JAR
else:
classpath = os.pathsep.join([
config.ANNOT_PROCESSOR_JAR,
self.args.classpath])
javac_cmd += ['-cp', classpath]
if self.args.classes_out is not None: if self.args.classes_out is not None:
javac_cmd += ['-d', self.args.classes_out] javac_cmd += ['-d', self.args.classes_out]
javac_cmd += self.remaining_args javac_cmd += self.remaining_args
javac_cmd.append('-J-Duser.language=en') javac_cmd.append('-J-Duser.language=en')
classpath = self.args.classpath
# the -processorpath option precludes searching the classpath for
# annotation processors, so we don't want to use it unless the
# javac command does
if self.args.processorpath is not None:
processorpath = os.pathsep.join([config.ANNOT_PROCESSOR_JAR,
self.args.processorpath])
javac_cmd += ['-processorpath', processorpath]
else:
if classpath is not None:
classpath = os.pathsep.join([config.ANNOT_PROCESSOR_JAR,
classpath])
else:
classpath = config.ANNOT_PROCESSOR_JAR
if classpath is not None:
javac_cmd += ['-classpath', classpath]
# this overrides the default mechanism for discovering annotation
# processors (checking the manifest of the annotation processor
# JAR), so we don't want to use it unless the javac command does
if self.args.processor is not None:
processor = '%s,%s' % (config.ANNOT_PROCESSOR_NAMES,
self.args.processor)
javac_cmd += ['-processor', processor]
with tempfile.NamedTemporaryFile( with tempfile.NamedTemporaryFile(
mode='w', mode='w',
suffix='.json', suffix='.json',

Loading…
Cancel
Save