meson/mesonbuild/templates/mesontemplates.py

71 lines
3.0 KiB
Python
Raw Normal View History

# SPDX-License-Identifier: Apache-2.0
2020-02-03 09:16:03 +08:00
# Copyright 2019 The Meson development team
from __future__ import annotations
2020-02-03 09:16:03 +08:00
import typing as T
if T.TYPE_CHECKING:
from ..minit import Arguments
2020-09-01 20:27:10 +08:00
2021-11-17 07:34:28 +08:00
meson_executable_template = '''project('{project_name}', {language},
2020-02-03 09:16:03 +08:00
version : '{version}',
default_options : [{default_options}])
executable('{executable}',
{sourcespec},{depspec}
install : true)
'''
2020-03-03 00:34:58 +08:00
meson_jar_template = '''project('{project_name}', '{language}',
version : '{version}',
default_options : [{default_options}])
jar('{executable}',
Fix meson_jar_template It was generating an extra comma. The Meson build system Version: 0.54.0 Source dir: /tmp/tmp34halxhe Build dir: /tmp/tmp34halxhe/build Build type: native build meson.build:6:15: ERROR: Expecting rparen got comma. 'Foo.java',, ^ For a block that started at 5,3 jar('tmp34halxhe', ^ A full log can be found at /tmp/tmp34halxhe/build/meson-logs/meson-log.txt Using "tmp34halxhe" (name of current directory) as project name. Using "tmp34halxhe" (project name) as name of executable to build. Detected source files: Foo.java Detected language: java Generated meson.build file: project('tmp34halxhe', 'java', version : '0.1', default_options : ['warning_level=3']) jar('tmp34halxhe', 'Foo.java',, main_class: tmp34halxhe, install : true) It was also missing quotes around the main class name. The Meson build system Version: 0.54.0 Source dir: /tmp/tmpjm5cg44a Build dir: /tmp/tmpjm5cg44a/build Build type: native build Project name: tmpjm5cg44a Project version: 0.1 Java compiler for the host machine: javac (unknown 1.8.0) Host machine cpu family: x86_64 Host machine cpu: x86_64 meson.build:5:0: ERROR: Unknown variable "tmpjm5cg44a". A full log can be found at /tmp/tmpjm5cg44a/build/meson-logs/meson-log.txt Using "tmpjm5cg44a" (name of current directory) as project name. Using "tmpjm5cg44a" (project name) as name of executable to build. Detected source files: Foo.java Detected language: java Generated meson.build file: project('tmpjm5cg44a', 'java', version : '0.1', default_options : ['warning_level=3']) jar('tmpjm5cg44a', 'Foo.java', main_class: tmpjm5cg44a, install : true)
2020-03-30 07:27:39 +08:00
{sourcespec},{depspec}
main_class: '{main_class}',
2020-03-03 00:34:58 +08:00
install : true)
'''
def create_meson_build(options: Arguments) -> None:
2020-02-03 09:16:03 +08:00
if options.type != 'executable':
raise SystemExit('\nGenerating a meson.build file from existing sources is\n'
'supported only for project type "executable".\n'
'Run meson init in an empty directory to create a sample project.')
default_options = ['warning_level=3']
if options.language == 'cpp':
# This shows how to set this very common option.
default_options += ['cpp_std=c++14']
# If we get a meson.build autoformatter one day, this code could
# be simplified quite a bit.
formatted_default_options = ', '.join(f"'{x}'" for x in default_options)
sourcespec = ',\n '.join(f"'{x}'" for x in options.srcfiles)
2020-02-03 09:16:03 +08:00
depspec = ''
if options.deps:
depspec = '\n dependencies : [\n '
depspec += ',\n '.join(f"dependency('{x}')"
2020-02-03 09:16:03 +08:00
for x in options.deps.split(','))
depspec += '],'
2020-03-03 00:34:58 +08:00
if options.language != 'java':
2021-11-17 07:34:28 +08:00
language = f"'{options.language}'" if options.language != 'vala' else ['c', 'vala']
2020-03-03 00:34:58 +08:00
content = meson_executable_template.format(project_name=options.name,
2021-11-17 07:34:28 +08:00
language=language,
2020-03-03 00:34:58 +08:00
version=options.version,
executable=options.executable,
sourcespec=sourcespec,
depspec=depspec,
default_options=formatted_default_options)
else:
content = meson_jar_template.format(project_name=options.name,
language=options.language,
version=options.version,
executable=options.executable,
main_class=options.name,
sourcespec=sourcespec,
depspec=depspec,
default_options=formatted_default_options)
open('meson.build', 'w', encoding='utf-8').write(content)
2020-02-03 09:16:03 +08:00
print('Generated meson.build file:\n\n' + content)