Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 385 lines (316 sloc) 9.439 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
#!/usr/bin/perl

use Module::Build;

# Define our custom build actions
my $class = Module::Build->subclass(
class => 'My::Builder',
code => << 'EOC'

use strict;
use File::Copy ();
use File::Path;

$ENV{PERL5LIB} ||= ''; # get rid of some warnings...

__PACKAGE__->add_property(data_files => {});

sub check_prereq {
my $self = shift;

eval 'use Gtk2';
my $gtk_ok = ! $@;

if ($gtk_ok and Gtk2->CHECK_VERSION(2, 10, 0)) {
my $recommends = $self->recommends;
delete $recommends->{'Gtk2::TrayIcon'};
}

my $prereq_ok = $self->SUPER::check_prereq(@_);

if (! $gtk_ok) {
$self->log_warn(" * ERROR: Could not load perl module Gtk2\n");
$self->log_warn(<<EOF) if $prereq_ok;

ERRORS/WARNINGS FOUND IN PREREQUISITES. You may wish to install the versions
of the modules indicated above before proceeding with this installation

EOF
}
elsif (! Gtk2->CHECK_VERSION(2, 4, 0)) {
my $version = join '.', Gtk2->GET_VERSION_INFO;
$self->log_warn(<<"EOF");

 * ERROR: gtk+ version $version is installed, but we need >= 2.4.0
   If you think you have the right version of gtk+ installed, try
   recompiling the Gtk2 perl package.

EOF
}

return $prereq_ok && $gtk_ok;
}

sub install_types {
my $self = shift;
my @types = $self->SUPER::install_types;
push @types, keys %{$$self{properties}{data_files}};
return sort @types;
}

sub install_destination {
my ($self, $type) = @_;
return $self->SUPER::install_destination($type)
unless exists $$self{properties}{data_files}{$type};

return $self->install_path($type) if $self->install_path($type);

my $relpath = $$self{properties}{data_files}{$type};

return File::Spec->catdir($self->install_base, $relpath)
if $self->install_base;

return File::Spec->catdir($self->prefix, $relpath)
if $self->prefix;

# Fall back to heuristic determination of prefix based on
# the 'bin' directory.
my $bindir = $self->install_sets($self->installdirs)->{'bin'};
my @prefix = File::Spec->splitdir($bindir);
pop @prefix; # loose 'bin'
return File::Spec->catdir(@prefix, $relpath);
}

sub process_share_files {
my $self = shift;
my $blib = $self->blib;

# Copy but exclude dev documentation
for (@{$self->rscan_dir('share')}) {
next if /(^|[\/\\])\.|Development/ or -d $_;
$self->copy_if_modified(
from => $_,
to => File::Spec->catfile($blib, $_) );
}

# Add changelog
my $dir = File::Spec->catdir($blib, qw/share zim doc/);
$self->copy_if_modified(
from => 'Changes',
to => File::Spec->catfile($dir, 'changelog.txt'));

# Set correct config for manual
my $conf = File::Spec->catfile($dir, 'notebook.zim');
open CONF, '<', $conf or die $!;
my $text = join '', <CONF>;
close CONF;

if ($text =~ s/^#(?!\s)//mg) { # un-escape some lines
my $mode = (stat $conf)[2];
chmod($mode | oct(222), $conf) or die $!;
print "Making the manual a read-only notebook\n";
open CONF, '>', $conf or die $!;
print CONF $text;
close CONF;
chmod($mode, $conf);
}
}

sub ACTION_install {
my $self = shift;
$self->SUPER::ACTION_install(@_);
$self->depends_on('postinstall');
}


sub ACTION_test {
my $self = shift;

# Multiple tests depend on data from the MANIFEST, so it needs to
# be correct. However only do this in dev tree when we can actually
# rebuild the manifest.
if (-e 'MANIFEST.SKIP') {
my $error = 0;
local $SIG{__WARN__} = sub {$error++; warn @_};
$self->depends_on('distcheck');
die "Please update the MANIFEST before testing\n" if $error;
}

$self->depends_on('test_data');
$self->SUPER::ACTION_test(@_);
}

sub ACTION_test_data {
my $self = shift;

for (qw#t/html t/notebook t/config t/share t/cache#) {
next unless -e $_;
$self->delete_filetree($_);
}

print "Extracting test notebook\n";

open IN, 't/notebook.txt' or die "t/notebook.txt: $!";
binmode IN, ':utf8' if not $] < 5.008;

my ($file, $fh);
while (<IN>) {
if (/^%%\s+(\S+)\s+%%$/) {
close $fh if $fh;
$file = $1;
mkpath $1 if $file =~ m#(.*/)#;
open $fh, ">$file" or die "$file: $!\n";
binmode $fh, ':utf8' if not $] < 5.008;
}
elsif ($fh) {
print $fh $_;
}
else { die "oops" }
}
close $fh if $fh;
}

#sub ACTION_distmeta {
#my $self = shift;
#$self->depends_on('messages');
#$self->run_perl_script('Lingua.PL') or return;
#$self->run_perl_script('Config.PL') or return;
#$self->SUPER::ACTION_distmeta(@_);
#}

