Skip to content

Commit

Permalink
Merge pull request #1978 from BlythMeister/fakeVarType
Browse files Browse the repository at this point in the history
FakeVar enhancements
  • Loading branch information
matthid authored Jun 5, 2018
2 parents 4a341f2 + 99e7402 commit c6ba91c
Show file tree
Hide file tree
Showing 63 changed files with 430 additions and 264 deletions.
49 changes: 48 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "dotnet:restore:fake.sln",
"group": "build",
"command": "dotnet restore FAKE.sln",
"type": "shell",
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
},
{
"label": "dotnet:build:fake.sln",
"group": "build",
Expand All @@ -11,7 +21,10 @@
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
"problemMatcher": "$msCompile",
"dependsOn": [
"dotnet:restore:fake.sln"
]
},
{
"label": "dotnet:run:unitTests",
Expand All @@ -22,6 +35,40 @@
"reveal": "always"
},
"problemMatcher": "$msCompile"
},
{
"label": "dotnet:run:commandLineUnitTests",
"group": "test",
"command": "dotnet run -p src/test/Fake.Core.CommandLine.UnitTests/Fake.Core.CommandLine.UnitTests.fsproj",
"type": "shell",
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
},
{
"label": "dotnet:run:integrationTests",
"group": "test",
"command": "dotnet run -p src/test/Fake.Core.IntegrationTests/Fake.Core.IntegrationTests.fsproj",
"type": "shell",
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
},
{
"label": "dotnet:run:allTests",
"group": "test",
"dependsOn": [
"dotnet:run:integrationTests",
"dotnet:run:commandLineUnitTests",
"dotnet:run:unitTests"
],
"type": "shell",
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
}
]
}
42 changes: 29 additions & 13 deletions Fake.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
Microsoft Visual Studio Solution File, Format Version 12.00

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2026
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "app", "app", "{7BFFAE76-DEE9-417A-A79B-6A6644C4553A}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Core.Context", "src/app/Fake.Core.Context/Fake.Core.Context.fsproj", "{D3D92ED7-C2B9-46D5-B611-A2CF0C30C8DB}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Core.FakeVar", "src/app/Fake.Core.FakeVar/Fake.Core.FakeVar.fsproj", "{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Core.Environment", "src/app/Fake.Core.Environment/Fake.Core.Environment.fsproj", "{A2C4A85F-24C4-4FFA-B165-4807B1127C4E}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Core.Process", "src/app/Fake.Core.Process/Fake.Core.Process.fsproj", "{DB09FF66-8750-40B8-9E25-70FADD9CF0BD}"
Expand Down Expand Up @@ -126,10 +129,10 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Tools.Pickles", "src/a
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{03CB61B6-EBB8-4C4A-B6A3-0D84D1F78A92}"
ProjectSection(SolutionItems) = preProject
.gitlab-ci.yml = .gitlab-ci.yml
build.fsx = build.fsx
paket.lock = paket.lock
paket.dependencies = paket.dependencies
.gitlab-ci.yml = .gitlab-ci.yml
paket.lock = paket.lock
RELEASE_NOTES.md = RELEASE_NOTES.md
EndProjectSection
EndProject
Expand All @@ -139,9 +142,9 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Windows.Registry", "sr
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.DotNet.Fsc", "src/app/Fake.DotNet.Fsc/Fake.DotNet.Fsc.fsproj", "{32A82EF2-BB35-40A2-9418-904ECFC1EF47}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.BuildServer.GitLab", "src/app/Fake.BuildServer.GitLab/Fake.BuildServer.GitLab.fsproj", "{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.BuildServer.GitLab", "src/app/Fake.BuildServer.GitLab/Fake.BuildServer.GitLab.fsproj", "{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "fake-cli", "src/app/fake-cli/fake-cli.fsproj", "{9E26B2AE-856A-42B6-9670-8766919F7D25}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "fake-cli", "src/app/fake-cli/fake-cli.fsproj", "{9E26B2AE-856A-42B6-9670-8766919F7D25}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -165,6 +168,18 @@ Global
{D3D92ED7-C2B9-46D5-B611-A2CF0C30C8DB}.Release|x64.Build.0 = Release|Any CPU
{D3D92ED7-C2B9-46D5-B611-A2CF0C30C8DB}.Release|x86.ActiveCfg = Release|Any CPU
{D3D92ED7-C2B9-46D5-B611-A2CF0C30C8DB}.Release|x86.Build.0 = Release|Any CPU
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}.Debug|x64.ActiveCfg = Debug|Any CPU
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}.Debug|x64.Build.0 = Debug|Any CPU
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}.Debug|x86.ActiveCfg = Debug|Any CPU
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}.Debug|x86.Build.0 = Debug|Any CPU
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}.Release|Any CPU.Build.0 = Release|Any CPU
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}.Release|x64.ActiveCfg = Release|Any CPU
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}.Release|x64.Build.0 = Release|Any CPU
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}.Release|x86.ActiveCfg = Release|Any CPU
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF}.Release|x86.Build.0 = Release|Any CPU
{A2C4A85F-24C4-4FFA-B165-4807B1127C4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2C4A85F-24C4-4FFA-B165-4807B1127C4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2C4A85F-24C4-4FFA-B165-4807B1127C4E}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -863,16 +878,16 @@ Global
{32A82EF2-BB35-40A2-9418-904ECFC1EF47}.Release|x86.Build.0 = Release|Any CPU
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Debug|x64.ActiveCfg = Debug|x64
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Debug|x64.Build.0 = Debug|x64
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Debug|x86.ActiveCfg = Debug|x86
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Debug|x86.Build.0 = Debug|x86
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Debug|x64.ActiveCfg = Debug|Any CPU
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Debug|x64.Build.0 = Debug|Any CPU
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Debug|x86.ActiveCfg = Debug|Any CPU
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Debug|x86.Build.0 = Debug|Any CPU
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Release|Any CPU.Build.0 = Release|Any CPU
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Release|x64.ActiveCfg = Release|x64
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Release|x64.Build.0 = Release|x64
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Release|x86.ActiveCfg = Release|x86
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Release|x86.Build.0 = Release|x86
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Release|x64.ActiveCfg = Release|Any CPU
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Release|x64.Build.0 = Release|Any CPU
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Release|x86.ActiveCfg = Release|Any CPU
{F778A9E5-FC1A-4934-A6B9-98C84BE9A667}.Release|x86.Build.0 = Release|Any CPU
{9E26B2AE-856A-42B6-9670-8766919F7D25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E26B2AE-856A-42B6-9670-8766919F7D25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E26B2AE-856A-42B6-9670-8766919F7D25}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -891,6 +906,7 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D3D92ED7-C2B9-46D5-B611-A2CF0C30C8DB} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{1CEE1FC0-41F4-4F6C-A409-3849B30D57EF} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{A2C4A85F-24C4-4FFA-B165-4807B1127C4E} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{DB09FF66-8750-40B8-9E25-70FADD9CF0BD} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{FEDE1F15-C0A5-4DA1-B20D-0A0C28F6858E} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
Expand Down
6 changes: 3 additions & 3 deletions src/app/Fake.Azure.Kudu/Kudu.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ type WebJobType = Scheduled | Continuous
do
Directory.ensure deploymentTemp |> ignore
Directory.ensure deploymentTarget |> ignore
Shell.CleanDir deploymentTemp
Shell.cleanDir deploymentTemp

