Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion HotReloadUtils.slnx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Solution>
<Folder Name="/tests/">
<Project Path="tests/Acceptance/EncCapabilitiesCompat.Tests/EncCapabilitiesCompat.Tests.csproj" />
<Project Path="tests/BuildTool/ImportExplcitly.ShouldNotRun.Tests/ImportExplicitly.ShouldNotRun.Tests.csproj" />
<Project Path="tests/BuildTool/ImportExplcitly.Tests/ImportExplicitly.Tests.csproj" />
<Project Path="tests/HotReload.Generator/EnC.Tests/EnC.Tests.csproj" />
Expand Down
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Dependencies>
<ProductDependencies>
<Dependency Name="Microsoft.CodeAnalysis" Version="5.3.0-1.25516.1">
<Dependency Name="Microsoft.CodeAnalysis" Version="5.3.0-1.25524.13">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>f5dcba88147466b9f989f60bc873c9e083938bf1</Sha>
<Sha>e7d28d80af8c576206dacf05e09cde03a105fb38</Sha>
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- Opt-out repo features -->
<UsingToolXliff>false</UsingToolXliff>
<!-- roslyn -->
<MicrosoftCodeAnalysisVersion>5.3.0-1.25516.1</MicrosoftCodeAnalysisVersion>
<MicrosoftCodeAnalysisVersion>5.3.0-1.25524.13</MicrosoftCodeAnalysisVersion>
<!-- arcade -->
<MicrosoftDotNetBuildTasksTemplatingVersion>11.0.0-beta.25524.1</MicrosoftDotNetBuildTasksTemplatingVersion>
<MicrosoftDotNetRemoteExecutorVersion>11.0.0-beta.25524.1</MicrosoftDotNetRemoteExecutorVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.ExternalAccess.HotReload.Api;

namespace Microsoft.DotNet.HotReload.Utils.Generator;

Expand All @@ -12,4 +13,4 @@ namespace Microsoft.DotNet.HotReload.Utils.Generator;
/// BaselineOutputAsmPath: absolute path of the baseline assembly
/// DocResolver: a map from document ids to documents
/// ChangeMakerService: A stateful encapsulatio of the series of changes that have been made to the baseline
public record struct BaselineArtifacts (Solution BaselineSolution, ProjectId BaselineProjectId, string BaselineOutputAsmPath, DocResolver DocResolver, EnC.ChangeMakerService ChangeMakerService);
internal record struct BaselineArtifacts (Solution BaselineSolution, ProjectId BaselineProjectId, string BaselineOutputAsmPath, DocResolver DocResolver, HotReloadService HotReloadService);
58 changes: 33 additions & 25 deletions src/Microsoft.DotNet.HotReload.Utils.Generator/BaselineProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,57 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ExternalAccess.HotReload.Api;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;
using Microsoft.Build.Framework;
using System.Linq;
using System.Collections.Immutable;

namespace Microsoft.DotNet.HotReload.Utils.Generator;

