Skip to content

Commit

Permalink
Perform AOT check on repository (#2845)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaurabhMSFT authored May 23, 2024
1 parent eb70c54 commit 800d959
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .github/workflows/aot-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "AOT Check"

on:
push:
branches: [ "master", "rel/v2" ]
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches: [ "master", "rel/v2" ]

jobs:
analyze:
runs-on: windows-latest
name: AOT check

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Runs powershell script
id: aot-powershell
run: build\test-aot.ps1 'net8.0'

9 changes: 8 additions & 1 deletion Microsoft.Identity.Web.sln
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "benchmark\Ben
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContosoWorker", "tests\DevApps\ContosoWorker\ContosoWorker.csproj", "{4A63EA63-5679-4498-BB4C-30E09F268E00}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Identity.Web.UI", "src\Microsoft.Identity.Web.UI\Microsoft.Identity.Web.UI.csproj", "{C6CB0D5B-917A-4127-9984-7592C757BBDE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Identity.Web.UI", "src\Microsoft.Identity.Web.UI\Microsoft.Identity.Web.UI.csproj", "{C6CB0D5B-917A-4127-9984-7592C757BBDE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Identity.Web.AotCompatibility.TestApp", "tests\Microsoft.Identity.Web.AotCompatibility.TestApp\Microsoft.Identity.Web.AotCompatibility.TestApp.csproj", "{BCE63265-6D36-423A-9C3D-BF8E448C7EA0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -401,6 +403,10 @@ Global
{C6CB0D5B-917A-4127-9984-7592C757BBDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6CB0D5B-917A-4127-9984-7592C757BBDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6CB0D5B-917A-4127-9984-7592C757BBDE}.Release|Any CPU.Build.0 = Release|Any CPU
{BCE63265-6D36-423A-9C3D-BF8E448C7EA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCE63265-6D36-423A-9C3D-BF8E448C7EA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCE63265-6D36-423A-9C3D-BF8E448C7EA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCE63265-6D36-423A-9C3D-BF8E448C7EA0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -480,6 +486,7 @@ Global
{8FB5433F-D625-464E-8957-FDD0AC20FBDE} = {A6799B45-E2FD-4ACA-86A2-D1AD5B1E2ECE}
{4A63EA63-5679-4498-BB4C-30E09F268E00} = {E37CDBC1-18F6-4C06-A3EE-532C9106721F}
{C6CB0D5B-917A-4127-9984-7592C757BBDE} = {1DDE1AAC-5AE6-4725-94B6-A26C58D3423F}
{BCE63265-6D36-423A-9C3D-BF8E448C7EA0} = {B4E72F1C-603F-437C-AAA1-153A604CD34A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {104367F1-CE75-4F40-B32F-F14853973187}
Expand Down
50 changes: 50 additions & 0 deletions build/test-aot.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
param([string]$targetNetFramework)

$projectName='Microsoft.Identity.Web.AotCompatibility.TestApp'
$rootDirectory = Split-Path $PSScriptRoot -Parent
$publishOutput = dotnet publish $rootDirectory/tests/$projectName/$projectName.csproj --framework $targetNetFramework -nodeReuse:false /p:UseSharedCompilation=false

$actualWarningCount = 0

foreach ($line in $($publishOutput -split "`r`n"))
{
if (($line -like "*analysis warning IL*") -or ($line -like "*analysis error IL*"))
{
Write-Host $line
$actualWarningCount += 1
}
}

Write-Host "Actual warning count is: ", $actualWarningCount
$expectedWarningCount = 63

if ($LastExitCode -ne 0)
{
Write-Host "There was an error while publishing AotCompatibility Test App. LastExitCode is:", $LastExitCode
Write-Host $publishOutput
}

$runtime = if ($IsWindows) { "win-x64" } elseif ($IsMacOS) { "macos-x64"} else {"linux-x64"}
$app = if ($IsWindows ) {"./$projectName.exe" } else {"./$projectName" }

Push-Location $rootDirectory/tests/$projectName/bin/Release/$targetNetFramework/$runtime

Write-Host "Executing test App..."
$app
Write-Host "Finished executing test App"

if ($LastExitCode -ne 0)
{
Write-Host "There was an error while executing AotCompatibility Test App. LastExitCode is:", $LastExitCode
}

Pop-Location

$testPassed = 0
if ($expectedWarningCount -ne $actualWarningCount)
{
$testPassed = 1
Write-Host "Actual warning count:", $actualWarningCount, "is not as expected. Expected warning count is:", $expectedWarningCount
}

Exit $testPassed
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<PublishAot>true</PublishAot>
<EventSourceSupport>true</EventSourceSupport>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>

<TrimmerRootAssembly Include="Microsoft.Identity.Web"/>
<TrimmerRootAssembly Include="Microsoft.Identity.Web.Azure"/>
<TrimmerRootAssembly Include="Microsoft.Identity.Web.Certificate"/>
<TrimmerRootAssembly Include="Microsoft.Identity.Web.Certificateless"/>
<TrimmerRootAssembly Include="Microsoft.Identity.Web.Diagnostics"/>
<TrimmerRootAssembly Include="Microsoft.Identity.Web.DownstreamApi"/>
<TrimmerRootAssembly Include="Microsoft.Identity.Web.GraphServiceClient"/>
<TrimmerRootAssembly Include="Microsoft.Identity.Web.GraphServiceClientBeta"/>

<!--
<TrimmerRootAssembly Include="Microsoft.Identity.Web.MicrosoftGraph"/>
<TrimmerRootAssembly Include="Microsoft.Identity.Web.MicrosoftGraphBeta"/>
<TrimmerRootAssembly Include="Microsoft.Identity.Web.OWIN"/>-->

<TrimmerRootAssembly Include="Microsoft.Identity.Web.TokenAcquisition"/>
<TrimmerRootAssembly Include="Microsoft.Identity.Web.TokenCache"/>
<TrimmerRootAssembly Include="Microsoft.Identity.Web.UI"/>

<TrimmerRootAssembly Update="@(TrimmerRootAssembly)" Path="..\..\src\%(Identity)\%(Identity).csproj" />
<ProjectReference Include="@(TrimmerRootAssembly->'%(Path)')" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions tests/Microsoft.Identity.Web.AotCompatibility.TestApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

internal sealed class Program
{
// The code in this program is expected to be trim and AOT compatible
private static int Main()
{
return 100;
}
}

0 comments on commit 800d959

Please sign in to comment.