Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit b021847

Browse files
committed
Add boost::regex to support gcc 4.8
Signed-off-by: Isaac Hier <isaachier@gmail.com>
1 parent b2b4420 commit b021847

File tree

11 files changed

+114
-25
lines changed

11 files changed

+114
-25
lines changed

.travis.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ matrix:
1212
- g++-6
1313
- lcov
1414
env:
15-
- MATRIX_EVAL="CC=gcc-6 && CXX=g++-6"
15+
- MATRIX_EVAL="CC=gcc-6 && CXX=g++-6 && COVERAGE=ON"
16+
- os: linux
17+
addons:
18+
apt:
19+
sources:
20+
- ubuntu-toolchain-r-test
21+
packages:
22+
- g++-4.8
23+
env:
24+
- MATRIX_EVAL="CC=gcc-4.8 && CXX=g++-4.8"
1625
branches:
1726
only:
1827
- master

CMakeLists.txt

+9-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,15 @@ endif()
5959

6060
set(package_deps)
6161

62-
hunter_add_package(Boost)
63-
find_package(Boost ${hunter_config} REQUIRED)
62+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
63+
CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")
64+
set(boost_components regex)
65+
hunter_add_package(Boost regex)
66+
else()
67+
set(boost_components)
68+
hunter_add_package(Boost)
69+
endif()
70+
find_package(Boost ${hunter_config} REQUIRED ${boost_components})
6471
list(APPEND package_deps Boost)
6572

6673
hunter_add_package(thrift)

cmake/Config.cmake.in

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
set(package_deps @package_deps@)
44
foreach(dep IN LISTS package_deps)
5-
if(dep STREQUAL "OpenSSL" OR
6-
dep STREQUAL "Threads")
5+
if(dep STREQUAL "OpenSSL" OR dep STREQUAL "Threads")
76
find_package(${dep} REQUIRED)
87
elseif(dep STREQUAL "OpenTracing" OR
98
dep STREQUAL "yaml-cpp")
@@ -13,6 +12,9 @@ foreach(dep IN LISTS package_deps)
1312
endif()
1413
endforeach()
1514

15+
set(boost_components @boost_components@)
16+
find_package(Boost CONFIG REQUIRED ${boost_components})
17+
1618
check_required_components("@PROJECT_NAME@")
1719

1820
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")

