Refactored builtin options to a dictionary and created a new default library target type.

pull/303/head
Jussi Pakkanen 9 years ago
parent e96a31cce4
commit e2313b85d7
  1. 19
      backends.py
  2. 71
      coredata.py
  3. 12
      environment.py
  4. 15
      interpreter.py
  5. 2
      meson.py
  6. 60
      mesonconf.py
  7. 28
      ninjabackend.py
  8. 8
      test cases/common/96 default library/ef.cpp
  9. 11
      test cases/common/96 default library/ef.h
  10. 14
      test cases/common/96 default library/eftest.cpp
  11. 5
      test cases/common/96 default library/meson.build

@ -68,7 +68,7 @@ class Backend():
return filename
def get_target_dir(self, target):
if self.environment.coredata.layout == 'mirror':
if self.environment.coredata.get_builtin_option('layout') == 'mirror':
dirname = target.get_subdir()
else:
dirname = 'meson-out'
@ -208,16 +208,16 @@ class Backend():
def generate_basic_compiler_args(self, target, compiler):
commands = []
commands += compiler.get_always_args()
if self.environment.coredata.buildtype != 'plain':
commands += compiler.get_warn_args(self.environment.coredata.warning_level)
if self.environment.coredata.get_builtin_option('buildtype') != 'plain':
commands += compiler.get_warn_args(self.environment.coredata.get_builtin_option('warning_level'))
commands += compiler.get_option_compile_args(self.environment.coredata.compiler_options)
commands += self.build.get_global_args(compiler)
commands += self.environment.coredata.external_args[compiler.get_language()]
commands += target.get_extra_args(compiler.get_language())
commands += compiler.get_buildtype_args(self.environment.coredata.buildtype)
if self.environment.coredata.coverage:
commands += compiler.get_buildtype_args(self.environment.coredata.get_builtin_option('buildtype'))
if self.environment.coredata.get_builtin_option('coverage'):
commands += compiler.get_coverage_args()
if self.environment.coredata.werror:
if self.environment.coredata.get_builtin_option('werror'):
commands += compiler.get_werror_args()
if isinstance(target, build.SharedLibrary):
commands += compiler.get_pic_args()
@ -302,9 +302,10 @@ class Backend():
outdir = self.environment.scratch_dir
fname = os.path.join(outdir, p.filebase + '.pc')
ofile = open(fname, 'w')
ofile.write('prefix=%s\n' % self.environment.get_coredata().prefix)
ofile.write('libdir=${prefix}/%s\n' % self.environment.get_coredata().libdir)
ofile.write('includedir=${prefix}/%s\n\n' % self.environment.get_coredata().includedir)
coredata = self.environment.get_coredata()
ofile.write('prefix=%s\n' % coredata.get_builtin_option('prefix'))
ofile.write('libdir=${prefix}/%s\n' % coredata.get_builtin_option('libdir'))
ofile.write('includedir=${prefix}/%s\n\n' % coredata.get_builtin_option('includedir'))
ofile.write('Name: %s\n' % p.name)
if len(p.description) > 0:
ofile.write('Description: %s\n' % p.description)

