|
6 | 6 |
|
7 | 7 | import typing as T |
8 | 8 |
|
| 9 | +from .samplefactory import sample_generator |
| 10 | + |
9 | 11 | if T.TYPE_CHECKING: |
10 | 12 | from ..minit import Arguments |
11 | 13 |
|
12 | | -meson_executable_template = '''project( |
13 | | - '{project_name}', |
14 | | - {language}, |
15 | | - version : '{version}', |
16 | | - meson_version : '>= {meson_version}', |
17 | | - default_options : [{default_options}], |
18 | | -) |
19 | | -
|
20 | | -executable( |
21 | | - '{executable}', |
22 | | - {sourcespec},{depspec} |
23 | | - install : true, |
24 | | -) |
25 | | -
|
26 | | -''' |
27 | | - |
28 | | - |
29 | | -meson_jar_template = '''project( |
30 | | - '{project_name}', |
31 | | - '{language}', |
32 | | - version : '{version}', |
33 | | - meson_version : '>= {meson_version}', |
34 | | - default_options : [{default_options}], |
35 | | -) |
36 | | -
|
37 | | -jar( |
38 | | - '{executable}', |
39 | | - {sourcespec},{depspec} |
40 | | - main_class : '{main_class}', |
41 | | - install : true, |
42 | | -) |
43 | | -
|
44 | | -''' |
45 | | - |
46 | 14 |
|
47 | 15 | def create_meson_build(options: Arguments) -> None: |
48 | | - if options.type != 'executable': |
49 | | - raise SystemExit('\nGenerating a meson.build file from existing sources is\n' |
50 | | - 'supported only for project type "executable".\n' |
51 | | - 'Run meson init in an empty directory to create a sample project.') |
52 | | - default_options = ['warning_level=3'] |
53 | | - if options.language == 'cpp': |
54 | | - # This shows how to set this very common option. |
55 | | - default_options += ['cpp_std=c++14'] |
56 | | - # If we get a meson.build autoformatter one day, this code could |
57 | | - # be simplified quite a bit. |
58 | | - formatted_default_options = ', '.join(f"'{x}'" for x in default_options) |
59 | | - sourcespec = ',\n '.join(f"'{x}'" for x in options.srcfiles) |
60 | | - depspec = '' |
61 | | - if options.deps: |
62 | | - depspec = '\n dependencies : [\n ' |
63 | | - depspec += ',\n '.join(f"dependency('{x}')" |
64 | | - for x in options.deps.split(',')) |
65 | | - depspec += '],' |
66 | | - tmpl = meson_executable_template if options.language != 'java' else meson_jar_template |
67 | | - content = tmpl.format(project_name=options.name, |
68 | | - language=options.language, |
69 | | - version=options.version, |
70 | | - meson_version='1.0.0' if options.language != 'rust' else '1.3.0', |
71 | | - main_class=options.name, |
72 | | - executable=options.executable, |
73 | | - sourcespec=sourcespec, |
74 | | - depspec=depspec, |
75 | | - default_options=formatted_default_options) |
76 | | - with open('meson.build', 'w', encoding='utf-8') as f: |
77 | | - f.write(content) |
78 | | - print('Generated meson.build file:\n\n' + content) |
| 16 | + proj = sample_generator(options) |
| 17 | + if options.type == 'executable': |
| 18 | + proj.create_executable() |
| 19 | + else: |
| 20 | + proj.create_library() |
0 commit comments