From 8a08a44ffee70f71bdb7d8bee90e325dafbfeae4 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 7 Aug 2015 08:58:11 -0400 Subject: RunClang: Exit with error if compilation jobs fail to build If an error occurs during Driver::BuildCompilation then exit with an error code immediately. This is important when an input file is missing, for example. GitHub-Issue: 23 --- src/RunClang.cxx | 3 +++ test/CMakeLists.txt | 1 + test/expect/cmd.input-missing.result.txt | 1 + test/expect/cmd.input-missing.stderr.txt | 2 ++ test/expect/cmd.rsp-missing.result.txt | 1 + 5 files changed, 8 insertions(+) create mode 100644 test/expect/cmd.input-missing.result.txt create mode 100644 test/expect/cmd.input-missing.stderr.txt create mode 100644 test/expect/cmd.rsp-missing.result.txt diff --git a/src/RunClang.cxx b/src/RunClang.cxx index fd0f313..d902123 100644 --- a/src/RunClang.cxx +++ b/src/RunClang.cxx @@ -318,6 +318,9 @@ static int runClangImpl(const char* const* argBeg, // Ask the driver to build the compiler commands for us. std::unique_ptr c(d.BuildCompilation(cArgs)); + if (diags->hasErrorOccurred()) { + return 1; + } // For '-###' just print the jobs and exit early. if(c->getArgs().hasArg(clang::driver::options::OPT__HASH_HASH_HASH)) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a104cb9..f44680f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -126,6 +126,7 @@ castxml_test_cmd(gccxml-and-objc2 --castxml-gccxml ${empty_mm}) castxml_test_cmd(gccxml-empty-c++98 --castxml-gccxml -std=c++98 ${empty_cxx}) castxml_test_cmd(gccxml-empty-c++98-E --castxml-gccxml -std=c++98 ${empty_cxx} -E) castxml_test_cmd(gccxml-empty-c++98-c --castxml-gccxml -std=c++98 ${empty_cxx} -c) +castxml_test_cmd(input-missing ${input}/does-not-exist.c) castxml_test_cmd(o-missing -o) castxml_test_cmd(start-missing --castxml-start) castxml_test_cmd(rsp-empty @${input}/empty.rsp) diff --git a/test/expect/cmd.input-missing.result.txt b/test/expect/cmd.input-missing.result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/expect/cmd.input-missing.result.txt @@ -0,0 +1 @@ +1 diff --git a/test/expect/cmd.input-missing.stderr.txt b/test/expect/cmd.input-missing.stderr.txt new file mode 100644 index 0000000..f46a447 --- /dev/null +++ b/test/expect/cmd.input-missing.stderr.txt @@ -0,0 +1,2 @@ +^error: no such file or directory: '.*/test/input/does-not-exist.c' +error: no input files$ diff --git a/test/expect/cmd.rsp-missing.result.txt b/test/expect/cmd.rsp-missing.result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/expect/cmd.rsp-missing.result.txt @@ -0,0 +1 @@ +1 -- cgit v0.12