You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
3.2 KiB
96 lines
3.2 KiB
9 years ago
|
# Copyright (c) 2009 - 2013 Monoidics ltd.
|
||
|
# Copyright (c) 2013 - present Facebook, Inc.
|
||
10 years ago
|
# All rights reserved.
|
||
9 years ago
|
#
|
||
|
# This source code is licensed under the BSD style license found in the
|
||
|
# LICENSE file in the root directory of this source tree. An additional grant
|
||
|
# of patent rights can be found in the PATENTS file in the same directory.
|
||
10 years ago
|
|
||
|
import argparse
|
||
|
import os
|
||
9 years ago
|
import tempfile
|
||
10 years ago
|
import subprocess
|
||
9 years ago
|
import utils
|
||
10 years ago
|
|
||
9 years ago
|
FILELISTS = 'filelists'
|
||
|
|
||
10 years ago
|
# javac options
|
||
|
parser = argparse.ArgumentParser()
|
||
|
|
||
|
current_directory = os.getcwd()
|
||
|
|
||
|
parser.add_argument('-version', action='store_true')
|
||
9 years ago
|
parser.add_argument('-deprecation', action='store_true')
|
||
10 years ago
|
parser.add_argument('-cp', '-classpath', type=str, dest='classpath')
|
||
|
parser.add_argument('-bootclasspath', type=str)
|
||
10 years ago
|
parser.add_argument('-d', dest='classes_out', default=current_directory)
|
||
10 years ago
|
|
||
|
|
||
9 years ago
|
class AnnotationProcessorNotFound(Exception):
|
||
|
|
||
|
def __init__(self, path):
|
||
|
self.path = path
|
||
|
|
||
|
def __str__(self):
|
||
|
return repr(self.path + ' not found')
|
||
|
|
||
|
|
||
10 years ago
|
class CompilerCall:
|
||
|
|
||
|
def __init__(self, arguments):
|
||
|
|
||
|
self.original_arguments = arguments
|
||
9 years ago
|
self.args, self.remaining_args = parser.parse_known_args(arguments)
|
||
10 years ago
|
self.verbose_out = None
|
||
9 years ago
|
self.annotations_out = None
|
||
10 years ago
|
|
||
|
def run(self):
|
||
|
if self.args.version:
|
||
|
return subprocess.call(['javac'] + self.original_arguments)
|
||
|
else:
|
||
9 years ago
|
javac_cmd = ['javac', '-verbose', '-g']
|
||
9 years ago
|
|
||
9 years ago
|
if self.args.bootclasspath is not None:
|
||
|
javac_cmd += ['-bootclasspath', self.args.bootclasspath]
|
||
9 years ago
|
|
||
9 years ago
|
if not os.path.isfile(utils.ANNOT_PROCESSOR_JAR):
|
||
|
raise AnnotationProcessorNotFound(utils.ANNOT_PROCESSOR_JAR)
|
||
|
|
||
9 years ago
|
if self.args.classpath is None:
|
||
|
classpath = utils.ANNOT_PROCESSOR_JAR
|
||
|
else:
|
||
|
classpath = os.pathsep.join([
|
||
|
utils.ANNOT_PROCESSOR_JAR,
|
||
|
self.args.classpath])
|
||
|
javac_cmd += ['-cp', classpath]
|
||
|
|
||
9 years ago
|
if self.args.classes_out is not None:
|
||
|
javac_cmd += ['-d', self.args.classes_out]
|
||
|
javac_cmd += self.remaining_args
|
||
10 years ago
|
javac_cmd.append('-J-Duser.language=en')
|
||
10 years ago
|
|
||
9 years ago
|
with tempfile.NamedTemporaryFile(
|
||
|
mode='w',
|
||
|
suffix='.out',
|
||
|
prefix='annotations_',
|
||
|
delete=False) as annot_out:
|
||
|
self.annotations_out = annot_out.name
|
||
|
|
||
10 years ago
|
with tempfile.NamedTemporaryFile(
|
||
|
mode='w',
|
||
|
suffix='.out',
|
||
|
prefix='javac_',
|
||
|
delete=False) as file_out:
|
||
|
self.verbose_out = file_out.name
|
||
9 years ago
|
os.environ['INFER_ANNOTATIONS_OUT'] = self.annotations_out
|
||
10 years ago
|
try:
|
||
|
subprocess.check_call(javac_cmd, stderr=file_out)
|
||
9 years ago
|
except subprocess.CalledProcessError:
|
||
10 years ago
|
error_msg = 'Javac compilation error with: \n\n{}\n'
|
||
|
failing_cmd = [arg for arg in javac_cmd
|
||
|
if arg != '-verbose']
|
||
9 years ago
|
utils.error(error_msg.format(failing_cmd))
|
||
|
subprocess.check_call(failing_cmd)
|
||
|
|
||
|
return os.EX_OK
|