-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts: Add Format-Build-Macro to format
build!
/generate!
blocks
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! {' |