Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

Commit 855d0fb

Browse files
committed
Merge branch 'add-vs2022'
2 parents 056b05d + dff078b commit 855d0fb

File tree

4 files changed

+65
-27
lines changed

4 files changed

+65
-27
lines changed

Common/Helper.cs

+18-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static class Helper
2020
public const string ConfigurationDelimiter = "/";
2121
public static readonly object LockObject = new object();
2222
public static readonly int MaxDegreeOfParallelism = CementSettings.Get().MaxDegreeOfParallelism ?? 2 * Environment.ProcessorCount;
23-
public static ParallelOptions ParallelOptions => new ParallelOptions { MaxDegreeOfParallelism = MaxDegreeOfParallelism };
23+
public static ParallelOptions ParallelOptions => new ParallelOptions {MaxDegreeOfParallelism = MaxDegreeOfParallelism};
2424
public static string CurrentWorkspace { get; private set; }
2525
public static readonly object PackageLockObject = new object();
2626
private static readonly ILogger Log = LogManager.GetLogger(typeof(Helper));
@@ -175,7 +175,8 @@ public static string GetCurrentBuildCommitHash()
175175
public static string GetAssemblyTitle()
176176
{
177177
return ((AssemblyTitleAttribute)
178-
Attribute.GetCustomAttribute(Assembly.GetEntryAssembly(),
178+
Attribute.GetCustomAttribute(
179+
Assembly.GetEntryAssembly(),
179180
typeof(AssemblyTitleAttribute))).Title;
180181
}
181182

@@ -189,6 +190,7 @@ public static string ConvertTime(long millisecs)
189190
{
190191
idx++;
191192
}
193+
192194
res = res.Substring(idx);
193195
return res;
194196
}
@@ -211,6 +213,7 @@ public static string GetModuleDirectory(string path)
211213
path = parent.FullName;
212214
parent = Directory.GetParent(parent.FullName);
213215
}
216+
214217
return null;
215218
}
216219

@@ -221,6 +224,7 @@ public static string GetWorkspaceDirectory(string path)
221224
{
222225
folder = Directory.GetParent(folder.FullName);
223226
}
227+
224228
return folder?.FullName;
225229
}
226230

@@ -231,6 +235,7 @@ public static string GetRelativePath(string filePath, string fromFolder)
231235
{
232236
fromFolder += Path.DirectorySeparatorChar;
233237
}
238+
234239
var folderUri = new Uri(fromFolder);
235240
return Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString().Replace('/', Path.DirectorySeparatorChar));
236241
}
@@ -244,6 +249,7 @@ public static string GetRootFolder(string path)
244249
break;
245250
path = temp;
246251
}
252+
247253
return path;
248254
}
249255

@@ -297,11 +303,14 @@ public static string FixPath([NotNull] string path)
297303
return path.Replace('\\', Path.DirectorySeparatorChar);
298304
}
299305

300-
public static string ProgramFiles()
306+
public static ProgramFilesInfo GetProgramFilesInfo()
301307
{
302-
var programFiles = Environment.GetEnvironmentVariable("ProgramFiles(x86)") ??
303-
Environment.GetEnvironmentVariable("ProgramFiles");
304-
return programFiles;
308+
var x86 = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
309+
var x64 = Environment.GetEnvironmentVariable("ProgramFiles");
310+
if (x64 == null && x86 == null)
311+
return null;
312+
313+
return new ProgramFilesInfo {x64 = x64, x86 = x86};
305314
}
306315

307316
public static IReadOnlyList<string> VisualStudioEditions { get; } =
@@ -314,16 +323,13 @@ public static string ProgramFiles()
314323
}.AsReadOnly();
315324

316325
public static IReadOnlyList<string> VisualStudioVersions { get; } =
317-
new List<string>
318-
{
319-
"2017",
320-
"2019",
321-
}.AsReadOnly();
326+
new List<string> {"2017", "2019", "2022"}.AsReadOnly();
322327

