Bug 1438866 - Use proper path separators for windows. r?emilio
The indexer has paths handed to it on Windows with the backslash path separator.
However it currently hard-codes the forward-slash Unix/macOS path separator,
so we need to generify that code appropriately.
MozReview-Commit-ID: Iy8bImt2BXW
--- a/build/clang-plugin/mozsearch-plugin/FileOperations.cpp
+++ b/build/clang-plugin/mozsearch-plugin/FileOperations.cpp
@@ -22,21 +22,21 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
// Make sure that all directories on path exist, excluding the final element of
// the path.
void ensurePath(std::string Path) {
size_t Pos = 0;
- if (Path[0] == '/') {
+ if (Path[0] == PATHSEP_CHAR) {
Pos++;
}
- while ((Pos = Path.find('/', Pos)) != std::string::npos) {
+ while ((Pos = Path.find(PATHSEP_CHAR, Pos)) != std::string::npos) {
std::string Portion = Path.substr(0, Pos);
if (!Portion.empty()) {
#if defined(_WIN32) || defined(_WIN64)
int Err = _mkdir(Portion.c_str());
#else
int Err = mkdir(Portion.c_str(), 0775);
#endif
if (Err == -1 && errno != EEXIST) {
--- a/build/clang-plugin/mozsearch-plugin/FileOperations.h
+++ b/build/clang-plugin/mozsearch-plugin/FileOperations.h
@@ -6,16 +6,21 @@
#ifndef FileOperations_h
#define FileOperations_h
#include <stdio.h>
#include <string>
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
+#define PATHSEP_CHAR '\\'
+#define PATHSEP_STRING "\\"
+#else
+#define PATHSEP_CHAR '/'
+#define PATHSEP_STRING "/"
#endif
// Make sure that all directories on path exist, excluding the final element of
// the path.
void ensurePath(std::string Path);
std::string getAbsolutePath(const std::string &Filename);
--- a/build/clang-plugin/mozsearch-plugin/MozsearchIndexer.cpp
+++ b/build/clang-plugin/mozsearch-plugin/MozsearchIndexer.cpp
@@ -31,17 +31,17 @@
#include <stdlib.h>
#include "FileOperations.h"
#include "JSONFormatter.h"
#include "StringOperations.h"
using namespace clang;
-const std::string GENERATED("__GENERATED__/");
+const std::string GENERATED("__GENERATED__" PATHSEP_STRING);
// Absolute path to directory containing source code.
std::string Srcdir;
// Absolute path to objdir (including generated code).
std::string Objdir;
// Absolute path where analysis JSON output will be stored.
@@ -1479,29 +1479,29 @@ protected:
if (Srcdir.empty()) {
DiagnosticsEngine &D = CI.getDiagnostics();
unsigned DiagID = D.getCustomDiagID(
DiagnosticsEngine::Error, "Source directory '%0' does not exist");
D.Report(DiagID) << Args[0];
return false;
}
- ensurePath(Args[1] + "/");
+ ensurePath(Args[1] + PATHSEP_STRING);
Outdir = getAbsolutePath(Args[1]);
- Outdir += "/";
+ Outdir += PATHSEP_STRING;
Objdir = getAbsolutePath(Args[2]);
if (Objdir.empty()) {
DiagnosticsEngine &D = CI.getDiagnostics();
unsigned DiagID = D.getCustomDiagID(DiagnosticsEngine::Error,
"Objdir '%0' does not exist");
D.Report(DiagID) << Args[2];
return false;
}
- Objdir += "/";
+ Objdir += PATHSEP_STRING;
printf("MOZSEARCH: %s %s %s\n", Srcdir.c_str(), Outdir.c_str(),
Objdir.c_str());
return true;
}
void printHelp(llvm::raw_ostream &Ros) {