Use get_option_for_target for builtins where sensible.

pull/1457/head
Jussi Pakkanen 8 years ago
parent 294abe244f
commit cf97c7af81
  1. 16
      mesonbuild/backend/backends.py
  2. 14
      mesonbuild/backend/ninjabackend.py
  3. 6
      mesonbuild/backend/vs2010backend.py
  4. 25
      mesonbuild/build.py

@ -107,7 +107,7 @@ class Backend:
if option_name in target.option_overrides: if option_name in target.option_overrides:
override = target.option_overrides[option_name] override = target.option_overrides[option_name]
return self.environment.coredata.validate_option_value(option_name, override) 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): def get_target_filename_for_linking(self, target):
# On some platforms (msvc for instance), the file that is used for # On some platforms (msvc for instance), the file that is used for
@ -194,7 +194,7 @@ class Backend:
elif isinstance(obj, mesonlib.File): elif isinstance(obj, mesonlib.File):
obj_list.append(obj.rel_to_builddir(self.build_to_src)) obj_list.append(obj.rel_to_builddir(self.build_to_src))
elif isinstance(obj, build.ExtractedObjects): 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: else:
raise MesonException('Unknown data type in object list.') raise MesonException('Unknown data type in object list.')
return obj_list return obj_list
@ -279,13 +279,13 @@ class Backend:
source = os.path.join(self.get_target_private_dir(target), source[:-5] + '.c') source = os.path.join(self.get_target_private_dir(target), source[:-5] + '.c')
return source.replace('/', '_').replace('\\', '_') + '.' + self.environment.get_object_suffix() 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 = [] result = []
targetdir = self.get_target_private_dir(extobj.target) targetdir = self.get_target_private_dir(extobj.target)
# With unity builds, there's just one object that contains all the # With unity builds, there's just one object that contains all the
# sources, and we only support extracting all the objects in this mode, # sources, and we only support extracting all the objects in this mode,
# so just return that. # 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(), comp = get_compiler_for_source(extobj.target.compilers.values(),
extobj.srclist[0]) extobj.srclist[0])
# There is a potential conflict here, but it is unlikely that # 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) # we weren't explicitly asked to not emit warnings (for Vala, f.ex)
if no_warn_args: if no_warn_args:
commands += compiler.get_no_warn_args() commands += compiler.get_no_warn_args()
elif self.environment.coredata.get_builtin_option('buildtype') != 'plain': elif self.get_option_for_target('buildtype', target) != 'plain':
commands += compiler.get_warn_args(self.environment.coredata.get_builtin_option('warning_level')) 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 # 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 # 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 # 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(). # 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() commands += compiler.get_werror_args()
# Add compile args for c_* or cpp_* build options set on the # Add compile args for c_* or cpp_* build options set on the
# command-line or default_options inside project(). # command-line or default_options inside project().
commands += compiler.get_option_compile_args(self.environment.coredata.compiler_options) commands += compiler.get_option_compile_args(self.environment.coredata.compiler_options)
# Add buildtype args: optimization level, debugging, etc. # 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() # Add compile args added using add_project_arguments()
commands += self.build.get_project_args(compiler, target.subproject) commands += self.build.get_project_args(compiler, target.subproject)
# Add compile args added using add_global_arguments() # Add compile args added using add_global_arguments()

