aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-06-26 08:02:45 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-06-26 16:42:24 +0900
commit08808d3a778e6b4b653372b6d08dd4da96ebee27 (patch)
tree54764055bcb3ec63f236b272c72846636438d2ea
parent2bed770578c05fde7a05d2f11782bfd167abd43c (diff)
downloadkati-08808d3a778e6b4b653372b6d08dd4da96ebee27.tar.gz
[C++] Add -c flag
-rw-r--r--Makefile1
-rw-r--r--exec.cc21
-rw-r--r--flags.cc19
-rw-r--r--flags.h20
-rw-r--r--main.cc3
5 files changed, 55 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 1641884..eba8db2 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,7 @@ CXX_SRCS:= \
file.cc \
file_cache.cc \
fileutil.cc \
+ flags.cc \
func.cc \
main.cc \
parser.cc \
diff --git a/exec.cc b/exec.cc
index d46541f..bc4497f 100644
--- a/exec.cc
+++ b/exec.cc
@@ -28,6 +28,7 @@
#include "dep.h"
#include "eval.h"
#include "fileutil.h"
+#include "flags.h"
#include "log.h"
#include "string_piece.h"
#include "strutil.h"
@@ -160,15 +161,17 @@ class Executor {
printf("%s\n", runner->cmd->c_str());
fflush(stdout);
}
- int result = system(runner->cmd->c_str());
- if (result != 0) {
- if (runner->ignore_error) {
- fprintf(stderr, "[%.*s] Error %d (ignored)\n",
- SPF(runner->output), WEXITSTATUS(result));
- } else {
- fprintf(stderr, "*** [%.*s] Error %d\n",
- SPF(runner->output), WEXITSTATUS(result));
- exit(1);
+ if (!g_is_syntax_check_only) {
+ int result = system(runner->cmd->c_str());
+ if (result != 0) {
+ if (runner->ignore_error) {
+ fprintf(stderr, "[%.*s] Error %d (ignored)\n",
+ SPF(runner->output), WEXITSTATUS(result));
+ } else {
+ fprintf(stderr, "*** [%.*s] Error %d\n",
+ SPF(runner->output), WEXITSTATUS(result));
+ exit(1);
+ }
}
}
delete runner;
diff --git a/flags.cc b/flags.cc
new file mode 100644
index 0000000..0c611df
--- /dev/null
+++ b/flags.cc
@@ -0,0 +1,19 @@
+// Copyright 2015 Google Inc. All rights reserved
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// +build ignore
+
+#include "flags.h"
+
+bool g_is_syntax_check_only;
diff --git a/flags.h b/flags.h
new file mode 100644
index 0000000..570d6b1
--- /dev/null
+++ b/flags.h
@@ -0,0 +1,20 @@
+// Copyright 2015 Google Inc. All rights reserved
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef FLAGS_H_
+#define FLAGS_H_
+
+extern bool g_is_syntax_check_only;
+
+#endif // FLAGS_H_
diff --git a/main.cc b/main.cc
index a8a6f11..3bb9fe6 100644
--- a/main.cc
+++ b/main.cc
@@ -26,6 +26,7 @@
#include "file.h"
#include "file_cache.h"
#include "fileutil.h"
+#include "flags.h"
#include "func.h"
#include "log.h"
#include "parser.h"
@@ -43,6 +44,8 @@ static void ParseCommandLine(int argc, char* argv[],
const char* arg = argv[i];
if (!strcmp(arg, "-f")) {
g_makefile = argv[++i];
+ } else if (!strcmp(arg, "-c")) {
+ g_is_syntax_check_only = true;
} else if (arg[0] == '-') {
ERROR("Unknown flag: %s", arg);
} else {