Skip to content

Commit

Permalink
Updating to support 0.10.2, fix for #5
Browse files Browse the repository at this point in the history
  • Loading branch information
glennblock committed Sep 29, 2014
1 parent b3fba5d commit 990a435
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 230 deletions.
24 changes: 1 addition & 23 deletions install.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var version = "0.8.1"
var version = "0.10.2"

var request = require('request');
var unzip = require('unzip');
Expand All @@ -15,26 +15,6 @@ var getScriptCs = function() {
});
}

var getRoslynCompilersCSharp = function() {
var response = request("http://nuget.org/api/v2/package/Roslyn.Compilers.CSharp/1.2.20906.2");

response.pipe(unzip.Extract({path:"roslyn1"}));

response.on("end", function(){
copyDir(path.join("roslyn1","lib","net45"), "lib");
});
}

var getRoslynCompilersCommon = function() {
var response = request("http://nuget.org/api/v2/package/Roslyn.Compilers.Common/1.2.20906.2");

response.pipe(unzip.Extract({path:"roslyn2"}));

response.on("end", function(){
copyDir(path.join("roslyn2","lib","net45"), "lib");
});
}

var copyDir = function(src, dest) {
var files = fs.readdirSync(src);
for(var i = 0; i < files.length; i++) {
Expand All @@ -55,5 +35,3 @@ var copy = function(src, dest) {
};

getScriptCs();
getRoslynCompilersCSharp();
getRoslynCompilersCommon();
Binary file modified lib/edge-scs.dll
Binary file not shown.
6 changes: 0 additions & 6 deletions src/edge-scs/.nuget/NuGet.Config

This file was deleted.

Binary file removed src/edge-scs/.nuget/NuGet.exe
Binary file not shown.
136 changes: 0 additions & 136 deletions src/edge-scs/.nuget/NuGet.targets

This file was deleted.

59 changes: 23 additions & 36 deletions src/edge-scs/EdgeCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,41 @@
using System.Text.RegularExpressions;
using System.Threading;
using Autofac.Core;
using Common.Logging;
using EdgeScs;
using NuGet;
using ScriptCs;
using ScriptCs.Contracts;
using ScriptCs.Engine.Roslyn;
using ScriptCs.Exceptions;
using System.Threading.Tasks;

//based on EdgeCompiler code in edge-cs: https://github.com/tjanczuk/edge-cs/blob/master/src/edge-cs/EdgeCompiler.cs
using ScriptCs.Hosting;

public class EdgeCompiler
{
private static readonly bool debuggingEnabled =
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("EDGE_CS_DEBUG"));

private static Dictionary<string, Assembly> referencedAssemblies = new Dictionary<string, Assembly>();

private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var name = new AssemblyName(args.Name).Name;
Assembly assembly = null;
var found = referencedAssemblies.TryGetValue(name, out assembly);
return assembly;
}
private static ScriptConsole _console;
private static ILog _logger;
private static IInitializationServices _initializationServices;

static EdgeCompiler()
{
//add System.Core
referencedAssemblies.Add(typeof (Enumerable).Assembly.GetName().Name, typeof (Enumerable).Assembly);

//add System
referencedAssemblies.Add(typeof (Uri).Assembly.GetName().Name, typeof (Uri).Assembly);

var edgeAssembly = Assembly.GetExecutingAssembly();
var bin = Path.GetDirectoryName(edgeAssembly.Location);

//populate the assembly cache
foreach (var file in Directory.GetFiles(bin, "*.dll"))
{
var assembly = Assembly.LoadFile(file);

if (!referencedAssemblies.ContainsKey(assembly.FullName))
referencedAssemblies.Add(assembly.GetName().Name, assembly);
}
_console = new ScriptConsole();
var loggerConfig = new LoggerConfigurator(ScriptCs.Contracts.LogLevel.Error);
loggerConfig.Configure(_console);
_logger = loggerConfig.GetLogger();
var overrides = new Dictionary<Type, object>();
overrides[typeof (ScriptCs.Contracts.IFileSystem)] = typeof (EdgeFileSystem);

AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
_initializationServices = new InitializationServices(_logger, overrides);

var resolver = _initializationServices.GetAppDomainAssemblyResolver();
var dir = Path.GetDirectoryName(typeof (EdgeCompiler).Assembly.Location);
var assemblies = Directory.GetFiles(dir, "*.dll");
resolver.AddAssemblyPaths(assemblies);
}

public Func<object, Task<object>> CompileFunc(IDictionary<string, object> parameters)
Expand Down Expand Up @@ -105,19 +95,16 @@ private static List<string> GetParamReferences(IDictionary<string, object> param

private IScriptExecutor GetExecutor(List<string> references, string rootPath)
{
var console = new ScriptConsole();
var loggerConfig = new LoggerConfigurator(ScriptCs.Contracts.LogLevel.Error);
loggerConfig.Configure(console);
var logger = loggerConfig.GetLogger();

var builder = new ScriptServicesBuilder(console, logger).
InMemory(true).
var builder = new ScriptServicesBuilder(_console, _logger, initializationServices: _initializationServices).
Debug(true).
ScriptName("");

builder.LoadModules("csx");
var services = builder.Build();
var executor = services.Executor;
var paths = services.AssemblyResolver.GetAssemblyPaths(rootPath, null).Where(p=>!p.Contains("Contracts"));

var scriptcsPaths = services.FileSystem.EnumerateBinaries(Path.Combine(rootPath, "node_modules", "edge-scs", "lib"), SearchOption.TopDirectoryOnly);
var paths = scriptcsPaths.Union(services.AssemblyResolver.GetAssemblyPaths(rootPath, true)).Where(p=>!p.Contains("Contracts"));
var packs = services.ScriptPackResolver.GetPacks();
executor.Initialize(paths, packs);

Expand Down
Loading

0 comments on commit 990a435

Please sign in to comment.