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
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,21 @@ private HotReloadSnapshotCaptureStats CaptureAssemblies(params string[] sources)
Array.Empty<UnityCompilationAssembly>(),
Array.Empty<string>(),
AssemblyFlags.EditorAssembly);
return HotReloadSourceSnapshotter.CaptureAssemblies(
HotReloadSnapshotCaptureInputs inputs = new HotReloadSnapshotCaptureInputs(
_root,
new[] { assembly },
HotReloadCompileStart.Unknown,
Array.Empty<HotReloadSnapshotPackageRoot>(),
StringComparison.Ordinal,
new[]
{
HotReloadSnapshotCaptureInputs.ToCaptureAssembly(
assembly,
Array.Empty<HotReloadSnapshotPackageRoot>(),
StringComparison.Ordinal)
},
0);
return HotReloadSourceSnapshotter.CaptureAssemblies(
inputs,
new HotReloadPdbDocumentIndex(Path.Combine(_root, "PdbDocuments")));
}

Expand All @@ -550,7 +561,9 @@ private HotReloadSnapshotSourceCheck CheckAgainst(string dllPath, string pdbPath
dllPath,
pdbPath,
HotReloadAssemblyMvid.Read(dllPath),
new HotReloadPdbDocumentIndex(Path.Combine(_root, "PdbDocuments")));
new HotReloadPdbDocumentIndex(Path.Combine(_root, "PdbDocuments")),
HotReloadSnapshotPackageRoots.ReadCurrent(),
HotReloadSnapshotCaptureInputs.CurrentPathComparison());
}

// A check whose suspect window never opens, so no copy is checked against a PDB.
Expand All @@ -561,7 +574,9 @@ private HotReloadSnapshotSourceCheck SuspectsNothing()
"unused.dll",
"unused.pdb",
"unused",
new HotReloadPdbDocumentIndex(Path.Combine(_root, "PdbDocuments")));
new HotReloadPdbDocumentIndex(Path.Combine(_root, "PdbDocuments")),
Array.Empty<HotReloadSnapshotPackageRoot>(),
StringComparison.Ordinal);
}

// Copies this test assembly's own DLL and PDB, so the fixture has a real image for Cecil to read.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public void CaptureAssemblies_WithoutStamp_CapturesSourcesRemovesStaleSnapshotAn
Directory.CreateDirectory(staleDirectory);

HotReloadSourceSnapshotter.CaptureAssemblies(
_projectRoot,
new[] { CreateAssembly("Fixture") },
HotReloadCompileStart.Unknown,
CreateInputs(_projectRoot, new[] { CreateAssembly("Fixture") }, HotReloadCompileStart.Unknown),
CreateDocumentIndex());

Assert.That(File.Exists(SnapshotSourcePath("Fixture", mvid)), Is.True);
Expand All @@ -88,9 +86,7 @@ public void CaptureAssemblies_WhenStampMatches_SkipsCapture()
File.WriteAllText(StampPath("Fixture"), stamp);

HotReloadSourceSnapshotter.CaptureAssemblies(
_projectRoot,
new[] { CreateAssembly("Fixture") },
HotReloadCompileStart.Unknown,
CreateInputs(_projectRoot, new[] { CreateAssembly("Fixture") }, HotReloadCompileStart.Unknown),
CreateDocumentIndex());

Assert.That(Directory.Exists(Path.Combine(_snapshotRoot, "Fixture-" + mvid)), Is.False);
Expand All @@ -112,9 +108,7 @@ public void CaptureAssemblies_WhenMvidDirectoryExists_KeepsSnapshotsAndWritesSta
Directory.CreateDirectory(staleDirectory);

HotReloadSourceSnapshotter.CaptureAssemblies(
_projectRoot,
new[] { CreateAssembly("Fixture") },
HotReloadCompileStart.Unknown,
CreateInputs(_projectRoot, new[] { CreateAssembly("Fixture") }, HotReloadCompileStart.Unknown),
CreateDocumentIndex());

