diff options
-rw-r--r-- | build.py | 7 | ||||
-rw-r--r-- | dependencies.py | 21 | ||||
-rw-r--r-- | interpreter.py | 48 | ||||
-rw-r--r-- | modules/gnome.py | 105 | ||||
-rw-r--r-- | modules/modtest.py | 14 | ||||
-rw-r--r-- | modules/qt5.py | 121 | ||||
-rw-r--r-- | ninjabackend.py | 15 | ||||
-rw-r--r-- | test cases/frameworks/4 qt5/meson.build | 7 |
8 files changed, 230 insertions, 108 deletions
@@ -19,11 +19,7 @@ import mlog import copy, os -known_basic_kwargs = {'ui_files': True, - 'moc_headers' : True, - 'qresources' : True, - 'moc_sources' : True, - 'install' : True, +known_basic_kwargs = {'install' : True, 'c_pch' : True, 'cpp_pch' : True, 'c_args' : True, @@ -78,6 +74,7 @@ class Build: self.pkgconfig_gens = [] self.install_script = None self.install_dirs = [] + self.modules = {} def has_language(self, language): for i in self.compilers: diff --git a/dependencies.py b/dependencies.py index 2779240..2f3cf6c 100644 --- a/dependencies.py +++ b/dependencies.py @@ -21,7 +21,6 @@ import os, stat, glob, subprocess, shutil from coredata import MesonException -import environment import mlog import mesonlib @@ -58,11 +57,6 @@ class Dependency(): def get_name(self): return self.name - # Rules for commands to execute before compilation - # such as Qt's moc preprocessor. - def get_generate_rules(self): - return [] - def get_exe_args(self): return [] @@ -664,21 +658,6 @@ class Qt5Dependency(Dependency): return False return True - def get_generate_rules(self): - moc_rule = CustomRule(self.moc.get_command() + ['$mocargs', '@INFILE@', '-o', '@OUTFILE@'], - 'moc_@BASENAME@.cpp', 'moc_headers', 'moc_hdr_compile', - 'Compiling header @INFILE@ with the moc preprocessor') - mocsrc_rule = CustomRule(self.moc.get_command() + ['$mocargs', '@INFILE@', '-o', '@OUTFILE@'], - '@BASENAME@.moc', 'moc_sources', 'moc_src_compile', - 'Compiling source @INFILE@ with the moc preprocessor') - ui_rule = CustomRule(self.uic.get_command() + ['@INFILE@', '-o', '@OUTFILE@'], - 'ui_@BASENAME@.h', 'ui_files', 'ui_compile', - 'Compiling @INFILE@ with the ui compiler') - rrc_rule = CustomRule(self.rcc.get_command() + ['@INFILE@', '-o', '@OUTFILE@', - '${rcc_args}'], '@BASENAME@.cpp','qresources', - 'rc_compile', 'Compiling @INFILE@ with the rrc compiler') - return [moc_rule, mocsrc_rule, ui_rule, rrc_rule] - def get_exe_args(self): # Qt5 seems to require this always. # Fix this to be more portable, especially to MSVC. diff --git a/interpreter.py b/interpreter.py index 064a2e9..d9a845c 100644 --- a/interpreter.py +++ b/interpreter.py @@ -382,9 +382,9 @@ class GeneratedObjectsHolder(InterpreterObject): self.held_object = held_object class BuildTargetHolder(InterpreterObject): - def __init__(self, targetttype, name, subdir, is_cross, sources, objects, environment, kwargs): + def __init__(self, target): super().__init__() - self.held_object = targetttype(name, subdir, is_cross, sources, objects, environment, kwargs) + self.held_object = target self.methods.update({'extract_objects' : self.extract_objects_method}) def is_cross(self): @@ -395,16 +395,16 @@ class BuildTargetHolder(InterpreterObject): return GeneratedObjectsHolder(gobjs) class ExecutableHolder(BuildTargetHolder): - def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs): - super().__init__(build.Executable, name, subdir, is_cross, sources, objects, environment, kwargs) + def __init__(self, target): + super().__init__(target) class StaticLibraryHolder(BuildTargetHolder): - def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs): - super().__init__(build.StaticLibrary, name, subdir, is_cross, sources, objects, environment, kwargs) + def __init__(self, target): + super().__init__(target) class SharedLibraryHolder(BuildTargetHolder): - def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs): - super().__init__(build.SharedLibrary, name, subdir, is_cross, sources, objects, environment, kwargs) + def __init__(self, target): + super().__init__(target) class JarHolder(BuildTargetHolder): def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs): @@ -600,7 +600,7 @@ class ModuleHolder(InterpreterObject): def __init__(self, modname, interpreter): InterpreterObject.__init__(self) self.modname = modname - self.m = importlib.import_module('modules.' + modname) + self.m = importlib.import_module('modules.' + modname).initialize() self.interpreter = interpreter def method_call(self, method_name, args, kwargs): @@ -612,6 +612,7 @@ class ModuleHolder(InterpreterObject): state.build_to_src = os.path.relpath(self.interpreter.environment.get_source_dir(), self.interpreter.environment.get_build_dir()) state.subdir = self.interpreter.subdir + state.environment = self.interpreter.environment value = fn(state, args, kwargs) return self.interpreter.module_method_callback(value) @@ -784,6 +785,11 @@ class Interpreter(): outvalues.append(CustomTargetHolder(v)) elif isinstance(v, int) or isinstance(v, str): outvalues.append(v) + elif isinstance(v, build.Executable): + if v.name in self.build.targets: + raise InterpreterException('Tried to create target %s which already exists.' % v.name) + self.build.targets[v.name] = v + outvalues.append(ExecutableHolder(v)) else: raise InterpreterException('Module returned a value of unknown type.') if len(outvalues) == 1 and unwrap_single: @@ -852,7 +858,9 @@ class Interpreter(): if not isinstance(modname, str): raise InvalidCode('Argument to import was not a string') if not modname in self.modules: - self.modules[modname] = ModuleHolder(modname, self) + mh = mh = ModuleHolder(modname, self) + self.modules[modname] = mh + self.build.modules[modname] = mh.m return self.modules[modname] def set_variable(self, varname, variable): @@ -1434,6 +1442,8 @@ class Interpreter(): return args if isinstance(args, InterpreterObject): return args + if isinstance(args, int): + return args result = [] for a in args: if isinstance(a, list): @@ -1445,7 +1455,7 @@ class Interpreter(): result.append(a) return result - def build_target(self, node, args, kwargs, targetclass): + def build_target(self, node, args, kwargs, targetholder): args = self.flatten(args) name = args[0] sources = args[1:] @@ -1472,15 +1482,19 @@ class Interpreter(): if name in self.build.targets: raise InvalidCode('Tried to create target "%s", but a target of that name already exists.' % name) self.check_sources_exist(os.path.join(self.source_root, self.subdir), sources) - l = targetclass(name, self.subdir, is_cross, sources, objs, self.environment, kwargs) + if isinstance(targetholder, ExecutableHolder): + targetclass = build.Executable + elif isinstance(targetholder, SharedLibraryHolder): + targetclass = build.SharedLibrary + elif isinstance(targetholder, StaticLibraryHolder): + targetclass = build.StaticLibrary + else: + raise RuntimeError('Unreachable code') + target = targetclass(name, self.subdir, is_cross, sources, objs, self.environment, kwargs) + l = targetholder(target) self.build.targets[name] = l.held_object if name not in self.coredata.target_guids: self.coredata.target_guids[name] = str(uuid.uuid4()).upper() - if self.environment.is_cross_build() and l.is_cross: - txt = ' cross build ' - else: - txt = ' build ' - displayname = os.path.join(l.held_object.subdir, name) self.global_args_frozen = True return l diff --git a/modules/gnome.py b/modules/gnome.py index fd8d09d..966fd73 100644 --- a/modules/gnome.py +++ b/modules/gnome.py @@ -1,4 +1,4 @@ -# Copyright 2012-2015 The Meson development team +# Copyright 2015 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. @@ -20,52 +20,59 @@ import os import subprocess from coredata import MesonException -def compile_resources(state, args, kwargs): - cmd = ['glib-compile-resources', '@INPUT@', '--generate'] - if 'source_dir' in kwargs: - d = os.path.join(state.build_to_src, kwargs.pop('source_dir')) - cmd += ['--sourcedir', d] - if 'c_name' in kwargs: - cmd += ['--c-name', kwargs.pop('c_name')] - cmd += ['--target', '@OUTPUT@'] - kwargs['command'] = cmd - output_c = args[0] + '.c' - output_h = args[0] + '.h' - kwargs['input'] = args[1] - kwargs['output'] = output_c - target_c = build.CustomTarget(args[0]+'_c', state.subdir, kwargs) - kwargs['output'] = output_h - target_h = build.CustomTarget(args[0] + '_h', state.subdir, kwargs) - return [target_c, target_h] - -def generate_gir(state, args, kwargs): - if len(args) != 1: - raise MesonException('Gir takes one argument') - girtarget = args[0] - while hasattr(girtarget, 'held_object'): - girtarget = girtarget.held_object - if not isinstance(girtarget, build.Executable): - raise MesonException('Gir target must be an executable') - pkgstr = subprocess.check_output(['pkg-config', '--cflags', 'gobject-introspection-1.0']) - pkgargs = pkgstr.decode().strip().split() - ns = kwargs.pop('namespace') - nsversion = kwargs.pop('nsversion') - libsources = kwargs.pop('sources') - girfile = '%s-%s.gir' % (ns, nsversion) - scan_name = girtarget.name + '-gir' - scan_command = ['g-ir-scanner', '@INPUT@', '--program', girtarget] - scan_command += pkgargs - scan_command += ['--include=GObject-2.0', '--namespace='+ns, - '--nsversion=' + nsversion, '--output', '@OUTPUT@'] - scankwargs = {'output' : girfile, - 'input' : libsources, - 'command' : scan_command} - scan_target = build.CustomTarget(scan_name, state.subdir, scankwargs) +class GnomeModule: + def get_rules(self, ): + return [] + + def compile_resources(self, state, args, kwargs): + cmd = ['glib-compile-resources', '@INPUT@', '--generate'] + if 'source_dir' in kwargs: + d = os.path.join(state.build_to_src, kwargs.pop('source_dir')) + cmd += ['--sourcedir', d] + if 'c_name' in kwargs: + cmd += ['--c-name', kwargs.pop('c_name')] + cmd += ['--target', '@OUTPUT@'] + kwargs['command'] = cmd + output_c = args[0] + '.c' + output_h = args[0] + '.h' + kwargs['input'] = args[1] + kwargs['output'] = output_c + target_c = build.CustomTarget(args[0]+'_c', state.subdir, kwargs) + kwargs['output'] = output_h + target_h = build.CustomTarget(args[0] + '_h', state.subdir, kwargs) + return [target_c, target_h] - typelib_name = girtarget.name + '-typelib' - typelib_output = '%s-%s.typelib' % (ns, nsversion) - typelib_cmd = ['g-ir-compiler', scan_target, '--output', '@OUTPUT@'] - kwargs['output'] = typelib_output - kwargs['command'] = typelib_cmd - typelib_target = build.CustomTarget(typelib_name, state.subdir, kwargs) - return [scan_target, typelib_target] + def generate_gir(self, state, args, kwargs): + if len(args) != 1: + raise MesonException('Gir takes one argument') + girtarget = args[0] + while hasattr(girtarget, 'held_object'): + girtarget = girtarget.held_object + if not isinstance(girtarget, build.Executable): + raise MesonException('Gir target must be an executable') + pkgstr = subprocess.check_output(['pkg-config', '--cflags', 'gobject-introspection-1.0']) + pkgargs = pkgstr.decode().strip().split() + ns = kwargs.pop('namespace') + nsversion = kwargs.pop('nsversion') + libsources = kwargs.pop('sources') + girfile = '%s-%s.gir' % (ns, nsversion) + scan_name = girtarget.name + '-gir' + scan_command = ['g-ir-scanner', '@INPUT@', '--program', girtarget] + scan_command += pkgargs + scan_command += ['--include=GObject-2.0', '--namespace='+ns, + '--nsversion=' + nsversion, '--output', '@OUTPUT@'] + scankwargs = {'output' : girfile, + 'input' : libsources, + 'command' : scan_command} + scan_target = build.CustomTarget(scan_name, state.subdir, scankwargs) + + typelib_name = girtarget.name + '-typelib' + typelib_output = '%s-%s.typelib' % (ns, nsversion) + typelib_cmd = ['g-ir-compiler', scan_target, '--output', '@OUTPUT@'] + kwargs['output'] = typelib_output + kwargs['command'] = typelib_cmd + typelib_target = build.CustomTarget(typelib_name, state.subdir, kwargs) + return [scan_target, typelib_target] + +def initialize(): + return GnomeModule() diff --git a/modules/modtest.py b/modules/modtest.py index 2bfc04a..f262140 100644 --- a/modules/modtest.py +++ b/modules/modtest.py @@ -1,4 +1,4 @@ -# Copyright 2012-2015 The Meson development team +# Copyright 2015 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. @@ -12,5 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -def print_hello(state, args, kwargs): - print('Hello from a Meson module') +class TestModule: + + def get_rules(self): + return [] + + def print_hello(self, state, args, kwargs): + print('Hello from a Meson module') + +def initialize(): + return TestModule() diff --git a/modules/qt5.py b/modules/qt5.py new file mode 100644 index 0000000..d1beb0b --- /dev/null +++ b/modules/qt5.py @@ -0,0 +1,121 @@ +# Copyright 2015 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. + +import dependencies, mlog, subprocess +import build +from coredata import MesonException + +class Qt5Module(): + + def __init__(self): + + mlog.log('Detecting Qt tools.') + # The binaries have different names on different + # distros. Joy. + self.moc = dependencies.ExternalProgram('moc', silent=True) + if not self.moc.found(): + self.moc = dependencies.ExternalProgram('moc-qt5', silent=True) + self.uic = dependencies.ExternalProgram('uic', silent=True) + if not self.uic.found(): + self.uic = dependencies.ExternalProgram('uic-qt5', silent=True) + self.rcc = dependencies.ExternalProgram('rcc', silent=True) + if not self.rcc.found(): + self.rcc = dependencies.ExternalProgram('rcc-qt5', silent=True) + # Moc, uic and rcc write their version strings to stderr. + # Moc and rcc return a non-zero result when doing so. + # What kind of an idiot thought that was a good idea? + if self.moc.found(): + mp = subprocess.Popen(self.moc.get_command() + ['-v'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (stdout, stderr) = mp.communicate() + stdout = stdout.decode().strip() + stderr = stderr.decode().strip() + if 'Qt 5' in stderr: + moc_ver = stderr + elif '5.' in stdout: + moc_ver = stdout + else: + raise MesonException('Moc preprocessor is not for Qt 5. Output:\n%s\n%s' % + (stdout, stderr)) + mlog.log(' moc:', mlog.green('YES'), '(%s, %s)' % \ + (' '.join(self.moc.fullpath), moc_ver.split()[-1])) + else: + mlog.log(' moc:', mlog.red('NO')) + if self.uic.found(): + up = subprocess.Popen(self.uic.get_command() + ['-v'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (stdout, stderr) = up.communicate() + stdout = stdout.decode().strip() + stderr = stderr.decode().strip() + if 'version 5.' in stderr: + uic_ver = stderr + elif '5.' in stdout: + uic_ver = stdout + else: + raise MesonException('Uic compiler is not for Qt 5. Output:\n%s\n%s' % + (stdout, stderr)) + mlog.log(' uic:', mlog.green('YES'), '(%s, %s)' % \ + (' '.join(self.uic.fullpath), uic_ver.split()[-1])) + else: + mlog.log(' uic:', mlog.red('NO')) + if self.rcc.found(): + rp = subprocess.Popen(self.rcc.get_command() + ['-v'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (stdout, stderr) = rp.communicate() + stdout = stdout.decode().strip() + stderr = stderr.decode().strip() + if 'version 5.' in stderr: + rcc_ver = stderr + elif '5.' in stdout: + rcc_ver = stdout + else: + raise MesonException('Rcc compiler is not for Qt 5. Output:\n%s\n%s' % + (stdout, stderr)) + mlog.log(' rcc:', mlog.green('YES'), '(%s, %s)'\ + % (' '.join(self.rcc.fullpath), rcc_ver.split()[-1])) + else: + mlog.log(' rcc:', mlog.red('NO')) + + def get_rules(self): + global moc, uic, rcc + moc_rule = dependencies.CustomRule(self.moc.get_command() + ['$mocargs', '@INFILE@', '-o', '@OUTFILE@'], + 'moc_@BASENAME@.cpp', 'moc_headers', 'moc_hdr_compile', + 'Compiling header @INFILE@ with the moc preprocessor') + mocsrc_rule = dependencies.CustomRule(self.moc.get_command() + ['$mocargs', '@INFILE@', '-o', '@OUTFILE@'], + '@BASENAME@.moc', 'moc_sources', 'moc_src_compile', + 'Compiling source @INFILE@ with the moc preprocessor') + ui_rule = dependencies.CustomRule(self.uic.get_command() + ['@INFILE@', '-o', '@OUTFILE@'], + 'ui_@BASENAME@.h', 'ui_files', 'ui_compile', + 'Compiling @INFILE@ with the ui compiler') + rrc_rule = dependencies.CustomRule(self.rcc.get_command() + ['@INFILE@', '-o', '@OUTFILE@', + '${rcc_args}'], '@BASENAME@.cpp','qresources', + 'rc_compile', 'Compiling @INFILE@ with the rrc compiler') + return [moc_rule, mocsrc_rule, ui_rule, rrc_rule] + + def executable(self, state, args, kwargs): + rcc_files = kwargs.pop('qresources', []) + uic_files = kwargs.pop('ui_files', []) + moc_headers = kwargs.pop('moc_headers', []) + moc_sources = kwargs.pop('moc_sources', []) + name = args[0] + srctmp = kwargs.pop('sources', []) + if not isinstance(srctmp, list): + srctmp = [srctmp] + sources = args[1:] + srctmp + objects = [] + return build.Executable(name, state.subdir, state.environment.is_cross_build(), sources, objects, + state.environment, kwargs) + +def initialize(): + return Qt5Module() diff --git a/ninjabackend.py b/ninjabackend.py index 66bae36..a00f216 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -499,15 +499,10 @@ class NinjaBackend(backends.Backend): velem.add_item('pool', 'console') velem.write(outfile) - def generate_dep_gen_rules(self, outfile): - outfile.write('# Rules for external dependency generators.\n\n') - processed = {} - for dep in self.environment.coredata.deps.values(): - name = dep.get_name() - if name in processed: - continue - processed[name] = True - for rule in dep.get_generate_rules(): + def generate_module_rules(self, outfile): + outfile.write('# Rules coming from modules.\n\n') + for mod in self.build.modules.values(): + for rule in mod.get_rules(): outfile.write('rule %s\n' % rule.name) command = ' '.join([ninja_quote(x) for x in rule.cmd_list]) command = command.replace('@INFILE@', '$in').replace('@OUTFILE@', '$out') @@ -529,7 +524,7 @@ class NinjaBackend(backends.Backend): self.generate_static_link_rules(True, outfile) self.generate_static_link_rules(False, outfile) self.generate_dynamic_link_rules(outfile) - self.generate_dep_gen_rules(outfile) + self.generate_module_rules(outfile) outfile.write('# Other rules\n\n') outfile.write('rule CUSTOM_COMMAND\n') outfile.write(' command = $COMMAND\n') diff --git a/test cases/frameworks/4 qt5/meson.build b/test cases/frameworks/4 qt5/meson.build index f72c445..7a90c1d 100644 --- a/test cases/frameworks/4 qt5/meson.build +++ b/test cases/frameworks/4 qt5/meson.build @@ -1,8 +1,9 @@ project('qt5 build test', 'cpp') +qt5 = import('qt5') qt5dep = dependency('qt5', modules : 'Widgets') -q5exe = executable('qt5app', +q5exe = qt5.executable('qt5app', sources : ['main.cpp', 'mainWindow.cpp'], # Sources that don't need preprocessing. moc_headers : ['mainWindow.h'], # These need to be fed through the moc tool before use. ui_files : 'mainWindow.ui', # XML files that need to be compiled with the uic tol. @@ -14,7 +15,7 @@ dependencies : qt5dep) qt5core = dependency('qt5', modules : 'Core') -qt5coreapp = executable('q5core', 'q5core.cpp', +qt5coreapp = qt5.executable('q5core', 'q5core.cpp', dependencies : qt5core) test('qt5test', qt5coreapp) @@ -22,7 +23,7 @@ test('qt5test', qt5coreapp) # The build system needs to include the cpp files from # headers but the user must manually include moc # files from sources. -q5maninclude = executable('q5maninclude', +q5maninclude = qt5.executable('q5maninclude', sources : 'manualinclude.cpp', moc_sources : 'mocinclude.cpp', moc_headers : 'manualinclude.h', |