Files
templates/c/firmware-info/tools/make_build_id.ps1

23 lines
1.2 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Создание firmware_build_id.h из идентификатора Git для включения в прошивку. При отсутствии
# Git используется предусмотренное скриптом резервное значение; выходной файл содержит
# метаданные сборки, а не исходный код протокола.
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"