javac: Fail gracefully if there's no JVM

Without this, we error out with an exception if `javac` is found but
`java` isn't:

[...]
File "mesonbuild/interpreter.py", line 1759, in detect_compilers
  comp.sanity_check(self.environment.get_scratch_dir(), self.environment)
File "mesonbuild/compilers.py", line 1279, in sanity_check
  pe = subprocess.Popen(cmdlist, cwd=work_dir)
File "/usr/lib64/python3.5/subprocess.py", line 947, in __init__
  restore_signals, start_new_session)
File "/usr/lib64/python3.5/subprocess.py", line 1551, in _execute_child
  raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'java'
pull/1005/head
Nirbheek Chauhan 8 years ago
parent 87f07cdf3d
commit e90f21ae59
  1. 20
      mesonbuild/compilers.py

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import shutil
import contextlib import contextlib
import subprocess, os.path import subprocess, os.path
import tempfile import tempfile
@ -1274,11 +1275,20 @@ class JavaCompiler(Compiler):
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
raise EnvironmentException('Java compiler %s can not compile programs.' % self.name_string()) raise EnvironmentException('Java compiler %s can not compile programs.' % self.name_string())
cmdlist = [self.javarunner, obj] runner = shutil.which(self.javarunner)
pe = subprocess.Popen(cmdlist, cwd=work_dir) if runner:
pe.wait() cmdlist = [runner, obj]
if pe.returncode != 0: pe = subprocess.Popen(cmdlist, cwd=work_dir)
raise EnvironmentException('Executables created by Java compiler %s are not runnable.' % self.name_string()) pe.wait()
if pe.returncode != 0:
raise EnvironmentException('Executables created by Java compiler %s are not runnable.' % self.name_string())
else:
m = "Java Virtual Machine wasn't found, but it's needed by Meson. " \
"Please install a JRE.\nIf you have specific needs where this " \
"requirement doesn't make sense, please open a bug at " \
"https://github.com/mesonbuild/meson/issues/new and tell us " \
"all about it."
raise EnvironmentException(m)
def needs_static_linker(self): def needs_static_linker(self):
return False return False

Loading…
Cancel
Save