Skip to content

Commit e6ff0a3

Browse files
committed
new 'shell' with wider options set compared to 'system'
1 parent dfa16c1 commit e6ff0a3

File tree

7 files changed

+69
-39
lines changed

7 files changed

+69
-39
lines changed

XakeLibTests/MiscTests.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ open System.IO
44
open NUnit.Framework
55

66
open Xake
7+
open Xake.SystemTasks
78

89
let xakeOptions = ExecOptions.Default
910

@@ -92,7 +93,7 @@ let ``script exits with errorlevel on script failure``() =
9293
rules [
9394
"one" => action {
9495
do! need ["1/script.fsx"]
95-
let! ec = system fsiApp ["1/script.fsx"]
96+
let! ec = system id fsiApp ["1/script.fsx"]
9697
errorCode := ec
9798
}
9899
"1/script.fsx" *> fun src -> action {

XakeLibTests/XakeScriptTests.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ let ``allows to define target in parameters``() =
202202
Assert.AreEqual(0, !mainCount)
203203
Assert.AreEqual(1, !xxxCount)
204204

205-
[<Test; Explicit("Fails on unix")>]
205+
[<Test; Platform("Win")>]
206206
let ``target could be a relative``() =
207207

208208
let needExecuteCount = ref 0
@@ -275,7 +275,7 @@ let ``matching groups in rule name``(tgt,mask,expect:string) =
275275

276276
type Runtime = {Ver: string; Folder: string}
277277

278-
[<Test; Explicit("Fails on unix")>]
278+
[<Test; Platform("Win")>]
279279
let ``target could be a relative2``() =
280280

281281
let needExecuteCount = ref 0

build.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ do xake {ExecOptions.Default with Vars = ["NETFX-TARGET", "4.5"]; FileLog = "bui
7979
includes "WorkerPool.fs"
8080
includes "Progress.fs"
8181
includes "XakeScript.fs"
82-
includes "CommonTasks.fs"
82+
includes "SystemTasks.fs"
8383
includes "FileTasks.fs"
8484
includes "ResourceFileset.fs"
8585
includes "DotNetFwk.fs"

core/DotNetFwk.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open System.IO
55

66
module (* internal *) pkg_config =
77

8-
open Xake.CommonTasks.impl
8+
open SystemTasks
99

1010
let private pkgcgf args =
1111
let outp = ref option<string>.None

core/DotnetTasks.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ module DotNetTaskTypes =
108108
[<AutoOpen>]
109109
module DotnetTasks =
110110

111-
open CommonTasks.impl
111+
open Xake.SystemTasks
112112

113113
/// Default setting for CSC task so that you could only override required settings
114114
let CscSettings = {
@@ -327,13 +327,13 @@ module DotnetTasks =
327327
do! trace Debug "Command line: '%s %s'" fwkInfo.CscTool (args |> Seq.map Impl.escapeArgument |> String.concat "\r\n\t")
328328

329329
let options = {
330-
SystemOptions.Default with
330+
SystemTasks.Options.Default with
331331
LogPrefix = "[CSC] "
332332
StdOutLevel = fun _ -> Level.Verbose
333333
ErrOutLevel = Impl.levelFromString Level.Verbose
334334
EnvVars = fwkInfo.EnvVars
335335
}
336-
let! exitCode = _system options fwkInfo.CscTool commandLine
336+
let! exitCode = SystemTasks._system options fwkInfo.CscTool commandLine
337337

338338
do! trace Level.Verbose "Deleting temporary files"
339339
seq {
@@ -477,12 +477,12 @@ module DotnetTasks =
477477
do! trace Debug "Command line: '%s'" args
478478

479479
let options = {
480-
SystemOptions.Default with
480+
SystemTasks.Options.Default with
481481
LogPrefix = pfx
482482
StdOutLevel = fun _ -> Level.Info
483483
ErrOutLevel = Impl.levelFromString Level.Verbose
484484
}
485-
let! exitCode = args |> _system options fwkInfo.MsbuildTool
485+
let! exitCode = args |> SystemTasks._system options fwkInfo.MsbuildTool
486486

487487
do! trace Info "%s done '%s'" pfx settings.BuildFile
488488
if exitCode <> 0 then
@@ -595,13 +595,13 @@ module DotnetTasks =
595595
do! trace Debug "Command line: '%s %s'" fsc (args |> Seq.map Impl.escapeArgument |> String.concat "\r\n\t")
596596

597597
let options = {
598-
SystemOptions.Default with
598+
SystemTasks.Options.Default with
599599
LogPrefix = "[FSC] "
600600
StdOutLevel = fun _ -> Level.Verbose
601601
ErrOutLevel = Impl.levelFromString Level.Verbose
602602
EnvVars = fwkInfo.EnvVars
603603
}
604-
let! exitCode = _system options fsc (args |> String.concat " ")
604+
let! exitCode = SystemTasks._system options fsc (args |> String.concat " ")
605605

606606
do! trace Level.Verbose "Deleting temporary files"
607607
seq {
Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// common tasks
2+
namespace Xake
23

3-
[<AutoOpen>]
4-
module Xake.CommonTasks
5-
6-
module internal impl =
7-
4+
module SystemTasks =
85
open Xake
96
open Xake.Env
7+
108
open System.Diagnostics
119

1210
// internal implementation
13-
let _pexec handleStd handleErr cmd args (envvars:(string * string) list) =
11+
let internal _pexec handleStd handleErr cmd args (envvars:(string * string) list) =
1412
let pinfo =
1513
ProcessStartInfo
1614
(cmd, args,
@@ -42,27 +40,27 @@ module internal impl =
4240
return proc.ExitCode
4341
}
4442

45-
type SystemOptions = {
43+
type Options = {
4644
LogPrefix:string;
4745
StdOutLevel: string -> Level; ErrOutLevel: string -> Level;
4846
EnvVars: (string * string) list
4947

5048
/// Indicates command has to be executed under mono/.net runtime
5149
UseClr: bool
5250
FailOnErrorLevel: bool
53-
}
51+
}
5452
with static member Default = {
55-
LogPrefix = ""; StdOutLevel = (fun _ -> Level.Info); ErrOutLevel = (fun _ -> Level.Error);
56-
EnvVars = []
57-
UseClr = false
58-
FailOnErrorLevel = false
53+
LogPrefix = ""; StdOutLevel = (fun _ -> Level.Info); ErrOutLevel = (fun _ -> Level.Error);
54+
EnvVars = []
55+
UseClr = false
56+
FailOnErrorLevel = false
5957
}
6058

6159
/// <summary>
6260
/// Executes system command. E.g. '_system SystemOptions "dir" []'
6361
/// </summary>
6462
let _system settings cmd args =
65-
63+
6664
let isExt file ext = System.IO.Path.GetExtension(file).Equals(ext, System.StringComparison.OrdinalIgnoreCase)
6765

6866
action {
@@ -87,20 +85,32 @@ module internal impl =
8785
return errorlevel
8886
}
8987

90-
// TODO expose settings
91-
open impl
88+
type OptionsFn = Options -> Options
9289

93-
/// <summary>
94-
/// Executes external process and waits until it completes
95-
/// </summary>
96-
/// <param name="cmd">Command or executable name.</param>
97-
/// <param name="args">Command arguments.</param>
98-
let system cmd args =
99-
action {
100-
do! trace Info "[system] starting '%s'" cmd
101-
let! exitCode = _system SystemOptions.Default cmd (args |> String.concat " ")
102-
do! trace Info "[system] completed '%s' exitcode: %d" cmd exitCode
90+
/// <summary>
91+
/// Executes external process and waits until it completes
92+
/// </summary>
93+
/// <param name="opts">Options setters</param>
94+
/// <param name="cmd">Command or executable name.</param>
95+
/// <param name="args">Command arguments.</param>
96+
let system (opts: OptionsFn) (cmd: string) (args: string seq) =
97+
action {
98+
do! trace Info "[shell.run] starting '%s'" cmd
99+
let! exitCode = _system (opts Options.Default) cmd (args |> String.concat " ")
100+
do! trace Info "[shell.run] completed '%s' exitcode: %d" cmd exitCode
101+
102+
return exitCode
103+
}
103104

104-
return exitCode
105-
}
105+
let useClr: OptionsFn = fun o -> {o with UseClr = true}
106+
let checkErrorLevel: OptionsFn = fun o -> {o with FailOnErrorLevel = true}
106107

108+
[<AutoOpen>]
109+
module CommonTasks =
110+
/// <summary>
111+
/// Executes external process and waits until it completes
112+
/// </summary>
113+
/// <param name="cmd">Command or executable name.</param>
114+
/// <param name="args">Command arguments.</param>
115+
[<System.Obsolete("Use shell id... instead")>]
116+
let system cmd args = SystemTasks.system id cmd args

docs/tasks.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
// TBD
44

5+
### Common tasks
6+
7+
#### Xake.SystemTasks
8+
Module shell provides actions related to command shell.
9+
Usage:
10+
```fsharp
11+
open Xake.SystemTasks
12+
let! errorlevel = system (fun o -> o) "ls" ["-lr"]
13+
```
14+
15+
There two predefined function for passing task settings:
16+
```fsharp
17+
open Xake.SystemTasks
18+
let! errorlevel = system (useClr >> checkErrorLevel) "ls" ["-lr"]
19+
```
20+
The first sets `UseClr` which instructs system command to run `mono <cmd>`. The second one instructs **system** to fail when command returned non-zero errorlevel.
21+
22+
> Notice there's another `system` action in Xake.CommonTasks. It lacks the first parameter (for settings) and is marked as obsolete.
23+
524
### File tasks
625

726
These tasks allows to perform various file operations. Using these tasks ensures the dependencies are properly resolved are recorded.

0 commit comments

Comments
 (0)