protected override TargetCompilationConfiguration PrepareTargetCompilationConfiguration( TargetCompilationConfiguration targetCompilationConfiguration) => targetCompilationConfiguration.With( defaultWarningSuppressions: targetCompilationConfiguration .DefaultWarningSuppressions .Concat(defaultWarningSuppressions) .ToArray());
internal NativeDependencyResolver(TargetCompilationConfiguration compilationConfiguration) { CompilationConfiguration = compilationConfiguration; agentArchitecture = Environment.Is64BitProcess ? Architecture.X64 : Architecture.X86; }
public AgentClientEvaluationContextManager( AgentClient agentClient, IReadOnlyList <string> assemblySearchPaths) { this.agentClient = agentClient; initialTargetCompilationConfiguration = TargetCompilationConfiguration .CreateInitialForCompilationWorkspace(assemblySearchPaths); }
internal NativeDependencyResolver(TargetCompilationConfiguration compilationConfiguration) { CompilationConfiguration = compilationConfiguration; agentArchitecture = Environment.Is64BitProcess && (HostEnvironment.OS != HostOS.Windows || compilationConfiguration.Sdk.IsNot(SdkId.ConsoleNetCore)) ? Architecture.X64 : Architecture.X86; }
internal InteractiveDependencyResolver(TargetCompilationConfiguration configuration) : base(configuration) { UseGacCache = configuration?.Sdk?.TargetFramework.Identifier == ".NETFramework"; AddAssemblySearchPath(assemblyTempDir); try { Directory.Delete(assemblyTempDir, recursive: true); } catch { } }
static Type ResolveHostObjectType( InteractiveDependencyResolver dependencyResolver, TargetCompilationConfiguration configuration, AgentType agentType) { using (var assemblyContext = new EvaluationAssemblyContext()) { string globalStateAssemblyCachePath = null; if (configuration.GlobalStateAssembly.Content.PEImage != null) { globalStateAssemblyCachePath = dependencyResolver.CacheRemoteAssembly( configuration.GlobalStateAssembly); } var resolvedAssemblies = dependencyResolver .Resolve(new [] { configuration.GlobalStateAssembly }) .Select(r => new AssemblyDefinition(r.AssemblyName, r.Path)); assemblyContext.AddRange(resolvedAssemblies); var globalStateAssemblyDef = resolvedAssemblies.First( assembly => ResolvedAssembly.NameEqualityComparer.Default.Equals( assembly.Name, configuration.GlobalStateAssembly.Name)); netStandardAssembly = netStandardAssembly ?? Assembly.ReflectionOnlyLoadFrom( new FilePath(Assembly.GetExecutingAssembly().Location) .ParentDirectory .Combine("netstandard.dll")); xiAssembly = xiAssembly ?? Assembly.ReflectionOnlyLoadFrom( new FilePath(Assembly.GetExecutingAssembly().Location) .ParentDirectory .Combine("Xamarin.Interactive.dll")); Assembly globalStateAssembly; if (globalStateAssemblyDef.Name.Name == "Xamarin.Interactive") { globalStateAssembly = xiAssembly; } else { globalStateAssembly = Assembly.ReflectionOnlyLoadFrom( globalStateAssemblyCachePath ?? globalStateAssemblyDef.Content.Location); } return(globalStateAssembly.GetType(configuration.GlobalStateTypeName)); } }
public Task <TargetCompilationConfiguration> CreateEvaluationContextAsync( TargetCompilationConfiguration configuration, CancellationToken cancellationToken = default) { var evaluationContextId = configuration.EvaluationContextId; if (evaluationContextId == default) { evaluationContextId = EvaluationContextId.Create(); } // On WASM, we'll have loaded the following assemblies by default: var assemblyBase = new FilePath(appPath); var defaultAssemblies = new [] {
public Task <TargetCompilationConfiguration> CreateEvaluationContextAsync( TargetCompilationConfiguration targetCompilationConfiguration, CancellationToken cancellationToken = default) { if (targetCompilationConfiguration == null) { throw new ArgumentNullException(nameof(targetCompilationConfiguration)); } var globalStateObject = CreateGlobalState(); targetCompilationConfiguration = targetCompilationConfiguration.With( runtime: Runtime.CurrentProcessRuntime, defaultImports: defaultImports); targetCompilationConfiguration = PrepareTargetCompilationConfiguration( targetCompilationConfiguration); targetCompilationConfiguration = FinalizeTargetCompilationConfiguration( targetCompilationConfiguration, globalStateObject); var evaluationContext = new EvaluationContext( this, globalStateObject); if (globalStateObject is EvaluationContextGlobalObject evaluationContextGlobalObject) { evaluationContextGlobalObject.EvaluationContext = evaluationContext; } evaluationContexts.Add( targetCompilationConfiguration.EvaluationContextId, new EvaluationContextRegistration( evaluationContext, evaluationContext.Events.Subscribe( new Observer <ICodeCellEvent> (events.Observers.OnNext)))); OnEvaluationContextCreated(evaluationContext); return(Task.FromResult(targetCompilationConfiguration)); }
static ImmutableArray <ResolvedAssembly> Resolve( TargetCompilationConfiguration configuration, InteractivePackageManager project, FilePath frameworkPath) { var result = ImmutableArray <ResolvedAssembly> .Empty; var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); try { return(result = new NativeDependencyResolver(configuration) .AddAssemblySearchPath(frameworkPath.Combine("Facades")) .AddAssemblySearchPath(frameworkPath) .Resolve(project.InstalledPackages.SelectMany( p => p.AssemblyReferences))); } finally { stopwatch.Stop(); Console.WriteLine("DependencyResolver.Resolve: {0} in {1}s", result.Length, stopwatch.Elapsed.TotalSeconds); } }
public Task <TargetCompilationConfiguration> CreateEvaluationContextAsync( CancellationToken cancellationToken = default) => CreateEvaluationContextAsync( TargetCompilationConfiguration.CreateInitialForCompilationWorkspace(), cancellationToken);
public RoslynCompilationWorkspace( InteractiveDependencyResolver dependencyResolver, TargetCompilationConfiguration compilationConfiguration, AgentType agentType, Type hostObjectType = null, bool includePeImagesInResolution = false) { if (dependencyResolver == null) { throw new ArgumentNullException(nameof(dependencyResolver)); } if (compilationConfiguration == null) { throw new ArgumentNullException(nameof(compilationConfiguration)); } workspace = new InteractiveWorkspace(); sourceReferenceResolver = new InteractiveSourceReferenceResolver(dependencyResolver); metadataReferenceResolver = new InteractiveMetadataReferenceResolver(dependencyResolver); monoScriptCompilationPatcher = new MonoScriptCompilationPatcher( assemblyNamePrefixBytes); DependencyResolver = dependencyResolver; this.hostObjectType = hostObjectType; EvaluationContextId = compilationConfiguration.EvaluationContextId; initialImports = compilationConfiguration.DefaultUsings.ToImmutableArray(); initialWarningSuppressions = compilationConfiguration.DefaultWarningSuppressions.ToImmutableArray(); initialDiagnosticOptions = initialWarningSuppressions.ToImmutableDictionary( warningId => warningId, warningId => ReportDiagnostic.Suppress); initialReferences = dependencyResolver.ResolveDefaultReferences(); var byNameImplicitReferences = new Tuple <string, Func <bool> > [] { Tuple.Create <string, Func <bool> > ("Microsoft.CSharp", () => true), // Add an implicit by name reference to System.ValueTuple if and only if the // agent is Console or WPF, and the current runtime does not have SVT in corlib. // This check makes sense because the Console and WPF agents run on the same // runtime as the current client. The other agents are on runtimes controlled // by us, and we can be sure that System.ValueTuple will be part of corlib on // those agents. A bug in .NET 4.7 means we can't just always implicitly add // the reference and have the runtime figure out what should be done. This bug // is fixed in .NET 4.7.1. Tuple.Create <string, Func <bool> > ("System.ValueTuple", () => { return((agentType == AgentType.Console || agentType == AgentType.WPF) && typeof(object).Assembly.GetType("System.ValueTuple") == null); }) }; foreach (var implicitReference in byNameImplicitReferences) { if (!implicitReference.Item2()) { continue; } var assembly = DependencyResolver.ResolveWithoutReferences( new AssemblyName(implicitReference.Item1)); if (assembly != null) { initialReferences = initialReferences.Add( MetadataReference.CreateFromFile(assembly.Path)); } } this.includePeImagesInResolution = includePeImagesInResolution; CompletionService = workspace .Services .GetLanguageServices(LanguageNames.CSharp) .GetService <CompletionService> (); }
protected override TargetCompilationConfiguration PrepareTargetCompilationConfiguration( TargetCompilationConfiguration configuration) => configuration.With( includePEImagesInDependencyResolution: configuration.CompilationOS != HostOS.macOS, defaultImports: configuration.DefaultImports.Concat(defaultImports).ToArray());
protected override TargetCompilationConfiguration PrepareTargetCompilationConfiguration( TargetCompilationConfiguration configuration) => configuration.With(includePEImagesInDependencyResolution: true);
public Task <TargetCompilationConfiguration> CreateEvaluationContextAsync( TargetCompilationConfiguration initialConfiguration, CancellationToken cancellationToken) => agentClient.SendAsync <TargetCompilationConfiguration> ( new EvaluationContextInitializeRequest(initialConfiguration), agentClient.GetCancellationToken(cancellationToken));
async Task LoadPackageIntegrationsAsync( AgentType agentType, TargetCompilationConfiguration targetCompilationConfiguration, IEvaluationContextManager evaluationContextManager, InteractivePackage package, CancellationToken cancellationToken) { // Forms is special-cased because we own it and load the extension from our framework. if (PackageIdComparer.Equals(package.Identity.Id, "Xamarin.Forms")) { await WorkspaceConfiguration.LoadFormsAgentExtensions( package.Identity.Version.Version, targetCompilationConfiguration, evaluationContextManager, dependencyResolver); } var assembliesToLoadOnAgent = new List <ResolvedAssembly> (); // Integration assemblies are not expected to be in a TFM directory—we look for them in // the `xamarin.interactive` folder inside the NuGet package. var packagePath = packageManager.GetPackageInstallPath(package); var interactivePath = packagePath.Combine("xamarin.interactive"); if (interactivePath.DirectoryExists) { var interactiveAssemblies = interactivePath.EnumerateFiles("*.dll"); foreach (var interactiveReference in interactiveAssemblies) { var resolvedAssembly = dependencyResolver.ResolveWithoutReferences(interactiveReference); if (HasIntegration(resolvedAssembly)) { assembliesToLoadOnAgent.Add(resolvedAssembly); } } } if (assembliesToLoadOnAgent.Count > 0) { var includePeImage = targetCompilationConfiguration.IncludePEImagesInDependencyResolution; var assembliesToLoad = assembliesToLoadOnAgent.Select(dep => { var peImage = includePeImage ? GetFileBytes(dep.Path) : null; var syms = includePeImage ? GetDebugSymbolsFromAssemblyPath(dep.Path) : null; return(new AssemblyDefinition( dep.AssemblyName, dep.Path, peImage: peImage, debugSymbols: syms )); }).ToArray(); await evaluationContextManager.LoadAssembliesAsync( targetCompilationConfiguration.EvaluationContextId, assembliesToLoad, cancellationToken); } await getAgentConnectionHandler(true, cancellationToken); }
public WorkspaceConfiguration(TargetCompilationConfiguration compilationConfiguration, InteractiveDependencyResolver dependencyResolver);
public WorkspaceConfiguration(TargetCompilationConfiguration compilationConfiguration, InteractiveDependencyResolver dependencyResolver, bool includePEImagesInDependencyResolution, Type hostObjectType = null);
public Task <TargetCompilationConfiguration> CreateEvaluationContextAsync(TargetCompilationConfiguration targetCompilationConfiguration, CancellationToken cancellationToken = default(CancellationToken));
protected override TargetCompilationConfiguration PrepareTargetCompilationConfiguration( TargetCompilationConfiguration configuration) => configuration.With( defaultImports: configuration.DefaultImports.Concat(defaultImports).ToArray());