fix odr test for bundled boost and test this

This commit is contained in:
Hans Dembinski 2020-04-06 00:45:55 +02:00 committed by GitHub
parent 830f238534
commit b63d7e2b6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 8 deletions

View File

@ -70,6 +70,9 @@ matrix:
# prepare build
- ./bootstrap.sh
- ./b2 headers
# simulate bundled boost by moving the headers instead of symlinking
- rm -rf boost/histogram.pp boost/histogram
- mv -f libs/histogram/include/boost/* boost
- cd libs/histogram
- B2="../../b2 -q -j2 warnings-as-errors=on"

View File

@ -4,6 +4,10 @@
# (See accompanying file LICENSE_1_0.txt
# or copy at http://www.boost.org/LICENSE_1_0.txt)
"""
This test makes sure that all boost.histogram headers are included in the ODR test carried out in odr_main_test.cpp. See that file for details on why this test needed.
"""
import os
import sys
import re
@ -11,12 +15,20 @@ import re
this_path = os.path.dirname(__file__)
all_headers = set()
include_path = os.path.join(this_path, "..", "include")
# Includes are either in this_path/../include for the standalone version or ...
include_path = os.path.join(this_path, "..", "include", "boost", "histogram")
if not os.path.exists(include_path):
# ... in this_path/../../.. for the bundled boost release
include_path = os.path.join(this_path, "..", "..", "..", "boost", "histogram")
assert os.path.exists(include_path)
# this has to be rindex, because any leading path could also be called boost
root_include_path = include_path[: include_path.rindex("boost")]
for root, dirs, files in os.walk(include_path):
for fn in files:
fn = os.path.join(root, fn)
assert fn.startswith(include_path)
fn = fn[len(include_path) + 1 :]
fn = fn[len(root_include_path) :]
all_headers.add(fn)
@ -37,7 +49,7 @@ while unread_headers:
included_headers.update(unread_headers)
for hdr in tuple(unread_headers): # copy needed because unread_headers is modified
unread_headers.remove(hdr)
for hdr2 in get_headers(os.path.join(include_path, hdr)):
for hdr2 in get_headers(os.path.join(root_include_path, hdr)):
if hdr2 not in included_headers:
unread_headers.add(hdr2)

View File

@ -4,7 +4,18 @@
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
// include all headers again
/*
For a header-only library, it is important to not accidentally violate the
One-Definition-Rule (ODR), which causes linker errors. The ODR is violated
when a non-templated function declared in a header is not inlined, and that
header is then included in several translation units which are then linked
together.
We carry out this test by including all headers in two separate translation
units which are then linked together. There is an additional test called
check_odr_test.py which checks that "odr_test.cpp" includes all headers.
*/
#include "odr_test.cpp"
int main() { return 0; }

View File

@ -4,9 +4,7 @@
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
// include all Boost.Histogram header here
// include all Boost.Histogram header here; see odr_main_test.cpp for details
#include <boost/histogram.hpp>
#include <boost/histogram/accumulators.hpp>
#include <boost/histogram/axis/ostream.hpp>
#include <boost/histogram/ostream.hpp>
#include <boost/histogram/serialization.hpp>