Bug 1438866 - Use proper path separators for windows. r?emilio draft
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 16 Feb 2018 17:07:39 -0500
changeset 756875 e2ead53bceb597a5413d1a20f150c5733b06b8d5
parent 756286 f529bbfd0f59e08b9f9f53165e590c251e2ce847
child 756876 41c880ff92f11d71ee9fd2d12c4b8ee41fccd564
push id99571
push userkgupta@mozilla.com
push dateMon, 19 Feb 2018 03:19:26 +0000
reviewersemilio
bugs1438866
milestone60.0a1
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
build/clang-plugin/mozsearch-plugin/FileOperations.cpp
build/clang-plugin/mozsearch-plugin/FileOperations.h
build/clang-plugin/mozsearch-plugin/MozsearchIndexer.cpp
--- 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) {