-
Notifications
You must be signed in to change notification settings - Fork 118
/
ubuntu-python-builder.psm1
85 lines (68 loc) · 2.62 KB
/
ubuntu-python-builder.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using module "./builders/nix-python-builder.psm1"
class UbuntuPythonBuilder : NixPythonBuilder {
<#
.SYNOPSIS
Ubuntu Python builder class.
.DESCRIPTION
Contains methods that required to build Ubuntu Python artifact from sources. Inherited from base NixPythonBuilder.
.PARAMETER platform
The full name of platform for which Python should be built.
.PARAMETER version
The version of Python that should be built.
#>
UbuntuPythonBuilder(
[version] $version,
[string] $architecture,
[string] $platform
) : Base($version, $architecture, $platform) { }
[void] Configure() {
<#
.SYNOPSIS
Execute configure script with required parameters.
#>
$pythonBinariesLocation = $this.GetFullPythonToolcacheLocation()
### To build Python with SO we must pass full path to lib folder to the linker
$env:LDFLAGS="-Wl,--rpath=${pythonBinariesLocation}/lib"
$configureString = "./configure --prefix=$pythonBinariesLocation --enable-shared --enable-optimizations"
if ($this.Version -lt "3.0.0") {
### Compile with ucs4 for Python 2.x. On 3.x, ucs4 is enabled by default
$configureString += " --enable-unicode=ucs4"
}
Execute-Command -Command $configureString
}
[void] PrepareEnvironment() {
<#
.SYNOPSIS
Prepare system environment by installing dependencies and required packages.
#>
if (($this.Version -gt "3.0.0") -and ($this.Version -lt "3.5.3")) {
Write-Host "Python3 versions lower than 3.5.3 are not supported"
exit 1
}
### Compile with tkinter support
if ($this.Version -gt "3.0.0") {
$tkinterInstallString = "sudo apt-get install -y --allow-downgrades python3-tk tk-dev"
} else {
$tkinterInstallString = "sudo apt install -y python-tk tk-dev"
}
Execute-Command -Command $tkinterInstallString
### Install dependent packages
@(
"make",
"build-essential",
"libssl-dev",
"zlib1g-dev",
"libbz2-dev",
"libsqlite3-dev",
"libncursesw5-dev",
"libreadline-dev",
"libgdbm-dev"
) | ForEach-Object {
Execute-Command -Command "sudo apt install -y $_"
}
if ($this.Platform -ne "ubuntu-1604") {
### On Ubuntu-1804, libgdbm-compat-dev has older modules that are no longer in libgdbm-dev
Execute-Command -Command "sudo apt install -y libgdbm-compat-dev"
}
}
}