Jan Tojnar [Mon, 13 Apr 2020 14:16:11 +0000 (16:16 +0200)]
build: Produce correct pc file with absolute libdir
The CMAKE_INSTALL_INCLUDEDIR and CMAKE_INSTALL_LIBDIR variables
can be absolute paths so simply appending them to \${prefix}
might not work.
Unfortunately, CMake does not have simple function for joining paths [1]
so I had to write my own suboptimal one.
It somewhat handles the following cases
- prefix absolute + libdir relative
- prefix absolute + libdir absolute but not under prefix
but for
- prefix absolute + libdir absolute & under prefix
we would want to strip the prefix and make the libdir relative
so we can make it relative to the pkg-config variables.
Basically, we want the equivalent of the following Python function:
import os.path
from pathlib import PurePath
if os.path.isabs(libdir) and os.path.commonpath([libdir, prefix]) == str(PurePath(prefix)):
# Convert path to be relative to prefix
skip = len(prefix) + 1
libdir = libdir[skip:]
return os.path.join('${prefix}', libdir)
This would be non-trivial to replicate in CMake scripts as far as I can tell.
Jan Tojnar [Mon, 13 Apr 2020 12:57:57 +0000 (14:57 +0200)]
build: Install man pages correctly
CMAKE_INSTALL_MANDIR can be absolute path so simply appending it to CMAKE_INSTALL_PREFIX will not work an may produce paths like /nix/store/5r86wqbn6ncdxrdwvmskc381krm32pzh-zziplib-0.13.70/nix/store/5r86wqbn6ncdxrdwvmskc381krm32pzh-zziplib-0.13.70/…
There's various warnings in the generated documentation either due to
missing links or to mistaken use of simple comments `/* */` instead of
docstyle comments `/** */`. Fix some of these by converting to docstyle
comments or fixing the referenced function names.
Commit 5b660a3 (Merge pull request #72 from jelly/python3, 2019-08-04)
introduced a conversion to use new-style Python exceptions.
The conversion introduced a new print statements, though, breaking
compatibility with Python 3 again.
Convert the statement to use the print function, instead.
With recent changes CMake is now favoring Python 3 instead of Python 2.
As Ubuntu has both versions of the interpreter installed, Azure has thus
started to use Python 3, but will fail due to a missing dependency on
xmlreporting when executing tests. This is caused by us installing
xmlreporting for Python 2, only.
As there is no python3-xmlreporting package available in Ubuntu, install
python3-pip instead and use it to install unittest-xml-reporting.
Now that all Python scripts are compatible with Python 2 and Python 3,
we can instruct CMake to not care for which Python interpreter is
available. Thus, convert to use the newer FindPython package without
specifying a version.
Instead of inheriting str, we can simply implement `__repr__` to return
a string representation of the pattern itself. This fixes compatibility
with Python 3, which throws when executing `str.__init__`.
In Python 3, the function string.replace has been removed in favor of
using replace on the string class directly. As Python 2.7 already
supports this variant, convert all instances of the old way to call
replace on the object.
The `has_key` function for dictionaries has been removed with Python 3
in favor of the new `in` keyword. Convert all uses of the old function
in favor of the new to improve compatibility with Python 3.
docs: use print function for compatibility with Python 3
Another quite visible change with Python 3 is that the old `print`
statement has been replaced with a function. To ease migration to the
newer way, Python 2.7 provides a compatibility module "print_function".
Convert all code in docs to use the new function syntax.
docs: exception syntax compatibility with Python 3
Since Python 2.7, there exists a new syntax to catch errors: the old way
of saying `except IOError, error` has been replaced with `except IOError
as e`. The old syntax has finally been removed in Python 3, but as we're
still using it in zziplib newer interpreters will raise a parsing error.
Convert to use the new syntax to improve compatibility with Python 3.
One of the most important and user-visible changes in Python 3 was that
when reading strings from some , one always needs to specify the
encoding lest the dreaded UnicodeException would occur if there were any
characters outside of the ASCII range. In the test suite, we're using a
subprocess taht communicates with the shell, but we do not specify the
encoding of both its stdout and stderr previous to reading them.
Explicitly decode both their output and error streams to UTF-8 to avoid
any exceptions raised by Python 3.
In Python 2, strings were represented by the class basestring, which has
been removed in Python 3 in favor of the str class. To keep
compatibility with both versions of Python, let's alias basestring to
str if basestring is not available.
test: use Python3-compatible way to specify octal numbers
Support for zero-prefixed octal numbers ("0755") has been removed in
Python 3 in favor of the zero-oh-prefix ("0o755"). As the latter has
been introduced in Python 2.6, we can safely switch all occurrences of
the former with the new way to improve compatibility with Python 3.