From ebb3a763d2487a7bcb46053b3d0659e3c4fa51cf Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Thu, 13 Oct 2022 11:20:46 -0700 Subject: [PATCH 1/4] Update Install-IronPython and pack in zipfile --- Package/zip/Zip.Packaging.targets | 4 +- Src/Scripts/Install-IronPython.ps1 | 119 +++++++++++++++++------------ 2 files changed, 74 insertions(+), 49 deletions(-) diff --git a/Package/zip/Zip.Packaging.targets b/Package/zip/Zip.Packaging.targets index 0e918c383..58ae9ecef 100644 --- a/Package/zip/Zip.Packaging.targets +++ b/Package/zip/Zip.Packaging.targets @@ -1,11 +1,13 @@ - + + + diff --git a/Src/Scripts/Install-IronPython.ps1 b/Src/Scripts/Install-IronPython.ps1 index 6863c145c..8bd3ea638 100755 --- a/Src/Scripts/Install-IronPython.ps1 +++ b/Src/Scripts/Install-IronPython.ps1 @@ -5,52 +5,79 @@ <# .SYNOPSIS - Install IronPython 3 for .NET 6 from an official zip file distributable. + Install IronPython 3 from an official zip file distributable. .DESCRIPTION - This script facilitates installation of IronPython on .NET 6 binaries from a zip file. The zip file is assumed to have content as published on the IronPython's download page. The zip file is produced by IronPython's "package" build target. + This script facilitates installation of IronPython binaries from a zip file. The zip file is assumed to have content as published on the IronPython's download page. The zip file is produced by IronPython's "package" build target. .EXAMPLE - PS>./make - PS>./make package - PS>./Src/Scripts/Install-IronPython.ps1 env - These commands should be issued on a Powershell prompt with the current directory set to the project root. - The project is first built, then packaged, and finally the script uses the zipfile produced during packaging to install IronPython in directory "env" + PS>Invoke-WebRequest -Uri https://github.com/IronLanguages/ironpython3/releases/download/v3.4.0-beta1/IronPython.3.4.0-beta1.zip -OutFile IronPython.3.4.0-beta1.zip + PS>Expand-Archive -Path IronPython.3.4.0-beta1.zip -DestinationPath IronPython-unzipped + PS>./IronPython-unzipped/scripts/Install-IronPython -Path ~/ipyenv/v3.4.0-beta1 + + The official binaries are downloaded from GitHub to the current directory, unzipped, and then the installation proceeds using the script from the unzipped directory. IronPython is installed into ~/ipyenv/v3.4.0-beta1. .EXAMPLE PS>Invoke-WebRequest -Uri https://github.com/IronLanguages/ironpython3/releases/download/v3.4.0-beta1/IronPython.3.4.0-beta1.zip -OutFile IronPython.3.4.0-beta1.zip - PS>Install-IronPython -Path ~/ipyenv/v3.4.0-beta1 -ZipFile IronPython.3.4.0-beta1.zip -Force + PS>Install-IronPython -Path ~/ipyenv/v3.4.0-beta1 -ZipFile IronPython.3.4.0-beta1.zip -Framework net462 -Force - The official binaries are downloaded from GitHub to the current directory and then the installation proceeds using the downloaded zip file. IronPython is installed into ~/ipyenv/v3.4.0-beta1, overwriting any previous installation in that location. + The official binaries are downloaded from GitHub to the current directory and then the installation proceeds using the downloaded zip file. IronPython is installed into ~/ipyenv/v3.4.0-beta1, overwriting any previous installation in that location. IronPython binaries running on .NET Framework 4.6.2 are used during the installation. This example assumes that the installation script is in a directory on the search path ($env:PATH). + +.EXAMPLE + + PS>./make + PS>./make package + PS>./Src/Scripts/Install-IronPython.ps1 env + + These commands should be issued on a Powershell prompt with the current directory set to the project root. + The project is first built, then packaged, and finally the script uses the zipfile produced during packaging to install IronPython in directory "env". + #> [CmdletBinding()] Param( # Target directory to which IronPython is to be installed. [Parameter(Position=0, Mandatory)] - [SupportsWildcards()] [string] $Path, # The path to the downloaded zip file with IronPython binaries. If empty, the script will try to grab the package directly produced by the local build. [string] $ZipFile, + # The moniker of the .NET platform to install for. + [string] $Framework = "net6.0", + # If the target path exists, it will be wiped clean beforehand. [switch] $Force ) $ErrorActionPreference = "Stop" -$defaultVersion = "3.4.0-beta1" - if (-not $ZipFile) { - # If zipfile path not given, assume that the script is in the standard location within the source tree - # and locate the zip archive in the standard location of the package target. - $projectRoot = $PSScriptRoot | Split-Path | Split-Path - $ZipFile = Join-Path $projectRoot "Package/Release/Packages/IronPython-$defaultVersion/IronPython.$defaultVersion.zip" + # If zipfile path not given, try to locate it + $splitPSScriptRoot = $PSScriptRoot -split "\$([IO.Path]::DirectorySeparatorChar)" + if ($splitPSScriptRoot[-2] -eq "Src" -and $splitPSScriptRoot[-1] -eq "Scripts") { + # Script run from within a checked out code base + # Locate the zip archive in the standard location of the package target + $projectRoot = $PSScriptRoot | Split-Path | Split-Path + $ZipFile = @(Resolve-Path (Join-Path $projectRoot "Package/Release/Packages/IronPython-*/IronPython.3.*.zip")) + if ($ZipFile.Count -gt 1) { + Write-Error "Ambiguous implicit project zip file: $ZipFile" + } elseif ($ZipFile.Count -lt 1) { + Write-Error "Missing zip file. Have you run './make package'?" + } + } elseif ($splitPSScriptRoot[-1] -eq "scripts") { + # Script run from within already expanded zip file + $unzipDir = $PSScriptRoot | Split-Path + } else { + Write-Error "Cannot locate implicit zip file. Provide path to the zip file using '-ZipFile '." + } +} elseif (-not (Test-Path $ZipFile)) { + Write-Error "ZipFile not found: $ZipFile" } +# Prepare destination path if (Test-Path $Path) { if ($Force) { if ((Resolve-Path $Path).Count -gt 1) { @@ -61,45 +88,41 @@ if (Test-Path $Path) { Write-Error "Path already exists: $Path" } } +New-Item $Path -ItemType Directory | Out-Null -# Unzip archive and move files into place -$unzipDir = Join-Path $Path "zip" +# Unzip archive +if (-not $unzipDir) { + $unzipDir = Join-Path $Path "unzipped" + Expand-Archive -Path $ZipFile -DestinationPath $unzipDir + $unzipped = $true +} -Expand-Archive -Path $ZipFile -DestinationPath $unzipDir -Move-Item -Path (Join-Path $unzipDir "lib") -Destination $Path -Move-Item -Path (Join-Path $unzipDir "net6.0/*") -Destination $Path -Exclude "*.xml","*.dll.config" -Remove-Item -Path $unzipDir -Recurse +# Copy files into place +Copy-Item -Path (Join-Path $unzipDir $Framework "*") -Destination $Path -Recurse +Copy-Item -Path (Join-Path $unzipDir "lib") -Destination $Path -# Create a startup script -$ipyPath = Join-Path $Path "ipy.ps1" -Set-Content -Path $ipyPath -Value @' +# Prepare startup scripts +if ($Framework -notlike "net4*") { + $ipyPath = Join-Path $Path "ipy.ps1" + Set-Content -Path $ipyPath -Value @' #!/usr/bin/env pwsh dotnet (Join-Path $PSScriptRoot ipy.dll) @args '@ + if ($IsMacOS -or $IsLinux) { + chmod +x $ipyPath + chmod +x (Join-Path $Path "ipy.sh") + Move-Item -Path (Join-Path $Path "ipy.sh") -Destination (Join-Path $Path "ipy") + Remove-Item -Path (Join-Path $Path "ipy.bat") + } +} + +# Install additional scripts +Copy-Item -Path (Join-Path $unzipDir "scripts/Enter-IronPythonEnvironment.ps1") -Destination $Path if ($IsMacOS -or $IsLinux) { - chmod +x $ipyPath - chmod +x (Join-Path $Path "ipy.sh") + chmod -x (Join-Path $Path "Enter-IronPythonEnvironment.ps1") } -# Add items that are missing in the zip file, directly from the bin directory -if ($projectRoot) { - $binPath = Join-Path $projectRoot "bin/Release/net6.0" - Copy-Item (Join-Path $projectRoot "Src/Scripts/Enter-IronPythonEnvironment.ps1") $Path - if ($IsWindows){ - Copy-Item (Join-Path $binPath "ipy.exe") $Path - } else { - Copy-Item (Join-Path $binPath "ipy") $Path - Copy-Item (Join-Path $binPath "Mono.Unix.dll") $Path - $arch = uname -m - switch ($arch) { - "x86_64" { $arch = "x64" } - } - if ($IsMacOS) { - $os = "osx" - } else { - $os = "linux" - } - $libs = Join-Path $binPath "runtimes" "$os-$arch" "native/*" -Resolve - Copy-Item $libs $Path - } +# Clean up unzipped files +if ($unzipped) { + Remove-Item -Path $unzipDir -Recurse } From a12f50690f42c9929b7116793723aa2bf3f99ae3 Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Thu, 13 Oct 2022 11:36:45 -0700 Subject: [PATCH 2/4] Create startup script for mono during installation --- Src/Scripts/Install-IronPython.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Src/Scripts/Install-IronPython.ps1 b/Src/Scripts/Install-IronPython.ps1 index 8bd3ea638..5c3547fcf 100755 --- a/Src/Scripts/Install-IronPython.ps1 +++ b/Src/Scripts/Install-IronPython.ps1 @@ -114,6 +114,15 @@ dotnet (Join-Path $PSScriptRoot ipy.dll) @args Move-Item -Path (Join-Path $Path "ipy.sh") -Destination (Join-Path $Path "ipy") Remove-Item -Path (Join-Path $Path "ipy.bat") } +} elseif ($IsMacOS -or $IsLinux) { # Mono + $ipyPath = Join-Path $Path "ipy" + Set-Content -Path $ipyPath -Value @' +#!/bin/sh +BASEDIR=$(dirname "$0") +ABS_PATH=$(cd "$BASEDIR"; pwd) +mono "$ABS_PATH/ipy.exe" "$@" +'@ + chmod +x $ipyPath } # Install additional scripts From 13993f217c9ddcb2b790262b90ebd58b3ee8b9f1 Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Thu, 13 Oct 2022 11:45:58 -0700 Subject: [PATCH 3/4] Update README for zip package --- Package/zip/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Package/zip/README.md b/Package/zip/README.md index c7991a376..5714284e7 100644 --- a/Package/zip/README.md +++ b/Package/zip/README.md @@ -13,6 +13,14 @@ After unpacking the archive, move or copy one of the `net` directories matching If access to the Python Standard Library is desired from IronPython, move or copy the whole `lib` directory **into** the moved/copied directory from the previous step. The `lib` directory has to be in the same directory as `IronPython.dll`. +The `scripts` subdirectory contains an installation script that facilitates the installation. Example: + +```powershell +PS> ./scripts/Install-IronPython.ps1 ~/.local/share/ironpython +``` + +Run `help ./scripts/Install-IronPython` in PowerShell for more information about supported options. + ## Command-line Usage To start a command-line interpreter on Windows run `ipy.exe` (for .NET Framework) or `ipy.bat` (for .NET). On Posix systems, run `ipy.sh`. `ipy.sh` may be renamed to simply `ipy` for convenience. From a7bc3746da98de8585aaf39521e769bc85109a3f Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Thu, 13 Oct 2022 13:41:38 -0700 Subject: [PATCH 4/4] Prioritize installation from within zip file --- Src/Scripts/Install-IronPython.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Src/Scripts/Install-IronPython.ps1 b/Src/Scripts/Install-IronPython.ps1 index 5c3547fcf..5255c20ed 100755 --- a/Src/Scripts/Install-IronPython.ps1 +++ b/Src/Scripts/Install-IronPython.ps1 @@ -57,7 +57,10 @@ $ErrorActionPreference = "Stop" if (-not $ZipFile) { # If zipfile path not given, try to locate it $splitPSScriptRoot = $PSScriptRoot -split "\$([IO.Path]::DirectorySeparatorChar)" - if ($splitPSScriptRoot[-2] -eq "Src" -and $splitPSScriptRoot[-1] -eq "Scripts") { + if ($splitPSScriptRoot[-1] -eq "scripts" -and (Test-Path (Join-Path (Split-Path $PSScriptRoot) "lib"))) { + # Script run from within already expanded zip file + $unzipDir = $PSScriptRoot | Split-Path + } elseif ($splitPSScriptRoot[-2] -eq "Src" -and $splitPSScriptRoot[-1] -eq "Scripts") { # Script run from within a checked out code base # Locate the zip archive in the standard location of the package target $projectRoot = $PSScriptRoot | Split-Path | Split-Path @@ -67,9 +70,6 @@ if (-not $ZipFile) { } elseif ($ZipFile.Count -lt 1) { Write-Error "Missing zip file. Have you run './make package'?" } - } elseif ($splitPSScriptRoot[-1] -eq "scripts") { - # Script run from within already expanded zip file - $unzipDir = $PSScriptRoot | Split-Path } else { Write-Error "Cannot locate implicit zip file. Provide path to the zip file using '-ZipFile '." }