2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00
qpdf/make_dist
Jay Berkenbilt 23b64f8357 Remove qpdf.cc version check
Remove comparison of qpdf CLI version with library. With almost all
the functionality moving into the library, this check is no longer
meaningful.
2022-01-30 13:11:03 -05:00

187 lines
3.6 KiB
Perl
Executable File

#!/usr/bin/env perl
#
# This program creates a source distribution of qpdf. For details,
# see README-maintainer.
#
require 5.008;
use warnings;
use strict;
use File::Basename;
use Cwd;
use Cwd 'abs_path';
use IO::File;
use File::Path qw(rmtree make_path);
my $whoami = basename($0);
my $tmp = $ENV{'TMPDIR'} || '/tmp';
my $keep_tmp = 0;
my $ci_mode = 0;
my $version = undef;
foreach my $arg (@ARGV)
{
if ($arg eq '--no-tests')
{
# ignore for compatibility
}
elsif ($arg eq '--keep-tmp')
{
$keep_tmp = 1;
}
elsif ($arg eq '--ci')
{
$ci_mode = 1;
}
elsif (! defined $version)
{
$version = $arg;
}
else
{
usage();
}
}
if ($ci_mode && (! defined $version))
{
$version = get_version_from_configure();
}
usage() unless defined $version;
usage() unless $version =~ m/^(\d+\.\d+(?:\.(a|b|rc)?\d+)?)$/;
my $distname = "qpdf-$version";
my $tmpdir = "${tmp}/$distname";
if ((-d $tmpdir) && (! $keep_tmp))
{
rmtree($tmpdir);
}
make_path($tmp);
run("git archive --prefix=qpdf-$version/ HEAD . | (cd $tmp; tar xf -)");
cd($tmpdir);
# Check versions
my $config_version = get_version_from_configure();
my $code_version = get_version_from_source();
my $doc_version = get_version_from_manual();
my $version_error = 0;
if ($version ne $config_version)
{
print "$whoami: configure.ac version = $config_version\n";
$version_error = 1;
}
if ($version ne $code_version)
{
print "$whoami: QPDF.cc version = $code_version\n";
$version_error = 1;
}
if ($version ne $doc_version)
{
print "$whoami: doc version = $doc_version\n";
$version_error = 1;
}
if ($version_error)
{
die "$whoami: version numbers are not consistent\n";
}
cd($tmp);
run("tar czvf $distname.tar.gz-candidate $distname");
my $distfile = ($ci_mode ? "$distname-ci.tar.gz" : "$distname.tar.gz");
rename "$distname.tar.gz-candidate", $distfile or die;
if (! $keep_tmp)
{
rmtree($tmpdir);
}
print "
Source distribution created as ${tmp}/$distfile
If this is a release, don't forget to tag the version control system and
make a backup of the release tar file.
";
sub get_version_from_configure
{
my $fh = safe_open("configure.ac");
my $config_version = 'unknown';
while (<$fh>)
{
if (m/^AC_INIT\(\[qpdf\],\[([^\)]+)\]\)/)
{
$config_version = $1;
last;
}
}
$fh->close();
$config_version;
}
sub get_version_from_source
{
my $fh = safe_open("libqpdf/QPDF.cc");
my $code_version = 'unknown';
while (<$fh>)
{
if (m/QPDF::qpdf_version = \"([^\"]+)\"/)
{
$code_version = $1;
last;
}
}
$fh->close();
$code_version;
}
sub get_version_from_manual
{
my $fh = safe_open("manual/conf.py");
my $doc_version = 'unknown';
while (<$fh>)
{
if (m/release = '([^\']+)\'/)
{
$doc_version = $1;
last;
}
}
$fh->close();
$doc_version;
}
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 "
Usage: $whoami [ --no-tests --keep-tmp ] version
Use of --no-tests can be used for internally testing releases, but do
not use it for a real release.
$whoami creates ${tmp}/qpdf-<version> and deletes it when done. With
--keep-tmp, the directory is kept. This can be useful for debugging
the release process.
";
}