Skip to content

Commit

Permalink
Adding inital proof of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Aug 8, 2014
1 parent 8a84068 commit 96ea3be
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .nuget/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit.Runners" version="2.6.3" />
</packages>
11 changes: 10 additions & 1 deletion FSharp.ProjectScaffold.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{1F1B4F0F-2998-4D74-865B-9122611C2B14}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
Expand Down Expand Up @@ -36,6 +38,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{ED8079DD
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.ProjectTemplate.Tests", "tests\FSharp.ProjectTemplate.Tests\FSharp.ProjectTemplate.Tests.fsproj", "{E789C72A-5CFD-436B-8EF1-61AA2852A89F}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ManualTest", "tests\ManualTest\ManualTest.fsproj", "{0252F0B5-B106-42F5-ABA8-743A1AAE8A6E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -50,6 +54,10 @@ Global
{E789C72A-5CFD-436B-8EF1-61AA2852A89F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E789C72A-5CFD-436B-8EF1-61AA2852A89F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E789C72A-5CFD-436B-8EF1-61AA2852A89F}.Release|Any CPU.Build.0 = Release|Any CPU
{0252F0B5-B106-42F5-ABA8-743A1AAE8A6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0252F0B5-B106-42F5-ABA8-743A1AAE8A6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0252F0B5-B106-42F5-ABA8-743A1AAE8A6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0252F0B5-B106-42F5-ABA8-743A1AAE8A6E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -58,5 +66,6 @@ Global
{83F16175-43B1-4C90-A1EE-8E351C33435D} = {A6A6AF7D-D6E3-442D-9B1E-58CC91879BE1}
{8E6D5255-776D-4B61-85F9-73C37AA1FB9A} = {A6A6AF7D-D6E3-442D-9B1E-58CC91879BE1}
{E789C72A-5CFD-436B-8EF1-61AA2852A89F} = {ED8079DD-2B06-4030-9F0F-DC548F98E1C4}
{0252F0B5-B106-42F5-ABA8-743A1AAE8A6E} = {ED8079DD-2B06-4030-9F0F-DC548F98E1C4}
EndGlobalSection
EndGlobal
58 changes: 58 additions & 0 deletions src/FSharp.ProjectTemplate/ConfigDSL.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
module FSharp.ProjectTemplate.ConfigDSL

open System
open System.IO
open System.Collections.Generic
open Microsoft.FSharp.Compiler.Interactive.Shell

let initialCode = """
let config = new System.Collections.Generic.Dictionary<string,string>()
let source x = () // Todo
let nuget x y = config.Add(x,y)
"""

let runConfig fileName =
let fsiConfig = FsiEvaluationSession.GetDefaultConfiguration()

let commonOptions = [| "fsi.exe"; "--noninteractive" |]

let sbOut = new Text.StringBuilder()
let sbErr = new Text.StringBuilder() // TODO: evtl. irgendwo ausgeben
let outStream = new StringWriter(sbOut)
let errStream = new StringWriter(sbErr)

let stdin = new StreamReader(Stream.Null)

try
let session = FsiEvaluationSession.Create(fsiConfig, commonOptions, stdin, outStream, errStream)

try

session.EvalInteraction initialCode |> ignore
session.EvalScript fileName
match session.EvalExpression "config" with
| Some x -> x.ReflectionValue :?> System.Collections.Generic.Dictionary<string,string>
| _ -> failwithf "Error: %s" <| sbErr.ToString()
with
| _ -> failwithf "Error: %s" <| sbErr.ToString()

with
| exn ->
printfn "FsiEvaluationSession could not be created."

raise exn

// TODO make this correct
let merge (config1:Dictionary<string,string>) (config2:Dictionary<string,string>) =

let config = Dictionary<string,string>()
for x in config1 do
config.Add(x.Key,x.Value)

for x in config2 do
config.[x.Key] <- x.Value

config

let (==>) c1 c2 = merge c1 c2
42 changes: 28 additions & 14 deletions src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<Name>FSharp.ProjectTemplate</Name>
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -33,19 +35,6 @@
<WarningLevel>3</WarningLevel>
<DocumentationFile>..\..\bin\FSharp.ProjectTemplate.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
</ItemGroup>
<ItemGroup>
<Compile Include="Library.fs" />
<None Include="Script.fsx" />
</ItemGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
Expand All @@ -61,7 +50,32 @@
</PropertyGroup>
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')" />
<Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<ItemGroup>
<Compile Include="ConfigDSL.fs" />
<None Include="Script.fsx" />
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="FSharp.Compiler.Service">
<HintPath>..\..\packages\FSharp.Compiler.Service.0.0.58\lib\net40\FSharp.Compiler.Service.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
16 changes: 0 additions & 16 deletions src/FSharp.ProjectTemplate/Library.fs

This file was deleted.

4 changes: 4 additions & 0 deletions src/FSharp.ProjectTemplate/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FSharp.Compiler.Service" version="0.0.58" targetFramework="net40" />
</packages>
6 changes: 2 additions & 4 deletions tests/FSharp.ProjectTemplate.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ open FSharp.ProjectTemplate
open NUnit.Framework

[<Test>]
let ``hello returns 42`` () =
let result = Library.hello 42
printfn "%i" result
Assert.AreEqual(42,result)
let ``Sound check`` () =
Assert.AreEqual(42,42)
86 changes: 86 additions & 0 deletions tests/ManualTest/ManualTest.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>0252f0b5-b106-42f5-aba8-743a1aae8a6e</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ManualTest</RootNamespace>
<AssemblyName>ManualTest</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFSharpCoreVersion>4.3.1.0</TargetFSharpCoreVersion>
<Name>ManualTest</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\Debug\ManualTest.XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\Release\ManualTest.XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '11.0'">
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" />
<ItemGroup>
<Content Include="myConfig.fsx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<ProjectReference Include="..\..\src\FSharp.ProjectTemplate\FSharp.ProjectTemplate.fsproj">
<Name>FSharp.ProjectTemplate</Name>
<Project>{7e90d6ce-a10b-4858-a5bc-41df7250cbca}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="myConfig2.fsx" />
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
10 changes: 10 additions & 0 deletions tests/ManualTest/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
open FSharp.ProjectTemplate.ConfigDSL

let completeConfig =
runConfig "myConfig.fsx"
==> runConfig "myConfig2.fsx"

for x in completeConfig do
printfn "%s => %s" x.Key x.Value

System.Console.ReadKey() |> ignore
6 changes: 6 additions & 0 deletions tests/ManualTest/myConfig.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "http://nuget.org/api/v2"

printfn "hello world from config"

nuget "Castle.Windsor-log4net" "~> 3.2"
nuget "Rx-Main" "~> 2.0"
6 changes: 6 additions & 0 deletions tests/ManualTest/myConfig2.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "http://nuget.org/api/v2"

printfn "hello world from config2"

nuget "FAKE" "~> 3"
nuget "Rx-Main" "~> 3.0"

0 comments on commit 96ea3be

Please sign in to comment.