Skip to content

Commit 6fa9778

Browse files
committed
Cleaned up MSVCToolchain.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 5aaa0a0 commit 6fa9778

File tree

1 file changed

+47
-38
lines changed

1 file changed

+47
-38
lines changed

src/Core/Toolchains/MSVCToolchain.cs

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ public struct ToolchainVersion
3434

3535
public bool IsValid => Version > 0 && !string.IsNullOrEmpty(Directory);
3636

37-
public override string ToString()
38-
{
39-
return string.Format("{0} (version: {1})", Directory, Version);
40-
}
37+
public override string ToString() => $"{Directory} (version: {Version})";
4138
}
4239

4340
/// <summary>
@@ -53,13 +50,6 @@ public struct Version
5350

5451
public static class MSVCToolchain
5552
{
56-
static void DumpSdks(string sku, IEnumerable<ToolchainVersion> sdks)
57-
{
58-
Console.WriteLine("\n{0} SDKs:", sku);
59-
foreach (var sdk in sdks)
60-
Console.WriteLine("\t({0}) {1}", sdk.Version, sdk.Directory);
61-
}
62-
6353
/// <summary>Dumps the detected SDK versions.</summary>
6454
public static void DumpSdks()
6555
{
@@ -120,24 +110,6 @@ public static Version GetCLVersion(VisualStudioVersion vsVersion)
120110
return clVersion;
121111
}
122112

123-
static int GetVisualStudioVersion(VisualStudioVersion version)
124-
{
125-
switch (version)
126-
{
127-
case VisualStudioVersion.VS2012:
128-
return 11;
129-
case VisualStudioVersion.VS2013:
130-
return 12;
131-
case VisualStudioVersion.VS2015:
132-
return 14;
133-
case VisualStudioVersion.VS2017:
134-
case VisualStudioVersion.Latest:
135-
return 15;
136-
default:
137-
throw new Exception("Unknown Visual Studio version");
138-
}
139-
}
140-
141113
public static ToolchainVersion GetVSToolchain(VisualStudioVersion vsVersion)
142114
{
143115
List<ToolchainVersion> vsSdks;
@@ -173,7 +145,7 @@ public static ToolchainVersion GetWindowsKitsToolchain(VisualStudioVersion vsVer
173145
if (match.Success)
174146
windowsSdkMajorVer = int.Parse(match.Groups[1].Value);
175147

176-
match = Regex.Match(vcVarsFile, @"KitsRoot([1-9][0-9]*)");
148+
match = Regex.Match(vcVarsFile, "KitsRoot([1-9][0-9]*)");
177149
if (match.Success)
178150
kitsRootKey = match.Groups[0].Value;
179151

@@ -186,7 +158,7 @@ public static ToolchainVersion GetWindowsKitsToolchain(VisualStudioVersion vsVer
186158
// If for some reason we cannot find the SDK version reported by VS
187159
// in the system, then fallback to the latest version found.
188160
if (windowsKitSdk.Value == null)
189-
windowsKitSdk = windowsKitsSdks.Last();
161+
windowsKitSdk = windowsKitsSdks.Last();
190162
return windowsKitSdk;
191163
}
192164

@@ -225,6 +197,31 @@ public static List<string> GetSystemIncludes(VisualStudioVersion wantedVsVersion
225197
return new List<string>();
226198
}
227199

200+
private static void DumpSdks(string sku, IEnumerable<ToolchainVersion> sdks)
201+
{
202+
Console.WriteLine("\n{0} SDKs:", sku);
203+
foreach (var sdk in sdks)
204+
Console.WriteLine("\t({0}) {1}", sdk.Version, sdk.Directory);
205+
}
206+
207+
private static int GetVisualStudioVersion(VisualStudioVersion version)
208+
{
209+
switch (version)
210+
{
211+
case VisualStudioVersion.VS2012:
212+
return 11;
213+
case VisualStudioVersion.VS2013:
214+
return 12;
215+
case VisualStudioVersion.VS2015:
216+
return 14;
217+
case VisualStudioVersion.VS2017:
218+
case VisualStudioVersion.Latest:
219+
return 15;
220+
default:
221+
throw new Exception("Unknown Visual Studio version");
222+
}
223+
}
224+
228225
private static List<string> GetSystemIncludes(VisualStudioVersion vsVersion, string vsDir)
229226
{
230227
if (vsVersion == VisualStudioVersion.VS2017)
@@ -405,7 +402,7 @@ public static bool GetWindowsSdks(out List<ToolchainVersion> versions)
405402
GetToolchainsFromSystemRegistry(
406403
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows",
407404
"InstallationFolder", versions, RegistryView.Registry64);
408-
}
405+
}
409406
versions.Sort((v1, v2) => (int)(v1.Version - v2.Version));
410407
return versions.Count != 0;
411408
}
@@ -473,7 +470,13 @@ public static bool GetVisualStudioSdks(out List<ToolchainVersion> versions)
473470
return true;
474471
}
475472

