Skip to content

Commit a4d254a

Browse files
committed
implemented CscPath for csc task, added csc6 sample
1 parent c2b1a87 commit a4d254a

File tree

10 files changed

+65
-14
lines changed

10 files changed

+65
-14
lines changed

core/DotnetTasks.fs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ module DotNetTaskTypes =
3636
CommandArgs: string list
3737
/// Build fails on compile error.
3838
FailOnError: bool
39+
/// Path to csc executable
40+
CscPath: string option
3941
}
4042
// see http://msdn.microsoft.com/en-us/library/78f4aasd.aspx
4143
// defines, optimize, warn, debug, platform
@@ -126,6 +128,7 @@ module DotnetTasks =
126128
TargetFramework = null
127129
CommandArgs = []
128130
FailOnError = true
131+
CscPath = None
129132
}
130133

131134
module internal Impl =
@@ -326,9 +329,10 @@ module DotnetTasks =
326329
yield "@" + rspFile
327330
}
328331
let commandLine = commandLineArgs |> String.concat " "
332+
let cscTool = settings.CscPath |> function | Some v -> v | _ -> fwkInfo.CscTool
329333

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

333337
let options = {
334338
SystemTasks.SysOptions.Default with
@@ -337,7 +341,7 @@ module DotnetTasks =
337341
ErrOutLevel = Impl.levelFromString Level.Verbose
338342
EnvVars = fwkInfo.EnvVars
339343
}
340-
let! exitCode = SystemTasks._system options fwkInfo.CscTool commandLine
344+
let! exitCode = SystemTasks._system options cscTool commandLine
341345

342346
do! trace Level.Verbose "Deleting temporary files"
343347
seq {
@@ -375,6 +379,7 @@ module DotnetTasks =
375379

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

379384
member this.Bind(x, f) = f x
380385
member this.Yield(()) = CscSettings

core/FileTasks.fs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,25 @@ let cp = copyFile
5454
let copyFiles (src: string list) targetDir =
5555

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

61-
let copyFile tgt_folder fi =
62-
// TODO this
63-
let tgt = Path.Combine(tgt_folder, fi |> File.getFileName)
64-
File.Copy((File.getFullName fi), tgt, true)
65-
66-
let copyByMask root mask =
67-
let (Filelist files) = Fileset.ls mask |> (toFileList root)
68-
files |> List.iter (copyFile targetDir)
69-
7060
action {
7161
let! options = getCtxOptions()
7262
do! trace Level.Info "[copyFiles] '%A' -> '%s'" src targetDir
7363

64+
let! ctx = getCtx()
65+
let logVerbose = ctx.Logger.Log Verbose "%s"
66+
67+
let copyFile target file =
68+
let tgt = Path.Combine(target, file |> File.getFileName)
69+
ctx.Logger.Log Verbose "Copying %s..." (file |> File.getName)
70+
File.Copy((File.getFullName file), tgt, true)
71+
72+
let copyByMask root mask =
73+
let (Filelist files) = Fileset.ls mask |> (toFileList root)
74+
files |> List.iter (copyFile targetDir)
75+
7476
src |> List.iter (copyByMask options.ProjectRoot)
7577
}
7678

core/SystemTasks.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ module SystemTasks =
110110

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

115115
[<AutoOpen>]
116116
module CommonTasks =

docs/implnotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,20 @@ do! _system [shellcmd] "dir" |> CheckErrorLevel
8080
### Other ideas
8181

8282
// or even that:
83+
```
8384
_system [fail_on_error; shellcmd] "dir"
8485
// where shellcmd and fail_on_error are functions
8586
```
8687

8788
Idea #3 (orthogonal): provide an option for _system function to fail in case non-zero errorcode.
89+
8890
```
8991
do! _system [fail_on_error; shellcmd; startin "./bin"] "dir"
9092
// where shellcmd and fail_on_error are functions
9193
```
9294

9395
### Ideas
96+
9497
Implemented IgnoreErrors.
9598

9699
* ExecContext option to ignore all errors

docs/todo.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
## TODOs and ideas
22

3+
* put the rule's target file to ExecContext so that target could be get as let! target = getTarget()
34
* change the first page to a tutorial with script and usage examples
4-
* <== for running tasks one by one. Current one runs in parallel only.
5+
6+
* <<< for running tasks one by one. Current one runs in parallel only.
57
* rules should accept #seq not just the list
68
* switch development to mono under windows
79
* 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)
@@ -34,6 +36,7 @@
3436

3537
## Done (top is recent)
3638

39+
* CscPath setting (cscpath in csc builder) allowing to define compiler path
3740
* allow to specify F# compiler version
3841
* overriding .xake database file name by options.DbFileName which defines relative db file name
3942
* redirect compiler output to [Info] category, parse output and log warnings and errors respectively

samples/csc6/build.fsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#r @"../../bin/Xake.Core.dll"
2+
3+
open Xake
4+
5+
do xake ExecOptions.Default {
6+
7+
var "NETFX-TARGET" "2.0"
8+
filelog "build.log" Logging.Diag
9+
10+
rules [
11+
"main" ==> ["hello.exe"]
12+
"hello.exe" *> fun file -> csc {
13+
cscpath @"packages\Microsoft.Net.Compilers\tools\csc.exe"
14+
out file
15+
src !! "hello_cs6.cs"
16+
}
17+
]
18+
}

samples/csc6/csc6.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
..\..\.paket\paket.exe restore
2+
fsi build.fsx

samples/csc6/hello_cs6.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using static System.Console;
2+
3+
class Program
4+
{
5+
public static void Main()
6+
{
7+
var username = "world";
8+
WriteLine($"Hello, {username}!");
9+
10+
WriteLine($"{username.GetType().Assembly.FullName}");
11+
}
12+
}

samples/csc6/paket.dependencies

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source https://www.nuget.org/api/v2/
2+
3+
nuget Microsoft.Net.Compilers

samples/csc6/paket.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NUGET
2+
remote: https://www.nuget.org/api/v2
3+
Microsoft.Net.Compilers (1.3.2)

0 commit comments

Comments
 (0)