fix: implement path-agnostic source patching and refine global compatibility header logic

This commit is contained in:
Timothy Hofland
2026-03-15 15:56:17 +01:00
parent 705b698b1d
commit 82813baa58

View File

@ -248,7 +248,11 @@ sudo -u "$REAL_USER" git clone --depth 1 https://github.com/kr15h/ofxPiMapper.gi
cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper" cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper"
echo "Applying clean Global Compatibility Patches..." echo "Applying clean Global Compatibility Patches..."
# 1. Fix highlight patch # 1. Locate OscControl.cpp and apply highlight patch
# Use 'find' to handle different subfolder structures
OSC_FILE=$(find src -name "OscControl.cpp" | head -n 1)
if [ -n "$OSC_FILE" ]; then
echo "Patching $OSC_FILE..."
cat <<'EOF_PATCH' > /tmp/highlight.patch cat <<'EOF_PATCH' > /tmp/highlight.patch
if (m.getAddress() == "/ofxPiMapper/surface/highlight"){ if (m.getAddress() == "/ofxPiMapper/surface/highlight"){
int surfaceIndex = m.getArgAsInt32(0); int surfaceIndex = m.getArgAsInt32(0);
@ -256,14 +260,11 @@ cat <<'EOF_PATCH' > /tmp/highlight.patch
return; return;
} }
EOF_PATCH EOF_PATCH
sed -i '/if (m.getAddress() == "\/ofxPiMapper\/surface\/select"){/r /tmp/highlight.patch' src/Osc/OscControl.cpp sed -i '/if (m.getAddress() == "\/ofxPiMapper\/surface\/select"){/r /tmp/highlight.patch' "$OSC_FILE"
rm -f /tmp/highlight.patch rm -f /tmp/highlight.patch
fi
# 2. Fix unique_ptr and make_unique globally (Only if std:: is missing) # 2. Create a single compatibility header for C++11
find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)unique_ptr\b/\1std::unique_ptr/g' {} +
find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)make_unique\b/\1std::make_unique/g' {} +
# 3. Create a single compatibility header for C++11
cat <<'EOF_COMPAT' > src/cpp11_compat.h cat <<'EOF_COMPAT' > src/cpp11_compat.h
#ifndef OFXPIMAPPER_CPP11_COMPAT_H #ifndef OFXPIMAPPER_CPP11_COMPAT_H
#define OFXPIMAPPER_CPP11_COMPAT_H #define OFXPIMAPPER_CPP11_COMPAT_H
@ -290,12 +291,16 @@ using std::string;
#endif #endif
EOF_COMPAT EOF_COMPAT
# 4. Include the compat header in the main addon header # 3. Include the compat header in the main addon header
sed -i '1i #include "cpp11_compat.h"' src/ofxPiMapper.h sed -i '1i #include "cpp11_compat.h"' src/ofxPiMapper.h
# 5. Add memory header to all headers where unique_ptr is used # 4. Fix unique_ptr and make_unique globally (Using relative paths and avoiding std::std::)
for f in $(grep -l "unique_ptr" src/*.h 2>/dev/null); do find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)unique_ptr\b/\1std::unique_ptr/g' {} +
sed -i '1i #include <memory>' "$f" find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)make_unique\b/\1std::make_unique/g' {} +
# 5. Add memory header only where needed
for f in $(grep -l "unique_ptr" src/*.h 2>/dev/null || true); do
grep -q "<memory>" "$f" || sed -i '1i #include <memory>' "$f"
done done
# Build Example # Build Example
@ -304,8 +309,6 @@ echo "Cleaning old objects..."
sudo -u "$REAL_USER" make clean sudo -u "$REAL_USER" make clean
echo "Starting compilation (Nuclear Stability Mode: -O0 + C++11 + VRP disabled)..." echo "Starting compilation (Nuclear Stability Mode: -O0 + C++11 + VRP disabled)..."
# Force -O0 and disable VRP pass completely.
# Also use OF_PROJECT variables to ensure these flags override the core makefile defaults.
GLOBAL_FLAGS="-Wno-error -Wno-reorder -Wno-sign-compare -Wno-delete-non-virtual-dtor -std=c++11 -O0 -fno-tree-vrp" GLOBAL_FLAGS="-Wno-error -Wno-reorder -Wno-sign-compare -Wno-delete-non-virtual-dtor -std=c++11 -O0 -fno-tree-vrp"
sudo -u "$REAL_USER" make -j1 \ sudo -u "$REAL_USER" make -j1 \
PLATFORM_CFLAGS="$GLOBAL_FLAGS -I$REAL_HOME/openFrameworks/addons/ofxPiMapper/src" \ PLATFORM_CFLAGS="$GLOBAL_FLAGS -I$REAL_HOME/openFrameworks/addons/ofxPiMapper/src" \