473+
/// <summary>
476474
/// Read registry strings looking for matching values.
475+
/// </summary>
476+
/// <param name="keyPath">The path to the key in the registry.</param>
477+
/// <param name="matchValue">The value to match in the located key, if any.</param>
478+
/// <param name="entries">The collected tool-chains.</param>
479+
/// <param name="view">The type of registry, 32 or 64, to target.</param>
477480
public static bool GetToolchainsFromSystemRegistryValues(string keyPath,
478481
string matchValue, ICollection<ToolchainVersion> entries, RegistryView view)
479482
{
@@ -518,6 +521,7 @@ public static bool GetToolchainsFromSystemRegistryValues(string keyPath,
518521
return true;
519522
}
520523

524+
/// <summary>
521525
/// Read registry string.
522526
/// This also supports a means to look for high-versioned keys by use
523527
/// of a $VERSION placeholder in the key path.
@@ -526,7 +530,12 @@ public static bool GetToolchainsFromSystemRegistryValues(string keyPath,
526530
/// I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio".
527531
/// There can be additional characters in the component. Only the numeric
528532
/// characters are compared.
529-
static bool GetToolchainsFromSystemRegistry(string keyPath, string valueName,
533+
/// </summary>
534+
/// <param name="keyPath">The path to the key in the registry.</param>
535+
/// <param name="matchValue">The value to match in the located key, if any.</param>
536+
/// <param name="entries">The collected tool-chains.</param>
537+
/// <param name="view">The type of registry, 32 or 64, to target.</param>
538+
private static bool GetToolchainsFromSystemRegistry(string keyPath, string valueName,
530539
ICollection<ToolchainVersion> entries, RegistryView view)
531540
{
532541
string subKey;
@@ -549,7 +558,7 @@ static bool GetToolchainsFromSystemRegistry(string keyPath, string valueName,
549558
return true;
550559
}
551560

552-
static bool HandleToolchainRegistrySubKey(out ToolchainVersion entry,
561+
private static bool HandleToolchainRegistrySubKey(out ToolchainVersion entry,
553562
RegistryKey key, string valueName, string subKeyName)
554563
{
555564
entry = new ToolchainVersion();
@@ -585,7 +594,7 @@ static bool HandleToolchainRegistrySubKey(out ToolchainVersion entry,
585594
return true;
586595
}
587596

588-
static RegistryHive GetRegistryHive(string keyPath, out string subKey)
597+
private static RegistryHive GetRegistryHive(string keyPath, out string subKey)
589598
{
590599
var hive = (RegistryHive)0;
591600
subKey = null;
@@ -647,7 +656,7 @@ private static List<string> GetSystemIncludesVS2017(string vsDir)
647656
where package.GetId().Contains("Microsoft.VisualStudio.Component.VC.Tools")
648657
orderby package.GetId()
649658
select package;
650-
if (vc_tools.Count() > 0)
659+
if (vc_tools.Any())
651660
{ // Tools found, get path
652661
var path = instance.GetInstallationPath();
653662
var versionFilePath = path + @"\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt";
@@ -664,7 +673,7 @@ where sdk.GetId().Contains("Windows10SDK")
664673
var win8sdks = from sdk in sdks
665674
where sdk.GetId().Contains("Windows81SDK")
666675
select sdk;
667-
if (win10sdks.Count() > 0)
676+
if (win10sdks.Any())
668677
{
669678
var sdk = win10sdks.Last();
670679
var matchVersion = regexWinSDK10Version.Match(sdk.GetId());
@@ -697,7 +706,7 @@ where sdk.GetId().Contains("Windows81SDK")
697706
includes.Add(ucrt);
698707
}
699708
}
700-
else if (win8sdks.Count() > 0)
709+
else if (win8sdks.Any())
701710
{
702711
includes.Add(@"C:\Program Files (x86)\Windows Kits\8.1\include\shared");
703712
includes.Add(@"C:\Program Files (x86)\Windows Kits\8.1\include\um");

0 commit comments

Comments
 (0)