Skip to content

Commit

Permalink
Make -D- option for compiled datalog behave same as if interpreted
Browse files Browse the repository at this point in the history
Fixes  #2348
  • Loading branch information
Gueckmooh authored Feb 27, 2023
1 parent 8aae521 commit 63a5996
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
8 changes: 6 additions & 2 deletions cmake/SouffleTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function(SOUFFLE_RUN_TEST_HELPER)
#Usually just "facts" but can be different when running multi - tests
cmake_parse_arguments(
PARAM
"COMPILED;COMPILED_SPLITTED;FUNCTORS;NEGATIVE;MULTI_TEST;NO_PREPROCESSOR" # Options
"COMPILED;COMPILED_SPLITTED;FUNCTORS;NEGATIVE;MULTI_TEST;NO_PREPROCESSOR;OUTPUT_STDOUT" # Options
"TEST_NAME;CATEGORY;FACTS_DIR_NAME;EXTRA_DATA" #Single valued options
"INCLUDE_DIRS" # Multi-valued options
${ARGV}
Expand Down Expand Up @@ -226,7 +226,11 @@ function(SOUFFLE_RUN_TEST_HELPER)
FIXTURE_NAME ${FIXTURE_NAME}
TEST_LABELS ${TEST_LABELS})

set(SOUFFLE_PARAMS "-D" "." "-F" "${FACTS_DIR}")
if(PARAM_OUTPUT_STDOUT)
set(SOUFFLE_PARAMS "-D-" "-F" "${FACTS_DIR}")
else()
set(SOUFFLE_PARAMS "-D" "." "-F" "${FACTS_DIR}")
endif()
list(PREPEND SOUFFLE_PARAMS ${EXTRA_FLAGS})

if (OPENMP_FOUND)
Expand Down
9 changes: 8 additions & 1 deletion src/include/souffle/CompiledOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class CmdOptions {
break;
/* Output directory for resulting .csv files */
case 'D':
if (*optarg && !existDir(optarg)) {
if (*optarg && !existDir(optarg) && !dirIsStdout(optarg)) {
printf("Output directory %s does not exists!\n", optarg);
ok = false;
}
Expand Down Expand Up @@ -258,6 +258,13 @@ class CmdOptions {
}
return false;
}

/**
* Check whether the output is "-", for which the output should be stdout
*/
bool dirIsStdout(const std::string& name) const {
return name == "-";
}
};

} // end of namespace souffle
5 changes: 4 additions & 1 deletion src/synthesiser/Synthesiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,10 @@ void Synthesiser::emitCode(std::ostream& out, const Statement& stmt) {
out << "std::map<std::string, std::string> directiveMap(";
printDirectives(directives);
out << ");\n";
out << R"_(if (!outputDirectory.empty()) {)_";
out << R"_(if (outputDirectory == "-"){)_";
out << R"_(directiveMap["IO"] = "stdout"; directiveMap["headers"] = "true";)_";
out << "}\n";
out << R"_(else if (!outputDirectory.empty()) {)_";
out << R"_(directiveMap["output-dir"] = outputDirectory;)_";
out << "}\n";
out << "IOSystem::getInstance().getWriter(";
Expand Down
8 changes: 7 additions & 1 deletion tests/semantic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ function(positive_test NAME)
souffle_positive_test(${NAME} semantic ${ARGN})
endfunction()

function(positive_output_stdout_test NAME)
souffle_run_test_helper(TEST_NAME ${NAME} CATEGORY semantic OUTPUT_STDOUT ${ARGV})
souffle_run_test_helper(TEST_NAME ${NAME} CATEGORY semantic OUTPUT_STDOUT ${ARGV} COMPILED)
endfunction()

function(negative_test NAME)
souffle_negative_test(${NAME} semantic)
endfunction()
Expand Down Expand Up @@ -259,4 +264,5 @@ positive_test(underscore5)
negative_test(mutually_dependent_aggregate)
positive_test(independent_aggregate)
positive_test(independent_aggregate2)
souffle_positive_functor_test(issue2373 CATEGORY semantic)
souffle_positive_functor_test(issue2373 CATEGORY semantic)
positive_output_stdout_test(output_stdout)
9 changes: 9 additions & 0 deletions tests/semantic/output_stdout/output_stdout.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Souffle - A Datalog Compiler
// Copyright (c) 2023, The Souffle Developers. All rights reserved
// Licensed under the Universal Permissive License v 1.0 as shown at:
// - https://opensource.org/licenses/UPL
// - <souffle root>/licenses/SOUFFLE-UPL.txt

.decl foo(a: symbol)
.output foo
foo("bar").
Empty file.
6 changes: 6 additions & 0 deletions tests/semantic/output_stdout/output_stdout.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---------------
foo
a
===============
bar
===============

0 comments on commit 63a5996

Please sign in to comment.