Skip to content

Replace PowerShell codegen with C# #656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3908c5e
Remove unused after.UnitsNet.sln.targets
angularsen Apr 17, 2019
abb1221
Initial project
angularsen Apr 17, 2019
83d14bd
Add CodeGen to solution
angularsen Apr 17, 2019
26b6878
Add DragonFruit 0.2.0-alpha.19174.3
angularsen Apr 17, 2019
ae7ec70
All codegen scripts recreated
angularsen Apr 17, 2019
752bd50
Codegen: Minor whitespace fixes
angularsen Apr 18, 2019
4929edf
README: Minor fix
angularsen Apr 18, 2019
0952a10
Remove PowerShell scripts
angularsen Apr 18, 2019
89a84b6
Update build script
angularsen Apr 18, 2019
cb5ab4e
WRC: Remove codegen for tests
angularsen Apr 18, 2019
eda78a2
Remove submodules from csproj
angularsen Apr 18, 2019
d95b941
Minor cleanup
angularsen Apr 18, 2019
ea3c1c6
Add initial WRC codegen
angularsen Apr 20, 2019
03335e1
Don't call WRC PS1 scripts
angularsen Apr 20, 2019
02acd93
WRC StaticQuantityGenerator exact match
angularsen Apr 20, 2019
7e21e98
WRC QuantityGenerator OK
angularsen Apr 20, 2019
005c893
WRC QuantityTypeGenerator OK
angularsen Apr 20, 2019
97ce62c
WRC UnitAbbreviationsCacheGenerator OK
angularsen Apr 20, 2019
bd73933
Restructure folders
angularsen Apr 20, 2019
d1dec6f
WRC: Remove all .ps1 scripts
angularsen Apr 20, 2019
3dd5f46
Update build message for codegen
angularsen Apr 20, 2019
105520e
Merge remote-tracking branch 'origin/master' into new/522-codegen-wit…
angularsen Apr 30, 2019
e6cc68d
WIP
angularsen Apr 30, 2019
8f7c795
Improve xmldoc of Main method
angularsen May 1, 2019
de40aee
Add option --skip-wrc
angularsen May 1, 2019
b1c30e0
Remove dead codegen code in WRC
angularsen May 1, 2019
0d14d67
Re-implement Support multiple abbreviations (#658)
angularsen May 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions Build/build-functions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,9 @@ function Remove-ArtifactsDir {
}

function Update-GeneratedCode {
# Regenerate source code since it occasionally happens that merged pull requests did not include all the regenerated code
$genScriptDotNet = "$root/UnitsNet/Scripts/GenerateUnits.ps1"
$genScriptWrc = "$root/UnitsNet.WindowsRuntimeComponent/Scripts/GenerateUnits.ps1"

write-host -foreground blue "Generate code for .NET...`n---"
write-host $genScriptDotNet
& $genScriptDotNet
if ($lastexitcode -ne 0) { exit 1 }

# Regenerate WRC code even if we are not building that target.
# The reason is that build.bat will skip WRC build since most people don't have that dependency installed.
# AppVeyor build server would still regen and build WRC regardless, but this way we also get the changes
# into pull requests so they are visible and master branch is kept up-to-date.
write-host -foreground blue "Generate code for Windows Runtime Component...`n---"
write-host $genScriptWrc
& $genScriptWrc
write-host -foreground blue "Generate code...`n---"
dotnet run --project "$root/CodeGen"
if ($lastexitcode -ne 0) { exit 1 }

write-host -foreground blue "Generate code...END`n"
}

Expand Down
15 changes: 15 additions & 0 deletions CodeGen/CodeGen.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Serilog" Version="2.8.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.2.0-alpha.19174.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
function GenerateQuantityTypeSourceCode($quantities)
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.

using CodeGen.Helpers;

namespace CodeGen.Generators
{
@"
//------------------------------------------------------------------------------
internal abstract class GeneratorBase
{
protected readonly MyTextWriter Writer = new MyTextWriter();
public abstract string Generate();

public const string GeneratedFileHeader = @"//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by \generate-code.bat.
//
Expand All @@ -19,24 +28,6 @@

// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.

// ReSharper disable once CheckNamespace
namespace UnitsNet
{
/// <summary>
/// Lists all generated quantities with the same name as the quantity struct type,
/// such as Length, Mass, Force etc.
/// This is useful for populating options in the UI, such as creating a generic conversion
/// tool with inputValue, quantityName, fromUnit and toUnit selectors.
/// </summary>
public enum QuantityType
{
Undefined = 0,
"@; foreach ($quantity in $quantities) {
@"
$($quantity.Name),
"@; }@"
";
}
}
"@;
}
Loading