Skip to content

Commit

Permalink
scripts: Add Format-Build-Macro to format build!/generate! blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed May 29, 2021
1 parent c4cf6b2 commit 5b92f98
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions scripts/Format-Build-Macro.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<#
.SYNOPSIS
Autoformats `build!` macros across `build.rs` scripts,
and `generate!` in bindings' `main.rs`.
#>

function Format-Macro {
param (
$File,
$Pattern
)

$shim = 'use format_build_macro::{'

$fmtResult = ((Get-Content -Raw $File).replace($Pattern, $shim) | & rustfmt) -join "`n"
# Some build macros contain a single item, where curly braces are removed. Those
# cannot easily be formatted yet.
if ($fmtResult.Contains($shim)) {
$fmtResult.replace($shim, $Pattern) | Set-Content $File
}
}

gci -r -fi build.rs | % { Format-Macro $_ 'windows::build! {' }
Format-Macro (gi './crates/bindings/src/main.rs') 'let tokens = windows_macros::generate! {'

0 comments on commit 5b92f98

Please sign in to comment.