diff --git a/src/app/FakeLib/ChangeWatcher.fs b/src/app/FakeLib/ChangeWatcher.fs index 875b992f847..594f4b3d8a8 100644 --- a/src/app/FakeLib/ChangeWatcher.fs +++ b/src/app/FakeLib/ChangeWatcher.fs @@ -19,6 +19,17 @@ let private handleWatcherEvents (status : FileStatus) (onChange : FileChange -> Name = e.Name Status = status }) +let private calcDirsToWatch fileIncludes = + let dirsToWatch = fileIncludes.Includes |> Seq.map (fun file -> Globbing.getRoot fileIncludes.BaseDirectory file) + + // remove subdirectories from watch list so that we don't get duplicate file watchers running + dirsToWatch + |> Seq.filter (fun d -> + dirsToWatch + |> Seq.exists (fun p -> d.StartsWith p && p <> d) + |> not) + |> Seq.toList + /// Watches the for changes in the matching files. /// Returns an IDisposable which allows to dispose all FileSystemWatchers. /// @@ -39,14 +50,8 @@ let private handleWatcherEvents (status : FileStatus) (onChange : FileChange -> /// ) /// let WatchChanges (onChange : FileChange seq -> unit) (fileIncludes : FileIncludes) = - let dirsToWatch = fileIncludes.Includes |> Seq.map (fun file -> Globbing.getRoot fileIncludes.BaseDirectory file) - - // remove subdirectories from watch list so that we don't get duplicate file watchers running - let dirsToWatch = - dirsToWatch |> Seq.filter (fun d -> - dirsToWatch - |> Seq.exists (fun p -> p.StartsWith d && p <> d) - |> not) + let dirsToWatch = fileIncludes |> calcDirsToWatch + tracefn "dirs to watch: %A" dirsToWatch // we collect changes in a mutable ref cell and wait for a few milliseconds to @@ -84,7 +89,7 @@ let WatchChanges (onChange : FileChange seq -> unit) (fileIncludes : FileInclude (timer:System.Timers.Timer).Start() ) let watchers = - dirsToWatch |> List.ofSeq |> List.map (fun dir -> + dirsToWatch |> List.map (fun dir -> tracefn "watching dir: %s" dir let watcher = new FileSystemWatcher(FullName dir, "*.*") diff --git a/src/test/Test.FAKECore/ChangeWatcherSpecs.cs b/src/test/Test.FAKECore/ChangeWatcherSpecs.cs new file mode 100644 index 00000000000..c26c7429085 --- /dev/null +++ b/src/test/Test.FAKECore/ChangeWatcherSpecs.cs @@ -0,0 +1,35 @@ +using System.Linq; +using Fake; +using Machine.Specifications; +using Microsoft.FSharp.Collections; + +namespace Test.FAKECore +{ + public class when_calculating_directories_to_watch + { + It should_watch_multiple_directories = + () => + { + var includes = ListModule.OfArray(new[] { @"test1\bin\*.dll", @"test2\bin\*.dll", }); + var fileIncludes = new FileSystem.FileIncludes(@"C:\Project", includes, ListModule.Empty()); + + var dirsToWatch = ChangeWatcher.calcDirsToWatch(fileIncludes); + + dirsToWatch.Length.ShouldEqual(2); + dirsToWatch.ShouldContain(Fake.Globbing.normalizePath(@"C:\Project\test1\bin")); + dirsToWatch.ShouldContain(Fake.Globbing.normalizePath(@"C:\Project\test2\bin")); + }; + + It should_only_take_the_most_root_path_when_multiple_directories_share_a_root = + () => + { + var includes = ListModule.OfArray(new[] { @"tests\**\test1\bin\*.dll", @"tests\test2\bin\*.dll", }); + var fileIncludes = new FileSystem.FileIncludes(@"C:\Project", includes, ListModule.Empty()); + + var dirsToWatch = ChangeWatcher.calcDirsToWatch(fileIncludes); + + dirsToWatch.Length.ShouldEqual(1); + dirsToWatch.ShouldContain(Fake.Globbing.normalizePath(@"C:\Project\tests")); + }; + } +} diff --git a/src/test/Test.FAKECore/Test.FAKECore.csproj b/src/test/Test.FAKECore/Test.FAKECore.csproj index a0ef4dc1457..164dc79736e 100644 --- a/src/test/Test.FAKECore/Test.FAKECore.csproj +++ b/src/test/Test.FAKECore/Test.FAKECore.csproj @@ -67,6 +67,7 @@ +