Debian Codegraph @

mesonbuild/templates/valatemplates.py

raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2019 The Meson development team
3 # Copyright © 2023-2025 Intel Corporation
4
5 from __future__ import annotations
6
7 from mesonbuild.templates.sampleimpl import FileImpl
8
9
10 hello_vala_template = '''void main (string[] args) {{
11 stdout.printf ("Hello {project_name}!\\n");
12 }}
13 '''
14
15 hello_vala_meson_template = '''project(
16 '{project_name}',
17 'vala',
18 meson_version : '>= {meson_version}',
19 version : '{version}',
20 )
21
22 dependencies = [
23 dependency('glib-2.0'),
24 dependency('gobject-2.0'),{dependencies}
25 ]
26
27 sources = [{source_files}
28 ]
29
30 exe = executable(
31 '{exe_name}',
32 sources,
33 dependencies : dependencies,
34 install : true,
35 )
36
37 test('basic', exe)
38 '''
39
40
41 lib_vala_template = '''namespace {namespace} {{
42 public int sum(int a, int b) {{
43 return(a + b);
44 }}
45
46 public int square(int a) {{
47 return(a * a);
48 }}
49 }}
50 '''
51
52 lib_vala_test_template = '''using {namespace};
53
54 public void main() {{
55 stdout.printf("\nTesting shlib");
56 stdout.printf("\n\t2 + 3 is %d", sum(2, 3));
57 stdout.printf("\n\t8 squared is %d\\n", square(8));
58 }}
59 '''
60
61 lib_vala_meson_template = '''project(
62 '{project_name}',
63 'vala',
64 meson_version : '>= {meson_version}',
65 version : '{version}',
66 )
67
68 dependencies = [
69 dependency('glib-2.0'),
70 dependency('gobject-2.0'),{dependencies}
71 ]
72
73 sources = [{source_files}
74 ]
75
76 # These arguments are only used to build the shared library
77 # not the executables that use the library.
78 lib = shared_library(
79 'foo',
80 sources,
81 dependencies : dependencies,
82 install : true,
83 install_dir : [true, true, true],
84 )
85
86 test_exe = executable(
87 '{test_exe_name}',
88 '{test_source_file}',
89 dependencies : dependencies,
90 link_with : lib,
91 )
92 test('{test_name}', test_exe)
93
94 # Make this library usable as a Meson subproject.
95 {ltoken}_dep = declare_dependency(
96 include_directories : include_directories('.'),
97 dependencies : dependencies,
98 link_with : lib,
99 )
100 meson.override_dependency('{project_name}', {ltoken}_dep)
101
102 '''
103
104
105 class ValaProject(FileImpl):
106
107 source_ext = 'vala'
108 exe_template = hello_vala_template
109 exe_meson_template = hello_vala_meson_template
110 lib_template = lib_vala_template
111 lib_test_template = lib_vala_test_template
112 lib_meson_template = lib_vala_meson_template