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.
This commit is contained in:
Martchus 2019-07-02 18:40:25 +02:00
parent 6b1a9cec01
commit 1be20da35a
3 changed files with 22 additions and 3 deletions

View File

@ -160,8 +160,14 @@ else ()
message(STATUS "Using std::fstream for NativeFileStream") message(STATUS "Using std::fstream for NativeFileStream")
endif () endif ()
# configure required libraries for std::filestream # configure required libraries for std::filesystem
use_standard_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 # 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) option(FORCE_UTF8_CODEPAGE "forces use of UTF-8 code page under Windows via ApplicationUtilities::startConsole()" OFF)

View File

@ -12,12 +12,15 @@
#include <algorithm> #include <algorithm>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <filesystem>
#include <iostream> #include <iostream>
#include <set> #include <set>
#include <sstream> #include <sstream>
#include <string> #include <string>
#ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEM
#include <filesystem>
#endif
using namespace std; using namespace std;
using namespace std::placeholders; using namespace std::placeholders;
using namespace std::literals; using namespace std::literals;
@ -1484,6 +1487,7 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi
} }
// -> completion for files and dirs // -> completion for files and dirs
#ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEM
if (completionInfo.completeFiles || completionInfo.completeDirs) { if (completionInfo.completeFiles || completionInfo.completeDirs) {
using namespace std::filesystem; using namespace std::filesystem;
const auto replace = "'"s, with = "'\"'\"'"s; const auto replace = "'"s, with = "'\"'\"'"s;
@ -1520,6 +1524,7 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi
haveFileOrDirCompletions = true; haveFileOrDirCompletions = true;
} }
} }
#endif
cout << ')'; cout << ')';
// ensure file or dir completions are formatted appropriately // ensure file or dir completions are formatted appropriately

View File

@ -659,9 +659,13 @@ void ArgumentParserTests::testBashCompletion()
parser.resetArgs(); parser.resetArgs();
const char *const argv5[] = { "get", "--files", iniFilePath.c_str() }; const char *const argv5[] = { "get", "--files", iniFilePath.c_str() };
{ {
#ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEM
// order for file names is not specified // order for file names is not specified
const OutputCheck c("COMPREPLY=('" % mkvFilePath % " '\"'\"'with quote'\"'\"'.mkv' '" % iniFilePath + ".ini' ); compopt -o filenames\n", 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"); "COMPREPLY=('" % iniFilePath % ".ini' '" % mkvFilePath + " '\"'\"'with quote'\"'\"'.mkv' ); compopt -o filenames\n");
#else
const OutputCheck c("COMPREPLY=()\n");
#endif
reader.reset(argv5, argv5 + 3).read(); reader.reset(argv5, argv5 + 3).read();
parser.printBashCompletion(3, argv5, 2, reader); parser.printBashCompletion(3, argv5, 2, reader);
} }
@ -672,8 +676,12 @@ void ArgumentParserTests::testBashCompletion()
parser.resetArgs(); parser.resetArgs();
const char *const argv14[] = { "get", "--files", directoryPath.c_str() }; const char *const argv14[] = { "get", "--files", directoryPath.c_str() };
{ {
#ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEM
// order for file names is not specified // order for file names is not specified
const OutputCheck c("COMPREPLY=('" % directoryPath + "subdir' ); compopt -o filenames\n"); const OutputCheck c("COMPREPLY=('" % directoryPath + "subdir' ); compopt -o filenames\n");
#else
const OutputCheck c("COMPREPLY=()\n");
#endif
reader.reset(argv14, argv14 + 3).read(); reader.reset(argv14, argv14 + 3).read();
parser.printBashCompletion(3, argv14, 2, reader); parser.printBashCompletion(3, argv14, 2, reader);
} }