sample factory implementation

pull/6803/head
Michael 5 years ago committed by Jussi Pakkanen
parent aff7fc89c3
commit 02e7316d31
  1. 91
      mesonbuild/minit.py
  2. 80
      mesonbuild/templates/cpptemplates.py
  3. 78
      mesonbuild/templates/cstemplates.py
  4. 76
      mesonbuild/templates/ctemplates.py
  5. 80
      mesonbuild/templates/cudatemplates.py
  6. 75
      mesonbuild/templates/dlangtemplates.py
  7. 70
      mesonbuild/templates/fortrantemplates.py
  8. 74
      mesonbuild/templates/javatemplates.py
  9. 77
      mesonbuild/templates/objcpptemplates.py
  10. 76
      mesonbuild/templates/objctemplates.py
  11. 74
      mesonbuild/templates/rusttemplates.py
  12. 38
      mesonbuild/templates/samplefactory.py
  13. 21
      mesonbuild/templates/sampleimpl.py

@ -24,17 +24,7 @@ import re
from glob import glob
from mesonbuild import mesonlib
from mesonbuild.environment import detect_ninja
from mesonbuild.templates.fortrantemplates import (create_exe_fortran_sample, create_lib_fortran_sample)
from mesonbuild.templates.objcpptemplates import (create_exe_objcpp_sample, create_lib_objcpp_sample)
from mesonbuild.templates.dlangtemplates import (create_exe_d_sample, create_lib_d_sample)
from mesonbuild.templates.rusttemplates import (create_exe_rust_sample, create_lib_rust_sample)
from mesonbuild.templates.javatemplates import (create_exe_java_sample, create_lib_java_sample)
from mesonbuild.templates.cudatemplates import (create_exe_cuda_sample, create_lib_cuda_sample)
from mesonbuild.templates.objctemplates import (create_exe_objc_sample, create_lib_objc_sample)
from mesonbuild.templates.cpptemplates import (create_exe_cpp_sample, create_lib_cpp_sample)
from mesonbuild.templates.cstemplates import (create_exe_cs_sample, create_lib_cs_sample)
from mesonbuild.templates.ctemplates import (create_exe_c_sample, create_lib_c_sample)
from mesonbuild.templates.samplefactory import sameple_generator
'''
we currently have one meson template at this time.
@ -51,8 +41,6 @@ class DEFAULT_TYPES(Enum):
EXE = 'executable'
LIB = 'library'
UNREACHABLE_CODE_ERROR = 'Unreachable code'
INFO_MESSAGE = '''Sample project created. To build it run the
following commands:
@ -66,78 +54,13 @@ def create_sample(options) -> None:
Based on what arguments are passed we check for a match in language
then check for project type and create new Meson samples project.
'''
if options.language == 'c':
if options.type == DEFAULT_TYPES['EXE'].value:
create_exe_c_sample(options.name, options.version)
elif options.type == DEFAULT_TYPES['LIB'].value:
create_lib_c_sample(options.name, options.version)
else:
raise RuntimeError(UNREACHABLE_CODE_ERROR)
elif options.language == 'cpp':
if options.type == DEFAULT_TYPES['EXE'].value:
create_exe_cpp_sample(options.name, options.version)
elif options.type == DEFAULT_TYPES['LIB'].value:
create_lib_cpp_sample(options.name, options.version)
else:
raise RuntimeError(UNREACHABLE_CODE_ERROR)
elif options.language == 'cs':
if options.type == DEFAULT_TYPES['EXE'].value:
create_exe_cs_sample(options.name, options.version)
elif options.type == DEFAULT_TYPES['LIB'].value:
create_lib_cs_sample(options.name, options.version)
else:
raise RuntimeError(UNREACHABLE_CODE_ERROR)
elif options.language == 'cuda':
if options.type == DEFAULT_TYPES['EXE'].value:
create_exe_cuda_sample(options.name, options.version)
elif options.type == DEFAULT_TYPES['LIB'].value:
create_lib_cuda_sample(options.name, options.version)
else:
raise RuntimeError(UNREACHABLE_CODE_ERROR)
elif options.language == 'd':
if options.type == DEFAULT_TYPES['EXE'].value:
create_exe_d_sample(options.name, options.version)
elif options.type == DEFAULT_TYPES['LIB'].value:
create_lib_d_sample(options.name, options.version)
else:
raise RuntimeError(UNREACHABLE_CODE_ERROR)
elif options.language == 'fortran':
if options.type == DEFAULT_TYPES['EXE'].value:
create_exe_fortran_sample(options.name, options.version)
elif options.type == DEFAULT_TYPES['LIB'].value:
create_lib_fortran_sample(options.name, options.version)
else:
raise RuntimeError(UNREACHABLE_CODE_ERROR)
elif options.language == 'rust':
if options.type == DEFAULT_TYPES['EXE'].value:
create_exe_rust_sample(options.name, options.version)
elif options.type == DEFAULT_TYPES['LIB'].value:
create_lib_rust_sample(options.name, options.version)
else:
raise RuntimeError(UNREACHABLE_CODE_ERROR)
elif options.language == 'objc':
if options.type == DEFAULT_TYPES['EXE'].value:
create_exe_objc_sample(options.name, options.version)
elif options.type == DEFAULT_TYPES['LIB'].value:
create_lib_objc_sample(options.name, options.version)
else:
raise RuntimeError(UNREACHABLE_CODE_ERROR)
elif options.language == 'objcpp':
if options.type == DEFAULT_TYPES['EXE'].value:
create_exe_objcpp_sample(options.name, options.version)
elif options.type == DEFAULT_TYPES['LIB'].value:
create_lib_objcpp_sample(options.name, options.version)
else:
raise RuntimeError(UNREACHABLE_CODE_ERROR)
elif options.language == 'java':
if options.type == DEFAULT_TYPES['EXE'].value:
create_exe_java_sample(options.name, options.version)
elif options.type == DEFAULT_TYPES['LIB'].value:
create_lib_java_sample(options.name, options.version)
else:
raise RuntimeError(UNREACHABLE_CODE_ERROR)
sample_gen = sameple_generator(options)
if options.type == DEFAULT_TYPES['EXE'].value:
sample_gen.create_executable()
elif options.type == DEFAULT_TYPES['LIB'].value:
sample_gen.create_library()
else:
raise RuntimeError(UNREACHABLE_CODE_ERROR)
raise RuntimeError('Unreachable code')
print(INFO_MESSAGE)
def autodetect_options(options, sample: bool = False) -> None:

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mesonbuild.templates.sampleimpl import SampleImpl
import re
@ -139,40 +140,45 @@ pkg_mod.generate(
'''
def create_exe_cpp_sample(project_name, project_version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
source_name = lowercase_token + '.cpp'
open(source_name, 'w').write(hello_cpp_template.format(project_name=project_name))
open('meson.build', 'w').write(hello_cpp_meson_template.format(project_name=project_name,
exe_name=lowercase_token,
source_name=source_name,
version=project_version))
def create_lib_cpp_sample(project_name, version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
uppercase_token = lowercase_token.upper()
class_name = uppercase_token[0] + lowercase_token[1:]
test_exe_name = lowercase_token + '_test'
namespace = lowercase_token
lib_hpp_name = lowercase_token + '.hpp'
lib_cpp_name = lowercase_token + '.cpp'
test_cpp_name = lowercase_token + '_test.cpp'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'class_name': class_name,
'namespace': namespace,
'header_file': lib_hpp_name,
'source_file': lib_cpp_name,
'test_source_file': test_cpp_name,
'test_exe_name': test_exe_name,
'project_name': project_name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': version,
}
open(lib_hpp_name, 'w').write(lib_hpp_template.format(**kwargs))
open(lib_cpp_name, 'w').write(lib_cpp_template.format(**kwargs))
open(test_cpp_name, 'w').write(lib_cpp_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_cpp_meson_template.format(**kwargs))
class CppProject(SampleImpl):
def __init__(self, options):
super().__init__()
self.name = options.name
self.version = options.version
def create_executable(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
source_name = lowercase_token + '.cpp'
open(source_name, 'w').write(hello_cpp_template.format(project_name=self.name))
open('meson.build', 'w').write(hello_cpp_meson_template.format(project_name=self.name,
exe_name=lowercase_token,
source_name=source_name,
version=self.version))
def create_library(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
uppercase_token = lowercase_token.upper()
class_name = uppercase_token[0] + lowercase_token[1:]
test_exe_name = lowercase_token + '_test'
namespace = lowercase_token
lib_hpp_name = lowercase_token + '.hpp'
lib_cpp_name = lowercase_token + '.cpp'
test_cpp_name = lowercase_token + '_test.cpp'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'class_name': class_name,
'namespace': namespace,
'header_file': lib_hpp_name,
'source_file': lib_cpp_name,
'test_source_file': test_cpp_name,
'test_exe_name': test_exe_name,
'project_name': self.name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': self.version,
}
open(lib_hpp_name, 'w').write(lib_hpp_template.format(**kwargs))
open(lib_cpp_name, 'w').write(lib_cpp_template.format(**kwargs))
open(test_cpp_name, 'w').write(lib_cpp_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_cpp_meson_template.format(**kwargs))

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mesonbuild.templates.sampleimpl import SampleImpl
import re
@ -88,39 +89,44 @@ test('{test_name}', test_exe)
'''
def create_exe_cs_sample(project_name, project_version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
uppercase_token = lowercase_token.upper()
class_name = uppercase_token[0] + lowercase_token[1:]
source_name = uppercase_token[0] + lowercase_token[1:] + '.cs'
open(source_name, 'w').write(hello_cs_template.format(project_name=project_name,
class_name=class_name))
open('meson.build', 'w').write(hello_cs_meson_template.format(project_name=project_name,
exe_name=project_name,
source_name=source_name,
version=project_version))
def create_lib_cs_sample(project_name, version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
uppercase_token = lowercase_token.upper()
class_name = uppercase_token[0] + lowercase_token[1:]
class_test = uppercase_token[0] + lowercase_token[1:] + '_test'
project_test = lowercase_token + '_test'
lib_cs_name = uppercase_token[0] + lowercase_token[1:] + '.cs'
test_cs_name = uppercase_token[0] + lowercase_token[1:] + '_test.cs'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'class_test': class_test,
'class_name': class_name,
'source_file': lib_cs_name,
'test_source_file': test_cs_name,
'test_exe_name': project_test,
'project_name': project_name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': version,
}
open(lib_cs_name, 'w').write(lib_cs_template.format(**kwargs))
open(test_cs_name, 'w').write(lib_cs_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_cs_meson_template.format(**kwargs))
class CSharpProject(SampleImpl):
def __init__(self, options):
super().__init__()
self.name = options.name
self.version = options.version
def create_executable(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
uppercase_token = lowercase_token.upper()
class_name = uppercase_token[0] + lowercase_token[1:]
source_name = uppercase_token[0] + lowercase_token[1:] + '.cs'
open(source_name, 'w').write(hello_cs_template.format(project_name=self.name,
class_name=class_name))
open('meson.build', 'w').write(hello_cs_meson_template.format(project_name=self.name,
exe_name=self.name,
source_name=source_name,
version=self.version))
def create_library(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
uppercase_token = lowercase_token.upper()
class_name = uppercase_token[0] + lowercase_token[1:]
class_test = uppercase_token[0] + lowercase_token[1:] + '_test'
project_test = lowercase_token + '_test'
lib_cs_name = uppercase_token[0] + lowercase_token[1:] + '.cs'
test_cs_name = uppercase_token[0] + lowercase_token[1:] + '_test.cs'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'class_test': class_test,
'class_name': class_name,
'source_file': lib_cs_name,
'test_source_file': test_cs_name,
'test_exe_name': project_test,
'project_name': self.name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': self.version,
}
open(lib_cs_name, 'w').write(lib_cs_template.format(**kwargs))
open(test_cs_name, 'w').write(lib_cs_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_cs_meson_template.format(**kwargs))

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mesonbuild.templates.sampleimpl import SampleImpl
import re
@ -121,37 +122,44 @@ exe = executable('{exe_name}', '{source_name}',
test('basic', exe)
'''
def create_exe_c_sample(project_name, project_version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
source_name = lowercase_token + '.c'
open(source_name, 'w').write(hello_c_template.format(project_name=project_name))
open('meson.build', 'w').write(hello_c_meson_template.format(project_name=project_name,
exe_name=lowercase_token,
source_name=source_name,
version=project_version))
def create_lib_c_sample(project_name, version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
uppercase_token = lowercase_token.upper()
function_name = lowercase_token[0:3] + '_func'
test_exe_name = lowercase_token + '_test'
lib_h_name = lowercase_token + '.h'
lib_c_name = lowercase_token + '.c'
test_c_name = lowercase_token + '_test.c'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'function_name': function_name,
'header_file': lib_h_name,
'source_file': lib_c_name,
'test_source_file': test_c_name,
'test_exe_name': test_exe_name,
'project_name': project_name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': version,
}
open(lib_h_name, 'w').write(lib_h_template.format(**kwargs))
open(lib_c_name, 'w').write(lib_c_template.format(**kwargs))
open(test_c_name, 'w').write(lib_c_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_c_meson_template.format(**kwargs))
class CProject(SampleImpl):
def __init__(self, options):
super().__init__()
self.name = options.name
self.version = options.version
def create_executable(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
source_name = lowercase_token + '.c'
open(source_name, 'w').write(hello_c_template.format(project_name=self.name))
open('meson.build', 'w').write(hello_c_meson_template.format(project_name=self.name,
exe_name=lowercase_token,
source_name=source_name,
version=self.version))
def create_library(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
uppercase_token = lowercase_token.upper()
function_name = lowercase_token[0:3] + '_func'
test_exe_name = lowercase_token + '_test'
lib_h_name = lowercase_token + '.h'
lib_c_name = lowercase_token + '.c'
test_c_name = lowercase_token + '_test.c'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'function_name': function_name,
'header_file': lib_h_name,
'source_file': lib_c_name,
'test_source_file': test_c_name,
'test_exe_name': test_exe_name,
'project_name': self.name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': self.version,
}
open(lib_h_name, 'w').write(lib_h_template.format(**kwargs))
open(lib_c_name, 'w').write(lib_c_template.format(**kwargs))
open(test_c_name, 'w').write(lib_c_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_c_meson_template.format(**kwargs))

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mesonbuild.templates.sampleimpl import SampleImpl
import re
@ -139,40 +140,45 @@ pkg_mod.generate(
'''
def create_exe_cuda_sample(project_name, project_version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
source_name = lowercase_token + '.cu'
open(source_name, 'w').write(hello_cuda_template.format(project_name=project_name))
open('meson.build', 'w').write(hello_cuda_meson_template.format(project_name=project_name,
exe_name=lowercase_token,
source_name=source_name,
version=project_version))
def create_lib_cuda_sample(project_name, version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
uppercase_token = lowercase_token.upper()
class_name = uppercase_token[0] + lowercase_token[1:]
test_exe_name = lowercase_token + '_test'
namespace = lowercase_token
lib_h_name = lowercase_token + '.h'
lib_cuda_name = lowercase_token + '.cu'
test_cuda_name = lowercase_token + '_test.cu'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'class_name': class_name,
'namespace': namespace,
'header_file': lib_h_name,
'source_file': lib_cuda_name,
'test_source_file': test_cuda_name,
'test_exe_name': test_exe_name,
'project_name': project_name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': version,
}
open(lib_h_name, 'w').write(lib_h_template.format(**kwargs))
open(lib_cuda_name, 'w').write(lib_cuda_template.format(**kwargs))
open(test_cuda_name, 'w').write(lib_cuda_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_cuda_meson_template.format(**kwargs))
class CudaProject(SampleImpl):
def __init__(self, options):
super().__init__()
self.name = options.name
self.version = options.version
def create_executable(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
source_name = lowercase_token + '.cu'
open(source_name, 'w').write(hello_cuda_template.format(project_name=self.name))
open('meson.build', 'w').write(hello_cuda_meson_template.format(project_name=self.name,
exe_name=lowercase_token,
source_name=source_name,
version=self.version))
def create_library(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
uppercase_token = lowercase_token.upper()
class_name = uppercase_token[0] + lowercase_token[1:]
test_exe_name = lowercase_token + '_test'
namespace = lowercase_token
lib_h_name = lowercase_token + '.h'
lib_cuda_name = lowercase_token + '.cu'
test_cuda_name = lowercase_token + '_test.cu'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'class_name': class_name,
'namespace': namespace,
'header_file': lib_h_name,
'source_file': lib_cuda_name,
'test_source_file': test_cuda_name,
'test_exe_name': test_exe_name,
'project_name': self.name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': self.version,
}
open(lib_h_name, 'w').write(lib_h_template.format(**kwargs))
open(lib_cuda_name, 'w').write(lib_cuda_template.format(**kwargs))
open(test_cuda_name, 'w').write(lib_cuda_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_cuda_meson_template.format(**kwargs))

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mesonbuild.templates.sampleimpl import SampleImpl
import re
@ -99,37 +100,43 @@ if find_program('dub', required: false).found()
endif
'''
def create_exe_d_sample(project_name, project_version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
source_name = lowercase_token + '.d'
open(source_name, 'w').write(hello_d_template.format(project_name=project_name))
open('meson.build', 'w').write(hello_d_meson_template.format(project_name=project_name,
exe_name=lowercase_token,
source_name=source_name,
version=project_version))
def create_lib_d_sample(project_name, version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
uppercase_token = lowercase_token.upper()
function_name = lowercase_token[0:3] + '_func'
test_exe_name = lowercase_token + '_test'
lib_m_name = lowercase_token
lib_d_name = lowercase_token + '.d'
test_d_name = lowercase_token + '_test.d'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'function_name': function_name,
'module_file': lib_m_name,
'source_file': lib_d_name,
'test_source_file': test_d_name,
'test_exe_name': test_exe_name,
'project_name': project_name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': version,
}
open(lib_d_name, 'w').write(lib_d_template.format(**kwargs))
open(test_d_name, 'w').write(lib_d_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_d_meson_template.format(**kwargs))
class DlangProject(SampleImpl):
def __init__(self, options):
super().__init__()
self.name = options.name
self.version = options.version
def create_executable(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
source_name = lowercase_token + '.d'
open(source_name, 'w').write(hello_d_template.format(project_name=self.name))
open('meson.build', 'w').write(hello_d_meson_template.format(project_name=self.name,
exe_name=lowercase_token,
source_name=source_name,
version=self.version))
def create_library(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
uppercase_token = lowercase_token.upper()
function_name = lowercase_token[0:3] + '_func'
test_exe_name = lowercase_token + '_test'
lib_m_name = lowercase_token
lib_d_name = lowercase_token + '.d'
test_d_name = lowercase_token + '_test.d'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'function_name': function_name,
'module_file': lib_m_name,
'source_file': lib_d_name,
'test_source_file': test_d_name,
'test_exe_name': test_exe_name,
'project_name': self.name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': self.version,
}
open(lib_d_name, 'w').write(lib_d_template.format(**kwargs))
open(test_d_name, 'w').write(lib_d_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_d_meson_template.format(**kwargs))

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mesonbuild.templates.sampleimpl import SampleImpl
import re
lib_fortran_template = '''
@ -98,34 +99,41 @@ exe = executable('{exe_name}', '{source_name}',
test('basic', exe)
'''
def create_exe_fortran_sample(project_name, project_version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
source_name = lowercase_token + '.f90'
open(source_name, 'w').write(hello_fortran_template.format(project_name=project_name))
open('meson.build', 'w').write(hello_fortran_meson_template.format(project_name=project_name,
exe_name=lowercase_token,
source_name=source_name,
version=project_version))
def create_lib_fortran_sample(project_name, version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
uppercase_token = lowercase_token.upper()
function_name = lowercase_token[0:3] + '_func'
test_exe_name = lowercase_token + '_test'
lib_fortran_name = lowercase_token + '.f90'
test_fortran_name = lowercase_token + '_test.f90'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'function_name': function_name,
'source_file': lib_fortran_name,
'test_source_file': test_fortran_name,
'test_exe_name': test_exe_name,
'project_name': project_name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': version,
}
open(lib_fortran_name, 'w').write(lib_fortran_template.format(**kwargs))
open(test_fortran_name, 'w').write(lib_fortran_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_fortran_meson_template.format(**kwargs))
class FortranProject(SampleImpl):
def __init__(self, options):
super().__init__()
self.name = options.name
self.version = options.version
def create_executable(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
source_name = lowercase_token + '.f90'
open(source_name, 'w').write(hello_fortran_template.format(project_name=self.name))
open('meson.build', 'w').write(hello_fortran_meson_template.format(project_name=self.name,
exe_name=lowercase_token,
source_name=source_name,
version=self.version))
def create_library(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
uppercase_token = lowercase_token.upper()
function_name = lowercase_token[0:3] + '_func'
test_exe_name = lowercase_token + '_test'
lib_fortran_name = lowercase_token + '.f90'
test_fortran_name = lowercase_token + '_test.f90'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'function_name': function_name,
'source_file': lib_fortran_name,
'test_source_file': test_fortran_name,
'test_exe_name': test_exe_name,
'project_name': self.name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': self.version,
}
open(lib_fortran_name, 'w').write(lib_fortran_template.format(**kwargs))
open(test_fortran_name, 'w').write(lib_fortran_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_fortran_meson_template.format(**kwargs))

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mesonbuild.templates.sampleimpl import SampleImpl
import re
@ -92,37 +93,42 @@ test('{test_name}', test_jar)
'''
def create_exe_java_sample(project_name, project_version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
uppercase_token = lowercase_token.upper()
class_name = uppercase_token[0] + lowercase_token[1:]
source_name = uppercase_token[0] + lowercase_token[1:] + '.java'
open(source_name, 'w').write(hello_java_template.format(project_name=project_name,
class_name=class_name))
open('meson.build', 'w').write(hello_java_meson_template.format(project_name=project_name,
exe_name=class_name,
source_name=source_name,
version=project_version))
def create_lib_java_sample(project_name, version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
uppercase_token = lowercase_token.upper()
class_name = uppercase_token[0] + lowercase_token[1:]
class_test = uppercase_token[0] + lowercase_token[1:] + '_test'
lib_java_name = uppercase_token[0] + lowercase_token[1:] + '.java'
test_java_name = uppercase_token[0] + lowercase_token[1:] + '_test.java'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'class_test': class_test,
'class_name': class_name,
'source_file': lib_java_name,
'test_source_file': test_java_name,
'project_name': project_name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': version,
}
open(lib_java_name, 'w').write(lib_java_template.format(**kwargs))
open(test_java_name, 'w').write(lib_java_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_java_meson_template.format(**kwargs))
class JavaProject(SampleImpl):
def __init__(self, options):
super().__init__()
self.name = options.name
self.version = options.version
def create_executable(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
uppercase_token = lowercase_token.upper()
class_name = uppercase_token[0] + lowercase_token[1:]
source_name = uppercase_token[0] + lowercase_token[1:] + '.java'
open(source_name, 'w').write(hello_java_template.format(project_name=self.name,
class_name=class_name))
open('meson.build', 'w').write(hello_java_meson_template.format(project_name=self.name,
exe_name=class_name,
source_name=source_name,
version=self.version))
def create_library(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
uppercase_token = lowercase_token.upper()
class_name = uppercase_token[0] + lowercase_token[1:]
class_test = uppercase_token[0] + lowercase_token[1:] + '_test'
lib_java_name = uppercase_token[0] + lowercase_token[1:] + '.java'
test_java_name = uppercase_token[0] + lowercase_token[1:] + '_test.java'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'class_test': class_test,
'class_name': class_name,
'source_file': lib_java_name,
'test_source_file': test_java_name,
'project_name': self.name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': self.version,
}
open(lib_java_name, 'w').write(lib_java_template.format(**kwargs))
open(test_java_name, 'w').write(lib_java_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_java_meson_template.format(**kwargs))

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mesonbuild.templates.sampleimpl import SampleImpl
import re
@ -121,37 +122,45 @@ exe = executable('{exe_name}', '{source_name}',
test('basic', exe)
'''
def create_exe_objcpp_sample(project_name, project_version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
source_name = lowercase_token + '.mm'
open(source_name, 'w').write(hello_objcpp_template.format(project_name=project_name))
open('meson.build', 'w').write(hello_objcpp_meson_template.format(project_name=project_name,
exe_name=lowercase_token,
source_name=source_name,
version=project_version))
def create_lib_objcpp_sample(project_name, version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
uppercase_token = lowercase_token.upper()
function_name = lowercase_token[0:3] + '_func'
test_exe_name = lowercase_token + '_test'
lib_h_name = lowercase_token + '.h'
lib_objcpp_name = lowercase_token + '.mm'
test_objcpp_name = lowercase_token + '_test.mm'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'function_name': function_name,
'header_file': lib_h_name,
'source_file': lib_objcpp_name,
'test_source_file': test_objcpp_name,
'test_exe_name': test_exe_name,
'project_name': project_name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': version,
}
open(lib_h_name, 'w').write(lib_h_template.format(**kwargs))
open(lib_objcpp_name, 'w').write(lib_objcpp_template.format(**kwargs))
open(test_objcpp_name, 'w').write(lib_objcpp_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_objcpp_meson_template.format(**kwargs))
class ObjCppProject(SampleImpl):
def __init__(self, options):
super().__init__()
self.name = options.name
self.version = options.version
def create_executable(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
source_name = lowercase_token + '.mm'
open(source_name, 'w').write(hello_objcpp_template.format(project_name=self.name))
open('meson.build', 'w').write(hello_objcpp_meson_template.format(project_name=self.name,
exe_name=lowercase_token,
source_name=source_name,
version=self.version))
def create_library(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
uppercase_token = lowercase_token.upper()
function_name = lowercase_token[0:3] + '_func'
test_exe_name = lowercase_token + '_test'
lib_h_name = lowercase_token + '.h'
lib_objcpp_name = lowercase_token + '.mm'
test_objcpp_name = lowercase_token + '_test.mm'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'function_name': function_name,
'header_file': lib_h_name,
'source_file': lib_objcpp_name,
'test_source_file': test_objcpp_name,
'test_exe_name': test_exe_name,
'project_name': self.name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': self.version,
}
open(lib_h_name, 'w').write(lib_h_template.format(**kwargs))
open(lib_objcpp_name, 'w').write(lib_objcpp_template.format(**kwargs))
open(test_objcpp_name, 'w').write(lib_objcpp_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_objcpp_meson_template.format(**kwargs))

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mesonbuild.templates.sampleimpl import SampleImpl
import re
@ -121,37 +122,44 @@ exe = executable('{exe_name}', '{source_name}',
test('basic', exe)
'''
def create_exe_objc_sample(project_name, project_version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
source_name = lowercase_token + '.m'
open(source_name, 'w').write(hello_objc_template.format(project_name=project_name))
open('meson.build', 'w').write(hello_objc_meson_template.format(project_name=project_name,
exe_name=lowercase_token,
source_name=source_name,
version=project_version))
def create_lib_objc_sample(project_name, version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
uppercase_token = lowercase_token.upper()
function_name = lowercase_token[0:3] + '_func'
test_exe_name = lowercase_token + '_test'
lib_h_name = lowercase_token + '.h'
lib_objc_name = lowercase_token + '.m'
test_objc_name = lowercase_token + '_test.m'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'function_name': function_name,
'header_file': lib_h_name,
'source_file': lib_objc_name,
'test_source_file': test_objc_name,
'test_exe_name': test_exe_name,
'project_name': project_name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': version,
}
open(lib_h_name, 'w').write(lib_h_template.format(**kwargs))
open(lib_objc_name, 'w').write(lib_objc_template.format(**kwargs))
open(test_objc_name, 'w').write(lib_objc_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_objc_meson_template.format(**kwargs))
class ObjCProject(SampleImpl):
def __init__(self, options):
super().__init__()
self.name = options.name
self.version = options.version
def create_executable(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
source_name = lowercase_token + '.m'
open(source_name, 'w').write(hello_objc_template.format(project_name=self.name))
open('meson.build', 'w').write(hello_objc_meson_template.format(project_name=self.name,
exe_name=lowercase_token,
source_name=source_name,
version=self.version))
def create_library(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
uppercase_token = lowercase_token.upper()
function_name = lowercase_token[0:3] + '_func'
test_exe_name = lowercase_token + '_test'
lib_h_name = lowercase_token + '.h'
lib_objc_name = lowercase_token + '.m'
test_objc_name = lowercase_token + '_test.m'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'function_name': function_name,
'header_file': lib_h_name,
'source_file': lib_objc_name,
'test_source_file': test_objc_name,
'test_exe_name': test_exe_name,
'project_name': self.name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': self.version,
}
open(lib_h_name, 'w').write(lib_h_template.format(**kwargs))
open(lib_objc_name, 'w').write(lib_objc_template.format(**kwargs))
open(test_objc_name, 'w').write(lib_objc_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_objc_meson_template.format(**kwargs))

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mesonbuild.templates.sampleimpl import SampleImpl
import re
@ -69,36 +70,43 @@ exe = executable('{exe_name}', '{source_name}',
test('basic', exe)
'''
def create_exe_rust_sample(project_name, project_version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
source_name = lowercase_token + '.rs'
open(source_name, 'w').write(hello_rust_template.format(project_name=project_name))
open('meson.build', 'w').write(hello_rust_meson_template.format(project_name=project_name,
exe_name=lowercase_token,
source_name=source_name,
version=project_version))
def create_lib_rust_sample(project_name, version):
lowercase_token = re.sub(r'[^a-z0-9]', '_', project_name.lower())
uppercase_token = lowercase_token.upper()
function_name = lowercase_token[0:3] + '_func'
test_exe_name = lowercase_token + '_test'
lib_crate_name = lowercase_token
lib_rs_name = lowercase_token + '.rs'
test_rs_name = lowercase_token + '_test.rs'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'function_name': function_name,
'crate_file': lib_crate_name,
'source_file': lib_rs_name,
'test_source_file': test_rs_name,
'test_exe_name': test_exe_name,
'project_name': project_name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': version,
}
open(lib_rs_name, 'w').write(lib_rust_template.format(**kwargs))
open(test_rs_name, 'w').write(lib_rust_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_rust_meson_template.format(**kwargs))
class RustProject(SampleImpl):
def __init__(self, options):
super().__init__()
self.name = options.name
self.version = options.version
def create_executable(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
source_name = lowercase_token + '.rs'
open(source_name, 'w').write(hello_rust_template.format(project_name=self.name))
open('meson.build', 'w').write(hello_rust_meson_template.format(project_name=self.name,
exe_name=lowercase_token,
source_name=source_name,
version=self.version))
def create_library(self):
lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower())
uppercase_token = lowercase_token.upper()
function_name = lowercase_token[0:3] + '_func'
test_exe_name = lowercase_token + '_test'
lib_crate_name = lowercase_token
lib_rs_name = lowercase_token + '.rs'
test_rs_name = lowercase_token + '_test.rs'
kwargs = {'utoken': uppercase_token,
'ltoken': lowercase_token,
'header_dir': lowercase_token,
'function_name': function_name,
'crate_file': lib_crate_name,
'source_file': lib_rs_name,
'test_source_file': test_rs_name,
'test_exe_name': test_exe_name,
'project_name': self.name,
'lib_name': lowercase_token,
'test_name': lowercase_token,
'version': self.version,
}
open(lib_rs_name, 'w').write(lib_rust_template.format(**kwargs))
open(test_rs_name, 'w').write(lib_rust_test_template.format(**kwargs))
open('meson.build', 'w').write(lib_rust_meson_template.format(**kwargs))

@ -0,0 +1,38 @@
# Copyright 2019 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mesonbuild.templates.fortrantemplates import FortranProject
from mesonbuild.templates.objcpptemplates import ObjCppProject
from mesonbuild.templates.dlangtemplates import DlangProject
from mesonbuild.templates.rusttemplates import RustProject
from mesonbuild.templates.javatemplates import JavaProject
from mesonbuild.templates.cudatemplates import CudaProject
from mesonbuild.templates.objctemplates import ObjCProject
from mesonbuild.templates.cpptemplates import CppProject
from mesonbuild.templates.cstemplates import CSharpProject
from mesonbuild.templates.ctemplates import CProject
def sameple_generator(options):
return {
'c': CProject,
'cpp': CppProject,
'cs': CSharpProject,
'cuda': CudaProject,
'objc': ObjCProject,
'objcpp': ObjCppProject,
'java': JavaProject,
'd': DlangProject,
'rust': RustProject,
'fortran': FortranProject
}[options.language](options)

@ -0,0 +1,21 @@
# Copyright 2019 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class SampleImpl:
def create_executable(self):
raise NotImplementedError('Sample implementation for "executable" not implemented!')
def create_library(self):
raise NotImplementedError('Sample implementation for "library" not implemented!')
Loading…
Cancel
Save