2008-04-29 12:55:25 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#
|
|
|
|
# This program creates a source distribution of qpdf. For details,
|
2021-12-21 14:23:20 +00:00
|
|
|
# see README-maintainer.
|
2008-04-29 12:55:25 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
require 5.008;
|
2011-08-10 20:43:12 +00:00
|
|
|
use warnings;
|
2008-04-29 12:55:25 +00:00
|
|
|
use strict;
|
2011-08-10 20:43:12 +00:00
|
|
|
use File::Basename;
|
2008-04-29 12:55:25 +00:00
|
|
|
use Cwd;
|
2018-02-21 12:02:45 +00:00
|
|
|
use Cwd 'abs_path';
|
2008-04-29 12:55:25 +00:00
|
|
|
use IO::File;
|
2021-12-13 12:43:26 +00:00
|
|
|
use File::Path qw(rmtree make_path);
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2011-08-10 20:43:12 +00:00
|
|
|
my $whoami = basename($0);
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2021-12-13 12:43:26 +00:00
|
|
|
my $tmp = $ENV{'TMPDIR'} || '/tmp';
|
2018-08-16 15:20:35 +00:00
|
|
|
my $keep_tmp = 0;
|
2018-10-13 15:51:35 +00:00
|
|
|
my $ci_mode = 0;
|
2018-08-16 15:20:35 +00:00
|
|
|
my $version = undef;
|
2018-02-21 12:02:45 +00:00
|
|
|
foreach my $arg (@ARGV)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2022-03-12 12:06:11 +00:00
|
|
|
if ($arg eq '--keep-tmp')
|
2018-08-16 15:20:35 +00:00
|
|
|
{
|
|
|
|
$keep_tmp = 1;
|
|
|
|
}
|
2018-10-13 15:51:35 +00:00
|
|
|
elsif ($arg eq '--ci')
|
|
|
|
{
|
|
|
|
$ci_mode = 1;
|
|
|
|
}
|
2018-08-16 15:20:35 +00:00
|
|
|
elsif (! defined $version)
|
|
|
|
{
|
|
|
|
$version = $arg;
|
|
|
|
}
|
2008-04-29 12:55:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
2018-02-21 12:02:45 +00:00
|
|
|
|
2018-10-13 15:51:35 +00:00
|
|
|
if ($ci_mode && (! defined $version))
|
|
|
|
{
|
2022-03-12 12:06:11 +00:00
|
|
|
$version = get_version_from_cmake();
|
2018-10-13 15:51:35 +00:00
|
|
|
}
|
|
|
|
|
2018-08-16 15:20:35 +00:00
|
|
|
usage() unless defined $version;
|
|
|
|
usage() unless $version =~ m/^(\d+\.\d+(?:\.(a|b|rc)?\d+)?)$/;
|
|
|
|
my $distname = "qpdf-$version";
|
2021-12-13 12:43:26 +00:00
|
|
|
my $tmpdir = "${tmp}/$distname";
|
2018-08-16 15:20:35 +00:00
|
|
|
if ((-d $tmpdir) && (! $keep_tmp))
|
|
|
|
{
|
|
|
|
rmtree($tmpdir);
|
|
|
|
}
|
2021-12-13 12:43:26 +00:00
|
|
|
make_path($tmp);
|
|
|
|
run("git archive --prefix=qpdf-$version/ HEAD . | (cd $tmp; tar xf -)");
|
2018-08-16 15:20:35 +00:00
|
|
|
cd($tmpdir);
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
# Check versions
|
2022-03-12 12:06:11 +00:00
|
|
|
my $cmakeversion = get_version_from_cmake();
|
2018-10-13 15:51:35 +00:00
|
|
|
my $code_version = get_version_from_source();
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
my $version_error = 0;
|
2022-03-12 12:06:11 +00:00
|
|
|
if ($version ne $cmakeversion)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2022-03-12 12:06:11 +00:00
|
|
|
print "$whoami: cmake version = $cmakeversion\n";
|
2008-04-29 12:55:25 +00:00
|
|
|
$version_error = 1;
|
|
|
|
}
|
|
|
|
if ($version ne $code_version)
|
|
|
|
{
|
2009-10-24 13:41:03 +00:00
|
|
|
print "$whoami: QPDF.cc version = $code_version\n";
|
2008-04-29 12:55:25 +00:00
|
|
|
$version_error = 1;
|
|
|
|
}
|
|
|
|
if ($version_error)
|
|
|
|
{
|
|
|
|
die "$whoami: version numbers are not consistent\n";
|
|
|
|
}
|
|
|
|
|
2021-12-13 12:43:26 +00:00
|
|
|
cd($tmp);
|
2018-08-16 15:20:35 +00:00
|
|
|
run("tar czvf $distname.tar.gz-candidate $distname");
|
2018-10-13 15:51:35 +00:00
|
|
|
my $distfile = ($ci_mode ? "$distname-ci.tar.gz" : "$distname.tar.gz");
|
|
|
|
rename "$distname.tar.gz-candidate", $distfile or die;
|
2018-08-16 15:20:35 +00:00
|
|
|
|
|
|
|
if (! $keep_tmp)
|
|
|
|
{
|
|
|
|
rmtree($tmpdir);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print "
|
2021-12-13 12:43:26 +00:00
|
|
|
Source distribution created as ${tmp}/$distfile
|
2008-04-29 12:55:25 +00:00
|
|
|
If this is a release, don't forget to tag the version control system and
|
|
|
|
make a backup of the release tar file.
|
|
|
|
|
|
|
|
";
|
|
|
|
|
2022-03-12 12:06:11 +00:00
|
|
|
sub get_version_from_cmake
|
2018-10-13 15:51:35 +00:00
|
|
|
{
|
2022-03-12 12:06:11 +00:00
|
|
|
my $fh = safe_open("CMakeLists.txt");
|
|
|
|
my $cmake_version = 'unknown';
|
|
|
|
my $saw_project = 0;
|
2018-10-13 15:51:35 +00:00
|
|
|
while (<$fh>)
|
|
|
|
{
|
2022-03-12 12:06:11 +00:00
|
|
|
if (m/project\(qpdf/)
|
2018-10-13 15:51:35 +00:00
|
|
|
{
|
2022-03-12 12:06:11 +00:00
|
|
|
$saw_project = 1;
|
|
|
|
}
|
|
|
|
elsif ($saw_project && m/VERSION (\S+)$/)
|
|
|
|
{
|
|
|
|
$cmake_version = $1;
|
2018-10-13 15:51:35 +00:00
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$fh->close();
|
2022-03-12 12:06:11 +00:00
|
|
|
$cmake_version;
|
2018-10-13 15:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub get_version_from_source
|
|
|
|
{
|
2022-02-04 17:21:52 +00:00
|
|
|
my $fh = safe_open("include/qpdf/DLL.h");
|
2018-10-13 15:51:35 +00:00
|
|
|
my $code_version = 'unknown';
|
2022-02-04 17:21:52 +00:00
|
|
|
my $major = '';
|
|
|
|
my $minor = '';
|
|
|
|
my $patch = '';
|
2018-10-13 15:51:35 +00:00
|
|
|
while (<$fh>)
|
|
|
|
{
|
2022-02-04 17:21:52 +00:00
|
|
|
if (m/QPDF_MAJOR_VERSION (\d+)/)
|
|
|
|
{
|
|
|
|
$major = $1;
|
|
|
|
}
|
|
|
|
elsif (m/QPDF_MINOR_VERSION (\d+)/)
|
|
|
|
{
|
|
|
|
$minor = $1;
|
|
|
|
}
|
|
|
|
elsif (m/QPDF_PATCH_VERSION (\d+)/)
|
|
|
|
{
|
|
|
|
$patch = $1;
|
|
|
|
}
|
|
|
|
elsif (m/QPDF_VERSION \"([^\"]+)\"/)
|
2018-10-13 15:51:35 +00:00
|
|
|
{
|
|
|
|
$code_version = $1;
|
|
|
|
}
|
|
|
|
}
|
2022-02-04 17:21:52 +00:00
|
|
|
my $t = sprintf("%s.%s.%s", $major, $minor, $patch);
|
|
|
|
if ($t ne $code_version)
|
|
|
|
{
|
|
|
|
die "$whoami: version is inconsistent in DLL.h:" .
|
|
|
|
" $t vs $code_version\n";
|
|
|
|
}
|
|
|
|
|
2018-10-13 15:51:35 +00:00
|
|
|
$fh->close();
|
|
|
|
$code_version;
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
sub safe_open
|
|
|
|
{
|
|
|
|
my $file = shift;
|
|
|
|
my $fh = new IO::File("<$file") or die "$whoami: can't open $file: $!";
|
|
|
|
$fh;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub run
|
|
|
|
{
|
|
|
|
my $cmd = shift;
|
|
|
|
system($cmd) == 0 or die "$whoami: $cmd failed\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub cd
|
|
|
|
{
|
|
|
|
my $dir = shift;
|
|
|
|
chdir($dir) or die;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub usage
|
|
|
|
{
|
|
|
|
die "
|
2022-03-12 12:06:11 +00:00
|
|
|
Usage: $whoami [--keep-tmp] {--ci|version}
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2021-12-13 12:43:26 +00:00
|
|
|
$whoami creates ${tmp}/qpdf-<version> and deletes it when done. With
|
2018-08-16 15:20:35 +00:00
|
|
|
--keep-tmp, the directory is kept. This can be useful for debugging
|
|
|
|
the release process.
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
";
|
|
|
|
}
|