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.
This commit is contained in:
parent
07800e29c9
commit
c38544a6ec
|
@ -970,33 +970,6 @@ class Backend:
|
|||
with open(install_data_file, 'wb') as 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):
|
||||
'''
|
||||
On macOS, we need to change the install names of all built libraries
|
||||
|
@ -1015,7 +988,7 @@ class Backend:
|
|||
if old in result:
|
||||
continue
|
||||
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)
|
||||
result.update({old: new})
|
||||
return result
|
||||
|
@ -1024,7 +997,7 @@ class Backend:
|
|||
for t in self.build.get_targets().values():
|
||||
if not t.should_install():
|
||||
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
|
||||
num_outdirs, num_out = len(outdirs), len(t.get_outputs())
|
||||
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.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):
|
||||
return self.name
|
||||
|
||||
|
@ -686,6 +700,9 @@ class BuildTarget(Target):
|
|||
result.update(i.get_link_dep_subdirs())
|
||||
return result
|
||||
|
||||
def get_default_install_dir(self, environment):
|
||||
return environment.get_libdir()
|
||||
|
||||
def get_custom_install_dir(self):
|
||||
return self.install_dir
|
||||
|
||||
|
@ -1323,6 +1340,9 @@ class Executable(BuildTarget):
|
|||
# Only linkwithable if using export_dynamic
|
||||
self.is_linkwithable = self.export_dynamic
|
||||
|
||||
def get_default_install_dir(self, environment):
|
||||
return environment.get_bindir()
|
||||
|
||||
def description(self):
|
||||
'''Human friendly description of the executable'''
|
||||
return self.name
|
||||
|
@ -1384,6 +1404,9 @@ class StaticLibrary(BuildTarget):
|
|||
self.filename = self.prefix + self.name + '.' + self.suffix
|
||||
self.outputs = [self.filename]
|
||||
|
||||
def get_default_install_dir(self, environment):
|
||||
return environment.get_static_lib_dir()
|
||||
|
||||
def type_suffix(self):
|
||||
return "@sta"
|
||||
|
||||
|
@ -1430,6 +1453,9 @@ class SharedLibrary(BuildTarget):
|
|||
self.basic_filename_tpl = '{0.prefix}{0.name}.{0.suffix}'
|
||||
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):
|
||||
"""
|
||||
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.')
|
||||
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):
|
||||
known_kwargs = set([
|
||||
'input',
|
||||
|
@ -1738,6 +1768,9 @@ class CustomTarget(Target):
|
|||
mlog.warning('Unknown keyword arguments in target %s: %s' %
|
||||
(self.name, ', '.join(unknowns)))
|
||||
|
||||
def get_default_install_dir(self, environment):
|
||||
return None
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.get_id() < other.get_id()
|
||||
|
||||
|
|
Loading…
Reference in New Issue