-
Notifications
You must be signed in to change notification settings - Fork 70
/
generate_version_translation_unit.ps1
53 lines (50 loc) · 2.27 KB
/
generate_version_translation_unit.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding =
New-Object System.Text.UTF8Encoding
$solutiondir = resolve-path $args[0]
$env:Path += ";$env:programfiles\Git\bin;$env:localappdata\GitHub\Portab~1\bin;$env:localappdata\GitHub\Portab~1\mingw32\bin"
$newdate = [DateTime](git log -1 --format=%cd --date=iso-strict)
$newversion = (git describe --tags --always --dirty --abbrev=40 --long)
$headerpath = (join-path $solutiondir "base/version.generated.cc")
$versionheadertext = [string]::format(
"`n" +
"#include `"base/version.hpp`"`n" +
"`n" +
"namespace principia {{`n" +
"namespace base {{`n" +
"namespace _version {{`n" +
"namespace internal {{`n" +
"`n" +
"char const BuildDate[] = `"{0:yyyy'-'MM'-'dd'T'HH':'mm':'ssK}`";`n" +
"char const Version[] =`n" +
" u8`"{1}`";`n" +
"`n" +
"}} // namespace internal`n" +
"}} // namespace _version`n" +
"}} // namespace base`n" +
"}} // namespace principia`n",
$newdate.ToUniversalTime(),
$newversion)
for(;;) {
try {
if ((test-path -path $headerpath) -and
[system.io.file]::readalltext($headerpath).equals($versionheadertext)) {
echo "No change to git describe, leaving base/version.generated.cc untouched"
return
}
break
} catch {
start-sleep -m 10
}
}
for(;;) {
try {
echo "Updating base/version.generated.cc, version is $newversion"
[system.io.file]::writealltext(
$headerpath,
$versionheadertext,
[system.text.encoding]::utf8)
break
} catch {
start-sleep -m 10
}
}