diff --git a/.github/workflows/package-action.yml b/.github/workflows/package-action.yml index fd3f1bb..da1d3ce 100644 --- a/.github/workflows/package-action.yml +++ b/.github/workflows/package-action.yml @@ -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: >- diff --git a/.pre-commit-hooks/copyright_headers.py b/.pre-commit-hooks/copyright_headers.py index eb0fedb..aa65dee 100644 --- a/.pre-commit-hooks/copyright_headers.py +++ b/.pre-commit-hooks/copyright_headers.py @@ -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 diff --git a/dockerbuild.sh b/dockerbuild.sh index 3264487..6369d4d 100755 --- a/dockerbuild.sh +++ b/dockerbuild.sh @@ -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 diff --git a/src/relenv_gdb/build.py b/src/relenv_gdb/build.py index 7c32422..3ad88cd 100644 --- a/src/relenv_gdb/build.py +++ b/src/relenv_gdb/build.py @@ -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 * @@ -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, @@ -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"] @@ -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"]) @@ -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) @@ -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)