sub ACTION_disttest {
my $self = shift;
$self->SUPER::ACTION_disttest(@_);

# Check how clean we build
my $start_dir = $self->cwd;
my $dist_dir = $self->dist_dir;
chdir $dist_dir or die "Cannot chdir to $dist_dir: $!";
$self->run_perl_script('Build', [], ['realclean']);
chdir $start_dir;

my %manifest;
open MANIFEST, 'MANIFEST' or die "Cannot open MANIFEST: $!";
while (<MANIFEST>) {
chomp;
s/\s.*//;
$manifest{$_}++;
}
close MANIFEST;
my @dirt;
my @files = grep {-f $_} @{$self->rscan_dir($dist_dir)};
for (@files) {
s/^$dist_dir[\/\\]//;
push @dirt, $_ unless $manifest{$_};
}
die "ERROR: The following files where not cleaned up properly:\n",
map "\t$_\n", @dirt
if @dirt;
print "Cleanup OK\n";
}

sub ACTION_realclean {
my $self = shift;
$self->SUPER::ACTION_realclean(@_);
my @files = grep /(\~|\.bak)$/, @{$self->rscan_dir('.')};
return unless @files;
warn "Also cleaning up:\n", map "\t$_\n", @files;
unlink $_ or die $! for @files;
}

=head1 ACTIONS

=over 4

=item C<postinstall>

Runs commands to update the XDG databases.

=cut

sub ACTION_postinstall {
my $self = shift;
my $sharedir = $self->install_destination('share');
my $mimedir = File::Spec->catdir($sharedir, 'mime');
my $icon = File::Spec->catfile($sharedir, 'pixmaps', 'zim.png');
for (
['update-desktop-database'],
['update-mime-database', $mimedir],
# [qw{xdg-icon-resource install --context apps --size 64},
# $icon],
[qw{xdg-icon-resource install --context mimetypes --size 64},
$icon, q{application-x-zim-notebook}],
) {
print "Trying: @$_\n";
print system(@$_) == 0 ? "Ok\n\n" : "Failed\n\n" ;
}

}

=item C<messages>

Generates a new F<zim.pot> file. Only works from development tree,
not from dist.

=cut

sub ACTION_messages {
my $self = shift;
die "This is not a development tree, can not build messages.\n"
unless -d './dev';
$self->do_system($self->perl, './dev/xgettext.pl');
}

=item C<static>

Builds a self-contained excutable for zim. Needs the L<PAR> and
L<ExtUtils::PkgConfig> modules.

=back

=cut

sub ACTION_static {
my $self = shift;
warn "## WARNING: Static building is experimental - feedback is welcome\n";
warn "## You need to have zim installed before running this command\n";
warn "## You can pass extra options to 'pp' using PP_OPTS\n";
eval 'use ExtUtils::PkgConfig';
die $@ if $@;
sleep 5;
$self->depends_on('build');
my @libs = map {s/^-l//i; ('-l', $_)} grep {length $_} split /\s+/,
ExtUtils::PkgConfig->libs('gtk+-2.0');
my @add = ('-a', 'share');
open MANIFEST, '<MANIFEST' or die "Could not read MANIFEST";
my @modules;
for (<MANIFEST>) { # grep modules from the manifest
/^lib\/(\S+?)\.pm/ or next;
my $mod = $1;
$mod =~ s/\//::/g;
push @modules, '-M', $mod;
}
close MANIFEST;
my $script = File::Spec->catfile(qw/script zim/);
my $blib = File::Spec->catdir($ENV{PWD}, $self->blib);
my $libdir = File::Spec->catdir($blib, 'lib');
print ">> cd $blib\n";
chdir $blib or die "Could not open dir $blib\n";
$ENV{PWD} = $blib;
print ">> pp -I $libdir -o zim @libs @add @modules $script\n";
system qw{pp -o ../zim}, @libs, @add, @modules, $script;
warn "\n## Your executable is ready\n";
}

#=item C<testflow>
#
#Run test suite and record which method calls which other methods.
#
#=cut

sub ACTION_testflow {
# TODO: Move "tmon.out" after each test, now it gets overwritten
# TODO: wrap script around "dprofpp -T" to make summaries or graphs
my $self = shift;

# $self->add_to_cleanup('flow_db');
$self->depends_on('code');

local $Test::Harness::switches =
local $Test::Harness::switches =
local $ENV{HARNESS_PERL_SWITCHES} = '-d:DProf';

$self->depends_on('test');
# $self->do_system('./dev/flow.pl');
}

EOC
);

# Define the build parameters
my $build = $class->new(
dist_name => 'Zim',
dist_version_from => 'lib/Zim.pm',
dist_abstract => 'A desktop wiki',
dist_author => 'Jaap Karssenberg <pardus@cpan.org>',
license => 'perl',
script_files => ['bin/zim'],
data_files => { share => 'share' },
requires => {
'perl' => '5.8.0',
'Gtk2' => '1.040',
# Older doesn't support Gtk2::UIManager I think
'POSIX' => 0,
'IO::File' => 0,
'File::Spec' => 0,
'File::Copy' => 0,
'File::BaseDir' => 0.03,
'File::MimeInfo' => '0.12',
'File::DesktopEntry' => 0.03,
'Encode' => 0,
},
recommends => {
'Gtk2::TrayIcon' => 0,
# This recommendation is removed on the
# fly when gtk+ >= 2.10 is detected because
# in that case we can use Gtk2::StatusIcon
'Gtk2::Spell' => 0,
},
build_requires => {
'Module::Build' => '0.28',
'Test::More' => 0,
'File::Path' => 0,
},
add_to_cleanup => [
'./cover_db/', # from Build testcover
'./tmon.out', # from dprof
'./tmp',
# Used by tests:
't/notebook/',
't/html/',
't/config/',
't/share/',
't/cache/',
],
create_makefile_pl => 'passthrough',
dynamic_config => 1,
);

# Add share dir as something to be build
$build->add_build_element('share');

# And finally create the script "./Build"
$build->create_build_script;

Something went wrong with that request. Please try again.