scripts/build.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ function working() {
2121

2222
mkdir -p build
2323
cd build || exit
24-
cmake -DCMAKE_BUILD_TYPE=Debug -DJAEGERTRACING_COVERAGE=ON ..
24+
if [ $COVERAGE != "" ]; then
25+
cmake -DCMAKE_BUILD_TYPE=Debug -DJAEGERTRACING_COVERAGE=ON ..
26+
else
27+
cmake -DCMAKE_BUILD_TYPE=Debug -DJAEGERTRACING_COVERAGE=OFF ..
28+
fi
29+
2530
if make -j3 UnitTest; then
2631
true
2732
else

src/jaegertracing/net/URI.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#include <cstring>
2121
#include <iomanip>
2222
#include <iostream>
23-
#include <regex>
23+
24+
#include "jaegertracing/utils/Regex.h"
2425

2526
namespace jaegertracing {
2627
namespace net {
@@ -67,11 +68,11 @@ URI URI::parse(const std::string& uriStr)
6768
{
6869
// See https://tools.ietf.org/html/rfc3986 for explanation.
6970
URI uri;
70-
std::regex uriRegex(
71+
regex_namespace::regex uriRegex(
7172
"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?",
72-
std::regex::extended);
73-
std::smatch match;
74-
std::regex_match(uriStr, match, uriRegex);
73+
regex_namespace::regex::extended);
74+
regex_namespace::smatch match;
75+
regex_namespace::regex_match(uriStr, match, uriRegex);
7576

7677
constexpr auto kSchemeIndex = 2;
7778
constexpr auto kAuthorityIndex = 4;

src/jaegertracing/net/http/Header.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <string>
2323

2424
#include "jaegertracing/net/http/Error.h"
25+
#include "jaegertracing/utils/Regex.h"
2526

2627
namespace jaegertracing {
2728
namespace net {
@@ -73,14 +74,15 @@ inline std::istream& readLineCRLF(std::istream& in, std::string& line)
7374

7475
inline void readHeaders(std::istream& in, std::vector<Header>& headers)
7576
{
76-
const std::regex headerPattern("([^:]+):(.+)$");
77+
const regex_namespace::regex headerPattern("([^:]+):(.+)$");
7778
std::string line;
78-
std::smatch match;
79+
regex_namespace::smatch match;
7980
while (readLineCRLF(in, line)) {
8081
if (line.empty()) {
8182
break;
8283
}
83-
if (!std::regex_match(line, match, headerPattern) || match.size() < 3) {
84+
if (!regex_namespace::regex_match(line, match, headerPattern) ||
85+
match.size() < 3) {
8486
throw ParseError::make("header", line);
8587
}
8688
headers.emplace_back(Header(match[1], match[2]));

src/jaegertracing/net/http/Request.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@
1616

1717
#include "jaegertracing/net/http/Request.h"
1818

19+
#include "jaegertracing/utils/Regex.h"
20+
1921
namespace jaegertracing {
2022
namespace net {
2123
namespace http {
2224

2325
Request Request::parse(std::istream& in)
2426
{
25-
const std::regex requestLinePattern(
27+
const regex_namespace::regex requestLinePattern(
2628
"([A-Z]+) ([^ ]+) HTTP/([0-9]\\.[0-9])$");
2729
std::string line;
28-
std::smatch match;
30+
regex_namespace::smatch match;
2931
if (!readLineCRLF(in, line) ||
30-
!std::regex_match(line, match, requestLinePattern) ||
32+
!regex_namespace::regex_match(line, match, requestLinePattern) ||
3133
match.size() < 4) {
3234
throw ParseError::make("request line", line);
3335
}

src/jaegertracing/net/http/Response.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@
2525

2626
#include "jaegertracing/Constants.h"
2727
#include "jaegertracing/net/Socket.h"
28+
#include "jaegertracing/utils/Regex.h"
2829

2930
namespace jaegertracing {
3031
namespace net {
3132
namespace http {
3233

3334
Response Response::parse(std::istream& in)
3435
{
35-
const std::regex statusLinePattern("HTTP/([0-9]\\.[0-9]) ([0-9]+) (.+)$");
36+
const regex_namespace::regex statusLinePattern(
37+
"HTTP/([0-9]\\.[0-9]) ([0-9]+) (.+)$");
3638
std::string line;
37-
std::smatch match;
39+
regex_namespace::smatch match;
3840
if (!readLineCRLF(in, line) ||
39-
!std::regex_match(line, match, statusLinePattern) || match.size() < 4) {
41+
!regex_namespace::regex_match(line, match, statusLinePattern) || match.size() < 4) {
4042
throw ParseError::make("status line", line);
4143
}
4244
Response response;

src/jaegertracing/testutils/MockAgent.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "jaegertracing/testutils/MockAgent.h"
1818

19-
#include <regex>
2019
#include <thread>
2120

2221
#include <thrift/protocol/TCompactProtocol.h>
@@ -28,6 +27,7 @@
2827
#include "jaegertracing/net/http/Request.h"
2928
#include "jaegertracing/net/http/Response.h"
3029
#include "jaegertracing/utils/ErrorUtil.h"
30+
#include "jaegertracing/utils/Regex.h"
3131
#include "jaegertracing/utils/UDPClient.h"
3232

3333
namespace jaegertracing {
@@ -139,7 +139,7 @@ void MockAgent::serveHTTP(std::promise<void>& started)
139139
_servingHTTP = true;
140140
started.set_value();
141141

142-
const std::regex servicePattern("[?&]service=([^?&]+)");
142+
const regex_namespace::regex servicePattern("[?&]service=([^?&]+)");
143143
while (isServingHTTP()) {
144144
constexpr auto kBufferSize = 256;
145145
std::array<char, kBufferSize> buffer;
@@ -167,11 +167,12 @@ void MockAgent::serveHTTP(std::promise<void>& started)
167167
_httpAddress.authority() + "/baggageRestrictions")) {
168168
resource = Resource::kBaggage;
169169
}
170-
std::smatch match;
171-
if (!std::regex_search(target, match, servicePattern)) {
170+
regex_namespace::smatch match;
171+
if (!regex_namespace::regex_search(target, match, servicePattern)) {
172172
throw net::http::ParseError("no 'service' parameter");
173173
}
174-
if (std::regex_search(match.suffix().str(), servicePattern)) {
174+
if (regex_namespace::regex_search(
175+
match.suffix().str(), servicePattern)) {
175176
throw net::http::ParseError(
176177
"'service' parameter must occur only once");
177178
}

src/jaegertracing/utils/Regex.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2017 Uber Technologies, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "jaegertracing/utils/Regex.h"

src/jaegertracing/utils/Regex.h

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2017 Uber Technologies, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef JAEGERTRACING_UTILS_REGEX_H
18+
#define JAEGERTRACING_UTILS_REGEX_H
19+
20+
#if (!defined(__GNUC__) || \
21+
defined(__clang__) || \
22+
__GNUC__ > 4 || \
23+
__GNUC_MINOR__ > 8)
24+
#define JAEGERTRACING_USE_STD_REGEX 1
25+
#else
26+
#define JAEGERTRACING_USE_STD_REGEX 0
27+
#endif
28+
29+
#if JAEGERTRACING_USE_STD_REGEX
30+
#include <regex>
31+
#else
32+
#include <boost/regex.hpp>
33+
#endif
34+
35+
#if JAEGERTRACING_USE_STD_REGEX
36+
#define regex_namespace std
37+
#else
38+
#define regex_namespace boost
39+
#endif
40+
41+
#endif // JAEGERTRACING_UTILS_REGEX_H

0 commit comments

Comments
 (0)