Skip to content

Commit 0c086dd

Browse files
authored
Add Install-IronPython.ps1 (#1433)
* Add Install-IronPython.ps1 * Update to work on macOS * Update to work on Linux * Update after review
1 parent 8a59f15 commit 0c086dd

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

Src/Scripts/Install-IronPython.ps1

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env pwsh
2+
# Licensed to the .NET Foundation under one or more agreements.
3+
# The .NET Foundation licenses this file to you under the Apache 2.0 License.
4+
# See the LICENSE file in the project root for more information.
5+
6+
<#
7+
.SYNOPSIS
8+
Install IronPython 3 for .NET 6 from an official zip file distributable.
9+
10+
.DESCRIPTION
11+
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.
12+
13+
.EXAMPLE
14+
PS>./make
15+
PS>./make package
16+
PS>./Src/Scripts/Install-IronPython.ps1 env
17+
18+
These commands should be issued on a Powershell prompt with the current directory set to the project root.
19+
The project is first built, then packaged, and finally the script uses the zipfile produced during packaging to install IronPython in directory "env"
20+
21+
.EXAMPLE
22+
23+
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
24+
PS>Install-IronPython -Path ~/ipyenv/v3.4.0-beta1 -ZipFile IronPython.3.4.0-beta1.zip -Force
25+
26+
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.
27+
This example assumes that the installation script is in a directory on the search path ($env:PATH).
28+
#>
29+
[CmdletBinding()]
30+
Param(
31+
# Target directory to which IronPython is to be installed.
32+
[Parameter(Position=0, Mandatory)]
33+
[SupportsWildcards()]
34+
[string] $Path,
35+
36+
# 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.
37+
[string] $ZipFile,
38+
39+
# If the target path exists, it will be wiped clean beforehand.
40+
[switch] $Force
41+
)
42+
43+
$ErrorActionPreference = "Stop"
44+
45+
$defaultVersion = "3.4.0-beta1"
46+
47+
if (-not $ZipFile) {
48+
# If zipfile path not given, assume that the script is in the standard location within the source tree
49+
# and locate the zip archive in the standard location of the package target.
50+
$projectRoot = $PSScriptRoot | Split-Path | Split-Path
51+
$ZipFile = Join-Path $projectRoot "Package/Release/Packages/IronPython-$defaultVersion/IronPython.$defaultVersion.zip"
52+
}
53+
54+
if (Test-Path $Path) {
55+
if ($Force) {
56+
if ((Resolve-Path $Path).Count -gt 1) {
57+
Write-Error "Overwriting of multiple destinations not allowed: $Path"
58+
}
59+
Remove-Item -Path $Path -Force -Recurse
60+
} else {
61+
Write-Error "Path already exists: $Path"
62+
}
63+
}
64+
65+
# Unzip archive and move files into place
66+
$unzipDir = Join-Path $Path "zip"
67+
68+
Expand-Archive -Path $ZipFile -DestinationPath $unzipDir
69+
Move-Item -Path (Join-Path $unzipDir "Lib") -Destination $Path
70+
Move-Item -Path (Join-Path $unzipDir "net6.0/*") -Destination $Path -Exclude "*.xml","*.dll.config"
71+
Remove-Item -Path $unzipDir -Recurse
72+
73+
# Create a startup script
74+
$ipyPath = Join-Path $Path "ipy.ps1"
75+
Set-Content -Path $ipyPath -Value @'
76+
#!/usr/bin/env pwsh
77+
dotnet (Join-Path $PSScriptRoot ipy.dll) @args
78+
'@
79+
if ($IsMacOS -or $IsLinux) {
80+
chmod +x $ipyPath
81+
}
82+
83+
# Add items that are missing in the zip file, directly from the bin directory
84+
if ($projectRoot) {
85+
$binPath = Join-Path $projectRoot "bin/Release/net6.0"
86+
Copy-Item (Join-Path $binPath "ipy") $Path
87+
if ($IsMacOS -or $IsLinux) {
88+
Copy-Item (Join-Path $binPath "Mono.Unix.dll") $Path
89+
$arch = uname -m
90+
switch ($arch) {
91+
"x86_64" { $arch = "x64" }
92+
}
93+
if ($IsMacOS) {
94+
$os = "osx"
95+
} else {
96+
$os = "linux"
97+
}
98+
$libs = Join-Path $binPath "runtimes" "$os-$arch" "native/*" -Resolve
99+
Copy-Item $libs $Path
100+
}
101+
}

0 commit comments

Comments
 (0)