aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-03-09 17:16:32 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2015-03-09 17:16:32 +0200
commit6e6ac02eaf265c6688c528175bce71ea45549ca7 (patch)
tree4f1436e628289ac43b950be8a73c64ac5382e730 /modules
parent3f46cd7fb30e3a478c44cac565d2ae12c72a0c25 (diff)
downloadmeson-6e6ac02eaf265c6688c528175bce71ea45549ca7.zip
meson-6e6ac02eaf265c6688c528175bce71ea45549ca7.tar.gz
meson-6e6ac02eaf265c6688c528175bce71ea45549ca7.tar.bz2
Major refactoring to move Qt5 from core into a module. Rules are written but moc/uic/rrc are not generated yet.
Diffstat (limited to 'modules')
-rw-r--r--modules/gnome.py105
-rw-r--r--modules/modtest.py14
-rw-r--r--modules/qt5.py121
3 files changed, 188 insertions, 52 deletions
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()