Skip to content
Snippets Groups Projects

Drop ghc-jailbreak submodule

Merged Ben Gamari requested to merge subtree into master
47 files
+ 5613
3
Compare changes
  • Side-by-side
  • Inline
Files
47
function Use-PatchGHC {
param( [string] $name
, [string] $patchtool
, [string] $redistdir
, [bool] $install = $true )
$proc = Execute-Command $name '--info' -PassThru
if ($proc.ExitCode -ne 0) {
throw ("Command `'$name --info`' did not complete successfully. ExitCode: " + $proc.ExitCode)
}
$infoTable = $proc.stdout
$paths = $infoTable -split '[\r\n]'`
| Select-String "C compiler command" -SimpleMatch `
| ForEach-Object { $_.ToString().Split('"') } `
| Where-Object { $_ -notlike $null} `
| ForEach-Object { Split-Path $_ -Resolve -ErrorAction Ignore }
if ($install -eq $true) {
$action = "install"
} else {
$action = "uninstall"
}
foreach ($path in $paths) {
$lst1 = Get-ChildItem "$path/.." -Filter *.exe -Recurse
$files = $lst1
Write-Debug "Inspecting `'$path`'."
$i=0
$ix=100 / $files.Count
foreach ($file in $files) {
Write-Progress -Activity Patching -Status 'Jailbreaking...' `
-PercentComplete $i -CurrentOperation $file.FullName
$proc = Execute-Command $patchtool @($action, $file.FullName)
$toolOutput = $proc.stdout
Write-Debug $toolOutput
if ($proc.ExitCode -ne 0) {
throw ("Could not patch `'$file`'. ExitCode: " + $proc.ExitCode)
}
Write-Debug ("Patched executable. Copying runtimes.")
Get-ChildItem -Path $redistdir -Filter *.dll `
| ForEach-Object { Copy-Item -Path $_.FullName -Destination `
$file.Directory.FullName -Force; }
$i+=$ix
Write-Progress -Activity Patching -Status 'Jailbreaking...' `
-PercentComplete $i -CurrentOperation $file.FullName
}
}
Write-Host "Done patching GHC's Mingw-w64 distribution. Good to go."
}
Function Execute-Command ($commandPath, $commandArguments)
{
Try {
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $commandPath
$pinfo.RedirectStandardError = $false
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.WindowStyle = 'Hidden'
$pinfo.CreateNoWindow = $true
$pinfo.Arguments = $commandArguments
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
[pscustomobject]@{
stdout = $p.StandardOutput.ReadToEnd()
ExitCode = $p.ExitCode
}
$p.WaitForExit()
}
Catch {
exit
}
}
Export-ModuleMember -Function "Use-PatchGHC"
\ No newline at end of file
Loading