@ -627,9 +627,9 @@ int dummy;
pickle.dump(d, ofile) pickle.dump(d, ofile)
def generate_target_install(self, d): def generate_target_install(self, d):
should_strip = self.environment.coredata.get_builtin_option('strip')
for t in self.build.get_targets().values(): for t in self.build.get_targets().values():
if t.should_install(): if t.should_install():
should_strip = self.get_option_for_target('strip', t)
# Find the installation directory. FIXME: Currently only one # Find the installation directory. FIXME: Currently only one
# installation directory is supported for each target # installation directory is supported for each target
outdir = t.get_custom_install_dir() outdir = t.get_custom_install_dir()
@ -843,7 +843,7 @@ int dummy;
return args, deps return args, deps
def generate_cs_target(self, target, outfile): 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() fname = target.get_filename()
outname_rel = os.path.join(self.get_target_dir(target), fname) outname_rel = os.path.join(self.get_target_dir(target), fname)
src_list = target.get_sources() src_list = target.get_sources()
@ -877,7 +877,7 @@ int dummy;
def generate_single_java_compile(self, src, target, compiler, outfile): def generate_single_java_compile(self, src, target, compiler, outfile):
args = [] 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_global_args(compiler)
args += self.build.get_project_args(compiler, target.subproject) args += self.build.get_project_args(compiler, target.subproject)
args += target.get_java_args() args += target.get_java_args()
@ -1010,7 +1010,7 @@ int dummy;
args = [] args = []
args += self.build.get_global_args(valac) args += self.build.get_global_args(valac)
args += self.build.get_project_args(valac, target.subproject) 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 # Tell Valac to output everything in our private directory. Sadly this
# means it will also preserve the directory components of Vala sources # means it will also preserve the directory components of Vala sources
# found inside the build tree (generated 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) girname = os.path.join(self.get_target_dir(target), target.vala_gir)
args += ['--gir', os.path.join('..', target.vala_gir)] args += ['--gir', os.path.join('..', target.vala_gir)]
valac_outputs.append(girname) 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() args += valac.get_werror_args()
for d in target.get_external_deps(): for d in target.get_external_deps():
if isinstance(d, dependencies.PkgConfigDependency): if isinstance(d, dependencies.PkgConfigDependency):
@ -1088,7 +1088,7 @@ int dummy;
else: else:
raise InvalidArguments('Unknown target type for rustc.') raise InvalidArguments('Unknown target type for rustc.')
args.append(cratetype) 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') depfile = os.path.join(target.subdir, target.name + '.d')
args += ['--emit', 'dep-info={}'.format(depfile), '--emit', 'link'] args += ['--emit', 'dep-info={}'.format(depfile), '--emit', 'link']
args += ['-o', os.path.join(target.subdir, target.get_filename())] 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 # Add things like /NOLOGO; usually can't be overriden
commands += linker.get_linker_always_args() commands += linker.get_linker_always_args()
# Add buildtype linker args: optimization level, etc. # 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 # Add /DEBUG and the pdb filename when using MSVC
commands += self.get_link_debugfile_args(linker, target, outname) commands += self.get_link_debugfile_args(linker, target, outname)
# Add link args specific to this BuildTarget type, such as soname args, # Add link args specific to this BuildTarget type, such as soname args,

@ -6,7 +6,7 @@
# http://www.apache.org/licenses/LICENSE-2.0 # 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, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
@ -692,7 +692,7 @@ class Vs2010Backend(backends.Backend):
elif '/Od' in o_flags: elif '/Od' in o_flags:
ET.SubElement(type_config, 'Optimization').text = 'Disabled' ET.SubElement(type_config, 'Optimization').text = 'Disabled'
# Warning level # 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 ET.SubElement(type_config, 'WarningLevel').text = 'Level' + warning_level
# End configuration # End configuration
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.props') 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, 'MinimalRebuild').text = 'true'
ET.SubElement(clconf, 'FunctionLevelLinking').text = 'true' ET.SubElement(clconf, 'FunctionLevelLinking').text = 'true'
pch_node = ET.SubElement(clconf, 'PrecompiledHeader') 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' ET.SubElement(clconf, 'TreatWarningAsError').text = 'true'
# Note: SuppressStartupBanner is /NOLOGO and is 'true' by default # Note: SuppressStartupBanner is /NOLOGO and is 'true' by default
pch_sources = {} pch_sources = {}

@ -271,6 +271,7 @@ class Target:
self.build_by_default = build_by_default self.build_by_default = build_by_default
self.install = False self.install = False
self.build_always = False self.build_always = False
self.option_overrides = {}
def get_basename(self): def get_basename(self):
return self.name return self.name
@ -283,6 +284,20 @@ class Target:
self.build_by_default = kwargs['build_by_default'] self.build_by_default = kwargs['build_by_default']
if not isinstance(self.build_by_default, bool): if not isinstance(self.build_by_default, bool):
raise InvalidArguments('build_by_default must be a boolean value.') 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): class BuildTarget(Target):
def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs): def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs):
@ -306,7 +321,6 @@ class BuildTarget(Target):
self.extra_args = {} self.extra_args = {}
self.generated = [] self.generated = []
self.extra_files = [] self.extra_files = []
self.option_overrides = {}
# Sources can be: # Sources can be:
# 1. Pre-existing source files in the source tree # 1. Pre-existing source files in the source tree
# 2. Pre-existing sources generated by configure_file in the build 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) self.pic = kwargs.get('pic', False)
if not isinstance(self.pic, bool): if not isinstance(self.pic, bool):
raise InvalidArguments('Argument pic to static library {!r} must be boolean'.format(self.name)) 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): def get_filename(self):
return self.filename return self.filename
@ -1247,6 +1253,7 @@ class CustomTarget(Target):
'depend_files': True, 'depend_files': True,
'depfile': True, 'depfile': True,
'build_by_default': True, 'build_by_default': True,
'override_options': True,
} }
def __init__(self, name, subdir, kwargs, absolute_paths=False): def __init__(self, name, subdir, kwargs, absolute_paths=False):

Loading…
Cancel
Save