Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

chokes on quotes in paths #8

Open
Trass3r opened this issue Dec 11, 2012 · 5 comments
Open

chokes on quotes in paths #8

Trass3r opened this issue Dec 11, 2012 · 5 comments

Comments

@Trass3r
Copy link

Trass3r commented Dec 11, 2012

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

@Trass3r
Copy link
Author

Trass3r commented Dec 11, 2012

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

@ishani
Copy link
Owner

ishani commented Dec 11, 2012

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.

@Trass3r
Copy link
Author

Trass3r commented Dec 13, 2012

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
Copy link
Author

Trass3r commented Dec 13, 2012

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

@Trass3r
Copy link
Author

Trass3r commented Dec 14, 2012

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants