Skip to content

Commit

Permalink
.include honors -I (include dir) options
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin committed May 18, 2022
1 parent cc8ea09 commit bec3083
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 8 deletions.
11 changes: 10 additions & 1 deletion cmake/SouffleTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ function(SOUFFLE_RUN_TEST_HELPER)
#PARAM_FUNCTORS - with -L for finding functor library in the testsuite
#PARAM_NEGATIVE - should it fail or not
#PARAM_MULTI_TEST - used to distinguish "multi-tests", sort of left over from automake
#PARAM_NO_PROCESSOR - should the C preprocessor be disabled or not
#PARAM_INCLUDE_DIRS - list of include directory paths, relative to the test input directory
#Basically, the same test dir has multiple sets of facts / outputs
#We should just get rid of this and make multiple tests
#It also means we need to use slightly different naming for tests
Expand All @@ -144,7 +146,7 @@ function(SOUFFLE_RUN_TEST_HELPER)
PARAM
"COMPILED;FUNCTORS;NEGATIVE;MULTI_TEST;NO_PREPROCESSOR" # Options
"TEST_NAME;CATEGORY;FACTS_DIR_NAME;EXTRA_DATA" #Single valued options
""
"INCLUDE_DIRS" # Multi-valued options
${ARGV}
)

Expand Down Expand Up @@ -182,6 +184,13 @@ function(SOUFFLE_RUN_TEST_HELPER)
set(INPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${PARAM_TEST_NAME}")
set(FACTS_DIR "${INPUT_DIR}/${PARAM_FACTS_DIR_NAME}")

if (PARAM_INCLUDE_DIRS)
## generate -I include directory options
list(TRANSFORM PARAM_INCLUDE_DIRS PREPEND "${INPUT_DIR}/")
list(TRANSFORM PARAM_INCLUDE_DIRS PREPEND "-I")
list(APPEND EXTRA_FLAGS ${PARAM_INCLUDE_DIRS})
endif()

if (PARAM_MULTI_TEST)
set(DATA_CHECK_DIR "${INPUT_DIR}/${PARAM_FACTS_DIR_NAME}")
set(MT_EXTRA_SUFFIX "_${PARAM_FACTS_DIR_NAME}")
Expand Down
26 changes: 19 additions & 7 deletions src/parser/ParserDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,34 @@ void ParserDriver::error(const std::string& msg) {

std::optional<std::filesystem::path> ParserDriver::searchIncludePath(
const std::string& IncludeString, const SrcLocation& Loc) {
std::filesystem::path Candidate(IncludeString);
std::filesystem::path Request(IncludeString);

if (Candidate.is_absolute()) {
if (std::filesystem::exists(Candidate)) {
return std::filesystem::canonical(Candidate);
if (Request.is_absolute()) {
if (std::filesystem::exists(Request)) {
return std::filesystem::canonical(Request);
} else {
return std::nullopt;
}
}

// search relative from current input file
Candidate = std::filesystem::path(Loc.file->Physical).parent_path() / IncludeString;
std::filesystem::path Candidate = std::filesystem::path(Loc.file->Physical).parent_path() / Request;
if (std::filesystem::exists(Candidate)) {
return std::filesystem::canonical(Candidate);
} else if (Candidate.is_absolute()) {
return std::nullopt;
}

// search relative from include directories
for (auto&& includeDir : Global::config().getMany("include-dir")) {
auto dir = std::filesystem::path(includeDir);
if (dir.is_relative()) {
dir = (std::filesystem::current_path() / includeDir);
}
if (std::filesystem::exists(dir)) {
Candidate = std::filesystem::path(dir) / Request;
if (std::filesystem::exists(Candidate)) {
return std::filesystem::canonical(Candidate);
}
}
}

return std::nullopt;
Expand Down
6 changes: 6 additions & 0 deletions tests/syntactic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ souffle_run_test(
CATEGORY syntactic
NO_PREPROCESSOR
)
souffle_run_test(
TEST_NAME include_directive4
CATEGORY syntactic
INCLUDE_DIRS q1 q2
NO_PREPROCESSOR
)
3 changes: 3 additions & 0 deletions tests/syntactic/include_directive4/include_directive4.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

.include "q1.dl"
.include "q2.dl"
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions tests/syntactic/include_directive4/q1/q1.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.once
.decl q1(s:number)
q1(1).
1 change: 1 addition & 0 deletions tests/syntactic/include_directive4/q2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
4 changes: 4 additions & 0 deletions tests/syntactic/include_directive4/q2/q2.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.once
.decl q2(n:number)
.output q2
q2(n) :- q1(n).

0 comments on commit bec3083

Please sign in to comment.