From 12b159118a67abf2c2d47492c6c502f5f5720d7f Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 20 Apr 2019 20:03:59 -0400 Subject: Compare versions between CLI and library --- ChangeLog | 7 +++++++ README-maintainer | 1 + make_dist | 22 ++++++++++++++++++++++ qpdf/qpdf.cc | 13 +++++++++++++ qpdf/qtest/qpdf.test | 2 +- 5 files changed, 44 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6ab197fc..66c82e4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2019-04-20 Jay Berkenbilt + * 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 diff --git a/README-maintainer b/README-maintainer index 4b47a809..3ae29e90 100644 --- a/README-maintainer +++ b/README-maintainer @@ -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. diff --git a/make_dist b/make_dist index 1b8b095e..d6e42332 100755 --- a/make_dist +++ b/make_dist @@ -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) @@ -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"; @@ -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; diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index 495816c3..5bf36c5b 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -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, @@ -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." diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index 6ee0ecfe..3eea8df3 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -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"}, -- cgit v1.2.3-54-g00ecf