From 1be20da35a56900c012866ab874dee0cba2530b2 Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 2 Jul 2019 18:40:25 +0200 Subject: [PATCH] Make use of std::filesystem optional It is not available under Android yet and only used for Bash completion. So make it optional to support Android by disabling that part of the Bash completion which is not useful under Android anyways. --- CMakeLists.txt | 10 ++++++++-- application/argumentparser.cpp | 7 ++++++- tests/argumentparsertests.cpp | 8 ++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b51caf8..4291eb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,8 +160,14 @@ else () message(STATUS "Using std::fstream for NativeFileStream") endif () -# configure required libraries for std::filestream -use_standard_filesystem() +# configure required libraries for std::filesystem +option(USE_STANDARD_FILESYSTEM "uses std::filesystem; if disabled Bash completion for files and directories is not working" ON) +if (USE_STANDARD_FILESYSTEM) + list(APPEND META_PRIVATE_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_STANDARD_FILESYSTEM) + use_standard_filesystem() +else () + message(WARNING "The use of std::filesystem has been disabled. Bash completion for files and directories will not work.") +endif () # configure forcing UTF-8 code page under Windows option(FORCE_UTF8_CODEPAGE "forces use of UTF-8 code page under Windows via ApplicationUtilities::startConsole()" OFF) diff --git a/application/argumentparser.cpp b/application/argumentparser.cpp index 210ca0e..06fbe31 100644 --- a/application/argumentparser.cpp +++ b/application/argumentparser.cpp @@ -12,12 +12,15 @@ #include #include #include -#include #include #include #include #include +#ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEM +#include +#endif + using namespace std; using namespace std::placeholders; using namespace std::literals; @@ -1484,6 +1487,7 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi } // -> completion for files and dirs +#ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEM if (completionInfo.completeFiles || completionInfo.completeDirs) { using namespace std::filesystem; const auto replace = "'"s, with = "'\"'\"'"s; @@ -1520,6 +1524,7 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi haveFileOrDirCompletions = true; } } +#endif cout << ')'; // ensure file or dir completions are formatted appropriately diff --git a/tests/argumentparsertests.cpp b/tests/argumentparsertests.cpp index 3d891ba..e4ae5c7 100644 --- a/tests/argumentparsertests.cpp +++ b/tests/argumentparsertests.cpp @@ -659,9 +659,13 @@ void ArgumentParserTests::testBashCompletion() parser.resetArgs(); const char *const argv5[] = { "get", "--files", iniFilePath.c_str() }; { +#ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEM // order for file names is not specified const OutputCheck c("COMPREPLY=('" % mkvFilePath % " '\"'\"'with quote'\"'\"'.mkv' '" % iniFilePath + ".ini' ); compopt -o filenames\n", "COMPREPLY=('" % iniFilePath % ".ini' '" % mkvFilePath + " '\"'\"'with quote'\"'\"'.mkv' ); compopt -o filenames\n"); +#else + const OutputCheck c("COMPREPLY=()\n"); +#endif reader.reset(argv5, argv5 + 3).read(); parser.printBashCompletion(3, argv5, 2, reader); } @@ -672,8 +676,12 @@ void ArgumentParserTests::testBashCompletion() parser.resetArgs(); const char *const argv14[] = { "get", "--files", directoryPath.c_str() }; { +#ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEM // order for file names is not specified const OutputCheck c("COMPREPLY=('" % directoryPath + "subdir' ); compopt -o filenames\n"); +#else + const OutputCheck c("COMPREPLY=()\n"); +#endif reader.reset(argv14, argv14 + 3).read(); parser.printBashCompletion(3, argv14, 2, reader); }