323328
public static string GetEnvVariableByVisualStudioVersion(string version)
324329
{
325330
switch (version)
326331
{
332+
case "2022": return "VS170COMNTOOLS";
327333
case "2019": return "VS160COMNTOOLS";
328334
default: return "VS150COMNTOOLS";
329335
}
@@ -393,6 +399,7 @@ public static string GetMsBuildVersion(string fullPathToMsBuild)
393399
{
394400
Log.LogWarning("Failed to get MSBuild version from " + fullPathToMsBuild, e);
395401
}
402+
396403
return null;
397404
}
398405
}

Common/ModuleBuilderHelper.cs

+16-9
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ private static string FindMsBuildUnix(string version, string moduleName)
4949

5050
public static List<KeyValuePair<string, string>> FindMsBuildsWindows()
5151
{
52-
if (msBuildsCache != null)
53-
return msBuildsCache;
54-
5552
var result = new List<KeyValuePair<string, string>>();
5653

5754
var ms1 = FindAvailableMsBuildsInProgramFiles();
@@ -66,11 +63,11 @@ public static List<KeyValuePair<string, string>> FindMsBuildsWindows()
6663

6764
private static List<KeyValuePair<string, string>> FindAvailableMsBuildsInProgramFiles()
6865
{
69-
var programFiles = Helper.ProgramFiles();
66+
var programFiles = Helper.GetProgramFilesInfo();
7067
if (programFiles == null)
7168
return new List<KeyValuePair<string, string>>();
7269

73-
var folders = new List<string> {programFiles};
70+
var folders = new List<string> {programFiles.x86, programFiles.x64};
7471

7572
var variables = VsDevHelper.GetCurrentSetVariables();
7673
if (variables.ContainsKey("VSINSTALLDIR"))
@@ -79,7 +76,11 @@ private static List<KeyValuePair<string, string>> FindAvailableMsBuildsInProgram
7976
foreach (var version in Helper.VisualStudioVersions)
8077
foreach (var edition in Helper.VisualStudioEditions)
8178
{
82-
folders.Add(Path.Combine(programFiles, "Microsoft Visual Studio", version, edition));
79+
if (!string.IsNullOrWhiteSpace(programFiles.x86))
80+
folders.Add(Path.Combine(programFiles.x86, "Microsoft Visual Studio", version, edition));
81+
82+
if (!string.IsNullOrWhiteSpace(programFiles.x64))
83+
folders.Add(Path.Combine(programFiles.x64, "Microsoft Visual Studio", version, edition));
8384
}
8485

8586
return folders.SelectMany(FindAvailableMsBuildsIn).Distinct().OrderByDescending(k => k.Key).ToList();
@@ -104,19 +105,21 @@ private static List<KeyValuePair<string, string>> FindAvailableMsBuildsIn(string
104105
continue;
105106

106107
var match = new DirectoryInfo(bin).GetFiles("msbuild.exe")
107-
.Select(m => new {fullPath = m.FullName, version = Helper.GetMsBuildVersion(m.FullName) })
108+
.Select(m => new {fullPath = m.FullName, version = Helper.GetMsBuildVersion(m.FullName)})
108109
.LastOrDefault(v => !string.IsNullOrEmpty(v.version));
109110
if (match != null)
110111
{
111112
result.Add(new KeyValuePair<string, string>(match.version, match.fullPath));
112113
}
113114
}
115+
114116
return result;
115117
}
116118

117119
private static List<KeyValuePair<string, string>> FindAvailableMsBuildsInWindows()
118120
{
119121
var winDir = Environment.GetEnvironmentVariable("WINDIR");
122+
120123
if (winDir == null)
121124
throw new CementException("WINDIR system variable not found");
122125

@@ -141,7 +144,9 @@ private static List<FileInfo> SearchMsBuild(string frameworkDirectory)
141144

142145
var subFolders = Directory.GetDirectories(frameworkDirectory);
143146
return subFolders.Select(folder => Path.Combine(folder, "msbuild.exe"))
144-
.Where(File.Exists).Select(f => new FileInfo(f)).ToList();
147+
.Where(File.Exists)
148+
.Select(f => new FileInfo(f))
149+
.ToList();
145150
}
146151

147152
public static void KillMsBuild(ILogger log)
@@ -170,7 +175,9 @@ public static void KillMsBuild(ILogger log)
170175
public static string GetBuildScriptName(Dep dep)
171176
{
172177
var configToBuild = dep.Configuration == "full-build" || dep.Configuration == null ? "" : "." + dep.Configuration;
173-
return Path.Combine(Helper.CurrentWorkspace, dep.Name,
178+
return Path.Combine(
179+
Helper.CurrentWorkspace,
180+
dep.Name,
174181
"build" + configToBuild + ".cmd");
175182
}
176183

Common/ProgramFilesInfo.cs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Common
2+
{
3+
public class ProgramFilesInfo
4+
{
5+
public string x86 { get; set; }
6+
public string x64 { get; set; }
7+
}
8+
}

Common/VsDevHelper.cs

+23-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static Dictionary<string, string> GetCurrentSetVariables()
2121
{
2222
result.Add(de.Key.ToString(), de.Value.ToString());
2323
}
24+
2425
return result;
2526
}
2627

@@ -37,8 +38,10 @@ public static void ReplaceVariablesToVs()
3738
private static Dictionary<string, string> GetVsSetVariables()
3839
{
3940
var text = RunVsDevCmd();
41+
4042
if (text == null)
4143
return null;
44+
4245
var lines = text.Split('\n');
4346
var result = new Dictionary<string, string>();
4447
foreach (var line in lines)
@@ -50,6 +53,7 @@ private static Dictionary<string, string> GetVsSetVariables()
5053
var value = line.Substring(equal + 1);
5154
result.Add(name, value);
5255
}
56+
5357
return result;
5458
}
5559

