activate_verification_toolchain.ps1 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Activate the local Prod2U P4 verification toolchain for this PowerShell session.
  2. # This script does not modify the system PATH, registry, user profile, or repository.
  3. [CmdletBinding()]
  4. param(
  5. [string]$ToolchainRoot
  6. )
  7. $ToolchainBase = Join-Path $HOME "CodexToolchains\CPLD"
  8. if ([string]::IsNullOrWhiteSpace($ToolchainRoot)) {
  9. $ToolchainRoot = Join-Path $ToolchainBase "oss-cad-suite\latest"
  10. } else {
  11. $ToolchainRoot = [System.IO.Path]::GetFullPath($ToolchainRoot)
  12. }
  13. $CocotbPython = Join-Path $ToolchainBase "venvs\prod2u-p4-actuator-trace-cocotb-venv\Scripts\python.exe"
  14. $ToolchainBin = Join-Path $ToolchainRoot "bin"
  15. $ToolchainLib = Join-Path $ToolchainRoot "lib"
  16. $VerilatorRoot = Join-Path $ToolchainRoot "share\verilator"
  17. $ToolchainShimDir = Join-Path $PSScriptRoot "toolchain_shims"
  18. $VerilatorShim = Join-Path $ToolchainShimDir "verilator.ps1"
  19. $VerilatorNative = @(
  20. (Join-Path $ToolchainBin "verilator_bin.exe")
  21. (Join-Path $ToolchainBin "verilator.exe")
  22. ) | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1
  23. $Smtbmc = Join-Path $ToolchainRoot "bin\yosys-smtbmc.exe.exe"
  24. if (-not (Test-Path -LiteralPath $ToolchainBin -PathType Container)) {
  25. throw "Verification toolchain bin directory is missing: $ToolchainBin"
  26. }
  27. if (-not $VerilatorNative) {
  28. throw "Verification toolchain does not contain a native Verilator executable; refusing to expose the extensionless wrapper: $ToolchainBin"
  29. }
  30. if (-not (Test-Path -LiteralPath $VerilatorShim -PathType Leaf)) {
  31. throw "Verification toolchain shim is missing: $VerilatorShim"
  32. }
  33. $env:PROD2U_P4_TOOLCHAIN_ROOT = $ToolchainRoot
  34. $env:OSS_CAD_SUITE_ROOT = $ToolchainRoot
  35. $env:PROD2U_P4_COCOTB_PYTHON = $CocotbPython
  36. if (Test-Path -LiteralPath $VerilatorRoot) {
  37. $env:VERILATOR_ROOT = $VerilatorRoot
  38. }
  39. # The suite's extensionless Perl wrapper opens Windows' app chooser.
  40. $env:VERILATOR = $VerilatorNative
  41. Set-Alias -Name verilator -Value $VerilatorNative -Scope Global -Force
  42. if (Test-Path -LiteralPath $Smtbmc) {
  43. $env:SMTBMC = $Smtbmc
  44. }
  45. if (Test-Path -LiteralPath $ToolchainBin) {
  46. $pathParts = $env:PATH -split ";"
  47. if ($pathParts -notcontains $ToolchainBin) {
  48. $env:PATH = "$ToolchainBin;$env:PATH"
  49. }
  50. }
  51. if (Test-Path -LiteralPath $ToolchainLib) {
  52. $pathParts = $env:PATH -split ";"
  53. if ($pathParts -notcontains $ToolchainLib) {
  54. $env:PATH = "$ToolchainLib;$env:PATH"
  55. }
  56. }
  57. $pathParts = @($env:PATH -split ";" | Where-Object { $_ -and $_ -ne $ToolchainShimDir })
  58. $env:PATH = (@($ToolchainShimDir) + $pathParts) -join ";"
  59. Write-Host "Prod2U P4 verification toolchain variables set for current PowerShell session."
  60. Write-Host "PROD2U_P4_TOOLCHAIN_ROOT=$env:PROD2U_P4_TOOLCHAIN_ROOT"
  61. Write-Host "PROD2U_P4_COCOTB_PYTHON=$env:PROD2U_P4_COCOTB_PYTHON"
  62. Write-Host "VERILATOR=$env:VERILATOR"