diff --git a/kdesrc-build b/kdesrc-build index 93e5545..b02ce43 100755 --- a/kdesrc-build +++ b/kdesrc-build @@ -927,226 +927,6 @@ EOM } # }}} -# package l10nSystem {{{ -{ - package l10nSystem; - - use ksb::Debug; - use ksb::Util; - use ksb::Updater::Svn; - use ksb::BuildSystem; - - our @ISA = ('ksb::Updater::Svn', 'ksb::BuildSystem'); - - sub new - { - my ($class, $module) = @_; - - # Ensure associated module updates from the proper svn path. - # TODO: Support different localization branches? - - $module->setOption('module-base-path', 'trunk/l10n-kde4'); - return bless { module => $module, needsRefreshed => 1 }, $class; - } - - sub module - { - my $self = shift; - return $self->{module}; - } - - sub configuredModuleFileName - { - # Not quite correct (we should be looking at each individual language - # but it at least keeps the process going. - return 'teamnames'; - } - - # Sets the directories that are to be checked out/built/etc. - # There should be one l10nSystem for the entire l10n build (i.e. add - # all required support dirs and languages). - sub setLanguageDirs - { - my ($self, @languageDirs) = @_; - $self->{l10n_dirs} = \@languageDirs; - } - - # Returns true if the given subdirectory (reference from the module's root source directory) - # can be built or not. Should be reimplemented by subclasses as appropriate. - sub isSubdirBuildable - { - my ($self, $subdir) = @_; - return ($subdir ne 'scripts' && $subdir ne 'templates'); - } - - sub prefixEnvironmentVariable - { - return 'CMAKE_PREFIX_PATH'; - } - - # scm-specific update procedure. - # May change the current directory as necessary. - sub updateInternal - { - my $self = assert_isa(shift, 'ksb::Updater'); - my $module = $self->module(); - my $fullpath = $module->fullpath('source'); - my @dirs = @{$self->{l10n_dirs}}; - - if (-e "$fullpath/.svn") { - $self->check_module_validity(); - my $count = $self->update_module_path(@dirs); - - $self->{needsRefreshed} = 0 if $count == 0; - return $count; - } - else { - return $self->checkout_module_path(@dirs); - } - } - - sub name - { - return 'l10n'; - } - - # Returns a list of just the languages to install. - sub languages - { - my $self = assert_isa(shift, 'l10nSystem'); - my @langs = @{$self->{l10n_dirs}}; - - return grep { $self->isSubdirBuildable($_); } (@langs); - } - - # Buildsystem support section - - sub needsRefreshed - { - my $self = shift; - - # Should be 1 except if no update happened. - return $self->{needsRefreshed}; - } - - sub buildInternal - { - my $self = assert_isa(shift, 'l10nSystem'); - my $builddir = $self->module()->fullpath('build'); - my @langs = $self->languages(); - my $result = 0; - - $result = ($self->safe_make({ - target => undef, - message => "Building localization for language...", - logbase => "build", - subdirs => \@langs, - }) == 0) || $result; - - return $result; - } - - sub configureInternal - { - my $self = assert_isa(shift, 'l10nSystem'); - - my $builddir = $self->module()->fullpath('build'); - my @langs = $self->languages(); - my $result = 0; - - for my $lang (@langs) { - my $prefix = $self->module()->installationPath(); - p_chdir("$builddir/$lang"); - - info ("\tConfiguring to build language $lang"); - $result = (log_command($self->module(), "cmake-$lang", - ['cmake', '-DCMAKE_INSTALL_PREFIX=' . $prefix]) == 0) || $result; - } - - return $result; - } - - sub installInternal - { - my $self = assert_isa(shift, 'l10nSystem'); - my $builddir = $self->module()->fullpath('build'); - my @langs = $self->languages(); - - return ($self->safe_make({ - target => 'install', - message => "Installing language...", - logbase => "install", - subdirs => \@langs, - }) == 0); - } - - # Subroutine to link a source directory into an alternate directory in - # order to fake srcdir != builddir for modules that don't natively support - # it. The first parameter is the module to prepare. - # - # The return value is true (non-zero) if it succeeded, and 0 (false) if it - # failed. - # - # On return from the subroutine the current directory will be in the build - # directory, since that's the only directory you should touch from then on. - sub prepareFakeBuilddir - { - my $self = assert_isa(shift, 'l10nSystem'); - my $module = $self->module(); - my $builddir = $module->fullpath('build'); - my $srcdir = $module->fullpath('source'); - - # List reference, not a real list. The initial kdesrc-build does *NOT* - # fork another kdesrc-build using exec, see sub log_command() for more - # info. - my $args = [ 'kdesrc-build', 'main::safe_lndir', $srcdir, $builddir ]; - - info ("\tSetting up alternate build directory for l10n"); - return (0 == log_command ($module, 'create-builddir', $args)); - } - - # Subroutine to create the build system for a module. This involves making - # sure the directory exists and then running any preparatory steps (like - # for l10n modules). This subroutine assumes that the module is already - # downloaded. - # - # Return convention: boolean (inherited) - sub createBuildSystem - { - my $self = assert_isa(shift, 'l10nSystem'); - my $module = $self->module(); - my $builddir = $module->fullpath('build'); - - # l10n doesn't support srcdir != builddir, fake it. - whisper ("\tFaking builddir for g[$module]"); - if (!$self->prepareFakeBuilddir()) - { - error ("Error creating r[$module] build system!"); - return 0; - } - - p_chdir ($builddir); - - my @langs = @{$self->{l10n_dirs}}; - @langs = grep { $self->isSubdirBuildable($_) } (@langs); - - foreach my $lang (@langs) { - my $cmd_ref = [ './scripts/autogen.sh', $lang ]; - if (log_command ($module, "build-system-$lang", $cmd_ref)) - { - error ("\tUnable to create build system for r[$module]"); - } - } - - $module->setOption('#reconfigure', 1); # Force reconfigure of the module - - return 1; - } - - 1; -} -# }}} - # package Module {{{ { package Module; @@ -1155,6 +935,8 @@ EOM use ksb::Debug; use ksb::Util; + use ksb::l10nSystem; + use ksb::Updater::Svn; use ksb::Updater::Git; use ksb::Updater::Bzr; @@ -1348,7 +1130,7 @@ EOF when('git') { $newType = ksb::Updater::Git->new($self); } when('proj') { $newType = ksb::Updater::KDEProject->new($self); } when('metadata') { $newType = ksb::Updater::KDEProjectMetadata->new($self); } - when('l10n') { $newType = l10nSystem->new($self); } + when('l10n') { $newType = ksb::l10nSystem->new($self); } when('svn') { $newType = ksb::Updater::Svn->new($self); } when('bzr') { $newType = ksb::Updater::Bzr->new($self); } default { $newType = undef; } diff --git a/kdesrc-build-test.pl b/kdesrc-build-test.pl index bd60d54..27778ee 100755 --- a/kdesrc-build-test.pl +++ b/kdesrc-build-test.pl @@ -39,6 +39,7 @@ use File::Temp 'tempdir'; use Storable 'dclone'; use File::Copy; use ksb::BuildSystem::QMake; +use ksb::l10nSystem; # From kdesrc-build our %ENV_VARS; @@ -505,7 +506,7 @@ ok ($buildSystem->isSubdirBuildable('meh'), 'generic-build isSubdirBuildable'); ok ($buildSystem->createBuildSystem(), 'Ensure createBuildSystem can be called'); ok ($buildSystem->cleanBuildSystem(), 'Ensure cleanBuildSystem can be called'); -$buildSystem = l10nSystem->new($ctx); +$buildSystem = ksb::l10nSystem->new($ctx); ok (!$buildSystem->isSubdirBuildable('scripts'), 'l10n-build isSubdirBuildable-scripts'); ok ($buildSystem->isSubdirBuildable(''), 'l10n-build isSubdirBuildable-other'); diff --git a/modules/ksb/l10nSystem.pm b/modules/ksb/l10nSystem.pm new file mode 100644 index 0000000..de7e11b --- /dev/null +++ b/modules/ksb/l10nSystem.pm @@ -0,0 +1,222 @@ +package ksb::l10nSystem; + +# This class is an implementation of both the source and build interfaces needed to +# support building KDE l10n modules. + +use strict; +use warnings; +use v5.10; + +use ksb::Debug; +use ksb::Util; +use ksb::Updater::Svn; +use ksb::BuildSystem; + +our @ISA = ('ksb::Updater::Svn', 'ksb::BuildSystem'); + +sub new +{ + my ($class, $module) = @_; + + # Ensure associated module updates from the proper svn path. + # TODO: Support different localization branches? + + $module->setOption('module-base-path', 'trunk/l10n-kde4'); + return bless { module => $module, needsRefreshed => 1 }, $class; +} + +sub module +{ + my $self = shift; + return $self->{module}; +} + +sub configuredModuleFileName +{ + # Not quite correct (we should be looking at each individual language + # but it at least keeps the process going. + return 'teamnames'; +} + +# Sets the directories that are to be checked out/built/etc. +# There should be one l10nSystem for the entire l10n build (i.e. add +# all required support dirs and languages). +sub setLanguageDirs +{ + my ($self, @languageDirs) = @_; + $self->{l10n_dirs} = \@languageDirs; +} + +# Returns true if the given subdirectory (reference from the module's root source directory) +# can be built or not. Should be reimplemented by subclasses as appropriate. +sub isSubdirBuildable +{ + my ($self, $subdir) = @_; + return ($subdir ne 'scripts' && $subdir ne 'templates'); +} + +sub prefixEnvironmentVariable +{ + return 'CMAKE_PREFIX_PATH'; +} + +# scm-specific update procedure. +# May change the current directory as necessary. +sub updateInternal +{ + my $self = assert_isa(shift, 'ksb::Updater'); + my $module = $self->module(); + my $fullpath = $module->fullpath('source'); + my @dirs = @{$self->{l10n_dirs}}; + + if (-e "$fullpath/.svn") { + $self->check_module_validity(); + my $count = $self->update_module_path(@dirs); + + $self->{needsRefreshed} = 0 if $count == 0; + return $count; + } + else { + return $self->checkout_module_path(@dirs); + } +} + +sub name +{ + return 'l10n'; +} + +# Returns a list of just the languages to install. +sub languages +{ + my $self = assert_isa(shift, 'ksb::l10nSystem'); + my @langs = @{$self->{l10n_dirs}}; + + return grep { $self->isSubdirBuildable($_); } (@langs); +} + +# Buildsystem support section + +sub needsRefreshed +{ + my $self = shift; + + # Should be 1 except if no update happened. + return $self->{needsRefreshed}; +} + +sub buildInternal +{ + my $self = assert_isa(shift, 'ksb::l10nSystem'); + my $builddir = $self->module()->fullpath('build'); + my @langs = $self->languages(); + my $result = 0; + + $result = ($self->safe_make({ + target => undef, + message => "Building localization for language...", + logbase => "build", + subdirs => \@langs, + }) == 0) || $result; + + return $result; +} + +sub configureInternal +{ + my $self = assert_isa(shift, 'ksb::l10nSystem'); + + my $builddir = $self->module()->fullpath('build'); + my @langs = $self->languages(); + my $result = 0; + + for my $lang (@langs) { + my $prefix = $self->module()->installationPath(); + p_chdir("$builddir/$lang"); + + info ("\tConfiguring to build language $lang"); + $result = (log_command($self->module(), "cmake-$lang", + ['cmake', '-DCMAKE_INSTALL_PREFIX=' . $prefix]) == 0) || $result; + } + + return $result; +} + +sub installInternal +{ + my $self = assert_isa(shift, 'ksb::l10nSystem'); + my $builddir = $self->module()->fullpath('build'); + my @langs = $self->languages(); + + return ($self->safe_make({ + target => 'install', + message => "Installing language...", + logbase => "install", + subdirs => \@langs, + }) == 0); +} + +# Subroutine to link a source directory into an alternate directory in +# order to fake srcdir != builddir for modules that don't natively support +# it. The first parameter is the module to prepare. +# +# The return value is true (non-zero) if it succeeded, and 0 (false) if it +# failed. +# +# On return from the subroutine the current directory will be in the build +# directory, since that's the only directory you should touch from then on. +sub prepareFakeBuilddir +{ + my $self = assert_isa(shift, 'ksb::l10nSystem'); + my $module = $self->module(); + my $builddir = $module->fullpath('build'); + my $srcdir = $module->fullpath('source'); + + # List reference, not a real list. The initial kdesrc-build does *NOT* + # fork another kdesrc-build using exec, see sub log_command() for more + # info. + my $args = [ 'kdesrc-build', 'main::safe_lndir', $srcdir, $builddir ]; + + info ("\tSetting up alternate build directory for l10n"); + return (0 == log_command ($module, 'create-builddir', $args)); +} + +# Subroutine to create the build system for a module. This involves making +# sure the directory exists and then running any preparatory steps (like +# for l10n modules). This subroutine assumes that the module is already +# downloaded. +# +# Return convention: boolean (inherited) +sub createBuildSystem +{ + my $self = assert_isa(shift, 'ksb::l10nSystem'); + my $module = $self->module(); + my $builddir = $module->fullpath('build'); + + # l10n doesn't support srcdir != builddir, fake it. + whisper ("\tFaking builddir for g[$module]"); + if (!$self->prepareFakeBuilddir()) + { + error ("Error creating r[$module] build system!"); + return 0; + } + + p_chdir ($builddir); + + my @langs = @{$self->{l10n_dirs}}; + @langs = grep { $self->isSubdirBuildable($_) } (@langs); + + foreach my $lang (@langs) { + my $cmd_ref = [ './scripts/autogen.sh', $lang ]; + if (log_command ($module, "build-system-$lang", $cmd_ref)) + { + error ("\tUnable to create build system for r[$module]"); + } + } + + $module->setOption('#reconfigure', 1); # Force reconfigure of the module + + return 1; +} + +1;