Assert.That(Directory.GetFiles(currentDirectory), Is.Empty);
Expand Down Expand Up @@ -154,9 +148,7 @@ public void CaptureAssemblies_WhenStampIsMalformedOrDiffers_CapturesAgain(string
File.WriteAllText(StampPath("Fixture"), stamp);

HotReloadSourceSnapshotter.CaptureAssemblies(
_projectRoot,
new[] { CreateAssembly("Fixture") },
HotReloadCompileStart.Unknown,
CreateInputs(_projectRoot, new[] { CreateAssembly("Fixture") }, HotReloadCompileStart.Unknown),
CreateDocumentIndex());

Assert.That(Directory.Exists(HotReloadSourceSnapshotLayout.AssemblyDirectory(_projectRoot, "Fixture", mvid)), Is.True);
Expand Down Expand Up @@ -184,9 +176,7 @@ public void CaptureAssemblies_RemovesOnlyThisAssemblysStaleMvidDirectories()
Directory.CreateDirectory(nonMvid);

HotReloadSourceSnapshotter.CaptureAssemblies(
_projectRoot,
new[] { CreateAssembly("Fixture") },
HotReloadCompileStart.Unknown,
CreateInputs(_projectRoot, new[] { CreateAssembly("Fixture") }, HotReloadCompileStart.Unknown),
CreateDocumentIndex());

Assert.That(Directory.Exists(orphanTemporary), Is.False);
Expand All @@ -206,15 +196,36 @@ public void CaptureAssemblies_WhenAssemblyHasNoSources_WritesNothing()
string mvid = HotReloadAssemblyMvid.Read(dllPath);

HotReloadSourceSnapshotter.CaptureAssemblies(
_projectRoot,
new[] { CreateAssemblyWithSources("NoSources", Array.Empty<string>()) },
HotReloadCompileStart.Unknown,
CreateInputs(_projectRoot, new[] { CreateAssemblyWithSources("NoSources", Array.Empty<string>()) }, HotReloadCompileStart.Unknown),
CreateDocumentIndex());

Assert.That(Directory.Exists(HotReloadSourceSnapshotLayout.AssemblyDirectory(_projectRoot, "NoSources", mvid)), Is.False);
Assert.That(File.Exists(StampPath("NoSources")), Is.False);
}

/// <summary>
/// Verifies an assembly the inputs classified as an immutable package's is counted and skipped
/// before anything is written, though its DLL and PDB are there: no snapshot directory and no stamp.
/// </summary>
[Test]
public void CaptureAssemblies_ImmutablePackageAssembly_CountsItAndWritesNothing()
{
PlantCompiledAssembly("Fixture");
HotReloadSnapshotCaptureInputs inputs = new HotReloadSnapshotCaptureInputs(
_projectRoot,
HotReloadCompileStart.Unknown,
Array.Empty<HotReloadSnapshotPackageRoot>(),
StringComparison.Ordinal,
new[] { new HotReloadCaptureAssembly("Fixture", new[] { SourceRelativePath }, true) },
0);

HotReloadSnapshotCaptureStats stats = HotReloadSourceSnapshotter.CaptureAssemblies(inputs, CreateDocumentIndex());

Assert.That(stats.AssembliesImmutable, Is.EqualTo(1), "immutable");
Assert.That(Directory.GetDirectories(_snapshotRoot, "Fixture-*"), Is.Empty);
Assert.That(File.Exists(StampPath("Fixture")), Is.False);
}

/// <summary>
/// Verifies an assembly whose compiled DLL or PDB is missing is skipped without a warning: no snapshot directory and no stamp.
/// </summary>
Expand All @@ -226,9 +237,7 @@ public void CaptureAssemblies_WhenCompiledOutputIsMissing_WritesNothingAndDoesNo
File.Delete(Path.ChangeExtension(dllPath, missingExtension));

HotReloadSourceSnapshotter.CaptureAssemblies(
_projectRoot,
new[] { CreateAssembly("Fixture") },
HotReloadCompileStart.Unknown,
CreateInputs(_projectRoot, new[] { CreateAssembly("Fixture") }, HotReloadCompileStart.Unknown),
CreateDocumentIndex());

Assert.That(Directory.GetDirectories(_snapshotRoot, "Fixture-*"), Is.Empty);
Expand All @@ -252,9 +261,7 @@ public void CaptureAssemblies_WhenStampMatches_DoesNotOpenTheCompiledAssembly()
File.WriteAllText(StampPath("Fixture"), stamp);

HotReloadSourceSnapshotter.CaptureAssemblies(
_projectRoot,
new[] { CreateAssembly("Fixture") },
HotReloadCompileStart.Unknown,
CreateInputs(_projectRoot, new[] { CreateAssembly("Fixture") }, HotReloadCompileStart.Unknown),
CreateDocumentIndex());

