diff options
-rw-r--r-- | mesonbuild/coredata.py | 12 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 33 | ||||
-rw-r--r-- | mesonbuild/mesonmain.py | 32 |
3 files changed, 46 insertions, 31 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 1e2a213..4c93ffb 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -197,7 +197,7 @@ class CoreData: self.target_guids = {} self.version = version self.init_builtins(options) - self.init_backend_options(self.builtins['backend'].value) + self.backend_options = {} self.user_options = {} self.compiler_options = {} self.base_options = {} @@ -307,12 +307,18 @@ class CoreData: args = [key] + builtin_options[key][1:-1] + [value] self.builtins[key] = builtin_options[key][0](*args) - def init_backend_options(self, backend_name): - self.backend_options = {} + def init_backend_options(self, backend_name, options): if backend_name == 'ninja': self.backend_options['backend_max_links'] = UserIntegerOption('backend_max_links', 'Maximum number of linker processes to run or 0 for no limit', 0, None, 0) + for o in options: + key, value = o.split('=', 1) + if not key.startswith('backend_'): + continue + if key not in self.backend_options: + raise MesonException('Unknown backend option %s' % key) + self.backend_options[key].set_value(value) def get_builtin_option(self, optname): if optname in self.builtins: diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 0dbe8ca..c513823 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1754,7 +1754,7 @@ permitted_kwargs = {'add_global_arguments': {'language'}, class Interpreter(InterpreterBase): - def __init__(self, build, backend, subproject='', subdir='', subproject_dir='subprojects', + def __init__(self, build, backend=None, subproject='', subdir='', subproject_dir='subprojects', modules = None, default_project_options=[]): super().__init__(build.environment.get_source_dir(), subdir) self.an_unpicklable_object = mesonlib.an_unpicklable_object @@ -2256,6 +2256,36 @@ to directly access options of other subprojects.''') newoptions = [defopt] + self.environment.cmd_line_options.projectoptions self.environment.cmd_line_options.projectoptions = newoptions + def set_backend(self): + # The backend is already set when parsing subprojects + if self.backend is not None: + return + backend = self.coredata.get_builtin_option('backend') + if backend == 'ninja': + from .backend import ninjabackend + self.backend = ninjabackend.NinjaBackend(self.build) + elif backend == 'vs': + from .backend import vs2010backend + self.backend = vs2010backend.autodetect_vs_version(self.build) + self.coredata.set_builtin_option('backend', self.backend.name) + mlog.log('Auto detected Visual Studio backend:', mlog.bold(self.backend.name)) + elif backend == 'vs2010': + from .backend import vs2010backend + self.backend = vs2010backend.Vs2010Backend(self.build) + elif backend == 'vs2015': + from .backend import vs2015backend + self.backend = vs2015backend.Vs2015Backend(self.build) + elif backend == 'vs2017': + from .backend import vs2017backend + self.backend = vs2017backend.Vs2017Backend(self.build) + elif backend == 'xcode': + from .backend import xcodebackend + self.backend = xcodebackend.XCodeBackend(self.build) + else: + raise InterpreterException('Unknown backend "%s".' % backend) + + self.coredata.init_backend_options(backend, self.environment.cmd_line_options.projectoptions) + @stringArgs @permittedKwargs(permitted_kwargs['project']) def func_project(self, node, args, kwargs): @@ -2277,6 +2307,7 @@ to directly access options of other subprojects.''') ) oi.process(self.option_file) self.build.environment.merge_options(oi.options) + self.set_backend() self.active_projectname = proj_name self.project_version = kwargs.get('version', 'undefined') if self.build.project_version is None: diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index f7a57d8..50a8c7e 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -148,30 +148,8 @@ class MesonApp: else: mlog.log('Build type:', mlog.bold('native build')) b = build.Build(env) - if self.options.backend == 'ninja': - from .backend import ninjabackend - g = ninjabackend.NinjaBackend(b) - elif self.options.backend == 'vs': - from .backend import vs2010backend - g = vs2010backend.autodetect_vs_version(b) - env.coredata.set_builtin_option('backend', g.name) - mlog.log('Auto detected Visual Studio backend:', mlog.bold(g.name)) - elif self.options.backend == 'vs2010': - from .backend import vs2010backend - g = vs2010backend.Vs2010Backend(b) - elif self.options.backend == 'vs2015': - from .backend import vs2015backend - g = vs2015backend.Vs2015Backend(b) - elif self.options.backend == 'vs2017': - from .backend import vs2017backend - g = vs2017backend.Vs2017Backend(b) - elif self.options.backend == 'xcode': - from .backend import xcodebackend - g = xcodebackend.XCodeBackend(b) - else: - raise RuntimeError('Unknown backend "%s".' % self.options.backend) - intr = interpreter.Interpreter(b, g) + intr = interpreter.Interpreter(b) if env.is_cross_build(): mlog.log('Host machine cpu family:', mlog.bold(intr.builtin['host_machine'].cpu_family_method([], {}))) mlog.log('Host machine cpu:', mlog.bold(intr.builtin['host_machine'].cpu_method([], {}))) @@ -194,14 +172,14 @@ class MesonApp: # possible, but before build files, and if any error occurs, delete it. cdf = env.dump_coredata() if self.options.profile: - fname = 'profile-{}-backend.log'.format(self.options.backend) + fname = 'profile-{}-backend.log'.format(intr.backend.name) fname = os.path.join(self.build_dir, 'meson-private', fname) - profile.runctx('g.generate(intr)', globals(), locals(), filename=fname) + profile.runctx('intr.backend.generate(intr)', globals(), locals(), filename=fname) else: - g.generate(intr) + intr.backend.generate(intr) build.save(b, dumpfile) # Post-conf scripts must be run after writing coredata or else introspection fails. - g.run_postconf_scripts() + intr.backend.run_postconf_scripts() except: if 'cdf' in locals(): old_cdf = cdf + '.prev' |