Skip to content

Commit

Permalink
Merge pull request #1076 from bentayloruk/fix-992-quote-csc-paths
Browse files Browse the repository at this point in the history
Fix #992 test failure when space in temp path.
  • Loading branch information
forki committed Jan 17, 2016
2 parents 13d173a + 6f66ec7 commit 492a157
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/app/FakeLib/CscHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,22 @@ 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 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 ensureTrimQuotedPath |> 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" (ensureTrimQuotedPath cscParams.Output)] else []
let target =
match cscParams.Target with
| Exe -> [ "/target:exe" ]
Expand All @@ -98,7 +109,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 (ensureTrimQuotedPath >> (sprintf "/reference:%s"))
let debug = if cscParams.Debug then [ "/debug" ] else []
let argList =
output @ target @ platform @ references @ debug @ cscParams.OtherParams
Expand Down

0 comments on commit 492a157

Please sign in to comment.