Now can detect Java compiler.

pull/15/head
Jussi Pakkanen 11 years ago
parent e321345f41
commit 11f2106228
  1. 2
      build.py
  2. 32
      environment.py
  3. 4
      interpreter.py

@ -50,7 +50,7 @@ class Build:
return False return False
def add_compiler(self, compiler): def add_compiler(self, compiler):
if len(self.compilers) == 0: if self.static_linker is None and compiler.get_language() != 'java':
self.static_linker = self.environment.detect_static_linker(compiler) self.static_linker = self.environment.detect_static_linker(compiler)
if self.has_language(compiler.get_language()): if self.has_language(compiler.get_language()):
return return

@ -387,7 +387,7 @@ class ObjCPPCompiler(CPPCompiler):
raise EnvironmentException('Executables created by ObjC++ compiler %s are not runnable.' % self.name_string()) raise EnvironmentException('Executables created by ObjC++ compiler %s are not runnable.' % self.name_string())
class JavaCompiler(): class JavaCompiler():
def __init__(self, exelist, version, is_cross, exe_wrapper=None): def __init__(self, exelist, version):
if type(exelist) == type(''): if type(exelist) == type(''):
self.exelist = [exelist] self.exelist = [exelist]
elif type(exelist) == type([]): elif type(exelist) == type([]):
@ -398,11 +398,6 @@ class JavaCompiler():
self.language = 'java' self.language = 'java'
self.default_suffix = 'java' self.default_suffix = 'java'
self.id = 'unknown' self.id = 'unknown'
self.is_cross = is_cross
if isinstance(exe_wrapper, str):
self.exe_wrapper = [exe_wrapper]
else:
self.exe_wrapper = exe_wrapper
self.javarunner = 'java' self.javarunner = 'java'
def get_always_flags(self): def get_always_flags(self):
@ -426,9 +421,6 @@ class JavaCompiler():
def get_dependency_gen_flags(self, outtarget, outfile): def get_dependency_gen_flags(self, outtarget, outfile):
return [] return []
def get_depfile_suffix(self):
return 'd'
def get_language(self): def get_language(self):
return self.language return self.language
@ -488,12 +480,12 @@ class JavaCompiler():
def sanity_check(self, work_dir): def sanity_check(self, work_dir):
src = 'SanityCheck.java' src = 'SanityCheck.java'
obj = 'SanityCheck.class' obj = 'SanityCheck'
source_name = os.path.join(work_dir, src) source_name = os.path.join(work_dir, src)
ofile = open(source_name, 'w') ofile = open(source_name, 'w')
ofile.write('''class SanityCheck { ofile.write('''class SanityCheck {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Java is working."); int i;
} }
} }
''') ''')
@ -1192,6 +1184,24 @@ class Environment():
return GnuObjCPPCompiler(exelist, version, is_cross, exe_wrap) return GnuObjCPPCompiler(exelist, version, is_cross, exe_wrap)
raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"') raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"')
def detect_java_compiler(self):
exelist = ['javac']
try:
p = subprocess.Popen(exelist + ['-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError:
raise EnvironmentException('Could not execute Java compiler "%s"' % ' '.join(exelist))
(out, err) = p.communicate()
out = out.decode()
err = err.decode()
vmatch = re.search(Environment.version_regex, err)
if vmatch:
version = vmatch.group(0)
else:
version = 'unknown version'
if 'javac' in err:
return JavaCompiler(exelist, version)
raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"')
def detect_static_linker(self, compiler): def detect_static_linker(self, compiler):
if compiler.is_cross: if compiler.is_cross:
linker = self.cross_info['ar'] linker = self.cross_info['ar']

@ -895,6 +895,10 @@ class Interpreter():
comp = self.environment.detect_objcpp_compiler(False) comp = self.environment.detect_objcpp_compiler(False)
if is_cross: if is_cross:
cross_comp = self.environment.detect_objcpp_compiler(True) cross_comp = self.environment.detect_objcpp_compiler(True)
elif lang.lower() == 'java':
comp = self.environment.detect_java_compiler()
if is_cross:
cross_comp = comp # Java is platform independent.
else: else:
raise InvalidCode('Tried to use unknown language "%s".' % lang) raise InvalidCode('Tried to use unknown language "%s".' % lang)
comp.sanity_check(self.environment.get_scratch_dir()) comp.sanity_check(self.environment.get_scratch_dir())

Loading…
Cancel
Save