From 281618a81b8b00cff7c7b71e9fc7c5077b70de95 Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Fri, 24 Apr 2020 12:59:51 +0200 Subject: GitHub Actions: Also run on Ubuntu 18.04 Builds with both GCC and Clang and runs clang-tidy, too. --- .clang-tidy | 9 +++++++++ .github/workflows/linux.yml | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..0b453ba --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,9 @@ +--- +Checks: ' + ,readability-avoid-const-params-in-decls, + ,readability-non-const-parameter, +' +WarningsAsErrors: ' + ,readability-avoid-const-params-in-decls, + ,readability-non-const-parameter, +' diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 71cd06e..20878ba 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -57,3 +57,36 @@ jobs: asset_path: ./artifact/ninja-linux.zip asset_name: ninja-linux.zip asset_content_type: application/zip + + test: + runs-on: [ubuntu-18.04] + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y python3-pytest ninja-build clang-tidy-9 + pip install cmake==3.17.* + - name: Configure (GCC) + run: cmake -Bbuild-gcc -DCMAKE_BUILD_TYPE=Debug -GNinja + - name: Build (GCC) + run: ninja + working-directory: build-gcc + - name: Unit tests (GCC) + run: ./build-gcc/ninja_test + - name: Python tests (GCC) + run: pytest-3 --color=yes .. + working-directory: build-gcc + - name: Configure (Clang) + run: CC=clang-9 CXX=clang++-9 cmake -Bbuild-clang -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + - name: Build (Clang) + run: ninja + working-directory: build-clang + - name: Unit tests (Clang) + run: ./build-clang/ninja_test + - name: Python tests (Clang) + run: pytest-3 --color=yes .. + working-directory: build-clang + - name: clang-tidy + run: /usr/lib/llvm-9/share/clang/run-clang-tidy.py -header-filter=src + working-directory: build-clang -- cgit v0.12 From 2127dab42c92b39d87d99f5b24e880fb61c1278f Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Mon, 18 May 2020 18:30:42 +0200 Subject: GitHub Actions: Build and test both Debug and Release configs --- .github/workflows/linux.yml | 55 ++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 20878ba..5bfd3af 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -67,26 +67,45 @@ jobs: sudo apt update sudo apt install -y python3-pytest ninja-build clang-tidy-9 pip install cmake==3.17.* + - name: Configure (GCC) - run: cmake -Bbuild-gcc -DCMAKE_BUILD_TYPE=Debug -GNinja - - name: Build (GCC) - run: ninja - working-directory: build-gcc - - name: Unit tests (GCC) - run: ./build-gcc/ninja_test - - name: Python tests (GCC) - run: pytest-3 --color=yes .. - working-directory: build-gcc + run: cmake -Bbuild-gcc -DCMAKE_BUILD_TYPE=Debug -G'Ninja Multi-Config' + + - name: Build (GCC, Debug) + run: cmake --build build-gcc --config Debug + - name: Unit tests (GCC, Debug) + run: ./build-gcc/Debug/ninja_test + - name: Python tests (GCC, Debug) + run: pytest-3 --color=yes ../.. + working-directory: build-gcc/Debug + + - name: Build (GCC, Release) + run: cmake --build build-gcc --config Release + - name: Unit tests (GCC, Release) + run: ./build-gcc/Release/ninja_test + - name: Python tests (GCC, Release) + run: pytest-3 --color=yes ../.. + working-directory: build-gcc/Release + - name: Configure (Clang) - run: CC=clang-9 CXX=clang++-9 cmake -Bbuild-clang -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=1 - - name: Build (Clang) - run: ninja - working-directory: build-clang - - name: Unit tests (Clang) - run: ./build-clang/ninja_test - - name: Python tests (Clang) - run: pytest-3 --color=yes .. - working-directory: build-clang + run: CC=clang-9 CXX=clang++-9 cmake -Bbuild-clang -DCMAKE_BUILD_TYPE=Debug -G'Ninja Multi-Config' -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + + - name: Build (Clang, Debug) + run: cmake --build build-clang --config Debug + - name: Unit tests (Clang, Debug) + run: ./build-clang/Debug/ninja_test + - name: Python tests (Clang, Debug) + run: pytest-3 --color=yes ../.. + working-directory: build-clang/Debug + + - name: Build (Clang, Release) + run: cmake --build build-clang --config Release + - name: Unit tests (Clang, Release) + run: ./build-clang/Release/ninja_test + - name: Python tests (Clang, Release) + run: pytest-3 --color=yes ../.. + working-directory: build-clang/Release + - name: clang-tidy run: /usr/lib/llvm-9/share/clang/run-clang-tidy.py -header-filter=src working-directory: build-clang -- cgit v0.12 From aa6c4d88bddbb998a652f7ba8292ada660240f64 Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Thu, 4 Jun 2020 13:41:58 +0200 Subject: Add more clang-tidy checks --- .clang-tidy | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index 0b453ba..2afce32 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,8 +2,12 @@ Checks: ' ,readability-avoid-const-params-in-decls, ,readability-non-const-parameter, + ,readability-container-size-empty, + ,readability-redundant-string-cstr, ' WarningsAsErrors: ' ,readability-avoid-const-params-in-decls, ,readability-non-const-parameter, + ,readability-container-size-empty, + ,readability-redundant-string-cstr, ' -- cgit v0.12 From 7e678b5d4d35bb497d42860c089bcf9468942bcc Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 2 Jun 2020 18:05:38 -0700 Subject: [clang-tidy] remove redundant member init Found with readability-redundant-member-init Signed-off-by: Rosen Penev --- src/build.cc | 9 +++------ src/clean.cc | 2 -- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/build.cc b/src/build.cc index a16593b..a32bdda 100644 --- a/src/build.cc +++ b/src/build.cc @@ -77,12 +77,9 @@ bool DryRunCommandRunner::WaitForCommand(Result* result) { } // namespace BuildStatus::BuildStatus(const BuildConfig& config) - : config_(config), - start_time_millis_(GetTimeMillis()), - started_edges_(0), finished_edges_(0), total_edges_(0), - progress_status_format_(NULL), - overall_rate_(), current_rate_(config.parallelism) { - + : config_(config), start_time_millis_(GetTimeMillis()), started_edges_(0), + finished_edges_(0), total_edges_(0), progress_status_format_(NULL), + current_rate_(config.parallelism) { // Don't do anything fancy in verbose mode. if (config_.verbosity != BuildConfig::NORMAL) printer_.set_smart_terminal(false); diff --git a/src/clean.cc b/src/clean.cc index ec6e7d7..55d7277 100644 --- a/src/clean.cc +++ b/src/clean.cc @@ -28,8 +28,6 @@ Cleaner::Cleaner(State* state, : state_(state), config_(config), dyndep_loader_(state, disk_interface), - removed_(), - cleaned_(), cleaned_files_count_(0), disk_interface_(disk_interface), status_(0) { -- cgit v0.12 From 0ab46c5918b7fdcbd0846f4c6284646015accd64 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 2 Jun 2020 18:28:20 -0700 Subject: [clang-tidy] fix small false positive else if has to be on the same line it seems. Found with readability-misleading-indentation Signed-off-by: Rosen Penev --- src/build.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/build.cc b/src/build.cc index a16593b..ecb35a4 100644 --- a/src/build.cc +++ b/src/build.cc @@ -1067,8 +1067,7 @@ bool Builder::ExtractDeps(CommandRunner::Result* result, // complexity in IncludesNormalize::Relativize. deps_nodes->push_back(state_->GetNode(*i, ~0u)); } - } else - if (deps_type == "gcc") { + } else if (deps_type == "gcc") { string depfile = result->edge->GetUnescapedDepfile(); if (depfile.empty()) { *err = string("edge with deps=gcc but no depfile makes no sense"); -- cgit v0.12 From 6c5fc1d4ec2cbe32b5e617895da433ee6e974ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Le=C5=9Bniak?= Date: Sat, 1 Aug 2020 17:04:14 +0200 Subject: Use c++ instead of g++ `configure.py` assumes `g++` is present on the system, which is not the case, e.g. for FreeBSD. `c++` should be used insted, which should be a link to system c++ compiler. This will be `g++` for linux, but `clang++` for FreeBSD. --- configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.py b/configure.py index 8eef7e6..48c4821 100755 --- a/configure.py +++ b/configure.py @@ -269,7 +269,7 @@ if configure_env: n.variable('configure_env', config_str + '$ ') n.newline() -CXX = configure_env.get('CXX', 'g++') +CXX = configure_env.get('CXX', 'c++') objext = '.o' if platform.is_msvc(): CXX = 'cl' -- cgit v0.12 From b0b26cc9c43eb6a3ba728a8bfbcbceeb6dfcab20 Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Wed, 26 Aug 2020 12:07:25 +0200 Subject: Close BuildLog while running generators, fix #1724 While #1780 delayed opening .ninja_log until the first write, this this didn't fully fix the issue on Windows: There might be build statements which run before the generator resulting in an actual write to .ninja_log. To fix this once and for all the BuildLog now gets closed before running the generator. BuildLog::log_file_path_ won't be cleared so that it can be opened again after the generator finished. --- src/build.cc | 4 ++++ src/build_log.cc | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/build.cc b/src/build.cc index db28e65..5b7c8d6 100644 --- a/src/build.cc +++ b/src/build.cc @@ -829,6 +829,10 @@ bool Builder::Build(string* err) { // See if we can start any more commands. if (failures_allowed && command_runner_->CanRunMore()) { if (Edge* edge = plan_.FindWork()) { + if (edge->GetBindingBool("generator")) { + scan_.build_log()->Close(); + } + if (!StartEdge(edge, err)) { Cleanup(); status_->BuildFinished(); diff --git a/src/build_log.cc b/src/build_log.cc index e5f179c..c261b20 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -181,7 +181,7 @@ void BuildLog::Close() { } bool BuildLog::OpenForWriteIfNeeded() { - if (log_file_path_.empty()) { + if (log_file_ || log_file_path_.empty()) { return true; } log_file_ = fopen(log_file_path_.c_str(), "ab"); @@ -200,7 +200,6 @@ bool BuildLog::OpenForWriteIfNeeded() { return false; } } - log_file_path_.clear(); return true; } -- cgit v0.12 From 5b80abbc729e94abb5f5776a3438ad57d480c097 Mon Sep 17 00:00:00 2001 From: Alastair Harrison Date: Thu, 27 Aug 2020 21:47:27 +0100 Subject: CMake: Add support for "browse" mode Fixes ninja-build/ninja#1822, fixes ninja-build/ninja#1853 Adds support for `ninja -t browse` to CMake builds. The platform support logic is copied from configure.py, so Windows, Solaris and AIX are treated as 'unsupported' platforms. All other platforms are assumed to be supported. As discussed in #1853, when built via CMake the `ninja` executable looks for a binary called `python` in the current path, in order to launch the "browse" mode. The behaviour differs from that of the configure.py script, which looks for a python executable that has the *same name* as the python executable that invoked the configure script. --- CMakeLists.txt | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65e42a4..d132965 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,18 @@ else() endif() target_include_directories(libninja-re2c PRIVATE src) +# --- Check for 'browse' mode support +set(unsupported_browse_platforms + "Windows" + "SunOS" + "AIX" +) +if(${CMAKE_SYSTEM_NAME} IN_LIST unsupported_browse_platforms) + set(platform_supports_ninja_browse FALSE) +else() + set(platform_supports_ninja_browse TRUE) +endif() + # Core source files all build into ninja library. add_library(libninja OBJECT src/build_log.cc @@ -96,6 +108,32 @@ endif() add_executable(ninja src/ninja.cc) target_link_libraries(ninja PRIVATE libninja libninja-re2c) +# Adds browse mode into the ninja binary if it's supported by the host platform. +if(platform_supports_ninja_browse) + # Inlines src/browse.py into the browse_py.h header, so that it can be included + # by src/browse.cc + add_custom_command( + OUTPUT build/browse_py.h + MAIN_DEPENDENCY src/browse.py + DEPENDS src/inline.sh + COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/build + COMMAND src/inline.sh kBrowsePy + < src/browse.py + > ${CMAKE_BINARY_DIR}/build/browse_py.h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + VERBATIM + ) + + target_compile_definitions(ninja PRIVATE NINJA_HAVE_BROWSE) + target_sources(ninja PRIVATE src/browse.cc) + set_source_files_properties(src/browse.cc + PROPERTIES + OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/build/browse_py.h" + INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR}" + COMPILE_DEFINITIONS NINJA_PYTHON="python" + ) +endif() + # Tests all build into ninja_test executable. add_executable(ninja_test src/build_log_test.cc -- cgit v0.12 From 67f960be1be8099ea1727af8d3361d38274b2bd1 Mon Sep 17 00:00:00 2001 From: Alastair Harrison Date: Fri, 28 Aug 2020 11:53:58 +0100 Subject: Improve error handling in inline.sh Previously the script would generate some output and return a zero error code, even if the calls to `od` or `sed` failed. This change ensures that: - If `od` or `sed` fail then the script will fail. - Output will only be written on success. --- src/inline.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/inline.sh b/src/inline.sh index b64e8ca..5092fa2 100755 --- a/src/inline.sh +++ b/src/inline.sh @@ -19,7 +19,14 @@ # stdin and writes stdout. varname="$1" -echo "const char $varname[] =" -od -t x1 -A n -v | sed -e 's|^[\t ]\{0,\}$||g; s|[\t ]\{1,\}| |g; s| \{1,\}$||g; s| |\\x|g; s|^|"|; s|$|"|' -echo ";" +# 'od' and 'sed' may not be available on all platforms, and may not support the +# flags used here. We must ensure that the script exits with a non-zero exit +# code in those cases. +byte_vals=$(od -t x1 -A n -v) || exit 1 +escaped_byte_vals=$(echo "${byte_vals}" \ + | sed -e 's|^[\t ]\{0,\}$||g; s|[\t ]\{1,\}| |g; s| \{1,\}$||g; s| |\\x|g; s|^|"|; s|$|"|') \ + || exit 1 + +# Only write output once we have successfully generated the required data +printf "const char %s[] = \n%s;" "${varname}" "${escaped_byte_vals}" -- cgit v0.12 From 0b5f5ba91020668856f87f079a61380198540bd7 Mon Sep 17 00:00:00 2001 From: Alastair Harrison Date: Fri, 28 Aug 2020 11:58:43 +0100 Subject: CMake: Add platform checks for browse mode support Browse mode requires a number of POSIX features to be available. This commit adds configure-time checks that the 'unistd.h' header is available and that the `inline.sh` script executes successfully. If the checks pass then browse mode is enabled. --- CMakeLists.txt | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d132965..b0c0911 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,7 @@ cmake_minimum_required(VERSION 3.15) + +include(CheckIncludeFileCXX) + project(ninja) # --- optional link-time optimization @@ -49,16 +52,28 @@ endif() target_include_directories(libninja-re2c PRIVATE src) # --- Check for 'browse' mode support -set(unsupported_browse_platforms - "Windows" - "SunOS" - "AIX" -) -if(${CMAKE_SYSTEM_NAME} IN_LIST unsupported_browse_platforms) - set(platform_supports_ninja_browse FALSE) -else() - set(platform_supports_ninja_browse TRUE) -endif() +function(check_platform_supports_browse_mode RESULT) + # Make sure the inline.sh script works on this platform. + # It uses the shell commands such as 'od', which may not be available. + execute_process( + COMMAND sh -c "echo 'TEST' | src/inline.sh var" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + RESULT_VARIABLE inline_result + OUTPUT_QUIET + ERROR_QUIET + ) + if(NOT inline_result EQUAL "0") + # The inline script failed, so browse mode is not supported. + set(${RESULT} "0" PARENT_SCOPE) + return() + endif() + + # Now check availability of the unistd header + check_include_file_cxx(unistd.h PLATFORM_HAS_UNISTD_HEADER) + set(${RESULT} "${PLATFORM_HAS_UNISTD_HEADER}" PARENT_SCOPE) +endfunction() + +check_platform_supports_browse_mode(platform_supports_ninja_browse) # Core source files all build into ninja library. add_library(libninja OBJECT -- cgit v0.12 From 54959b0f2c4950d97d94c03810b3b5185be0d69e Mon Sep 17 00:00:00 2001 From: David Callu Date: Mon, 14 Sep 2020 12:39:13 +0200 Subject: cmake: add BUILD_TESTING option (ON by default) (#1839) option provided by cmake's Module CTest enable_testing() is call by this Module --- CMakeLists.txt | 80 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0c0911..8e6bdd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,45 +149,47 @@ if(platform_supports_ninja_browse) ) endif() -# Tests all build into ninja_test executable. -add_executable(ninja_test - src/build_log_test.cc - src/build_test.cc - src/clean_test.cc - src/clparser_test.cc - src/depfile_parser_test.cc - src/deps_log_test.cc - src/disk_interface_test.cc - src/dyndep_parser_test.cc - src/edit_distance_test.cc - src/graph_test.cc - src/lexer_test.cc - src/manifest_parser_test.cc - src/ninja_test.cc - src/state_test.cc - src/string_piece_util_test.cc - src/subprocess_test.cc - src/test.cc - src/util_test.cc -) -if(WIN32) - target_sources(ninja_test PRIVATE src/includes_normalize_test.cc src/msvc_helper_test.cc) +include(CTest) +if(BUILD_TESTING) + # Tests all build into ninja_test executable. + add_executable(ninja_test + src/build_log_test.cc + src/build_test.cc + src/clean_test.cc + src/clparser_test.cc + src/depfile_parser_test.cc + src/deps_log_test.cc + src/disk_interface_test.cc + src/dyndep_parser_test.cc + src/edit_distance_test.cc + src/graph_test.cc + src/lexer_test.cc + src/manifest_parser_test.cc + src/ninja_test.cc + src/state_test.cc + src/string_piece_util_test.cc + src/subprocess_test.cc + src/test.cc + src/util_test.cc + ) + if(WIN32) + target_sources(ninja_test PRIVATE src/includes_normalize_test.cc src/msvc_helper_test.cc) + endif() + target_link_libraries(ninja_test PRIVATE libninja libninja-re2c) + + foreach(perftest + build_log_perftest + canon_perftest + clparser_perftest + depfile_parser_perftest + hash_collision_bench + manifest_parser_perftest + ) + add_executable(${perftest} src/${perftest}.cc) + target_link_libraries(${perftest} PRIVATE libninja libninja-re2c) + endforeach() + + add_test(NinjaTest ninja_test) endif() -target_link_libraries(ninja_test PRIVATE libninja libninja-re2c) - -foreach(perftest - build_log_perftest - canon_perftest - clparser_perftest - depfile_parser_perftest - hash_collision_bench - manifest_parser_perftest -) - add_executable(${perftest} src/${perftest}.cc) - target_link_libraries(${perftest} PRIVATE libninja libninja-re2c) -endforeach() - -enable_testing() -add_test(NinjaTest ninja_test) install(TARGETS ninja DESTINATION bin) -- cgit v0.12 From 811b3d88764b7219cb78f5e1c4c711f09adb0835 Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Sat, 19 Sep 2020 10:58:05 +0200 Subject: GitHub Actions: Update to Ubuntu 20.04 --- .github/workflows/linux.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 5bfd3af..4f31a7a 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -59,13 +59,13 @@ jobs: asset_content_type: application/zip test: - runs-on: [ubuntu-18.04] + runs-on: [ubuntu-20.04] steps: - uses: actions/checkout@v2 - name: Install dependencies run: | sudo apt update - sudo apt install -y python3-pytest ninja-build clang-tidy-9 + sudo apt install -y python3-pytest ninja-build clang-tidy pip install cmake==3.17.* - name: Configure (GCC) @@ -88,7 +88,7 @@ jobs: working-directory: build-gcc/Release - name: Configure (Clang) - run: CC=clang-9 CXX=clang++-9 cmake -Bbuild-clang -DCMAKE_BUILD_TYPE=Debug -G'Ninja Multi-Config' -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + run: CC=clang CXX=clang++ cmake -Bbuild-clang -DCMAKE_BUILD_TYPE=Debug -G'Ninja Multi-Config' -DCMAKE_EXPORT_COMPILE_COMMANDS=1 - name: Build (Clang, Debug) run: cmake --build build-clang --config Debug @@ -107,5 +107,5 @@ jobs: working-directory: build-clang/Release - name: clang-tidy - run: /usr/lib/llvm-9/share/clang/run-clang-tidy.py -header-filter=src + run: /usr/lib/llvm-10/share/clang/run-clang-tidy.py -header-filter=src working-directory: build-clang -- cgit v0.12 From 3b8b83802f409dccdc513c049afa93a6c52a6fea Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Sat, 19 Sep 2020 11:02:53 +0200 Subject: clang-tidy: Drop readability-container-size-empty due to tests --- .clang-tidy | 2 -- 1 file changed, 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 2afce32..8968011 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,12 +2,10 @@ Checks: ' ,readability-avoid-const-params-in-decls, ,readability-non-const-parameter, - ,readability-container-size-empty, ,readability-redundant-string-cstr, ' WarningsAsErrors: ' ,readability-avoid-const-params-in-decls, ,readability-non-const-parameter, - ,readability-container-size-empty, ,readability-redundant-string-cstr, ' -- cgit v0.12 From ff4f2a0db21b738bba743ad543d8553417aca7b0 Mon Sep 17 00:00:00 2001 From: Michael Jones Date: Sat, 6 Jun 2020 17:23:54 -0500 Subject: Add 'using namespace std;' to all cc files to prepare for removing it from header files --- src/browse.cc | 2 ++ src/build.cc | 2 ++ src/build_log.cc | 2 ++ src/build_log_perftest.cc | 2 ++ src/build_log_test.cc | 2 ++ src/build_test.cc | 2 ++ src/canon_perftest.cc | 2 ++ src/clean.cc | 2 ++ src/clean_test.cc | 2 ++ src/clparser.cc | 2 ++ src/clparser_perftest.cc | 2 ++ src/clparser_test.cc | 2 ++ src/depfile_parser.cc | 2 ++ src/depfile_parser.in.cc | 2 ++ src/depfile_parser_perftest.cc | 2 ++ src/depfile_parser_test.cc | 2 ++ src/deps_log.cc | 2 ++ src/deps_log_test.cc | 2 ++ src/disk_interface.cc | 2 ++ src/disk_interface_test.cc | 2 ++ src/dyndep.cc | 2 ++ src/dyndep_parser.cc | 2 ++ src/dyndep_parser_test.cc | 2 ++ src/edit_distance.cc | 2 ++ src/eval_env.cc | 2 ++ src/graph.cc | 2 ++ src/graph_test.cc | 2 ++ src/graphviz.cc | 2 ++ src/hash_collision_bench.cc | 3 ++- src/includes_normalize-win32.cc | 2 ++ src/includes_normalize_test.cc | 2 ++ src/lexer.in.cc | 2 ++ src/lexer_test.cc | 2 ++ src/line_printer.cc | 2 ++ src/manifest_parser.cc | 2 ++ src/manifest_parser_perftest.cc | 2 ++ src/manifest_parser_test.cc | 2 ++ src/metrics.cc | 2 ++ src/minidump-win32.cc | 2 ++ src/msvc_helper-win32.cc | 2 ++ src/msvc_helper_main-win32.cc | 2 ++ src/msvc_helper_test.cc | 2 ++ src/ninja.cc | 2 ++ src/ninja_test.cc | 2 ++ src/parser.cc | 2 ++ src/state.cc | 1 + src/state_test.cc | 2 ++ src/string_piece_util_test.cc | 2 ++ src/subprocess-posix.cc | 2 ++ src/subprocess-win32.cc | 2 ++ src/subprocess_test.cc | 2 ++ src/test.cc | 2 ++ src/util.cc | 2 ++ src/util_test.cc | 2 ++ src/version.cc | 2 ++ 55 files changed, 109 insertions(+), 1 deletion(-) diff --git a/src/browse.cc b/src/browse.cc index c08c9f4..76bee07 100644 --- a/src/browse.cc +++ b/src/browse.cc @@ -22,6 +22,8 @@ #include "build/browse_py.h" +using namespace std; + void RunBrowsePython(State* state, const char* ninja_command, const char* input_file, int argc, char* argv[]) { // Fork off a Python process and have it run our code via its stdin. diff --git a/src/build.cc b/src/build.cc index 8c6ada5..e3131e2 100644 --- a/src/build.cc +++ b/src/build.cc @@ -40,6 +40,8 @@ #include "subprocess.h" #include "util.h" +using namespace std; + namespace { /// A CommandRunner that doesn't actually run the commands. diff --git a/src/build_log.cc b/src/build_log.cc index e5f179c..0a2fac6 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -41,6 +41,8 @@ #define strtoll _strtoi64 #endif +using namespace std; + // Implementation details: // Each run's log appends to the log file. // To load, we run through all log entries in series, throwing away diff --git a/src/build_log_perftest.cc b/src/build_log_perftest.cc index e471d13..ced0df9 100644 --- a/src/build_log_perftest.cc +++ b/src/build_log_perftest.cc @@ -26,6 +26,8 @@ #include #endif +using namespace std; + const char kTestFilename[] = "BuildLogPerfTest-tempfile"; struct NoDeadPaths : public BuildLogUser { diff --git a/src/build_log_test.cc b/src/build_log_test.cc index c81f570..3718299 100644 --- a/src/build_log_test.cc +++ b/src/build_log_test.cc @@ -27,6 +27,8 @@ #endif #include +using namespace std; + namespace { const char kTestFilename[] = "BuildLogTest-tempfile"; diff --git a/src/build_test.cc b/src/build_test.cc index 12c3383..078080d 100644 --- a/src/build_test.cc +++ b/src/build_test.cc @@ -21,6 +21,8 @@ #include "graph.h" #include "test.h" +using namespace std; + struct CompareEdgesByOutput { static bool cmp(const Edge* a, const Edge* b) { return a->outputs_[0]->path() < b->outputs_[0]->path(); diff --git a/src/canon_perftest.cc b/src/canon_perftest.cc index 03f4a2f..088bd45 100644 --- a/src/canon_perftest.cc +++ b/src/canon_perftest.cc @@ -18,6 +18,8 @@ #include "util.h" #include "metrics.h" +using namespace std; + const char kPath[] = "../../third_party/WebKit/Source/WebCore/" "platform/leveldb/LevelDBWriteBatch.cpp"; diff --git a/src/clean.cc b/src/clean.cc index 55d7277..3e57437 100644 --- a/src/clean.cc +++ b/src/clean.cc @@ -22,6 +22,8 @@ #include "state.h" #include "util.h" +using namespace std; + Cleaner::Cleaner(State* state, const BuildConfig& config, DiskInterface* disk_interface) diff --git a/src/clean_test.cc b/src/clean_test.cc index d068f3c..1b843a2 100644 --- a/src/clean_test.cc +++ b/src/clean_test.cc @@ -22,6 +22,8 @@ #include #endif +using namespace std; + namespace { const char kTestFilename[] = "CleanTest-tempfile"; diff --git a/src/clparser.cc b/src/clparser.cc index 7994c06..275641e 100644 --- a/src/clparser.cc +++ b/src/clparser.cc @@ -28,6 +28,8 @@ #include "util.h" #endif +using namespace std; + namespace { /// Return true if \a input ends with \a needle. diff --git a/src/clparser_perftest.cc b/src/clparser_perftest.cc index 7ac5230..008ac46 100644 --- a/src/clparser_perftest.cc +++ b/src/clparser_perftest.cc @@ -18,6 +18,8 @@ #include "clparser.h" #include "metrics.h" +using namespace std; + int main(int argc, char* argv[]) { // Output of /showIncludes from #include string perf_testdata = diff --git a/src/clparser_test.cc b/src/clparser_test.cc index 1549ab1..0b829c1 100644 --- a/src/clparser_test.cc +++ b/src/clparser_test.cc @@ -17,6 +17,8 @@ #include "test.h" #include "util.h" +using namespace std; + TEST(CLParserTest, ShowIncludes) { ASSERT_EQ("", CLParser::FilterShowIncludes("", "")); diff --git a/src/depfile_parser.cc b/src/depfile_parser.cc index 0b7dce1..bffeb76 100644 --- a/src/depfile_parser.cc +++ b/src/depfile_parser.cc @@ -18,6 +18,8 @@ #include +using namespace std; + DepfileParser::DepfileParser(DepfileParserOptions options) : options_(options) { diff --git a/src/depfile_parser.in.cc b/src/depfile_parser.in.cc index 95b4346..75ba982 100644 --- a/src/depfile_parser.in.cc +++ b/src/depfile_parser.in.cc @@ -17,6 +17,8 @@ #include +using namespace std; + DepfileParser::DepfileParser(DepfileParserOptions options) : options_(options) { diff --git a/src/depfile_parser_perftest.cc b/src/depfile_parser_perftest.cc index b215221..52555e6 100644 --- a/src/depfile_parser_perftest.cc +++ b/src/depfile_parser_perftest.cc @@ -19,6 +19,8 @@ #include "util.h" #include "metrics.h" +using namespace std; + int main(int argc, char* argv[]) { if (argc < 2) { printf("usage: %s \n", argv[0]); diff --git a/src/depfile_parser_test.cc b/src/depfile_parser_test.cc index 8e2cd25..8886258 100644 --- a/src/depfile_parser_test.cc +++ b/src/depfile_parser_test.cc @@ -16,6 +16,8 @@ #include "test.h" +using namespace std; + struct DepfileParserTest : public testing::Test { bool Parse(const char* input, string* err); diff --git a/src/deps_log.cc b/src/deps_log.cc index 1fb65ae..0567c95 100644 --- a/src/deps_log.cc +++ b/src/deps_log.cc @@ -30,6 +30,8 @@ typedef unsigned __int32 uint32_t; #include "state.h" #include "util.h" +using namespace std; + // The version is stored as 4 bytes after the signature and also serves as a // byte order mark. Signature and version combined are 16 bytes long. const char kFileSignature[] = "# ninjadeps\n"; diff --git a/src/deps_log_test.cc b/src/deps_log_test.cc index 0cdeb45..4055941 100644 --- a/src/deps_log_test.cc +++ b/src/deps_log_test.cc @@ -23,6 +23,8 @@ #include "util.h" #include "test.h" +using namespace std; + namespace { const char kTestFilename[] = "DepsLogTest-tempfile"; diff --git a/src/disk_interface.cc b/src/disk_interface.cc index 594bc51..49af001 100644 --- a/src/disk_interface.cc +++ b/src/disk_interface.cc @@ -33,6 +33,8 @@ #include "metrics.h" #include "util.h" +using namespace std; + namespace { string DirName(const string& path) { diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc index 866d1d6..066c770 100644 --- a/src/disk_interface_test.cc +++ b/src/disk_interface_test.cc @@ -23,6 +23,8 @@ #include "graph.h" #include "test.h" +using namespace std; + namespace { struct DiskInterfaceTest : public testing::Test { diff --git a/src/dyndep.cc b/src/dyndep.cc index 2aee601..b388e9b 100644 --- a/src/dyndep.cc +++ b/src/dyndep.cc @@ -24,6 +24,8 @@ #include "state.h" #include "util.h" +using namespace std; + bool DyndepLoader::LoadDyndeps(Node* node, std::string* err) const { DyndepFile ddf; return LoadDyndeps(node, &ddf, err); diff --git a/src/dyndep_parser.cc b/src/dyndep_parser.cc index baebbac..56da16f 100644 --- a/src/dyndep_parser.cc +++ b/src/dyndep_parser.cc @@ -22,6 +22,8 @@ #include "util.h" #include "version.h" +using namespace std; + DyndepParser::DyndepParser(State* state, FileReader* file_reader, DyndepFile* dyndep_file) : Parser(state, file_reader) diff --git a/src/dyndep_parser_test.cc b/src/dyndep_parser_test.cc index 39ec657..1bba7ba 100644 --- a/src/dyndep_parser_test.cc +++ b/src/dyndep_parser_test.cc @@ -22,6 +22,8 @@ #include "state.h" #include "test.h" +using namespace std; + struct DyndepParserTest : public testing::Test { void AssertParse(const char* input) { DyndepParser parser(&state_, &fs_, &dyndep_file_); diff --git a/src/edit_distance.cc b/src/edit_distance.cc index 3bb62b8..34bf0e5 100644 --- a/src/edit_distance.cc +++ b/src/edit_distance.cc @@ -17,6 +17,8 @@ #include #include +using namespace std; + int EditDistance(const StringPiece& s1, const StringPiece& s2, bool allow_replacements, diff --git a/src/eval_env.cc b/src/eval_env.cc index e9b6c43..796a326 100644 --- a/src/eval_env.cc +++ b/src/eval_env.cc @@ -16,6 +16,8 @@ #include "eval_env.h" +using namespace std; + string BindingEnv::LookupVariable(const string& var) { map::iterator i = bindings_.find(var); if (i != bindings_.end()) diff --git a/src/graph.cc b/src/graph.cc index 28a9653..ea11360 100644 --- a/src/graph.cc +++ b/src/graph.cc @@ -28,6 +28,8 @@ #include "state.h" #include "util.h" +using namespace std; + bool Node::Stat(DiskInterface* disk_interface, string* err) { return (mtime_ = disk_interface->Stat(path_, err)) != -1; } diff --git a/src/graph_test.cc b/src/graph_test.cc index 660943f..14f6375 100644 --- a/src/graph_test.cc +++ b/src/graph_test.cc @@ -17,6 +17,8 @@ #include "test.h" +using namespace std; + struct GraphTest : public StateTestWithBuiltinRules { GraphTest() : scan_(&state_, NULL, NULL, &fs_, NULL) {} diff --git a/src/graphviz.cc b/src/graphviz.cc index 0d07251..37b7108 100644 --- a/src/graphviz.cc +++ b/src/graphviz.cc @@ -20,6 +20,8 @@ #include "dyndep.h" #include "graph.h" +using namespace std; + void GraphViz::AddTarget(Node* node) { if (visited_nodes_.find(node) != visited_nodes_.end()) return; diff --git a/src/hash_collision_bench.cc b/src/hash_collision_bench.cc index ff947dc..52ff56d 100644 --- a/src/hash_collision_bench.cc +++ b/src/hash_collision_bench.cc @@ -15,11 +15,12 @@ #include "build_log.h" #include -using namespace std; #include #include +using namespace std; + int random(int low, int high) { return int(low + (rand() / double(RAND_MAX)) * (high - low) + 0.5); } diff --git a/src/includes_normalize-win32.cc b/src/includes_normalize-win32.cc index 79bf5b4..9f8dfc2 100644 --- a/src/includes_normalize-win32.cc +++ b/src/includes_normalize-win32.cc @@ -24,6 +24,8 @@ #include +using namespace std; + namespace { bool InternalGetFullPathName(const StringPiece& file_name, char* buffer, diff --git a/src/includes_normalize_test.cc b/src/includes_normalize_test.cc index dbcdbe0..9214f53 100644 --- a/src/includes_normalize_test.cc +++ b/src/includes_normalize_test.cc @@ -22,6 +22,8 @@ #include "test.h" #include "util.h" +using namespace std; + namespace { string GetCurDir() { diff --git a/src/lexer.in.cc b/src/lexer.in.cc index c1fb822..88007e7 100644 --- a/src/lexer.in.cc +++ b/src/lexer.in.cc @@ -19,6 +19,8 @@ #include "eval_env.h" #include "util.h" +using namespace std; + bool Lexer::Error(const string& message, string* err) { // Compute line/column. int line = 1; diff --git a/src/lexer_test.cc b/src/lexer_test.cc index 331d8e1..c5c416d 100644 --- a/src/lexer_test.cc +++ b/src/lexer_test.cc @@ -17,6 +17,8 @@ #include "eval_env.h" #include "test.h" +using namespace std; + TEST(Lexer, ReadVarValue) { Lexer lexer("plain text $var $VaR ${x}\n"); EvalString eval; diff --git a/src/line_printer.cc b/src/line_printer.cc index c93173e..68c58ad 100644 --- a/src/line_printer.cc +++ b/src/line_printer.cc @@ -30,6 +30,8 @@ #include "util.h" +using namespace std; + LinePrinter::LinePrinter() : have_blank_line_(true), console_locked_(false) { const char* term = getenv("TERM"); #ifndef _WIN32 diff --git a/src/manifest_parser.cc b/src/manifest_parser.cc index bb53dc2..860a8fc 100644 --- a/src/manifest_parser.cc +++ b/src/manifest_parser.cc @@ -23,6 +23,8 @@ #include "util.h" #include "version.h" +using namespace std; + ManifestParser::ManifestParser(State* state, FileReader* file_reader, ManifestParserOptions options) : Parser(state, file_reader), diff --git a/src/manifest_parser_perftest.cc b/src/manifest_parser_perftest.cc index 67d11f9..92f5e13 100644 --- a/src/manifest_parser_perftest.cc +++ b/src/manifest_parser_perftest.cc @@ -37,6 +37,8 @@ #include "state.h" #include "util.h" +using namespace std; + bool WriteFakeManifests(const string& dir, string* err) { RealDiskInterface disk_interface; TimeStamp mtime = disk_interface.Stat(dir + "/build.ninja", err); diff --git a/src/manifest_parser_test.cc b/src/manifest_parser_test.cc index f4aee2d..ec2eeed 100644 --- a/src/manifest_parser_test.cc +++ b/src/manifest_parser_test.cc @@ -21,6 +21,8 @@ #include "state.h" #include "test.h" +using namespace std; + struct ParserTest : public testing::Test { void AssertParse(const char* input) { ManifestParser parser(&state, &fs_); diff --git a/src/metrics.cc b/src/metrics.cc index a7d3c7a..dbaf221 100644 --- a/src/metrics.cc +++ b/src/metrics.cc @@ -28,6 +28,8 @@ #include "util.h" +using namespace std; + Metrics* g_metrics = NULL; namespace { diff --git a/src/minidump-win32.cc b/src/minidump-win32.cc index ca93638..9aea767 100644 --- a/src/minidump-win32.cc +++ b/src/minidump-win32.cc @@ -19,6 +19,8 @@ #include "util.h" +using namespace std; + typedef BOOL (WINAPI *MiniDumpWriteDumpFunc) ( IN HANDLE, IN DWORD, diff --git a/src/msvc_helper-win32.cc b/src/msvc_helper-win32.cc index de6147a..1148ae5 100644 --- a/src/msvc_helper-win32.cc +++ b/src/msvc_helper-win32.cc @@ -18,6 +18,8 @@ #include "util.h" +using namespace std; + namespace { string Replace(const string& input, const string& find, const string& replace) { diff --git a/src/msvc_helper_main-win32.cc b/src/msvc_helper_main-win32.cc index 644b2a2..7d59307 100644 --- a/src/msvc_helper_main-win32.cc +++ b/src/msvc_helper_main-win32.cc @@ -24,6 +24,8 @@ #include "getopt.h" +using namespace std; + namespace { void Usage() { diff --git a/src/msvc_helper_test.cc b/src/msvc_helper_test.cc index eaae51f..d9e2ee6 100644 --- a/src/msvc_helper_test.cc +++ b/src/msvc_helper_test.cc @@ -17,6 +17,8 @@ #include "test.h" #include "util.h" +using namespace std; + TEST(EscapeForDepfileTest, SpacesInFilename) { ASSERT_EQ("sub\\some\\ sdk\\foo.h", EscapeForDepfile("sub\\some sdk\\foo.h")); diff --git a/src/ninja.cc b/src/ninja.cc index 00e3a5c..471a023 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -46,6 +46,8 @@ #include "util.h" #include "version.h" +using namespace std; + #ifdef _MSC_VER // Defined in msvc_helper_main-win32.cc. int MSVCHelperMain(int argc, char** argv); diff --git a/src/ninja_test.cc b/src/ninja_test.cc index d642c5c..b40e176 100644 --- a/src/ninja_test.cc +++ b/src/ninja_test.cc @@ -28,6 +28,8 @@ #include "test.h" #include "line_printer.h" +using namespace std; + struct RegisteredTest { testing::Test* (*factory)(); const char *name; diff --git a/src/parser.cc b/src/parser.cc index 745c532..756922d 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -17,6 +17,8 @@ #include "disk_interface.h" #include "metrics.h" +using namespace std; + bool Parser::Load(const string& filename, string* err, Lexer* parent) { METRIC_RECORD(".ninja parse"); string contents; diff --git a/src/state.cc b/src/state.cc index 74cf4c1..d3a9e29 100644 --- a/src/state.cc +++ b/src/state.cc @@ -22,6 +22,7 @@ #include "metrics.h" #include "util.h" +using namespace std; void Pool::EdgeScheduled(const Edge& edge) { if (depth_ != 0) diff --git a/src/state_test.cc b/src/state_test.cc index 458b519..96469f9 100644 --- a/src/state_test.cc +++ b/src/state_test.cc @@ -16,6 +16,8 @@ #include "state.h" #include "test.h" +using namespace std; + namespace { TEST(State, Basic) { diff --git a/src/string_piece_util_test.cc b/src/string_piece_util_test.cc index 648c647..b77ae84 100644 --- a/src/string_piece_util_test.cc +++ b/src/string_piece_util_test.cc @@ -16,6 +16,8 @@ #include "test.h" +using namespace std; + TEST(StringPieceUtilTest, SplitStringPiece) { { string input("a:b:c"); diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc index 74785d1..0c5f556 100644 --- a/src/subprocess-posix.cc +++ b/src/subprocess-posix.cc @@ -34,6 +34,8 @@ extern char** environ; #include "util.h" +using namespace std; + Subprocess::Subprocess(bool use_console) : fd_(-1), pid_(-1), use_console_(use_console) { } diff --git a/src/subprocess-win32.cc b/src/subprocess-win32.cc index d221476..ff3baac 100644 --- a/src/subprocess-win32.cc +++ b/src/subprocess-win32.cc @@ -21,6 +21,8 @@ #include "util.h" +using namespace std; + Subprocess::Subprocess(bool use_console) : child_(NULL) , overlapped_(), is_reading_(false), use_console_(use_console) { diff --git a/src/subprocess_test.cc b/src/subprocess_test.cc index 6e487db..073fe86 100644 --- a/src/subprocess_test.cc +++ b/src/subprocess_test.cc @@ -24,6 +24,8 @@ #include #endif +using namespace std; + namespace { #ifdef _WIN32 diff --git a/src/test.cc b/src/test.cc index 021005e..11b1c9e 100644 --- a/src/test.cc +++ b/src/test.cc @@ -43,6 +43,8 @@ extern "C" { } #endif +using namespace std; + namespace { #ifdef _WIN32 diff --git a/src/util.cc b/src/util.cc index 4df2bb2..c76f730 100644 --- a/src/util.cc +++ b/src/util.cc @@ -54,6 +54,8 @@ #include "edit_distance.h" #include "metrics.h" +using namespace std; + void Fatal(const char* msg, ...) { va_list ap; fprintf(stderr, "ninja: fatal: "); diff --git a/src/util_test.cc b/src/util_test.cc index b43788d..1621c91 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -16,6 +16,8 @@ #include "test.h" +using namespace std; + namespace { bool CanonicalizePath(string* path, string* err) { diff --git a/src/version.cc b/src/version.cc index 9d27e87..f25a30a 100644 --- a/src/version.cc +++ b/src/version.cc @@ -18,6 +18,8 @@ #include "util.h" +using namespace std; + const char* kNinjaVersion = "1.10.1.git"; void ParseVersion(const string& version, int* major, int* minor) { -- cgit v0.12 From c22512b9b5ff47864cc5774018a0be12dfb6da44 Mon Sep 17 00:00:00 2001 From: Michael Jones Date: Wed, 30 Sep 2020 12:43:16 -0500 Subject: Add clang-analyze to build --- .github/workflows/linux.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 71cd06e..47dd062 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -22,13 +22,13 @@ jobs: curl -L -O https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/p7zip-plugins-16.02-10.el7.x86_64.rpm rpm -U --quiet p7zip-16.02-10.el7.x86_64.rpm rpm -U --quiet p7zip-plugins-16.02-10.el7.x86_64.rpm - yum install -y make gcc-c++ + yum install -y make gcc-c++ clang-analyzer - name: Build ninja shell: bash run: | cmake -DCMAKE_BUILD_TYPE=Release -B build - cmake --build build --parallel --config Release + scan-build -o scanlogs cmake --build build --parallel --config Release strip build/ninja - name: Test ninja -- cgit v0.12 From a5aae85a3c8a4032ab18b82afe6c77673125d888 Mon Sep 17 00:00:00 2001 From: Michael Jones Date: Thu, 5 Apr 2018 20:13:04 -0500 Subject: Remove 'using namespace std' from header files, properly namespace all std symbols --- src/build.h | 62 ++++++++++++++++++++++----------------------- src/build_log.h | 15 +++++------ src/clean.h | 16 +++++------- src/clparser.h | 15 +++++------ src/depfile_parser.h | 5 ++-- src/deps_log.h | 17 ++++++------- src/disk_interface.h | 29 ++++++++++----------- src/dyndep_parser.h | 11 ++++---- src/eval_env.h | 43 +++++++++++++++---------------- src/graph.h | 55 ++++++++++++++++++++-------------------- src/includes_normalize.h | 16 ++++++------ src/lexer.cc | 66 +++++++++++++++++++++--------------------------- src/lexer.h | 12 ++++----- src/line_printer.h | 9 +++---- src/manifest_parser.h | 16 ++++++------ src/metrics.h | 7 +++-- src/msvc_helper.h | 5 ++-- src/parser.h | 10 +++----- src/state.h | 27 ++++++++++---------- src/string_piece.h | 9 +++---- src/string_piece_util.cc | 1 + src/string_piece_util.h | 5 ++-- src/subprocess.h | 13 +++++----- src/test.h | 34 ++++++++++++------------- src/util.h | 23 ++++++++--------- src/version.h | 5 ++-- 26 files changed, 250 insertions(+), 276 deletions(-) diff --git a/src/build.h b/src/build.h index 97773c4..41120e1 100644 --- a/src/build.h +++ b/src/build.h @@ -46,7 +46,7 @@ struct Plan { /// Add a target to our plan (including all its dependencies). /// Returns false if we don't need to build this target; may /// fill in |err| with an error message if there's a problem. - bool AddTarget(const Node* node, string* err); + bool AddTarget(const Node* node, std::string* err); // Pop a ready edge off the queue of edges to build. // Returns NULL if there's no work to do. @@ -67,11 +67,11 @@ struct Plan { /// If any of the edge's outputs are dyndep bindings of their dependents, /// this loads dynamic dependencies from the nodes' paths. /// Returns 'false' if loading dyndep info fails and 'true' otherwise. - bool EdgeFinished(Edge* edge, EdgeResult result, string* err); + bool EdgeFinished(Edge* edge, EdgeResult result, std::string* err); /// Clean the given node during the build. /// Return false on error. - bool CleanNode(DependencyScan* scan, Node* node, string* err); + bool CleanNode(DependencyScan* scan, Node* node, std::string* err); /// Number of edges with commands to run. int command_edge_count() const { return command_edges_; } @@ -82,18 +82,18 @@ struct Plan { /// Update the build plan to account for modifications made to the graph /// by information loaded from a dyndep file. bool DyndepsLoaded(DependencyScan* scan, const Node* node, - const DyndepFile& ddf, string* err); + const DyndepFile& ddf, std::string* err); private: - bool RefreshDyndepDependents(DependencyScan* scan, const Node* node, string* err); - void UnmarkDependents(const Node* node, set* dependents); - bool AddSubTarget(const Node* node, const Node* dependent, string* err, - set* dyndep_walk); + bool RefreshDyndepDependents(DependencyScan* scan, const Node* node, std::string* err); + void UnmarkDependents(const Node* node, std::set* dependents); + bool AddSubTarget(const Node* node, const Node* dependent, std::string* err, + std::set* dyndep_walk); /// Update plan with knowledge that the given node is up to date. /// If the node is a dyndep binding on any of its dependents, this /// loads dynamic dependencies from the node's path. /// Returns 'false' if loading dyndep info fails and 'true' otherwise. - bool NodeFinished(Node* node, string* err); + bool NodeFinished(Node* node, std::string* err); /// Enumerate possible steps we want for an edge. enum Want @@ -109,20 +109,20 @@ private: }; void EdgeWanted(const Edge* edge); - bool EdgeMaybeReady(map::iterator want_e, string* err); + bool EdgeMaybeReady(std::map::iterator want_e, std::string* err); /// Submits a ready edge as a candidate for execution. /// The edge may be delayed from running, for example if it's a member of a /// currently-full pool. - void ScheduleWork(map::iterator want_e); + void ScheduleWork(std::map::iterator want_e); /// Keep track of which edges we want to build in this plan. If this map does /// not contain an entry for an edge, we do not want to build the entry or its /// dependents. If it does contain an entry, the enumeration indicates what /// we want for the edge. - map want_; + std::map want_; - set ready_; + std::set ready_; Builder* builder_; @@ -146,13 +146,13 @@ struct CommandRunner { Result() : edge(NULL) {} Edge* edge; ExitStatus status; - string output; + std::string output; bool success() const { return status == ExitSuccess; } }; /// Wait for a command to complete, or return false if interrupted. virtual bool WaitForCommand(Result* result) = 0; - virtual vector GetActiveEdges() { return vector(); } + virtual std::vector GetActiveEdges() { return std::vector(); } virtual void Abort() {} }; @@ -186,24 +186,24 @@ struct Builder { /// Clean up after interrupted commands by deleting output files. void Cleanup(); - Node* AddTarget(const string& name, string* err); + Node* AddTarget(const std::string& name, std::string* err); /// Add a target to the build, scanning dependencies. /// @return false on error. - bool AddTarget(Node* target, string* err); + bool AddTarget(Node* target, std::string* err); /// Returns true if the build targets are already up to date. bool AlreadyUpToDate() const; /// Run the build. Returns false on error. /// It is an error to call this function when AlreadyUpToDate() is true. - bool Build(string* err); + bool Build(std::string* err); - bool StartEdge(Edge* edge, string* err); + bool StartEdge(Edge* edge, std::string* err); /// Update status ninja logs following a command termination. /// @return false if the build can not proceed further due to a fatal error. - bool FinishCommand(CommandRunner::Result* result, string* err); + bool FinishCommand(CommandRunner::Result* result, std::string* err); /// Used for tests. void SetBuildLog(BuildLog* log) { @@ -211,22 +211,22 @@ struct Builder { } /// Load the dyndep information provided by the given node. - bool LoadDyndeps(Node* node, string* err); + bool LoadDyndeps(Node* node, std::string* err); State* state_; const BuildConfig& config_; Plan plan_; #if __cplusplus < 201703L - auto_ptr command_runner_; + std::auto_ptr command_runner_; #else - unique_ptr command_runner_; // auto_ptr was removed in C++17. + std::unique_ptr command_runner_; // auto_ptr was removed in C++17. #endif BuildStatus* status_; private: - bool ExtractDeps(CommandRunner::Result* result, const string& deps_type, - const string& deps_prefix, vector* deps_nodes, - string* err); + bool ExtractDeps(CommandRunner::Result* result, const std::string& deps_type, + const std::string& deps_prefix, std::vector* deps_nodes, + std::string* err); DiskInterface* disk_interface_; DependencyScan scan_; @@ -241,7 +241,7 @@ struct BuildStatus { explicit BuildStatus(const BuildConfig& config); void PlanHasTotalEdges(int total); void BuildEdgeStarted(const Edge* edge); - void BuildEdgeFinished(Edge* edge, bool success, const string& output, + void BuildEdgeFinished(Edge* edge, bool success, const std::string& output, int* start_time, int* end_time); void BuildLoadDyndeps(); void BuildStarted(); @@ -257,8 +257,8 @@ struct BuildStatus { /// placeholders. /// @param progress_status_format The format of the progress status. /// @param status The status of the edge. - string FormatProgressStatus(const char* progress_status_format, - EdgeStatus status) const; + std::string FormatProgressStatus(const char* progress_status_format, + EdgeStatus status) const; private: void PrintStatus(const Edge* edge, EdgeStatus status); @@ -271,7 +271,7 @@ struct BuildStatus { int started_edges_, finished_edges_, total_edges_; /// Map of running edge to time the edge started running. - typedef map RunningEdgeMap; + typedef std::map RunningEdgeMap; RunningEdgeMap running_edges_; /// Prints progress output. @@ -327,7 +327,7 @@ struct BuildStatus { double rate_; Stopwatch stopwatch_; const size_t N; - queue times_; + std::queue times_; int last_update_; }; diff --git a/src/build_log.h b/src/build_log.h index 6d060d1..842c467 100644 --- a/src/build_log.h +++ b/src/build_log.h @@ -17,7 +17,6 @@ #include #include -using namespace std; #include "hash_map.h" #include "load_status.h" @@ -47,17 +46,17 @@ struct BuildLog { /// Prepares writing to the log file without actually opening it - that will /// happen when/if it's needed - bool OpenForWrite(const string& path, const BuildLogUser& user, string* err); + bool OpenForWrite(const std::string& path, const BuildLogUser& user, std::string* err); bool RecordCommand(Edge* edge, int start_time, int end_time, TimeStamp mtime = 0); void Close(); /// Load the on-disk log. - LoadStatus Load(const string& path, string* err); + LoadStatus Load(const std::string& path, std::string* err); struct LogEntry { - string output; + std::string output; uint64_t command_hash; int start_time; int end_time; @@ -72,19 +71,19 @@ struct BuildLog { mtime == o.mtime; } - explicit LogEntry(const string& output); - LogEntry(const string& output, uint64_t command_hash, + explicit LogEntry(const std::string& output); + LogEntry(const std::string& output, uint64_t command_hash, int start_time, int end_time, TimeStamp restat_mtime); }; /// Lookup a previously-run command by its output path. - LogEntry* LookupByOutput(const string& path); + LogEntry* LookupByOutput(const std::string& path); /// Serialize an entry into a log file. bool WriteEntry(FILE* f, const LogEntry& entry); /// Rewrite the known log entries, throwing away old data. - bool Recompact(const string& path, const BuildLogUser& user, string* err); + bool Recompact(const std::string& path, const BuildLogUser& user, std::string* err); /// Restat all outputs in the log bool Restat(StringPiece path, const DiskInterface& disk_interface, diff --git a/src/clean.h b/src/clean.h index 4c02ff6..cf3f1c3 100644 --- a/src/clean.h +++ b/src/clean.h @@ -22,8 +22,6 @@ #include "dyndep.h" #include "build_log.h" -using namespace std; - struct State; struct Node; struct Rule; @@ -78,15 +76,15 @@ struct Cleaner { private: /// Remove the file @a path. /// @return whether the file has been removed. - int RemoveFile(const string& path); + int RemoveFile(const std::string& path); /// @returns whether the file @a path exists. - bool FileExists(const string& path); - void Report(const string& path); + bool FileExists(const std::string& path); + void Report(const std::string& path); /// Remove the given @a path file only if it has not been already removed. - void Remove(const string& path); + void Remove(const std::string& path); /// @return whether the given @a path has already been removed. - bool IsAlreadyRemoved(const string& path); + bool IsAlreadyRemoved(const std::string& path); /// Remove the depfile and rspfile for an Edge. void RemoveEdgeFiles(Edge* edge); @@ -103,8 +101,8 @@ struct Cleaner { State* state_; const BuildConfig& config_; DyndepLoader dyndep_loader_; - set removed_; - set cleaned_; + std::set removed_; + std::set cleaned_; int cleaned_files_count_; DiskInterface* disk_interface_; int status_; diff --git a/src/clparser.h b/src/clparser.h index e597e7e..2a33628 100644 --- a/src/clparser.h +++ b/src/clparser.h @@ -17,7 +17,6 @@ #include #include -using namespace std; /// Visual Studio's cl.exe requires some massaging to work with Ninja; /// for example, it emits include information on stderr in a funny @@ -27,26 +26,26 @@ struct CLParser { /// Parse a line of cl.exe output and extract /showIncludes info. /// If a dependency is extracted, returns a nonempty string. /// Exposed for testing. - static string FilterShowIncludes(const string& line, - const string& deps_prefix); + static std::string FilterShowIncludes(const std::string& line, + const std::string& deps_prefix); /// Return true if a mentioned include file is a system path. /// Filtering these out reduces dependency information considerably. - static bool IsSystemInclude(string path); + static bool IsSystemInclude(std::string path); /// Parse a line of cl.exe output and return true if it looks like /// it's printing an input filename. This is a heuristic but it appears /// to be the best we can do. /// Exposed for testing. - static bool FilterInputFilename(string line); + static bool FilterInputFilename(std::string line); /// Parse the full output of cl, filling filtered_output with the text that /// should be printed (if any). Returns true on success, or false with err /// filled. output must not be the same object as filtered_object. - bool Parse(const string& output, const string& deps_prefix, - string* filtered_output, string* err); + bool Parse(const std::string& output, const std::string& deps_prefix, + std::string* filtered_output, std::string* err); - set includes_; + std::set includes_; }; #endif // NINJA_CLPARSER_H_ diff --git a/src/depfile_parser.h b/src/depfile_parser.h index 11b1228..0e8db81 100644 --- a/src/depfile_parser.h +++ b/src/depfile_parser.h @@ -17,7 +17,6 @@ #include #include -using namespace std; #include "string_piece.h" @@ -33,10 +32,10 @@ struct DepfileParser { /// Parse an input file. Input must be NUL-terminated. /// Warning: may mutate the content in-place and parsed StringPieces are /// pointers within it. - bool Parse(string* content, string* err); + bool Parse(std::string* content, std::string* err); std::vector outs_; - vector ins_; + std::vector ins_; DepfileParserOptions options_; }; diff --git a/src/deps_log.h b/src/deps_log.h index c4ada8b..cc44b41 100644 --- a/src/deps_log.h +++ b/src/deps_log.h @@ -17,7 +17,6 @@ #include #include -using namespace std; #include @@ -71,8 +70,8 @@ struct DepsLog { ~DepsLog(); // Writing (build-time) interface. - bool OpenForWrite(const string& path, string* err); - bool RecordDeps(Node* node, TimeStamp mtime, const vector& nodes); + bool OpenForWrite(const std::string& path, std::string* err); + bool RecordDeps(Node* node, TimeStamp mtime, const std::vector& nodes); bool RecordDeps(Node* node, TimeStamp mtime, int node_count, Node** nodes); void Close(); @@ -85,11 +84,11 @@ struct DepsLog { int node_count; Node** nodes; }; - LoadStatus Load(const string& path, State* state, string* err); + LoadStatus Load(const std::string& path, State* state, std::string* err); Deps* GetDeps(Node* node); /// Rewrite the known log entries, throwing away old data. - bool Recompact(const string& path, string* err); + bool Recompact(const std::string& path, std::string* err); /// Returns if the deps entry for a node is still reachable from the manifest. /// @@ -100,8 +99,8 @@ struct DepsLog { bool IsDepsEntryLiveFor(Node* node); /// Used for tests. - const vector& nodes() const { return nodes_; } - const vector& deps() const { return deps_; } + const std::vector& nodes() const { return nodes_; } + const std::vector& deps() const { return deps_; } private: // Updates the in-memory representation. Takes ownership of |deps|. @@ -119,9 +118,9 @@ struct DepsLog { std::string file_path_; /// Maps id -> Node. - vector nodes_; + std::vector nodes_; /// Maps id -> deps of that id. - vector deps_; + std::vector deps_; friend struct DepsLogTest; }; diff --git a/src/disk_interface.h b/src/disk_interface.h index 145e089..b75f1f6 100644 --- a/src/disk_interface.h +++ b/src/disk_interface.h @@ -17,7 +17,6 @@ #include #include -using namespace std; #include "timestamp.h" @@ -35,8 +34,8 @@ struct FileReader { /// Read and store in given string. On success, return Okay. /// On error, return another Status and fill |err|. - virtual Status ReadFile(const string& path, string* contents, - string* err) = 0; + virtual Status ReadFile(const std::string& path, std::string* contents, + std::string* err) = 0; }; /// Interface for accessing the disk. @@ -46,25 +45,25 @@ struct FileReader { struct DiskInterface: public FileReader { /// stat() a file, returning the mtime, or 0 if missing and -1 on /// other errors. - virtual TimeStamp Stat(const string& path, string* err) const = 0; + virtual TimeStamp Stat(const std::string& path, std::string* err) const = 0; /// Create a directory, returning false on failure. - virtual bool MakeDir(const string& path) = 0; + virtual bool MakeDir(const std::string& path) = 0; /// Create a file, with the specified name and contents /// Returns true on success, false on failure - virtual bool WriteFile(const string& path, const string& contents) = 0; + virtual bool WriteFile(const std::string& path, const std::string& contents) = 0; /// Remove the file named @a path. It behaves like 'rm -f path' so no errors /// are reported if it does not exists. /// @returns 0 if the file has been removed, /// 1 if the file does not exist, and /// -1 if an error occurs. - virtual int RemoveFile(const string& path) = 0; + virtual int RemoveFile(const std::string& path) = 0; /// Create all the parent directories for path; like mkdir -p /// `basename path`. - bool MakeDirs(const string& path); + bool MakeDirs(const std::string& path); }; /// Implementation of DiskInterface that actually hits the disk. @@ -75,11 +74,11 @@ struct RealDiskInterface : public DiskInterface { #endif {} virtual ~RealDiskInterface() {} - virtual TimeStamp Stat(const string& path, string* err) const; - virtual bool MakeDir(const string& path); - virtual bool WriteFile(const string& path, const string& contents); - virtual Status ReadFile(const string& path, string* contents, string* err); - virtual int RemoveFile(const string& path); + virtual TimeStamp Stat(const std::string& path, std::string* err) const; + virtual bool MakeDir(const std::string& path); + virtual bool WriteFile(const std::string& path, const std::string& contents); + virtual Status ReadFile(const std::string& path, std::string* contents, std::string* err); + virtual int RemoveFile(const std::string& path); /// Whether stat information can be cached. Only has an effect on Windows. void AllowStatCache(bool allow); @@ -89,10 +88,10 @@ struct RealDiskInterface : public DiskInterface { /// Whether stat information can be cached. bool use_cache_; - typedef map DirCache; + typedef std::map DirCache; // TODO: Neither a map nor a hashmap seems ideal here. If the statcache // works out, come up with a better data structure. - typedef map Cache; + typedef std::map Cache; mutable Cache cache_; #endif }; diff --git a/src/dyndep_parser.h b/src/dyndep_parser.h index 09a3722..8f4c28d 100644 --- a/src/dyndep_parser.h +++ b/src/dyndep_parser.h @@ -27,17 +27,18 @@ struct DyndepParser: public Parser { DyndepFile* dyndep_file); /// Parse a text string of input. Used by tests. - bool ParseTest(const string& input, string* err) { + bool ParseTest(const std::string& input, std::string* err) { return Parse("input", input, err); } private: /// Parse a file, given its contents as a string. - bool Parse(const string& filename, const string& input, string* err); + bool Parse(const std::string& filename, const std::string& input, + std:: string* err); - bool ParseDyndepVersion(string* err); - bool ParseLet(string* key, EvalString* val, string* err); - bool ParseEdge(string* err); + bool ParseDyndepVersion(std::string* err); + bool ParseLet(std::string* key, EvalString* val, std::string* err); + bool ParseEdge(std::string* err); DyndepFile* dyndep_file_; BindingEnv env_; diff --git a/src/eval_env.h b/src/eval_env.h index 8fb9bf4..ca7daa4 100644 --- a/src/eval_env.h +++ b/src/eval_env.h @@ -18,7 +18,6 @@ #include #include #include -using namespace std; #include "string_piece.h" @@ -27,7 +26,7 @@ struct Rule; /// An interface for a scope for variable (e.g. "$foo") lookups. struct Env { virtual ~Env() {} - virtual string LookupVariable(const string& var) = 0; + virtual std::string LookupVariable(const std::string& var) = 0; }; /// A tokenized string that contains variable references. @@ -35,10 +34,10 @@ struct Env { struct EvalString { /// @return The evaluated string with variable expanded using value found in /// environment @a env. - string Evaluate(Env* env) const; + std::string Evaluate(Env* env) const; /// @return The string with variables not expanded. - string Unparse() const; + std::string Unparse() const; void Clear() { parsed_.clear(); } bool empty() const { return parsed_.empty(); } @@ -48,32 +47,32 @@ struct EvalString { /// Construct a human-readable representation of the parsed state, /// for use in tests. - string Serialize() const; + std::string Serialize() const; private: enum TokenType { RAW, SPECIAL }; - typedef vector > TokenList; + typedef std::vector > TokenList; TokenList parsed_; }; /// An invokable build command and associated metadata (description, etc.). struct Rule { - explicit Rule(const string& name) : name_(name) {} + explicit Rule(const std::string& name) : name_(name) {} - const string& name() const { return name_; } + const std::string& name() const { return name_; } - void AddBinding(const string& key, const EvalString& val); + void AddBinding(const std::string& key, const EvalString& val); - static bool IsReservedBinding(const string& var); + static bool IsReservedBinding(const std::string& var); - const EvalString* GetBinding(const string& key) const; + const EvalString* GetBinding(const std::string& key) const; private: // Allow the parsers to reach into this object and fill out its fields. friend struct ManifestParser; - string name_; - typedef map Bindings; + std::string name_; + typedef std::map Bindings; Bindings bindings_; }; @@ -84,26 +83,26 @@ struct BindingEnv : public Env { explicit BindingEnv(BindingEnv* parent) : parent_(parent) {} virtual ~BindingEnv() {} - virtual string LookupVariable(const string& var); + virtual std::string LookupVariable(const std::string& var); void AddRule(const Rule* rule); - const Rule* LookupRule(const string& rule_name); - const Rule* LookupRuleCurrentScope(const string& rule_name); - const map& GetRules() const; + const Rule* LookupRule(const std::string& rule_name); + const Rule* LookupRuleCurrentScope(const std::string& rule_name); + const std::map& GetRules() const; - void AddBinding(const string& key, const string& val); + void AddBinding(const std::string& key, const std::string& val); /// This is tricky. Edges want lookup scope to go in this order: /// 1) value set on edge itself (edge_->env_) /// 2) value set on rule, with expansion in the edge's scope /// 3) value set on enclosing scope of edge (edge_->env_->parent_) /// This function takes as parameters the necessary info to do (2). - string LookupWithFallback(const string& var, const EvalString* eval, - Env* env); + std::string LookupWithFallback(const std::string& var, const EvalString* eval, + Env* env); private: - map bindings_; - map rules_; + std::map bindings_; + std::map rules_; BindingEnv* parent_; }; diff --git a/src/graph.h b/src/graph.h index 2fa54af..4833f49 100644 --- a/src/graph.h +++ b/src/graph.h @@ -17,7 +17,6 @@ #include #include -using namespace std; #include "dyndep.h" #include "eval_env.h" @@ -36,7 +35,7 @@ struct State; /// Information about a node in the dependency graph: the file, whether /// it's dirty, mtime, etc. struct Node { - Node(const string& path, uint64_t slash_bits) + Node(const std::string& path, uint64_t slash_bits) : path_(path), slash_bits_(slash_bits), mtime_(-1), @@ -46,10 +45,10 @@ struct Node { id_(-1) {} /// Return false on error. - bool Stat(DiskInterface* disk_interface, string* err); + bool Stat(DiskInterface* disk_interface, std::string* err); /// Return false on error. - bool StatIfNecessary(DiskInterface* disk_interface, string* err) { + bool StatIfNecessary(DiskInterface* disk_interface, std::string* err) { if (status_known()) return true; return Stat(disk_interface, err); @@ -74,13 +73,13 @@ struct Node { return mtime_ != -1; } - const string& path() const { return path_; } + const std::string& path() const { return path_; } /// Get |path()| but use slash_bits to convert back to original slash styles. - string PathDecanonicalized() const { + std::string PathDecanonicalized() const { return PathDecanonicalized(path_, slash_bits_); } - static string PathDecanonicalized(const string& path, - uint64_t slash_bits); + static std::string PathDecanonicalized(const std::string& path, + uint64_t slash_bits); uint64_t slash_bits() const { return slash_bits_; } TimeStamp mtime() const { return mtime_; } @@ -98,13 +97,13 @@ struct Node { int id() const { return id_; } void set_id(int id) { id_ = id; } - const vector& out_edges() const { return out_edges_; } + const std::vector& out_edges() const { return out_edges_; } void AddOutEdge(Edge* edge) { out_edges_.push_back(edge); } void Dump(const char* prefix="") const; private: - string path_; + std::string path_; /// Set bits starting from lowest for backslashes that were normalized to /// forward slashes by CanonicalizePath. See |PathDecanonicalized|. @@ -130,7 +129,7 @@ private: Edge* in_edge_; /// All Edges that use this Node as an input. - vector out_edges_; + std::vector out_edges_; /// A dense integer id for the node, assigned and used by DepsLog. int id_; @@ -158,13 +157,13 @@ struct Edge { std::string EvaluateCommand(bool incl_rsp_file = false) const; /// Returns the shell-escaped value of |key|. - std::string GetBinding(const string& key) const; - bool GetBindingBool(const string& key) const; + std::string GetBinding(const std::string& key) const; + bool GetBindingBool(const std::string& key) const; /// Like GetBinding("depfile"), but without shell escaping. - string GetUnescapedDepfile() const; + std::string GetUnescapedDepfile() const; /// Like GetBinding("dyndep"), but without shell escaping. - string GetUnescapedDyndep() const; + std::string GetUnescapedDyndep() const; /// Like GetBinding("rspfile"), but without shell escaping. std::string GetUnescapedRspfile() const; @@ -172,8 +171,8 @@ struct Edge { const Rule* rule_; Pool* pool_; - vector inputs_; - vector outputs_; + std::vector inputs_; + std::vector outputs_; Node* dyndep_; BindingEnv* env_; VisitMark mark_; @@ -232,7 +231,7 @@ struct ImplicitDepLoader { /// Load implicit dependencies for \a edge. /// @return false on error (without filling \a err if info is just missing // or out of date). - bool LoadDeps(Edge* edge, string* err); + bool LoadDeps(Edge* edge, std::string* err); DepsLog* deps_log() const { return deps_log_; @@ -241,15 +240,15 @@ struct ImplicitDepLoader { private: /// Load implicit dependencies for \a edge from a depfile attribute. /// @return false on error (without filling \a err if info is just missing). - bool LoadDepFile(Edge* edge, const string& path, string* err); + bool LoadDepFile(Edge* edge, const std::string& path, std::string* err); /// Load implicit dependencies for \a edge from the DepsLog. /// @return false on error (without filling \a err if info is just missing). - bool LoadDepsFromLog(Edge* edge, string* err); + bool LoadDepsFromLog(Edge* edge, std::string* err); /// Preallocate \a count spaces in the input array on \a edge, returning /// an iterator pointing at the first new space. - vector::iterator PreallocateSpace(Edge* edge, int count); + std::vector::iterator PreallocateSpace(Edge* edge, int count); /// If we don't have a edge that generates this input already, /// create one; this makes us not abort if the input is missing, @@ -279,12 +278,12 @@ struct DependencyScan { /// needs to be re-run, and update outputs_ready_ and each outputs' |dirty_| /// state accordingly. /// Returns false on failure. - bool RecomputeDirty(Node* node, string* err); + bool RecomputeDirty(Node* node, std::string* err); /// Recompute whether any output of the edge is dirty, if so sets |*dirty|. /// Returns false on failure. bool RecomputeOutputsDirty(Edge* edge, Node* most_recent_input, - bool* dirty, string* err); + bool* dirty, std::string* err); BuildLog* build_log() const { return build_log_; @@ -301,17 +300,17 @@ struct DependencyScan { /// build graph with the new information. One overload accepts /// a caller-owned 'DyndepFile' object in which to store the /// information loaded from the dyndep file. - bool LoadDyndeps(Node* node, string* err) const; - bool LoadDyndeps(Node* node, DyndepFile* ddf, string* err) const; + bool LoadDyndeps(Node* node, std::string* err) const; + bool LoadDyndeps(Node* node, DyndepFile* ddf, std::string* err) const; private: - bool RecomputeDirty(Node* node, vector* stack, string* err); - bool VerifyDAG(Node* node, vector* stack, string* err); + bool RecomputeDirty(Node* node, std::vector* stack, std::string* err); + bool VerifyDAG(Node* node, std::vector* stack, std::string* err); /// Recompute whether a given single output should be marked dirty. /// Returns true if so. bool RecomputeOutputDirty(const Edge* edge, const Node* most_recent_input, - const string& command, Node* output); + const std::string& command, Node* output); BuildLog* build_log_; DiskInterface* disk_interface_; diff --git a/src/includes_normalize.h b/src/includes_normalize.h index 0339581..1b852e1 100644 --- a/src/includes_normalize.h +++ b/src/includes_normalize.h @@ -14,7 +14,6 @@ #include #include -using namespace std; struct StringPiece; @@ -22,18 +21,19 @@ struct StringPiece; /// TODO: this likely duplicates functionality of CanonicalizePath; refactor. struct IncludesNormalize { /// Normalize path relative to |relative_to|. - IncludesNormalize(const string& relative_to); + IncludesNormalize(const std::string& relative_to); // Internal utilities made available for testing, maybe useful otherwise. - static string AbsPath(StringPiece s, string* err); - static string Relativize(StringPiece path, - const vector& start_list, string* err); + static std::string AbsPath(StringPiece s, std::string* err); + static std::string Relativize(StringPiece path, + const std::vector& start_list, + std::string* err); /// Normalize by fixing slashes style, fixing redundant .. and . and makes the /// path |input| relative to |this->relative_to_| and store to |result|. - bool Normalize(const string& input, string* result, string* err) const; + bool Normalize(const std::string& input, std::string* result, std::string* err) const; private: - string relative_to_; - vector split_relative_to_; + std::string relative_to_; + std::vector split_relative_to_; }; diff --git a/src/lexer.cc b/src/lexer.cc index 35ae97b..6e4a470 100644 --- a/src/lexer.cc +++ b/src/lexer.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.16 */ +/* Generated by re2c 1.1.1 */ // Copyright 2011 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +20,8 @@ #include "eval_env.h" #include "util.h" +using namespace std; + bool Lexer::Error(const string& message, string* err) { // Compute line/column. int line = 1; @@ -233,8 +235,7 @@ yy8: goto yy5; yy9: yyaccept = 0; - q = ++p; - yych = *p; + yych = *(q = ++p); if (yybm[0+yych] & 32) { goto yy9; } @@ -252,8 +253,7 @@ yy12: if (yych <= 0x00) goto yy5; goto yy33; yy13: - ++p; - yych = *p; + yych = *++p; yy14: if (yybm[0+yych] & 64) { goto yy13; @@ -290,8 +290,8 @@ yy25: if (yych == 'u') goto yy41; goto yy14; yy26: - ++p; - if ((yych = *p) == '|') goto yy42; + yych = *++p; + if (yych == '|') goto yy42; { token = PIPE; break; } yy28: ++p; @@ -307,8 +307,7 @@ yy31: goto yy5; } yy32: - ++p; - yych = *p; + yych = *++p; yy33: if (yybm[0+yych] & 128) { goto yy32; @@ -380,14 +379,14 @@ yy52: if (yych == 'u') goto yy61; goto yy14; yy53: - ++p; - if (yybm[0+(yych = *p)] & 64) { + yych = *++p; + if (yybm[0+yych] & 64) { goto yy13; } { token = POOL; break; } yy55: - ++p; - if (yybm[0+(yych = *p)] & 64) { + yych = *++p; + if (yybm[0+yych] & 64) { goto yy13; } { token = RULE; break; } @@ -396,8 +395,8 @@ yy57: if (yych == 'i') goto yy62; goto yy14; yy58: - ++p; - if (yybm[0+(yych = *p)] & 64) { + yych = *++p; + if (yybm[0+yych] & 64) { goto yy13; } { token = BUILD; break; } @@ -426,22 +425,22 @@ yy65: if (yych == 'j') goto yy70; goto yy14; yy66: - ++p; - if (yybm[0+(yych = *p)] & 64) { + yych = *++p; + if (yybm[0+yych] & 64) { goto yy13; } { token = DEFAULT; break; } yy68: - ++p; - if (yybm[0+(yych = *p)] & 64) { + yych = *++p; + if (yybm[0+yych] & 64) { goto yy13; } { token = INCLUDE; break; } yy70: yych = *++p; if (yych != 'a') goto yy14; - ++p; - if (yybm[0+(yych = *p)] & 64) { + yych = *++p; + if (yybm[0+yych] & 64) { goto yy13; } { token = SUBNINJA; break; } @@ -521,8 +520,7 @@ yy77: yy78: { break; } yy79: - ++p; - yych = *p; + yych = *++p; if (yybm[0+yych] & 128) { goto yy79; } @@ -600,8 +598,7 @@ bool Lexer::ReadIdent(string* out) { return false; } yy93: - ++p; - yych = *p; + yych = *++p; if (yybm[0+yych] & 128) { goto yy93; } @@ -681,8 +678,7 @@ yy98: return Error("unexpected EOF", err); } yy100: - ++p; - yych = *p; + yych = *++p; if (yybm[0+yych] & 16) { goto yy100; } @@ -704,8 +700,8 @@ yy103: } } yy105: - ++p; - if ((yych = *p) == '\n') goto yy108; + yych = *++p; + if (yych == '\n') goto yy108; { last_token_ = start; return Error(DescribeLastError(), err); @@ -750,8 +746,7 @@ yy111: return Error("bad $-escape (literal $ must be written as $$)", err); } yy112: - ++p; - yych = *p; + yych = *++p; if (yybm[0+yych] & 32) { goto yy112; } @@ -775,8 +770,7 @@ yy118: continue; } yy120: - ++p; - yych = *p; + yych = *++p; if (yybm[0+yych] & 64) { goto yy120; } @@ -797,15 +791,13 @@ yy125: } goto yy111; yy126: - ++p; - yych = *p; + yych = *++p; if (yych == ' ') goto yy126; { continue; } yy129: - ++p; - yych = *p; + yych = *++p; if (yybm[0+yych] & 128) { goto yy129; } diff --git a/src/lexer.h b/src/lexer.h index f366556..788d948 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -55,7 +55,7 @@ struct Lexer { /// If the last token read was an ERROR token, provide more info /// or the empty string. - string DescribeLastError(); + std::string DescribeLastError(); /// Start parsing some input. void Start(StringPiece filename, StringPiece input); @@ -71,30 +71,30 @@ struct Lexer { /// Read a simple identifier (a rule or variable name). /// Returns false if a name can't be read. - bool ReadIdent(string* out); + bool ReadIdent(std::string* out); /// Read a path (complete with $escapes). /// Returns false only on error, returned path may be empty if a delimiter /// (space, newline) is hit. - bool ReadPath(EvalString* path, string* err) { + bool ReadPath(EvalString* path, std::string* err) { return ReadEvalString(path, true, err); } /// Read the value side of a var = value line (complete with $escapes). /// Returns false only on error. - bool ReadVarValue(EvalString* value, string* err) { + bool ReadVarValue(EvalString* value, std::string* err) { return ReadEvalString(value, false, err); } /// Construct an error message with context. - bool Error(const string& message, string* err); + bool Error(const std::string& message, std::string* err); private: /// Skip past whitespace (called after each read token/ident/etc.). void EatWhitespace(); /// Read a $-escaped string. - bool ReadEvalString(EvalString* eval, bool path, string* err); + bool ReadEvalString(EvalString* eval, bool path, std::string* err); StringPiece filename_; StringPiece input_; diff --git a/src/line_printer.h b/src/line_printer.h index 92d4dc4..a8ec9ff 100644 --- a/src/line_printer.h +++ b/src/line_printer.h @@ -17,7 +17,6 @@ #include #include -using namespace std; /// Prints lines of text, possibly overprinting previously printed lines /// if the terminal supports it. @@ -35,10 +34,10 @@ struct LinePrinter { }; /// Overprints the current line. If type is ELIDE, elides to_print to fit on /// one line. - void Print(string to_print, LineType type); + void Print(std::string to_print, LineType type); /// Prints a string on a new line, not overprinting previous output. - void PrintOnNewLine(const string& to_print); + void PrintOnNewLine(const std::string& to_print); /// Lock or unlock the console. Any output sent to the LinePrinter while the /// console is locked will not be printed until it is unlocked. @@ -58,13 +57,13 @@ struct LinePrinter { bool console_locked_; /// Buffered current line while console is locked. - string line_buffer_; + std::string line_buffer_; /// Buffered line type while console is locked. LineType line_type_; /// Buffered console output while console is locked. - string output_buffer_; + std::string output_buffer_; #ifdef _WIN32 void* console_; diff --git a/src/manifest_parser.h b/src/manifest_parser.h index e14d069..887be50 100644 --- a/src/manifest_parser.h +++ b/src/manifest_parser.h @@ -44,24 +44,24 @@ struct ManifestParser : public Parser { ManifestParserOptions options = ManifestParserOptions()); /// Parse a text string of input. Used by tests. - bool ParseTest(const string& input, string* err) { + bool ParseTest(const std::string& input, std::string* err) { quiet_ = true; return Parse("input", input, err); } private: /// Parse a file, given its contents as a string. - bool Parse(const string& filename, const string& input, string* err); + bool Parse(const std::string& filename, const std::string& input, std::string* err); /// Parse various statement types. - bool ParsePool(string* err); - bool ParseRule(string* err); - bool ParseLet(string* key, EvalString* val, string* err); - bool ParseEdge(string* err); - bool ParseDefault(string* err); + bool ParsePool(std::string* err); + bool ParseRule(std::string* err); + bool ParseLet(std::string* key, EvalString* val, std::string* err); + bool ParseEdge(std::string* err); + bool ParseDefault(std::string* err); /// Parse either a 'subninja' or 'include' line. - bool ParseFileInclude(bool new_scope, string* err); + bool ParseFileInclude(bool new_scope, std::string* err); BindingEnv* env_; ManifestParserOptions options_; diff --git a/src/metrics.h b/src/metrics.h index b6da859..11239b5 100644 --- a/src/metrics.h +++ b/src/metrics.h @@ -17,7 +17,6 @@ #include #include -using namespace std; #include "util.h" // For int64_t. @@ -26,7 +25,7 @@ using namespace std; /// A single metrics we're tracking, like "depfile load time". struct Metric { - string name; + std::string name; /// Number of times we've hit the code path. int count; /// Total time (in micros) we've spent on the code path. @@ -49,13 +48,13 @@ private: /// The singleton that stores metrics and prints the report. struct Metrics { - Metric* NewMetric(const string& name); + Metric* NewMetric(const std::string& name); /// Print a summary report to stdout. void Report(); private: - vector metrics_; + std::vector metrics_; }; /// Get the current time as relative to some epoch. diff --git a/src/msvc_helper.h b/src/msvc_helper.h index 70d1fff..568b9f9 100644 --- a/src/msvc_helper.h +++ b/src/msvc_helper.h @@ -13,9 +13,8 @@ // limitations under the License. #include -using namespace std; -string EscapeForDepfile(const string& path); +std::string EscapeForDepfile(const std::string& path); /// Wraps a synchronous execution of a CL subprocess. struct CLWrapper { @@ -27,7 +26,7 @@ struct CLWrapper { /// Start a process and gather its raw output. Returns its exit code. /// Crashes (calls Fatal()) on error. - int Run(const string& command, string* output); + int Run(const std::string& command, std::string* output); void* env_block_; }; diff --git a/src/parser.h b/src/parser.h index e2d2b97..011fad8 100644 --- a/src/parser.h +++ b/src/parser.h @@ -17,8 +17,6 @@ #include -using namespace std; - #include "lexer.h" struct FileReader; @@ -30,12 +28,12 @@ struct Parser { : state_(state), file_reader_(file_reader) {} /// Load and parse a file. - bool Load(const string& filename, string* err, Lexer* parent = NULL); + bool Load(const std::string& filename, std::string* err, Lexer* parent = NULL); protected: /// If the next token is not \a expected, produce an error string /// saying "expected foo, got bar". - bool ExpectToken(Lexer::Token expected, string* err); + bool ExpectToken(Lexer::Token expected, std::string* err); State* state_; FileReader* file_reader_; @@ -43,8 +41,8 @@ protected: private: /// Parse a file, given its contents as a string. - virtual bool Parse(const string& filename, const string& input, - string* err) = 0; + virtual bool Parse(const std::string& filename, const std::string& input, + std::string* err) = 0; }; #endif // NINJA_PARSER_H_ diff --git a/src/state.h b/src/state.h index 6fe886c..f553ed4 100644 --- a/src/state.h +++ b/src/state.h @@ -19,7 +19,6 @@ #include #include #include -using namespace std; #include "eval_env.h" #include "hash_map.h" @@ -38,13 +37,13 @@ struct Rule; /// the total scheduled weight diminishes enough (i.e. when a scheduled edge /// completes). struct Pool { - Pool(const string& name, int depth) + Pool(const std::string& name, int depth) : name_(name), current_use_(0), depth_(depth), delayed_(&WeightedEdgeCmp) {} // A depth of 0 is infinite bool is_valid() const { return depth_ >= 0; } int depth() const { return depth_; } - const string& name() const { return name_; } + const std::string& name() const { return name_; } int current_use() const { return current_use_; } /// true if the Pool might delay this edge @@ -62,13 +61,13 @@ struct Pool { void DelayEdge(Edge* edge); /// Pool will add zero or more edges to the ready_queue - void RetrieveReadyEdges(set* ready_queue); + void RetrieveReadyEdges(std::set* ready_queue); /// Dump the Pool and its edges (useful for debugging). void Dump() const; private: - string name_; + std::string name_; /// |current_use_| is the total of the weights of the edges which are /// currently scheduled in the Plan (i.e. the edges in Plan::ready_). @@ -77,7 +76,7 @@ struct Pool { static bool WeightedEdgeCmp(const Edge* a, const Edge* b); - typedef set DelayedEdges; + typedef std::set DelayedEdges; DelayedEdges delayed_; }; @@ -90,17 +89,17 @@ struct State { State(); void AddPool(Pool* pool); - Pool* LookupPool(const string& pool_name); + Pool* LookupPool(const std::string& pool_name); Edge* AddEdge(const Rule* rule); Node* GetNode(StringPiece path, uint64_t slash_bits); Node* LookupNode(StringPiece path) const; - Node* SpellcheckNode(const string& path); + Node* SpellcheckNode(const std::string& path); void AddIn(Edge* edge, StringPiece path, uint64_t slash_bits); bool AddOut(Edge* edge, StringPiece path, uint64_t slash_bits); - bool AddDefault(StringPiece path, string* error); + bool AddDefault(StringPiece path, std::string* error); /// Reset state. Keeps all nodes and edges, but restores them to the /// state where we haven't yet examined the disk for dirty state. @@ -111,21 +110,21 @@ struct State { /// @return the root node(s) of the graph. (Root nodes have no output edges). /// @param error where to write the error message if somethings went wrong. - vector RootNodes(string* error) const; - vector DefaultNodes(string* error) const; + std::vector RootNodes(std::string* error) const; + std::vector DefaultNodes(std::string* error) const; /// Mapping of path -> Node. typedef ExternalStringHashMap::Type Paths; Paths paths_; /// All the pools used in the graph. - map pools_; + std::map pools_; /// All the edges of the graph. - vector edges_; + std::vector edges_; BindingEnv bindings_; - vector defaults_; + std::vector defaults_; }; #endif // NINJA_STATE_H_ diff --git a/src/string_piece.h b/src/string_piece.h index 031bda4..1c0bee6 100644 --- a/src/string_piece.h +++ b/src/string_piece.h @@ -17,8 +17,6 @@ #include -using namespace std; - #include /// StringPiece represents a slice of a string whose memory is managed @@ -30,7 +28,7 @@ struct StringPiece { StringPiece() : str_(NULL), len_(0) {} /// The constructors intentionally allow for implicit conversions. - StringPiece(const string& str) : str_(str.data()), len_(str.size()) {} + StringPiece(const std::string& str) : str_(str.data()), len_(str.size()) {} StringPiece(const char* str) : str_(str), len_(strlen(str)) {} StringPiece(const char* str, size_t len) : str_(str), len_(len) {} @@ -38,14 +36,15 @@ struct StringPiece { bool operator==(const StringPiece& other) const { return len_ == other.len_ && memcmp(str_, other.str_, len_) == 0; } + bool operator!=(const StringPiece& other) const { return !(*this == other); } /// Convert the slice into a full-fledged std::string, copying the /// data into a new string. - string AsString() const { - return len_ ? string(str_, len_) : string(); + std::string AsString() const { + return len_ ? std::string(str_, len_) : std::string(); } const_iterator begin() const { diff --git a/src/string_piece_util.cc b/src/string_piece_util.cc index 69513f5..5a77294 100644 --- a/src/string_piece_util.cc +++ b/src/string_piece_util.cc @@ -17,6 +17,7 @@ #include #include #include + using namespace std; vector SplitStringPiece(StringPiece input, char sep) { diff --git a/src/string_piece_util.h b/src/string_piece_util.h index 2e40b9f..28470f1 100644 --- a/src/string_piece_util.h +++ b/src/string_piece_util.h @@ -19,11 +19,10 @@ #include #include "string_piece.h" -using namespace std; -vector SplitStringPiece(StringPiece input, char sep); +std::vector SplitStringPiece(StringPiece input, char sep); -string JoinStringPiece(const vector& list, char sep); +std::string JoinStringPiece(const std::vector& list, char sep); inline char ToLowerASCII(char c) { return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c; diff --git a/src/subprocess.h b/src/subprocess.h index b2d486c..9e3d2ee 100644 --- a/src/subprocess.h +++ b/src/subprocess.h @@ -18,7 +18,6 @@ #include #include #include -using namespace std; #ifdef _WIN32 #include @@ -49,14 +48,14 @@ struct Subprocess { bool Done() const; - const string& GetOutput() const; + const std::string& GetOutput() const; private: Subprocess(bool use_console); - bool Start(struct SubprocessSet* set, const string& command); + bool Start(struct SubprocessSet* set, const std::string& command); void OnPipeReady(); - string buf_; + std::string buf_; #ifdef _WIN32 /// Set up pipe_ as the parent-side pipe of the subprocess; return the @@ -84,13 +83,13 @@ struct SubprocessSet { SubprocessSet(); ~SubprocessSet(); - Subprocess* Add(const string& command, bool use_console = false); + Subprocess* Add(const std::string& command, bool use_console = false); bool DoWork(); Subprocess* NextFinished(); void Clear(); - vector running_; - queue finished_; + std::vector running_; + std::queue finished_; #ifdef _WIN32 static BOOL WINAPI NotifyInterrupted(DWORD dwCtrlType); diff --git a/src/test.h b/src/test.h index 6af17b3..7fee55e 100644 --- a/src/test.h +++ b/src/test.h @@ -118,7 +118,7 @@ struct StateTestWithBuiltinRules : public testing::Test { void AddCatRule(State* state); /// Short way to get a Node by its path from state_. - Node* GetNode(const string& path); + Node* GetNode(const std::string& path); State state_; }; @@ -135,7 +135,7 @@ struct VirtualFileSystem : public DiskInterface { VirtualFileSystem() : now_(1) {} /// "Create" a file with contents. - void Create(const string& path, const string& contents); + void Create(const std::string& path, const std::string& contents); /// Tick "time" forwards; subsequent file operations will be newer than /// previous ones. @@ -144,25 +144,25 @@ struct VirtualFileSystem : public DiskInterface { } // DiskInterface - virtual TimeStamp Stat(const string& path, string* err) const; - virtual bool WriteFile(const string& path, const string& contents); - virtual bool MakeDir(const string& path); - virtual Status ReadFile(const string& path, string* contents, string* err); - virtual int RemoveFile(const string& path); + virtual TimeStamp Stat(const std::string& path, std::string* err) const; + virtual bool WriteFile(const std::string& path, const std::string& contents); + virtual bool MakeDir(const std::string& path); + virtual Status ReadFile(const std::string& path, std::string* contents, std::string* err); + virtual int RemoveFile(const std::string& path); /// An entry for a single in-memory file. struct Entry { int mtime; - string stat_error; // If mtime is -1. - string contents; + std::string stat_error; // If mtime is -1. + std::string contents; }; - vector directories_made_; - vector files_read_; - typedef map FileMap; + std::vector directories_made_; + std::vector files_read_; + typedef std::map FileMap; FileMap files_; - set files_removed_; - set files_created_; + std::set files_removed_; + std::set files_created_; /// A simple fake timestamp for file operations. int now_; @@ -170,15 +170,15 @@ struct VirtualFileSystem : public DiskInterface { struct ScopedTempDir { /// Create a temporary directory and chdir into it. - void CreateAndEnter(const string& name); + void CreateAndEnter(const std::string& name); /// Clean up the temporary directory. void Cleanup(); /// The temp directory containing our dir. - string start_dir_; + std::string start_dir_; /// The subdirectory name for our dir, or empty if it hasn't been set up. - string temp_dir_name_; + std::string temp_dir_name_; }; #endif // NINJA_TEST_H_ diff --git a/src/util.h b/src/util.h index 6a4a7a9..b2ba1cd 100644 --- a/src/util.h +++ b/src/util.h @@ -23,7 +23,6 @@ #include #include -using namespace std; #ifdef _MSC_VER #define NORETURN __declspec(noreturn) @@ -57,29 +56,29 @@ void Error(const char* msg, ...); /// Canonicalize a path like "foo/../bar.h" into just "bar.h". /// |slash_bits| has bits set starting from lowest for a backslash that was /// normalized to a forward slash. (only used on Windows) -bool CanonicalizePath(string* path, uint64_t* slash_bits, string* err); +bool CanonicalizePath(std::string* path, uint64_t* slash_bits, std::string* err); bool CanonicalizePath(char* path, size_t* len, uint64_t* slash_bits, - string* err); + std::string* err); /// Appends |input| to |*result|, escaping according to the whims of either /// Bash, or Win32's CommandLineToArgvW(). /// Appends the string directly to |result| without modification if we can /// determine that it contains no problematic characters. -void GetShellEscapedString(const string& input, string* result); -void GetWin32EscapedString(const string& input, string* result); +void GetShellEscapedString(const std::string& input, std::string* result); +void GetWin32EscapedString(const std::string& input, std::string* result); /// Read a file to a string (in text mode: with CRLF conversion /// on Windows). /// Returns -errno and fills in \a err on error. -int ReadFile(const string& path, string* contents, string* err); +int ReadFile(const std::string& path, std::string* contents, std::string* err); /// Mark a file descriptor to not be inherited on exec()s. void SetCloseOnExec(int fd); /// Given a misspelled string and a list of correct spellings, returns /// the closest match or NULL if there is no close enough match. -const char* SpellcheckStringV(const string& text, - const vector& words); +const char* SpellcheckStringV(const std::string& text, + const std::vector& words); /// Like SpellcheckStringV, but takes a NULL-terminated list. const char* SpellcheckString(const char* text, ...); @@ -87,7 +86,7 @@ const char* SpellcheckString(const char* text, ...); bool islatinalpha(int c); /// Removes all Ansi escape codes (http://www.termsys.demon.co.uk/vtansi.htm). -string StripAnsiEscapeCodes(const string& in); +std::string StripAnsiEscapeCodes(const std::string& in); /// @return the number of processors on the machine. Useful for an initial /// guess for how many jobs to run in parallel. @return 0 on error. @@ -99,10 +98,10 @@ double GetLoadAverage(); /// Elide the given string @a str with '...' in the middle if the length /// exceeds @a width. -string ElideMiddle(const string& str, size_t width); +std::string ElideMiddle(const std::string& str, size_t width); /// Truncates a file to the given size. -bool Truncate(const string& path, size_t size, string* err); +bool Truncate(const std::string& path, size_t size, std::string* err); #ifdef _MSC_VER #define snprintf _snprintf @@ -116,7 +115,7 @@ bool Truncate(const string& path, size_t size, string* err); #ifdef _WIN32 /// Convert the value returned by GetLastError() into a string. -string GetLastErrorString(); +std::string GetLastErrorString(); /// Calls Fatal() with a function name and GetLastErrorString. NORETURN void Win32Fatal(const char* function, const char* hint = NULL); diff --git a/src/version.h b/src/version.h index bd6b9ff..9d84ecb 100644 --- a/src/version.h +++ b/src/version.h @@ -16,17 +16,16 @@ #define NINJA_VERSION_H_ #include -using namespace std; /// The version number of the current Ninja release. This will always /// be "git" on trunk. extern const char* kNinjaVersion; /// Parse the major/minor components of a version string. -void ParseVersion(const string& version, int* major, int* minor); +void ParseVersion(const std::string& version, int* major, int* minor); /// Check whether \a version is compatible with the current Ninja version, /// aborting if not. -void CheckNinjaVersion(const string& required_version); +void CheckNinjaVersion(const std::string& required_version); #endif // NINJA_VERSION_H_ -- cgit v0.12 From 73e96c6aef818f3bbf67bbd81a048f3eaf6f4300 Mon Sep 17 00:00:00 2001 From: Michael Jones Date: Wed, 7 Aug 2019 13:54:44 -0500 Subject: Comply with project formatting rules wrt 80 column lines --- src/build.h | 6 +++--- src/build_log.h | 7 ++++--- src/disk_interface.h | 6 ++++-- src/includes_normalize.h | 3 ++- src/manifest_parser.h | 3 ++- src/string_piece_util.cc | 1 - src/test.h | 3 ++- src/util.h | 3 ++- 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/build.h b/src/build.h index 41120e1..2798693 100644 --- a/src/build.h +++ b/src/build.h @@ -224,9 +224,9 @@ struct Builder { BuildStatus* status_; private: - bool ExtractDeps(CommandRunner::Result* result, const std::string& deps_type, - const std::string& deps_prefix, std::vector* deps_nodes, - std::string* err); + bool ExtractDeps(CommandRunner::Result* result, const std::string& deps_type, + const std::string& deps_prefix, + std::vector* deps_nodes, std::string* err); DiskInterface* disk_interface_; DependencyScan scan_; diff --git a/src/build_log.h b/src/build_log.h index 842c467..88551e3 100644 --- a/src/build_log.h +++ b/src/build_log.h @@ -46,8 +46,8 @@ struct BuildLog { /// Prepares writing to the log file without actually opening it - that will /// happen when/if it's needed - bool OpenForWrite(const std::string& path, const BuildLogUser& user, std::string* err); - + bool OpenForWrite(const std::string& path, const BuildLogUser& user, + std::string* err); bool RecordCommand(Edge* edge, int start_time, int end_time, TimeStamp mtime = 0); void Close(); @@ -83,7 +83,8 @@ struct BuildLog { bool WriteEntry(FILE* f, const LogEntry& entry); /// Rewrite the known log entries, throwing away old data. - bool Recompact(const std::string& path, const BuildLogUser& user, std::string* err); + bool Recompact(const std::string& path, const BuildLogUser& user, + std::string* err); /// Restat all outputs in the log bool Restat(StringPiece path, const DiskInterface& disk_interface, diff --git a/src/disk_interface.h b/src/disk_interface.h index b75f1f6..bc29ab7 100644 --- a/src/disk_interface.h +++ b/src/disk_interface.h @@ -52,7 +52,8 @@ struct DiskInterface: public FileReader { /// Create a file, with the specified name and contents /// Returns true on success, false on failure - virtual bool WriteFile(const std::string& path, const std::string& contents) = 0; + virtual bool WriteFile(const std::string& path, + const std::string& contents) = 0; /// Remove the file named @a path. It behaves like 'rm -f path' so no errors /// are reported if it does not exists. @@ -77,7 +78,8 @@ struct RealDiskInterface : public DiskInterface { virtual TimeStamp Stat(const std::string& path, std::string* err) const; virtual bool MakeDir(const std::string& path); virtual bool WriteFile(const std::string& path, const std::string& contents); - virtual Status ReadFile(const std::string& path, std::string* contents, std::string* err); + virtual Status ReadFile(const std::string& path, std::string* contents, + std::string* err); virtual int RemoveFile(const std::string& path); /// Whether stat information can be cached. Only has an effect on Windows. diff --git a/src/includes_normalize.h b/src/includes_normalize.h index 1b852e1..7d50556 100644 --- a/src/includes_normalize.h +++ b/src/includes_normalize.h @@ -31,7 +31,8 @@ struct IncludesNormalize { /// Normalize by fixing slashes style, fixing redundant .. and . and makes the /// path |input| relative to |this->relative_to_| and store to |result|. - bool Normalize(const std::string& input, std::string* result, std::string* err) const; + bool Normalize(const std::string& input, std::string* result, + std::string* err) const; private: std::string relative_to_; diff --git a/src/manifest_parser.h b/src/manifest_parser.h index 887be50..954cf46 100644 --- a/src/manifest_parser.h +++ b/src/manifest_parser.h @@ -51,7 +51,8 @@ struct ManifestParser : public Parser { private: /// Parse a file, given its contents as a string. - bool Parse(const std::string& filename, const std::string& input, std::string* err); + bool Parse(const std::string& filename, const std::string& input, + std::string* err); /// Parse various statement types. bool ParsePool(std::string* err); diff --git a/src/string_piece_util.cc b/src/string_piece_util.cc index 5a77294..69513f5 100644 --- a/src/string_piece_util.cc +++ b/src/string_piece_util.cc @@ -17,7 +17,6 @@ #include #include #include - using namespace std; vector SplitStringPiece(StringPiece input, char sep) { diff --git a/src/test.h b/src/test.h index 7fee55e..4552c34 100644 --- a/src/test.h +++ b/src/test.h @@ -147,7 +147,8 @@ struct VirtualFileSystem : public DiskInterface { virtual TimeStamp Stat(const std::string& path, std::string* err) const; virtual bool WriteFile(const std::string& path, const std::string& contents); virtual bool MakeDir(const std::string& path); - virtual Status ReadFile(const std::string& path, std::string* contents, std::string* err); + virtual Status ReadFile(const std::string& path, std::string* contents, + std::string* err); virtual int RemoveFile(const std::string& path); /// An entry for a single in-memory file. diff --git a/src/util.h b/src/util.h index b2ba1cd..4e6ebb8 100644 --- a/src/util.h +++ b/src/util.h @@ -56,7 +56,8 @@ void Error(const char* msg, ...); /// Canonicalize a path like "foo/../bar.h" into just "bar.h". /// |slash_bits| has bits set starting from lowest for a backslash that was /// normalized to a forward slash. (only used on Windows) -bool CanonicalizePath(std::string* path, uint64_t* slash_bits, std::string* err); +bool CanonicalizePath(std::string* path, uint64_t* slash_bits, + std::string* err); bool CanonicalizePath(char* path, size_t* len, uint64_t* slash_bits, std::string* err); -- cgit v0.12 From e14c2552e9db71f12dcc0686cac5587e4e3d2366 Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Fri, 2 Oct 2020 13:49:17 +0200 Subject: Revert "Merge pull request #1768 from jhasse/github-actions-lint" This reverts commit 18df4d1e5dbd905507476d92351a2f8010a49356, reversing changes made to 54959b0f2c4950d97d94c03810b3b5185be0d69e. --- .clang-tidy | 11 ---------- .github/workflows/linux.yml | 52 --------------------------------------------- 2 files changed, 63 deletions(-) delete mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy deleted file mode 100644 index 8968011..0000000 --- a/.clang-tidy +++ /dev/null @@ -1,11 +0,0 @@ ---- -Checks: ' - ,readability-avoid-const-params-in-decls, - ,readability-non-const-parameter, - ,readability-redundant-string-cstr, -' -WarningsAsErrors: ' - ,readability-avoid-const-params-in-decls, - ,readability-non-const-parameter, - ,readability-redundant-string-cstr, -' diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 4f31a7a..71cd06e 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -57,55 +57,3 @@ jobs: asset_path: ./artifact/ninja-linux.zip asset_name: ninja-linux.zip asset_content_type: application/zip - - test: - runs-on: [ubuntu-20.04] - steps: - - uses: actions/checkout@v2 - - name: Install dependencies - run: | - sudo apt update - sudo apt install -y python3-pytest ninja-build clang-tidy - pip install cmake==3.17.* - - - name: Configure (GCC) - run: cmake -Bbuild-gcc -DCMAKE_BUILD_TYPE=Debug -G'Ninja Multi-Config' - - - name: Build (GCC, Debug) - run: cmake --build build-gcc --config Debug - - name: Unit tests (GCC, Debug) - run: ./build-gcc/Debug/ninja_test - - name: Python tests (GCC, Debug) - run: pytest-3 --color=yes ../.. - working-directory: build-gcc/Debug - - - name: Build (GCC, Release) - run: cmake --build build-gcc --config Release - - name: Unit tests (GCC, Release) - run: ./build-gcc/Release/ninja_test - - name: Python tests (GCC, Release) - run: pytest-3 --color=yes ../.. - working-directory: build-gcc/Release - - - name: Configure (Clang) - run: CC=clang CXX=clang++ cmake -Bbuild-clang -DCMAKE_BUILD_TYPE=Debug -G'Ninja Multi-Config' -DCMAKE_EXPORT_COMPILE_COMMANDS=1 - - - name: Build (Clang, Debug) - run: cmake --build build-clang --config Debug - - name: Unit tests (Clang, Debug) - run: ./build-clang/Debug/ninja_test - - name: Python tests (Clang, Debug) - run: pytest-3 --color=yes ../.. - working-directory: build-clang/Debug - - - name: Build (Clang, Release) - run: cmake --build build-clang --config Release - - name: Unit tests (Clang, Release) - run: ./build-clang/Release/ninja_test - - name: Python tests (Clang, Release) - run: pytest-3 --color=yes ../.. - working-directory: build-clang/Release - - - name: clang-tidy - run: /usr/lib/llvm-10/share/clang/run-clang-tidy.py -header-filter=src - working-directory: build-clang -- cgit v0.12 From 6fa1c59e02ff84e75627a04af80605c5e99e6667 Mon Sep 17 00:00:00 2001 From: Michael Jones Date: Fri, 2 Oct 2020 11:29:55 -0500 Subject: Add debug build with sanitizers support --- .github/workflows/linux.yml | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 47dd062..511b92b 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -22,23 +22,36 @@ jobs: curl -L -O https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/p7zip-plugins-16.02-10.el7.x86_64.rpm rpm -U --quiet p7zip-16.02-10.el7.x86_64.rpm rpm -U --quiet p7zip-plugins-16.02-10.el7.x86_64.rpm - yum install -y make gcc-c++ clang-analyzer + yum install -y make gcc-c++ libasan clang-analyzer - - name: Build ninja + - name: Build debug ninja + shell: bash + env: + CFLAGS: -fstack-protector-all -fsanitize=address + CXXFLAGS: -fstack-protector-all -fsanitize=address + run: | + scan-build -o scanlogs cmake -DCMAKE_BUILD_TYPE=Debug -B debug-build + scan-build -o scanlogs cmake --build debug-build --parallel --config Debug + + - name: Test debug ninja + run: ./ninja_test + working-directory: debug-build + + - name: Build release ninja shell: bash run: | - cmake -DCMAKE_BUILD_TYPE=Release -B build - scan-build -o scanlogs cmake --build build --parallel --config Release - strip build/ninja + cmake -DCMAKE_BUILD_TYPE=Release -B release-build + cmake --build release-build --parallel --config Release + strip release-build/ninja - - name: Test ninja + - name: Test release ninja run: ./ninja_test - working-directory: build + working-directory: release-build - name: Create ninja archive run: | mkdir artifact - 7z a artifact/ninja-linux.zip ./build/ninja + 7z a artifact/ninja-linux.zip ./release-build/ninja # Upload ninja binary archive as an artifact - name: Upload artifact -- cgit v0.12 From 5203aa49ed2f86fa3bed2968f4719d9e9ce5b60f Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski Date: Thu, 29 Oct 2020 10:00:47 -0500 Subject: build: Add IBM i compile/link flags --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e6bdd9..fc5931c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,6 +119,14 @@ if(MINGW) target_compile_definitions(libninja PRIVATE _WIN32_WINNT=0x0601 __USE_MINGW_ANSI_STDIO=1) endif() +# On IBM i (identified as "OS400" for compatibility reasons), this fixes missing +# PRId64 (and others) at compile time, and links to libutil for getopt_long +if(CMAKE_SYSTEM_NAME STREQUAL "OS400") + string(APPEND CMAKE_CXX_FLAGS " -D__STDC_FORMAT_MACROS") + string(APPEND CMAKE_C_FLAGS " -D__STDC_FORMAT_MACROS") + string(APPEND CMAKE_EXE_LINKER_FLAGS " -lutil") +endif() + # Main executable is library plus main() function. add_executable(ninja src/ninja.cc) target_link_libraries(ninja PRIVATE libninja libninja-re2c) -- cgit v0.12 From e74884f02614c6718898d169632078a15e532e50 Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski Date: Thu, 29 Oct 2020 10:33:49 -0500 Subject: fixup: remove unneeded CMAKE_C_FLAGS --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc5931c..b0b2fef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,6 @@ endif() # PRId64 (and others) at compile time, and links to libutil for getopt_long if(CMAKE_SYSTEM_NAME STREQUAL "OS400") string(APPEND CMAKE_CXX_FLAGS " -D__STDC_FORMAT_MACROS") - string(APPEND CMAKE_C_FLAGS " -D__STDC_FORMAT_MACROS") string(APPEND CMAKE_EXE_LINKER_FLAGS " -lutil") endif() -- cgit v0.12 From d45ff8ebf88ef4add46a80ccdfc2d97a8b4b091b Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Fri, 30 Oct 2020 10:02:35 +0100 Subject: Check return value of setvbuf, fix #509 --- src/build_log.cc | 4 +++- src/deps_log.cc | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/build_log.cc b/src/build_log.cc index 0a2fac6..04409c8 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -190,7 +190,9 @@ bool BuildLog::OpenForWriteIfNeeded() { if (!log_file_) { return false; } - setvbuf(log_file_, NULL, _IOLBF, BUFSIZ); + if (setvbuf(log_file_, NULL, _IOLBF, BUFSIZ) != 0) { + return false; + } SetCloseOnExec(fileno(log_file_)); // Opening a file in append mode doesn't set the file pointer to the file's diff --git a/src/deps_log.cc b/src/deps_log.cc index 0567c95..191f300 100644 --- a/src/deps_log.cc +++ b/src/deps_log.cc @@ -413,7 +413,9 @@ bool DepsLog::OpenForWriteIfNeeded() { } // Set the buffer size to this and flush the file buffer after every record // to make sure records aren't written partially. - setvbuf(file_, NULL, _IOFBF, kMaxRecordSize + 1); + if (setvbuf(file_, NULL, _IOFBF, kMaxRecordSize + 1) != 0) { + return false; + } SetCloseOnExec(fileno(file_)); // Opening a file in append mode doesn't set the file pointer to the file's -- cgit v0.12 From ee2e2faa13a63168bcf63b6ec612881ea6ad7ae6 Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Sat, 31 Oct 2020 00:43:23 +0100 Subject: GitHub Actions: Run more tests on Ubuntu 20.04 (Docker) --- .clang-tidy | 11 ++++++++++ .github/workflows/linux.yml | 53 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..8968011 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,11 @@ +--- +Checks: ' + ,readability-avoid-const-params-in-decls, + ,readability-non-const-parameter, + ,readability-redundant-string-cstr, +' +WarningsAsErrors: ' + ,readability-avoid-const-params-in-decls, + ,readability-non-const-parameter, + ,readability-redundant-string-cstr, +' diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 511b92b..9062d98 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -70,3 +70,56 @@ jobs: asset_path: ./artifact/ninja-linux.zip asset_name: ninja-linux.zip asset_content_type: application/zip + + test: + runs-on: [ubuntu-latest] + container: + image: ubuntu:20.04 + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: | + apt update + apt install -y python3-pytest ninja-build clang-tidy python3-pip clang + pip3 install cmake==3.17.* + - name: Configure (GCC) + run: cmake -Bbuild-gcc -DCMAKE_BUILD_TYPE=Debug -G'Ninja Multi-Config' + + - name: Build (GCC, Debug) + run: cmake --build build-gcc --config Debug + - name: Unit tests (GCC, Debug) + run: ./build-gcc/Debug/ninja_test + - name: Python tests (GCC, Debug) + run: pytest-3 --color=yes ../.. + working-directory: build-gcc/Debug + + - name: Build (GCC, Release) + run: cmake --build build-gcc --config Release + - name: Unit tests (GCC, Release) + run: ./build-gcc/Release/ninja_test + - name: Python tests (GCC, Release) + run: pytest-3 --color=yes ../.. + working-directory: build-gcc/Release + + - name: Configure (Clang) + run: CC=clang CXX=clang++ cmake -Bbuild-clang -DCMAKE_BUILD_TYPE=Debug -G'Ninja Multi-Config' -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + + - name: Build (Clang, Debug) + run: cmake --build build-clang --config Debug + - name: Unit tests (Clang, Debug) + run: ./build-clang/Debug/ninja_test + - name: Python tests (Clang, Debug) + run: pytest-3 --color=yes ../.. + working-directory: build-clang/Debug + + - name: Build (Clang, Release) + run: cmake --build build-clang --config Release + - name: Unit tests (Clang, Release) + run: ./build-clang/Release/ninja_test + - name: Python tests (Clang, Release) + run: pytest-3 --color=yes ../.. + working-directory: build-clang/Release + + - name: clang-tidy + run: /usr/lib/llvm-10/share/clang/run-clang-tidy.py -header-filter=src + working-directory: build-clang -- cgit v0.12 From 7ea6c537d2968effb024634a6367a1a1b4cafeb4 Mon Sep 17 00:00:00 2001 From: Kevin Adler Date: Sat, 31 Oct 2020 00:35:44 -0500 Subject: Handle process signalling correctly on AIX POSIX shells set the exit code to 128 + the signal number, which coincidentally matches the layout used by the WIFSIGNALLED/WTERMSIG macros on most Unix-like systems, but not on AIX. Instead, AIX stores the signal value in the bottom 8 bits and also bits 16-23. The only time ninja currently handles signals correctly is when the shell used to call the program dies via signal. To handle both scenarios, we detect the shell exit code format and convert it to the format that the WIFSIGNALED/WTERMSIG macros expect. Fixes #1623 --- src/subprocess-posix.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc index 0c5f556..8e78540 100644 --- a/src/subprocess-posix.cc +++ b/src/subprocess-posix.cc @@ -154,6 +154,16 @@ ExitStatus Subprocess::Finish() { Fatal("waitpid(%d): %s", pid_, strerror(errno)); pid_ = -1; +#ifdef _AIX + if (WIFEXITED(status) && WEXITSTATUS(status) & 0x80) { + // Map the shell's exit code used for signal failure (128 + signal) to the + // status code expected by AIX WIFSIGNALED and WTERMSIG macros which, unlike + // other systems, uses a different bit layout. + int signal = WEXITSTATUS(status) & 0x7f; + status = (signal << 16) | signal; + } +#endif + if (WIFEXITED(status)) { int exit = WEXITSTATUS(status); if (exit == 0) -- cgit v0.12 From f92b5b61f38d688fa7ee77a76fc59ecbfc75f11b Mon Sep 17 00:00:00 2001 From: Nathan Mulcahey Date: Tue, 3 Nov 2020 08:41:20 -0800 Subject: cmake: Use ${CMAKE_COMMAND} instead of `cmake` Not all users have `cmake` on their PATH and this causes a build failure. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0b2fef..e02849d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,7 +138,7 @@ if(platform_supports_ninja_browse) OUTPUT build/browse_py.h MAIN_DEPENDENCY src/browse.py DEPENDS src/inline.sh - COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/build + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/build COMMAND src/inline.sh kBrowsePy < src/browse.py > ${CMAKE_BINARY_DIR}/build/browse_py.h -- cgit v0.12 From 9fa3491284af9a595cd46c6b230bcffb0ab8aec9 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 2 Jun 2020 18:07:40 -0700 Subject: [clang-tidy] remove pointless string init Found with readability-redundant-string-init Signed-off-by: Rosen Penev --- .clang-tidy | 2 ++ src/string_piece_util_test.cc | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 8968011..df4c1ed 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,9 +3,11 @@ Checks: ' ,readability-avoid-const-params-in-decls, ,readability-non-const-parameter, ,readability-redundant-string-cstr, + ,readability-redundant-string-init, ' WarningsAsErrors: ' ,readability-avoid-const-params-in-decls, ,readability-non-const-parameter, ,readability-redundant-string-cstr, + ,readability-redundant-string-init, ' diff --git a/src/string_piece_util_test.cc b/src/string_piece_util_test.cc index b77ae84..61586dd 100644 --- a/src/string_piece_util_test.cc +++ b/src/string_piece_util_test.cc @@ -31,7 +31,7 @@ TEST(StringPieceUtilTest, SplitStringPiece) { } { - string empty(""); + string empty; vector list = SplitStringPiece(empty, ':'); EXPECT_EQ(list.size(), 1); @@ -82,7 +82,7 @@ TEST(StringPieceUtilTest, JoinStringPiece) { } { - string empty(""); + string empty; vector list = SplitStringPiece(empty, ':'); EXPECT_EQ("", JoinStringPiece(list, ':')); -- cgit v0.12 From 8cf4a393faf5784c2ce6b8307a771924d91825ca Mon Sep 17 00:00:00 2001 From: hdf89shfdfs Date: Fri, 13 Nov 2020 07:07:02 -0500 Subject: Fix mulit-configuration bug. This affected users who use multi-configuration generators for building ninja. --- CMakeLists.txt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e02849d..0b56e31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,18 @@ cmake_minimum_required(VERSION 3.15) include(CheckIncludeFileCXX) +include(CheckIPOSupported) project(ninja) # --- optional link-time optimization -if(CMAKE_BUILD_TYPE MATCHES "Release") - include(CheckIPOSupported) - check_ipo_supported(RESULT lto_supported OUTPUT error) - - if(lto_supported) - message(STATUS "IPO / LTO enabled") - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) - else() - message(STATUS "IPO / LTO not supported: <${error}>") - endif() +check_ipo_supported(RESULT lto_supported OUTPUT error) + +if(lto_supported) + message(STATUS "IPO / LTO enabled") + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE) +else() + message(STATUS "IPO / LTO not supported: <${error}>") endif() # --- compiler flags -- cgit v0.12 From 1cb029b33cefe5a5937ca446a00528787f5bafe4 Mon Sep 17 00:00:00 2001 From: Kevin Adler Date: Mon, 2 Nov 2020 11:21:17 -0600 Subject: Use internal getopt for IBM i and AIX --- CMakeLists.txt | 10 ++++++---- src/manifest_parser_perftest.cc | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e02849d..efc4090 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,9 @@ if(WIN32) endif() else() target_sources(libninja PRIVATE src/subprocess-posix.cc) + if(CMAKE_SYSTEM_NAME STREQUAL "OS400" OR CMAKE_SYSTEM_NAME STREQUAL "AIX") + target_sources(libninja PRIVATE src/getopt.c) + endif() endif() #Fixes GetActiveProcessorCount on MinGW @@ -119,11 +122,10 @@ if(MINGW) target_compile_definitions(libninja PRIVATE _WIN32_WINNT=0x0601 __USE_MINGW_ANSI_STDIO=1) endif() -# On IBM i (identified as "OS400" for compatibility reasons), this fixes missing -# PRId64 (and others) at compile time, and links to libutil for getopt_long -if(CMAKE_SYSTEM_NAME STREQUAL "OS400") +# On IBM i (identified as "OS400" for compatibility reasons) and AIX, this fixes missing +# PRId64 (and others) at compile time in C++ sources +if(CMAKE_SYSTEM_NAME STREQUAL "OS400" OR CMAKE_SYSTEM_NAME STREQUAL "AIX") string(APPEND CMAKE_CXX_FLAGS " -D__STDC_FORMAT_MACROS") - string(APPEND CMAKE_EXE_LINKER_FLAGS " -lutil") endif() # Main executable is library plus main() function. diff --git a/src/manifest_parser_perftest.cc b/src/manifest_parser_perftest.cc index 92f5e13..853d8e0 100644 --- a/src/manifest_parser_perftest.cc +++ b/src/manifest_parser_perftest.cc @@ -25,6 +25,9 @@ #ifdef _WIN32 #include "getopt.h" #include +#elif defined(_AIX) +#include "getopt.h" +#include #else #include #include -- cgit v0.12 From b52970e86b7b487da182e3b767b256c5e577d269 Mon Sep 17 00:00:00 2001 From: Kevin Adler Date: Mon, 2 Nov 2020 11:22:10 -0600 Subject: Add libperfstat to AIX CMake build --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index efc4090..7cf6006 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,11 @@ else() if(CMAKE_SYSTEM_NAME STREQUAL "OS400" OR CMAKE_SYSTEM_NAME STREQUAL "AIX") target_sources(libninja PRIVATE src/getopt.c) endif() + + # Needed for perfstat_cpu_total + if(CMAKE_SYSTEM_NAME STREQUAL "AIX") + target_link_libraries(libninja PUBLIC "-lperfstat") + endif() endif() #Fixes GetActiveProcessorCount on MinGW -- cgit v0.12 From 92fc37555fd74b9a3848c956df49a516906af711 Mon Sep 17 00:00:00 2001 From: Kevin Adler Date: Fri, 13 Nov 2020 15:30:51 -0600 Subject: Fix test crashes on AIX Both hash_collision_bench and manifest_parser_perftest crash on AIX with terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc IOT/Abort trap (core dumped) 32-bit AIX applications by default allocates only a single 256M segment for stack and heap for 32-bit applications, which is insufficient for these tests. When building these tests on AIX in 32-bit mode, increase the max number of segments so they will run without crashing. --- CMakeLists.txt | 6 ++++++ configure.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cf6006..7009214 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,6 +203,12 @@ if(BUILD_TESTING) target_link_libraries(${perftest} PRIVATE libninja libninja-re2c) endforeach() + if(CMAKE_SYSTEM_NAME STREQUAL "AIX" AND CMAKE_SIZEOF_VOID_P EQUAL 4) + # These tests require more memory than will fit in the standard AIX shared stack/heap (256M) + target_link_libraries(hash_collision_bench PRIVATE "-Wl,-bmaxdata:0x80000000") + target_link_libraries(manifest_parser_perftest PRIVATE "-Wl,-bmaxdata:0x80000000") + endif() + add_test(NinjaTest ninja_test) endif() diff --git a/configure.py b/configure.py index 48c4821..cded265 100755 --- a/configure.py +++ b/configure.py @@ -596,6 +596,11 @@ all_targets += ninja_test n.comment('Ancillary executables.') +if platform.is_aix() and '-maix64' not in ldflags: + # Both hash_collision_bench and manifest_parser_perftest require more + # memory than will fit in the standard 32-bit AIX shared stack/heap (256M) + libs.append('-Wl,-bmaxdata:0x80000000') + for name in ['build_log_perftest', 'canon_perftest', 'depfile_parser_perftest', -- cgit v0.12 From a8ad5332894e5276e837b90d378a097024dcfad1 Mon Sep 17 00:00:00 2001 From: Kevin Adler Date: Fri, 13 Nov 2020 15:35:06 -0600 Subject: Fix buffer overread in hash_collision_benchmark.cc The randomly generated command strings are not null-terminated and implicitly converted to StringPiece objects, which will use strlen to determine how long the passed `char*` is. Without the null terminator, this results in undefined behavior and regularly causes crashes on AIX. --- src/hash_collision_bench.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hash_collision_bench.cc b/src/hash_collision_bench.cc index 52ff56d..8f37ed0 100644 --- a/src/hash_collision_bench.cc +++ b/src/hash_collision_bench.cc @@ -27,9 +27,10 @@ int random(int low, int high) { void RandomCommand(char** s) { int len = random(5, 100); - *s = new char[len]; + *s = new char[len+1]; for (int i = 0; i < len; ++i) (*s)[i] = (char)random(32, 127); + (*s)[len] = '\0'; } int main() { -- cgit v0.12 From 242b7dd90007e1ac493cdf59a0a5980a72409efa Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Mon, 23 Nov 2020 16:41:04 +0100 Subject: GitHub Actions: Build Universal Binary for macOS --- .github/workflows/macos.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 411cfe1..4ea958f 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -8,7 +8,7 @@ on: jobs: build: - runs-on: macOS-latest + runs-on: macos-11.0 steps: - uses: actions/checkout@v2 @@ -21,8 +21,9 @@ jobs: env: MACOSX_DEPLOYMENT_TARGET: 10.12 run: | - cmake -DCMAKE_BUILD_TYPE=Release -B build - cmake --build build --parallel --config Release + sudo xcode-select -s /Applications/Xcode_12.2.app + cmake -Bbuild -GXcode '-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64' + cmake --build build --config Release - name: Test ninja run: ctest -vv @@ -32,7 +33,7 @@ jobs: shell: bash run: | mkdir artifact - 7z a artifact/ninja-mac.zip ./build/ninja + 7z a artifact/ninja-mac.zip ./build/Release/ninja # Upload ninja binary archive as an artifact - name: Upload artifact -- cgit v0.12 From ed056bdd8c8d578a9952bd93b76f29c14199c85b Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Sat, 28 Nov 2020 12:21:05 +0100 Subject: mark this 1.10.2.git --- src/version.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.cc b/src/version.cc index f25a30a..97afa7e 100644 --- a/src/version.cc +++ b/src/version.cc @@ -20,7 +20,7 @@ using namespace std; -const char* kNinjaVersion = "1.10.1.git"; +const char* kNinjaVersion = "1.10.2.git"; void ParseVersion(const string& version, int* major, int* minor) { size_t end = version.find('.'); -- cgit v0.12