private DependencyContext BuildDependencyContext(BuildContext context) { return(new DependencyContext( new TargetInfo(Framework, Runtime, null, Runtime == null), CompilationOptions.Default, Enumerable.Empty <CompilationLibrary>(), RuntimeLibraries.Select(rl => rl.Build(context)), RuntimeFallbacks.Select(rf => rf.Build()))); }
public NetCoreAppBuilder WithRuntimeLibrary( RuntimeLibraryType type, string name, string version, Action <RuntimeLibraryBuilder> customizer = null) { RuntimeLibraryBuilder runtimeLibrary = new RuntimeLibraryBuilder(type, name, version); customizer?.Invoke(runtimeLibrary); RuntimeLibraries.Add(runtimeLibrary); return(this); }
public DependencyContext Merge(DependencyContext other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } return(new DependencyContext( Target, CompilationOptions, CompileLibraries.Union(other.CompileLibraries, new LibraryMergeEqualityComparer <CompilationLibrary>()), RuntimeLibraries.Union(other.RuntimeLibraries, new LibraryMergeEqualityComparer <RuntimeLibrary>()), RuntimeGraph.Union(other.RuntimeGraph) )); }
public static (byte[] DllFile, byte[] PdbFile) CompileForStore(string script, ISchemaProvider provider) { var items = new BuildItems { SchemaProvider = provider, RawQuery = script }; RuntimeLibraries.CreateReferences(); var chain = new CreateTree( new TransformTree( new TurnQueryIntoRunnableCode(null))); chain.Build(items); return(items.DllFile, items.PdbFile); }
public static CompiledQuery CompileForExecution(string script, ISchemaProvider schemaProvider) { var items = new BuildItems { SchemaProvider = schemaProvider, RawQuery = script }; var compiled = true; RuntimeLibraries.CreateReferences(); BuildChain chain = new CreateTree( new TransformTree( new TurnQueryIntoRunnableCode(null))); CompilationException compilationError = null; try { chain.Build(items); } catch (CompilationException ce) { compilationError = ce; compiled = false; } if (compiled && !Debugger.IsAttached) { return(new CompiledQuery(CreateRunnable(items))); } var tempPath = Path.Combine(Path.GetTempPath(), "Musoq"); var tempFileName = $"InMemoryAssembly"; var assemblyPath = Path.Combine(tempPath, $"{tempFileName}.dll"); var pdbPath = Path.Combine(tempPath, $"{tempFileName}.pdb"); var csPath = Path.Combine(tempPath, $"{tempFileName}.cs"); if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } var builder = new StringBuilder(); using (var writer = new StringWriter(builder)) { items.Compilation?.SyntaxTrees.ElementAt(0).GetRoot().WriteTo(writer); } using (var file = new StreamWriter(File.Open(csPath, FileMode.Create))) { file.Write(builder.ToString()); } if (items.DllFile != null && items.DllFile.Length > 0) { using (var file = new BinaryWriter(File.Open(assemblyPath, FileMode.Create))) { if (items.DllFile != null) { file.Write(items.DllFile); } } } if (items.PdbFile != null && items.PdbFile.Length > 0) { using (var file = new BinaryWriter(File.Open(pdbPath, FileMode.Create))) { if (items.PdbFile != null) { file.Write(items.PdbFile); } } } if (!compiled && compilationError != null) { throw compilationError; } var runnable = new RunnableDebugDecorator(CreateRunnable(items), csPath, assemblyPath, pdbPath); return(new CompiledQuery(runnable)); }