1scanner_test_env = environment()
2scanner_test_env.prepend('PYTHONPATH', test_env_common_pypath)
3if test_env_common_path.length() > 0
4    scanner_test_env.prepend('PATH', test_env_common_path)
5endif
6
7scanner_test_files = [
8  'test_ccompiler.py',
9  'test_shlibs.py',
10  'test_sourcescanner.py',
11  'test_transformer.py',
12  'test_xmlwriter.py',
13  'test_pkgconfig.py',
14  'test_docwriter.py',
15  'test_scanner.py',
16  'test_maintransformer.py',
17]
18
19foreach f : scanner_test_files
20  test(f, python, args: files(f), env: scanner_test_env, depends: [giscanner_pymod])
21endforeach
22
23test_girs = []
24test_typelibs = []
25
26custom_c_args = []
27if cc.get_id() != 'msvc'
28  custom_c_args = cc.get_supported_arguments([
29    '-Wno-unused-parameter',
30  ])
31endif
32
33typedef_lib = shared_library('typedef-1.0',
34  sources: ['typedefs.c'],
35  include_directories : [configinc, include_directories('..')],
36  c_args: gi_hidden_visibility_cflags + custom_c_args,
37  dependencies: [gobject_dep],
38)
39
40sletter_lib = shared_library('sletter-1.0',
41  sources: ['sletter.c'],
42  include_directories : [configinc, include_directories('..')],
43  c_args: gi_hidden_visibility_cflags + custom_c_args,
44  dependencies: [gio_dep],
45)
46
47warnlib_lib = shared_library('warnlib-1.0',
48  sources: ['warnlib.c'],
49  include_directories : [configinc, include_directories('..')],
50  c_args: gi_hidden_visibility_cflags + custom_c_args,
51  dependencies: [gio_dep],
52)
53
54utility_lib = shared_library('utility-1.0',
55  sources: ['utility.c'],
56  include_directories : [configinc, include_directories('..')],
57  c_args: gi_hidden_visibility_cflags + custom_c_args,
58  dependencies: [gobject_dep],
59)
60
61gtkfrob_lib = shared_library('gtkfrob-1.0',
62  sources: ['gtkfrob.c'],
63  include_directories : [configinc, include_directories('..')],
64  c_args: gi_hidden_visibility_cflags + custom_c_args,
65  dependencies: [gobject_dep],
66)
67
68gettype_lib = shared_library('gettype-1.0',
69  sources: ['gettype.c'],
70  include_directories : [configinc, include_directories('..')],
71  c_args: gi_hidden_visibility_cflags + custom_c_args,
72  dependencies: [gobject_dep],
73)
74
75barapp_lib = shared_library('barapp-1.0',
76  sources: ['barapp.c'],
77  include_directories : [configinc, include_directories('..')],
78  c_args: gi_hidden_visibility_cflags + custom_c_args,
79  dependencies: [gobject_dep, girepo_dep],
80)
81
82if cc.get_id() != 'msvc'
83  custom_c_args = cc.get_supported_arguments([
84    '-Wno-unused-parameter',
85    '-Wno-old-style-definition',
86    '-Wno-missing-field-initializers',
87  ])
88endif
89
90if cairo_deps_found
91  regress_deps = [cairo_dep, cairo_gobject_dep]
92  regress_c_args = []
93else
94  regress_deps = []
95  regress_c_args = ['-D_GI_DISABLE_CAIRO']
96endif
97
98regress_lib = shared_library('regress-1.0',
99  sources: ['regress.c', 'annotation.c', 'foo.c', 'drawable.c'],
100  include_directories : [configinc, include_directories('..')],
101  c_args: gi_hidden_visibility_cflags + regress_c_args + custom_c_args,
102  dependencies: [gobject_dep, gio_dep] + regress_deps,
103)
104
105python_path = run_command(python, ['-c', 'import sys; sys.stdout.write(sys.executable)']).stdout()
106
107gircompiler_command = [
108  test_gircompiler, '-o', '@OUTPUT@', '@INPUT@',
109  '--includedir', join_paths(build_root, 'gir'),
110  '--includedir', meson.current_build_dir(),
111]
112
113if (glib_dep.type_name() == 'pkgconfig' and
114    get_option('build_introspection_data') == true)
115  typedef_gir = custom_target('gir-typedef',
116    input: ['typedefs.c', 'typedefs.h'],
117    output: 'Typedefs-1.0.gir',
118    depends: [typedef_lib] + typelibs,
119    command: [
120      test_girscanner,
121      '--quiet',
122      '--output=@OUTPUT@',
123      '--no-libtool',
124      '--reparse-validate',
125      '--add-include-path', join_paths(source_root, 'gir'),
126      '--add-include-path', join_paths(build_root, 'gir'),
127      '--warn-all',
128      '--warn-error',
129      '--namespace=Typedefs',
130      '--nsversion=1.0',
131      '--symbol-prefix=typedefs',
132      '--identifier-prefix=Typedefs',
133      '--include=GObject-2.0',
134      '--pkg=gobject-2.0',
135      '--library=typedef-1.0',
136      '--c-include=typedefs.h',
137      '-L', meson.current_build_dir(),
138      '-I', meson.current_source_dir(),
139      '-I', join_paths(meson.current_source_dir(), '..'),
140      extra_giscanner_args,
141      '@INPUT@',
142    ]
143  )
144  test_girs += typedef_gir
145
146  test_typelibs += custom_target(
147    'generate-typelib-typedef',
148    input: typedef_gir,
149    output: '@BASENAME@.typelib',
150    depends: [gobject_gir],
151    command: gircompiler_command,
152  )
153
154  bar_gir = custom_target('gir-bar',
155    input: ['barapp.c', 'barapp.h'],
156    output: 'Bar-1.0.gir',
157    depends: [barapp_lib] + typelibs,
158    command: [
159      test_girscanner,
160      '--quiet',
161      '--output=@OUTPUT@',
162      '--no-libtool',
163      '--reparse-validate',
164      '--add-include-path', join_paths(source_root, 'gir'),
165      '--add-include-path', join_paths(build_root, 'gir'),
166      '--warn-all',
167      '--warn-error',
168      '--namespace=Bar',
169      '--nsversion=1.0',
170      '--include=GObject-2.0',
171      '--pkg=gobject-2.0',
172      '--library=barapp-1.0',
173      '--accept-unprefixed',
174      '-L', meson.current_build_dir(),
175      '-L', join_paths(build_root, 'girepository'),
176      '-I', meson.current_source_dir(),
177      '-I', join_paths(meson.current_source_dir(), '..'),
178      extra_giscanner_args,
179      '@INPUT@',
180    ]
181  )
182  test_girs += bar_gir
183
184  test_typelibs += custom_target(
185    'generate-typelib-bar',
186    input: bar_gir,
187    output: '@BASENAME@.typelib',
188    depends: [gobject_gir],
189    command: gircompiler_command,
190  )
191
192  sletter_gir = custom_target('gir-sletter',
193    input: ['sletter.c', 'sletter.h'],
194    output: 'SLetter-1.0.gir',
195    depends: [sletter_lib] + typelibs,
196    command: [
197      test_girscanner,
198      '--quiet',
199      '--output=@OUTPUT@',
200      '--no-libtool',
201      '--reparse-validate',
202      '--add-include-path', join_paths(source_root, 'gir'),
203      '--add-include-path', join_paths(build_root, 'gir'),
204      '--warn-all',
205      '--warn-error',
206      '--namespace=SLetter',
207      '--nsversion=1.0',
208      '--identifier-prefix=S',
209      '--include=Gio-2.0',
210      '--library=sletter-1.0',
211      '--c-include=sletter.h',
212      '-L', meson.current_build_dir(),
213      '-I', meson.current_source_dir(),
214      '-I', join_paths(meson.current_source_dir(), '..'),
215      extra_giscanner_args,
216      '@INPUT@',
217    ]
218  )
219  test_girs += sletter_gir
220
221  test_typelibs += custom_target(
222    'generate-typelib-sletter',
223    input: sletter_gir,
224    output: '@BASENAME@.typelib',
225    depends: [gio_gir],
226    command: gircompiler_command,
227  )
228
229  warnlib_gir = custom_target('gir-warnlib',
230    input: ['warnlib.c', 'warnlib.h'],
231    output: 'WarnLib-1.0.gir',
232    depends: [warnlib_lib] + typelibs,
233    command: [
234      test_girscanner,
235      '--quiet',
236      '--output=@OUTPUT@',
237      '--no-libtool',
238      '--reparse-validate',
239      '--add-include-path', join_paths(source_root, 'gir'),
240      '--add-include-path', join_paths(build_root, 'gir'),
241      '--namespace=WarnLib',
242      '--nsversion=1.0',
243      '--include=Gio-2.0',
244      '--library=warnlib-1.0',
245      '--symbol-prefix=warnlib_',
246      '--c-include=warnlib.h',
247      '-L', meson.current_build_dir(),
248      '-I', meson.current_source_dir(),
249      '-I', join_paths(meson.current_source_dir(), '..'),
250      extra_giscanner_args,
251      '@INPUT@',
252    ]
253  )
254  test_girs += warnlib_gir
255
256  test_typelibs += custom_target(
257    'generate-typelib-warnlib',
258    input: warnlib_gir,
259    output: '@BASENAME@.typelib',
260    depends: [gio_gir],
261    command: gircompiler_command,
262  )
263
264  utility_gir = custom_target('gir-utility',
265    input: ['utility.c', 'utility.h'],
266    output: 'Utility-1.0.gir',
267    depends: [utility_lib] + typelibs,
268    command: [
269      test_girscanner,
270      '--quiet',
271      '--output=@OUTPUT@',
272      '--no-libtool',
273      '--reparse-validate',
274      '--add-include-path', join_paths(source_root, 'gir'),
275      '--add-include-path', join_paths(build_root, 'gir'),
276      '--warn-all',
277      '--warn-error',
278      '--namespace=Utility',
279      '--nsversion=1.0',
280      '--include=GObject-2.0',
281      '--pkg=gobject-2.0',
282      '--library=utility-1.0',
283      '--c-include=utility.h',
284      '-L', meson.current_build_dir(),
285      '-I', meson.current_source_dir(),
286      '-I', join_paths(meson.current_source_dir(), '..'),
287      extra_giscanner_args,
288      '@INPUT@',
289    ]
290  )
291  test_girs += utility_gir
292
293  test_typelibs += custom_target(
294    'generate-typelib-utility',
295    input: utility_gir,
296    output: '@BASENAME@.typelib',
297    depends: [gobject_gir],
298    command: gircompiler_command,
299  )
300
301  gtkfrob_gir = custom_target('gir-gtkfrob',
302    input: ['gtkfrob.c', 'gtkfrob.h'],
303    output: 'GtkFrob-1.0.gir',
304    depends: [gtkfrob_lib] + typelibs,
305    command: [
306      test_girscanner,
307      '--quiet',
308      '--output=@OUTPUT@',
309      '--no-libtool',
310      '--reparse-validate',
311      '--add-include-path', join_paths(source_root, 'gir'),
312      '--add-include-path', join_paths(build_root, 'gir'),
313      '--warn-all',
314      '--warn-error',
315      '--namespace=GtkFrob',
316      '--nsversion=1.0',
317      '--identifier-prefix=Gtk',
318      '--symbol-prefix=gtk_frob',
319      '--include=GObject-2.0',
320      '--pkg=gobject-2.0',
321      '--library=gtkfrob-1.0',
322      '-L', meson.current_build_dir(),
323      '-I', meson.current_source_dir(),
324      '-I', join_paths(meson.current_source_dir(), '..'),
325      extra_giscanner_args,
326      '@INPUT@',
327    ]
328  )
329  test_girs += gtkfrob_gir
330
331  test_typelibs += custom_target(
332    'generate-typelib-gtkfrob',
333    input: gtkfrob_gir,
334    output: '@BASENAME@.typelib',
335    depends: [gobject_gir],
336    command: gircompiler_command,
337  )
338
339  gettype_gir = custom_target('gir-gettype',
340    input: ['gettype.c', 'gettype.h'],
341    output: 'GetType-1.0.gir',
342    depends: [gettype_lib] + typelibs,
343    command: [
344      test_girscanner,
345      '--quiet',
346      '--output=@OUTPUT@',
347      '--no-libtool',
348      '--reparse-validate',
349      '--add-include-path', join_paths(source_root, 'gir'),
350      '--add-include-path', join_paths(build_root, 'gir'),
351      '--namespace=GetType',
352      '--nsversion=1.0',
353      '--identifier-prefix=GetType',
354      '--symbol-prefix=gettype',
355      '--include=GObject-2.0',
356      '--pkg=gobject-2.0',
357      '--library=gettype-1.0',
358      '--c-include=gettype.h',
359      '-L', meson.current_build_dir(),
360      '-I', meson.current_source_dir(),
361      '-I', join_paths(meson.current_source_dir(), '..'),
362      extra_giscanner_args,
363      '@INPUT@',
364    ]
365  )
366  test_girs += gettype_gir
367
368  test_typelibs += custom_target(
369    'generate-typelib-gettype',
370    input: gettype_gir,
371    output: '@BASENAME@.typelib',
372    depends: [gobject_gir],
373    command: gircompiler_command,
374  )
375
376  symbolfilter_gir = custom_target('gir-symbolfilter',
377    input: ['symbolfilter.h'],
378    output: 'Symbolfilter-1.0.gir',
379    depends: typelibs,
380    command: [
381      test_girscanner,
382      '--quiet',
383      '--output=@OUTPUT@',
384      '--no-libtool',
385      '--reparse-validate',
386      '--namespace=Symbolfilter',
387      '--nsversion=1.0',
388      '--header-only',
389      '--symbol-filter-cmd=' + python_path + ' ' +  join_paths(meson.current_source_dir(), 'symbolfilter.py'),
390      extra_giscanner_args,
391      '@INPUT@',
392    ]
393  )
394  test_girs += symbolfilter_gir
395
396  test_typelibs += custom_target(
397    'generate-typelib-symbolfilter',
398    input: symbolfilter_gir,
399    output: '@BASENAME@.typelib',
400    command: gircompiler_command,
401  )
402
403  identfilter_gir = custom_target('gir-identfilter',
404    input: ['identfilter.h'],
405    output: 'Identfilter-1.0.gir',
406    depends: typelibs,
407    command: [
408      test_girscanner,
409      '--quiet',
410      '--output=@OUTPUT@',
411      '--no-libtool',
412      '--accept-unprefixed',
413      '--reparse-validate',
414      '--namespace=Identfilter',
415      '--nsversion=1.0',
416      '--header-only',
417      '--identifier-filter-cmd=' + python_path + ' ' +  join_paths(meson.current_source_dir(), 'identfilter.py'),
418      extra_giscanner_args,
419      '@INPUT@',
420    ]
421  )
422  test_girs += identfilter_gir
423
424  test_typelibs += custom_target(
425    'generate-typelib-identfilter',
426    input: identfilter_gir,
427    output: '@BASENAME@.typelib',
428    command: gircompiler_command,
429  )
430
431  headeronly_gir = custom_target('gir-headeronly',
432    input: ['headeronly.h'],
433    output: 'Headeronly-1.0.gir',
434    depends: typelibs,
435    command: [
436      test_girscanner,
437      '--quiet',
438      '--output=@OUTPUT@',
439      '--no-libtool',
440      '--warn-all',
441      '--warn-error',
442      '--reparse-validate',
443      '--namespace=Headeronly',
444      '--nsversion=1.0',
445      '--header-only',
446      extra_giscanner_args,
447      '@INPUT@',
448    ]
449  )
450  test_girs += headeronly_gir
451
452  test_typelibs += custom_target(
453    'generate-typelib-headeronly',
454    input: headeronly_gir,
455    output: '@BASENAME@.typelib',
456    command: gircompiler_command,
457  )
458
459  if cairo_deps_found
460    regress_scanner_cairo_args = ['--include=cairo-1.0']
461  else
462    regress_scanner_cairo_args = ['-D_GI_DISABLE_CAIRO',]
463  endif
464
465  regress_gir = custom_target('gir-regress',
466    input: ['regress.c', 'regress.h', 'annotation.c', 'annotation.h',
467            'foo.c', 'foo.h', 'drawable.c', 'drawable.h'],
468    output: 'Regress-1.0.gir',
469    depends: [regress_lib] + typelibs + [utility_gir],
470    command: [
471      test_girscanner,
472      '--quiet',
473      '--output=@OUTPUT@',
474      '--no-libtool',
475      '--reparse-validate',
476      '--add-include-path', join_paths(source_root, 'gir'),
477      '--add-include-path', join_paths(build_root, 'gir'),
478      '--add-include-path', meson.current_build_dir(),
479      '--namespace=Regress',
480      '--nsversion=1.0',
481      '--include=Gio-2.0',
482      '--include=Utility-1.0',
483      '--library=regress-1.0',
484      '--c-include=regress.h',
485      '-L', meson.current_build_dir(),
486      '-I', meson.current_source_dir(),
487      '-I', join_paths(meson.current_source_dir(), '..'),
488      extra_giscanner_args,
489      ] + regress_scanner_cairo_args + [
490      '@INPUT@',
491    ]
492  )
493
494  # The reference gir is generated with cairo support, so we can only compare
495  # things if we build with cairo as well
496  if cairo_deps_found
497    test_girs += regress_gir
498  endif
499
500  regress_typelib = custom_target(
501    'generate-typelib-regress',
502    input: regress_gir,
503    output: '@BASENAME@.typelib',
504    command: gircompiler_command,
505  )
506  test_typelibs += regress_typelib
507else
508  regress_gir = disabler()
509endif
510
511gi_tester = files(join_paths('..', 'gi-tester'))
512
513foreach gir : test_girs
514  gir_name = gir.full_path().split('/')[-1]
515  test(
516    'gi-tester-' + gir_name,
517    python,
518    args: [gi_tester, gir_name],
519    depends: [gir],
520    env: [
521      'srcdir=' + meson.current_source_dir(),
522      'builddir=' + meson.current_build_dir(),
523    ],
524  )
525endforeach
526
527if has_girdoctool and glib_dep.type_name() == 'pkgconfig'
528  foreach language : ['C', 'Python', 'Gjs']
529    regress_docs = custom_target(
530      'generate-docs-' + language,
531      input: regress_gir,
532      depends: [doc_templates],
533      build_by_default: not cairo_deps_found,
534      output: 'Regress-1.0-' + language,
535      command: [
536        python, girdoctool,
537        '--add-include-path=' + join_paths(build_root, 'gir'),
538        '--add-include-path=' + meson.current_build_dir(),
539        '--language', language,
540        '@INPUT@', '-o', '@OUTPUT@'],
541    )
542
543    if cairo_deps_found
544      test(
545        'gi-tester-docs-Regress-1.0-' + language,
546        python,
547        args: [gi_tester, 'Regress-1.0-' + language],
548        depends: [regress_docs],
549        env: [
550          'srcdir=' + meson.current_source_dir(),
551          'builddir=' + meson.current_build_dir(),
552        ],
553      )
554    endif
555  endforeach
556
557  regress_sections = custom_target(
558    'generate-docs-sections',
559    input: regress_gir,
560    depends: [doc_templates],
561    build_by_default: not cairo_deps_found,
562    output: 'Regress-1.0-sections.txt',
563    command: [
564      python, girdoctool,
565      '--add-include-path=' + join_paths(build_root, 'gir'),
566      '--add-include-path=' + meson.current_build_dir(),
567      '--write-sections-file',
568      '@INPUT@', '-o', '@OUTPUT@'],
569  )
570
571  if cairo_deps_found
572    test(
573      'gi-tester-docs-Regress-1.0-sections.txt',
574      python,
575      args: [gi_tester, 'Regress-1.0-sections.txt'],
576      depends: [regress_sections],
577      env: [
578        'srcdir=' + meson.current_source_dir(),
579        'builddir=' + meson.current_build_dir(),
580      ],
581    )
582  endif
583endif
584
585foreach typelib : test_typelibs
586  typelib_name = typelib.full_path().split('/')[-1]
587  test(
588    'gi-tester-' + typelib_name,
589    python,
590    args: [gi_tester, typelib.full_path()],
591    depends: [typelib],
592  )
593endforeach
594
595subdir('annotationparser')
596