public CompilationEngine( CompilationCache compilationCache, CompilationEngineContext context) { _context = context; RootLibraryExporter = new LibraryExporter(_context.LibraryManager, this, _context.TargetFramework, _context.Configuration); _compilerLoadContext = new Lazy<IAssemblyLoadContext>(() => { var factory = (IAssemblyLoadContextFactory)_context.Services.GetService(typeof(IAssemblyLoadContextFactory)); // Ensure this compilation engine is in the service provider var services = new ServiceProvider(_context.Services); services.Add(typeof(ICompilationEngine), this); return factory.Create(services); }); CompilationCache = compilationCache; // Register compiler services // TODO(anurse): Switch to project factory model to avoid needing to do this. _context.AddService(typeof(ICache), CompilationCache.Cache); _context.AddService(typeof(ICacheContextAccessor), CompilationCache.CacheContextAccessor); _context.AddService(typeof(INamedCacheDependencyProvider), CompilationCache.NamedCacheDependencyProvider); _context.AddService(typeof(IFileWatcher), context.FileWatcher); }
public EdgeAssemblyLoadContext(EdgeAssemblyLoadContextAccessor loadContextAccessor) { DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Starting"); DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Application root is {0}", RuntimeEnvironment.ApplicationDirectory); _loadContextAccessor = loadContextAccessor; if (File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, "project.lock.json"))) { IList <LibraryDescription> libraries = ApplicationHostContext.GetRuntimeLibraries(ApplicationHostContext); Dictionary <string, ProjectDescription> projects = libraries.Where(p => p.Type == LibraryTypes.Project).ToDictionary(p => p.Identity.Name, p => (ProjectDescription)p); Dictionary <AssemblyName, string> assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries); CompilationEngineContext compilationContext = new CompilationEngineContext(ApplicationEnvironment, RuntimeEnvironment, this, new CompilationCache()); CompilationEngine compilationEngine = new CompilationEngine(compilationContext); AddCompileAssemblies(libraries); _loaders.Add(new ProjectAssemblyLoader(_loadContextAccessor, compilationEngine, projects.Values)); _loaders.Add(new PackageAssemblyLoader(_loadContextAccessor, assemblies, libraries)); } else { _noProjectJsonFile = true; if (File.Exists(Path.Combine(RuntimeEnvironment.EdgeNodePath, "project.lock.json"))) { ApplicationHostContext stockHostContext = new ApplicationHostContext { ProjectDirectory = RuntimeEnvironment.EdgeNodePath, TargetFramework = TargetFrameworkName }; IList <LibraryDescription> libraries = ApplicationHostContext.GetRuntimeLibraries(stockHostContext); Dictionary <AssemblyName, string> assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries); AddCompileAssemblies(libraries); _loaders.Add(new PackageAssemblyLoader(_loadContextAccessor, assemblies, libraries)); } } DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Created the dependency providers for the application"); }
public EdgeAssemblyLoadContext(EdgeAssemblyLoadContextAccessor loadContextAccessor) { DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Starting"); DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Application root is {0}", RuntimeEnvironment.ApplicationDirectory); _loadContextAccessor = loadContextAccessor; if (File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, "project.lock.json"))) { IList <LibraryDescription> libraries = ApplicationHostContext.GetRuntimeLibraries(ApplicationHostContext); Dictionary <string, ProjectDescription> projects = libraries.Where(p => p.Type == LibraryTypes.Project).ToDictionary(p => p.Identity.Name, p => (ProjectDescription)p); Dictionary <AssemblyName, string> assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries); CompilationEngineContext compilationContext = new CompilationEngineContext(ApplicationEnvironment, RuntimeEnvironment, this, new CompilationCache()); CompilationEngine compilationEngine = new CompilationEngine(compilationContext); foreach (LibraryDescription libraryDescription in libraries.Where(l => l.Type == LibraryTypes.Package)) { PackageDescription packageDescription = (PackageDescription)libraryDescription; if (packageDescription.Target.CompileTimeAssemblies != null && packageDescription.Target.CompileTimeAssemblies.Count > 0) { CompileAssemblies[libraryDescription.Identity.Name] = Path.Combine(packageDescription.Path, packageDescription.Target.CompileTimeAssemblies[0].Path); } else { CompileAssemblies[libraryDescription.Identity.Name] = Path.Combine(packageDescription.Path, packageDescription.Target.RuntimeAssemblies[0].Path); } } _loaders.Add(new ProjectAssemblyLoader(_loadContextAccessor, compilationEngine, projects.Values)); _loaders.Add(new PackageAssemblyLoader(_loadContextAccessor, assemblies, libraries)); } else { _noProjectJsonFile = true; } DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Created the dependency providers for the application"); }
public CompilationEngine(CompilationEngineContext context) { _context = context; CompilationCache = _context.CompilationCache; }
private void Initialize(DefaultHostOptions options, IAssemblyLoadContextAccessor loadContextAccessor) { var applicationHostContext = new ApplicationHostContext { ProjectDirectory = _projectDirectory, RuntimeIdentifiers = _runtimeEnvironment.GetAllRuntimeIdentifiers(), TargetFramework = _targetFramework }; var libraries = ApplicationHostContext.GetRuntimeLibraries(applicationHostContext, throwOnInvalidLockFile: true); Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, applicationHostContext.ProjectDirectory); Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, applicationHostContext.RootDirectory); Logger.TraceInformation("[{0}]: Project configuration: {1}", GetType().Name, options.Configuration); Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, applicationHostContext.PackagesDirectory); _applicationHostContext = applicationHostContext; _project = applicationHostContext.Project; #if FEATURE_DNX_MIN_VERSION_CHECK ValidateMinRuntimeVersion(libraries); #endif // Create a new Application Environment for running the app. It needs a reference to the Host's application environment // (if any), which we can get from the service provider we were given. // If this is null (i.e. there is no Host Application Environment), that's OK, the Application Environment we are creating // will just have it's own independent set of global data. var hostEnvironment = PlatformServices.Default.Application; var applicationEnvironment = new ApplicationEnvironment(Project, _targetFramework, hostEnvironment); var compilationContext = new CompilationEngineContext( applicationEnvironment, _runtimeEnvironment, loadContextAccessor.Default, new CompilationCache()); var compilationEngine = new CompilationEngine(compilationContext); var runtimeLibraryExporter = new RuntimeLibraryExporter(() => compilationEngine.CreateProjectExporter(Project, _targetFramework, options.Configuration)); var runtimeLibraryManager = new RuntimeLibraryManager(applicationHostContext); // Default services _serviceProvider.Add(typeof(ILibraryExporter), runtimeLibraryExporter); _serviceProvider.Add(typeof(IApplicationEnvironment), applicationEnvironment); _serviceProvider.Add(typeof(IRuntimeEnvironment), PlatformServices.Default.Runtime); _serviceProvider.Add(typeof(ILibraryManager), runtimeLibraryManager); _serviceProvider.Add(typeof(IAssemblyLoadContextAccessor), PlatformServices.Default.AssemblyLoadContextAccessor); _serviceProvider.Add(typeof(IAssemblyLoaderContainer), PlatformServices.Default.AssemblyLoaderContainer); PlatformServices.SetDefault(new ApplicationHostPlatformServices(PlatformServices.Default, applicationEnvironment, runtimeLibraryManager)); if (options.CompilationServerPort.HasValue) { // Change the project reference provider Project.DefaultCompiler = Project.DefaultDesignTimeCompiler; Project.DesignTimeCompilerPort = options.CompilationServerPort.Value; } // TODO: Dedupe this logic in the RuntimeLoadContext var projects = libraries.Where(p => p.Type == Runtime.LibraryTypes.Project) .ToDictionary(p => p.Identity.Name, p => (ProjectDescription)p); var assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries); // Configure Assembly loaders _loaders.Add(new ProjectAssemblyLoader(loadContextAccessor, compilationEngine, projects.Values, options.Configuration)); _loaders.Add(new PackageAssemblyLoader(loadContextAccessor, assemblies, libraries)); var compilerOptionsProvider = new CompilerOptionsProvider(projects); _serviceProvider.Add(typeof(ICompilerOptionsProvider), compilerOptionsProvider); CompilationServices.SetDefault( CompilationServices.Create( libraryExporter: runtimeLibraryExporter, compilerOptionsProvider: compilerOptionsProvider ) ); #if DNX451 PackageDependencyProvider.EnableLoadingNativeLibraries(libraries); #endif AddBreadcrumbs(libraries); }
private void Initialize(RuntimeOptions options, IServiceProvider hostServices, IAssemblyLoadContextAccessor loadContextAccessor, IFileWatcher fileWatcher) { var applicationHostContext = new ApplicationHostContext { ProjectDirectory = _projectDirectory, TargetFramework = _targetFramework }; ApplicationHostContext.Initialize(applicationHostContext); Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, applicationHostContext.ProjectDirectory); Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, applicationHostContext.RootDirectory); Logger.TraceInformation("[{0}]: Project configuration: {1}", GetType().Name, options.Configuration); Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, applicationHostContext.PackagesDirectory); _libraryManager = applicationHostContext.LibraryManager; _project = applicationHostContext.Project; if (options.WatchFiles) { fileWatcher.OnChanged += _ => { _shutdown.RequestShutdownWaitForDebugger(); }; } // Create a new Application Environment for running the app. It needs a reference to the Host's application environment // (if any), which we can get from the service provider we were given. // If this is null (i.e. there is no Host Application Environment), that's OK, the Application Environment we are creating // will just have it's own independent set of global data. var hostEnvironment = (IApplicationEnvironment)hostServices.GetService(typeof(IApplicationEnvironment)); var applicationEnvironment = new ApplicationEnvironment(Project, _targetFramework, options.Configuration, hostEnvironment); var compilationContext = new CompilationEngineContext(applicationEnvironment, loadContextAccessor.Default, new CompilationCache(), fileWatcher, new ProjectGraphProvider()); // Compilation services available only for runtime compilation compilationContext.AddCompilationService(typeof(RuntimeOptions), options); compilationContext.AddCompilationService(typeof(IApplicationShutdown), _shutdown); var compilationEngine = new CompilationEngine(compilationContext); // Default services _serviceProvider.Add(typeof(IApplicationEnvironment), applicationEnvironment); _serviceProvider.Add(typeof(ILibraryManager), _libraryManager); // TODO: Make this lazy _serviceProvider.Add(typeof(ILibraryExporter), compilationEngine.CreateProjectExporter(Project, _targetFramework, options.Configuration)); _serviceProvider.Add(typeof(IApplicationShutdown), _shutdown); _serviceProvider.Add(typeof(ICompilerOptionsProvider), new CompilerOptionsProvider(_libraryManager)); if (options.CompilationServerPort.HasValue) { // Change the project reference provider Project.DefaultCompiler = Project.DefaultDesignTimeCompiler; } CallContextServiceLocator.Locator.ServiceProvider = ServiceProvider; // Configure Assembly loaders _loaders.Add(new ProjectAssemblyLoader( loadContextAccessor, compilationEngine, _libraryManager)); _loaders.Add(new PackageAssemblyLoader(loadContextAccessor, _libraryManager)); }
private CompilationEngine CreateEngineCore(CompilationEngineContext context) { return new CompilationEngine( CompilationCache, context); }
// Having two versions of this allows consumers of the concrete Factory type to avoid casting the output by calling the // above version, while people calling through the interface (i.e. the runtime) can get the interface ICompilationEngine ICompilationEngineFactory.CreateEngine(CompilationEngineContext context) { return CreateEngineCore(context); }
public CompilationEngine CreateEngine(CompilationEngineContext context) { return CreateEngineCore(context); }
private void Initialize(RuntimeOptions options, IServiceProvider hostServices, IAssemblyLoadContextAccessor loadContextAccessor, IFileWatcher fileWatcher) { var applicationHostContext = new ApplicationHostContext { ProjectDirectory = _projectDirectory, RuntimeIdentifiers = _runtimeEnvironment.GetAllRuntimeIdentifiers(), TargetFramework = _targetFramework }; var libraries = ApplicationHostContext.GetRuntimeLibraries(applicationHostContext, throwOnInvalidLockFile: true); Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, applicationHostContext.ProjectDirectory); Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, applicationHostContext.RootDirectory); Logger.TraceInformation("[{0}]: Project configuration: {1}", GetType().Name, options.Configuration); Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, applicationHostContext.PackagesDirectory); _applicationHostContext = applicationHostContext; _project = applicationHostContext.Project; ValidateMinRuntimeVersion(libraries); if (options.WatchFiles) { fileWatcher.OnChanged += _ => { _shutdown.RequestShutdownWaitForDebugger(); }; } // Create a new Application Environment for running the app. It needs a reference to the Host's application environment // (if any), which we can get from the service provider we were given. // If this is null (i.e. there is no Host Application Environment), that's OK, the Application Environment we are creating // will just have it's own independent set of global data. var hostEnvironment = (IApplicationEnvironment)hostServices.GetService(typeof(IApplicationEnvironment)); var applicationEnvironment = new ApplicationEnvironment(Project, _targetFramework, options.Configuration, hostEnvironment); var compilationContext = new CompilationEngineContext( applicationEnvironment, _runtimeEnvironment, loadContextAccessor.Default, new CompilationCache(), fileWatcher); // Compilation services available only for runtime compilation compilationContext.AddCompilationService(typeof(RuntimeOptions), options); compilationContext.AddCompilationService(typeof(IApplicationShutdown), _shutdown); var compilationEngine = new CompilationEngine(compilationContext); // Default services _serviceProvider.Add(typeof(IApplicationEnvironment), applicationEnvironment); _serviceProvider.Add(typeof(ILibraryManager), new RuntimeLibraryManager(applicationHostContext)); _serviceProvider.Add(typeof(ILibraryExporter), new RuntimeLibraryExporter(() => compilationEngine.CreateProjectExporter(Project, _targetFramework, options.Configuration))); _serviceProvider.Add(typeof(IApplicationShutdown), _shutdown); if (options.CompilationServerPort.HasValue) { // Change the project reference provider Project.DefaultCompiler = Project.DefaultDesignTimeCompiler; } CallContextServiceLocator.Locator.ServiceProvider = ServiceProvider; // TODO: Dedupe this logic in the RuntimeLoadContext var projects = libraries.Where(p => p.Type == LibraryTypes.Project) .ToDictionary(p => p.Identity.Name, p => (ProjectDescription)p); var assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries); // Configure Assembly loaders _loaders.Add(new ProjectAssemblyLoader(loadContextAccessor, compilationEngine, projects.Values)); _loaders.Add(new PackageAssemblyLoader(loadContextAccessor, assemblies)); _serviceProvider.Add(typeof(ICompilerOptionsProvider), new CompilerOptionsProvider(projects)); AddBreadcrumbs(libraries); }