From aa3480dabaaf8fe164ae9fa5115cc092277245f5 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 16 Mar 2017 20:33:50 +0530 Subject: [PATCH] Reduce an indent level in the install for loop if not t.should_install(): continue No logic changes at all. Also improve the message when erroring out about insufficient install_dir: list elements. --- mesonbuild/backend/ninjabackend.py | 156 +++++++++++++++-------------- 1 file changed, 79 insertions(+), 77 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 464cdcb0c..9378a564e 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -628,85 +628,87 @@ int dummy; def generate_target_install(self, d): for t in self.build.get_targets().values(): - if t.should_install(): + if not t.should_install(): + continue + # Find the installation directory. + outdirs = t.get_custom_install_dir() + custom_install_dir = False + if outdirs[0] is not None and outdirs[0] is not True: + # Either the value is set, or is set to False which means + # we want this specific output out of many outputs to not + # be installed. + custom_install_dir = True + elif isinstance(t, build.SharedLibrary): + outdirs[0] = self.environment.get_shared_lib_dir() + elif isinstance(t, build.StaticLibrary): + outdirs[0] = self.environment.get_static_lib_dir() + elif isinstance(t, build.Executable): + outdirs[0] = self.environment.get_bindir() + else: + assert(isinstance(t, build.BuildTarget)) + # XXX: Add BuildTarget-specific install dir cases here + outdirs[0] = self.environment.get_libdir() + # 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: + m = 'Target {!r} has {} outputs: {!r}, but only {} "install_dir"s were found.\n' \ + "Pass 'false' for outputs that should not be installed and 'true' for\n" \ + 'using the default installation directory for an output.' + raise MesonException(m.format(t.name, num_out, t.get_outputs(), num_outdirs)) + # Install the target output(s) + if isinstance(t, build.BuildTarget): should_strip = self.get_option_for_target('strip', t) - # Find the installation directory. - outdirs = t.get_custom_install_dir() - custom_install_dir = False - if outdirs[0] is not None and outdirs[0] is not True: - # Either the value is set, or is set to False which means - # we want this specific output out of many outputs to not - # be installed. - custom_install_dir = True - elif isinstance(t, build.SharedLibrary): - outdirs[0] = self.environment.get_shared_lib_dir() - elif isinstance(t, build.StaticLibrary): - outdirs[0] = self.environment.get_static_lib_dir() - elif isinstance(t, build.Executable): - outdirs[0] = self.environment.get_bindir() - else: - assert(isinstance(t, build.BuildTarget)) - # XXX: Add BuildTarget-specific install dir cases here - outdirs[0] = self.environment.get_libdir() - # 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: - raise MesonException('Target {!r} has {} outputs, but only ' - '{} "install_dir"s were specified' - ''.format(t.name, num_out, num_outdirs)) - # Install the target output(s) - if isinstance(t, build.BuildTarget): - # Install primary build output (library/executable/jar, etc) - # Done separately because of strip/aliases/rpath - if outdirs[0] is not False: - i = [self.get_target_filename(t), outdirs[0], - t.get_aliases(), should_strip, t.install_rpath] + # Install primary build output (library/executable/jar, etc) + # Done separately because of strip/aliases/rpath + if outdirs[0] is not False: + i = [self.get_target_filename(t), outdirs[0], + t.get_aliases(), should_strip, t.install_rpath] + d.targets.append(i) + # On toolchains/platforms that use an import library for + # linking (separate from the shared library with all the + # code), we need to install that too (dll.a/.lib). + if isinstance(t, build.SharedLibrary) and t.get_import_filename(): + if custom_install_dir: + # If the DLL is installed into a custom directory, + # install the import library into the same place so + # it doesn't go into a surprising place + implib_install_dir = outdirs[0] + else: + implib_install_dir = self.environment.get_import_lib_dir() + # Install the import library. + i = [self.get_target_filename_for_linking(t), + implib_install_dir, + # It has no aliases, should not be stripped, and + # doesn't have an install_rpath + {}, False, ''] d.targets.append(i) - # On toolchains/platforms that use an import library for - # linking (separate from the shared library with all the - # code), we need to install that too (dll.a/.lib). - if isinstance(t, build.SharedLibrary) and t.get_import_filename(): - if custom_install_dir: - # If the DLL is installed into a custom directory, - # install the import library into the same place so - # it doesn't go into a surprising place - implib_install_dir = outdirs[0] - else: - implib_install_dir = self.environment.get_import_lib_dir() - # Install the import library. - i = [self.get_target_filename_for_linking(t), - implib_install_dir, - # It has no aliases, should not be stripped, and - # doesn't have an install_rpath - {}, False, ''] - d.targets.append(i) - # Install secondary outputs. Only used for Vala right now. - if num_outdirs > 1: - for output, outdir in zip(t.get_outputs()[1:], outdirs[1:]): - # User requested that we not install this output - if outdir is False: - continue - f = os.path.join(self.get_target_dir(t), output) - d.targets.append([f, outdir, {}, False, None]) - elif isinstance(t, build.CustomTarget): - # If only one install_dir is specified, assume that all - # outputs will be installed into it. This is for - # backwards-compatibility and because it makes sense to - # avoid repetition since this is a common use-case. - # - # To selectively install only some outputs, pass `false` as - # the install_dir for the corresponding output by index - if num_outdirs == 1 and num_out > 1: - for output in t.get_outputs(): - f = os.path.join(self.get_target_dir(t), output) - d.targets.append([f, outdirs[0], {}, False, None]) - else: - for output, outdir in zip(t.get_outputs(), outdirs): - # User requested that we not install this output - if outdir is False: - continue - f = os.path.join(self.get_target_dir(t), output) - d.targets.append([f, outdir, {}, False, None]) + # Install secondary outputs. Only used for Vala right now. + if num_outdirs > 1: + for output, outdir in zip(t.get_outputs()[1:], outdirs[1:]): + # User requested that we not install this output + if outdir is False: + continue + f = os.path.join(self.get_target_dir(t), output) + d.targets.append([f, outdir, {}, False, None]) + elif isinstance(t, build.CustomTarget): + # If only one install_dir is specified, assume that all + # outputs will be installed into it. This is for + # backwards-compatibility and because it makes sense to + # avoid repetition since this is a common use-case. + # + # To selectively install only some outputs, pass `false` as + # the install_dir for the corresponding output by index + if num_outdirs == 1 and num_out > 1: + for output in t.get_outputs(): + f = os.path.join(self.get_target_dir(t), output) + d.targets.append([f, outdirs[0], {}, False, None]) + else: + for output, outdir in zip(t.get_outputs(), outdirs): + # User requested that we not install this output + if outdir is False: + continue + f = os.path.join(self.get_target_dir(t), output) + d.targets.append([f, outdir, {}, False, None]) def generate_custom_install_script(self, d): d.install_scripts = self.build.install_scripts