-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support GCC 4.8, using Boost.Regex #43
Conversation
#include <iostream> | ||
#include <cassert> | ||
#include <cstddef> | ||
|
||
// Workaround GCC 4.8 not having std::regex | ||
#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what is the best thing to do here. We can either make the use of Boost.Regex opt-in (with some flag), or default like this.
We also can add some preprocessor warning to the user:
#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8)
#ifdef DOCTOPT_USE_BOOST_REGEX
#include <boost/regex.hpp>
[...]
#else
#error "GCC 4.8 can not build docopt alone. You can opt-in using Boost.Regex by defining DOCTOPT_USE_BOOST_REGEX"
#endif
#else
#include <regex>
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we just have "#if DOCTOPT_USE_BOOST_REGEX" without the version check? If people really want to use GCC 4.8 then it would be on them to fix up the flag rather than us trying to guard it.
Updated to use |
target_link_libraries(docopt_s ${Boost_LIBRARIES}) | ||
endif() | ||
endif() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this really should be implicit? Or should we just assume that people on 4.8 will pass in the "use boost" option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I mean, if that's the only way this'll work, then try as hard as possible to make it work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to update this part. The condition in the if should be if(USE_BOOST_REGEX)
, and maybe add an error message with a suggestion to define this variable on GCC 4.8.
Just a question and very minor typo... thanks for working on this! |
Also, can you rebase this on top of latest? Looks like there's a merge conflict. |
The only caveat is that the user should make sure to link boost libraries as needed.
Updated, with comments addressed. I still get the same test failure on my machine, i.e.:
Should I add GCC 4.8 to Travis too ? |
This looks great ... if you could add it to Travis, that would be awesome. That would atleast make sure no one in the future ever breaks it. Are you willing to do that? If so, I'll merge this right away. (I'll merge it even if you say you wont do that part, but then there's nothing to stop it from breaking later) |
Ok, I'll add it to Travis. What should I do for the failing tests? Is there a way to prevent this exact test from running? |
Ok, so now after the updates and 134760a, the failure is a legit one: https://travis-ci.org/docopt/docopt.cpp/jobs/141999566. Does anyone with doctopt and regex knowledge can help to fix this? |
Is this just a case sensitivity issue? http://stackoverflow.com/questions/15619665/ignore-case-with-boostregexp
|
It does not seems to be. If I update this line to read |
@Luthaf I wanted to check out this code and poke around a bit, but I've failed so far. first problemcmake couldn't find boost_regex with that capitol 'R'. I tested this on redhad 6.8 with g++4.8.1. diff --git a/CMakeLists.txt b/CMakeLists.txt
index ecad376..3a2b751 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -55,7 +55,7 @@ endif()
if(USE_BOOST_REGEX)
add_definitions("-DDOCTOPT_USE_BOOST_REGEX")
- find_package(Boost REQUIRED COMPONENTS Regex)
+ find_package(Boost REQUIRED COMPONENTS regex)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(docopt ${Boost_LIBRARIES})
if(WITH_STATIC) second problem
|
'sh g++-5 --version || true' will fail as sh try to open a file named g++-5
@rhd I updated the PR, both issues should be fixed now. Thank you for your help. |
If the option definition spans over multiple lines, then parsing of the [default: x] was not working on Windows - tested on MS Visual Studio 2015. This is due to the differences in regex's multiline property implementation. On some platforms - Linux libstd++ the multiline property is off, on some platforms - msvc2015 the multiline property is on. It cannot be changed programmatically AFAIK. I was not able to come up with a regex expression which would work on Linux and on Windows as well. So I tried to be smart and replace '\n' by '\f' in the string beforehand. The regex was easy and worked on Linux and Windows just fine - up until I tried a longer option definition. Then the msvc2015 regex failed with 'stack' exception. Hence this change. It splits the option definition section by a simple regex which does not use the problematic '$'. modified: docopt.cpp modified: docopt_util.h
The issue was not with case sensitivity, but with multiline matching. By cherry-picking fdc4826 from #23, it seems to work. @jaredgrubb is it good to merge for you? |
}; | ||
|
||
std::vector<Option> defaults; | ||
for (auto s : parse_section("options:", doc)) { | ||
s.erase(s.begin(), s.begin() + s.find(':') + 1); // get rid of "options:" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You got rid of a static_cast<std::ptrdiff_t>
here .. I think we need to put that back in order to quiet some warnings.
I'm going to merge this as-is and then put back the static_cast .. thanks for you work on this! |
I got one failure on my machine:
Also, I checked that the code still compiles normally using clang.
I can try to add GCC 4.8 to travis, but this will make it fail.
Fixes #42.