ClangVSx icon indicating copy to clipboard operation
ClangVSx copied to clipboard

chokes on quotes in paths

Open Trass3r opened this issue 13 years ago • 5 comments

in GatherIncludes for example. Please tell me if you need more info.

Trass3r avatar Dec 11 '12 19:12 Trass3r

This implcitly includes that spaces in paths must be handled correctly.

Trass3r avatar Dec 11 '12 19:12 Trass3r

By default it will wrap all paths in quotes incase they have spaces. I guess I need to check for any pre-wrapped with quotes and skip that process.

ishani avatar Dec 11 '12 22:12 ishani

It's worse. It also received paths like "aa\b\c\d" (read it as-is, \ aren't escapes) This is my quickly and dirty fix:

 CVXBuildSystem.cs | 43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/CVXBuildSystem.cs b/CVXBuildSystem.cs
index de1768a..493ea74 100644
--- a/CVXBuildSystem.cs
+++ b/CVXBuildSystem.cs
@@ -530,6 +530,24 @@ namespace ClangVSx

     #region Data Gathering

+    static internal string addQuotes(string input)
+    {
+      if (!input.Contains("\""))
+        return "\"" + input + "\"";
+      // check if they are in the right place
+      if (!(input[0] == '"' && input[input.Length - 1] == '"'))
+        throw new Exception("Unexpected quotes inside the string: " + input);
+      return input;
+    }
+
+    static internal string sanitizePath(string input)
+    {
+      input = input.Replace("\"", "");
+      if (input[0] == '/') input = input.Substring(1);
+      if (input[input.Length - 1] == '/') input = input.Remove(input.Length - 1);
+        return input;
+    }
+
     /// <summary>
     /// 
     /// </summary>
@@ -554,16 +572,13 @@ namespace ClangVSx
               result.Append("-I");
               String incCheck = parsedInc.Replace("\\", "/");

-              // Clang doesn't like the trailing / on these
-              if (incCheck == "./") incCheck = ".";
-              if (incCheck == "../") incCheck = "..";
+              // remove /
+              incCheck = sanitizePath(incCheck);

               // resolve any relative paths
               incCheck = Path.GetFullPath(incCheck);

-              result.Append("\"");
-              result.Append(incCheck);
-              result.Append("\" ");
+              result.Append(addQuotes(incCheck));
+              result.Append(" ");
             }
           }
         }
@@ -587,9 +602,9 @@ namespace ClangVSx
               // resolve any relative paths
               incCheck = Path.GetFullPath(incCheck);

-              result.Append("-include \"");
-              result.Append(incCheck);
-              result.Append("\" ");
+              result.Append("-include ");
+              result.Append(addQuotes(incCheck));
+              result.Append(" ");
             }
           }
         }
@@ -747,16 +762,16 @@ namespace ClangVSx
         {
           if (inc.Length > 0)
           {
-            uniqueDirs.Add(Path.GetFullPath(inc.Replace("\\", "/")));
+              uniqueDirs.Add(Path.GetFullPath(sanitizePath(inc.Replace("\\", "/"))));
           }
         }

         foreach (String inc in uniqueDirs)
         {
-          defaultCompilerString.Append("-isystem \"");
-          defaultCompilerString.Append(inc);
-          defaultCompilerString.Replace("\\", "", defaultCompilerString.Length - 1, 1);
-          defaultCompilerString.Append("\" ");
+          defaultCompilerString.Append("-isystem ");
+          defaultCompilerString.Append(addQuotes(inc));
+          defaultCompilerString.Replace("\\", "", defaultCompilerString.Length - 2, 1);
+          defaultCompilerString.Append(" ");
         }
       }
       defaultCompilerString.Append(" -fms-compatibility ");

Trass3r avatar Dec 13 '12 18:12 Trass3r

Now it manages to run clang, but preprocessed output is always empty.

Trass3r avatar Dec 13 '12 18:12 Trass3r

Looks like it didn't like the show compiler phases switch.

Trass3r avatar Dec 14 '12 19:12 Trass3r