-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_props.ps1
71 lines (59 loc) · 1.88 KB
/
generate_props.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
if ($Env:SOURCE_DIR) {
$SourceDirectory = $Env:SOURCE_DIR
} else {
$SourceDirectory = Split-Path $MyInvocation.MyCommand.Path -Parent
}
if ($Env:SHA) {
$Sha = $Env:SHA
} else {
$Sha = & git --git-dir="${SourceDirectory}/.git" rev-parse HEAD:libgit2
}
function Recurse-Directory($path) {
foreach ($child in Get-ChildItem $path) {
$item = Resolve-Path -Relative $child
if ($item.StartsWith("./") -or $item.StartsWith(".\")) {
$item = $item.Substring(2)
}
if ($child -is [System.IO.DirectoryInfo]) {
Recurse-Directory($child)
} else {
$item
}
}
}
$ShaAbbreviation = $Sha.Substring(0,7)
$LibraryFilename = "git2-${ShaAbbreviation}"
New-Item -ItemType Directory -Force -Path build | Out-Null
$PropsFile = Join-Path -Path build -ChildPath Dogged.Native.Binaries.props
Set-Content -Encoding UTF8 ${PropsFile} @"
<Project>
<PropertyGroup>
<MSBuildAllProjects>`$(MSBuildAllProjects);`$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<libgit2_propsfile>`$(MSBuildThisFileFullPath)</libgit2_propsfile>
<libgit2_hash>$Sha</libgit2_hash>
<libgit2_filename>$LibraryFilename</libgit2_filename>
</PropertyGroup>
</Project>
"@
$TargetsFile = Join-Path -Path build -ChildPath Dogged.Native.Binaries.targets
Set-Content -Encoding UTF8 ${TargetsFile} @'
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
'@
Recurse-Directory runtimes | % {
Add-Content -Encoding UTF8 ${TargetsFile} @"
<None Include=`"`$(MSBuildThisFileDirectory)\..\$_`">
<Visible>false</Visible>
<Link>$_</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
"@
}
Add-Content -Encoding UTF8 ${TargetsFile} @'
</ItemGroup>
</Project>
'@