Skip to content
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

Fix dotnet generator (#2446) (Backport to Ni) #2450

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions .github/workflows/check-dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CheckDotnet

on:
push:
branches:
- main
- release/*
pull_request:
branches:
- main
- release/*

permissions: read-all

jobs:
validate:
permissions:
contents: read # for actions/checkout to fetch code
name: Validate
runs-on: windows-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@bdb12b622a910dfdc99a31fdfe6f45a16bc287a4
with:
egress-policy: audit
- name: Setup .NET
uses: actions/setup-dotnet@9211491ffb35dd6a6657ca4f45d43dfe6e97c829
with:
dotnet-version: 6.0.x
- name: Checkout repository
uses: actions/checkout@629c2de402a417ea7690ca6ce3f33229e27606a5
- name: Prepare Machine
run: scripts/prepare-machine.ps1 -Configuration Dev
shell: pwsh
- name: Run DotNet Update
run: scripts/generate-dotnet.ps1
shell: pwsh
- name: Check for Changes
run: |
git add .
git --no-pager diff --exit-code HEAD
49 changes: 37 additions & 12 deletions scripts/generate-dotnet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,47 @@ $PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
# Root directory of the project.
$RootDir = Split-Path $PSScriptRoot -Parent

$ToolPath = Join-Path $RootDir build dotnetgenerator

if (Test-Path $ToolPath) { Remove-Item $ToolPath -Recurse -Force | Out-Null }

dotnet tool install ClangSharpPInvokeGenerator --version 13.0.0-beta1 --tool-path $ToolPath

$MsQuicHeader = Join-Path $RootDir src inc msquic.h
$MsQuicGeneratedSource = Join-Path $RootDir src cs lib msquic_generated.cs

$LicenseHeader = Join-Path $RootDir src cs LicenseHeader.txt

ClangSharpPInvokeGenerator -f $MsQuicHeader -n Microsoft.Quic -o $MsQuicGeneratedSource -m MsQuic -l msquic `
-c exclude-enum-operators -r _SOCKADDR_INET=QuicAddr -c generate-macro-bindings -h $LicenseHeader `
-e QUIC_UINT62_MAX -e MsQuicOpen2 -e QUIC_API_VERSION_1 -D QUIC_API_ENABLE_INSECURE_FEATURES `
-D QUIC_API_ENABLE_PREVIEW_FEATURES

$ReplaceDir = $RootDir + "\"

(Get-Content $MsQuicGeneratedSource)
.Replace($ReplaceDir, "") `
.Replace($ReplaceDir.Replace("\", "/"), "") `
.Replace('(?<!(\[Flags\])\n )public enum .*?_FLAGS','[Flags]\n $0') `
.Replace('(?<!using System;\n)(?!using System;\n)(using .*?;\n)+', 'using System;\n$0') `
$ToolExe = Join-Path $ToolPath ClangSharpPInvokeGenerator.exe

$Arguments = @(
"-f $MsQuicHeader", # Header to parse
"-n Microsoft.Quic", # Namespace to place generated code in
"-o $MsQuicGeneratedSource", # Output file
"-m MsQuic", # Class to place global functions and definitions in
"-l msquic", # Library to import for functions
"-c exclude-enum-operators", # Exclude enum operators from generated
"-r _SOCKADDR_INET=QuicAddr", # Remap _SOCKADDR_INET to QuicAddr
"-c generate-macro-bindings", # Generate values for macros (Such as status codes)
"-h $LicenseHeader", # Add license header to file
"-e QUIC_UINT62_MAX", # Exclude QUIC_UINT62_MAX from generator
"-e MsQuicOpen2", # Exclude MsQuicOpen2 macro from generator
"-e QUIC_API_VERSION_1", # Exclude v1 API define
"-D QUIC_API_ENABLE_INSECURE_FEATURES", # Enable insecure features to be generated
"-D QUIC_API_ENABLE_PREVIEW_FEATURES" # Enable preview features to be generated
"-e QUIC_DATAGRAM_SEND_STATE_IS_FINAL" # Cannot generate macro functions
"-e QUIC_PARAM_IS_GLOBAL" # Cannot generate macro functions
)

$FullArgs = $Arguments -join " "

Invoke-Expression "$ToolExe $FullArgs"

(Get-Content $MsQuicGeneratedSource) `
-replace '\(anonymous struct.+\)\"', "(anonymous struct)`"" `
-replace '\(anonymous union.+\)\"', "(anonymous union)`"" `
-replace "public enum .*?_FLAGS","[System.Flags]`n `$0" `
| `
Out-File $MsQuicGeneratedSource

$LASTEXITCODE = 0
Loading