From 7addb258b2d2cbbb84c46157a7daa8c4e59cfa34 Mon Sep 17 00:00:00 2001 From: Michael Pyne Date: Sat, 7 Jan 2012 00:26:39 -0500 Subject: [PATCH] Move install to Module and build system. Right now that just means the functionality is split between Module::install and GenericBuildSystem::installInternal but it's now at least possible in theory for e.g. the qmake build system to add the required DESTDIR= parameter to install to the right location. This has built for me just fine on a couple of modules so far, haven't been able to compile further though. --- kdesrc-build | 177 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 106 insertions(+), 71 deletions(-) diff --git a/kdesrc-build b/kdesrc-build index 3fe9cfd..c344dd2 100755 --- a/kdesrc-build +++ b/kdesrc-build @@ -2210,6 +2210,38 @@ HOME return 0; } + # Used to install a module (that has already been built, tested, etc.) + # All options passed are prefixed to the eventual command to be run. + # Returns boolean false if unable to install, true otherwise. + sub installInternal + { + my $self = shift; + my $module = $self->module(); + my @cmdPrefix = @_; + + return main::safe_make ($module, { + target => 'install', + message => "Installing g[$module]", + 'prefix-options' => [@cmdPrefix], + }) == 0; + } + + # Used to uninstall a previously installed module. + # All options passed are prefixed to the eventual command to be run. + # Returns boolean false if unable to uninstall, true otherwise. + sub uninstallInternal + { + my $self = shift; + my $module = $self->module(); + my @cmdPrefix = @_; + + return main::safe_make ($module, { + target => 'uninstall', + message => "Uninstalling g[$module]", + 'prefix-options' => [@cmdPrefix], + }) == 0; + } + # Subroutine to clean the build system for the given module. Works by # recursively deleting the directory and then recreating it. # Returns 0 for failure, non-zero for success. @@ -3086,6 +3118,76 @@ EOF return 1; } + # Responsible for installing the module (no update, build, etc.) + # Return value: Boolean flag indicating whether module installed successfully or + # not. + # Exceptions may be thrown for abnormal conditions (e.g. no build dir exists) + sub install + { + my $self = assert_isa(shift, 'Module'); + my $builddir = $self->fullpath('build'); + my $buildSysFile = $self->buildSystem()->configuredModuleFileName(); + + if (!pretending() && ! -e "$builddir/$buildSysFile") + { + warning ("\tThe build system doesn't exist for r[$self]."); + warning ("\tTherefore, we can't install it. y[:-(]."); + return 0; + } + + $self->setupEnvironment(); + + my @makeInstallOpts = split(' ', $self->getOption('make-install-prefix')); + + # We can optionally uninstall prior to installing + # to weed out old unused files. + if ($self->getOption('use-clean-install') && + $self->getPersistentOption('last-install-rev') && + !$self->buildSystem()->uninstallInternal(@makeInstallOpts)) + { + warning ("\tUnable to uninstall r[$self] before installing the new build."); + warning ("\tContinuing anyways..."); + } + + if (!$self->buildSystem()->installInternal(@makeInstallOpts)) + { + error ("\tUnable to install r[$self]!"); + $self->buildContext()->markModulePhaseFailed('install', $self); + return 0; + } + + if (pretending()) + { + pretend ("\tWould have installed g[$self]"); + next; + } + + # Past this point we know we've successfully installed, for real. + + $self->setPersistentOption('last-install-rev', $self->currentScmRevision()); + + my $remove_setting = $self->getOption('remove-after-install'); + + # Possibly remove the srcdir and builddir after install for users with + # a little bit of HD space. + if($remove_setting eq 'all') + { + # Remove srcdir + my $srcdir = $self->fullpath('source'); + note ("\tRemoving b[r[$self source]."); + safe_rmtree($srcdir); + } + + if($remove_setting eq 'builddir' || $remove_setting eq 'all') + { + # Remove builddir + note ("\tRemoving b[r[$self build directory]."); + safe_rmtree($builddir); + } + + return 1; + } + sub buildContext { my $self = shift; @@ -7304,78 +7406,11 @@ sub handle_install for my $module (@modules) { $ctx->resetEnvironment(); - $module->setupEnvironment(); - - my $builddir = $module->fullpath('build'); - my $moduleName = $module->name(); + $result = $module->install() || $result; - if (not pretending and not -e "$builddir/Makefile") - { - warning "\tThe build system doesn't exist for r[$module]."; - warning "\tTherefore, we can't install it. y[:-(]."; - next; - } - - my @makeInstallOpts = split(' ', $module->getOption('make-install-prefix')); - - # We can optionally uninstall prior to installing - # to weed out old unused files. - if ($module->getOption('use-clean-install') && - $module->getPersistentOption('last-install-rev') && - safe_make ($module, { - target => 'uninstall', - message => "Uninstalling g[$module]", - 'prefix-options' => [@makeInstallOpts], - })) - { - warning "\tUnable to uninstall r[$module] before installing the new build."; - warning "\tContinuing anyways..."; - } - - if (safe_make ($module, { - target => 'install', - message => "Installing g[$module]", - 'prefix-options' => [@makeInstallOpts], - })) - { - error "\tUnable to install r[$module]!"; - $result = 1; - $ctx->markModulePhaseFailed('install', $module); - - if ($module->getOption('stop-on-failure')) - { - note "y[Stopping here]."; - return 1; # Error - } - } - - if (pretending) - { - pretend "\tWould have installed g[$module]"; - next; - } - - next if $result != 0; # Don't delete anything if the build failed. - - $module->setPersistentOption('last-install-rev', $module->currentScmRevision()); - - my $remove_setting = $module->getOption('remove-after-install'); - - # Possibly remove the srcdir and builddir after install for users with - # a little bit of HD space. - if($remove_setting eq 'all') - { - # Remove srcdir - my $srcdir = $module->fullpath('source'); - note "\tRemoving b[r[$module source]."; - safe_rmtree($srcdir); - } - - if($remove_setting eq 'builddir' or $remove_setting eq 'all') - { - # Remove builddir - note "\tRemoving b[r[$module build directory]."; - safe_rmtree($builddir); + if ($result && $module->getOption('stop-on-failure')) { + note ("y[Stopping here]."); + return 1; # Error } }