build: move default_install_dir to the Target classes

there is a huge amount of isinstance calls, this reduces the amount of
these calls while splitting up a rather big function. It also assosiates
every target type with theire default install directory.
pull/4293/head
Marcel Hollerbach 6 years ago
parent 07800e29c9
commit c38544a6ec
  1. 31
      mesonbuild/backend/backends.py
  2. 33
      mesonbuild/build.py

@ -970,33 +970,6 @@ class Backend:
with open(install_data_file, 'wb') as ofile: with open(install_data_file, 'wb') as ofile:
pickle.dump(d, ofile) pickle.dump(d, ofile)
def get_target_install_dirs(self, t):
# Find the installation directory.
if isinstance(t, build.SharedModule):
default_install_dir = self.environment.get_shared_module_dir()
elif isinstance(t, build.SharedLibrary):
default_install_dir = self.environment.get_shared_lib_dir()
elif isinstance(t, build.StaticLibrary):
default_install_dir = self.environment.get_static_lib_dir()
elif isinstance(t, build.Executable):
default_install_dir = self.environment.get_bindir()
elif isinstance(t, build.CustomTarget):
default_install_dir = None
else:
assert(isinstance(t, build.BuildTarget))
# XXX: Add BuildTarget-specific install dir cases here
default_install_dir = self.environment.get_libdir()
outdirs = t.get_custom_install_dir()
if outdirs[0] is not None and outdirs[0] != default_install_dir and outdirs[0] is not True:
# Either the value is set to a non-default value, or is set to
# False (which means we want this specific output out of many
# outputs to not be installed).
custom_install_dir = True
else:
custom_install_dir = False
outdirs[0] = default_install_dir
return outdirs, custom_install_dir
def get_target_link_deps_mappings(self, t, prefix): def get_target_link_deps_mappings(self, t, prefix):
''' '''
On macOS, we need to change the install names of all built libraries On macOS, we need to change the install names of all built libraries
@ -1015,7 +988,7 @@ class Backend:
if old in result: if old in result:
continue continue
fname = ld.get_filename() fname = ld.get_filename()
outdirs, _ = self.get_target_install_dirs(ld) outdirs, _ = ld.get_install_dir(self.environment)
new = os.path.join(prefix, outdirs[0], fname) new = os.path.join(prefix, outdirs[0], fname)
result.update({old: new}) result.update({old: new})
return result return result
@ -1024,7 +997,7 @@ class Backend:
for t in self.build.get_targets().values(): for t in self.build.get_targets().values():
if not t.should_install(): if not t.should_install():
continue continue
outdirs, custom_install_dir = self.get_target_install_dirs(t) outdirs, custom_install_dir = t.get_install_dir(self.environment)
# Sanity-check the outputs and install_dirs # Sanity-check the outputs and install_dirs
num_outdirs, num_out = len(outdirs), len(t.get_outputs()) num_outdirs, num_out = len(outdirs), len(t.get_outputs())
if num_outdirs != 1 and num_outdirs != num_out: if num_outdirs != 1 and num_outdirs != num_out:

@ -324,6 +324,20 @@ a hard error in the future.''' % name)
self.build_always_stale = False self.build_always_stale = False
self.option_overrides = {} self.option_overrides = {}
def get_install_dir(self, environment):
# Find the installation directory.
default_install_dir = self.get_default_install_dir(environment)
outdirs = self.get_custom_install_dir()
if outdirs[0] is not None and outdirs[0] != default_install_dir and outdirs[0] is not True:
# Either the value is set to a non-default value, or is set to
# False (which means we want this specific output out of many
# outputs to not be installed).
custom_install_dir = True
else:
custom_install_dir = False
outdirs[0] = default_install_dir
return outdirs, custom_install_dir
def get_basename(self): def get_basename(self):
return self.name return self.name
@ -686,6 +700,9 @@ class BuildTarget(Target):
result.update(i.get_link_dep_subdirs()) result.update(i.get_link_dep_subdirs())
return result return result
def get_default_install_dir(self, environment):
return environment.get_libdir()
def get_custom_install_dir(self): def get_custom_install_dir(self):
return self.install_dir return self.install_dir
@ -1323,6 +1340,9 @@ class Executable(BuildTarget):
# Only linkwithable if using export_dynamic # Only linkwithable if using export_dynamic
self.is_linkwithable = self.export_dynamic self.is_linkwithable = self.export_dynamic
def get_default_install_dir(self, environment):
return environment.get_bindir()
def description(self): def description(self):
'''Human friendly description of the executable''' '''Human friendly description of the executable'''
return self.name return self.name
@ -1384,6 +1404,9 @@ class StaticLibrary(BuildTarget):
self.filename = self.prefix + self.name + '.' + self.suffix self.filename = self.prefix + self.name + '.' + self.suffix
self.outputs = [self.filename] self.outputs = [self.filename]
def get_default_install_dir(self, environment):
return environment.get_static_lib_dir()
def type_suffix(self): def type_suffix(self):
return "@sta" return "@sta"
@ -1430,6 +1453,9 @@ class SharedLibrary(BuildTarget):
self.basic_filename_tpl = '{0.prefix}{0.name}.{0.suffix}' self.basic_filename_tpl = '{0.prefix}{0.name}.{0.suffix}'
self.determine_filenames(is_cross, environment) self.determine_filenames(is_cross, environment)
def get_default_install_dir(self, environment):
return environment.get_shared_lib_dir()
def determine_filenames(self, is_cross, env): def determine_filenames(self, is_cross, env):
""" """
See https://github.com/mesonbuild/meson/pull/417 for details. See https://github.com/mesonbuild/meson/pull/417 for details.
@ -1701,6 +1727,10 @@ class SharedModule(SharedLibrary):
raise MesonException('Shared modules must not specify the soversion kwarg.') raise MesonException('Shared modules must not specify the soversion kwarg.')
super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs) super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs)
def get_default_install_dir(self, environment):
return environment.get_shared_module_dir()
class CustomTarget(Target): class CustomTarget(Target):
known_kwargs = set([ known_kwargs = set([
'input', 'input',
@ -1738,6 +1768,9 @@ class CustomTarget(Target):
mlog.warning('Unknown keyword arguments in target %s: %s' % mlog.warning('Unknown keyword arguments in target %s: %s' %
(self.name, ', '.join(unknowns))) (self.name, ', '.join(unknowns)))
def get_default_install_dir(self, environment):
return None
def __lt__(self, other): def __lt__(self, other):
return self.get_id() < other.get_id() return self.get_id() < other.get_id()

Loading…
Cancel
Save