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

Refactor to expose dependencies on NodeContext and avoid NodeContextRepository lookups #92

Merged
merged 1 commit into from
Oct 14, 2024
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
2 changes: 0 additions & 2 deletions src/AzureBlobStorage/MSBuildCacheAzureBlobStoragePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public sealed class MSBuildCacheAzureBlobStoragePlugin : MSBuildCachePluginBase<
protected override async Task<ICacheClient> CreateCacheClientAsync(PluginLoggerBase logger, CancellationToken cancellationToken)
{
if (Settings == null
|| NodeContextRepository == null
|| FingerprintFactory == null
|| ContentHasher == null
|| NugetPackageRoot == null)
Expand Down Expand Up @@ -94,7 +93,6 @@ protected override async Task<ICacheClient> CreateCacheClientAsync(PluginLoggerB
ContentHasher,
Settings.RepoRoot,
NugetPackageRoot,
NodeContextRepository,
GetFileRealizationMode,
Settings.MaxConcurrentCacheContentOperations,
Settings.AsyncCachePublishing,
Expand Down
2 changes: 0 additions & 2 deletions src/AzurePipelines/MSBuildCacheAzurePipelinesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public sealed class MSBuildCacheAzurePipelinesPlugin : MSBuildCachePluginBase
protected override async Task<ICacheClient> CreateCacheClientAsync(PluginLoggerBase logger, CancellationToken cancellationToken)
{
if (Settings == null
|| NodeContextRepository == null
|| FingerprintFactory == null
|| ContentHasher == null
|| NugetPackageRoot == null)
Expand Down Expand Up @@ -58,7 +57,6 @@ protected override async Task<ICacheClient> CreateCacheClientAsync(PluginLoggerB
Settings.CacheUniverse,
Settings.RepoRoot,
NugetPackageRoot,
NodeContextRepository,
GetFileRealizationMode,
Settings.MaxConcurrentCacheContentOperations,
Settings.RemoteCacheIsReadOnly,
Expand Down
3 changes: 1 addition & 2 deletions src/AzurePipelines/PipelineCachingCacheClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,12 @@ public PipelineCachingCacheClient(
string universe,
string repoRoot,
string nugetPackageRoot,
INodeContextRepository nodeContextRepository,
Func<string, FileRealizationMode> getFileRealizationMode,
int maxConcurrentCacheContentOperations,
bool remoteCacheIsReadOnly,
bool enableAsyncPublishing,
bool enableAsyncMaterialization)
: base(rootContext, fingerprintFactory, hasher, repoRoot, nugetPackageRoot, nodeContextRepository, getFileRealizationMode, localCache, localCAS, maxConcurrentCacheContentOperations, enableAsyncPublishing, enableAsyncMaterialization)
: base(rootContext, fingerprintFactory, hasher, repoRoot, nugetPackageRoot, getFileRealizationMode, localCache, localCAS, maxConcurrentCacheContentOperations, enableAsyncPublishing, enableAsyncMaterialization)
{
_remoteCacheIsReadOnly = remoteCacheIsReadOnly;
_universe = $"pccc-{(int)hasher.Info.HashType}-{InternalSeed}-" + (string.IsNullOrEmpty(universe) ? "DEFAULT" : universe);
Expand Down
9 changes: 2 additions & 7 deletions src/Common/Caching/CacheClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using BuildXL.Cache.ContentStore.UtilitiesCore;
using BuildXL.Cache.MemoizationStore.Interfaces.Caches;
using BuildXL.Cache.MemoizationStore.Interfaces.Sessions;
using Microsoft.Build.Graph;
using Microsoft.CopyOnWrite;
using Microsoft.MSBuildCache.Fingerprinting;
using Microsoft.MSBuildCache.Hashing;
Expand All @@ -40,7 +39,6 @@ public abstract class CacheClient : ICacheClient
private readonly ICopyOnWriteFilesystem _copyOnWriteFilesystem = CopyOnWriteFilesystemFactory.GetInstance();
private readonly IContentHasher _hasher;
private readonly IFingerprintFactory _fingerprintFactory;
private readonly INodeContextRepository _nodeContextRepository;
private readonly bool _enableAsyncMaterialization;
private readonly ICache _localCache;
private readonly string _nugetPackageRoot;
Expand All @@ -52,7 +50,6 @@ protected CacheClient(
IContentHasher hasher,
string repoRoot,
string nugetPackageRoot,
INodeContextRepository nodeContextRepository,
Func<string, FileRealizationMode> getFileRealizationMode,
ICache localCache,
IContentSession localCas,
Expand All @@ -66,7 +63,6 @@ protected CacheClient(
EmptySelector = new(hasher.Info.EmptyHash, EmptySelectorOutput);
RepoRoot = repoRoot;
_nugetPackageRoot = nugetPackageRoot;
_nodeContextRepository = nodeContextRepository;
_localCache = localCache;
LocalCacheSession = localCas;
EnableAsyncPublishing = enableAsyncPublishing;
Expand Down Expand Up @@ -356,10 +352,9 @@ await AddNodeAsync(
// On cache miss ensure all dependencies are materialized before returning to MSBuild so that MSBuild's execution will actually work.
if (_enableAsyncMaterialization && result.NodeBuildResult == null)
{
foreach (ProjectGraphNode dependencyNode in nodeContext.Node.ProjectReferences)
foreach (NodeContext dependency in nodeContext.Dependencies)
{
if (_nodeContextRepository.TryGetNodeContext(dependencyNode.ProjectInstance, out NodeContext? dependency)
&& _materializationTasks.TryGetValue(dependency, out Task? dependencyMaterializationTask))
if (_materializationTasks.TryGetValue(dependency, out Task? dependencyMaterializationTask))
{
await dependencyMaterializationTask;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Common/Caching/CasCacheClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ public CasCacheClient(
IContentHasher hasher,
string repoRoot,
string nugetPackageRoot,
INodeContextRepository nodeContextRepository,
Func<string, FileRealizationMode> getFileRealizationMode,
int maxConcurrentCacheContentOperations,
bool enableAsyncPublishing,
bool enableAsyncMaterialization)
: base(rootContext, fingerprintFactory, hasher, repoRoot, nugetPackageRoot, nodeContextRepository, getFileRealizationMode, localCache, localCacheSession, maxConcurrentCacheContentOperations, enableAsyncPublishing, enableAsyncMaterialization)
: base(rootContext, fingerprintFactory, hasher, repoRoot, nugetPackageRoot, getFileRealizationMode, localCache, localCacheSession, maxConcurrentCacheContentOperations, enableAsyncPublishing, enableAsyncMaterialization)
{
ICacheSession cacheSession;
if (remoteCache == null)
Expand Down
25 changes: 4 additions & 21 deletions src/Common/Fingerprinting/FingerprintFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using BuildXL.Cache.ContentStore.Hashing;
using BuildXL.Cache.ContentStore.Interfaces.Extensions;
using DotNet.Globbing;
using Microsoft.Build.Graph;
using Microsoft.MSBuildCache.Hashing;

namespace Microsoft.MSBuildCache.Fingerprinting;
Expand All @@ -31,26 +30,20 @@ public sealed class FingerprintFactory : IFingerprintFactory
private readonly ConcurrentDictionary<string, byte[]> _stringHashCache = new(StringComparer.OrdinalIgnoreCase);
private readonly IContentHasher _contentHasher;
private readonly IInputHasher _inputHasher;
private readonly INodeContextRepository _nodeContextRepository;
private readonly List<FingerprintEntry> _pluginSettingsFingerprintEntries;
private readonly PluginSettings _pluginSettings;
private readonly PathNormalizer _pathNormalizer;
private readonly string _repoRoot;

public FingerprintFactory(
IContentHasher contentHasher,
IInputHasher inputHasher,
INodeContextRepository nodeRepository,
PluginSettings pluginSettings,
PathNormalizer pathNormalizer,
string repoRoot)
PathNormalizer pathNormalizer)
{
_contentHasher = contentHasher;
_inputHasher = inputHasher;
_nodeContextRepository = nodeRepository;
_pluginSettings = pluginSettings;
_pathNormalizer = pathNormalizer;
_repoRoot = repoRoot;

_pluginSettingsFingerprintEntries = new List<FingerprintEntry>()
{
Expand Down Expand Up @@ -100,14 +93,14 @@ void AddSettingToFingerprint(IReadOnlyCollection<Glob>? patterns, string setting
entries.Add(CreateFingerprintEntry($"Targets: {targetList}"));

// If the VC toolchain changes, the node should rebuild.
string vcToolsVersion = nodeContext.Node.ProjectInstance.GetPropertyValue("VCToolsVersion");
string vcToolsVersion = nodeContext.ProjectInstance.GetPropertyValue("VCToolsVersion");
if (!string.IsNullOrEmpty(vcToolsVersion))
{
entries.Add(CreateFingerprintEntry($"VCToolsVersion: {vcToolsVersion}"));
}

// If the .NET SDK changes, the node should rebuild.
string dotnetSdkVersion = nodeContext.Node.ProjectInstance.GetPropertyValue("NETCoreSdkVersion");
string dotnetSdkVersion = nodeContext.ProjectInstance.GetPropertyValue("NETCoreSdkVersion");
if (!string.IsNullOrEmpty(dotnetSdkVersion))
{
entries.Add(CreateFingerprintEntry($"DotnetSdkVersion: {dotnetSdkVersion}"));
Expand All @@ -118,18 +111,8 @@ void AddSettingToFingerprint(IReadOnlyCollection<Glob>? patterns, string setting

// Gather dependencies. Dependencies are sorted for a consistent hash ordering.
SortedDictionary<string, NodeContext> dependencies = new(StringComparer.Ordinal);
foreach (ProjectGraphNode dependencyNode in nodeContext.Node.ProjectReferences)
foreach (NodeContext dependency in nodeContext.Dependencies)
{
if (!_nodeContextRepository.TryGetNodeContext(dependencyNode.ProjectInstance, out NodeContext? dependency))
{
if (!dependencyNode.ProjectInstance.FullPath.IsUnderDirectory(_repoRoot))
{
continue;
}

return null;
}

if (dependency.BuildResult == null)
{
// The dependency has not been built, or at least not successfully
Expand Down
12 changes: 0 additions & 12 deletions src/Common/INodeContextRepository.cs

This file was deleted.

Loading