Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Dotnet.Script.DependencyModel to version 0.50.0 #1609

Merged
merged 17 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions build/Packages.props
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please reset the changes to this file so that only the relevant lines are updated? we often look here at the blame to identify when a specific dependency was introduced - and this will break it

xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<MSBuildPackageVersion>16.3.0-preview-19426-01</MSBuildPackageVersion>
<NuGetPackageVersion>5.0.0</NuGetPackageVersion>
<NuGetPackageVersion>5.2.0</NuGetPackageVersion>
<RoslynPackageVersion>3.4.0-beta1-19460-02</RoslynPackageVersion>
<XunitPackageVersion>2.4.0</XunitPackageVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Update="Cake.Scripting.Transport" Version="0.3.0" />

<PackageReference Update="Dotnet.Script.DependencyModel" Version="0.6.1" />
<PackageReference Update="Dotnet.Script.DependencyModel.NuGet" Version="0.6.2" />
<PackageReference Update="Dotnet.Script.DependencyModel" Version="0.50.0" />
<PackageReference Update="Dotnet.Script.DependencyModel.NuGet" Version="0.50.0" />

<PackageReference Update="Humanizer" Version="2.2.0" />
<PackageReference Update="McMaster.Extensions.CommandLineUtils" Version="2.2.4" />
Expand Down
3 changes: 1 addition & 2 deletions src/OmniSharp.Script/ScriptContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Dotnet.Script.DependencyModel.Compilation;
using Microsoft.CodeAnalysis;

namespace OmniSharp.Script
Expand All @@ -21,6 +20,6 @@ public ScriptContext(ScriptProjectProvider scriptProjectProvider, HashSet<Metada

public CompilationDependency[] CompilationDependencies { get; }

public Type GlobalsType { get; }
public Type GlobalsType { get; }
}
}
27 changes: 23 additions & 4 deletions src/OmniSharp.Script/ScriptContextProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Scripting.Hosting;
using Microsoft.Extensions.Logging;
using OmniSharp.FileSystem;
using OmniSharp.Roslyn.Utilities;
using OmniSharp.Services;
using LogLevel = Dotnet.Script.DependencyModel.Logging.LogLevel;
Expand All @@ -23,22 +24,28 @@ public class ScriptContextProvider
private readonly CompilationDependencyResolver _compilationDependencyResolver;
private readonly IOmniSharpEnvironment _env;
private readonly MetadataFileReferenceCache _metadataFileReferenceCache;
private readonly FileSystemHelper _fileSystemHelper;
private readonly ILogger _logger;

[ImportingConstructor]
public ScriptContextProvider(ILoggerFactory loggerFactory, IOmniSharpEnvironment env, MetadataFileReferenceCache metadataFileReferenceCache)
public ScriptContextProvider(ILoggerFactory loggerFactory, IOmniSharpEnvironment env, MetadataFileReferenceCache metadataFileReferenceCache, FileSystemHelper fileSystemHelper)
{
_loggerFactory = loggerFactory;
_env = env;
_metadataFileReferenceCache = metadataFileReferenceCache;
_fileSystemHelper = fileSystemHelper;
_logger = loggerFactory.CreateLogger<ScriptContextProvider>();
_compilationDependencyResolver = new CompilationDependencyResolver(type =>
{
// Prefix with "OmniSharp" so that we make it through the log filter.
var categoryName = $"OmniSharp.Script.{type.FullName}";
var dependencyResolverLogger = loggerFactory.CreateLogger(categoryName);
return ((level, message) =>
return ((level, message, exception) =>
{
if (level == LogLevel.Trace)
{
dependencyResolverLogger.LogTrace(message);
}
if (level == LogLevel.Debug)
{
dependencyResolverLogger.LogDebug(message);
Expand All @@ -47,11 +54,23 @@ public ScriptContextProvider(ILoggerFactory loggerFactory, IOmniSharpEnvironment
{
dependencyResolverLogger.LogInformation(message);
}
if (level == LogLevel.Warning)
{
dependencyResolverLogger.LogWarning(message);
}
if (level == LogLevel.Error)
{
dependencyResolverLogger.LogError(exception, message);
}
if (level == LogLevel.Critical)
{
dependencyResolverLogger.LogCritical(exception, message);
}
});
});
}

public ScriptContext CreateScriptContext(ScriptOptions scriptOptions)
public ScriptContext CreateScriptContext(ScriptOptions scriptOptions, string[] allCsxFiles)
{
var currentDomainAssemblies = AppDomain.CurrentDomain.GetAssemblies();

Expand All @@ -67,7 +86,7 @@ public ScriptContext CreateScriptContext(ScriptOptions scriptOptions)
try
{
_logger.LogInformation($"Searching for compilation dependencies with the fallback framework of '{scriptOptions.DefaultTargetFramework}'.");
compilationDependencies = _compilationDependencyResolver.GetDependencies(_env.TargetDirectory, scriptOptions.IsNugetEnabled(), scriptOptions.DefaultTargetFramework).ToArray();
compilationDependencies = _compilationDependencyResolver.GetDependencies(_env.TargetDirectory, allCsxFiles, scriptOptions.IsNugetEnabled(), scriptOptions.DefaultTargetFramework).ToArray();
}
catch (Exception e)
{
Expand Down
25 changes: 24 additions & 1 deletion src/OmniSharp.Script/ScriptOptions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
using System.IO;
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.CodeAnalysis;

namespace OmniSharp.Script
{
public class ScriptOptions
{
private Lazy<Dictionary<string, ReportDiagnostic>> _nullableDiagnostics;

public ScriptOptions()
{
_nullableDiagnostics = new Lazy<Dictionary<string, ReportDiagnostic>>(CreateNullableDiagnostics);
}

private Dictionary<string, ReportDiagnostic> CreateNullableDiagnostics()
{
var nullableDiagnostics = new Dictionary<string, ReportDiagnostic>();
for (var i = 8600; i <= 8655; i++)
{
nullableDiagnostics.Add($"CS{i}", ReportDiagnostic.Error);
}

return nullableDiagnostics;
}

public bool EnableScriptNuGetReferences { get; set; }

public string DefaultTargetFramework { get; set; } = "net461";
Expand All @@ -24,5 +45,7 @@ public string GetNormalizedRspFilePath(IOmniSharpEnvironment env)
? RspFilePath
: Path.Combine(env.TargetDirectory, RspFilePath);
}

public Dictionary<string, ReportDiagnostic> NullableDiagnostics => _nullableDiagnostics.Value;
}
}
13 changes: 9 additions & 4 deletions src/OmniSharp.Script/ScriptProjectProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private CSharpCommandLineArguments CreateCommandLineArguments()
_isDesktopClr ? Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.ManifestModule.FullyQualifiedName) : null);
}
}

