From ed0c801fc69f55103c597dcc29cadf4c7cb7d575 Mon Sep 17 00:00:00 2001 From: Chris Kay Date: Tue, 28 Jan 2025 18:04:11 +0000 Subject: [PATCH] refactor(memmap): migrate to Poetry This change refactors the memmap tool into a Poetry project, with its own dependencies. You can continue to run it manually with: poetry run memory Change-Id: I346283df1b8bfad4babc1f5a3861dab94d4a006a Signed-off-by: Chris Kay --- .github/dependabot.yml | 2 +- .readthedocs.yaml | 5 +- Makefile | 3 +- docs/tools/memory-layout-tool.rst | 4 +- poetry.lock | 25 +++++- pyproject.toml | 13 +-- tools/memory/__init__.py | 7 -- tools/memory/memory/__init__.py | 7 -- tools/memory/poetry.lock | 95 ++++++++++++++++++++ tools/memory/pyproject.toml | 21 +++++ tools/memory/src/memory/__init__.py | 5 ++ tools/memory/{ => src}/memory/buildparser.py | 2 +- tools/memory/{ => src}/memory/elfparser.py | 2 +- tools/memory/{ => src}/memory/mapparser.py | 2 +- tools/memory/{ => src}/memory/memmap.py | 2 +- tools/memory/{ => src}/memory/printer.py | 2 +- 16 files changed, 155 insertions(+), 42 deletions(-) delete mode 100644 tools/memory/__init__.py delete mode 100644 tools/memory/memory/__init__.py create mode 100644 tools/memory/poetry.lock create mode 100644 tools/memory/pyproject.toml create mode 100644 tools/memory/src/memory/__init__.py rename tools/memory/{ => src}/memory/buildparser.py (97%) rename tools/memory/{ => src}/memory/elfparser.py (98%) rename tools/memory/{ => src}/memory/mapparser.py (97%) rename tools/memory/{ => src}/memory/memmap.py (97%) rename tools/memory/{ => src}/memory/printer.py (98%) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3f1fff2ca..523728b03 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -36,7 +36,7 @@ updates: - target-branch: "main" package-ecosystem: "pip" versioning-strategy: "lockfile-only" - directories: ["/", "/tools/cot_dt2c", "/tools/tlc"] + directories: ["/", "/tools/cot_dt2c", "/tools/memory", "/tools/tlc"] schedule: interval: "daily" groups: diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 2d1afab82..d308fdd28 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, Arm Limited. All rights reserved +# Copyright (c) 2023-2025, Arm Limited. All rights reserved # # SPDX-License-Identifier: BSD-3-Clause # @@ -20,7 +20,7 @@ build: post_create_environment: - pip install poetry=="1.3.2" post_install: - - VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install --with docs + - VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install --no-root --with docs sphinx: configuration: docs/conf.py @@ -28,4 +28,3 @@ sphinx: # Auxiliary formats to export to (in addition to the default HTML output). formats: - pdf - diff --git a/Makefile b/Makefile index a3aad1207..5c6ab35ce 100644 --- a/Makefile +++ b/Makefile @@ -1757,8 +1757,7 @@ $(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT $(q)${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} CRYPTO_SUPPORT=${CRYPTO_SUPPORT} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES=$(call escape-shell,$(INCLUDES)) DEFINES=$(call escape-shell,$(DEFINES)) --no-print-directory -C ${ROMLIBPATH} all memmap: all - $(q)PYTHONPATH=${CURDIR}/tools/memory \ - ${PYTHON} -m memory.memmap -sr ${BUILD_PLAT} + $(q)$(if $(host-poetry),poetry run )memory -sr ${BUILD_PLAT} tl: ${BUILD_PLAT}/tl.bin ${BUILD_PLAT}/tl.bin: ${HW_CONFIG} diff --git a/docs/tools/memory-layout-tool.rst b/docs/tools/memory-layout-tool.rst index 8874bd7c7..d9c358d4d 100644 --- a/docs/tools/memory-layout-tool.rst +++ b/docs/tools/memory-layout-tool.rst @@ -23,7 +23,7 @@ Getting Started .. code:: shell - poetry install --with memory + poetry install --no-root #. Verify that the tool runs in the installed virtual environment @@ -231,6 +231,6 @@ you can specify the depth with: -------------- -*Copyright (c) 2023, Arm Limited. All rights reserved.* +*Copyright (c) 2023-2025, Arm Limited. All rights reserved.* .. _Poetry: https://python-poetry.org/docs/ diff --git a/poetry.lock b/poetry.lock index 4127bcd4b..341a2bd03 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.5 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. [[package]] name = "alabaster" @@ -537,6 +537,25 @@ files = [ {file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"}, ] +[[package]] +name = "memory" +version = "0.1.0" +description = "A tool for analysis of " +optional = false +python-versions = "^3.8.0" +files = [] +develop = true + +[package.dependencies] +anytree = "^2.8.0" +click = "^8.1.3" +prettytable = "^3.5.0" +pyelftools = "^0.29.0" + +[package.source] +type = "directory" +url = "tools/memory" + [[package]] name = "myst-parser" version = "0.18.1" @@ -1147,7 +1166,7 @@ develop = true [package.dependencies] click = "^8.1.7" -jinja2 = "^3.1.4" +jinja2 = "^3.1.5" pyyaml = "^6.0.1" rich = "^10.14.0" tox = "^4.18.0" @@ -1312,4 +1331,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "6a6d2fe9390a4d7d1ecf808d5f303f2dc1eeb44736827b706a858046f3eea1db" +content-hash = "7574eee0a05db1d9631bb29288abfc806810906a66e087a5a32e6e3920eb4bba" diff --git a/pyproject.toml b/pyproject.toml index 62878b412..55f3f2a3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,16 +5,11 @@ description = "Trusted Firmware-A (TF-A) Python dependencies." authors = ["Arm Ltd."] license = "BSD-3-Clause" readme = "readme.rst" -packages = [ - { include = "memory", from = "tools/memory"} -] - -[tool.poetry.scripts] -memory = "memory.memmap:main" [tool.poetry.dependencies] python = "^3.8" cot-dt2c = {path = "tools/cot_dt2c", develop = true} +memory = {path = "tools/memory", develop = true} tlc = {path = "tools/tlc", develop = true} [tool.poetry.group.docs] @@ -30,9 +25,3 @@ sphinxcontrib-svg2pdfconverter = "^1.2.2" [tool.poetry.group.ci.dependencies] click = "^8.1.3" - -[tool.poetry.group.memory.dependencies] -pyelftools = "^0.29" -anytree = "^2.8.0" -click = "^8.1.3" -prettytable = "^3.5.0" diff --git a/tools/memory/__init__.py b/tools/memory/__init__.py deleted file mode 100644 index 0b4c8d355..000000000 --- a/tools/memory/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python3 - -# -# Copyright (c) 2023, Arm Limited. All rights reserved. -# -# SPDX-License-Identifier: BSD-3-Clause -# diff --git a/tools/memory/memory/__init__.py b/tools/memory/memory/__init__.py deleted file mode 100644 index 0b4c8d355..000000000 --- a/tools/memory/memory/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python3 - -# -# Copyright (c) 2023, Arm Limited. All rights reserved. -# -# SPDX-License-Identifier: BSD-3-Clause -# diff --git a/tools/memory/poetry.lock b/tools/memory/poetry.lock new file mode 100644 index 000000000..274747997 --- /dev/null +++ b/tools/memory/poetry.lock @@ -0,0 +1,95 @@ +# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. + +[[package]] +name = "anytree" +version = "2.12.1" +description = "Powerful and Lightweight Python Tree Data Structure with various plugins" +optional = false +python-versions = ">=3.7.2,<4" +files = [ + {file = "anytree-2.12.1-py3-none-any.whl", hash = "sha256:5ea9e61caf96db1e5b3d0a914378d2cd83c269dfce1fb8242ce96589fa3382f0"}, + {file = "anytree-2.12.1.tar.gz", hash = "sha256:244def434ccf31b668ed282954e5d315b4e066c4940b94aff4a7962d85947830"}, +] + +[package.dependencies] +six = "*" + +[[package]] +name = "click" +version = "8.1.8" +description = "Composable command line interface toolkit" +optional = false +python-versions = ">=3.7" +files = [ + {file = "click-8.1.8-py3-none-any.whl", hash = "sha256:63c132bbbed01578a06712a2d1f497bb62d9c1c0d329b7903a866228027263b2"}, + {file = "click-8.1.8.tar.gz", hash = "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "prettytable" +version = "3.11.0" +description = "A simple Python library for easily displaying tabular data in a visually appealing ASCII table format" +optional = false +python-versions = ">=3.8" +files = [ + {file = "prettytable-3.11.0-py3-none-any.whl", hash = "sha256:aa17083feb6c71da11a68b2c213b04675c4af4ce9c541762632ca3f2cb3546dd"}, + {file = "prettytable-3.11.0.tar.gz", hash = "sha256:7e23ca1e68bbfd06ba8de98bf553bf3493264c96d5e8a615c0471025deeba722"}, +] + +[package.dependencies] +wcwidth = "*" + +[package.extras] +tests = ["pytest", "pytest-cov", "pytest-lazy-fixtures"] + +[[package]] +name = "pyelftools" +version = "0.29" +description = "Library for analyzing ELF files and DWARF debugging information" +optional = false +python-versions = "*" +files = [ + {file = "pyelftools-0.29-py2.py3-none-any.whl", hash = "sha256:519f38cf412f073b2d7393aa4682b0190fa901f7c3fa0bff2b82d537690c7fc1"}, + {file = "pyelftools-0.29.tar.gz", hash = "sha256:ec761596aafa16e282a31de188737e5485552469ac63b60cfcccf22263fd24ff"}, +] + +[[package]] +name = "six" +version = "1.17.0" +description = "Python 2 and 3 compatibility utilities" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" +files = [ + {file = "six-1.17.0-py2.py3-none-any.whl", hash = "sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274"}, + {file = "six-1.17.0.tar.gz", hash = "sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81"}, +] + +[[package]] +name = "wcwidth" +version = "0.2.13" +description = "Measures the displayed width of unicode strings in a terminal" +optional = false +python-versions = "*" +files = [ + {file = "wcwidth-0.2.13-py2.py3-none-any.whl", hash = "sha256:3da69048e4540d84af32131829ff948f1e022c1c6bdb8d6102117aac784f6859"}, + {file = "wcwidth-0.2.13.tar.gz", hash = "sha256:72ea0c06399eb286d978fdedb6923a9eb47e1c486ce63e9b4e64fc18303972b5"}, +] + +[metadata] +lock-version = "2.0" +python-versions = "^3.8.0" +content-hash = "d7c185b3dbfc9bba145f12146e18ce501caf081d7762f138bc5a7fde99f40543" diff --git a/tools/memory/pyproject.toml b/tools/memory/pyproject.toml new file mode 100644 index 000000000..c2fdfcb8a --- /dev/null +++ b/tools/memory/pyproject.toml @@ -0,0 +1,21 @@ +[tool.poetry] +name = "memory" +version = "0.1.0" +description = "A tool for analysis of static memory consumption by TF-A images" +authors = ["Chris Kay ", "Harrison Mutai "] +license = "BSD-3-Clause" +packages = [{include = "memory", from = "src"}] + +[tool.poetry.dependencies] +anytree = "^2.8.0" +click = "^8.1.3" +prettytable = "^3.5.0" +pyelftools = "^0.29.0" +python = "^3.8.0" + +[tool.poetry.scripts] +memory = "memory.memmap:main" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/tools/memory/src/memory/__init__.py b/tools/memory/src/memory/__init__.py new file mode 100644 index 000000000..8e0db6b69 --- /dev/null +++ b/tools/memory/src/memory/__init__.py @@ -0,0 +1,5 @@ +# +# Copyright (c) 2025, Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# diff --git a/tools/memory/memory/buildparser.py b/tools/memory/src/memory/buildparser.py similarity index 97% rename from tools/memory/memory/buildparser.py rename to tools/memory/src/memory/buildparser.py index dedff7993..ea417e128 100755 --- a/tools/memory/memory/buildparser.py +++ b/tools/memory/src/memory/buildparser.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2023, Arm Limited. All rights reserved. +# Copyright (c) 2023-2025, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # diff --git a/tools/memory/memory/elfparser.py b/tools/memory/src/memory/elfparser.py similarity index 98% rename from tools/memory/memory/elfparser.py rename to tools/memory/src/memory/elfparser.py index 2dd251359..e6581c98a 100644 --- a/tools/memory/memory/elfparser.py +++ b/tools/memory/src/memory/elfparser.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2023, Arm Limited. All rights reserved. +# Copyright (c) 2023-2025, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # diff --git a/tools/memory/memory/mapparser.py b/tools/memory/src/memory/mapparser.py similarity index 97% rename from tools/memory/memory/mapparser.py rename to tools/memory/src/memory/mapparser.py index ce4cc3113..1c28e715c 100644 --- a/tools/memory/memory/mapparser.py +++ b/tools/memory/src/memory/mapparser.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2023-2024, Arm Limited. All rights reserved. +# Copyright (c) 2023-2025, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # diff --git a/tools/memory/memory/memmap.py b/tools/memory/src/memory/memmap.py similarity index 97% rename from tools/memory/memory/memmap.py rename to tools/memory/src/memory/memmap.py index 34f5069c0..f46db8cf5 100755 --- a/tools/memory/memory/memmap.py +++ b/tools/memory/src/memory/memmap.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -# Copyright (c) 2023-2024, Arm Limited. All rights reserved. +# Copyright (c) 2023-2025, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # diff --git a/tools/memory/memory/printer.py b/tools/memory/src/memory/printer.py similarity index 98% rename from tools/memory/memory/printer.py rename to tools/memory/src/memory/printer.py index 4b185604f..f797139cf 100755 --- a/tools/memory/memory/printer.py +++ b/tools/memory/src/memory/printer.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2023, Arm Limited. All rights reserved. +# Copyright (c) 2023-2025, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause #