Skip to content

Commit

Permalink
Update to current gdb and python
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Sep 4, 2024
1 parent 4a5bd1d commit 578fc57
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/package-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Install OS Dependencies
run: >-
apt-get install -y python3
python3-pip python3-venv patchelf build-essential m4
python3-pip python3-venv patchelf build-essential m4 texinfo
- name: Create virtualenv
run: >-
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-hooks/copyright_headers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright 2021-2023 VMware, Inc.
# Copyright 2021-2024 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
#
# pylint: disable=invalid-name,missing-module-docstring,missing-function-docstring
Expand Down
2 changes: 1 addition & 1 deletion dockerbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export CHOWN
CMD="
apt-get update;
apt-get install -y gcc python3 \
python3-pip python3-venv build-essential patchelf
python3-pip python3-venv build-essential patchelf m4 texinfo
cd /src
python3 -m venv venv
venv/bin/pip install build wheel setuptools
Expand Down
115 changes: 64 additions & 51 deletions src/relenv_gdb/build.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# Copyright 2023 VMware, Inc.
# Copyright 2023-2024 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
#
"""
Build our python wheel.
"""
import contextlib
import logging
import os
import pathlib
import pprint
import shutil
import subprocess
import tempfile
import pprint
import sys

import relenv.build
import relenv.buildenv
import relenv.common
import relenv.create
import relenv.build
import relenv.fetch
import relenv.toolchain
from setuptools.build_meta import *
Expand All @@ -39,40 +40,69 @@ def pushd(path):
def build_gdb(prefix):
"""Compile and install gdb to the prefix."""
src = prefix / "src"
src.mkdir()
src.mkdir(exist_ok=True)

os.environ.update(relenv.buildenv.buildenv(prefix))
os.environ["CFLAGS"] = (
f"{os.environ['CFLAGS']} -I{os.environ['RELENV_PATH']}/include/ncursesw "
f"-I{os.environ['RELENV_PATH']}/include/readline "
f"-I{os.environ['RELENV_PATH']}/lib/python3.10/site-packages/relenv_gdb/gdb/include"
)
os.environ["CPPFLAGS"] = (
f"{os.environ['CPPFLAGS']} -I{os.environ['RELENV_PATH']}/include/ncursesw "
f"-I{os.environ['RELENV_PATH']}/include/readline "
f"-I{os.environ['RELENV_PATH']}/lib/python3.10/site-packages/relenv_gdb/gdb/include"
)
os.environ["LDFLAGS"] = (
f"{os.environ['LDFLAGS']} "
f"-L{os.environ['RELENV_PATH']}/lib/python3.10/site-packages/relenv_gdb/gdb/lib "
f"-lreadline"
)

print(f"Build environment: {pprint.pformat(dict(os.environ))}")
sys.stdout.flush()

url = "https://gmplib.org/download/gmp/gmp-6.3.0.tar.xz"
relenv.common.download_url(
url,
src,
)

archive_name = str(src / pathlib.Path(url).name)
relenv.common.extract_archive(str(src), archive_name)
dir_name = archive_name.split(".tar")[0]
os.environ.update(relenv.buildenv.buildenv(prefix))
os.environ["RELENV_PATH"] = str(prefix)
os.environ[
"CFLAGS"
] = f"{os.environ['CFLAGS']} -I{os.environ['RELENV_PATH']}/include/ncursesw"
os.environ[
"CPPFLAGS"
] = f"{os.environ['CPPFLAGS']} -I{os.environ['RELENV_PATH']}/include/ncursesw"

print(f"Build environment: {pprint.pformat(dict(os.environ))}")
with pushd(src / dir_name):
subprocess.run(
[
"./configure",
f"--prefix={os.environ['RELENV_PATH']}/lib/python3.10/site-packages/relenv_gdb/gdb",
],
check=True,
)
subprocess.run(["make"], check=True)
subprocess.run(["make", "install"], check=True)

