vala.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. import typing as T
  13. from .. import mlog
  14. from ..mesonlib import EnvironmentException, MachineChoice, version_compare
  15. from .compilers import Compiler
  16. if T.TYPE_CHECKING:
  17. from ..envconfig import MachineInfo
  18. class ValaCompiler(Compiler):
  19. language = 'vala'
  20. def __init__(self, exelist, version, for_machine: MachineChoice,
  21. is_cross, info: 'MachineInfo'):
  22. super().__init__(exelist, version, for_machine, info)
  23. self.version = version
  24. self.is_cross = is_cross
  25. self.id = 'valac'
  26. self.base_options = ['b_colorout']
  27. def name_string(self):
  28. return ' '.join(self.exelist)
  29. def needs_static_linker(self):
  30. return False # Because compiles into C.
  31. def get_optimization_args(self, optimization_level):
  32. return []
  33. def get_debug_args(self, is_debug):
  34. return ['--debug'] if is_debug else []
  35. def get_output_args(self, target):
  36. return [] # Because compiles into C.
  37. def get_compile_only_args(self):
  38. return [] # Because compiles into C.
  39. def get_pic_args(self):
  40. return []
  41. def get_pie_args(self):
  42. return []
  43. def get_pie_link_args(self):
  44. return []
  45. def get_always_args(self):
  46. return ['-C']
  47. def get_warn_args(self, warning_level):
  48. return []
  49. def get_no_warn_args(self):
  50. return ['--disable-warnings']
  51. def get_werror_args(self):
  52. return ['--fatal-warnings']
  53. def get_colorout_args(self, colortype):
  54. if version_compare(self.version, '>=0.37.1'):
  55. return ['--color=' + colortype]
  56. return []
  57. def compute_parameters_with_absolute_paths(self, parameter_list, build_dir):
  58. for idx, i in enumerate(parameter_list):
  59. if i[:9] == '--girdir=':
  60. parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:]))
  61. if i[:10] == '--vapidir=':
  62. parameter_list[idx] = i[:10] + os.path.normpath(os.path.join(build_dir, i[10:]))
  63. if i[:13] == '--includedir=':
  64. parameter_list[idx] = i[:13] + os.path.normpath(os.path.join(build_dir, i[13:]))
  65. if i[:14] == '--metadatadir=':
  66. parameter_list[idx] = i[:14] + os.path.normpath(os.path.join(build_dir, i[14:]))
  67. return parameter_list
  68. def sanity_check(self, work_dir, environment):
  69. code = 'class MesonSanityCheck : Object { }'
  70. extra_flags = []
  71. extra_flags += environment.coredata.get_external_args(self.for_machine, self.language)
  72. if self.is_cross:
  73. extra_flags += self.get_compile_only_args()
  74. else:
  75. extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language)
  76. with self.cached_compile(code, environment.coredata, extra_args=extra_flags, mode='compile') as p:
  77. if p.returncode != 0:
  78. msg = 'Vala compiler {!r} can not compile programs' \
  79. ''.format(self.name_string())
  80. raise EnvironmentException(msg)
  81. def get_buildtype_args(self, buildtype):
  82. if buildtype == 'debug' or buildtype == 'debugoptimized' or buildtype == 'minsize':
  83. return ['--debug']
  84. return []
  85. def find_library(self, libname, env, extra_dirs, *args):
  86. if extra_dirs and isinstance(extra_dirs, str):
  87. extra_dirs = [extra_dirs]
  88. # Valac always looks in the default vapi dir, so only search there if
  89. # no extra dirs are specified.
  90. if not extra_dirs:
  91. code = 'class MesonFindLibrary : Object { }'
  92. args = []
  93. args += env.coredata.get_external_args(self.for_machine, self.language)
  94. vapi_args = ['--pkg', libname]
  95. args += vapi_args
  96. with self.cached_compile(code, env.coredata, extra_args=args, mode='compile') as p:
  97. if p.returncode == 0:
  98. return vapi_args
  99. # Not found? Try to find the vapi file itself.
  100. for d in extra_dirs:
  101. vapi = os.path.join(d, libname + '.vapi')
  102. if os.path.isfile(vapi):
  103. return [vapi]
  104. mlog.debug('Searched {!r} and {!r} wasn\'t found'.format(extra_dirs, libname))
  105. return None
  106. def thread_flags(self, env):
  107. return []
  108. def thread_link_flags(self, env):
  109. return []