Skip to content

Commit

Permalink
Remove perl dependency (#2830)
Browse files Browse the repository at this point in the history
Rewrite VerifyResourceUsage in powershell

Co-authored-by: Keegan Caruso <[email protected]>
  • Loading branch information
keegan-caruso and Keegan Caruso authored Sep 19, 2024
1 parent 9f61d7b commit 5f437df
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 441 deletions.
51 changes: 51 additions & 0 deletions Tools/VerifyResourceUsage.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
$folderPath = $PSScriptRoot + "/../src"

# Get LogMessages C# files
$files = Get-ChildItem -Path $folderPath -Filter LogMessages.cs -Recurse

# Dictionary to hold constants and their usage status
$constants = @{}

# Extract constants
foreach ($file in $files) {
$content = Get-Content -Path $file.FullName
foreach ($line in $content) {
if (($line -match 'const\s+\w+\s+(\w+)\s*=') -and !($line.Contains("//"))) {
$constantName = $matches[1]
$constants[$constantName] = [PSCustomObject]@{
File = $file.FullName
ConstantName = $constantName
Found = $false
}
}
}
}

$files = Get-ChildItem -Path $folderPath -Filter *.cs -Exclude LogMessages.cs -Recurse
$keys = @($constants.Keys)

# Check for usage
foreach ($file in $files) {
$content = Get-Content -Path $file.FullName
foreach ($constantName in $keys) {
if (Select-String -InputObject $content -Pattern $constantName) {
$constants[$constantName].Found = $true
}
}
}

# Output unused constants
$unusedConstants = $constants.GetEnumerator() | Where-Object { $_.Value.Found -eq $false }
if ($unusedConstants.Count -eq 0) {
Write-Output "No unused constants found."
} else {
Write-Output "Unused constants:"
foreach ($unused in $unusedConstants) {
$constName = $unused.Value.ConstantName
$filePath = $unused.Value.File
$message = "'$constName' in file '$filePath'"
Write-Output $message
}

throw "found unused constants"
}
8 changes: 4 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ $ErrorActionPreference = "Stop"

WriteSectionHeader("VerifyResourceUsage.pl");

Write-Host ">>> Start-Process -Wait -PassThru -NoNewWindow perl $root\src\VerifyResourceUsage.pl"
$verifyResourceUsageResult = Start-Process -Wait -PassThru -NoNewWindow perl $root\src\VerifyResourceUsage.pl
Write-Host ">>> Start-Process -Wait -PassThru -NoNewWindow powershell $root\tools\VerifyResourceUsage.ps1"
$verifyResourceUsageResult = Start-Process -Wait -PassThru -NoNewWindow powershell $root\tools\VerifyResourceUsage.ps1

if($verifyResourceUsageResult.ExitCode -ne 0)
{
throw "VerifyResourceUsage.pl failed."
throw "VerifyResourceUsage.ps1 failed."
}

WriteSectionFooter("End VerifyResourceUsage.pl");
WriteSectionFooter("End VerifyResourceUsage.ps1");

WriteSectionHeader("Build");

Expand Down
93 changes: 0 additions & 93 deletions build/install-strawberry-perl.ps1

This file was deleted.

13 changes: 2 additions & 11 deletions build/template-Build-run-tests-sign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,9 @@ steps:
custom: '--list-sdks'

- task: PowerShell@2
displayName: "Install Strawberry Perl"
inputs:
targetType: filePath
filePath: $(Build.SourcesDirectory)\$(WilsonSourceDirectory)build\install-strawberry-perl.ps1
arguments: >
-ci_path "$(Build.SourcesDirectory)"
-debug
condition: and(succeeded(), eq(variables['PipelineType'], 'onebranch'))

- powershell: |
perl "$(Build.SourcesDirectory)\$(WilsonSourceDirectory)src\VerifyResourceUsage.pl"
displayName: 'Verify error messages are all used.'
inputs:
filePath: $(Build.SourcesDirectory)\$(WilsonSourceDirectory)Tools\VerifyResourceUsage.ps1

- powershell: |
regedit /s .\build\strongNameBypass.reg
Expand Down
Loading

0 comments on commit 5f437df

Please sign in to comment.