-
Notifications
You must be signed in to change notification settings - Fork 34
/
syncwinflexbison.ps1
59 lines (50 loc) · 1.69 KB
/
syncwinflexbison.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
# Script that synchronizes Windows versions of flex and bison.
#
# Version: 20230104
Function ExtractZip($Filename, $Destination)
{
# AppVeyor does not seem to support extraction using "native ZIP" so we use 7z instead.
$SevenZip = "C:\Program Files\7-Zip\7z.exe"
If (-Not (Test-Path ${Destination}))
{
New-Item -ItemType directory -Path ${Destination} -Force | Out-Null
}
If (Test-Path ${SevenZip})
{
# PowerShell will raise NativeCommandError if 7z writes to stdout or stderr
# therefore 2>&1 is added and the output is stored in a variable.
# The leading & and single quotes are necessary to compensate for the spaces in the path.
$Output = Invoke-Expression -Command "& '${SevenZip}' -y -o${Destination} x ${Filename} 2>&1"
}
else
{
$Shell = New-Object -ComObject Shell.Application
$Archive = ${Shell}.NameSpace(${Filename})
$Directory = ${Shell}.Namespace(${Destination})
ForEach($FileEntry in ${Archive}.items())
{
${Directory}.CopyHere(${FileEntry})
}
}
}
$Version = "2.5.25"
$Filename = "${pwd}\win_flex_bison-${Version}.zip"
$Url = "https://github.com/lexxmark/winflexbison/releases/download/v${Version}/win_flex_bison-${Version}.zip"
$ExtractedPath = "win_flex_bison-${Version}"
$DestinationPath = "..\win_flex_bison"
If (Test-Path ${Filename})
{
Remove-Item -Path ${Filename} -Force
}
Invoke-WebRequest -Uri ${Url} -OutFile ${Filename}
If (Test-Path ${ExtractedPath})
{
Remove-Item -Path ${ExtractedPath} -Force -Recurse
}
ExtractZip -Filename ${Filename} -Destination "${pwd}\${ExtractedPath}"
Remove-Item -Path ${Filename} -Force
If (Test-Path ${DestinationPath})
{
Remove-Item -Path ${DestinationPath} -Force -Recurse
}
Move-Item ${ExtractedPath} ${DestinationPath}