Skip to content

Commit 79c33ce

Browse files
committed
Revert "Removed Build project"
This reverts commit bd5b1c6.
1 parent bd5b1c6 commit 79c33ce

21 files changed

+1089
-0
lines changed

src/Build.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34607.119
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{31D5C875-27D6-460B-AD34-7CCD984A69DD}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{31D5C875-27D6-460B-AD34-7CCD984A69DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{31D5C875-27D6-460B-AD34-7CCD984A69DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{31D5C875-27D6-460B-AD34-7CCD984A69DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{31D5C875-27D6-460B-AD34-7CCD984A69DD}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {5D3E4460-FF5C-4D38-BBE5-8A51D08F2C29}
24+
EndGlobalSection
25+
EndGlobal

src/DevToys-Windows.lutconfig

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<LUTConfig Version="1.0">
2+
<Repository>..\</Repository>
3+
<ParallelBuilds>true</ParallelBuilds>
4+
<ParallelTestRuns>true</ParallelTestRuns>
5+
<TestCaseTimeout>180000</TestCaseTimeout>
6+
</LUTConfig>

src/build/.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[*.cs]
2+
dotnet_style_qualification_for_field = false:warning
3+
dotnet_style_qualification_for_property = false:warning
4+
dotnet_style_qualification_for_method = false:warning
5+
dotnet_style_qualification_for_event = false:warning
6+
dotnet_style_require_accessibility_modifiers = never:warning
7+
8+
csharp_style_expression_bodied_methods = true:silent
9+
csharp_style_expression_bodied_properties = true:warning
10+
csharp_style_expression_bodied_indexers = true:warning
11+
csharp_style_expression_bodied_accessors = true:warning
+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using Nuke.Common.IO;
4+
using Serilog;
5+
6+
internal static class AppVersionTask
7+
{
8+
internal static void SetAppVersion(AbsolutePath rootDirectory)
9+
{
10+
string[] appVersionNumberAppContent = GetAppVersionNumberFileContent(rootDirectory);
11+
string appVersion = GetAppVersion(appVersionNumberAppContent);
12+
string sdkVersion = GetSdkVersion(appVersionNumberAppContent);
13+
14+
var csharpUpdater = new CSharpUpdater(appVersion, sdkVersion);
15+
IReadOnlyCollection<AbsolutePath> assemblyVersionFiles
16+
= rootDirectory.GlobFiles("**/*AssemblyVersion.cs");
17+
foreach (AbsolutePath file in assemblyVersionFiles)
18+
{
19+
Log.Information("Updating app version in {File}...", file);
20+
csharpUpdater.UpdateFile(file);
21+
}
22+
23+
var projectUpdater = new ProjectUpdater(sdkVersion);
24+
IReadOnlyCollection<AbsolutePath> projectFiles
25+
= rootDirectory.GlobFiles("**/*DevToys.Api.csproj");
26+
foreach (AbsolutePath file in projectFiles)
27+
{
28+
Log.Information("Updating project version in {File}...", file);
29+
projectUpdater.UpdateFile(file);
30+
}
31+
32+
var appxManifestUpdater = new AppxManifestUpdater(appVersion);
33+
IReadOnlyCollection<AbsolutePath> appxmanifestFiles
34+
= rootDirectory.GlobFiles("**/*.appxmanifest");
35+
foreach (AbsolutePath file in appxmanifestFiles)
36+
{
37+
Log.Information("Updating app version in {File}...", file);
38+
appxManifestUpdater.UpdateFile(file);
39+
}
40+
}
41+
42+
private static string[] GetAppVersionNumberFileContent(AbsolutePath rootDirectory)
43+
{
44+
AbsolutePath appVersionNumberFile = rootDirectory / "tools" / "app-version-number.txt";
45+
if (!appVersionNumberFile.FileExists())
46+
{
47+
Log.Error("Unable to find the app version number in {AppVersionNumberFile}...", appVersionNumberFile);
48+
throw new FileNotFoundException("Unable to find the app version number file.", appVersionNumberFile.ToString());
49+
}
50+
51+
return File.ReadAllLines(appVersionNumberFile);
52+
}
53+
54+
private static string GetAppVersion(string[] appVersionNumberAppContent)
55+
{
56+
return GetVersion(appVersionNumberAppContent, "app");
57+
}
58+
59+
private static string GetSdkVersion(string[] appVersionNumberAppContent)
60+
{
61+
return GetVersion(appVersionNumberAppContent, "sdk");
62+
}
63+
64+
private static string GetVersion(string[] appVersionNumberAppContent, string name)
65+
{
66+
for (int i = 0; i < appVersionNumberAppContent.Length; i++)
67+
{
68+
if (appVersionNumberAppContent[i].StartsWith(name + ":"))
69+
{
70+
return appVersionNumberAppContent[i].Substring(name.Length + 1);
71+
}
72+
}
73+
74+
return string.Empty;
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.IO;
3+
4+
internal sealed class AppxManifestUpdater
5+
{
6+
private readonly string _versionRule;
7+
8+
internal AppxManifestUpdater(string versionRule)
9+
{
10+
_versionRule = versionRule;
11+
}
12+
13+
public void UpdateFile(string fileName)
14+
{
15+
string text = File.ReadAllText(fileName);
16+
17+
string ouputText = UpdateTextWithRule(text);
18+
19+
File.WriteAllText(fileName, ouputText);
20+
}
21+
22+
public string UpdateTextWithRule(string text)
23+
{
24+
Tuple<string, int, int>? g = GetVersionString(text);
25+
if (g != null)
26+
{
27+
if (VersionString.TryParse(g.Item1, out VersionString? v) && v is not null)
28+
{
29+
string newVersion = new VersionUpdateRule(_versionRule).Update(v);
30+
return string.Concat(text.AsSpan(0, g.Item2), newVersion, text.AsSpan(g.Item2 + g.Item3));
31+
}
32+
}
33+
34+
return text;
35+
}
36+
37+
public static Tuple<string, int, int>? GetVersionString(string input)
38+
{
39+
string identityTagStart = "<Identity";
40+
string identityTagEnd = ">";
41+
string versionAttributeStart = "Version=\"";
42+
string versionAttributeEnd = "\"";
43+
44+
int identityTagStartPosition = input.IndexOf(identityTagStart);
45+
if (identityTagStartPosition > -1)
46+
{
47+
int identityTagEndPosition = input.IndexOf(identityTagEnd, identityTagStartPosition + identityTagStart.Length);
48+
if (identityTagEndPosition > -1)
49+
{
50+
int versionAttributeStartPosition = input.IndexOf(versionAttributeStart, identityTagStartPosition + identityTagStart.Length);
51+
if (versionAttributeStartPosition > identityTagStartPosition && versionAttributeStartPosition < identityTagEndPosition)
52+
{
53+
int versionAttributeEndPosition = input.IndexOf(versionAttributeEnd, versionAttributeStartPosition + versionAttributeStart.Length);
54+
55+
if (versionAttributeEndPosition > versionAttributeStartPosition && versionAttributeEndPosition < identityTagEndPosition)
56+
{
57+
string oldVersion = input.Substring(versionAttributeStartPosition + versionAttributeStart.Length, versionAttributeEndPosition - (versionAttributeStartPosition + versionAttributeStart.Length));
58+
return new Tuple<string, int, int>(
59+
oldVersion,
60+
versionAttributeStartPosition + versionAttributeStart.Length,
61+
oldVersion.Length);
62+
}
63+
}
64+
}
65+
}
66+
67+
return null;
68+
}
69+
}

src/build/AppVersion/CSharpUpdater.cs

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System.Collections.Generic;
2+
using System.Text.RegularExpressions;
3+
using System.IO;
4+
using System;
5+
6+
internal sealed class CSharpUpdater
7+
{
8+
private readonly List<CSharpVersionUpdateRule> _updateRules;
9+
10+
internal CSharpUpdater(string appVersion, string sdkVersion)
11+
{
12+
_updateRules = new List<CSharpVersionUpdateRule>();
13+
if (!string.IsNullOrEmpty(appVersion))
14+
{
15+
_updateRules.Add(new CSharpVersionUpdateRule("AssemblyVersion", appVersion));
16+
_updateRules.Add(new CSharpVersionUpdateRule("AssemblyFileVersion", appVersion));
17+
_updateRules.Add(new CSharpVersionUpdateRule("AssemblyInformationalVersion", sdkVersion));
18+
}
19+
}
20+
21+
public void UpdateFile(string fileName)
22+
{
23+
string[] lines = File.ReadAllLines(fileName);
24+
25+
var outlines = new List<string>();
26+
foreach (string line in lines)
27+
{
28+
outlines.Add(UpdateLine(line));
29+
}
30+
31+
File.WriteAllLines(fileName, outlines.ToArray());
32+
}
33+
34+
private string UpdateLine(string line)
35+
{
36+
foreach (CSharpVersionUpdateRule rule in _updateRules)
37+
{
38+
if (UpdateLineWithRule(ref line, rule))
39+
{
40+
break;
41+
}
42+
}
43+
return line;
44+
}
45+
46+
private static bool UpdateLineWithRule(ref string line, CSharpVersionUpdateRule rule)
47+
{
48+
bool updated = false;
49+
Group? g = GetVersionString(line, rule.AttributeName);
50+
if (g != null)
51+
{
52+
if (VersionString.TryParse(g.Value, out VersionString? v) && v is not null)
53+
{
54+
string newVersion = rule.Update(v);
55+
line = string.Concat(line.AsSpan(0, g.Index), newVersion, line.AsSpan(g.Index + g.Length));
56+
updated = true;
57+
}
58+
}
59+
60+
return updated;
61+
}
62+
63+
private static Group? GetVersionString(string input, string attributeName)
64+
{
65+
int commentIndex = input.IndexOf("//");
66+
if (commentIndex != -1)
67+
{
68+
input = input.Substring(0, commentIndex);
69+
}
70+
string attributeMatch = string.Format("(?:(?:{0})|(?:{0}Attribute))", attributeName);
71+
72+
string pattern = @"^\s*\[assembly: " + attributeMatch + @"\(""(?<Version>[0-9(\-\w)?\.\*]+)""\)\]";
73+
var regex = new Regex(pattern);
74+
Match m = regex.Match(input);
75+
if (m.Success)
76+
{
77+
return m.Groups["Version"];
78+
}
79+
return null;
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
internal class CSharpVersionUpdateRule
2+
{
3+
private readonly VersionUpdateRule _updateRule;
4+
public CSharpVersionUpdateRule(string attributeName, string updateRule)
5+
{
6+
AttributeName = attributeName;
7+
_updateRule = new VersionUpdateRule(updateRule);
8+
}
9+
public string AttributeName { get; private set; }
10+
public string Update(VersionString v) { return _updateRule.Update(v); }
11+
}
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System.Collections.Generic;
2+
using System.Text.RegularExpressions;
3+
using System.IO;
4+
using System;
5+
6+
internal sealed class ProjectUpdater
7+
{
8+
private readonly List<ProjectVersionUpdateRule> _updateRules;
9+
10+
internal ProjectUpdater(string sdkVersion)
11+
{
12+
_updateRules = new List<ProjectVersionUpdateRule>();
13+
if (!string.IsNullOrEmpty(sdkVersion))
14+
{
15+
_updateRules.Add(new ProjectVersionUpdateRule("Version", sdkVersion));
16+
}
17+
}
18+
19+
public void UpdateFile(string fileName)
20+
{
21+
string[] lines = File.ReadAllLines(fileName);
22+
23+
var outlines = new List<string>();
24+
foreach (string line in lines)
25+
{
26+
outlines.Add(UpdateLine(line));
27+
}
28+
29+
File.WriteAllLines(fileName, outlines.ToArray());
30+
}
31+
32+
private string UpdateLine(string line)
33+
{
34+
foreach (ProjectVersionUpdateRule rule in _updateRules)
35+
{
36+
if (UpdateLineWithRule(ref line, rule))
37+
{
38+
break;
39+
}
40+
}
41+
return line;
42+
}
43+
44+
private static bool UpdateLineWithRule(ref string line, ProjectVersionUpdateRule rule)
45+
{
46+
bool updated = false;
47+
Group? g = GetVersionString(line, rule.ParameterName);
48+
if (g != null)
49+
{
50+
if (VersionString.TryParse(g.Value, out VersionString? v) && v is not null)
51+
{
52+
string newVersion = rule.Update(v);
53+
line = string.Concat(line.AsSpan(0, g.Index), newVersion, line.AsSpan(g.Index + g.Length));
54+
updated = true;
55+
}
56+
}
57+
58+
return updated;
59+
}
60+
61+
private static Group? GetVersionString(string input, string parameterName)
62+
{
63+
string parameterMatch = string.Format("(?:(?:{0})|(?:{0}Attribute))", parameterName);
64+
65+
string pattern = @"^\s*\<" + parameterMatch + @">(?<Version>[0-9(\-\w)?\.\*]+)</" + parameterMatch + ">";
66+
var regex = new Regex(pattern);
67+
Match m = regex.Match(input);
68+
if (m.Success)
69+
{
70+
return m.Groups["Version"];
71+
}
72+
return null;
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
internal class ProjectVersionUpdateRule
2+
{
3+
private readonly VersionUpdateRule _updateRule;
4+
public ProjectVersionUpdateRule(string parameterName, string updateRule)
5+
{
6+
ParameterName = parameterName;
7+
_updateRule = new VersionUpdateRule(updateRule);
8+
}
9+
public string ParameterName { get; private set; }
10+
public string Update(VersionString v) { return _updateRule.Update(v); }
11+
}

0 commit comments

Comments
 (0)