Skip to content

Commit

Permalink
implemented CscPath for csc task, added csc6 sample
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegZee committed Jan 26, 2017
1 parent c2b1a87 commit a4d254a
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 14 deletions.
9 changes: 7 additions & 2 deletions core/DotnetTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ module DotNetTaskTypes =
CommandArgs: string list
/// Build fails on compile error.
FailOnError: bool
/// Path to csc executable
CscPath: string option
}
// see http://msdn.microsoft.com/en-us/library/78f4aasd.aspx
// defines, optimize, warn, debug, platform
Expand Down Expand Up @@ -126,6 +128,7 @@ module DotnetTasks =
TargetFramework = null
CommandArgs = []
FailOnError = true
CscPath = None
}

module internal Impl =
Expand Down Expand Up @@ -326,9 +329,10 @@ module DotnetTasks =
yield "@" + rspFile
}
let commandLine = commandLineArgs |> String.concat " "
let cscTool = settings.CscPath |> function | Some v -> v | _ -> fwkInfo.CscTool

do! trace Info "compiling '%s' using framework '%s'" outFile.Name fwkInfo.Version
do! trace Debug "Command line: '%s %s'" fwkInfo.CscTool (args |> Seq.map Impl.escapeArgument |> String.concat "\r\n\t")
do! trace Debug "Command line: '%s %s'" cscTool (args |> Seq.map Impl.escapeArgument |> String.concat "\r\n\t")

let options = {
SystemTasks.SysOptions.Default with
Expand All @@ -337,7 +341,7 @@ module DotnetTasks =
ErrOutLevel = Impl.levelFromString Level.Verbose
EnvVars = fwkInfo.EnvVars
}
let! exitCode = SystemTasks._system options fwkInfo.CscTool commandLine
let! exitCode = SystemTasks._system options cscTool commandLine

do! trace Level.Verbose "Deleting temporary files"
seq {
Expand Down Expand Up @@ -375,6 +379,7 @@ module DotnetTasks =

[<CustomOperation("define")>] member this.Define(s:CscSettingsType, value) = {s with Define = value}
[<CustomOperation("unsafe")>] member this.Unsafe(s:CscSettingsType, value) = {s with Unsafe = value}
[<CustomOperation("cscpath")>] member this.CscPath(s:CscSettingsType, value) = {s with CscPath = Some value}

member this.Bind(x, f) = f x
member this.Yield(()) = CscSettings
Expand Down
22 changes: 12 additions & 10 deletions core/FileTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,25 @@ let cp = copyFile
let copyFiles (src: string list) targetDir =

// TODO check how should it process dependencies
// TODO print the file name (in Verbose mode)
// TODO currently if flattens target files layout so that
// /src/**/*.c files will be stored without preserving folders structure.

let copyFile tgt_folder fi =
// TODO this
let tgt = Path.Combine(tgt_folder, fi |> File.getFileName)
File.Copy((File.getFullName fi), tgt, true)

let copyByMask root mask =
let (Filelist files) = Fileset.ls mask |> (toFileList root)
files |> List.iter (copyFile targetDir)

action {
let! options = getCtxOptions()
do! trace Level.Info "[copyFiles] '%A' -> '%s'" src targetDir

let! ctx = getCtx()
let logVerbose = ctx.Logger.Log Verbose "%s"

let copyFile target file =
let tgt = Path.Combine(target, file |> File.getFileName)
ctx.Logger.Log Verbose "Copying %s..." (file |> File.getName)
File.Copy((File.getFullName file), tgt, true)

let copyByMask root mask =
let (Filelist files) = Fileset.ls mask |> (toFileList root)
files |> List.iter (copyFile targetDir)

src |> List.iter (copyByMask options.ProjectRoot)
}

2 changes: 1 addition & 1 deletion core/SystemTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module SystemTasks =

let useClr: ExecOptionsFn = fun o -> {o with UseClr = true}
let checkErrorLevel: ExecOptionsFn = fun o -> {o with FailOnErrorLevel = true}
let workingDir dir: ExecOptionsFn = fun o -> {o with WorkingDir = dir}
let workingDir dir: ExecOptionsFn = fun o -> {o with WorkingDir = Some dir}

[<AutoOpen>]
module CommonTasks =
Expand Down
3 changes: 3 additions & 0 deletions docs/implnotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,20 @@ do! _system [shellcmd] "dir" |> CheckErrorLevel
### Other ideas

// or even that:
```
_system [fail_on_error; shellcmd] "dir"
// where shellcmd and fail_on_error are functions
```

Idea #3 (orthogonal): provide an option for _system function to fail in case non-zero errorcode.

```
do! _system [fail_on_error; shellcmd; startin "./bin"] "dir"
// where shellcmd and fail_on_error are functions
```

### Ideas

Implemented IgnoreErrors.

* ExecContext option to ignore all errors
Expand Down
5 changes: 4 additions & 1 deletion docs/todo.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## TODOs and ideas

* put the rule's target file to ExecContext so that target could be get as let! target = getTarget()
* change the first page to a tutorial with script and usage examples
* <== for running tasks one by one. Current one runs in parallel only.

* <<< for running tasks one by one. Current one runs in parallel only.
* rules should accept #seq not just the list
* switch development to mono under windows
* idea: xake script as a task. Override/inherit variables. How to change variable on the fly is the original question. (we have got it out of the box, need more info)
Expand Down Expand Up @@ -34,6 +36,7 @@

## Done (top is recent)

* CscPath setting (cscpath in csc builder) allowing to define compiler path
* allow to specify F# compiler version
* overriding .xake database file name by options.DbFileName which defines relative db file name
* redirect compiler output to [Info] category, parse output and log warnings and errors respectively
Expand Down
18 changes: 18 additions & 0 deletions samples/csc6/build.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#r @"../../bin/Xake.Core.dll"

open Xake

do xake ExecOptions.Default {

var "NETFX-TARGET" "2.0"
filelog "build.log" Logging.Diag

rules [
"main" ==> ["hello.exe"]
"hello.exe" *> fun file -> csc {
cscpath @"packages\Microsoft.Net.Compilers\tools\csc.exe"
out file
src !! "hello_cs6.cs"
}
]
}
2 changes: 2 additions & 0 deletions samples/csc6/csc6.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
..\..\.paket\paket.exe restore
fsi build.fsx
12 changes: 12 additions & 0 deletions samples/csc6/hello_cs6.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using static System.Console;

class Program
{
public static void Main()
{
var username = "world";
WriteLine($"Hello, {username}!");

WriteLine($"{username.GetType().Assembly.FullName}");
}
}
3 changes: 3 additions & 0 deletions samples/csc6/paket.dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source https://www.nuget.org/api/v2/

nuget Microsoft.Net.Compilers
3 changes: 3 additions & 0 deletions samples/csc6/paket.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NUGET
remote: https://www.nuget.org/api/v2
Microsoft.Net.Compilers (1.3.2)

0 comments on commit a4d254a

Please sign in to comment.