add
This commit is contained in:
parent
6e058bf024
commit
c93ef640e5
@ -6,10 +6,10 @@
|
||||
import re
|
||||
|
||||
# --- Version Data (Generated) ---
|
||||
__version__ = "v.1.0.0.3-4-g5f6d85b"
|
||||
GIT_COMMIT_HASH = "5f6d85b34bf03f89668d8f02e4a9482261e0b1fb"
|
||||
__version__ = "v.1.0.0.4-0-gb2cad05-dirty"
|
||||
GIT_COMMIT_HASH = "b2cad050aa4377ffbf81f68c7dd5231c0f20ba24"
|
||||
GIT_BRANCH = "master"
|
||||
BUILD_TIMESTAMP = "2025-09-25T12:04:11.622704+00:00"
|
||||
BUILD_TIMESTAMP = "2025-10-07T06:00:05.984082+00:00"
|
||||
IS_GIT_REPO = True
|
||||
|
||||
# --- Default Values (for comparison or fallback) ---
|
||||
|
||||
@ -7,6 +7,11 @@ import time
|
||||
import re
|
||||
from typing import Optional, Dict, Any, List, Tuple
|
||||
|
||||
# DUMPER_VERSION placeholder. This will be replaced automatically by
|
||||
# tools/update_dumper_version.py at commit/build time when you want a
|
||||
# concrete version baked into the file. Keep the quotes.
|
||||
DUMPER_VERSION = "__DUMPER_VERSION__"
|
||||
|
||||
# --- Initial Sourcing Diagnostic ---
|
||||
try:
|
||||
gdb.write(
|
||||
@ -48,9 +53,18 @@ def _dumper_log_write(message: str):
|
||||
if CAN_WRITE_TO_INTERNAL_LOG: CAN_WRITE_TO_INTERNAL_LOG = False
|
||||
gdb.write(f"GDB_DUMPER_LOG_FALLBACK: {message}\n"); gdb.flush()
|
||||
except Exception as e: CAN_WRITE_TO_INTERNAL_LOG = False; print(f"CRITICAL GDB DUMPER LOG ERROR: {e}")
|
||||
_dumper_log_write("--- GDB Dumper Script Initializing ---")
|
||||
if not CAN_WRITE_TO_INTERNAL_LOG: _dumper_log_write("Using GDB console fallback for logging.")
|
||||
gdb.write("GDB_DUMPER_SCRIPT: Logger initialization sequence complete.\n"); gdb.flush()
|
||||
_dumper_log_write("--- GDB Dumper Script Initializing ---")
|
||||
if not CAN_WRITE_TO_INTERNAL_LOG: _dumper_log_write("Using GDB console fallback for logging.")
|
||||
# Log the (possibly placeholder) dumper version so it's recorded even if the
|
||||
# script is copied far away from the repository. The placeholder can be
|
||||
# replaced by a commit/build step using the helper script in tools/.
|
||||
try:
|
||||
_dumper_log_write(f"DUMPER_VERSION: {DUMPER_VERSION}")
|
||||
gdb.write(f"GDB_DUMPER_SCRIPT: Logger initialization sequence complete. DUMPER_VERSION={DUMPER_VERSION}\n")
|
||||
gdb.flush()
|
||||
except Exception:
|
||||
# Best-effort: if gdb.write fails for any reason, continue silently.
|
||||
pass
|
||||
|
||||
|
||||
# --- INIZIO MODIFICA CHIAVE ---
|
||||
|
||||
21
tools/README.md
Normal file
21
tools/README.md
Normal file
@ -0,0 +1,21 @@
|
||||
tools/update_dumper_version.py
|
||||
|
||||
This helper updates the `DUMPER_VERSION` placeholder in
|
||||
`cpp_python_debug/core/gdb_dumper.py`.
|
||||
|
||||
Usage examples:
|
||||
|
||||
# 1) Use version from package file
|
||||
python tools/update_dumper_version.py
|
||||
|
||||
# 2) Force a version and commit the change
|
||||
python tools/update_dumper_version.py --version 1.2.3 --commit
|
||||
|
||||
# 3) If you prefer a git pre-commit hook, add the following to .git/hooks/pre-commit
|
||||
|
||||
#!/bin/sh
|
||||
python tools/update_dumper_version.py || exit 1
|
||||
|
||||
Note: Git hooks are not versioned automatically; you can place an example hook
|
||||
in `tools/hooks/pre-commit.example` and ask contributors to copy it to
|
||||
`.git/hooks/pre-commit`.
|
||||
109
tools/update_dumper_version.py
Normal file
109
tools/update_dumper_version.py
Normal file
@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Update the DUMPER_VERSION placeholder in cpp_python_debug/core/gdb_dumper.py.
|
||||
|
||||
Usage:
|
||||
python tools/update_dumper_version.py [--version X.Y.Z] [--commit]
|
||||
|
||||
Behavior:
|
||||
- If --version is provided, that version will be used.
|
||||
- Otherwise the script will try, in order:
|
||||
1) read cpp_python_debug/_version.py for __version__
|
||||
2) run `git describe --tags --always` in the repository root (searching upwards)
|
||||
- The script replaces the first occurrence of DUMPER_VERSION = "..." in
|
||||
`cpp_python_debug/core/gdb_dumper.py` with the chosen version string.
|
||||
- If --commit is passed and the repo is a git repo, it will stage and commit
|
||||
the updated file with a message.
|
||||
|
||||
Note: This script does not assume the dumper will be executed in the repo; it
|
||||
writes the version directly into the dumper file so that copies of the file
|
||||
still carry a concrete version string.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
|
||||
DUMPER_PATH = os.path.join(ROOT, "cpp_python_debug", "core", "gdb_dumper.py")
|
||||
VERSION_FILE = os.path.join(ROOT, "cpp_python_debug", "_version.py")
|
||||
|
||||
|
||||
def read_version_from_file():
|
||||
if not os.path.exists(VERSION_FILE):
|
||||
return None
|
||||
content = open(VERSION_FILE, "r", encoding="utf-8").read()
|
||||
m = re.search(r"^__version__\s*=\s*['\"]([^'\"]+)['\"]", content, re.M)
|
||||
return m.group(1) if m else None
|
||||
|
||||
|
||||
def git_describe_from(path):
|
||||
# Walk upwards looking for a .git directory
|
||||
cur = os.path.abspath(path)
|
||||
for _ in range(50):
|
||||
if os.path.isdir(os.path.join(cur, ".git")):
|
||||
try:
|
||||
out = subprocess.check_output(["git", "-C", cur, "describe", "--tags", "--always"], stderr=subprocess.DEVNULL)
|
||||
return out.decode().strip()
|
||||
except Exception:
|
||||
return None
|
||||
parent = os.path.dirname(cur)
|
||||
if parent == cur:
|
||||
break
|
||||
cur = parent
|
||||
# As a last resort, try running git describe in the provided path
|
||||
try:
|
||||
out = subprocess.check_output(["git", "describe", "--tags", "--always"], cwd=path, stderr=subprocess.DEVNULL)
|
||||
return out.decode().strip()
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def replace_dumper_version(new_version: str, commit: bool = False):
|
||||
if not os.path.exists(DUMPER_PATH):
|
||||
print(f"ERROR: dumper file not found at {DUMPER_PATH}")
|
||||
return 2
|
||||
txt = open(DUMPER_PATH, "r", encoding="utf-8").read()
|
||||
# Replace the first occurrence of DUMPER_VERSION = "..."
|
||||
new_txt, count = re.subn(r"DUMPER_VERSION\s*=\s*\"[^\"]*\"", f'DUMPER_VERSION = "{new_version}"', txt, count=1)
|
||||
if count == 0:
|
||||
print("WARNING: placeholder not found; inserting at top of file")
|
||||
# Prepend definition after imports block heuristically
|
||||
new_txt = txt.replace("from typing import Optional, Dict, Any, List, Tuple\n", "from typing import Optional, Dict, Any, List, Tuple\n\n# DUMPER_VERSION injected by tools/update_dumper_version.py\nDUMPER_VERSION = \"{0}\"\n".format(new_version), 1)
|
||||
if new_txt == txt:
|
||||
print("No changes needed (version already set).")
|
||||
return 0
|
||||
open(DUMPER_PATH, "w", encoding="utf-8").write(new_txt)
|
||||
print(f"Updated {DUMPER_PATH} -> DUMPER_VERSION = {new_version}")
|
||||
if commit:
|
||||
try:
|
||||
subprocess.check_call(["git", "add", DUMPER_PATH], cwd=ROOT)
|
||||
subprocess.check_call(["git", "commit", "-m", f"chore: update dumper version to {new_version}"], cwd=ROOT)
|
||||
print("Committed change to git.")
|
||||
except Exception as e:
|
||||
print(f"Failed to commit: {e}")
|
||||
return 3
|
||||
return 0
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--version", help="explicit version to write")
|
||||
ap.add_argument("--commit", action="store_true", help="stage and commit the change")
|
||||
args = ap.parse_args()
|
||||
|
||||
version = args.version
|
||||
if not version:
|
||||
version = read_version_from_file()
|
||||
if not version:
|
||||
version = git_describe_from(ROOT)
|
||||
if not version:
|
||||
print("Could not determine version from _version.py or git; please pass --version")
|
||||
return 10
|
||||
return replace_dumper_version(version, commit=args.commit)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Loading…
Reference in New Issue
Block a user