Skip to content

Commit

Permalink
Implement IEnumerable in FileIncludes and therefor make explicit "Sca…
Browse files Browse the repository at this point in the history
…n" obsolete - No need to scan in the build.fsx
  • Loading branch information
forki committed Nov 5, 2013
1 parent 8c3630e commit 5def167
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 91 deletions.
3 changes: 1 addition & 2 deletions Samples/ContinuousDeploymentWebsite/build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ Target "AssemblyInfo" (fun _ ->
)

Target "BuildApp" (fun _ ->
!+ @"src\app\**\*.csproj"
!! @"src\app\**\*.csproj"
++ @"src\app\**\*.fsproj"
|> Scan
|> MSBuildRelease buildDir "Build"
|> Log "Build-Output: "
)
Expand Down
10 changes: 4 additions & 6 deletions Samples/SideBySideSpecification/build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ let fxCopRoot = @".\Tools\FxCop\FxCopCmd.exe"

// Filesets
let appReferences =
!+ @"src\app\**\*.csproj"
!! @"src\app\**\*.csproj"
++ @"src\app\**\*.fsproj"
-- "**\*_Spliced*"
|> Scan
-- "**\*_Spliced*"

// version info
let version = "0.2" // or retrieve from CI server
Expand Down Expand Up @@ -61,9 +60,8 @@ Target "Test" (fun _ ->
)

Target "Deploy" (fun _ ->
!+ (buildDir + "\**\*.*")
-- "*.zip"
|> Scan
!! (buildDir + "\**\*.*")
-- "*.zip"
|> Zip buildDir (deployDir + "Calculator." + version + ".zip")
)

Expand Down
3 changes: 1 addition & 2 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@ Target "CopyLicense" (fun _ ->
)

Target "BuildZip" (fun _ ->
!+ (buildDir @@ @"**/*.*")
!! (buildDir @@ @"**/*.*")
-- "*.zip"
-- "**/*.pdb"
|> Scan
|> Zip buildDir deployZip
)

Expand Down
8 changes: 3 additions & 5 deletions help/fxcop.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ Open *build.fsx* from your Calculator sample folder and add a new target *FxCop*

