From cf97c7af813ef39a7edf0693a4b127d30ad9cc55 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 12 Mar 2017 20:05:21 +0200 Subject: [PATCH] Use get_option_for_target for builtins where sensible. --- mesonbuild/backend/backends.py | 16 ++++++++-------- mesonbuild/backend/ninjabackend.py | 14 +++++++------- mesonbuild/backend/vs2010backend.py | 6 +++--- mesonbuild/build.py | 25 ++++++++++++++++--------- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index eaef7d349..93a75ec5b 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -107,7 +107,7 @@ class Backend: if option_name in target.option_overrides: override = target.option_overrides[option_name] return self.environment.coredata.validate_option_value(option_name, override) - return self.environment.coredata.get_builtin_option('unity') + return self.environment.coredata.get_builtin_option(option_name) def get_target_filename_for_linking(self, target): # On some platforms (msvc for instance), the file that is used for @@ -194,7 +194,7 @@ class Backend: elif isinstance(obj, mesonlib.File): obj_list.append(obj.rel_to_builddir(self.build_to_src)) elif isinstance(obj, build.ExtractedObjects): - obj_list += self.determine_ext_objs(obj, proj_dir_to_build_root) + obj_list += self.determine_ext_objs(target, obj, proj_dir_to_build_root) else: raise MesonException('Unknown data type in object list.') return obj_list @@ -279,13 +279,13 @@ class Backend: source = os.path.join(self.get_target_private_dir(target), source[:-5] + '.c') return source.replace('/', '_').replace('\\', '_') + '.' + self.environment.get_object_suffix() - def determine_ext_objs(self, extobj, proj_dir_to_build_root): + def determine_ext_objs(self, target, extobj, proj_dir_to_build_root): result = [] targetdir = self.get_target_private_dir(extobj.target) # With unity builds, there's just one object that contains all the # sources, and we only support extracting all the objects in this mode, # so just return that. - if self.environment.coredata.get_builtin_option('unity'): + if self.get_option_for_target('unity', target): comp = get_compiler_for_source(extobj.target.compilers.values(), extobj.srclist[0]) # There is a potential conflict here, but it is unlikely that @@ -358,19 +358,19 @@ class Backend: # we weren't explicitly asked to not emit warnings (for Vala, f.ex) if no_warn_args: commands += compiler.get_no_warn_args() - elif self.environment.coredata.get_builtin_option('buildtype') != 'plain': - commands += compiler.get_warn_args(self.environment.coredata.get_builtin_option('warning_level')) + elif self.get_option_for_target('buildtype', target) != 'plain': + commands += compiler.get_warn_args(self.get_option_for_target('warning_level', target)) # Add -Werror if werror=true is set in the build options set on the # command-line or default_options inside project(). This only sets the # action to be done for warnings if/when they are emitted, so it's ok # to set it after get_no_warn_args() or get_warn_args(). - if self.environment.coredata.get_builtin_option('werror'): + if self.get_option_for_target('werror', target): commands += compiler.get_werror_args() # Add compile args for c_* or cpp_* build options set on the # command-line or default_options inside project(). commands += compiler.get_option_compile_args(self.environment.coredata.compiler_options) # Add buildtype args: optimization level, debugging, etc. - commands += compiler.get_buildtype_args(self.environment.coredata.get_builtin_option('buildtype')) + commands += compiler.get_buildtype_args(self.get_option_for_target('buildtype', target)) # Add compile args added using add_project_arguments() commands += self.build.get_project_args(compiler, target.subproject) # Add compile args added using add_global_arguments() diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 76492fcfa..e1e239faa 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -627,9 +627,9 @@ int dummy; pickle.dump(d, ofile) def generate_target_install(self, d): - should_strip = self.environment.coredata.get_builtin_option('strip') for t in self.build.get_targets().values(): if t.should_install(): + should_strip = self.get_option_for_target('strip', t) # Find the installation directory. FIXME: Currently only one # installation directory is supported for each target outdir = t.get_custom_install_dir() @@ -843,7 +843,7 @@ int dummy; return args, deps def generate_cs_target(self, target, outfile): - buildtype = self.environment.coredata.get_builtin_option('buildtype') + buildtype = self.get_option_for_target('buildtype', target) fname = target.get_filename() outname_rel = os.path.join(self.get_target_dir(target), fname) src_list = target.get_sources() @@ -877,7 +877,7 @@ int dummy; def generate_single_java_compile(self, src, target, compiler, outfile): args = [] - args += compiler.get_buildtype_args(self.environment.coredata.get_builtin_option('buildtype')) + args += compiler.get_buildtype_args(self.get_option_for_target('buildtype', target)) args += self.build.get_global_args(compiler) args += self.build.get_project_args(compiler, target.subproject) args += target.get_java_args() @@ -1010,7 +1010,7 @@ int dummy; args = [] args += self.build.get_global_args(valac) args += self.build.get_project_args(valac, target.subproject) - args += valac.get_buildtype_args(self.environment.coredata.get_builtin_option('buildtype')) + args += valac.get_buildtype_args(self.get_option_for_target('buildtype', target)) # Tell Valac to output everything in our private directory. Sadly this # means it will also preserve the directory components of Vala sources # found inside the build tree (generated sources). @@ -1033,7 +1033,7 @@ int dummy; girname = os.path.join(self.get_target_dir(target), target.vala_gir) args += ['--gir', os.path.join('..', target.vala_gir)] valac_outputs.append(girname) - if self.environment.coredata.get_builtin_option('werror'): + if self.get_option_for_target('werror', target): args += valac.get_werror_args() for d in target.get_external_deps(): if isinstance(d, dependencies.PkgConfigDependency): @@ -1088,7 +1088,7 @@ int dummy; else: raise InvalidArguments('Unknown target type for rustc.') args.append(cratetype) - args += rustc.get_buildtype_args(self.environment.coredata.get_builtin_option('buildtype')) + args += rustc.get_buildtype_args(self.get_option_for_target('buildtype', target)) depfile = os.path.join(target.subdir, target.name + '.d') args += ['--emit', 'dep-info={}'.format(depfile), '--emit', 'link'] args += ['-o', os.path.join(target.subdir, target.get_filename())] @@ -2149,7 +2149,7 @@ rule FORTRAN_DEP_HACK # Add things like /NOLOGO; usually can't be overriden commands += linker.get_linker_always_args() # Add buildtype linker args: optimization level, etc. - commands += linker.get_buildtype_linker_args(self.environment.coredata.get_builtin_option('buildtype')) + commands += linker.get_buildtype_linker_args(self.get_option_for_target('buildtype', target)) # Add /DEBUG and the pdb filename when using MSVC commands += self.get_link_debugfile_args(linker, target, outname) # Add link args specific to this BuildTarget type, such as soname args, diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index 902e95f28..cc44458e0 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -6,7 +6,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, software +# Unless required by applicable law or agreed to in writingget_, 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 @@ -692,7 +692,7 @@ class Vs2010Backend(backends.Backend): elif '/Od' in o_flags: ET.SubElement(type_config, 'Optimization').text = 'Disabled' # Warning level - warning_level = self.environment.coredata.get_builtin_option('warning_level') + warning_level = self.get_option_for_target('warning_level', target) ET.SubElement(type_config, 'WarningLevel').text = 'Level' + warning_level # End configuration ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.props') @@ -846,7 +846,7 @@ class Vs2010Backend(backends.Backend): ET.SubElement(clconf, 'MinimalRebuild').text = 'true' ET.SubElement(clconf, 'FunctionLevelLinking').text = 'true' pch_node = ET.SubElement(clconf, 'PrecompiledHeader') - if self.environment.coredata.get_builtin_option('werror'): + if self.get_option_for_target('werror', target): ET.SubElement(clconf, 'TreatWarningAsError').text = 'true' # Note: SuppressStartupBanner is /NOLOGO and is 'true' by default pch_sources = {} diff --git a/mesonbuild/build.py b/mesonbuild/build.py index e46b65fc7..6dc38e9af 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -271,6 +271,7 @@ class Target: self.build_by_default = build_by_default self.install = False self.build_always = False + self.option_overrides = {} def get_basename(self): return self.name @@ -283,6 +284,20 @@ class Target: self.build_by_default = kwargs['build_by_default'] if not isinstance(self.build_by_default, bool): raise InvalidArguments('build_by_default must be a boolean value.') + self.option_overrides = self.parse_overrides(kwargs) + + def parse_overrides(self, kwargs): + result = {} + overrides = stringlistify(kwargs.get('override_options', [])) + for o in overrides: + if '=' not in o: + raise InvalidArguments('Overrides must be of form "key=value"') + k, v = o.split('=', 1) + k = k.strip() + v = v.strip() + result[k] = v + return result + class BuildTarget(Target): def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs): @@ -306,7 +321,6 @@ class BuildTarget(Target): self.extra_args = {} self.generated = [] self.extra_files = [] - self.option_overrides = {} # Sources can be: # 1. Pre-existing source files in the source tree # 2. Pre-existing sources generated by configure_file in the build tree @@ -672,14 +686,6 @@ class BuildTarget(Target): self.pic = kwargs.get('pic', False) if not isinstance(self.pic, bool): raise InvalidArguments('Argument pic to static library {!r} must be boolean'.format(self.name)) - overrides = stringlistify(kwargs.get('override_options', [])) - for o in overrides: - if '=' not in o: - raise InvalidArguments('Overrides must be of form "key=value"') - k, v = o.split('=', 1) - k = k.strip() - v = v.strip() - self.option_overrides[k] = v def get_filename(self): return self.filename @@ -1247,6 +1253,7 @@ class CustomTarget(Target): 'depend_files': True, 'depfile': True, 'build_by_default': True, + 'override_options': True, } def __init__(self, name, subdir, kwargs, absolute_paths=False):