Skip to content

Commit 2e8dddc

Browse files
author
Bernhard Scholz
authored
Merge pull request #2276 from quentin/includedirs
`.include` honors `-I` (include dir) options
2 parents ba5313f + bec3083 commit 2e8dddc

File tree

9 files changed

+46
-8
lines changed

9 files changed

+46
-8
lines changed

cmake/SouffleTests.cmake

+10-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ function(SOUFFLE_RUN_TEST_HELPER)
134134
#PARAM_FUNCTORS - with -L for finding functor library in the testsuite
135135
#PARAM_NEGATIVE - should it fail or not
136136
#PARAM_MULTI_TEST - used to distinguish "multi-tests", sort of left over from automake
137+
#PARAM_NO_PROCESSOR - should the C preprocessor be disabled or not
138+
#PARAM_INCLUDE_DIRS - list of include directory paths, relative to the test input directory
137139
#Basically, the same test dir has multiple sets of facts / outputs
138140
#We should just get rid of this and make multiple tests
139141
#It also means we need to use slightly different naming for tests
@@ -144,7 +146,7 @@ function(SOUFFLE_RUN_TEST_HELPER)
144146
PARAM
145147
"COMPILED;FUNCTORS;NEGATIVE;MULTI_TEST;NO_PREPROCESSOR" # Options
146148
"TEST_NAME;CATEGORY;FACTS_DIR_NAME;EXTRA_DATA" #Single valued options
147-
""
149+
"INCLUDE_DIRS" # Multi-valued options
148150
${ARGV}
149151
)
150152

@@ -182,6 +184,13 @@ function(SOUFFLE_RUN_TEST_HELPER)
182184
set(INPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${PARAM_TEST_NAME}")
183185
set(FACTS_DIR "${INPUT_DIR}/${PARAM_FACTS_DIR_NAME}")
184186

187+
if (PARAM_INCLUDE_DIRS)
188+
## generate -I include directory options
189+
list(TRANSFORM PARAM_INCLUDE_DIRS PREPEND "${INPUT_DIR}/")
190+
list(TRANSFORM PARAM_INCLUDE_DIRS PREPEND "-I")
191+
list(APPEND EXTRA_FLAGS ${PARAM_INCLUDE_DIRS})
192+
endif()
193+
185194
if (PARAM_MULTI_TEST)
186195
set(DATA_CHECK_DIR "${INPUT_DIR}/${PARAM_FACTS_DIR_NAME}")
187196
set(MT_EXTRA_SUFFIX "_${PARAM_FACTS_DIR_NAME}")

src/parser/ParserDriver.cpp

+19-7
Original file line numberDiff line numberDiff line change
@@ -262,22 +262,34 @@ void ParserDriver::error(const std::string& msg) {
262262

263263
std::optional<std::filesystem::path> ParserDriver::searchIncludePath(
264264
const std::string& IncludeString, const SrcLocation& Loc) {
265-
std::filesystem::path Candidate(IncludeString);
265+
std::filesystem::path Request(IncludeString);
266266

267-
if (Candidate.is_absolute()) {
268-
if (std::filesystem::exists(Candidate)) {
269-
return std::filesystem::canonical(Candidate);
267+
if (Request.is_absolute()) {
268+
if (std::filesystem::exists(Request)) {
269+
return std::filesystem::canonical(Request);
270270
} else {
271271
return std::nullopt;
272272
}
273273
}
274274

275275
// search relative from current input file
276-
Candidate = std::filesystem::path(Loc.file->Physical).parent_path() / IncludeString;
276+
std::filesystem::path Candidate = std::filesystem::path(Loc.file->Physical).parent_path() / Request;
277277
if (std::filesystem::exists(Candidate)) {
278278
return std::filesystem::canonical(Candidate);
279-
} else if (Candidate.is_absolute()) {
280-
return std::nullopt;
279+
}
280+
281+
// search relative from include directories
282+
for (auto&& includeDir : Global::config().getMany("include-dir")) {
283+
auto dir = std::filesystem::path(includeDir);
284+
if (dir.is_relative()) {
285+
dir = (std::filesystem::current_path() / includeDir);
286+
}
287+
if (std::filesystem::exists(dir)) {
288+
Candidate = std::filesystem::path(dir) / Request;
289+
if (std::filesystem::exists(Candidate)) {
290+
return std::filesystem::canonical(Candidate);
291+
}
292+
}
281293
}
282294

283295
return std::nullopt;

tests/syntactic/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,9 @@ souffle_run_test(
8585
CATEGORY syntactic
8686
NO_PREPROCESSOR
8787
)
88+
souffle_run_test(
89+
TEST_NAME include_directive4
90+
CATEGORY syntactic
91+
INCLUDE_DIRS q1 q2
92+
NO_PREPROCESSOR
93+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
.include "q1.dl"
3+
.include "q2.dl"

tests/syntactic/include_directive4/include_directive4.err

Whitespace-only changes.

tests/syntactic/include_directive4/include_directive4.out

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.once
2+
.decl q1(s:number)
3+
q1(1).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.once
2+
.decl q2(n:number)
3+
.output q2
4+
q2(n) :- q1(n).

0 commit comments

Comments
 (0)