vala.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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
  12. from .. import mlog
  13. from ..mesonlib import EnvironmentException, version_compare
  14. from .compilers import Compiler
  15. class ValaCompiler(Compiler):
  16. def __init__(self, exelist, version):
  17. self.language = 'vala'
  18. super().__init__(exelist, version)
  19. self.version = version
  20. self.id = 'valac'
  21. self.is_cross = False
  22. self.base_options = ['b_colorout']
  23. def name_string(self):
  24. return ' '.join(self.exelist)
  25. def needs_static_linker(self):
  26. return False # Because compiles into C.
  27. def get_output_args(self, target):
  28. return ['-o', target]
  29. def get_compile_only_args(self):
  30. return ['-C']
  31. def get_pic_args(self):
  32. return []
  33. def get_always_args(self):
  34. return ['-C']
  35. def get_warn_args(self, warning_level):
  36. return []
  37. def get_no_warn_args(self):
  38. return ['--disable-warnings']
  39. def get_werror_args(self):
  40. return ['--fatal-warnings']
  41. def get_colorout_args(self, colortype):
  42. if version_compare(self.version, '>=0.37.1'):
  43. return ['--color=' + colortype]
  44. return []
  45. def sanity_check(self, work_dir, environment):
  46. code = 'class MesonSanityCheck : Object { }'
  47. args = self.get_cross_extra_flags(environment, link=False)
  48. with self.compile(code, args, 'compile') as p:
  49. if p.returncode != 0:
  50. msg = 'Vala compiler {!r} can not compile programs' \
  51. ''.format(self.name_string())
  52. raise EnvironmentException(msg)
  53. def get_buildtype_args(self, buildtype):
  54. if buildtype == 'debug' or buildtype == 'debugoptimized' or buildtype == 'minsize':
  55. return ['--debug']
  56. return []
  57. def find_library(self, libname, env, extra_dirs):
  58. if extra_dirs and isinstance(extra_dirs, str):
  59. extra_dirs = [extra_dirs]
  60. # Valac always looks in the default vapi dir, so only search there if
  61. # no extra dirs are specified.
  62. if not extra_dirs:
  63. code = 'class MesonFindLibrary : Object { }'
  64. vapi_args = ['--pkg', libname]
  65. args = self.get_cross_extra_flags(env, link=False)
  66. args += vapi_args
  67. with self.compile(code, args, 'compile') as p:
  68. if p.returncode == 0:
  69. return vapi_args
  70. # Not found? Try to find the vapi file itself.
  71. for d in extra_dirs:
  72. vapi = os.path.join(d, libname + '.vapi')
  73. if os.path.isfile(vapi):
  74. return [vapi]
  75. mlog.debug('Searched {!r} and {!r} wasn\'t found'.format(extra_dirs, libname))
  76. return None