• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from enum import Enum
2import os
3import re
4import warnings
5import meson_impl as impl
6
7_gArrayOptions = []
8_gFeatureOptions = []
9_gBooleanOptions = []
10_gComboOptions = []
11_gSimpleOptions = []
12
13
14def noop():
15  return
16
17
18def message(str):
19  print(str)
20
21
22def error(message):
23  exit(message)
24
25
26def warning(message):
27  warnings.warn(message)
28
29
30def set_relative_dir(dir):
31  impl.set_relative_dir(dir)
32
33
34def files(*filenames):
35  file_list = []
36  for file in filenames:
37    file_list.append(impl.File(os.path.join(impl.get_relative_dir(), file)))
38  return file_list
39
40
41def declare_dependency(
42    compile_args=[],
43    d_import_dirs=[],
44    d_module_versions='',
45    dependencies=[],
46    extra_files=[],
47    include_directories=[],
48    link_args=[],
49    link_whole=[],
50    link_with=[],
51    objects=[],
52    sources=[],
53    variables=[],
54    version='',
55):
56  link_with = impl.get_linear_list([link_with])
57  link_whole = impl.get_linear_list([link_whole])
58
59  return impl.Dependency(
60      'declared',
61      version,
62      found=True,
63      compile_args=compile_args,
64      include_directories=include_directories,
65      dependencies=dependencies,
66      sources=sources,
67      link_with=link_with,
68      link_whole=link_whole,
69  )
70
71
72def find_program(
73    name: str, required=False, native=False, disabler=False, version=''
74):
75  maybe_filename = impl.get_relative_dir(name)
76
77  # may be a script in the current directory
78  if os.path.isfile(maybe_filename):
79    return impl.Program(maybe_filename, found=True)
80
81  # These are required for building turnip though not tagged as such
82  if name == 'bison' or name == 'flex' or name == 'gzip':
83    return impl.Program(name, found=True)
84
85  if (
86      name == 'byacc'
87      or name == 'glslangValidator'
88      or name == 'install_megadrivers.py'
89      or name == 'nm'
90      or name == 'python'
91      or name == 'symbols-check.py'
92  ):
93    return impl.Program(name, found=required)
94
95  exit('Unhandled program check: ' + name)
96
97
98def add_project_arguments(args, language=[], native=False):
99  impl.add_project_arguments(args, language, native)
100
101
102def add_project_link_arguments(args, language=[], native=False):
103  return
104
105
106# Used by meson_options.txt to define an option
107def option(
108    name: str,
109    type: str,
110    min: int = 0,
111    max: int = 0,
112    value='',
113    choices=[],
114    description='',
115    deprecated=None,
116):
117  if type == 'array':
118    global _gArrayOptions
119    _gArrayOptions.append(impl.ArrayOption(name, value))
120    return
121  if type == 'feature':
122    global _gFeatureOptions
123    if value == '' or value == 'auto':
124      state = impl.EnableState.AUTO
125    elif value == 'disabled':
126      state = impl.EnableState.DISABLED
127    elif value == 'enabled':
128      state = impl.EnableState.ENABLED
129    else:
130      exit('Unhandled feature option value')
131    _gFeatureOptions.append(impl.FeatureOption(name, state))
132    return
133  if type == 'boolean':
134    global _gBooleanOptions
135    if isinstance(value, str):
136      flag = True if value.lower() == 'true' else False
137      _gBooleanOptions.append(impl.BooleanOption(name, flag))
138    else:
139      _gBooleanOptions.append(impl.BooleanOption(name, value))
140    return
141  if type == 'combo':
142    global _gComboOptions
143    _gComboOptions.append(impl.ComboOption(name, value))
144    return
145  if type == 'string' or type == 'integer':
146    global _gSimpleOptions
147    _gSimpleOptions.append(impl.SimpleOption(name, value))
148    return
149
150
151def set_option(name, value: str):
152  print('set_option: %s=%s' % (name, value))
153  for option in _gArrayOptions:
154    if option.name == name:
155      option.set(value)
156
157  for option in _gFeatureOptions:
158    if option.name == name:
159      option.set(value)
160
161  for option in _gBooleanOptions:
162    if option.name == name:
163      option.set(value)
164
165  for option in _gComboOptions:
166    if option.name == name:
167      option.set(value)
168
169  for option in _gSimpleOptions:
170    if option.name == name:
171      option.set(value)
172
173  for option in impl.get_project_options():
174    if option.name == name:
175      option.set(value)
176
177
178def get_option(name):
179  for option in _gArrayOptions:
180    if option.name == name:
181      return option.strings
182
183  for option in _gFeatureOptions:
184    if option.name == name:
185      return option
186
187  for option in _gBooleanOptions:
188    if option.name == name:
189      return option.value
190
191  for option in _gComboOptions:
192    if option.name == name:
193      return option.value
194
195  for option in _gSimpleOptions:
196    if option.name == name:
197      return option.value
198
199  for option in impl.get_project_options():
200    if option.name == name:
201      return option.value
202
203  # built-in options
204  if name == 'layout':
205    return 'mirror'
206  if name == 'prefix':
207    return 'prefix'
208  if name == 'libdir':
209    return 'libdir'
210  if name == 'datadir':
211    return 'datadir'
212  if name == 'sysconfdir':
213    return 'sysconfdir'
214  if name == 'includedir':
215    return 'includedir'
216  if name == 'c_args':
217    return ''
218  if name == 'cpp_rtti':
219    return False
220  if name == 'debug':
221    return True
222  if name == 'b_sanitize':
223    return False
224  if name == 'backend':
225    return 'custom'
226
227  exit('Unhandled option: ' + name)
228
229
230def project(
231    name, language_list, version, license, meson_version, default_options=[]
232):
233  impl.project(
234      name, language_list, version, license, meson_version, default_options
235  )
236
237
238def run_command(program, *commands, check=False):
239  return program.run_command(commands)
240
241
242def environment():
243  return impl.Environment()
244
245
246def join_paths(*paths):
247  joined_path = ''
248  for path in paths:
249    joined_path = os.path.join(joined_path, path)
250  return joined_path
251
252
253def executable(
254    target_name,
255    *source,
256    c_args=[],
257    cpp_args=[],
258    c_pch='',
259    build_by_default=False,
260    build_rpath='',
261    d_debug=[],
262    d_import_dirs=[],
263    d_module_versions=[],
264    d_unittest=False,
265    dependencies=[],
266    export_dynamic=False,
267    extra_files='',
268    gnu_symbol_visibility='',
269    gui_app=False,
270    implib=False,
271    implicit_include_directories=False,
272    include_directories=[],
273    install=False,
274    install_dir='',
275    install_mode=[],
276    install_rpath='',
277    install_tag='',
278    link_args=[],
279    link_depends='',
280    link_language='',
281    link_whole=[],
282    link_with=[],
283    name_prefix='',
284    name_suffix='',
285    native=False,
286    objects=[],
287    override_options=[],
288    pie=False,
289    rust_crate_type='',
290    rust_dependency_map={},
291    sources='',
292    vala_args=[],
293    vs_module_defs='',
294    win_subsystem='',
295):
296  return impl.Executable(target_name)
297
298
299def test(
300    name,
301    executable,
302    args=[],
303    depends=[],
304    env=[],
305    is_parallel=False,
306    priority=0,
307    protocol='',
308    should_fail=False,
309    suite='',
310    timeout=0,
311    verbose=False,
312    workdir='',
313):
314  return
315
316
317def summary(entry, bool_yn=False, list_sep='', section=''):
318  return
319
320
321def install_headers(*headers, subdir=''):
322  return
323
324
325def install_data(
326    *files,
327    follow_symlinks=False,
328    install_dir='',
329    install_mode=[],
330    install_tag='',
331    preserve_path=False,
332    rename=[],
333    sources=[],
334):
335  return
336