changeset 1473:d40066b38710

Handle spaces in filenames passed to GCC (caught by Zachary Tatlock)
author Adam Chlipala <adam@chlipala.net>
date Wed, 15 Jun 2011 09:52:06 -0400
parents 18d18a70821e
children 3d0cc841cafd
files src/compiler.sml tests/has space.ur tests/spacey.ur tests/spacey.urp
diffstat 4 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/compiler.sml	Tue Jun 14 08:54:45 2011 -0400
+++ b/src/compiler.sml	Wed Jun 15 09:52:06 2011 -0400
@@ -1307,6 +1307,8 @@
 
 val toSqlify = transform sqlify "sqlify" o toMono_opt2
 
+val escapeFilename = String.translate (fn #" " => "\\ " | #"\"" => "\\\"" | #"'" => "\\'" | ch => str ch)
+
 fun compileC {cname, oname, ename, libs, profile, debug, link = link'} =
     let
         val proto = Settings.currentProtocol ()
@@ -1318,10 +1320,10 @@
 
         val compile = "gcc " ^ Config.gccArgs ^ " -Wimplicit -Werror -O3 -fno-inline -I " ^ Config.includ
                       ^ " " ^ #compile proto
-                      ^ " -c " ^ cname ^ " -o " ^ oname
+                      ^ " -c " ^ escapeFilename cname ^ " -o " ^ escapeFilename oname
 
-        val link = "gcc -Werror -O3 -lm -pthread " ^ Config.gccArgs ^ " " ^ lib ^ " " ^ Config.openssl ^ " " ^ oname
-                   ^ " -o " ^ ename ^ " " ^ libs
+        val link = "gcc -Werror -O3 -lm -pthread " ^ Config.gccArgs ^ " " ^ lib ^ " " ^ Config.openssl ^ " " ^ escapeFilename oname
+                   ^ " -o " ^ escapeFilename ename ^ " " ^ libs
 
         val (compile, link) =
             if profile then
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/has space.ur	Wed Jun 15 09:52:06 2011 -0400
@@ -0,0 +1,2 @@
+fun main () : transaction page = return <xml>Hehe</xml>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/spacey.ur	Wed Jun 15 09:52:06 2011 -0400
@@ -0,0 +1,1 @@
+fun main () : transaction page = return <xml/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/spacey.urp	Wed Jun 15 09:52:06 2011 -0400
@@ -0,0 +1,3 @@
+exe has space.exe
+
+spacey