@ -44,22 +44,8 @@ class CoreData():
self.test_guid = str(uuid.uuid4()).upper()
self.target_guids = {}
self.version = version
self.prefix = options.prefix
self.libdir = options.libdir
self.bindir = options.bindir
self.includedir = options.includedir
self.datadir = options.datadir
self.mandir = options.mandir
self.localedir = options.localedir
self.backend = options.backend
self.buildtype = options.buildtype
self.strip = options.strip
self.use_pch = options.use_pch
self.unity = options.unity
self.coverage = options.coverage
self.warning_level = options.warning_level
self.werror = options.werror
self.layout = options.layout
self.builtin_options = {}
self.init_builtins(options)
self.user_options = {}
self.compiler_options = {}
self.external_args = {} # These are set from "the outside" with e.g. mesonconf
@ -76,35 +62,36 @@ class CoreData():
self.ext_libs = {}
self.modules = {}
def init_builtins(self, options):
self.builtin_options['prefix'] = options.prefix
self.builtin_options['libdir'] = options.libdir
self.builtin_options['bindir'] = options.bindir
self.builtin_options['includedir'] = options.includedir
self.builtin_options['datadir'] = options.datadir
self.builtin_options['mandir'] = options.mandir
self.builtin_options['localedir'] = options.localedir
self.builtin_options['backend'] = options.backend
self.builtin_options['buildtype'] = options.buildtype
self.builtin_options['strip'] = options.strip
self.builtin_options['use_pch'] = options.use_pch
self.builtin_options['unity'] = options.unity
self.builtin_options['coverage'] = options.coverage
self.builtin_options['warning_level'] = options.warning_level
self.builtin_options['werror'] = options.werror
self.builtin_options['layout'] = options.layout
self.builtin_options['default_library'] = options.default_library
def get_builtin_option(self, optname):
if optname == 'buildtype':
return self.buildtype
if optname == 'strip':
return self.strip
if optname == 'coverage':
return self.coverage
if optname == 'pch':
return self.use_pch
if optname == 'unity':
return self.unity
if optname == 'prefix':
return self.prefix
if optname == 'libdir':
return self.libdir
if optname == 'bindir':
return self.bindir
if optname == 'includedir':
return self.includedir
if optname == 'datadir':
return self.datadir
if optname == 'mandir':
return self.mandir
if optname == 'localedir':
return self.localedir
if optname == 'layout':
return self.layout
if optname in self.builtin_options:
return self.builtin_options[optname]
raise RuntimeError('Tried to get unknown builtin option %s' % optname)
def set_builtin_option(self, optname, value):
if optname in self.builtin_options:
self.builtin_options[optname] = value
else:
raise RuntimeError('Tried to set unknown builtin option %s' % optname)
def load(filename):
obj = pickle.load(open(filename, 'rb'))
if not isinstance(obj, CoreData):

@ -543,22 +543,22 @@ class Environment():
return self.object_suffix
def get_prefix(self):
return self.coredata.prefix
return self.coredata.get_builtin_option('prefix')
def get_libdir(self):
return self.coredata.libdir
return self.coredata.get_builtin_option('libdir')
def get_bindir(self):
return self.coredata.bindir
return self.coredata.get_builtin_option('bindir')
def get_includedir(self):
return self.coredata.includedir
return self.coredata.get_builtin_option('includedir')
def get_mandir(self):
return self.coredata.mandir
return self.coredata.get_builtin_option('mandir')
def get_datadir(self):
return self.coredata.datadir
return self.coredata.get_builtin_option('datadir')
def find_library(self, libname, dirs):
if dirs is None:

@ -855,7 +855,7 @@ class MesonMain(InterpreterObject):
raise InterpreterException('Tried to access compiler for unspecified language "%s".' % cname)
def is_unity_method(self, args, kwargs):
return self.build.environment.coredata.unity
return self.build.environment.coredata.get_builtin_option('unity')
def is_subproject_method(self, args, kwargs):
return self.interpreter.is_subproject()
@ -933,6 +933,7 @@ class Interpreter():
'dependency' : self.func_dependency,
'static_library' : self.func_static_lib,
'shared_library' : self.func_shared_lib,
'default_library' : self.func_default_library,
'jar' : self.func_jar,
'build_target': self.func_build_target,
'custom_target' : self.func_custom_target,
@ -1339,9 +1340,10 @@ class Interpreter():
if '=' not in option:
raise InterpreterException('All default options must be of type key=value.')
key, value = option.split('=', 1)
if hasattr(self.coredata, key):
builtin_options = self.coredata.builtin_options
if key in builtin_options:
if not hasattr(self.environment.cmd_line_options, value):
setattr(self.coredata, key, value)
self.coredata.set_builtin_option(key, value)
# If this was set on the command line, do not override.
else:
newoptions = [option] + self.environment.cmd_line_options.projectoptions
@ -1567,6 +1569,11 @@ class Interpreter():
def func_shared_lib(self, node, args, kwargs):
return self.build_target(node, args, kwargs, SharedLibraryHolder)
def func_default_library(self, node, args, kwargs):
if self.coredata.get_builtin_option('default_library') == 'shared':
return self.func_shared_lib(node, args, kwargs)
return self.func_static_lib(node, args, kwargs)
def func_jar(self, node, args, kwargs):
return self.build_target(node, args, kwargs, JarHolder)
@ -2009,7 +2016,7 @@ class Interpreter():
else:
obj = self.evaluate_statement(invokable)
method_name = node.name
if method_name == 'extract_objects' and self.environment.coredata.unity:
if method_name == 'extract_objects' and self.environment.coredata.get_builtin_option('unity'):
raise InterpreterException('Single object files can not be extracted in Unity builds.')
args = node.args
if isinstance(obj, mparser.StringNode):

