Skip to content

Commit

Permalink
openssl: convert bash script to python
Browse files Browse the repository at this point in the history
More portable.

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Oct 26, 2023
1 parent 110ec25 commit f0aca06
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 54 deletions.
1 change: 1 addition & 0 deletions releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,7 @@
"openssl"
],
"versions": [
"3.0.8-2",
"3.0.8-1",
"3.0.7-2",
"3.0.7-1",
Expand Down
69 changes: 69 additions & 0 deletions subprojects/packagefiles/openssl/generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python3

import os
import subprocess

# Change to the directory of the Bash script
script_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(script_dir)

# Node.js version should bundle OpenSSL of matching version to one specified in wrap file
node_version = "v19.7.0"
openssl_version = os.environ.get("OPENSSL_VERSION")

if openssl_version is None:
with open("../../openssl.wrap") as wrap_file:
for line in wrap_file:
if "directory = " in line:
openssl_version = line.strip().split()[-1]
break

# Clone the Node.js repository
subprocess.run(["git", "clone", "--depth", "1", "-b", node_version, "https://github.com/nodejs/node.git"])

# Remove the generated-config directory
subprocess.run(["rm", "-rf", "generated-config"])

# Change directory to Node.js deps/openssl
os.chdir("node/deps/openssl")

# Apply the patch to generate meson.build for different targets
subprocess.run(["patch", "-u", "config/generate_gypi.pl", "-i", "../../../generate_gypi.pl.patch"])

# Copy meson.build template file
subprocess.run(["cp", "../../../meson.build.tmpl", "config/"])

# Clone the upstream OpenSSL repository
subprocess.run(["rm", "-rf", "openssl"])
subprocess.run(["git", "clone", "--depth", "1", "--branch", "openssl-" + openssl_version, "https://github.com/openssl/openssl.git"])

# Remove the config/archs directory
subprocess.run(["rm", "-rf", "config/archs"])

# Run the make command with LANG set to C
os.environ['LANG'] = 'C'
subprocess.run(["make", "-C", "config"])

# Copy generated files back into the correct place
find_cmd = 'mkdir -p ../../../generated-$(dirname "$1"); cp "$1" ../../../generated-"$1"'
subprocess.run(["find", "config/archs", "-name", "meson.build", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
subprocess.run(["find", "config/archs", "-name", "*.asm", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
subprocess.run(["find", "config/archs", "-name", "*.c", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
subprocess.run(["find", "config/archs", "-name", "*.h", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
subprocess.run(["find", "config/archs", "-iname", "*.s", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])

# AIX is not supported by Meson
subprocess.run(["rm", "-rf", "../../../generated-config/archs/aix*"])

# 32-bit s390x supported in Meson
subprocess.run(["rm", "-rf", "../../../generated-config/archs/linux32-s390x"])

# Remove build info files
subprocess.run(["rm", "-rf", "../../../generated-config/archs/*/asm_avx2"])
subprocess.run(["rm", "-rf", "../../../generated-config/archs/*/*/crypto/buildinf.h"])

# Change back to the original directory
os.chdir(script_dir)

# Remove the Node.js directory
subprocess.run(["rm", "-rf", "node"])
52 changes: 0 additions & 52 deletions subprojects/packagefiles/openssl/generator.sh

This file was deleted.

3 changes: 2 additions & 1 deletion subprojects/packagefiles/openssl/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ if not fs.exists('generated-config')
error('Generator only works on Linux, other platforms are not supported')
endif

generator = find_program('generator.py')
run_command(
'generator.sh',
generator,
check: true,
env: ['OPENSSL_VERSION=' + meson.project_version()],
)
Expand Down
3 changes: 2 additions & 1 deletion tools/sanity_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pathlib import Path
from utils import Version, is_ci, is_alpinelike, is_debianlike, is_linux, is_macos, is_windows, is_msys

PERMITTED_FILES = ['generator.sh', 'meson.build', 'meson_options.txt', 'LICENSE.build']
PERMITTED_FILES = ['meson.build', 'meson_options.txt', 'LICENSE.build']
PER_PROJECT_PERMITTED_FILES = {
'box2d': [
'doctest.h'
Expand Down Expand Up @@ -97,6 +97,7 @@
'dso_conf.h',
'buildinf.h',
'generate_gypi.pl.patch',
'generator.py',
'meson.build.tmpl',
'README.md',
],
Expand Down

0 comments on commit f0aca06

Please sign in to comment.