19 lines
876 B
PowerShell
19 lines
876 B
PowerShell
param(
|
|
[string]$Repository = (Resolve-Path (Join-Path $PSScriptRoot '..\..\..\..\..')).Path,
|
|
[string]$Output = (Join-Path $PSScriptRoot '..\generated\firmware_build_id.h')
|
|
)
|
|
|
|
$id = 'NOGIT000'
|
|
$hash = (& git -C $Repository rev-parse --short=8 HEAD 2>$null)
|
|
if ($LASTEXITCODE -eq 0 -and $hash) {
|
|
& git -C $Repository diff --quiet HEAD 2>$null
|
|
$id = if ($LASTEXITCODE -eq 0) { $hash.Substring(0, 8) } else { $hash.Substring(0, 7) + '+' }
|
|
}
|
|
$directory = Split-Path -Parent $Output
|
|
New-Item -ItemType Directory -Force -Path $directory | Out-Null
|
|
$body = "#ifndef FIRMWARE_BUILD_ID_H`n#define FIRMWARE_BUILD_ID_H`n#define FIRMWARE_BUILD_ID `"$id`"`n#endif`n"
|
|
if (!(Test-Path -LiteralPath $Output) -or ((Get-Content -Raw $Output) -ne $body)) {
|
|
[IO.File]::WriteAllText($Output, $body, [Text.UTF8Encoding]::new($false))
|
|
}
|
|
Write-Host "[firmware-info] build-id: $id"
|