From 08ca88b3130231e266b9fb6322beaf11f038480b Mon Sep 17 00:00:00 2001 From: Ben Taylor Date: Fri, 15 Jan 2016 22:01:12 +0000 Subject: [PATCH 1/2] Fix #992 test failure when space in temp path. Tests invoking csc.exe were failing when paths contained a space. Updated csc invocation to ensure quote references, output path and input file paths when a space is detected and not already quoted. --- src/app/FakeLib/CscHelper.fs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/app/FakeLib/CscHelper.fs b/src/app/FakeLib/CscHelper.fs index a65799b8ba6..7c067553fa9 100644 --- a/src/app/FakeLib/CscHelper.fs +++ b/src/app/FakeLib/CscHelper.fs @@ -78,11 +78,21 @@ let cscExe toolPath (srcFiles : string list) (opts : string list) : int = /// Target = ... /// ... }) let csc (setParams : CscParams -> CscParams) (inputFiles : string list) : int = - let inputFiles = inputFiles |> Seq.toList + // Helper to quote a path with spaces in it, if not already quoted. See https://github.com/fsharp/FAKE/issues/992 + let ensureQuotedPath (path : string) = + // Sensitive to being backwards compatible with people that are using + // Csc AND quoting their paths. Only quote if space in path and quotes not detected. + // MAYBE this should go in the FileSystemHelper module? + if path.Contains(" ") then + if (path.StartsWith("\"") && path.EndsWith("\"")) || (path.StartsWith("'") && path.EndsWith("'")) then path + else sprintf "\"%s\"" path + else path + + let inputFiles = inputFiles |> Seq.map ensureQuotedPath |> Seq.toList let taskDesc = inputFiles |> separated ", " let cscParams = setParams CscParams.Default - let output = if cscParams.Output <> "" then [sprintf "/out:%s" cscParams.Output] else [] + let output = if cscParams.Output <> "" then [sprintf "/out:%s" (ensureQuotedPath cscParams.Output)] else [] let target = match cscParams.Target with | Exe -> [ "/target:exe" ] @@ -98,7 +108,7 @@ let csc (setParams : CscParams -> CscParams) (inputFiles : string list) : int = | AnyCpu -> [ "/platform:anycpu" ] let references = cscParams.References - |> List.map (fun r -> sprintf "/reference:%s" r) + |> List.map (ensureQuotedPath >> (sprintf "/reference:%s")) let debug = if cscParams.Debug then [ "/debug" ] else [] let argList = output @ target @ platform @ references @ debug @ cscParams.OtherParams From 6f66ec7a9f44ee35103ef906aa013dd9d12570f6 Mon Sep 17 00:00:00 2001 From: Ben Taylor Date: Sat, 16 Jan 2016 12:12:32 +0000 Subject: [PATCH 2/2] Trim paths provided to Csc. Change for #992. Don't think anyone would intentionally pad a path and doubt Csc would care if they did, so trim paths. This change avoids us quoting a path that is quoted, but with whitespace at one end, the other or both. --- src/app/FakeLib/CscHelper.fs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/FakeLib/CscHelper.fs b/src/app/FakeLib/CscHelper.fs index 7c067553fa9..f6b8e1d79fa 100644 --- a/src/app/FakeLib/CscHelper.fs +++ b/src/app/FakeLib/CscHelper.fs @@ -79,20 +79,21 @@ let cscExe toolPath (srcFiles : string list) (opts : string list) : int = /// ... }) let csc (setParams : CscParams -> CscParams) (inputFiles : string list) : int = // Helper to quote a path with spaces in it, if not already quoted. See https://github.com/fsharp/FAKE/issues/992 - let ensureQuotedPath (path : string) = + let ensureTrimQuotedPath (path : string) = // Sensitive to being backwards compatible with people that are using // Csc AND quoting their paths. Only quote if space in path and quotes not detected. // MAYBE this should go in the FileSystemHelper module? + let path = path.Trim() if path.Contains(" ") then if (path.StartsWith("\"") && path.EndsWith("\"")) || (path.StartsWith("'") && path.EndsWith("'")) then path else sprintf "\"%s\"" path else path - let inputFiles = inputFiles |> Seq.map ensureQuotedPath |> Seq.toList + let inputFiles = inputFiles |> Seq.map ensureTrimQuotedPath |> Seq.toList let taskDesc = inputFiles |> separated ", " let cscParams = setParams CscParams.Default - let output = if cscParams.Output <> "" then [sprintf "/out:%s" (ensureQuotedPath cscParams.Output)] else [] + let output = if cscParams.Output <> "" then [sprintf "/out:%s" (ensureTrimQuotedPath cscParams.Output)] else [] let target = match cscParams.Target with | Exe -> [ "/target:exe" ] @@ -108,7 +109,7 @@ let csc (setParams : CscParams -> CscParams) (inputFiles : string list) : int = | AnyCpu -> [ "/platform:anycpu" ] let references = cscParams.References - |> List.map (ensureQuotedPath >> (sprintf "/reference:%s")) + |> List.map (ensureTrimQuotedPath >> (sprintf "/reference:%s")) let debug = if cscParams.Debug then [ "/debug" ] else [] let argList = output @ target @ platform @ references @ debug @ cscParams.OtherParams