/// <summary>
/// Stages a folder and all subdirectories into the temp deployment area, ready for deployment into the website.
/// </summary>
/// <param name="source">The source folder to copy.</param>
/// <param name="shouldInclude">A predicate which includes files from the folder. If the entire directory should be copied, this predicate should always return true.</param>
let stageFolder source shouldInclude =
Shell.CopyRecursive source deploymentTemp true
Shell.copyRecursive source deploymentTemp true
|> Seq.filter (not << shouldInclude)
|> Seq.iter File.Delete

Expand All @@ -47,7 +47,7 @@ let getWebJobPath webJobType webJobName =
let stageWebJob webJobType webJobName files =
let webJobPath = getWebJobPath webJobType webJobName
Directory.ensure webJobPath |> ignore
files |> Shell.CopyFiles webJobPath
files |> Shell.copyFiles webJobPath

/// Synchronises all staged files from the temporary deployment to the actual deployment, removing
/// any obsolete files, updating changed files and adding new files.
Expand Down
9 changes: 7 additions & 2 deletions src/app/Fake.Core.Context/Context.fs
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,31 @@ let forceFakeContext () =
invalidOp "no Fake Execution context was found. You can initialize one via Fake.Core.Context.setExecutionContext"
| RuntimeContext.Fake e -> e

