From 8dcaf94a3bf80dc030f133e6e3c698232e97f03d Mon Sep 17 00:00:00 2001 From: jasonborg <48138260+jasonborg@users.noreply.github.com> Date: Thu, 2 Mar 2023 17:54:19 +0000 Subject: [PATCH 1/3] chore: Add extra tess cleanup to build scripts (#82) This addresses an issue where first running `./build_and_test.sh` followed by `build-dist.sh` could see some test failures while running the second script. One concrete scenario was when the local python version was 3.10.9 while version 3.10.10 was used during `build-dist.sh`. --- build_and_test.sh | 6 ++++++ src/build-wheels.sh | 17 ++++++++++++++--- src/build.sh | 11 ++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/build_and_test.sh b/build_and_test.sh index 8e742ea..4ce82b9 100755 --- a/build_and_test.sh +++ b/build_and_test.sh @@ -1,5 +1,8 @@ #!/bin/bash -e +# Clean up any previous generated test files. +rm -rf tests/py/__pycache__ + cd src ./build.sh cd .. @@ -10,3 +13,6 @@ pip3 install -r requirements_dev.txt pip3 install src/dist/* --force-reinstall python3 -m pytest tests/py deactivate + +# Clean up any generated test files. +rm -rf tests/py/__pycache__ diff --git a/src/build-wheels.sh b/src/build-wheels.sh index 1e4a0c6..8477d84 100755 --- a/src/build-wheels.sh +++ b/src/build-wheels.sh @@ -10,8 +10,14 @@ ROOT=$(cd $(dirname "${BASH_SOURCE[0]}") >/dev/null; /bin/pwd -P) # Parallelize the build over N threads where N is the number of cores * 1.5. PARALLEL_BUILD_OPTION="-j $(($(nproc 2> /dev/null || echo 4)*3/2))" -# Clean up any previous build files. -rm -rf ${ROOT}/build ${ROOT}/dist ${ROOT}/setup.cfg +# Clean up any previous build/test files. +rm -rf \ + ${ROOT}/build \ + ${ROOT}/dist \ + ${ROOT}/setup.cfg \ + ${ROOT}/google_python_cloud_debugger.egg-info \ + /io/dist \ + /io/tests/py/__pycache__ # Create directory for third-party libraries. mkdir -p ${ROOT}/build/third_party @@ -78,6 +84,11 @@ done popd # Clean up temporary directories. -rm -rf ${ROOT}/build ${ROOT}/setup.cfg +rm -rf \ + ${ROOT}/build \ + ${ROOT}/setup.cfg \ + ${ROOT}/google_python_cloud_debugger.egg-info \ + /io/tests/py/__pycache__ + echo "Build artifacts are in the dist directory" diff --git a/src/build.sh b/src/build.sh index ba9a944..f61ef2f 100755 --- a/src/build.sh +++ b/src/build.sh @@ -42,7 +42,11 @@ ROOT=$(cd $(dirname "${BASH_SOURCE[0]}") >/dev/null; /bin/pwd -P) PARALLEL_BUILD_OPTION="-j $(($(nproc 2> /dev/null || echo 4)*3/2))" # Clean up any previous build files. -rm -rf ${ROOT}/build ${ROOT}/dist ${ROOT}/setup.cfg +rm -rf \ + ${ROOT}/build \ + ${ROOT}/dist \ + ${ROOT}/setup.cfg \ + ${ROOT}/google_python_cloud_debugger.egg-info # Create directory for third-party libraries. mkdir -p ${ROOT}/build/third_party @@ -91,3 +95,8 @@ pushd ${ROOT} "${PYTHON:-python3}" -m pip wheel . --no-deps -w dist popd +# Clean up temporary directories. +rm -rf \ + ${ROOT}/build \ + ${ROOT}/setup.cfg \ + ${ROOT}/google_python_cloud_debugger.egg-info From ed9d2b935a53d2dee7f0bc43540a1fdc9dd314f7 Mon Sep 17 00:00:00 2001 From: James McTavish Date: Tue, 4 Apr 2023 09:49:27 -0400 Subject: [PATCH 2/3] fix: address some cases where jumps were not being updated (#83) Affects Python 3.10 only; in some situations jump instructions were not updated with new targets due to the targets being interpretted as memory offsets instead of instruction offsets. --- .../bytecode_manipulator.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/googleclouddebugger/bytecode_manipulator.cc b/src/googleclouddebugger/bytecode_manipulator.cc index 3c95edd..44cef74 100644 --- a/src/googleclouddebugger/bytecode_manipulator.cc +++ b/src/googleclouddebugger/bytecode_manipulator.cc @@ -132,6 +132,9 @@ static PythonOpcodeType GetOpcodeType(uint8_t opcode) { #if PY_VERSION_HEX < 0x03080000 // Removed in Python 3.8. case CONTINUE_LOOP: +#endif +#if PY_VERSION_HEX >= 0x03090000 + case JUMP_IF_NOT_EXC_MATCH: #endif return BRANCH_ABSOLUTE_OPCODE; @@ -144,10 +147,18 @@ static PythonOpcodeType GetOpcodeType(uint8_t opcode) { static int GetBranchTarget(int offset, PythonInstruction instruction) { switch (GetOpcodeType(instruction.opcode)) { case BRANCH_DELTA_OPCODE: +#if PY_VERSION_HEX < 0x030A0000 return offset + instruction.size + instruction.argument; +#else + return offset + instruction.size + instruction.argument * 2; +#endif case BRANCH_ABSOLUTE_OPCODE: +#if PY_VERSION_HEX < 0x030A0000 return instruction.argument; +#else + return instruction.argument * 2; +#endif default: DCHECK(false) << "Not a branch instruction"; @@ -428,13 +439,21 @@ static bool InsertAndUpdateBranchInstructions( // argument of 0 even when it is not required. This needs to be taken // into account when calculating the target of a branch instruction. int inst_size = std::max(instruction.size, it->original_size); +#if PY_VERSION_HEX < 0x030A0000 int32_t target = it->current_offset + inst_size + arg; +#else + int32_t target = it->current_offset + inst_size + arg * 2; +#endif need_to_update = it->current_offset < insertion.current_offset && insertion.current_offset < target; } else if (opcode_type == BRANCH_ABSOLUTE_OPCODE) { // For absolute branches, the argument needs to be updated if the // insertion before the target. +#if PY_VERSION_HEX < 0x030A0000 need_to_update = insertion.current_offset < arg; +#else + need_to_update = insertion.current_offset < arg * 2; +#endif } // If we are inserting the original method call instructions, we want to From 317073840c3930e64bdc2498cd56572deac3f3ee Mon Sep 17 00:00:00 2001 From: James McTavish Date: Wed, 5 Apr 2023 09:48:14 -0400 Subject: [PATCH 3/3] chore: release version 3.5 (#84) --- src/googleclouddebugger/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/googleclouddebugger/version.py b/src/googleclouddebugger/version.py index 5c21bc2..0f8f662 100644 --- a/src/googleclouddebugger/version.py +++ b/src/googleclouddebugger/version.py @@ -4,4 +4,4 @@ # The major version should only change on breaking changes. Minor version # changes go between regular updates. Instances running debuggers with # different major versions will show up as two different debuggees. -__version__ = '3.4' +__version__ = '3.5'