'?\n)?
(?:(?:\#\ |:\ ')\@\(\#\)[^\n]*\n)?
(?:\#\ |:\ ')$pd_rx
/xo,
".c" => qr!\A\/\*\n\*\*\ $pd_rx!o,
".h" => qr!\A(?:\#(?:ifndef|define)\ [^\n]*\n|\n)*\/\*\n\*\*\ $pd_rx!o,
".htm" => qr!(?:\A(?>.*?)|)\n?$pd_rx!so,
);
$pd_rx{".html"} = $pd_rx{".htm"};
$pd_rx{".$_"} = qr/\n\.\\\"\ $pd_rx[^\n]*\n(?:\.\\\"[^\n]*\n)*\z/o
foreach 1..8;
sub action_download_olson(@) {
die "bad arguments\n" unless @_ == 1;
my($ver) = @_;
if((-e "$target_dir/tzsrc") || (-e "$target_dir/tzsrc.meta")) {
die "won't replace existing Olson source\n";
}
my $dl = Time::OlsonTZ::Download->new($ver eq "latest" ? () : ($ver));
my $dldir = $dl->unpacked_dir;
my $tdir = "$target_dir/tzsrc.new$$";
clean_dir($tdir);
my $dirdone = 0;
my $clean_tdir = end {
local($., $@, $!, $^E, $?);
clean_dir($tdir) unless $dirdone;
};
mkpath($tdir);
my @files;
find({
no_chdir => 1,
wanted => sub {
return unless -f $_;
unless(m#\A$dldir/([^/]+)\z#) {
die "downloaded file $_ in unexpected place\n";
}
my $lname = $1;
if(m#/tz(?:code|data)\.tar\.(?:Z|gz)\z#) {
# Is download tarball; not a source file.
return;
}
if(m#
/(?:date|(?:new)?strftime)
\.(?:c|[1-8](?:\.txt)?)
\z#x) {
# Is under BSD license rather than PD,
# so skip. (Don't need these files.)
return;
}
if(m#(?:
/checktab\.awk|/tzselect\.ksh|/zoneinfo2tdf\.pl
|\.[1-8]\.txt|/usno[0-9]{4}[a-z]?
)\z#x) {
# Is PD but not explicitly labelled
# as such. Don't need these files,
# so skip.
return;
}
my($ext) = m#(\.[0-9a-z]+)\z#;
$ext = "" unless defined($ext) && exists($pd_rx{$ext});
my $content = read_file($_);
unless($content =~ $pd_rx{$ext}) {
die "could not confirm PD status of $lname\n";
}
write_file("$tdir/$lname", $content);
push @files, $lname;
},
}, $dldir);
rename($tdir, "$target_dir/tzsrc")
or die "can't create $target_dir/tzsrc: $!\n";
$dirdone = 1;
write_target_file("tzsrc.meta", "+".tabbed_pond({
version => $dl->version,
code_version => $dl->code_version,
data_version => $dl->data_version,
files => [ sort @files ],
})."\n");
}
my %tpl_handler = (
canonical_names_list => sub ($) {
my @names = sort keys %{$_[0]->canonical_names};
my $lines = "";
my $line = "";
while(@names) {
my $name = shift(@names);
if(length($line)+1+length($name) > 73) {
$lines .= $line . "\n";
$line = "";
}
$line .= ($line ? " " : "\t") . $name;
}
$lines .= $line . "\n";
return "qw(\n".$lines.")";
},
links_hash => sub ($) { tabbed_pond($_[0]->threaded_links) },
version_lettered => sub ($) { $_[0]->version },
version_numeric => sub ($) {
my $v = $_[0]->version;
$v =~ s/([a-z])/sprintf("%02d", ord($1)-0x60)/eg;
return $v;
},
code_version_lettered => sub ($) { $_[0]->code_version },
data_version_lettered => sub ($) { $_[0]->data_version },
);
sub expand_template_item($$) {
my($dl, $itemname) = @_;
my $handler = $tpl_handler{$itemname}
or die "unknown template item `$itemname'\n";
return $handler->($dl);
}
sub expand_template($$) {
my($dl, $filename) = @_;
my $content = read_target_file("$filename.tpl");
$content =~ s//expand_template_item($dl, $1)/eg;
write_target_file($filename, $content);
}
sub generate_country_selection($) {
my($dl) = @_;
my $expr = tabbed_pond($dl->country_selection);
write_target_file("$data_relpath/country_selection.tzp",
q{{ use 5.006; }}."\n".
q{use warnings;}."\n".
q{no if "$]" < 5.007, "warnings", "deprecated";}."\n".
q{use strict;}."\n".
"+$expr\n");
}
sub expand_manifest($) {
my($extra_names) = @_;
my @base_names = split(/\n/, read_target_file("MANIFEST.base"));
write_target_file("MANIFEST", join("", map { $_."\n" }
sort { $a cmp $b } @base_names, @$extra_names));
}
sub tzfile_name($) {
my($zonename) = @_;
unless($zonename =~ m#\A[0-9A-Za-z\-\+_]+(?:/[0-9A-Za-z\-\+_]+)*\z#) {
die "zone name `$zonename' is not good as a filename\n";
}
return "$data_relpath/$zonename.tz";
}
sub action_build_data(@) {
die "bad arguments\n" if @_;
action_unbuild_data();
my $tzsrc_meta = do {
$@ = "";
do("$target_dir/tzsrc.meta") ||
die($@ eq "" ? "$target_dir/tzsrc.meta: $!\n" : $@);
};
my $dl = Time::OlsonTZ::Download->new_from_local_source(
version => $tzsrc_meta->{version},
code_version => $tzsrc_meta->{code_version},
data_version => $tzsrc_meta->{data_version},
source_dir => "$target_dir/tzsrc",
);
expand_template($dl, "lib/Time/OlsonTZ/Data.pm");
generate_country_selection($dl);
expand_manifest([
(map { "tzsrc/$_" } @{$tzsrc_meta->{files}}),
(map { tzfile_name($_) } keys %{$dl->canonical_names}),
]);
my $dl_tzfile_dir = $dl->zoneinfo_dir;
foreach(keys %{$dl->canonical_names}) {
write_target_file(tzfile_name($_),
read_file("$dl_tzfile_dir/$_"));
}
}
my $action = shift(@ARGV);
defined $action or die "no action specified\n";
{
no strict "refs";
unless(defined(&{"action_$action"})) {
die "no action '$action' defined\n";
}
&{"action_$action"}(@ARGV);
}
exit 0;
=head1 NAME
prebuild - custom build process for Time::OlsonTZ::Data
=head1 SYNOPSIS
./prebuild status
./prebuild download_olson latest
./prebuild build_data
./prebuild unbuild_data
./prebuild bare
=head1 DESCRIPTION
This program performs build actions for the L
module that should run I the usual build process of C
and C. The module distribution tarball for CPAN includes the
results of the prebuild process, because the prebuilding process only
runs on Unix and requires a C compiler, whereas some CPAN users use other
platforms or lack a compiler. The products of the prebuild process are
treated as source for by C and C. Those who are on Unix
can use this program to rebuild the data files from their true source,
possibly with modifications.
A further complication is that the source for the data files, and for the
program that builds most of the data files, is not actually maintained
as part of the L module. These source files are
maintained and canonically distributed by the maintainers of the Olson
timezone database, entirely outside the Perl context. The purpose of
this module is to repackage this data for Perl purposes. For this reason,
this program supports downloading that part of the source.
The process of building L thus involves the following
sequence of states for the module distribution directory:
=over
=item bare wrapper source
Directory contains only the CPAN wrapper code. There are no Olson
source files, no built tzfiles or Perl-format metadata, no C
script, and no C subdirectory.
This is the form of the directory that version-control repositories
should have, if they're tracking only the CPAN wrapper project.
=item combined true source
In addition to the CPAN wrapper code, there is a full set of Olson
source files (C and C) in the C subdirectory,
and a C file giving identification details for the Olson
source files. There are no built tzfiles or Perl-format metadata,
no C script, and no C subdirectory.
This is the main form of the directory that should be used by someone
who edits the Olson source as well as wanting the CPAN wrapper.
A version-control repository could sensibly track this, for such a user.
However, if you maintain a non-standard version of the Olson database
outside the context of this wrapper, and want to apply this wrapper to
it, it's better to work from the bare wrapper source and use a custom
mechanism to incorporate the Olson source.
=item data built
In addition to the combined true source, there is a full
set of tzfiles under C, and metadata
described in Perl form in C and
C. There is no C
script, and no C subdirectory.
This is the form of the directory that is published as a tarball on CPAN.
The tzfiles and Perl-format metadata are generated from Olson data source
files, using a combination of Olson and wrapper code. All the generated
files are platform-neutral.
=item configured for target
In addition to the combined source and built data files, there is a
C script incorporating knowledge of a particular host and proposed
installation location. There is no C subdirectory.
This is an intermediate stage in normal CPAN build processing.
=item built for target
In addition to the combined source, built data files, and C
script, there is a C subdirectiory which contains all the files
that are to be installed, laid out as they will be when installed.
This is an intermediate stage in normal CPAN build processing.
Installation and automated testing proceed from this state.
=back
=head1 ACTIONS
The first command-line argument specifies what action is required from
this program. The actions are:
=over
=item B
Describe the status of the build process. This will primarily be one
of the five states listed above. If some build products exist from
later in the process, but not enough to reach the next major state,
the specific additional items are listed.
=item B I
Download Olson database source from an appropriate distribution
site, placing (most of) it in a C subdirectory and creating a
C file to describe it. This will not replace an existing
C directory; use the B action first if you want to throw
away existing source. The I argument may be an Olson database
version number such as "C<2012b>", to download that specific version,
or "B" to get the current version.
This action ensures that only public-domain matter goes into the C
subdirectory. The downloaded source is checked for the expected markers
indicating public-domain status, and an error is signalled if it cannot
be confirmed. A small number of known files are filtered out, because
they are either definitely not PD (they are BSD licensed) or not properly
labelled (though presumably actually are PD). None of the files that
are filtered out are required for building tzfiles.
The downloading and PD-checking code is quite strict about the expected
form of the Olson source distribution. Anything surprising is liable
to cause an abort, and it is entirely foreseeable that it will abort
in situations that are actually acceptable. An error at this stage,
therefore, does not necessarily indicate a fatal problem; it indicates
a need for human attention, potentially resulting in editing this code
to handle the new situation.
=item B
Build a full set of tzfiles and put metadata into Perl form. This
requires Olson source to be available in the C subdirectory.
It will replace any existing tzfiles and metadata files.
=item B
Remove any target build, target configuration, and data build products.
This cleans up the distribution directory as far as the combined true
source state.
=item B
Remove any target build, target configuration, and data build products,
and Olson database source. This cleans up the distribution directory
as far as the bare wrapper source state.
=back
=head1 OPTIONS
=over
=item B I
Operate on the module distribution in the specified directory.
Defaults to the current directory.
=back
=head1 AUTHOR
The Olson timezone database was compiled by Arthur David Olson, Paul
Eggert, and many others. It is maintained by the denizens of the mailing
list (formerly ).
The C Perl module wrapper for the database was
developed by Andrew Main (Zefram) .
=head1 COPYRIGHT
The Olson timezone database is is the public domain.
The C Perl module wrapper for the database is
Copyright (C) 2010, 2011, 2012 Andrew Main (Zefram) .
=head1 LICENSE
No license is required to do anything with public domain materials.
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.