java.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # Copyright 2012-2017 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. import os.path, shutil, subprocess
  12. from ..mesonlib import EnvironmentException
  13. from .compilers import Compiler, java_buildtype_args
  14. class JavaCompiler(Compiler):
  15. def __init__(self, exelist, version):
  16. self.language = 'java'
  17. super().__init__(exelist, version)
  18. self.id = 'unknown'
  19. self.javarunner = 'java'
  20. def get_soname_args(self, *args):
  21. return []
  22. def get_werror_args(self):
  23. return ['-Werror']
  24. def split_shlib_to_parts(self, fname):
  25. return None, fname
  26. def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
  27. return []
  28. def get_dependency_gen_args(self, outtarget, outfile):
  29. return []
  30. def get_linker_exelist(self):
  31. return self.exelist[:]
  32. def get_compile_only_args(self):
  33. return []
  34. def get_output_args(self, subdir):
  35. if subdir == '':
  36. subdir = './'
  37. return ['-d', subdir, '-s', subdir]
  38. def get_linker_output_args(self, outputname):
  39. return []
  40. def get_coverage_args(self):
  41. return []
  42. def get_coverage_link_args(self):
  43. return []
  44. def get_std_exe_link_args(self):
  45. return []
  46. def get_include_args(self, path):
  47. return []
  48. def get_pic_args(self):
  49. return []
  50. def name_string(self):
  51. return ' '.join(self.exelist)
  52. def get_pch_use_args(self, pch_dir, header):
  53. return []
  54. def get_pch_name(self, header_name):
  55. return ''
  56. def get_buildtype_args(self, buildtype):
  57. return java_buildtype_args[buildtype]
  58. def sanity_check(self, work_dir, environment):
  59. src = 'SanityCheck.java'
  60. obj = 'SanityCheck'
  61. source_name = os.path.join(work_dir, src)
  62. with open(source_name, 'w') as ofile:
  63. ofile.write('''class SanityCheck {
  64. public static void main(String[] args) {
  65. int i;
  66. }
  67. }
  68. ''')
  69. pc = subprocess.Popen(self.exelist + [src], cwd=work_dir)
  70. pc.wait()
  71. if pc.returncode != 0:
  72. raise EnvironmentException('Java compiler %s can not compile programs.' % self.name_string())
  73. runner = shutil.which(self.javarunner)
  74. if runner:
  75. cmdlist = [runner, obj]
  76. pe = subprocess.Popen(cmdlist, cwd=work_dir)
  77. pe.wait()
  78. if pe.returncode != 0:
  79. raise EnvironmentException('Executables created by Java compiler %s are not runnable.' % self.name_string())
  80. else:
  81. m = "Java Virtual Machine wasn't found, but it's needed by Meson. " \
  82. "Please install a JRE.\nIf you have specific needs where this " \
  83. "requirement doesn't make sense, please open a bug at " \
  84. "https://github.com/mesonbuild/meson/issues/new and tell us " \
  85. "all about it."
  86. raise EnvironmentException(m)
  87. def needs_static_linker(self):
  88. return False