Skip to content

Commit 8ff6e7b

Browse files
authored
Replace PowerShell codegen with C# (#656)
* Initial project * Add CodeGen to solution * Add DragonFruit 0.2.0-alpha.19174.3 * Remove unused after.UnitsNet.sln.targets * All codegen scripts recreated * Codegen: Minor whitespace fixes * README: Minor fix * Remove PowerShell scripts * Update build script * WRC: Remove codegen for tests It was stepping on the toes of the new codegen and WRC should not generate test code anyhow. * Remove submodules from csproj * Minor cleanup * Add initial WRC codegen * Don't call WRC PS1 scripts * WRC StaticQuantityGenerator exact match * WRC QuantityGenerator OK * WRC QuantityTypeGenerator OK * WRC UnitAbbreviationsCacheGenerator OK * Restructure folders * WRC: Remove all .ps1 scripts * Update build message for codegen * WIP * Improve xmldoc of Main method * Add option --skip-wrc * Remove dead codegen code in WRC * Re-implement Support multiple abbreviations (#658) Merge conflict had to be ported from PowerShell to C#. UnitAbbreviationsCache now gets single entries with string arrays instead of multiple entries with single item arrays. This is an improvement, but should be functionally equivalent.
1 parent f983a98 commit 8ff6e7b

File tree

55 files changed

+3927
-4127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3927
-4127
lines changed

Build/build-functions.psm1

+2-17
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,9 @@ function Remove-ArtifactsDir {
1818
}
1919

2020
function Update-GeneratedCode {
21-
# Regenerate source code since it occasionally happens that merged pull requests did not include all the regenerated code
22-
$genScriptDotNet = "$root/UnitsNet/Scripts/GenerateUnits.ps1"
23-
$genScriptWrc = "$root/UnitsNet.WindowsRuntimeComponent/Scripts/GenerateUnits.ps1"
24-
25-
write-host -foreground blue "Generate code for .NET...`n---"
26-
write-host $genScriptDotNet
27-
& $genScriptDotNet
28-
if ($lastexitcode -ne 0) { exit 1 }
29-
30-
# Regenerate WRC code even if we are not building that target.
31-
# The reason is that build.bat will skip WRC build since most people don't have that dependency installed.
32-
# AppVeyor build server would still regen and build WRC regardless, but this way we also get the changes
33-
# into pull requests so they are visible and master branch is kept up-to-date.
34-
write-host -foreground blue "Generate code for Windows Runtime Component...`n---"
35-
write-host $genScriptWrc
36-
& $genScriptWrc
21+
write-host -foreground blue "Generate code...`n---"
22+
dotnet run --project "$root/CodeGen"
3723
if ($lastexitcode -ne 0) { exit 1 }
38-
3924
write-host -foreground blue "Generate code...END`n"
4025
}
4126

CodeGen/CodeGen.csproj

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
10+
<PackageReference Include="Serilog" Version="2.8.0" />
11+
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
12+
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.2.0-alpha.19174.3" />
13+
</ItemGroup>
14+
15+
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
function GenerateQuantityTypeSourceCode($quantities)
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
2+
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
3+
4+
using CodeGen.Helpers;
5+
6+
namespace CodeGen.Generators
27
{
3-
@"
4-
//------------------------------------------------------------------------------
8+
internal abstract class GeneratorBase
9+
{
10+
protected readonly MyTextWriter Writer = new MyTextWriter();
11+
public abstract string Generate();
12+
13+
public const string GeneratedFileHeader = @"//------------------------------------------------------------------------------
514
// <auto-generated>
615
// This code was generated by \generate-code.bat.
716
//
@@ -19,24 +28,6 @@
1928
2029
// Licensed under MIT No Attribution, see LICENSE file at the root.
2130
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
22-
23-
// ReSharper disable once CheckNamespace
24-
namespace UnitsNet
25-
{
26-
/// <summary>
27-
/// Lists all generated quantities with the same name as the quantity struct type,
28-
/// such as Length, Mass, Force etc.
29-
/// This is useful for populating options in the UI, such as creating a generic conversion
30-
/// tool with inputValue, quantityName, fromUnit and toUnit selectors.
31-
/// </summary>
32-
public enum QuantityType
33-
{
34-
Undefined = 0,
35-
"@; foreach ($quantity in $quantities) {
36-
@"
37-
$($quantity.Name),
38-
"@; }@"
31+
";
3932
}
4033
}
41-
"@;
42-
}

0 commit comments

Comments
 (0)