local_setup.ps1 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # generated from colcon_powershell/shell/template/prefix.ps1.em
  2. # This script extends the environment with all packages contained in this
  3. # prefix path.
  4. # check environment variable for custom Python executable
  5. if ($env:COLCON_PYTHON_EXECUTABLE) {
  6. if (!(Test-Path "$env:COLCON_PYTHON_EXECUTABLE" -PathType Leaf)) {
  7. echo "error: COLCON_PYTHON_EXECUTABLE '$env:COLCON_PYTHON_EXECUTABLE' doesn't exist"
  8. exit 1
  9. }
  10. $_colcon_python_executable="$env:COLCON_PYTHON_EXECUTABLE"
  11. } else {
  12. # use the Python executable known at configure time
  13. $_colcon_python_executable="/usr/bin/python3"
  14. # if it doesn't exist try a fall back
  15. if (!(Test-Path "$_colcon_python_executable" -PathType Leaf)) {
  16. if (!(Get-Command "python3" -ErrorAction SilentlyContinue)) {
  17. echo "error: unable to find python3 executable"
  18. exit 1
  19. }
  20. $_colcon_python_executable="python3"
  21. }
  22. }
  23. # function to source another script with conditional trace output
  24. # first argument: the path of the script
  25. function _colcon_prefix_powershell_source_script {
  26. param (
  27. $_colcon_prefix_powershell_source_script_param
  28. )
  29. # source script with conditional trace output
  30. if (Test-Path $_colcon_prefix_powershell_source_script_param) {
  31. if ($env:COLCON_TRACE) {
  32. echo ". '$_colcon_prefix_powershell_source_script_param'"
  33. }
  34. . "$_colcon_prefix_powershell_source_script_param"
  35. } else {
  36. Write-Error "not found: '$_colcon_prefix_powershell_source_script_param'"
  37. }
  38. }
  39. # get all commands in topological order
  40. $_colcon_ordered_commands = & "$_colcon_python_executable" "$(Split-Path $PSCommandPath -Parent)/_local_setup_util_ps1.py" ps1
  41. # execute all commands in topological order
  42. if ($env:COLCON_TRACE) {
  43. echo "Execute generated script:"
  44. echo "<<<"
  45. $_colcon_ordered_commands.Split([Environment]::NewLine, [StringSplitOptions]::RemoveEmptyEntries) | Write-Output
  46. echo ">>>"
  47. }
  48. if ($_colcon_ordered_commands) {
  49. $_colcon_ordered_commands.Split([Environment]::NewLine, [StringSplitOptions]::RemoveEmptyEntries) | Invoke-Expression
  50. }