diff options
Diffstat (limited to 'libraries/vendors/shared.psm1')
-rw-r--r-- | libraries/vendors/shared.psm1 | 311 |
1 files changed, 160 insertions, 151 deletions
diff --git a/libraries/vendors/shared.psm1 b/libraries/vendors/shared.psm1 index 3ff91c2db..8c7c0fb08 100644 --- a/libraries/vendors/shared.psm1 +++ b/libraries/vendors/shared.psm1 @@ -1,55 +1,48 @@ -# EMACS settings: -*- tab-width: 2; indent-tabs-mode: t -*- -# vim: tabstop=2:shiftwidth=2:noexpandtab -# kate: tab-width 2; replace-tabs off; indent-width 2; -# # ============================================================================== -# Authors: Patrick Lehmann -# -# PowerShell Module: The module provides common CmdLets for the library -# pre-compilation process. -# -# Description: -# ------------------------------------ -# This PowerShell module provides CommandLets (CmdLets) to handle the GHDL.exe -# output streams (stdout and stderr). +# Authors: Patrick Lehmann # # ============================================================================== -# Copyright (C) 2015-2016 Patrick Lehmann - Dresden, Germany -# Copyright (C) 2017 Patrick Lehmann - Freiburg, Germany -# -# GHDL is free software; you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation; either version 2, or (at your option) any later -# version. -# -# GHDL is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# for more details. -# -# You should have received a copy of the GNU General Public License -# along with GHDL; see the file COPYING. If not, write to the Free -# Software Foundation, 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. +# Copyright (C) 2017-2021 Patrick Lehmann - Boetzingen, Germany +# Copyright (C) 2015-2016 Patrick Lehmann - Dresden, Germany +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <gnu.org/licenses>. # ============================================================================== +# .SYNOPSIS +# This module provides common CmdLets for the library pre-compilation process. +# +# .DESCRIPTION +# This PowerShell module provides CommandLets (CmdLets) to handle the 'ghdl.exe' +# output streams (stdout and stderr). +# [CmdletBinding()] param( [Parameter(Mandatory=$true)][string]$VendorToolName, [Parameter(Mandatory=$true)][string]$WorkingDir ) -$Module_VendorToolName = $VendorToolName -$Module_WorkingDir = $WorkingDir +$Module_VendorToolName = $VendorToolName +$Module_WorkingDir = $WorkingDir function Exit-CompileScript { <# .SYNOPSIS Undocumented - + .DESCRIPTION Undocumented - + .PARAMETER ExitCode ExitCode of this script run #> @@ -57,29 +50,24 @@ function Exit-CompileScript param( [int]$ExitCode = 0 ) - + cd $Module_WorkingDir - + # unload modules Remove-Module config -Verbose:$false Remove-Module shared -Verbose:$false - - if ($ExitCode -eq 0) - { exit 0 } - else - { Write-Host "[DEBUG]: HARD EXIT" -ForegroundColor Red - exit $ExitCode - } + + exit $ExitCode } function Get-SourceDirectory { <# .SYNOPSIS Undocumented - + .DESCRIPTION Undocumented - + .PARAMETER Source Undocumented .PARAMETER EnvSource @@ -93,24 +81,24 @@ function Get-SourceDirectory $VendorToolInstallationDirectory = Get-VendorToolInstallationDirectory $VendorToolSourceDirectory = Get-VendorToolSourceDirectory - + if ($Source -ne "") - { $SourceDirectory = $Source.TrimEnd("\") } + { $SourceDirectory = $Source.TrimEnd("\") } elseif ($EnvSource -ne "") - { $SourceDirectory = $EnvSource } + { $SourceDirectory = $EnvSource } elseif ($VendorToolInstallationDirectory -ne "") - { $SourceDirectory = $VendorToolInstallationDirectory + "\" + $VendorToolSourceDirectory } + { $SourceDirectory = $VendorToolInstallationDirectory + "\" + $VendorToolSourceDirectory } else { Write-Host "[ERROR]: $Module_VendorToolName is not configured in '$ScriptDir\config.psm1'." -ForegroundColor Red Write-Host " Use adv. options '-Source' and '-Output' or configure 'config.psm1'." -ForegroundColor Red Exit-CompileScript -1 } - + if (-not (Test-Path $SourceDirectory -PathType Container)) { Write-Host "[ERROR]: Path '$SourceDirectory' does not exist." -ForegroundColor Red Exit-CompileScript -1 } - + return Convert-Path (Resolve-Path $SourceDirectory) } @@ -118,10 +106,10 @@ function Get-DestinationDirectory { <# .SYNOPSIS Undocumented - + .DESCRIPTION Undocumented - + .PARAMETER Output Undocumented #> @@ -130,19 +118,19 @@ function Get-DestinationDirectory [string]$Output ) if ($Output -ne "") - { $DestinationDirectory = $Output.TrimEnd("\") } + { $DestinationDirectory = $Output.TrimEnd("\") } else - { $DestinationDirectory = Get-VendorToolDestinationDirectory } - + { $DestinationDirectory = Get-VendorToolDestinationDirectory } + if ($DestinationDirectory -eq "") { Write-Host "[ERROR]: $Module_VendorToolName is not configured in '$ScriptDir\config.psm1'." -ForegroundColor Red Write-Host " Use adv. options '-Source' and '-Output' or configure 'config.psm1'." -ForegroundColor Red Exit-CompileScript -1 } - + if (-not [System.IO.Path]::IsPathRooted($DestinationDirectory)) - { $DestinationDirectory = "$Module_WorkingDir\$DestinationDirectory" } - + { $DestinationDirectory = "$Module_WorkingDir\$DestinationDirectory" } + return $DestinationDirectory } @@ -150,10 +138,10 @@ function Get-GHDLBinary { <# .SYNOPSIS Undocumented - + .DESCRIPTION Undocumented - + .PARAMETER GHDL Undocumented #> @@ -163,17 +151,24 @@ function Get-GHDLBinary ) if ($GHDL -ne "") - { $GHDLBinary = $GHDL.TrimEnd("\") + "\ghdl.exe" } + { $GHDLBinary = $GHDL } elseif (Test-Path env:GHDL) - { $GHDLBinary = $env:GHDL.TrimEnd("\") + "\ghdl.exe" } + { $GHDLBinary = $env:GHDL } else - { $GHDLBinary = "ghdl.exe" } - + { try + { write-host "calling which ..." + $GHDLBinary = (Get-Command "ghdl.exe").Source } + catch + { Write-Host "Use adv. options '-GHDL' to set the GHDL executable." -ForegroundColor Red + Exit-CompileScript -1 + } + } + if (-not (Test-Path $GHDLBinary -PathType Leaf)) { Write-Host "Use adv. options '-GHDL' to set the GHDL executable." -ForegroundColor Red Exit-CompileScript -1 } - + return $GHDLBinary } @@ -182,10 +177,10 @@ function Get-VHDLVariables { <# .SYNOPSIS Undocumented - + .DESCRIPTION Undocumented - + .PARAMETER VHDL93 Undocumented .PARAMETER VHDL2008 @@ -193,24 +188,24 @@ function Get-VHDLVariables #> [CmdletBinding()] param( - [bool]$VHDL93 = $false, + [bool]$VHDL93 = $false, [bool]$VHDL2008 = $true ) - + if ($VHDL93) - { $VHDLVersion = "v93" - $VHDLStandard = "93c" - $VHDLFlavor = "synopsys" + { $VHDLVersion = "v93" + $VHDLStandard = "93c" + $VHDLFlavor = "synopsys" } elseif ($VHDL2008) - { $VHDLVersion = "v08" + { $VHDLVersion = "v08" $VHDLStandard = "08" - $VHDLFlavor = "synopsys" + $VHDLFlavor = "synopsys" } else - { $VHDLVersion = "v93" + { $VHDLVersion = "v93" $VHDLStandard = "93c" - $VHDLFlavor = "synopsys" + $VHDLFlavor = "synopsys" } return $VHDLVersion,$VHDLStandard,$VHDLFlavor } @@ -219,10 +214,10 @@ function New-DestinationDirectory { <# .SYNOPSIS Undocumented - + .DESCRIPTION Undocumented - + .PARAMETER DestinationDirectory Undocumented #> @@ -232,7 +227,7 @@ function New-DestinationDirectory ) if (Test-Path $DestinationDirectory -PathType Container) - { Write-Host "Vendor directory '$DestinationDirectory' already exists." -ForegroundColor Yellow } + { Write-Host "Vendor directory '$DestinationDirectory' already exists." -ForegroundColor Yellow } elseif (Test-Path $DestinationDirectory -PathType Leaf) { Write-Host "[ERROR]: Vendor directory '$DestinationDirectory' already exists as a file." -ForegroundColor Red Exit-CompileScript -1 @@ -247,10 +242,10 @@ function Start-PackageCompilation { <# .SYNOPSIS Undocumented - + .DESCRIPTION Undocumented - + .PARAMETER GHDLBinary Undocumented .PARAMETER GHDLOptions @@ -274,41 +269,48 @@ function Start-PackageCompilation [Parameter(Mandatory=$true)][bool]$HaltOnError ) # set default valuesvalues - $EnableDebug = [bool]$PSCmdlet.MyInvocation.BoundParameters["Debug"] - $EnableVerbose = [bool]$PSCmdlet.MyInvocation.BoundParameters["Verbose"] -or $EnableDebug - + $EnableDebug = [bool]$PSCmdlet.MyInvocation.BoundParameters["Debug"] + $EnableVerbose = [bool]$PSCmdlet.MyInvocation.BoundParameters["Verbose"] -or $EnableDebug + + if ($EnableDebug) + { $Indent = " " } + elseif ($EnableVerbose) + { $Indent = " " } + else + { $Indent = " " } + Write-Host "Compiling library '$Library' ..." -ForegroundColor Yellow - $LibraryDirectory= "$DestinationDirectory/$Library/$VHDLVersion" - $EnableVerbose -and (Write-Host " Creating library $Library ..." -ForegroundColor Gray ) | Out-Null - $EnableDebug -and (Write-Host " mkdir $LibraryDirectory" -ForegroundColor DarkGray ) | Out-Null + $LibraryDirectory= "$DestinationDirectory/$Library/$VHDLVersion" + $EnableVerbose -and (Write-Host " Creating library $Library ..." -ForegroundColor Gray ) | Out-Null + $EnableDebug -and (Write-Host " mkdir $LibraryDirectory" -ForegroundColor DarkGray ) | Out-Null mkdir $LibraryDirectory -ErrorAction SilentlyContinue | Out-Null - $EnableDebug -and (Write-Host " cd $LibraryDirectory" -ForegroundColor DarkGray ) | Out-Null + $EnableDebug -and (Write-Host " cd $LibraryDirectory" -ForegroundColor DarkGray ) | Out-Null cd $LibraryDirectory $ErrorCount = 0 foreach ($File in $SourceFiles) { Write-Host " Analyzing package file '$File'" -ForegroundColor DarkCyan $InvokeExpr = "& '$GHDLBinary' " + ($GHDLOptions -join " ") + " --work=$Library " + $File + " 2>&1" - $EnableDebug -and (Write-Host " $InvokeExpr" -ForegroundColor DarkGray ) | Out-Null - $ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGHDLLine $SuppressWarnings " " - if ($LastExitCode -ne 0) + $EnableDebug -and (Write-Host " $InvokeExpr" -ForegroundColor DarkGray ) | Out-Null + $ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGHDLLine $SuppressWarnings -Indent:"$Indent" + if (($LastExitCode -ne 0) -or $ErrorRecordFound) { $ErrorCount += 1 if ($HaltOnError) - { break } - } + { break } + } } - + cd $DestinationDirectory - # return $ErrorCount + return $ErrorCount } function Start-PrimitiveCompilation { <# .SYNOPSIS Undocumented - + .DESCRIPTION Undocumented - + .PARAMETER GHDLBinary Undocumented .PARAMETER GHDLOptions @@ -332,31 +334,38 @@ function Start-PrimitiveCompilation [Parameter(Mandatory=$true)][bool]$HaltOnError ) # set default values - $EnableDebug = [bool]$PSCmdlet.MyInvocation.BoundParameters["Debug"] - $EnableVerbose = [bool]$PSCmdlet.MyInvocation.BoundParameters["Verbose"] -or $EnableDebug - - Write-Host "Compiling library '$Library' ..." -ForegroundColor Yellow + $EnableDebug = [bool]$PSCmdlet.MyInvocation.BoundParameters["Debug"] + $EnableVerbose = [bool]$PSCmdlet.MyInvocation.BoundParameters["Verbose"] -or $EnableDebug + + if ($EnableDebug) + { $Indent = " " } + elseif ($EnableVerbose) + { $Indent = " " } + else + { $Indent = " " } + + Write-Host "Compiling library '$Library' ..." -ForegroundColor Cyan $LibraryDirectory="$DestinationDirectory/$Library/$VHDLVersion" - $EnableVerbose -and (Write-Host " Creating library $Library ..." -ForegroundColor Gray ) | Out-Null - $EnableDebug -and (Write-Host " mkdir $LibraryDirectory" -ForegroundColor DarkGray ) | Out-Null + $EnableVerbose -and (Write-Host " Creating library $Library ..." -ForegroundColor Gray ) | Out-Null + $EnableDebug -and (Write-Host " mkdir $LibraryDirectory" -ForegroundColor DarkGray ) | Out-Null mkdir $LibraryDirectory -ErrorAction SilentlyContinue | Out-Null - $EnableDebug -and (Write-Host " cd $LibraryDirectory" -ForegroundColor DarkGray ) | Out-Null + $EnableDebug -and (Write-Host " cd $LibraryDirectory" -ForegroundColor DarkGray ) | Out-Null cd $LibraryDirectory $ErrorCount = 0 foreach ($File in $SourceFiles) { Write-Host " Analyzing primitive file '$File'" -ForegroundColor DarkCyan $InvokeExpr = "& '$GHDLBinary' " + ($GHDLOptions -join " ") + " --work=$Library " + $File + " 2>&1" - $EnableDebug -and (Write-Host " $InvokeExpr" -ForegroundColor DarkGray ) | Out-Null - $ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGHDLLine $SuppressWarnings " " - if ($LastExitCode -ne 0) + $EnableDebug -and (Write-Host " $InvokeExpr" -ForegroundColor DarkGray ) | Out-Null + $ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGHDLLine $SuppressWarnings -Indent:"$Indent" + if (($LastExitCode -ne 0) -or $ErrorRecordFound) { $ErrorCount += 1 if ($HaltOnError) - { break } + { break } } } - + cd $DestinationDirectory - # return $ErrorCount + return $ErrorCount } @@ -365,11 +374,11 @@ function Restore-NativeCommandStream .SYNOPSIS This CmdLet gathers multiple ErrorRecord objects and reconstructs outputs as a single line. - + .DESCRIPTION This CmdLet collects multiple ErrorRecord objects and emits one String object per line. - + .PARAMETER InputObject A object stream is required as an input. #> @@ -379,33 +388,19 @@ function Restore-NativeCommandStream $InputObject ) - begin - { $LineRemainer = "" } - process { if (-not $InputObject) - { Write-Host "Empty pipeline!" } - elseif ($InputObject -is [System.Management.Automation.ErrorRecord]) - { if ($InputObject.FullyQualifiedErrorId -eq "NativeCommandError") - { Write-Output $InputObject.ToString() } - elseif ($InputObject.FullyQualifiedErrorId -eq "NativeCommandErrorMessage") - { $NewLine = $LineRemainer + $InputObject.ToString() - while (($NewLinePos = $NewLine.IndexOf("`n")) -ne -1) - { Write-Output $NewLine.Substring(0, $NewLinePos) - $NewLine = $NewLine.Substring($NewLinePos + 1) - } - $LineRemainer = $NewLine - } - } - elseif ($InputObject -is [String]) - { Write-Output $InputObject } - else - { Write-Host "Unsupported object in pipeline stream" } - } - - end - { if ($LineRemainer -ne "") - { Write-Output $LineRemainer } + { Write-Host "Empty pipeline!" } + elseif ($InputObject -is [System.Management.Automation.ErrorRecord]) + { if ($InputObject.FullyQualifiedErrorId -eq "NativeCommandError") + { Write-Output $InputObject.ToString() } + elseif ($InputObject.FullyQualifiedErrorId -eq "NativeCommandErrorMessage") + { Write-Output $InputObject.ToString() } + } + elseif ($InputObject -is [String]) + { Write-Output $InputObject } + else + { Write-Host "Unsupported object in pipeline stream" } } } @@ -413,11 +408,11 @@ function Write-ColoredGHDLLine { <# .SYNOPSIS This CmdLet colors GHDL output lines. - + .DESCRIPTION This CmdLet colors GHDL output lines. Warnings are prefixed with 'WARNING: ' in yellow and errors are prefixed with 'ERROR: ' in red. - + .PARAMETER InputObject A object stream is required as an input. .PARAMETER SuppressWarnings @@ -429,7 +424,7 @@ function Write-ColoredGHDLLine param( [Parameter(ValueFromPipeline=$true)] $InputObject, - + [Parameter(Position=1)] [switch]$SuppressWarnings = $false, [Parameter(Position=2)] @@ -437,35 +432,49 @@ function Write-ColoredGHDLLine ) begin - { $ErrorRecordFound = $false } - + { $ErrorRecordFound = $false } + process { if ($InputObject -is [String]) { if ($InputObject -match ":\d+:\d+:warning:\s") { if (-not $SuppressWarnings) - { Write-Host "${Indent}WARNING: " -NoNewline -ForegroundColor Yellow + { Write-Host "${Indent}WARNING: " -NoNewline -ForegroundColor Yellow Write-Host $InputObject } } elseif ($InputObject -match ":\d+:\d+:\s") - { $ErrorRecordFound = $true - Write-Host "${Indent}ERROR: " -NoNewline -ForegroundColor Red + { $ErrorRecordFound = $true + Write-Host "${Indent}ERROR: " -NoNewline -ForegroundColor Red + Write-Host $InputObject + } + elseif ($InputObject -match ":warning:\s") + { Write-Host "${Indent}WARNING: " -NoNewline -ForegroundColor Yellow Write-Host $InputObject } elseif ($InputObject -match ":error:\s") - { $ErrorRecordFound = $true - Write-Host "${Indent}ERROR: " -NoNewline -ForegroundColor Red + { $ErrorRecordFound = $true + Write-Host "${Indent}ERROR: " -NoNewline -ForegroundColor Red + Write-Host $InputObject + } + elseif ($InputObject -match ": unknown option\s") + { $ErrorRecordFound = $true + Write-Host "${Indent}ERROR: " -NoNewline -ForegroundColor Red + Write-Host $InputObject + } + elseif ($InputObject -match ": cannot open\s") + { $ErrorRecordFound = $true + Write-Host "${Indent}ERROR: " -NoNewline -ForegroundColor Red Write-Host $InputObject } else - { Write-Host "${Indent}$InputObject" } + { Write-Host "${Indent}$InputObject" } } else - { Write-Host "Unsupported object in pipeline stream" } + { Write-Host "Unsupported object in pipeline stream" } } end - { $ErrorRecordFound } + { $ErrorRecordFound } } Export-ModuleMember -Function 'Exit-CompileScript' |