#include "Util.hpp"
#include "hashutil.hpp"
+#include <util/path_utils.hpp>
+
#include <algorithm>
#include <string>
#include <vector>
Logging::init(config);
ignore_header_paths =
- Util::split_into_strings(config.ignore_headers_in_manifest(), PATH_DELIM);
+ util::split_path_list(config.ignore_headers_in_manifest());
set_ignore_options(Util::split_into_strings(config.ignore_options(), " "));
// Set default umask for all files created by ccache from now on (if
}
if (!ctx.config.extra_files_to_hash().empty()) {
- for (const std::string& path : Util::split_into_strings(
- ctx.config.extra_files_to_hash(), PATH_DELIM)) {
+ for (const std::string& path :
+ util::split_path_list(ctx.config.extra_files_to_hash())) {
LOG("Hashing extra file {}", path);
hash.hash_delimiter("extrafile");
if (!hash_binary_file(ctx, hash, path)) {
// Search the path looking for the first compiler of the right name that isn't
// us.
- for (const std::string& dir : Util::split_into_strings(path, PATH_DELIM)) {
+ for (const std::string& dir : util::split_path_list(path)) {
#ifdef _WIN32
char namebuf[MAX_PATH];
int ret = SearchPath(
# define STDIN_FILENO 0
# define STDOUT_FILENO 1
# define STDERR_FILENO 2
-# define PATH_DELIM ";"
#else
# define DLLIMPORT
-# define PATH_DELIM ":"
#endif
DLLIMPORT extern char** environ;
#include "path_utils.hpp"
-#include <Logging.hpp>
#include <Util.hpp>
#include <fmtmacros.hpp>
+#ifdef _WIN32
+const char k_path_delimiter[] = ";";
+#else
+const char k_path_delimiter[] = ":";
+#endif
+
namespace util {
bool
return !path.empty() && path[0] == '/';
}
+std::vector<std::string>
+split_path_list(nonstd::string_view path_list)
+{
+ return Util::split_into_strings(path_list, k_path_delimiter);
+}
+
std::string
to_absolute_path(nonstd::string_view path)
{
#include <third_party/nonstd/string_view.hpp>
#include <string>
+#include <vector>
namespace util {
// Return whether `path` is absolute.
bool is_absolute_path(nonstd::string_view path);
+// Split a list of paths (such as the content of $PATH on Unix platforms or
+// %PATH% on Windows platforms) into paths.
+std::vector<std::string> split_path_list(nonstd::string_view path_list);
+
// Make `path` an absolute path.
std::string to_absolute_path(nonstd::string_view path);
CHECK(!util::is_absolute_path("foo/fie"));
}
+TEST_CASE("util::split_path_list")
+{
+ CHECK(util::split_path_list("").empty());
+ {
+ const auto v = util::split_path_list("a");
+ REQUIRE(v.size() == 1);
+ CHECK(v[0] == "a");
+ }
+ {
+ const auto v = util::split_path_list("a/b");
+ REQUIRE(v.size() == 1);
+ CHECK(v[0] == "a/b");
+ }
+ {
+#ifdef _WIN32
+ const auto v = util::split_path_list("a/b;c");
+#else
+ const auto v = util::split_path_list("a/b:c");
+#endif
+ REQUIRE(v.size() == 2);
+ CHECK(v[0] == "a/b");
+ CHECK(v[1] == "c");
+ }
+}
+
TEST_CASE("util::to_absolute_path")
{
CHECK(util::to_absolute_path("/foo/bar") == "/foo/bar");