Re-arrange depfile parser token processing logic
Re-arrange the existing logic to support later addition of post-token
code even for empty tokens.
diff --git a/src/depfile_parser.cc b/src/depfile_parser.cc
index 24e374f..2ad2a00 100644
--- a/src/depfile_parser.cc
+++ b/src/depfile_parser.cc
@@ -175,22 +175,21 @@
}
int len = (int)(out - filename);
- const bool is_target = parsing_targets;
+ const bool is_dependency = !parsing_targets;
if (len > 0 && filename[len - 1] == ':') {
len--; // Strip off trailing colon, if any.
parsing_targets = false;
}
- if (len == 0)
- continue;
-
- if (!is_target) {
- ins_.push_back(StringPiece(filename, len));
- } else if (!out_.str_) {
- out_ = StringPiece(filename, len);
- } else if (out_ != StringPiece(filename, len)) {
- *err = "depfile has multiple output paths";
- return false;
+ if (len > 0) {
+ if (is_dependency) {
+ ins_.push_back(StringPiece(filename, len));
+ } else if (!out_.str_) {
+ out_ = StringPiece(filename, len);
+ } else if (out_ != StringPiece(filename, len)) {
+ *err = "depfile has multiple output paths";
+ return false;
+ }
}
}
if (parsing_targets) {
diff --git a/src/depfile_parser.in.cc b/src/depfile_parser.in.cc
index 464efda..4df8ce2 100644
--- a/src/depfile_parser.in.cc
+++ b/src/depfile_parser.in.cc
@@ -94,22 +94,21 @@
}
int len = (int)(out - filename);
- const bool is_target = parsing_targets;
+ const bool is_dependency = !parsing_targets;
if (len > 0 && filename[len - 1] == ':') {
len--; // Strip off trailing colon, if any.
parsing_targets = false;
}
- if (len == 0)
- continue;
-
- if (!is_target) {
- ins_.push_back(StringPiece(filename, len));
- } else if (!out_.str_) {
- out_ = StringPiece(filename, len);
- } else if (out_ != StringPiece(filename, len)) {
- *err = "depfile has multiple output paths";
- return false;
+ if (len > 0) {
+ if (is_dependency) {
+ ins_.push_back(StringPiece(filename, len));
+ } else if (!out_.str_) {
+ out_ = StringPiece(filename, len);
+ } else if (out_ != StringPiece(filename, len)) {
+ *err = "depfile has multiple output paths";
+ return false;
+ }
}
}
if (parsing_targets) {