url = "https://www.mpfr.org/mpfr-current/mpfr-4.2.1.tar.xz"
relenv.common.download_url(
url,
src,
)
archive_name = str(src / pathlib.Path(url).name)
relenv.common.extract_archive(str(src), archive_name)
dir_name = archive_name.split(".tar")[0]

with pushd(src / dir_name):
subprocess.run(
[
"./configure",
f"--prefix={os.environ['RELENV_PATH']}/lib/python3.10/site-packages/relenv_gdb/gdb",
]
check=True
],
check=True,
)
subprocess.run(["make"], check=True)
subprocess.run(["make", "install"], check=True)

url = "https://ftp.gnu.org/gnu/gdb/gdb-13.2.tar.xz"
url = "https://ftp.gnu.org/gnu/gdb/gdb-15.1.tar.xz"
relenv.common.download_url(
url,
src,
Expand All @@ -88,8 +118,8 @@ def build_gdb(prefix):
f"--with-python={os.environ['RELENV_PATH']}/bin/python3",
"--with-lzma",
"--with-separate-debug-dir=/usr/lib/debug",
]
check=True
],
check=True,
)
subprocess.run(["make"], check=True)
bins = ["gdb/gdb", "gdbserver/gdbserver", "gdbserver/libinproctrace.so"]
Expand All @@ -101,7 +131,7 @@ def build_gdb(prefix):
f"{os.environ['TOOLCHAIN_PATH']}/{os.environ['TRIPLET']}/sysroot/lib",
_,
],
check=True
check=True,
)
subprocess.run(["make", "install"])

Expand All @@ -118,11 +148,8 @@ def build_gdb(prefix):

def build_wheel(wheel_directory, metadata_directory=None, config_settings=None):
"""PEP 517 wheel creation hook."""
import logging
logging.basicConfig(level=logging.DEBUG)
static_build_dir = os.environ.get("PY_STATIC_BUILD_DIR", "")

#XXX should be in relenv
dirs = relenv.common.work_dirs()
if not dirs.toolchain.exists():
os.makedirs(dirs.toolchain)
Expand All @@ -131,32 +158,18 @@ def build_wheel(wheel_directory, metadata_directory=None, config_settings=None):

arch = relenv.common.build_arch()
triplet = relenv.common.get_triplet(machine=arch)

python = relenv.build.platform_versions()[0]
version = relenv.common.__version__

if static_build_dir:
relenvdir = (pathlib.Path(static_build_dir) / "gdb").resolve()
relenv.toolchain.fetch(
arch, dirs.toolchain
)
relenv.fetch.fetch(relenv.common.__version__, triplet, python)
relenv.create.create(str(relenvdir))
build_gdb(relenvdir)
try:
return _build_wheel(wheel_directory, metadata_directory, config_settings)
finally:
shutil.rmtree("src/relenv_gdb/gdb")
else:
with tempfile.TemporaryDirectory() as tmp_dist_dir:
relenvdir = pathlib.Path(tmp_dist_dir) / "gdb"
relenv.toolchain.fetch(
arch, dirs.toolchain
)
relenv.fetch.fetch(relenv.common.__version__, triplet, python)
relenv.create.create(str(relenvdir))
build_gdb(relenvdir)
try:
return _build_wheel(
wheel_directory, metadata_directory, config_settings
)
finally:
shutil.rmtree("src/relenv_gdb/gdb")
root = pathlib.Path(os.environ.get("PWD", os.getcwd()))
build = root / "build"

relenvdir = (build / "gdb").resolve()

relenv.toolchain.fetch(arch, dirs.toolchain)
relenv.fetch.fetch(version, triplet, python)
if not relenvdir.exists():
relenv.create.create(str(relenvdir), version=python)
build_gdb(relenvdir)
return _build_wheel(wheel_directory, metadata_directory, config_settings)

0 comments on commit 578fc57

Please sign in to comment.