Added method kwarg to subproject

pull/4969/head
Daniel Mensinger 6 years ago
parent 09a722c4bd
commit a9a3b3ffe6
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 46
      mesonbuild/interpreter.py
  2. 3
      mesonbuild/wrap/wrap.py

@ -2027,7 +2027,7 @@ permitted_kwargs = {'add_global_arguments': {'language', 'native'},
'both_libraries': known_library_kwargs, 'both_libraries': known_library_kwargs,
'library': known_library_kwargs, 'library': known_library_kwargs,
'subdir': {'if_found'}, 'subdir': {'if_found'},
'subproject': {'version', 'default_options', 'required'}, 'subproject': {'version', 'default_options', 'required', 'method'},
'test': {'args', 'depends', 'env', 'is_parallel', 'should_fail', 'timeout', 'workdir', 'test': {'args', 'depends', 'env', 'is_parallel', 'should_fail', 'timeout', 'workdir',
'suite', 'protocol'}, 'suite', 'protocol'},
'vcs_tag': {'input', 'output', 'fallback', 'command', 'replace_string'}, 'vcs_tag': {'input', 'output', 'fallback', 'command', 'replace_string'},
@ -2412,6 +2412,7 @@ external dependencies (including libraries) must go to "dependencies".''')
raise InterpreterException('Tried to call option() in build description file. All options must be in the option file.') raise InterpreterException('Tried to call option() in build description file. All options must be in the option file.')
@FeatureNewKwargs('subproject', '0.38.0', ['default_options']) @FeatureNewKwargs('subproject', '0.38.0', ['default_options'])
@FeatureNewKwargs('subproject', '0.50.0', ['method'])
@permittedKwargs(permitted_kwargs['subproject']) @permittedKwargs(permitted_kwargs['subproject'])
@stringArgs @stringArgs
def func_subproject(self, nodes, args, kwargs): def func_subproject(self, nodes, args, kwargs):
@ -2432,6 +2433,7 @@ external dependencies (including libraries) must go to "dependencies".''')
default_options = mesonlib.stringlistify(kwargs.get('default_options', [])) default_options = mesonlib.stringlistify(kwargs.get('default_options', []))
default_options = coredata.create_options_dict(default_options) default_options = coredata.create_options_dict(default_options)
method = kwargs.get('method', 'auto')
if dirname == '': if dirname == '':
raise InterpreterException('Subproject dir name must not be empty.') raise InterpreterException('Subproject dir name must not be empty.')
if dirname[0] == '.': if dirname[0] == '.':
@ -2473,22 +2475,27 @@ external dependencies (including libraries) must go to "dependencies".''')
raise e raise e
subdir = os.path.join(self.subproject_dir, resolved) subdir = os.path.join(self.subproject_dir, resolved)
subdir_abs = os.path.join(subproject_dir_abs, resolved)
os.makedirs(os.path.join(self.build.environment.get_build_dir(), subdir), exist_ok=True) os.makedirs(os.path.join(self.build.environment.get_build_dir(), subdir), exist_ok=True)
self.global_args_frozen = True self.global_args_frozen = True
# Determine the method to use when 'auto' is given
if method == 'auto':
if os.path.exists(os.path.join(subdir_abs, environment.build_filename)):
method = 'meson'
elif os.path.exists(os.path.join(subdir_abs, 'CMakeLists.txt')):
method = 'cmake'
mlog.log() mlog.log()
with mlog.nested(): with mlog.nested():
mlog.log('Executing subproject', mlog.bold(dirname), '\n') mlog.log('Executing subproject', mlog.bold(dirname), 'method', mlog.bold(method), '\n')
try: try:
with mlog.nested(): if method == 'meson':
new_build = self.build.copy() return self.do_subproject_meson(dirname, subdir, default_options, required, kwargs)
subi = Interpreter(new_build, self.backend, dirname, subdir, self.subproject_dir, elif method == 'cmake':
self.modules, default_options) return self.do_subproject_cmake(dirname, subdir, required, kwargs)
subi.subprojects = self.subprojects else:
raise InterpreterException('The method {} is invalid for the subproject {}'.format(method, dirname))
subi.subproject_stack = self.subproject_stack + [dirname]
current_active = self.active_projectname
subi.run()
mlog.log('Subproject', mlog.bold(dirname), 'finished.')
# Invalid code is always an error # Invalid code is always an error
except InvalidCode: except InvalidCode:
raise raise
@ -2502,6 +2509,18 @@ external dependencies (including libraries) must go to "dependencies".''')
return self.disabled_subproject(dirname) return self.disabled_subproject(dirname)
raise e raise e
def do_subproject_meson(self, dirname, subdir, default_options, required, kwargs):
with mlog.nested():
new_build = self.build.copy()
subi = Interpreter(new_build, self.backend, dirname, subdir, self.subproject_dir,
self.modules, default_options)
subi.subprojects = self.subprojects
subi.subproject_stack = self.subproject_stack + [dirname]
current_active = self.active_projectname
subi.run()
mlog.log('Subproject', mlog.bold(dirname), 'finished.')
mlog.log() mlog.log()
if 'version' in kwargs: if 'version' in kwargs:
@ -2518,6 +2537,9 @@ external dependencies (including libraries) must go to "dependencies".''')
self.build.subprojects[dirname] = subi.project_version self.build.subprojects[dirname] = subi.project_version
return self.subprojects[dirname] return self.subprojects[dirname]
def do_subproject_cmake(self, dirname, subdir, required, kwargs):
raise InterpreterException('CMake subprojects are currently a stub')
def get_option_internal(self, optname): def get_option_internal(self, optname):
for opts in chain( for opts in chain(
[self.coredata.base_options, compilers.base_options, self.coredata.builtins], [self.coredata.base_options, compilers.base_options, self.coredata.builtins],

@ -123,9 +123,10 @@ class Resolver:
raise WrapException('Directory key must be a name and not a path') raise WrapException('Directory key must be a name and not a path')
self.dirname = os.path.join(self.subdir_root, self.directory) self.dirname = os.path.join(self.subdir_root, self.directory)
meson_file = os.path.join(self.dirname, 'meson.build') meson_file = os.path.join(self.dirname, 'meson.build')
cmake_file = os.path.join(self.dirname, 'CMakeLists.txt')
# The directory is there and has meson.build? Great, use it. # The directory is there and has meson.build? Great, use it.
if os.path.exists(meson_file): if os.path.exists(meson_file) or os.path.exists(cmake_file):
return self.directory return self.directory
# Check if the subproject is a git submodule # Check if the subproject is a git submodule

Loading…
Cancel
Save