@@ -61,14 +65,16 @@ private static string RunVsDevCmd()
6165
Log.LogDebug("VsDevCmd.bat not found");
6266
return null;
6367
}
64-
Log.LogInformation($"VsDevCmd found in {path}");
68+
69+
Log.LogInformation($"VsDevCmd found in '{path}'");
6570
var command = $"\"{path}\" && set";
6671
var runner = new ShellRunner();
6772
if (runner.Run(command) != 0)
6873
{
6974
Log.LogDebug("VsDevCmd.bat not working");
7075
return null;
7176
}
77+
7278
return runner.Output;
7379
}
7480

@@ -79,20 +85,30 @@ private static string FindVsDevCmd()
7985
foreach (var key in set.Keys)
8086
{
8187
if (key.StartsWith("VS") && key.EndsWith("COMNTOOLS"))
82-
paths.Add(new KeyValuePair<string, string>(
83-
key, Path.Combine(set[key], "VsDevCmd.bat")));
88+
paths.Add(
89+
new KeyValuePair<string, string>(
90+
key,
91+
Path.Combine(set[key], "VsDevCmd.bat")));
8492
}
8593

86-
var programFiles = Helper.ProgramFiles();
94+
var programFiles = Helper.GetProgramFilesInfo();
8795
if (programFiles == null)
8896
return null;
8997

9098
foreach (var version in Helper.VisualStudioVersions)
9199
foreach (var edition in Helper.VisualStudioEditions)
92100
{
93-
paths.Add(new KeyValuePair<string, string>(
94-
Helper.GetEnvVariableByVisualStudioVersion(version),
95-
Path.Combine(programFiles, "Microsoft Visual Studio", version, edition, "Common7", "Tools", "VsDevCmd.bat")));
101+
if (programFiles.x64 != null)
102+
paths.Add(
103+
new KeyValuePair<string, string>(
104+
Helper.GetEnvVariableByVisualStudioVersion(version),
105+
Path.Combine(programFiles.x64, "Microsoft Visual Studio", version, edition, "Common7", "Tools", "VsDevCmd.bat")));
106+
107+
if (programFiles.x86 != null)
108+
paths.Add(
109+
new KeyValuePair<string, string>(
110+
Helper.GetEnvVariableByVisualStudioVersion(version),
111+
Path.Combine(programFiles.x86, "Microsoft Visual Studio", version, edition, "Common7", "Tools", "VsDevCmd.bat")));
96112
}
97113

98114
paths = paths.OrderByDescending(x => x.Key).Where(x => File.Exists(x.Value)).ToList();

0 commit comments

Comments
 (0)