Skip to content

Commit

Permalink
Merge branch 'jsp/optimize-GetVisualStudioVCToolsCompilerVersion' int…
Browse files Browse the repository at this point in the history
…o 'main'

Add cache for GetVisualStudioVCToolsCompilerVersion()

See merge request Sharpmake/sharpmake!574
  • Loading branch information
jspelletier committed Nov 13, 2024
2 parents 8d2b1da + 3f0d2da commit a47e8de
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Sharpmake/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,18 @@ public static Version GetVisualStudioVCToolsVersion(this DevEnv visualVersion)
return version;
}

private static ConcurrentDictionary<(DevEnv, Platform), Version> s_visualStudioCompilerVersionCache = new ConcurrentDictionary<(DevEnv, Platform), Version>();

public static Version GetVisualStudioVCToolsCompilerVersion(this DevEnv visualVersion, Platform platform)
{
string clExeFile = Path.Combine(visualVersion.GetVisualStudioBinPath(platform), "cl.exe");
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(clExeFile);
return new Version(fileVersionInfo.FileMajorPart, fileVersionInfo.FileMinorPart, fileVersionInfo.FileBuildPart, fileVersionInfo.FilePrivatePart);
var cacheKey = (visualVersion, platform);
Version version = s_visualStudioCompilerVersionCache.GetOrAdd(cacheKey, ((DevEnv, Platform) key) =>
{
string clExeFile = Path.Combine(visualVersion.GetVisualStudioBinPath(platform), "cl.exe");
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(clExeFile);
return new Version(fileVersionInfo.FileMajorPart, fileVersionInfo.FileMinorPart, fileVersionInfo.FileBuildPart, fileVersionInfo.FilePrivatePart);
});
return version;
}

/// <summary>
Expand Down

0 comments on commit a47e8de

Please sign in to comment.