-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance Dynamic Include Path Management in xeus-cpp with XEUS_SEARCH_PATH Support #187
base: main
Are you sure you want to change the base?
Enhance Dynamic Include Path Management in xeus-cpp with XEUS_SEARCH_PATH Support #187
Conversation
This change: 1. Replaces compile-time XEUS_SEARCH_PATH define with runtime environment variable 2. Removes CMake definition to eliminate redefinition warnings 3. Adds test to verify non-standard include path functionality 4. Makes include path configuration more flexible (can be changed without recompiling) Resolves compiler-research#175
I have pushed new changes, please approve the awaiting workflows @vgvassilev |
Hi, I shall find the time to review this soon ! |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #187 +/- ##
==========================================
- Coverage 80.80% 80.44% -0.36%
==========================================
Files 19 19
Lines 974 987 +13
Branches 93 97 +4
==========================================
+ Hits 787 794 +7
- Misses 187 193 +6
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
Cpp::AddIncludePath((xeus::prefix_path() + "/include/").c_str()); | ||
|
||
// Get include paths from environment variable | ||
const char* non_standard_paths = std::getenv("XEUS_SEARCH_PATH"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "std::getenv" is directly included [misc-include-cleaner]
src/xinterpreter.cpp:19:
- #ifndef EMSCRIPTEN
+ #include <cstdlib>
+ #ifndef EMSCRIPTEN
non_standard_paths = ""; | ||
} | ||
|
||
if (std::strlen(non_standard_paths) > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "std::strlen" is directly included [misc-include-cleaner]
src/xinterpreter.cpp:19:
- #ifndef EMSCRIPTEN
+ #include <cstring>
+ #ifndef EMSCRIPTEN
if (std::strlen(non_standard_paths) > 0) | ||
{ | ||
// Split the paths by colon ':' and add each one | ||
std::istringstream stream(non_standard_paths); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "std::istringstream" is directly included [misc-include-cleaner]
src/xinterpreter.cpp:19:
- #ifndef EMSCRIPTEN
+ #include <sstream>
+ #ifndef EMSCRIPTEN
// Split the paths by colon ':' and add each one | ||
std::istringstream stream(non_standard_paths); | ||
std::string path; | ||
while (std::getline(stream, path, ':')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "std::getline" is directly included [misc-include-cleaner]
while (std::getline(stream, path, ':'))
^
- Add <cstring> for std::strlen - Add <sstream> for std::istringstream - Add <string> for std::getline Resolves include-cleaner warnings by explicitly including headers for all used standard library symbols. This improves code maintainability and prevents reliance on indirect includes.
I have fixed the warnings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
CMakeLists.txt
Outdated
|
||
# Find doctest package | ||
find_package(doctest REQUIRED) | ||
|
||
# Test for non-standard include paths | ||
add_executable(test_include_paths test/test_include_paths.cpp) | ||
target_link_libraries(test_include_paths PRIVATE doctest::doctest) | ||
target_include_directories(test_include_paths PRIVATE | ||
${CMAKE_SOURCE_DIR}/test/custom_includes | ||
${DOCTEST_INCLUDE_DIR} | ||
) | ||
target_compile_definitions(test_include_paths PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN) | ||
add_test(NAME test_include_paths COMMAND test_include_paths) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block should go in the test folder.
src/xinterpreter.cpp
Outdated
// Get include paths from environment variable | ||
const char* non_standard_paths = std::getenv("XEUS_SEARCH_PATH"); | ||
if (!non_standard_paths) { | ||
non_standard_paths = ""; | ||
} | ||
|
||
if (std::strlen(non_standard_paths) > 0) | ||
{ | ||
// Split the paths by colon ':' and add each one | ||
std::istringstream stream(non_standard_paths); | ||
std::string path; | ||
while (std::getline(stream, path, ':')) | ||
{ | ||
if (!path.empty()) | ||
{ | ||
Cpp::AddIncludePath(path.c_str()); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can simplify this by a lot, reduce the mount braces and also consider non-unix path delimiters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
- Relocated the test_include_paths executable setup from the root CMakeLists.txt to the test folder's CMakeLists.txt. - Included the necessary doctest package configuration and non-standard include paths. - Ensured proper target linking and definitions for the test_include_paths target.
clang-tidy review says "All clean, LGTM! 👍" |
I have fixed the clang-format problem. |
src/xinterpreter.cpp
Outdated
while (std::getline(stream, path, path_separator)) | ||
{ | ||
if (!path.empty()) | ||
{ | ||
Cpp::AddIncludePath(path.c_str()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while (std::getline(stream, path, path_separator)) | |
{ | |
if (!path.empty()) | |
{ | |
Cpp::AddIncludePath(path.c_str()); | |
} | |
} | |
while (std::getline(stream, path, path_separator)) | |
if (!path.empty()) | |
Cpp::AddIncludePath(path.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, I initially thought the braces were necessary for the clang-tidy format check to pass. I've now edited and correctly formatted the file.
clang-tidy review says "All clean, LGTM! 👍" |
Please approve the awaiting workflows. @anutosh491 @vgvassilev |
clang-tidy review says "All clean, LGTM! 👍" |
@AhmedFatthy1040 please squash the commits of the PR and perform git-clang-format on the single commit. Then the ci should pass. Then another review can be made. |
@mcbarton I previously addressed this issue by adding braces here. However, @vgvassilev recommended removing them for code simplification, which I implemented. Unfortunately, this removal triggered a failure in the git clang-format check. I have now corrected the issue by re-adding the braces. Please approve the pending workflows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
src/xinterpreter.cpp
Outdated
std::istringstream stream(non_standard_paths); | ||
std::string path; | ||
while (std::getline(stream, path, path_separator)) | ||
+ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: expected expression [clang-diagnostic-error]
+ {
^
@AhmedFatthy1040 Please revert this change. Squash the commits into 1 commit, then perform git-clang-format on this single commit. Then well see if the workflows pass. We can then review it from that point. |
Sorry for the mistake in the last commit, i am fixing it now. |
okay |
c508161
to
bdb66eb
Compare
I found out that i was using an old version of clang-format, so i updated to version 18 as it is the version used in the CI/CD pipeline, and formatted the code again @mcbarton |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
There were too many comments to post at once. Showing the first 10 out of 15. Check the log or trigger a new build to see more.
{ | ||
Args ClangArgs = {/*"-xc++"*/ "-v"}; // ? {"-Xclang", "-emit-llvm-only", "-Xclang", | ||
// "-diagnostic-log-file", "-Xclang", "-", "-xc++"}; | ||
if (std::find_if( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "std::find_if" is directly included [misc-include-cleaner]
src/xinterpreter.cpp:17:
- #include <cstring> // for std::strlen
+ #include <algorithm>
+ #include <cstring> // for std::strlen
) | ||
== ExtraArgs.end()) | ||
{ | ||
std::string resource_dir = Cpp::DetectResourceDir(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "Cpp::DetectResourceDir" is directly included [misc-include-cleaner]
src/xinterpreter.cpp:17:
- #include <cstring> // for std::strlen
+ #include <clang/Interpreter/CppInterOp.h>
+ #include <cstring> // for std::strlen
std::string resource_dir = Cpp::DetectResourceDir(); | ||
if (resource_dir.empty()) | ||
{ | ||
std::cerr << "Failed to detect the resource-dir\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "std::cerr" is directly included [misc-include-cleaner]
src/xinterpreter.cpp:18:
- #include <sstream> // for std::istringstream
+ #include <iostream>
+ #include <sstream> // for std::istringstream
ClangArgs.push_back(resource_dir.c_str()); | ||
} | ||
std::vector<std::string> CxxSystemIncludes; | ||
Cpp::DetectSystemCompilerIncludePaths(CxxSystemIncludes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "Cpp::DetectSystemCompilerIncludePaths" is directly included [misc-include-cleaner]
Cpp::DetectSystemCompilerIncludePaths(CxxSystemIncludes);
^
ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end()); | ||
// FIXME: We should process the kernel input options and conditionally pass | ||
// the gpu args here. | ||
return Cpp::CreateInterpreter(ClangArgs /*, {"-cuda"}*/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "Cpp::CreateInterpreter" is directly included [misc-include-cleaner]
return Cpp::CreateInterpreter(ClangArgs /*, {"-cuda"}*/);
^
err = Cpp::EndStdStreamCapture(); | ||
std::cout << out; | ||
} | ||
struct StreamRedirectRAII |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: class 'StreamRedirectRAII' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
struct StreamRedirectRAII
^
} | ||
struct StreamRedirectRAII | ||
{ | ||
std::string& err; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: member 'err' of type 'std::string &' (aka 'basic_string &') is a reference [cppcoreguidelines-avoid-const-or-ref-data-members]
std::string& err;
^
StreamRedirectRAII(std::string& e) | ||
: err(e) | ||
{ | ||
Cpp::BeginStdStreamCapture(Cpp::kStdErr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "Cpp::BeginStdStreamCapture" is directly included [misc-include-cleaner]
Cpp::BeginStdStreamCapture(Cpp::kStdErr);
^
StreamRedirectRAII(std::string& e) | ||
: err(e) | ||
{ | ||
Cpp::BeginStdStreamCapture(Cpp::kStdErr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "Cpp::kStdErr" is directly included [misc-include-cleaner]
Cpp::BeginStdStreamCapture(Cpp::kStdErr);
^
: err(e) | ||
{ | ||
Cpp::BeginStdStreamCapture(Cpp::kStdErr); | ||
Cpp::BeginStdStreamCapture(Cpp::kStdOut); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "Cpp::kStdOut" is directly included [misc-include-cleaner]
Cpp::BeginStdStreamCapture(Cpp::kStdOut);
^
I will try to fix the clang-tidy suggestions tomorrow. Additionally, there was a block of code that was refactored, but it got deleted by mistake when I reset some commits. I will fix that as well. |
Description
This PR introduces improvements to the
xeus-cpp
library to handle dynamic include paths more effectively. It includes updates to theinterpreter::init_includes
function and the CMakeLists file. These changes aim to enhance flexibility and maintainability by leveraging theXEUS_SEARCH_PATH
environment variable for managing include directories dynamically.Key Changes
Updated
interpreter::init_includes
Function:XEUS_SEARCH_PATH
environment variable to include non-standard directories.:
).Modified CMakeLists File:
XEUS_SEARCH_PATH
variable by joining target include directories.src
directory for non-EMSCRIPTEN builds.XEUS_SEARCH_PATH
as a preprocessor definition to the compiler.These updates simplify the configuration and usage of custom include paths.
Fixes #175
Type of change
Please tick all options which are relevant.