|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | +set -x |
| 5 | + |
| 6 | +# Get the source |
| 7 | +mkdir -p /opt/sources |
| 8 | +cd /opt/sources |
| 9 | +wget --no-verbose https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz |
| 10 | +# SHA-256 generated via `shasum -a 256 [file]` |
| 11 | +shasum --check <<EOF |
| 12 | +36c1b81ac29d0f8341f727ef40864d99d8206897be96be73dc34d4739c9c9f06 Python-3.7.1.tgz |
| 13 | +EOF |
| 14 | +tar xzf Python-3.7.1.tgz |
| 15 | + |
| 16 | +cd Python-3.7.1 |
| 17 | + |
| 18 | +# Explanation of flags: |
| 19 | +# |
| 20 | +# Noteworthy Debian options we _don't_ use: |
| 21 | +# |
| 22 | +# This is complicated to get right, and we don't expect our |
| 23 | +# --enable-shared |
| 24 | +# customers to embed Python in a native code application. There is |
| 25 | +# also a noteworthy interaction with 'make altinstall' |
| 26 | +# (https://bugs.python.org/issue27685) |
| 27 | +# --without-ensurepip |
| 28 | +# Debian unbundles pip for their own reasons |
| 29 | +# CFLAGS=-fdebug-prefix-map |
| 30 | +# Unnecessary in our build environment |
| 31 | +# |
| 32 | +# |
| 33 | +# Flags that we _do_ use: |
| 34 | +# (Debian) means it was taken from Debian build rules. |
| 35 | +# |
| 36 | +# --enable-ipv6 |
| 37 | +# (Debian) Ensure support is compiled in instead of relying on autodetection |
| 38 | +# --enable-loadable-sqlite-extensions |
| 39 | +# (Debian) |
| 40 | +# --enable-optimizations |
| 41 | +# Performance optimization (Enables PGO and may or may not enable |
| 42 | +# LTO based on complex logic and bugs) |
| 43 | +# --prefix |
| 44 | +# Avoid possible collisions with Debian or others |
| 45 | +# --with-computed-gotos |
| 46 | +# (Debian) Performance optimization |
| 47 | +# --with-dbmliborder=bdb:gdbm |
| 48 | +# (Debian) Python default is "ndbm:gdbm:bdb", I have no idea why one |
| 49 | +# would prefer one over the other. |
| 50 | +# --with-fpectl |
| 51 | +# (Debian) Floating point exception control |
| 52 | +# --with-system-expat |
| 53 | +# (Debian) for compatibility with other Debian packages |
| 54 | +# --with-system-ffi |
| 55 | +# (Debian) for compatibility with other Debian packages |
| 56 | +# --with-system-libmpdec |
| 57 | +# (Debian) for compatibility with other Debian packages |
| 58 | +# AR= |
| 59 | +# (Debian) No-op |
| 60 | +# CC= |
| 61 | +# (Debian) No-op |
| 62 | +# CFLAGS=-fstack-protector-strong |
| 63 | +# (Debian) Security hardening |
| 64 | +# CFLAGS=-g |
| 65 | +# (Debian) More debug info |
| 66 | +# CFLAGS=-Wformat -Werror=format-security |
| 67 | +# (Debian) Security hardening |
| 68 | +# CPPFLAGS=-D_FORTIFY_SOURCE=2 |
| 69 | +# (Debian) Security hardening |
| 70 | +# CPPFLAGS=-Wdate-time |
| 71 | +# (Debian) Warnings about non-reproducible builds |
| 72 | +# CXX= |
| 73 | +# (Debian) No-op |
| 74 | +# LDFLAGS=-Wl,-z,relro: |
| 75 | +# (Debian) Security hardening |
| 76 | +# RANLIB= |
| 77 | +# (Debian) No-op |
| 78 | +# |
| 79 | +# |
| 80 | +# LTO (Link time optimization) |
| 81 | +# |
| 82 | +# Currently disabled, due to unresolved compile problems. There is a |
| 83 | +# --with-lto flag, but Debian doesn't use it. Instead, they pass lto |
| 84 | +# related flags in EXTRA_CFLAGS (to make, rather than configure). |
| 85 | +# Specifically EXTRA_CFLAGS="-g -flto -fuse-linker-plugin |
| 86 | +# -ffat-lto-objects" |
| 87 | + |
| 88 | +PREFIX=/opt/python3.7 |
| 89 | + |
| 90 | +mkdir build-static |
| 91 | +cd build-static |
| 92 | + |
| 93 | +../configure \ |
| 94 | + --enable-ipv6 \ |
| 95 | + --enable-loadable-sqlite-extensions \ |
| 96 | + --enable-optimizations \ |
| 97 | + --prefix="$PREFIX" \ |
| 98 | + --with-dbmliborder=bdb:gdbm \ |
| 99 | + --with-computed-gotos \ |
| 100 | + --with-fpectl \ |
| 101 | + --with-system-expat \ |
| 102 | + --with-system-ffi \ |
| 103 | + --with-system-libmpdec \ |
| 104 | + AR="x86_64-linux-gnu-gcc-ar" \ |
| 105 | + CC="x86_64-linux-gnu-gcc" \ |
| 106 | + CFLAGS="\ |
| 107 | + -fstack-protector-strong \ |
| 108 | + -g \ |
| 109 | + -Wformat -Werror=format-security \ |
| 110 | + " \ |
| 111 | + CPPFLAGS="\ |
| 112 | + -D_FORTIFY_SOURCE=2 \ |
| 113 | + -Wdate-time \ |
| 114 | + " \ |
| 115 | + CXX="x86_64-linux-gnu-g++" \ |
| 116 | + LDFLAGS="-Wl,-z,relro" \ |
| 117 | + RANLIB="x86_64-linux-gnu-gcc-ranlib" \ |
| 118 | + |
| 119 | +make profile-opt |
| 120 | + |
| 121 | +# Run tests |
| 122 | +# test___all__: Depends on Debian-specific locale changes |
| 123 | +# test_dbm: https://bugs.python.org/issue28700 |
| 124 | +# test_imap: https://bugs.python.org/issue30175 |
| 125 | +# test_shutil: https://bugs.python.org/issue29317 |
| 126 | +# test_xmlrpc_net: https://bugs.python.org/issue31724 |
| 127 | +make test TESTOPTS="--exclude test___all__ test_dbm test_imaplib test_shutil test_xmlrpc_net test_os" |
| 128 | + |
| 129 | +# Install |
| 130 | +make altinstall |
| 131 | +# Remove redundant copy of libpython |
| 132 | +rm "$PREFIX"/lib/libpython3.7m.a |
| 133 | +# Remove opt-mode bytecode |
| 134 | +find "$PREFIX"/lib/python3.7/ \ |
| 135 | + -name \*.opt-\?.pyc \ |
| 136 | + -exec rm {} \; |
| 137 | +# Remove all but a few files in the 'test' subdirectory |
| 138 | +find "$PREFIX"/lib/python3.7/test \ |
| 139 | + -mindepth 1 -maxdepth 1 \ |
| 140 | + \! -name support \ |
| 141 | + -a \! -name __init__.py \ |
| 142 | + -a \! -name pystone.\* \ |
| 143 | + -a \! -name regrtest.\* \ |
| 144 | + -a \! -name test_support.py \ |
| 145 | + -exec rm -rf {} \; |
| 146 | + |
| 147 | +# Clean-up sources |
| 148 | +cd /opt |
| 149 | +rm /opt/sources/Python-3.7.1.tgz |
| 150 | +rm -r /opt/sources/Python-3.7.1 |
| 151 | + |
| 152 | +# Archive and copy to persistent external volume |
| 153 | +tar czf /workspace/runtime-image/interpreter-3.7.tar.gz /opt/python3.7 |
0 commit comments