public record BaselineProject (Solution Solution, ProjectId ProjectId, EnC.ChangeMakerService ChangeMakerService) {

internal record BaselineProject (Solution Solution, ProjectId ProjectId, HotReloadService HotReloadService) {

public static async Task<BaselineProject> Make (Config config, EnC.EditAndContinueCapabilities capabilities, CancellationToken ct = default) {
(var changeMakerService, var solution, var projectId) = await PrepareMSBuildProject(config, capabilities, ct);
return new BaselineProject(solution, projectId, changeMakerService);
}

static async Task<(EnC.ChangeMakerService, Solution, ProjectId)> PrepareMSBuildProject (Config config, EnC.EditAndContinueCapabilities capabilities, CancellationToken ct = default)
static async Task<(HotReloadService, Solution, ProjectId)> PrepareMSBuildProject (Config config, EnC.EditAndContinueCapabilities capabilities, CancellationToken ct = default)
{
Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace msw;
// https://stackoverflow.com/questions/43386267/roslyn-project-configuration says I have to specify at least a Configuration property
// to get an output path, is that true?
var props = new Dictionary<string,string> (config.Properties);
msw = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create(props);
msw.LoadMetadataForReferencedProjects = true;
_ = msw.RegisterWorkspaceFailedHandler(diag => {
bool warning = diag.Diagnostic.Kind == WorkspaceDiagnosticKind.Warning;
if (!warning)
Console.WriteLine ($"msbuild failed opening project {config.ProjectPath}");
Console.WriteLine ($"MSBuildWorkspace {diag.Diagnostic.Kind}: {diag.Diagnostic.Message}");
if (!warning)
throw new DiffyException ("failed workspace", 1);
});
Microsoft.Build.Framework.ILogger? logger = null;
// https://stackoverflow.com/questions/43386267/roslyn-project-configuration says I have to specify at least a Configuration property
// to get an output path, is that true?
var props = new Dictionary<string,string> (config.Properties);
var workspace = MSBuildWorkspace.Create(props);
workspace.LoadMetadataForReferencedProjects = true;
_ = workspace.RegisterWorkspaceFailedHandler(diag => {
bool warning = diag.Diagnostic.Kind == WorkspaceDiagnosticKind.Warning;
if (!warning)
Console.WriteLine ($"msbuild failed opening project {config.ProjectPath}");
Console.WriteLine ($"MSBuildWorkspace {diag.Diagnostic.Kind}: {diag.Diagnostic.Message}");
if (!warning)
throw new DiffyException ("failed workspace", 1);
});

ILogger? logger = null;
#if false
logger = new Microsoft.Build.Logging.BinaryLogger () {
Parameters = "/tmp/enc.binlog"
};
logger = new Microsoft.Build.Logging.BinaryLogger () {
Parameters = "/tmp/enc.binlog"
};
#endif
var project = await msw.OpenProjectAsync (config.ProjectPath, logger, null, ct);
var project = await workspace.OpenProjectAsync (config.ProjectPath, logger, null, ct);

var service = new HotReloadService(
workspace.CurrentSolution.Services,
() => new([.. capabilities.ToString().Split(", ")]));

return (EnC.ChangeMakerService.Make (msw.Services, capabilities), msw.CurrentSolution, project.Id);
return (service, workspace.CurrentSolution, project.Id);
}


public async Task<BaselineArtifacts> PrepareBaseline (CancellationToken ct = default) {
await ChangeMakerService.StartSessionAsync(Solution, ct);
await HotReloadService.StartSessionAsync(Solution, ct);
var project = Solution.GetProject(ProjectId)!;

// gets a snapshot of the text of the baseline document in memory
Expand All @@ -70,7 +78,7 @@ public async Task<BaselineArtifacts> PrepareBaseline (CancellationToken ct = def
BaselineProjectId = ProjectId,
BaselineOutputAsmPath = outputAsm,
DocResolver = new DocResolver (project),
ChangeMakerService = ChangeMakerService
HotReloadService = HotReloadService
};
await t;
return artifacts;
Expand Down
25 changes: 13 additions & 12 deletions src/Microsoft.DotNet.HotReload.Utils.Generator/DeltaProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,30 @@
using System.Threading.Tasks;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.ExternalAccess.HotReload.Api;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.DotNet.HotReload.Utils.Generator;

/// Drives the creation of deltas from textual changes.
public class DeltaProject
internal class DeltaProject
{
readonly EnC.ChangeMakerService _changeMakerService;
readonly HotReloadService _hotReloadService;

readonly Solution _solution;
readonly ProjectId _baseProjectId;
readonly DeltaNaming _nextName;

public DeltaProject(BaselineArtifacts artifacts) {
_changeMakerService = artifacts.ChangeMakerService;
_hotReloadService = artifacts.HotReloadService;
_solution = artifacts.BaselineSolution;
_baseProjectId = artifacts.BaselineProjectId;
_nextName = new DeltaNaming(artifacts.BaselineOutputAsmPath, 1);
}

internal DeltaProject (DeltaProject prev, Solution newSolution)
{
_changeMakerService = prev._changeMakerService;
_hotReloadService = prev._hotReloadService;
_solution = newSolution;
_baseProjectId = prev._baseProjectId;
_nextName = prev._nextName.Next ();
Expand Down Expand Up @@ -92,28 +93,28 @@ public async Task<DeltaProject> BuildDelta (Delta delta, bool ignoreUnchanged =

Console.WriteLine ($"Found changes in {oldDocument.Name}");

var updates2 = await _changeMakerService.EmitSolutionUpdateAsync (updatedSolution, ct);
var updates = await _hotReloadService.GetUpdatesAsync (updatedSolution, runningProjects: [], ct);

if (updates2.CompilationDiagnostics.Any(d => d.Severity == DiagnosticSeverity.Error)) {
if (updates.PersistentDiagnostics.Any(d => d.Severity == DiagnosticSeverity.Error)) {
var sb = new StringBuilder();
foreach (var diag in updates2.CompilationDiagnostics) {
foreach (var diag in updates.PersistentDiagnostics) {
sb.AppendLine (diag.ToString ());
}
throw new DiffyException ($"Failed to emit delta for {oldDocument.Name}: {sb}", exitStatus: 8);
}

foreach (var fancyChange in updates2.ProjectUpdates)
foreach (var fancyChange in updates.ProjectUpdates)
{
Console.WriteLine("change service made {0}", fancyChange.ModuleId);
}

_changeMakerService.CommitUpdate();
_hotReloadService.CommitUpdate();

await using (var output = makeOutputs != null ? makeOutputs(dinfo) : DefaultMakeFileOutputs(dinfo)) {
if (updates2.ProjectUpdates.Length != 1) {
throw new DiffyException($"Expected only one module in the delta, got {updates2.ProjectUpdates.Length}", exitStatus: 10);
if (updates.ProjectUpdates.Length != 1) {
throw new DiffyException($"Expected only one module in the delta, got {updates.ProjectUpdates.Length}", exitStatus: 10);
}
var update = updates2.ProjectUpdates.First();
var update = updates.ProjectUpdates.First();
output.MetaStream.Write(update.MetadataDelta.AsSpan());
output.IlStream.Write(update.ILDelta.AsSpan());
output.PdbStream.Write(update.PdbDelta.AsSpan());
Expand Down
51 changes: 0 additions & 51 deletions src/Microsoft.DotNet.HotReload.Utils.Generator/EnC/ChangeMaker.cs

This file was deleted.

Loading