Major refactoring to move Qt5 from core into a module. Rules are written but moc/uic/rrc are not generated yet.

pull/54/merge
Jussi Pakkanen 10 years ago
parent 3f46cd7fb3
commit 6e6ac02eaf
  1. 7
      build.py
  2. 21
      dependencies.py
  3. 48
      interpreter.py
  4. 13
      modules/gnome.py
  5. 12
      modules/modtest.py
  6. 121
      modules/qt5.py
  7. 15
      ninjabackend.py
  8. 7
      test cases/frameworks/4 qt5/meson.build

@ -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:

@ -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.

@ -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

@ -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,7 +20,11 @@ import os
import subprocess
from coredata import MesonException
def compile_resources(state, args, kwargs):
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'))
@ -38,7 +42,7 @@ def compile_resources(state, args, kwargs):
target_h = build.CustomTarget(args[0] + '_h', state.subdir, kwargs)
return [target_c, target_h]
def generate_gir(state, args, kwargs):
def generate_gir(self, state, args, kwargs):
if len(args) != 1:
raise MesonException('Gir takes one argument')
girtarget = args[0]
@ -69,3 +73,6 @@ def generate_gir(state, args, kwargs):
kwargs['command'] = typelib_cmd
typelib_target = build.CustomTarget(typelib_name, state.subdir, kwargs)
return [scan_target, typelib_target]
def initialize():
return GnomeModule()

@ -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):
class TestModule:
def get_rules(self):
return []
def print_hello(self, state, args, kwargs):
print('Hello from a Meson module')
def initialize():
return TestModule()

@ -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()

@ -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')

@ -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',

Loading…
Cancel
Save