Skip to content

Commit 61a8a39

Browse files
author
Nick Berardi
committed
refactored roslyn out of core to fix scriptcs#90 in preperation for scriptcs#80
1 parent dd31732 commit 61a8a39

22 files changed

Lines changed: 434 additions & 325 deletions

ScriptCs.sln

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{9659F354
2828
build\ScriptCs.Version.props = build\ScriptCs.Version.props
2929
EndProjectSection
3030
EndProject
31+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScriptCs.Engine.Roslyn", "src\ScriptCs.Engine.Roslyn\ScriptCs.Engine.Roslyn.csproj", "{E79EC231-E27D-4057-91C9-2D001A3A8C3B}"
32+
EndProject
33+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScriptCs.Engine.Roslyn.Tests", "test\ScriptCs.Engine.Roslyn.Tests\ScriptCs.Engine.Roslyn.Tests.csproj", "{28D11DE5-9F98-4E0A-8CCC-9CDC19110451}"
34+
EndProject
3135
Global
3236
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3337
Debug|Any CPU = Debug|Any CPU
@@ -54,12 +58,21 @@ Global
5458
{AC228213-7356-4F0D-BA48-EBA5FB8A7506}.Debug|Any CPU.Build.0 = Debug|Any CPU
5559
{AC228213-7356-4F0D-BA48-EBA5FB8A7506}.Release|Any CPU.ActiveCfg = Release|Any CPU
5660
{AC228213-7356-4F0D-BA48-EBA5FB8A7506}.Release|Any CPU.Build.0 = Release|Any CPU
61+
{E79EC231-E27D-4057-91C9-2D001A3A8C3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62+
{E79EC231-E27D-4057-91C9-2D001A3A8C3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
63+
{E79EC231-E27D-4057-91C9-2D001A3A8C3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
64+
{E79EC231-E27D-4057-91C9-2D001A3A8C3B}.Release|Any CPU.Build.0 = Release|Any CPU
65+
{28D11DE5-9F98-4E0A-8CCC-9CDC19110451}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
66+
{28D11DE5-9F98-4E0A-8CCC-9CDC19110451}.Debug|Any CPU.Build.0 = Debug|Any CPU
67+
{28D11DE5-9F98-4E0A-8CCC-9CDC19110451}.Release|Any CPU.ActiveCfg = Release|Any CPU
68+
{28D11DE5-9F98-4E0A-8CCC-9CDC19110451}.Release|Any CPU.Build.0 = Release|Any CPU
5769
EndGlobalSection
5870
GlobalSection(SolutionProperties) = preSolution
5971
HideSolutionNode = FALSE
6072
EndGlobalSection
6173
GlobalSection(NestedProjects) = preSolution
6274
{4D6A2A55-BB17-40CB-9567-EAFF80BEFDCE} = {A59C6538-62EA-4BF6-AA00-E0E9A2892D47}
6375
{AC228213-7356-4F0D-BA48-EBA5FB8A7506} = {A59C6538-62EA-4BF6-AA00-E0E9A2892D47}
76+
{28D11DE5-9F98-4E0A-8CCC-9CDC19110451} = {A59C6538-62EA-4BF6-AA00-E0E9A2892D47}
6477
EndGlobalSection
6578
EndGlobal

src/ScriptCs.Contracts/IScriptPack.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.ComponentModel.Composition;
44
using System.Linq;
55
using System.Text;
6-
using Roslyn.Scripting.CSharp;
76

87
namespace ScriptCs.Contracts
98
{

src/ScriptCs.Contracts/ScriptCs.Contracts.csproj

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@
99
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
1010
</PropertyGroup>
1111
<ItemGroup>
12-
<Reference Include="Roslyn.Compilers, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
13-
<Private>True</Private>
14-
<HintPath>..\..\packages\Roslyn.Compilers.Common.1.2.20906.2\lib\net45\Roslyn.Compilers.dll</HintPath>
15-
</Reference>
16-
<Reference Include="Roslyn.Compilers.CSharp, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
17-
<Private>True</Private>
18-
<HintPath>..\..\packages\Roslyn.Compilers.CSharp.1.2.20906.2\lib\net45\Roslyn.Compilers.CSharp.dll</HintPath>
19-
</Reference>
2012
<Reference Include="System" />
2113
<Reference Include="System.ComponentModel.Composition" />
2214
<Reference Include="System.Core" />
@@ -38,9 +30,6 @@
3830
</Compile>
3931
<Compile Include="Properties\AssemblyInfo.cs" />
4032
</ItemGroup>
41-
<ItemGroup>
42-
<None Include="packages.config" />
43-
</ItemGroup>
4433
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
4534
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
4635
</Project>

src/ScriptCs.Core/IScriptEngine.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel.Composition;
3-
using Roslyn.Scripting;
4+
using System.Threading.Tasks;
5+
using ScriptCs.Contracts;
46

57
namespace ScriptCs
68
{
79
[InheritedExport]
810
public interface IScriptEngine
911
{
1012
string BaseDirectory { get; set; }
11-
12-
void AddReference(string assemblyDisplayNameOrPath);
13+
IScriptHostFactory ScriptHostFactory { get; set; }
1314

14-
ISession CreateSession<THostObject>(THostObject hostObject) where THostObject : class;
15-
16-
ISession CreateSession(object hostObject, Type hostObjectType = null);
17-
18-
ISession CreateSession();
15+
void Execute(string code, IEnumerable<string> references, IEnumerable<IScriptPack> scriptPacks);
1916
}
2017
}

src/ScriptCs.Core/ISession.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/ScriptCs.Core/ScriptCs.Core.csproj

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313
<SpecificVersion>False</SpecificVersion>
1414
<HintPath>..\..\packages\Nuget.Core.2.2.0\lib\net40-Client\NuGet.Core.dll</HintPath>
1515
</Reference>
16-
<Reference Include="Roslyn.Compilers, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
17-
<Private>True</Private>
18-
<HintPath>..\..\packages\Roslyn.Compilers.Common.1.2.20906.2\lib\net45\Roslyn.Compilers.dll</HintPath>
19-
</Reference>
20-
<Reference Include="Roslyn.Compilers.CSharp, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
21-
<Private>True</Private>
22-
<HintPath>..\..\packages\Roslyn.Compilers.CSharp.1.2.20906.2\lib\net45\Roslyn.Compilers.CSharp.dll</HintPath>
23-
</Reference>
2416
<Reference Include="System" />
2517
<Reference Include="System.ComponentModel.Composition" />
2618
<Reference Include="System.Core" />
@@ -47,7 +39,6 @@
4739
<Compile Include="IScriptPackResolver.cs" />
4840
<Compile Include="IScriptEngine.cs" />
4941
<Compile Include="IScriptExecutor.cs" />
50-
<Compile Include="ISession.cs" />
5142
<Compile Include="PackageAssemblyResolver.cs" />
5243
<Compile Include="Constants.cs" />
5344
<Compile Include="Package\IPackageContainer.cs" />
@@ -62,9 +53,6 @@
6253
<Compile Include="ScriptPackManager.cs" />
6354
<Compile Include="ScriptPackResolver.cs" />
6455
<Compile Include="ScriptExecutor.cs" />
65-
<Compile Include="ScriptPackSession.cs" />
66-
<Compile Include="Wrappers\ScriptEngineWrapper.cs" />
67-
<Compile Include="Wrappers\SessionWrapper.cs" />
6856
</ItemGroup>
6957
<ItemGroup>
7058
<None Include="packages.config" />
Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using Roslyn.Scripting.CSharp;
32
using System.Collections.Generic;
43
using System.ComponentModel.Composition;
54
using System.IO;
@@ -24,31 +23,28 @@ public ScriptExecutor(IFileSystem fileSystem, IFilePreProcessor filePreProcessor
2423
}
2524

2625
public ScriptExecutor(IFileSystem fileSystem, IFilePreProcessor filePreProcessor, IScriptEngine scriptEngine) :
27-
this(fileSystem, filePreProcessor, scriptEngine, new ScriptHostFactory())
28-
{
29-
30-
}
26+
this(fileSystem, filePreProcessor, scriptEngine, new ScriptHostFactory()) { }
3127

3228
public void Execute(string script, IEnumerable<string> paths, IEnumerable<IScriptPack> scriptPacks)
3329
{
34-
_scriptEngine.AddReference("System");
35-
_scriptEngine.AddReference("System.Core");
36-
3730
var bin = Path.Combine(_fileSystem.GetWorkingDirectory(script), "bin");
31+
var files = PrepareBinFolder(paths, bin);
32+
33+
var references = new List<string>();
34+
references.Add("System");
35+
references.Add("System.Core");
36+
references.AddRange(files);
3837

3938
_scriptEngine.BaseDirectory = bin;
39+
_scriptEngine.ScriptHostFactory = _scriptHostFactory;
4040

41-
var files = PrepareBinFolder(paths, bin);
42-
var contexts = GetContexts(scriptPacks);
43-
var host = _scriptHostFactory.CreateScriptHost(contexts);
44-
var session = _scriptEngine.CreateSession(host);
45-
AddReferences(files, session);
46-
var scriptPackSession = new ScriptPackSession(session);
47-
InitializeScriptPacks(scriptPacks, scriptPackSession);
4841
var path = Path.IsPathRooted(script) ? script : Path.Combine(_fileSystem.CurrentDirectory, script);
49-
var csx = _filePreProcessor.ProcessFile(path);
50-
session.Execute(csx);
51-
TerminateScriptPacks(scriptPacks);
42+
var code = _filePreProcessor.ProcessFile(path);
43+
44+
_scriptEngine.Execute(
45+
code: code,
46+
references: references,
47+
scriptPacks: scriptPacks);
5248
}
5349

5450
private IEnumerable<string> PrepareBinFolder(IEnumerable<string> paths, string bin)
@@ -70,38 +66,5 @@ private IEnumerable<string> PrepareBinFolder(IEnumerable<string> paths, string b
7066

7167
return files;
7268
}
73-
74-
private void AddReferences(IEnumerable<string> files, ISession session)
75-
{
76-
foreach (var file in files)
77-
{
78-
session.AddReference(file);
79-
}
80-
}
81-
82-
private IEnumerable<IScriptPackContext> GetContexts(IEnumerable<IScriptPack> scriptPacks)
83-
{
84-
foreach (var pack in scriptPacks)
85-
{
86-
yield return pack.GetContext();
87-
}
88-
}
89-
90-
private void InitializeScriptPacks(IEnumerable<IScriptPack> scriptPacks, IScriptPackSession session)
91-
{
92-
foreach (var pack in scriptPacks)
93-
{
94-
pack.Initialize(session);
95-
}
96-
}
97-
98-
private void TerminateScriptPacks(IEnumerable<IScriptPack> scriptPacks)
99-
{
100-
foreach (var pack in scriptPacks)
101-
{
102-
pack.Terminate();
103-
}
104-
}
105-
10669
}
10770
}

src/ScriptCs.Core/Wrappers/ScriptEngineWrapper.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/ScriptCs.Core/Wrappers/SessionWrapper.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/ScriptCs.Core/packages.config

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Nuget.Core" version="2.2.0" targetFramework="net45" />
4-
<package id="Roslyn.Compilers.Common" version="1.2.20906.2" targetFramework="net45" />
5-
<package id="Roslyn.Compilers.CSharp" version="1.2.20906.2" targetFramework="net45" />
64
</packages>

0 commit comments

Comments
 (0)