-
Notifications
You must be signed in to change notification settings - Fork 6
/
synclibs.ps1
100 lines (80 loc) · 3.19 KB
/
synclibs.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Script that synchronizes the local library dependencies
#
# Version: 20180125
Param (
[switch]$UseHead = $false
)
$GitUrlPrefix = "https://github.com/libyal"
$LocalLibs = "libcdata libcerror libcfile libclocale libcnotify libcpath libcsplit libcthreads libuna"
$LocalLibs = ${LocalLibs} -split " "
$Git = "git"
$WinFlex = "..\win_flex_bison\win_flex.exe"
$WinBison = "..\win_flex_bison\win_bison.exe"
ForEach (${LocalLib} in ${LocalLibs})
{
# Split will return an array of a single empty string when LocalLibs is empty.
If (-Not (${LocalLib}))
{
Continue
}
$GitUrl = "${GitUrlPrefix}/${LocalLib}.git"
# PowerShell will raise NativeCommandError if git writes to stdout or stderr
# therefore 2>&1 is added and the output is stored in a variable.
$Output = Invoke-Expression -Command "${Git} clone ${GitUrl} ${LocalLib}-${pid} 2>&1"
Push-Location "${LocalLib}-${pid}"
Try
{
$Output = Invoke-Expression -Command "${Git} fetch --quiet --all --tags --prune 2>&1"
$LatestTag = Invoke-Expression -Command "${Git} describe --tags --abbrev=0 2>&1"
If (${LatestTag} -and -not ${UseHead})
{
Write-Host "Synchronizing: ${LocalLib} from ${GitUrl} tag ${LatestTag}"
$Output = Invoke-Expression -Command "${Git} checkout --quiet tags/${LatestTag} 2>&1"
}
Else
{
Write-Host "Synchronizing: ${LocalLib} from ${GitUrl} HEAD"
}
}
Finally
{
Pop-Location
}
If (Test-Path ${LocalLib}-${pid})
{
$LocalLibVersion = Get-Content -Path ${LocalLib}-${pid}\configure.ac | select -skip 4 -first 1 | % { $_ -Replace " \[","" } | % { $_ -Replace "\],","" }
If (Test-Path ${LocalLib})
{
Remove-Item -Path ${LocalLib} -Force -Recurse
}
New-Item -ItemType directory -Path ${LocalLib} -Force | Out-Null
If (Test-Path ${LocalLib})
{
Copy-Item -Path ${LocalLib}-${pid}\${LocalLib}\*.[chly] -Destination ${LocalLib}\
Get-Content -Path ${LocalLib}-${pid}\${LocalLib}\${LocalLib}_definitions.h.in | % { $_ -Replace "@VERSION@",${LocalLibVersion} } > ${LocalLib}\${LocalLib}_definitions.h
}
Remove-Item -Path ${LocalLib}-${pid} -Force -Recurse
$NamePrefix = ""
ForEach (${DirectoryElement} in Get-ChildItem -Path "${LocalLib}\*.l")
{
$OutputFile = ${DirectoryElement} -Replace ".l$",".c"
$NamePrefix = Split-Path -path ${DirectoryElement} -leaf
$NamePrefix = ${NamePrefix} -Replace "^${LocalLib}_",""
$NamePrefix = ${NamePrefix} -Replace ".l$","_"
# PowerShell will raise NativeCommandError if win_flex writes to stdout or stderr
# therefore 2>&1 is added and the output is stored in a variable.
$Output = Invoke-Expression -Command "& '${WinFlex}' -Cf ${DirectoryElement} 2>&1"
Write-Host ${Output}
# Moving manually sicne win_flex -o <filename> does not provide the expected behavior.
Move-Item "lex.yy.c" ${OutputFile} -force
}
ForEach (${DirectoryElement} in Get-ChildItem -Path "${LocalLib}\*.y")
{
$OutputFile = ${DirectoryElement} -Replace ".y$",".c"
# PowerShell will raise NativeCommandError if win_bison writes to stdout or stderr
# therefore 2>&1 is added and the output is stored in a variable.
$Output = Invoke-Expression -Command "& '${WinBison}' -d -v -l -p ${NamePrefix} -o ${OutputFile} ${DirectoryElement} 2>&1"
Write-Host ${Output}
}
}
}