return null;
}

Expand All @@ -100,6 +100,11 @@ private CSharpCompilationOptions CreateCompilationOptions()
.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default)
.WithSpecificDiagnosticOptions(CompilationOptionsHelper.GetDefaultSuppressedDiagnosticOptions());

if (_scriptOptions.IsNugetEnabled())
{
compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(_scriptOptions.NullableDiagnostics);
}

var topLevelBinderFlagsProperty = typeof(CSharpCompilationOptions).GetProperty(TopLevelBinderFlagsProperty, BindingFlags.Instance | BindingFlags.NonPublic);
var binderFlagsType = typeof(CSharpCompilationOptions).GetTypeInfo().Assembly.GetType(BinderFlagsType);

Expand All @@ -124,18 +129,18 @@ private CachingScriptMetadataResolver CreateMetadataReferenceResolver()
InjectXMLDocumentationProviderIntoRuntimeMetadataReferenceResolver(defaultResolver);

var decoratedResolver = _scriptOptions.EnableScriptNuGetReferences
? new CachingScriptMetadataResolver(new NuGetMetadataReferenceResolver(defaultResolver))
? new CachingScriptMetadataResolver(new NuGetMetadataReferenceResolver(defaultResolver))
: new CachingScriptMetadataResolver(defaultResolver);

return decoratedResolver;
}

public ProjectInfo CreateProject(string csxFileName, IEnumerable<MetadataReference> references, string csxFilePath, Type globalsType, IEnumerable<string> namespaces = null)
{
var csharpCommandLineArguments = _commandLineArgs.Value;

// if RSP file was used, include the metadata references from RSP merged with the provided set
// otherwise just use the provided metadata references
// otherwise just use the provided metadata references
if (csharpCommandLineArguments != null && csharpCommandLineArguments.MetadataReferences.Any())
{
var resolvedRspReferences = csharpCommandLineArguments.ResolveMetadataReferences(_compilationOptions.Value.MetadataReferenceResolver);
Expand Down
22 changes: 12 additions & 10 deletions src/OmniSharp.Script/ScriptProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ public void Initalize(IConfiguration configuration)
if (Initialized) return;

_scriptOptions = new ScriptOptions();
ConfigurationBinder.Bind(configuration, _scriptOptions);

_scriptContext = new Lazy<ScriptContext>(() => _scriptContextProvider.CreateScriptContext(_scriptOptions));
ConfigurationBinder.Bind(configuration, _scriptOptions);

_logger.LogInformation($"Detecting CSX files in '{_env.TargetDirectory}'.");

// Nothing to do if there are no CSX files
var allCsxFiles = _fileSystemHelper.GetFiles("**/*.csx").ToArray();

_scriptContext = new Lazy<ScriptContext>(() => _scriptContextProvider.CreateScriptContext(_scriptOptions, allCsxFiles));

if (allCsxFiles.Length == 0)
{
_logger.LogInformation("Could not find any CSX files");
Expand Down Expand Up @@ -110,14 +112,14 @@ private void AddToWorkspace(string csxPath)
var csxFileName = Path.GetFileName(csxPath);
var project = _scriptContext.Value.ScriptProjectProvider.CreateProject(csxFileName, _scriptContext.Value.MetadataReferences, csxPath, _scriptContext.Value.GlobalsType);

if (_scriptOptions.IsNugetEnabled())
{
var scriptMap = _scriptContext.Value.CompilationDependencies.ToDictionary(rdt => rdt.Name, rdt => rdt.Scripts);
var options = project.CompilationOptions.WithSourceReferenceResolver(
new NuGetSourceReferenceResolver(ScriptSourceResolver.Default,
scriptMap));
project = project.WithCompilationOptions(options);
}
if (_scriptOptions.IsNugetEnabled())
{
var scriptMap = _scriptContext.Value.CompilationDependencies.ToDictionary(rdt => rdt.Name, rdt => rdt.Scripts);
var options = project.CompilationOptions.WithSourceReferenceResolver(
new NuGetSourceReferenceResolver(ScriptSourceResolver.Default,
scriptMap));
project = project.WithCompilationOptions(options);
}

// add CSX project to workspace
_workspace.AddProject(project);
Expand Down