Skip to content

Commit

Permalink
Compare versions between CLI and library
Browse files Browse the repository at this point in the history
  • Loading branch information
jberkenbilt committed Apr 21, 2019
1 parent 2b011f9 commit 12b1591
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
2019-04-20 Jay Berkenbilt <[email protected]>

* When qpdf --version is run, it will detect if the qpdf CLI was
built with a different version of qpdf than the library. This
usually indicates that multiple versions of qpdf are installed and
that the library path is not set up properly. This situation
sometimes causes confusing behavior for users who are not actually
running the version of qpdf they think they are running.

* Add parameter --remove-page-labels to remove page labels from
output. In qpdf 8.3.0, the behavior changed so that page labels
were preserved when merging and splitting files. Some users were
Expand Down
1 change: 1 addition & 0 deletions README-maintainer
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ RELEASE PREPARATION
* configure.ac
* libqpdf/QPDF.cc
* manual/qpdf-manual.xml
* qpdf/qpdf.cc
`make_dist` verifies this consistency.

* Add a release entry to ChangeLog.
Expand Down
22 changes: 22 additions & 0 deletions make_dist
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ cd($tmpdir);
my $config_version = get_version_from_configure();
my $code_version = get_version_from_source();
my $doc_version = get_version_from_manual();
my $cli_version = get_version_from_cli();

my $version_error = 0;
if ($version ne $config_version)
Expand All @@ -80,6 +81,11 @@ if ($version ne $doc_version)
print "$whoami: qpdf-manual.xml version = $doc_version\n";
$version_error = 1;
}
if ($version ne $cli_version)
{
print "$whoami: qpdf.cc version = $cli_version\n";
$version_error = 1;
}
if ($version_error)
{
die "$whoami: version numbers are not consistent\n";
Expand Down Expand Up @@ -161,6 +167,22 @@ sub get_version_from_manual
$doc_version;
}

sub get_version_from_cli
{
my $fh = safe_open("qpdf/qpdf.cc");
my $cli_version = 'unknown';
while (<$fh>)
{
if (m/expected_version = \"([^\"]+)\"/)
{
$cli_version = $1;
last;
}
}
$fh->close();
$cli_version;
}

sub safe_open
{
my $file = shift;
Expand Down
13 changes: 13 additions & 0 deletions qpdf/qpdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ static int const EXIT_WARNING = 3;

static char const* whoami = 0;

static std::string expected_version = "8.4.0";

struct PageSpec
{
PageSpec(std::string const& filename,
Expand Down Expand Up @@ -993,6 +995,17 @@ ArgParser::argPositional(char* arg)
void
ArgParser::argVersion()
{
if (expected_version != QPDF::QPDFVersion())
{
std::cerr << "***\n"
<< "WARNING: qpdf CLI from version " << expected_version
<< " is using library version " << QPDF::QPDFVersion()
<< ".\n"
<< "This probably means you have multiple versions of qpdf installed\n"
<< "and don't have your library path configured correctly.\n"
<< "***"
<< std::endl;
}
std::cout
<< whoami << " version " << QPDF::QPDFVersion() << std::endl
<< "Run " << whoami << " --copyright to see copyright and license information."
Expand Down
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf.test
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ $n_tests += 3;

$td->runtest("qpdf version",
{$td->COMMAND => "qpdf --version"},
{$td->REGEXP => "qpdf version \\S+\n.*", $td->EXIT_STATUS => 0},
{$td->REGEXP => ".*qpdf version \\S+\n.*", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("qpdf copyright contains version too",
{$td->COMMAND => "qpdf --copyright"},
Expand Down

0 comments on commit 12b1591

Please sign in to comment.