summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/windows.yml4
-rw-r--r--CMakeLists.txt6
-rw-r--r--doc/manual.asciidoc4
-rw-r--r--misc/ninja_syntax.py14
-rw-r--r--src/build.cc4
-rw-r--r--src/build_test.cc2
-rw-r--r--src/depfile_parser.cc87
-rw-r--r--src/depfile_parser.in.cc23
-rw-r--r--src/depfile_parser_test.cc35
-rw-r--r--src/deps_log.cc2
-rw-r--r--src/disk_interface.cc2
-rw-r--r--src/disk_interface_test.cc2
-rw-r--r--src/ninja.cc4
-rw-r--r--src/string_piece_util.cc2
-rw-r--r--src/subprocess-posix.cc7
15 files changed, 158 insertions, 40 deletions
diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml
index d961582..04fc2f6 100644
--- a/.github/workflows/windows.yml
+++ b/.github/workflows/windows.yml
@@ -23,8 +23,8 @@ jobs:
cmake --build build --parallel --config Release
- name: Test ninja
- run: ctest -vv
- working-directory: build
+ run: .\ninja_test.exe
+ working-directory: build/Release
- name: Create ninja archive
shell: bash
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 007c662..65e42a4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,9 +39,9 @@ if(RE2C)
COMMAND ${RE2C} -b -i --no-generation-date -o ${OUT} ${IN}
)
endfunction()
- re2c(${CMAKE_SOURCE_DIR}/src/depfile_parser.in.cc ${CMAKE_BINARY_DIR}/depfile_parser.cc)
- re2c(${CMAKE_SOURCE_DIR}/src/lexer.in.cc ${CMAKE_BINARY_DIR}/lexer.cc)
- add_library(libninja-re2c OBJECT ${CMAKE_BINARY_DIR}/depfile_parser.cc ${CMAKE_BINARY_DIR}/lexer.cc)
+ re2c(${PROJECT_SOURCE_DIR}/src/depfile_parser.in.cc ${PROJECT_BINARY_DIR}/depfile_parser.cc)
+ re2c(${PROJECT_SOURCE_DIR}/src/lexer.in.cc ${PROJECT_BINARY_DIR}/lexer.cc)
+ add_library(libninja-re2c OBJECT ${PROJECT_BINARY_DIR}/depfile_parser.cc ${PROJECT_BINARY_DIR}/lexer.cc)
else()
message(WARNING "re2c was not found; changes to src/*.in.cc will not affect your build.")
add_library(libninja-re2c OBJECT src/depfile_parser.cc src/lexer.cc)
diff --git a/doc/manual.asciidoc b/doc/manual.asciidoc
index 9976ce4..e1ae083 100644
--- a/doc/manual.asciidoc
+++ b/doc/manual.asciidoc
@@ -899,7 +899,7 @@ set environment variables.
On Windows, commands are strings, so Ninja passes the `command` string
directly to `CreateProcess`. (In the common case of simply executing
a compiler this means there is less overhead.) Consequently the
-quoting rules are deterimined by the called program, which on Windows
+quoting rules are determined by the called program, which on Windows
are usually provided by the C library. If you need shell
interpretation of the command (such as the use of `&&` to chain
multiple commands), make the command execute the Windows shell by
@@ -935,7 +935,7 @@ There are three types of build dependencies which are subtly different.
1. _Explicit dependencies_, as listed in a build line. These are
available as the `$in` variable in the rule. Changes in these files
- cause the output to be rebuilt; if these file are missing and
+ cause the output to be rebuilt; if these files are missing and
Ninja doesn't know how to build them, the build is aborted.
+
This is the standard form of dependency to be used e.g. for the
diff --git a/misc/ninja_syntax.py b/misc/ninja_syntax.py
index ebe6490..ab5c0d4 100644
--- a/misc/ninja_syntax.py
+++ b/misc/ninja_syntax.py
@@ -1,5 +1,19 @@
#!/usr/bin/python
+# Copyright 2011 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.
+
"""Python module for generating .ninja files.
Note that this is emphatically not a required piece of Ninja; it's
diff --git a/src/build.cc b/src/build.cc
index cd8df4e..db28e65 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -183,7 +183,7 @@ void BuildStatus::BuildLoadDyndeps() {
// it considers a portion of the graph to be out of date. Normally
// this is done before the build starts, but our caller is about to
// load a dyndep file during the build. Doing so may generate more
- // exlanation lines (via fprintf directly to stderr), but in an
+ // explanation lines (via fprintf directly to stderr), but in an
// interactive console the cursor is currently at the end of a status
// line. Start a new line so that the first explanation does not
// append to the status line. After the explanations are done a
@@ -1033,7 +1033,7 @@ bool Builder::FinishCommand(CommandRunner::Result* result, string* err) {
}
if (!deps_type.empty() && !config_.dry_run) {
- assert(edge->outputs_.size() >= 1 && "should have been rejected by parser");
+ assert(!edge->outputs_.empty() && "should have been rejected by parser");
for (std::vector<Node*>::const_iterator o = edge->outputs_.begin();
o != edge->outputs_.end(); ++o) {
TimeStamp deps_mtime = disk_interface_->Stat((*o)->path(), err);
diff --git a/src/build_test.cc b/src/build_test.cc
index 426e825..12c3383 100644
--- a/src/build_test.cc
+++ b/src/build_test.cc
@@ -672,7 +672,7 @@ bool FakeCommandRunner::WaitForCommand(Result* result) {
bool verify_active_edge_found = false;
for (vector<Edge*>::iterator i = active_edges_.begin();
i != active_edges_.end(); ++i) {
- if ((*i)->outputs_.size() >= 1 &&
+ if (!(*i)->outputs_.empty() &&
(*i)->outputs_[0]->path() == verify_active_edge) {
verify_active_edge_found = true;
}
diff --git a/src/depfile_parser.cc b/src/depfile_parser.cc
index 90d4a8a..0b7dce1 100644
--- a/src/depfile_parser.cc
+++ b/src/depfile_parser.cc
@@ -1,4 +1,4 @@
-/* Generated by re2c 1.1.1 */
+/* Generated by re2c 1.3 */
// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -166,22 +166,23 @@ yy12:
goto yy5;
yy13:
yych = *(yymarker = ++in);
- if (yych <= 0x1F) {
+ if (yych <= ' ') {
if (yych <= '\n') {
if (yych <= 0x00) goto yy5;
if (yych <= '\t') goto yy16;
goto yy17;
} else {
if (yych == '\r') goto yy19;
- goto yy16;
+ if (yych <= 0x1F) goto yy16;
+ goto yy21;
}
} else {
- if (yych <= '#') {
- if (yych <= ' ') goto yy21;
- if (yych <= '"') goto yy16;
- goto yy23;
+ if (yych <= '9') {
+ if (yych == '#') goto yy23;
+ goto yy16;
} else {
- if (yych == '\\') goto yy25;
+ if (yych <= ':') goto yy25;
+ if (yych == '\\') goto yy27;
goto yy16;
}
}
@@ -231,26 +232,63 @@ yy23:
}
yy25:
yych = *++in;
- if (yych <= 0x1F) {
+ if (yych <= '\f') {
+ if (yych <= 0x00) goto yy28;
+ if (yych <= 0x08) goto yy26;
+ if (yych <= '\n') goto yy28;
+ } else {
+ if (yych <= '\r') goto yy28;
+ if (yych == ' ') goto yy28;
+ }
+yy26:
+ {
+ // De-escape colon sign, but preserve other leading backslashes.
+ // Regular expression uses lookahead to make sure that no whitespace
+ // nor EOF follows. In that case it'd be the : at the end of a target
+ int len = (int)(in - start);
+ if (len > 2 && out < start)
+ memset(out, '\\', len - 2);
+ out += len - 2;
+ *out++ = ':';
+ continue;
+ }
+yy27:
+ yych = *++in;
+ if (yych <= ' ') {
if (yych <= '\n') {
if (yych <= 0x00) goto yy11;
if (yych <= '\t') goto yy16;
goto yy11;
} else {
if (yych == '\r') goto yy11;
- goto yy16;
+ if (yych <= 0x1F) goto yy16;
+ goto yy30;
}
} else {
- if (yych <= '#') {
- if (yych <= ' ') goto yy26;
- if (yych <= '"') goto yy16;
- goto yy23;
+ if (yych <= '9') {
+ if (yych == '#') goto yy23;
+ goto yy16;
} else {
- if (yych == '\\') goto yy28;
+ if (yych <= ':') goto yy25;
+ if (yych == '\\') goto yy32;
goto yy16;
}
}
-yy26:
+yy28:
+ ++in;
+ {
+ // Backslash followed by : and whitespace.
+ // It is therefore normal text and not an escaped colon
+ int len = (int)(in - start - 1);
+ // Need to shift it over if we're overwriting backslashes.
+ if (out < start)
+ memmove(out, start, len);
+ out += len;
+ if (*(in - 1) == '\n')
+ have_newline = true;
+ break;
+ }
+yy30:
++in;
{
// 2N backslashes plus space -> 2N backslashes, end of filename.
@@ -260,24 +298,25 @@ yy26:
out += len - 1;
break;
}
-yy28:
+yy32:
yych = *++in;
- if (yych <= 0x1F) {
+ if (yych <= ' ') {
if (yych <= '\n') {
if (yych <= 0x00) goto yy11;
if (yych <= '\t') goto yy16;
goto yy11;
} else {
if (yych == '\r') goto yy11;
- goto yy16;
+ if (yych <= 0x1F) goto yy16;
+ goto yy21;
}
} else {
- if (yych <= '#') {
- if (yych <= ' ') goto yy21;
- if (yych <= '"') goto yy16;
- goto yy23;
+ if (yych <= '9') {
+ if (yych == '#') goto yy23;
+ goto yy16;
} else {
- if (yych == '\\') goto yy25;
+ if (yych <= ':') goto yy25;
+ if (yych == '\\') goto yy27;
goto yy16;
}
}
diff --git a/src/depfile_parser.in.cc b/src/depfile_parser.in.cc
index b32b942..95b4346 100644
--- a/src/depfile_parser.in.cc
+++ b/src/depfile_parser.in.cc
@@ -103,6 +103,29 @@ bool DepfileParser::Parse(string* content, string* err) {
*out++ = '#';
continue;
}
+ '\\'+ ':' [\x00\x20\r\n\t] {
+ // Backslash followed by : and whitespace.
+ // It is therefore normal text and not an escaped colon
+ int len = (int)(in - start - 1);
+ // Need to shift it over if we're overwriting backslashes.
+ if (out < start)
+ memmove(out, start, len);
+ out += len;
+ if (*(in - 1) == '\n')
+ have_newline = true;
+ break;
+ }
+ '\\'+ ':' {
+ // De-escape colon sign, but preserve other leading backslashes.
+ // Regular expression uses lookahead to make sure that no whitespace
+ // nor EOF follows. In that case it'd be the : at the end of a target
+ int len = (int)(in - start);
+ if (len > 2 && out < start)
+ memset(out, '\\', len - 2);
+ out += len - 2;
+ *out++ = ':';
+ continue;
+ }
'$$' {
// De-escape dollar character.
*out++ = '$';
diff --git a/src/depfile_parser_test.cc b/src/depfile_parser_test.cc
index bf1a0bc..8e2cd25 100644
--- a/src/depfile_parser_test.cc
+++ b/src/depfile_parser_test.cc
@@ -142,6 +142,41 @@ TEST_F(DepfileParserTest, Escapes) {
ASSERT_EQ(0u, parser_.ins_.size());
}
+TEST_F(DepfileParserTest, EscapedColons)
+{
+ std::string err;
+ // Tests for correct parsing of depfiles produced on Windows
+ // by both Clang, GCC pre 10 and GCC 10
+ EXPECT_TRUE(Parse(
+"c\\:\\gcc\\x86_64-w64-mingw32\\include\\stddef.o: \\\n"
+" c:\\gcc\\x86_64-w64-mingw32\\include\\stddef.h \n",
+ &err));
+ ASSERT_EQ("", err);
+ ASSERT_EQ(1u, parser_.outs_.size());
+ EXPECT_EQ("c:\\gcc\\x86_64-w64-mingw32\\include\\stddef.o",
+ parser_.outs_[0].AsString());
+ ASSERT_EQ(1u, parser_.ins_.size());
+ EXPECT_EQ("c:\\gcc\\x86_64-w64-mingw32\\include\\stddef.h",
+ parser_.ins_[0].AsString());
+}
+
+TEST_F(DepfileParserTest, EscapedTargetColon)
+{
+ std::string err;
+ EXPECT_TRUE(Parse(
+"foo1\\: x\n"
+"foo1\\:\n"
+"foo1\\:\r\n"
+"foo1\\:\t\n"
+"foo1\\:",
+ &err));
+ ASSERT_EQ("", err);
+ ASSERT_EQ(1u, parser_.outs_.size());
+ EXPECT_EQ("foo1\\", parser_.outs_[0].AsString());
+ ASSERT_EQ(1u, parser_.ins_.size());
+ EXPECT_EQ("x", parser_.ins_[0].AsString());
+}
+
TEST_F(DepfileParserTest, SpecialChars) {
// See filenames like istreambuf.iterator_op!= in
// https://github.com/google/libcxx/tree/master/test/iterators/stream.iterators/istreambuf.iterator/
diff --git a/src/deps_log.cc b/src/deps_log.cc
index db8f071..1fb65ae 100644
--- a/src/deps_log.cc
+++ b/src/deps_log.cc
@@ -383,7 +383,7 @@ bool DepsLog::RecordId(Node* node) {
if (fwrite(&size, 4, 1, file_) < 1)
return false;
if (fwrite(node->path().data(), path_size, 1, file_) < 1) {
- assert(node->path().size() > 0);
+ assert(!node->path().empty());
return false;
}
if (padding && fwrite("\0\0", padding, 1, file_) < 1)
diff --git a/src/disk_interface.cc b/src/disk_interface.cc
index dc297c4..594bc51 100644
--- a/src/disk_interface.cc
+++ b/src/disk_interface.cc
@@ -26,6 +26,8 @@
#include <sstream>
#include <windows.h>
#include <direct.h> // _mkdir
+#else
+#include <unistd.h>
#endif
#include "metrics.h"
diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc
index bac515d..866d1d6 100644
--- a/src/disk_interface_test.cc
+++ b/src/disk_interface_test.cc
@@ -190,7 +190,7 @@ TEST_F(DiskInterfaceTest, ReadFile) {
TEST_F(DiskInterfaceTest, MakeDirs) {
string path = "path/with/double//slash/";
- EXPECT_TRUE(disk_.MakeDirs(path.c_str()));
+ EXPECT_TRUE(disk_.MakeDirs(path));
FILE* f = fopen((path + "a_file").c_str(), "w");
EXPECT_TRUE(f);
EXPECT_EQ(0, fclose(f));
diff --git a/src/ninja.cc b/src/ninja.cc
index 1429639..00e3a5c 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -91,7 +91,7 @@ struct NinjaMain : public BuildLogUser {
/// Loaded state (rules, nodes).
State state_;
- /// Functions for accesssing the disk.
+ /// Functions for accessing the disk.
RealDiskInterface disk_interface_;
/// The build directory, used for storing the build log etc.
@@ -1050,7 +1050,7 @@ bool DebugEnable(const string& name) {
}
}
-/// Set a warning flag. Returns false if Ninja should exit instead of
+/// Set a warning flag. Returns false if Ninja should exit instead of
/// continuing.
bool WarningEnable(const string& name, Options* options) {
if (name == "list") {
diff --git a/src/string_piece_util.cc b/src/string_piece_util.cc
index 8e1ecfd..69513f5 100644
--- a/src/string_piece_util.cc
+++ b/src/string_piece_util.cc
@@ -39,7 +39,7 @@ vector<StringPiece> SplitStringPiece(StringPiece input, char sep) {
}
string JoinStringPiece(const vector<StringPiece>& list, char sep) {
- if (list.size() == 0){
+ if (list.empty()) {
return "";
}
diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc
index fc5543e..74785d1 100644
--- a/src/subprocess-posix.cc
+++ b/src/subprocess-posix.cc
@@ -18,13 +18,18 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
-#include <poll.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <spawn.h>
+#if defined(USE_PPOLL)
+#include <poll.h>
+#else
+#include <sys/select.h>
+#endif
+
extern char** environ;
#include "util.h"