@ -68,6 +68,8 @@ parser.add_argument('--werror', action='store_true', dest='werror', default=Fals
help='Treat warnings as errors')
parser.add_argument('--layout', choices=layouts, dest='layout', default='mirror',\
help='Build directory layout.')
parser.add_argument('--default-library', choices=['shared', 'static'], dest='default_library',
default='static', help='Default library type.')
parser.add_argument('--warnlevel', default=default_warning, dest='warning_level', choices=warning_levels,\
help='Level of compiler warnings to use (larger is more, default is %(default)s)')
parser.add_argument('--cross-file', default=None, dest='cross_file',

@ -72,52 +72,55 @@ class Conf:
if k == 'buildtype':
if v not in build_types:
raise ConfException('Invalid build type %s.' % v)
self.coredata.buildtype = v
self.coredata.set_builtin_option('buildtype', v)
elif k == 'layout':
if v not in layouts:
raise ConfException('Invalid layout type %s.' % v)
self.coredata.layout = v
self.coredata.set_builtin_option('layout', v)
elif k == 'warnlevel':
if not v in warning_levels:
raise ConfException('Invalid warning level %s.' % v)
self.coredata.warning_level = v
self.coredata.set_builtin_option('warning_level', v)
elif k == 'strip':
self.coredata.strip = self.tobool(v)
self.coredata.set_builtin_option('strip', self.tobool(v))
elif k == 'coverage':
v = self.tobool(v)
self.coredata.coverage = self.tobool(v)
self.coredata.set_builtin_option('coverage', self.tobool(v))
elif k == 'pch':
self.coredata.use_pch = self.tobool(v)
self.coredata.set_builtin_option('use_pch', self.tobool(v))
elif k == 'unity':
self.coredata.unity = self.tobool(v)
self.coredata.set_builtin_option('unity', self.tobool(v))
elif k == 'default_library':
if v != 'shared' and v != 'static':
raise ConfException('Invalid value for default_library')
self.coredata.set_builtin_option('default_library', v)
elif k == 'prefix':
if not os.path.isabs(v):
raise ConfException('Install prefix %s is not an absolute path.' % v)
self.coredata.prefix = v
self.coredata.set_builtin_option('prefix', v)
elif k == 'libdir':
if os.path.isabs(v):
raise ConfException('Library dir %s must not be an absolute path.' % v)
self.coredata.libdir = v
self.coredata.set_builtin_option('libdir', v)
elif k == 'bindir':
if os.path.isabs(v):
raise ConfException('Binary dir %s must not be an absolute path.' % v)
self.coredata.bindir = v
self.coredata.set_builtin_option('bindir',v)
elif k == 'includedir':
if os.path.isabs(v):
raise ConfException('Include dir %s must not be an absolute path.' % v)
self.coredata.includedir = v
self.coredata.set_builtin_option('includedir', v)
elif k == 'datadir':
if os.path.isabs(v):
raise ConfException('Data dir %s must not be an absolute path.' % v)
self.coredata.datadir = v
self.coredata.set_builtin_option('datadir', v)
elif k == 'mandir':
if os.path.isabs(v):
raise ConfException('Man dir %s must not be an absolute path.' % v)
self.coredata.mandir = v
self.coredata.set_builtin_option('mandir', v)
elif k == 'localedir':
if os.path.isabs(v):
raise ConfException('Locale dir %s must not be an absolute path.' % v)
self.coredata.localedir = v
self.coredata.set_builtin_option('localedir', v)
elif k in self.coredata.user_options:
tgt = self.coredata.user_options[k]
tgt.set_value(v)
@ -150,12 +153,13 @@ class Conf:
print('')
print('Core options\n')
carr = []
carr.append(['buildtype', 'Build type', self.coredata.buildtype])
carr.append(['warnlevel', 'Warning level', self.coredata.warning_level])
carr.append(['strip', 'Strip on install', self.coredata.strip])
carr.append(['coverage', 'Coverage report', self.coredata.coverage])
carr.append(['pch', 'Precompiled headers', self.coredata.use_pch])
carr.append(['unity', 'Unity build', self.coredata.unity])
carr.append(['buildtype', 'Build type', self.coredata.get_builtin_option('buildtype')])
carr.append(['warnlevel', 'Warning level', self.coredata.get_builtin_option('warning_level')])
carr.append(['strip', 'Strip on install', self.coredata.get_builtin_option('strip')])
carr.append(['coverage', 'Coverage report', self.coredata.get_builtin_option('coverage')])
carr.append(['pch', 'Precompiled headers', self.coredata.get_builtin_option('use_pch')])
carr.append(['unity', 'Unity build', self.coredata.get_builtin_option('unity')])
carr.append(['default_library', 'Default library type', self.coredata.get_builtin_option('default_library')])
self.print_aligned(carr)
print('')
print('Compiler arguments\n')
@ -179,13 +183,13 @@ class Conf:
print('')
print('Directories\n')
parr = []
parr.append(['prefix', 'Install prefix', self.coredata.prefix])
parr.append(['libdir', 'Library directory', self.coredata.libdir])
parr.append(['bindir', 'Binary directory', self.coredata.bindir])
parr.append(['includedir', 'Header directory', self.coredata.includedir])
parr.append(['datadir', 'Data directory', self.coredata.datadir])
parr.append(['mandir', 'Man page directory', self.coredata.mandir])
parr.append(['localedir', 'Locale file directory', self.coredata.localedir])
parr.append(['prefix', 'Install prefix', self.coredata.get_builtin_option('prefix')])
parr.append(['libdir', 'Library directory', self.coredata.get_builtin_option('libdir')])
parr.append(['bindir', 'Binary directory', self.coredata.get_builtin_option('bindir')])
parr.append(['includedir', 'Header directory', self.coredata.get_builtin_option('includedir')])
parr.append(['datadir', 'Data directory', self.coredata.get_builtin_option('datadir')])
parr.append(['mandir', 'Man page directory', self.coredata.get_builtin_option('mandir')])
parr.append(['localedir', 'Locale file directory', self.coredata.get_builtin_option('localedir')])
self.print_aligned(parr)
print('')
if len(self.coredata.user_options) == 0:

@ -150,7 +150,7 @@ class NinjaBackend(backends.Backend):
self.generate_tests(outfile)
outfile.write('# Install rules\n\n')
self.generate_install(outfile)
if self.environment.coredata.coverage:
if self.environment.coredata.get_builtin_option('coverage'):
outfile.write('# Coverage rules\n\n')
self.generate_coverage_rules(outfile)
outfile.write('# Suffix\n\n')
@ -203,8 +203,8 @@ class NinjaBackend(backends.Backend):
self.generate_custom_generator_rules(target, outfile)
outname = self.get_target_filename(target)
obj_list = []
use_pch = self.environment.coredata.use_pch
is_unity = self.environment.coredata.unity
use_pch = self.environment.coredata.get_builtin_option('use_pch')
is_unity = self.environment.coredata.get_builtin_option('unity')
if use_pch and target.has_pch():
pch_objects = self.generate_pch(target, outfile)
else:
@ -480,14 +480,14 @@ class NinjaBackend(backends.Backend):
for lang in languages:
rel_src = os.path.join(subdir, lang + '.gmo')
src_file = os.path.join(self.environment.get_build_dir(), rel_src)
d.po.append((src_file, self.environment.coredata.localedir, lang))
d.po.append((src_file, self.environment.coredata.get_builtin_option('localedir'), lang))
elem.add_dep(rel_src)
def generate_target_install(self, d):
libdir = self.environment.get_libdir()
bindir = self.environment.get_bindir()
should_strip = self.environment.coredata.strip
should_strip = self.environment.coredata.get_builtin_option('strip')
for t in self.build.get_targets().values():
if t.should_install():
outdir = t.get_custom_install_dir()
@ -501,7 +501,7 @@ class NinjaBackend(backends.Backend):
d.targets.append(i)
def generate_pkgconfig_install(self, d):
pkgroot = os.path.join(self.environment.coredata.libdir, 'pkgconfig')
pkgroot = os.path.join(self.environment.coredata.get_builtin_option('libdir'), 'pkgconfig')
for p in self.build.pkgconfig_gens:
pcfile = p.filebase + '.pc'
@ -683,7 +683,7 @@ class NinjaBackend(backends.Backend):
return (args, deps)
def generate_cs_target(self, target, outfile):
buildtype = self.environment.coredata.buildtype
buildtype = self.environment.coredata.get_builtin_option('buildtype')
fname = target.get_filename()
outname_rel = os.path.join(self.get_target_dir(target), fname)
src_list = target.get_sources()
@ -719,7 +719,7 @@ class NinjaBackend(backends.Backend):
def generate_single_java_compile(self, src, target, compiler, outfile):
args = []
args += compiler.get_buildtype_args(self.environment.coredata.buildtype)
args += compiler.get_buildtype_args(self.environment.coredata.get_builtin_option('buildtype'))
args += compiler.get_output_args(self.get_target_private_dir(target))
rel_src = src.rel_to_builddir(self.build_to_src)
plain_class_path = src.fname[:-4] + 'class'
@ -789,7 +789,7 @@ class NinjaBackend(backends.Backend):
relsc = os.path.join(self.get_target_private_dir_abs(target), sc)
rel_s = s.rel_to_builddir(self.build_to_src)
args += ['--deps', relsc + '.d']
if self.environment.coredata.werror:
if self.environment.coredata.get_builtin_option('werror'):
args += valac.get_werror_args()
for d in target.external_deps:
if isinstance(d, dependencies.PkgConfigDependency):
@ -1293,7 +1293,7 @@ rule FORTRAN_DEP_HACK
rel_obj = os.path.join(self.get_target_private_dir(target), obj_basename)
rel_obj += '.' + self.environment.get_object_suffix()
dep_file = rel_obj + '.' + compiler.get_depfile_suffix()
if self.environment.coredata.use_pch:
if self.environment.coredata.get_builtin_option('use_pch'):
pchlist = target.get_pch(compiler.language)
else:
pchlist = []
@ -1323,7 +1323,7 @@ rule FORTRAN_DEP_HACK
custom_target_include_dirs.append(idir)
for i in custom_target_include_dirs:
commands+= compiler.get_include_args(i)
if self.environment.coredata.use_pch:
if self.environment.coredata.get_builtin_option('use_pch'):
commands += self.get_pch_include_args(compiler, target)
crstr = ''
if target.is_cross:
@ -1458,7 +1458,7 @@ rule FORTRAN_DEP_HACK
abspath = os.path.join(self.environment.get_build_dir(), target.subdir)
commands = []
commands += linker.get_linker_always_args()
commands += linker.get_buildtype_linker_args(self.environment.coredata.buildtype)
commands += linker.get_buildtype_linker_args(self.environment.coredata.get_builtin_option('buildtype'))
commands += linker.get_option_link_args(self.environment.coredata.compiler_options)
if not(isinstance(target, build.StaticLibrary)):
commands += self.environment.coredata.external_link_args[linker.get_language()]
@ -1498,7 +1498,7 @@ rule FORTRAN_DEP_HACK
commands += dep.get_link_args()
commands += linker.build_rpath_args(self.environment.get_build_dir(),\
self.determine_rpath_dirs(target), target.install_rpath)
if self.environment.coredata.coverage:
if self.environment.coredata.get_builtin_option('coverage'):
commands += linker.get_coverage_link_args()
commands += extra_args
dep_targets = [self.get_dependency_filename(t) for t in dependencies]
@ -1603,7 +1603,7 @@ rule FORTRAN_DEP_HACK
elem = NinjaBuildElement('clean', 'CUSTOM_COMMAND', 'PHONY')
elem.add_item('COMMAND', [ninja_command, '-t', 'clean'])
elem.add_item('description', 'Cleaning')
if self.environment.coredata.coverage:
if self.environment.coredata.get_builtin_option('coverage'):
self.generate_gcov_clean(outfile)
elem.add_dep('clean-gcda')
elem.add_dep('clean-gcno')

@ -0,0 +1,8 @@
#include"ef.h"
Ef::Ef() : x(99) {
}
int Ef::get_x() const {
return x;
}

@ -0,0 +1,11 @@
#pragma once
class Ef {
private:
int x;
public:
Ef();
int get_x() const;
};

@ -0,0 +1,14 @@
#include"ef.h"
#include<iostream>
int main(int, char **) {
Ef var;
if(var.get_x() == 99) {
std::cout << "All is fine.\n";
return 0;
} else {
std::cout << "Something went wrong.\n";
return 1;
}
}

@ -0,0 +1,5 @@
project('default library', 'cpp')
flib = default_library('ef', 'ef.cpp')
exe = executable('eftest', 'eftest.cpp', link_with : flib)
test('eftest', exe)
Loading…
Cancel
Save