Assert.That(Directory.Exists(HotReloadSourceSnapshotLayout.AssemblyDirectory(_projectRoot, "Fixture", mvid)), Is.False);
Expand All @@ -280,9 +287,7 @@ public void CaptureAssemblies_WhenOneAssemblyCannotBeRead_WarnsAndCapturesTheRes
LogAssert.Expect(LogType.Warning, new Regex("Snapshot capture failed for assembly Broken"));

HotReloadSourceSnapshotter.CaptureAssemblies(
_projectRoot,
new[] { CreateAssembly("Broken"), CreateAssembly("Fixture") },
HotReloadCompileStart.Unknown,
CreateInputs(_projectRoot, new[] { CreateAssembly("Broken"), CreateAssembly("Fixture") }, HotReloadCompileStart.Unknown),
CreateDocumentIndex());

Assert.That(File.Exists(StampPath("Broken")), Is.False);
Expand Down Expand Up @@ -343,9 +348,7 @@ public void CaptureAssemblies_ForVirtualPlayerRoot_ReadsTheMainProjectsDllAndSna
string mvid = HotReloadAssemblyMvid.Read(dllPath);

HotReloadSourceSnapshotter.CaptureAssemblies(
playerRoot,
new[] { CreateAssembly("Fixture") },
HotReloadCompileStart.Unknown,
CreateInputs(playerRoot, new[] { CreateAssembly("Fixture") }, HotReloadCompileStart.Unknown),
CreateDocumentIndex());

string playerSnapshotSource = HotReloadSourceSnapshotLayout.SourcePath(
Expand Down Expand Up @@ -417,14 +420,10 @@ public void CaptureAssemblies_ReturnsWhatItCopiedAndWhatItSkipped()
};

HotReloadSnapshotCaptureStats first = HotReloadSourceSnapshotter.CaptureAssemblies(
_projectRoot,
assemblies,
HotReloadCompileStart.Unknown,
CreateInputs(_projectRoot, assemblies, HotReloadCompileStart.Unknown),
CreateDocumentIndex());
HotReloadSnapshotCaptureStats second = HotReloadSourceSnapshotter.CaptureAssemblies(
_projectRoot,
assemblies,
HotReloadCompileStart.Unknown,
CreateInputs(_projectRoot, assemblies, HotReloadCompileStart.Unknown),
CreateDocumentIndex());

Assert.That(first.Assemblies, Is.EqualTo(1), "first: assemblies");
Expand Down Expand Up @@ -452,9 +451,7 @@ private string CaptureWithSourceSavedBetweenStartAndDll(
string mvid = HotReloadAssemblyMvid.Read(dllPath);

stats = HotReloadSourceSnapshotter.CaptureAssemblies(
_projectRoot,
new[] { CreateAssembly("Fixture") },
compileStart,
CreateInputs(_projectRoot, new[] { CreateAssembly("Fixture") }, compileStart),
CreateDocumentIndex());

return Path.Combine(_snapshotRoot, "Fixture-" + mvid);
Expand Down Expand Up @@ -511,6 +508,31 @@ private static UnityCompilationAssembly CreateAssemblyWithSources(string assembl
AssemblyFlags.EditorAssembly);
}

// The capture's inputs for a temporary root: no package is registered there, so every
// assembly reads as editable.
private static HotReloadSnapshotCaptureInputs CreateInputs(
string projectRoot,
IEnumerable<UnityCompilationAssembly> assemblies,
HotReloadCompileStart compileStart)
{
List<HotReloadCaptureAssembly> captureAssemblies = new List<HotReloadCaptureAssembly>();
foreach (UnityCompilationAssembly assembly in assemblies)
{
captureAssemblies.Add(HotReloadSnapshotCaptureInputs.ToCaptureAssembly(
assembly,
Array.Empty<HotReloadSnapshotPackageRoot>(),
StringComparison.Ordinal));
}

return new HotReloadSnapshotCaptureInputs(
projectRoot,
compileStart,
Array.Empty<HotReloadSnapshotPackageRoot>(),
StringComparison.Ordinal,
captureAssemblies,
0);
}

private string SnapshotSourcePath(string assemblyName, string mvid)
{
return HotReloadSourceSnapshotLayout.SourcePath(
Expand Down
Loading
Loading