Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pre-commit-hooks/fix-local-includes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ else
main_src_dirs=$(find ./src -maxdepth 1 -type d -exec basename {} \; | paste -sd '|' | sed 's/|/\\|/g')
fi

# Get a list of all header filenames in src/ and tests/ (recursively, unique)
all_local_headers=$(find ./src ./tests -type f \( -name '*.hpp' -o -name '*.h' \) -exec basename {} \; | sort -u)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have *.h files

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need 2 implementations?
I mean using both main_src_dirs and all_local_headers?


# Generate a sed script for batch replacements
sed_script=$(mktemp)
for header in $all_local_headers; do
escaped_header=$(printf '%s\n' "$header" | sed 's/[\/&]/\\&/g')
echo "s|#include[[:space:]]*[\"<]$escaped_header[\">]|#include \"$header\"|g" >> "$sed_script"
done
Comment on lines +23 to +27
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make replacements directly, instead of generating code to make replacements?


fix_includes() {
file_path="$1"

Expand All @@ -29,6 +39,9 @@ fix_includes() {
sed -E "s|#include <(($main_src_dirs)/.*)>|#include \"\1\"|g" "$file_path_all_global" > "$file_path_fixed"
rm "$file_path_all_global"

# Make local includes without prefix to be "..." style
sed -i -f "$sed_script" "$file_path_fixed"

# Check if the temporary file is different from the original file
if ! cmp -s "$file_path" "$file_path_fixed"; then
# Replace the original file with the temporary file
Expand All @@ -42,3 +55,6 @@ fix_includes() {
for file in $files; do
fix_includes "$file"
done

# Remove the temporary sed script
rm "$sed_script"
2 changes: 1 addition & 1 deletion tests/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ target_sources(
migration/cassandra/ExampleDropTableMigrator.cpp
util/CassandraDBHelper.cpp
# Test runner
TestGlobals.cpp
Main.cpp
TestGlobals.cpp
)

# Fix for dwarf5 bug on ci. IS STILL NEEDED???
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
//==============================================================================

#include "TestGlobals.hpp"
#include "util/LoggerFixtures.hpp"
#include "util/TerminationHandler.hpp"

#include <TestGlobals.hpp>
#include <gtest/gtest.h>

/*
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/TestGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
*/
//==============================================================================

#include <TestGlobals.hpp>
#include "TestGlobals.hpp"

#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/value_semantic.hpp>
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/data/BackendFactoryTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
//==============================================================================

#include "TestGlobals.hpp"
#include "data/BackendFactory.hpp"
#include "data/LedgerCache.hpp"
#include "data/cassandra/Handle.hpp"
Expand All @@ -28,7 +29,6 @@
#include "util/config/ConfigValue.hpp"
#include "util/config/Types.hpp"

#include <TestGlobals.hpp>
#include <boost/json/parse.hpp>
#include <fmt/format.h>
#include <gtest/gtest.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/data/cassandra/BackendTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
//==============================================================================

#include "TestGlobals.hpp"
#include "data/BackendInterface.hpp"
#include "data/CassandraBackend.hpp"
#include "data/DBHelpers.hpp"
Expand All @@ -39,7 +40,6 @@
#include "util/config/ObjectView.hpp"
#include "util/config/Types.hpp"

#include <TestGlobals.hpp>
#include <boost/asio/executor_work_guard.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/spawn.hpp>
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/data/cassandra/BaseTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
//==============================================================================

#include "TestGlobals.hpp"
#include "data/cassandra/Handle.hpp"
#include "data/cassandra/Types.hpp"

#include <TestGlobals.hpp>
#include <cassandra.h>
#include <fmt/format.h>
#include <gtest/gtest.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
//==============================================================================

#include "TestGlobals.hpp"
#include "data/BackendInterface.hpp"
#include "data/DBHelpers.hpp"
#include "data/LedgerCache.hpp"
Expand All @@ -39,7 +40,6 @@
#include "util/config/ConfigValue.hpp"
#include "util/config/Types.hpp"

#include <TestGlobals.hpp>
#include <gtest/gtest.h>
#include <xrpl/basics/base_uint.h>

Expand Down
Loading