[<System.Obsolete "Please use 'Fake.Core.FakeVar.get' instead">]
let getFakeVar name =
forceFakeContext()
|> getFakeContext name
|> Option.map (fun o -> o :?> 'a)


[<System.Obsolete "Please use 'Fake.Core.FakeVar.remove' instead">]
let removeFakeVar name =
forceFakeContext()
|> removeFakeContext name
|> Option.map (fun o -> o :?> 'a)

[<System.Obsolete "Please use 'Fake.Core.FakeVar.set' instead">]
let setFakeVar name (v:'a) =
forceFakeContext()
|> setFakeContext name v (fun _ -> v :> obj)
:?> 'a

[<System.Obsolete "Please use 'Fake.Core.FakeVar.define' instead">]
let fakeVar name =
(fun () -> getFakeVar name : 'a option),
(fun () -> (removeFakeVar name : 'a option) |> ignore),
(fun (v : 'a) -> setFakeVar name v |> ignore)

[<System.Obsolete "Please use 'Fake.Core.FakeVar.defineAllowNoContext' instead">]
let fakeVarAllowNoContext name =
let mutable varWithoutContext = None
(fun () ->
Expand All @@ -145,4 +150,4 @@ let fakeVarAllowNoContext name =
(fun (v : 'a) ->
if isFakeContext() then
setFakeVar name v |> ignore
else varWithoutContext <- Some v)
else varWithoutContext <- Some v)
17 changes: 17 additions & 0 deletions src/app/Fake.Core.FakeVar/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("FAKE - F# Make Core FakeVar")>]
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>]
[<assembly: AssemblyVersionAttribute("5.0.0")>]
[<assembly: AssemblyInformationalVersionAttribute("5.0.0.0")>]
[<assembly: AssemblyFileVersionAttribute("5.0.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FAKE - F# Make Core FakeVar"
let [<Literal>] AssemblyProduct = "FAKE - F# Make"
let [<Literal>] AssemblyVersion = "5.0.0"
let [<Literal>] AssemblyInformationalVersion = "5.0.0.0"
let [<Literal>] AssemblyFileVersion = "5.0.0"
18 changes: 18 additions & 0 deletions src/app/Fake.Core.FakeVar/Fake.Core.FakeVar.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>net46;netstandard1.6;netstandard2.0</TargetFrameworks>
<AssemblyName>Fake.Core.FakeVar</AssemblyName>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="FakeVar.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fake.Core.Context\Fake.Core.Context.fsproj" FromP2P="true" />
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
62 changes: 62 additions & 0 deletions src/app/Fake.Core.FakeVar/FakeVar.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/// This module contains helpers for managing build time variables
[<RequireQualifiedAccess>]
module Fake.Core.FakeVar

open Fake.Core.Context

/// Gets a strongly typed FakeVar by name returning an option type
let get<'a> name =
forceFakeContext()
|> getFakeContext name
|> Option.map (fun o -> try
o :?> 'a
with e ->
raise <| exn(sprintf "Cast error on variable '%s'" name, e)
)

/// Gets a strongly typed FakeVar by name will fail if variable is not found
let getOrFail<'a> name =
match get<'a> name with
| Some v -> v
| _ -> failwithf "Unable to find variable '%s'" name

/// Gets a strongly typed FakeVar by name will return default value if variable is not found
let getOrDefault<'a> name defaultValue =
match get<'a> name with
| Some v -> v
| _ -> defaultValue

/// Removes a FakeVar by name
let remove name =
forceFakeContext()
|> removeFakeContext name
|> ignore

/// Sets value of a FakeVar
let set name (v:'a) =
forceFakeContext()
|> setFakeContext name v (fun _ -> v :> obj)
|> ignore

/// Define a named FakeVar providing the get, remove and set
/// Will fail if there is no context
let define<'a> name =
if isFakeContext() then
(fun () -> get name : 'a option),
(fun () -> remove name),
(fun (v : 'a) -> set name v)
else
failwithf "Cannot define variable '%s' without context" name

/// Define a named FakeVar providing the get, remove and set
/// Will create a local variable if there is no context
let defineAllowNoContext<'a> name =
if isFakeContext() then
(fun () -> get name : 'a option),
(fun () -> remove name),
(fun (v : 'a) -> set name v)
else
let mutable varWithoutContext = None
(fun () -> varWithoutContext),
(fun () -> varWithoutContext <- None),
(fun (v : 'a) -> varWithoutContext <- Some v)
4 changes: 4 additions & 0 deletions src/app/Fake.Core.FakeVar/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
group netcore

FSharp.Core
NETStandard.Library
3 changes: 2 additions & 1 deletion src/app/Fake.Core.Process/Fake.Core.Process.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ProjectReference Include="..\Fake.Core.String\Fake.Core.String.fsproj" />
<ProjectReference Include="..\Fake.Core.Trace\Fake.Core.Trace.fsproj" />
<ProjectReference Include="..\Fake.Core.Context\Fake.Core.Context.fsproj" />
<ProjectReference Include="..\Fake.Core.FakeVar\Fake.Core.FakeVar.fsproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' " >
<Reference Include="System.Configuration" />
Expand All @@ -38,4 +39,4 @@
<Compile Include="Mono.fs" />
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
</Project>
Loading

0 comments on commit c6ba91c

Please sign in to comment.