Target "FxCop" (fun () ->
let assemblies =
!+ (buildDir + @"\**\*.dll")
!! (buildDir + @"\**\*.dll")
++ (buildDir + @"\**\*.exe")
|> Scan

FxCop
(fun p ->
Expand Down Expand Up @@ -44,9 +43,8 @@ If you want to let the build fail in the case that FxCop reports any errors or w

Target "FxCop" (fun () ->
let assemblies =
!+ (buildDir + @"\**\*.dll")
++ (buildDir + @"\**\*.exe")
|> Scan
!! (buildDir + @"\**\*.dll")
++ (buildDir + @"\**\*.exe")

FxCop
(fun p ->
Expand Down
5 changes: 2 additions & 3 deletions help/gettingstarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,8 @@ Now we want to deploy a *.zip file containing our application:
)

Target "Zip" (fun _ ->
!+ (buildDir + "\**\*.*")
-- "*.zip"
|> Scan
!! (buildDir + "\**\*.*")
-- "*.zip"
|> Zip buildDir (deployDir + "Calculator." + version + ".zip")
)

Expand Down
50 changes: 9 additions & 41 deletions help/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,48 +120,19 @@ These targets will be executed even if the build fails but have to be activated

### File includes

// Includes all *.csproj files under /src/app by using the !+ operator
!+ "src/app/**/*.csproj"
// Includes all *.csproj files under /src/app by using the !! operator
!! "src/app/**/*.csproj"

// Includes all *.csproj files under /src/app and /test with the ++ operator
!+ "src/app/**/*.csproj"
!! "src/app/**/*.csproj"
++ "test/**/*.csproj"

### File excludes

// Includes all files under /src/app but excludes *.zip files
!+ "src/app/**/*.*"
!! "src/app/**/*.*"
-- "*.zip"

### Scan vs. ScanImmediately

"FAKE - F# Make" provides two scan methods: Scan() and ScanImmediately().

Scan is a lazy method and evaluates the FileSet as late as possible ("on-demand").
If the FileSet is used twice, it will be reevaluated.

The following code defines a lazy FileSet:

// Includes all *.csproj files under /src/app and scans them lazy
let apps =
!+ "src/app/**/*.csproj"
|> Scan

The same FileSet by using the !! operator:

// Includes all *.csproj files under /src/app and scans them lazy
let apps = !! "src/app/**/*.csproj"

ScanImmediately() scans the FileSet immediatly at time of its definition
and memoizes it.

// Includes all files under /src/app but excludes *.zip files
// eager scan ==> All files memoized at the time of this definition
let files =
!+ "src/app/**/*.csproj"
-- "*.zip"
|> ScanImmediately

## UnitTests

### NUnit
Expand Down Expand Up @@ -236,9 +207,8 @@ You can read the [getting started guide](gettingstarted.html) to build such a sc

// Filesets
let appReferences =
!+ @"src\app\**\*.csproj"
++ @"src\app\**\*.fsproj"
|> Scan
!! @"src\app\**\*.csproj"
++ @"src\app\**\*.fsproj"

let testReferences = !! @"src\test\**\*.csproj"
Expand Down Expand Up @@ -301,19 +271,17 @@ You can read the [getting started guide](gettingstarted.html) to build such a sc
)

Target "FxCop" (fun _ ->
!+ (buildDir + @"\**\*.dll")
++ (buildDir + @"\**\*.exe")
|> Scan
!! (buildDir + @"\**\*.dll")
++ (buildDir + @"\**\*.exe")
|> FxCop (fun p ->
{p with
ReportFileName = testDir + "FXCopResults.xml";
ToolPath = fxCopRoot})
)

Target "Deploy" (fun _ ->
!+ (buildDir + "\**\*.*")
!! (buildDir + "\**\*.*")
-- "*.zip"
|> Scan
|> Zip buildDir (deployDir + "Calculator." + version + ".zip")
)

Expand Down
3 changes: 1 addition & 2 deletions src/app/FakeLib/FileHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ let DeleteDir path =
let dir = directoryInfo path
if dir.Exists then
// set all files readonly = false
!+ "/**/*.*"
!! "/**/*.*"
|> SetBaseDir dir.FullName
|> Scan
|> (SetReadOnly false)

logfn "Deleting %s" dir.FullName
Expand Down
37 changes: 19 additions & 18 deletions src/app/FakeLib/FileSet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,19 @@
/// Contains abstractions which allow to use file globbing.
module Fake.FileSetHelper

open System
open System.IO
open System.Globalization
open System.Text
open System.Text.RegularExpressions

/// The FileSet is eagerly loaded into a list of strings.
/// The scan is only done once.
type EagerFileSet = string list

/// The FileSet is lazy loaded into a sequence of strings.
/// Every time the FileSet is used it scans again.
type LazyFileSet = string seq

/// [omit]
/// Internal representation
type RegexEntry =
{ IsRecursive : bool;
BaseDirectory: string;
Pattern: string}

/// Internal representation of a file set
type FileIncludes =
{ BaseDirectories: string list;
Includes: string list;
Excludes: string list}

/// Patterns can use either / \ as a directory separator.
/// This function creates a StringBuilder which replaces both of these characters with Path.DirectorySeparatorChar
let cleanPathBuilder (path:string) =
Expand Down Expand Up @@ -339,16 +326,28 @@ let Log message files = files |> Seq.iter (log << sprintf "%s%s" message)

/// The default base directory (the current directory).
let DefaultBaseDir = Path.GetFullPath "."

/// Internal representation of a file set
type FileIncludes =
{ BaseDirectories: string list;
Includes: string list;
Excludes: string list}

interface IEnumerable<string> with
member this.GetEnumerator() = (Files this.BaseDirectories this.Includes this.Excludes).GetEnumerator()
member this.GetEnumerator() = (Files this.BaseDirectories this.Includes this.Excludes).GetEnumerator():> System.Collections.IEnumerator


/// Include files
let Include x =
{ BaseDirectories = [DefaultBaseDir];
Includes = [x];
Excludes = []}
Excludes = []}

/// Lazy scan for include files.
/// Will be processed at the time when needed.
let Scan includes : LazyFileSet = Files includes.BaseDirectories includes.Includes includes.Excludes
[<Obsolete("FileIncludes implement IEnumerable<string> so explicit scanning is not needed")>]
let Scan files = files

/// Adds a directory as baseDirectory for fileIncludes.
let AddBaseDir dir fileInclude = {fileInclude with BaseDirectories = dir::fileInclude.BaseDirectories}
Expand All @@ -357,9 +356,11 @@ let AddBaseDir dir fileInclude = {fileInclude with BaseDirectories = dir::fileIn
let SetBaseDir (dir:string) fileInclude = {fileInclude with BaseDirectories = [dir.TrimEnd(directorySeparator.[0])]}

/// Scans immediately for include files - all matching files will be memoized.
let ScanImmediately includes : EagerFileSet = Scan includes |> Seq.toList
[<Obsolete("FileIncludes implement IEnumerable<string> so explicit scanning is not needed. Just use Seq.toList")>]
let ScanImmediately includes = includes |> Seq.toList

/// Include prefix operator
[<Obsolete("!+ is obsolete - use !! instead")>]
let inline (!+) x = Include x

/// Add Include operator
Expand All @@ -369,7 +370,7 @@ let inline (++) x y = {x with Includes = y::x.Includes}
let inline (--) x y = {x with Excludes = y::x.Excludes}

/// Includes a single pattern and scans the files - !! x = AllFilesMatching x
let inline (!!) x = !+ x |> Scan
let inline (!!) x = Include x

/// Includes a single pattern and scans the files - !! x = AllFilesMatching x
let AllFilesMatching x = !! x
Expand Down
2 changes: 1 addition & 1 deletion src/app/FakeLib/MSBuildHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ let MSBuildWithProjectProperties outputPath (targets: string) (properties: strin
|> List.iter (fun project -> build (setBuildParam project) project)

// it makes no sense to output the root dir content here since it does not contain the build output
if isNotNullOrEmpty output then !! (outputPath @@ "/**/*.*") else Seq.empty
if isNotNullOrEmpty output then !! (outputPath @@ "/**/*.*") |> Seq.toList else []

/// Builds the given project files or solution files and collects the output files.
/// ## Parameters
Expand Down
5 changes: 2 additions & 3 deletions src/app/FakeLib/WiXHelper.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[<AutoOpen>]
[<AutoOpen>]
/// Contains tasks to create msi installers using the [WiX toolset](http://wixtoolset.org/)
module Fake.WiXHelper

Expand Down Expand Up @@ -123,10 +123,9 @@ let Light (parameters:WiXParams) outputFile wixObj =
/// ## Sample
/// Target "BuildSetup" (fun _ ->
/// // Copy all important files to the deploy directory
/// !+ (buildDir + "/**/*.dll")
/// !! (buildDir + "/**/*.dll")
/// ++ (buildDir + "/**/*.exe")
/// ++ (buildDir + "/**/*.config")
/// |> Scan
/// |> Copy deployPrepDir
///
/// // replace tags in a template file in order to generate a WiX script
Expand Down
5 changes: 1 addition & 4 deletions src/test/Test.FAKECore/FileHandling/BaseFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ public static List<string> Scan(string pattern, string baseDir)
{
TraceHelper.trace(string.Format("Scan for {0} in {1}:", pattern, baseDir));

var list =
FileSetHelper.Scan(
FileSetHelper.SetBaseDir(baseDir,
FileSetHelper.Include(pattern))).ToList();
var list = FileSetHelper.SetBaseDir(baseDir, FileSetHelper.Include(pattern)).ToList();
foreach (var file in list)
TraceHelper.trace(string.Format(" - {0}", file));
return list;
Expand Down
3 changes: 1 addition & 2 deletions src/test/Test.FAKECore/Globbing/Directories/build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
open System
open Fake

!+ "SampleApp\\bin\\*"
!! "SampleApp\\bin\\*"
// -- "SampleApp\\bin"
|> Scan
|> Seq.iter (printfn "scanned %s")
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.IO;
using System.Linq;
using System.Linq;
using Fake;
using Machine.Specifications;
using Test.FAKECore.FileHandling;

namespace Test.FAKECore.Globbing.Excludes
{
public class when_extracting_sample_zip : BaseFunctions
Expand Down

0 comments on commit 5def167

Please sign in to comment.