diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2016-10-10 23:07:29 -0700 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2016-10-10 23:07:29 -0700 |
| commit | 9e1d40e4dc313de2e6de0ac4f60a2df224215ae2 (patch) | |
| tree | bc60827a29151d7829f4b6fdeaa8d6f60e8f8258 /toolsrc/src | |
| parent | c494892eb24ce6f84c777f24dfceb71a4988fd24 (diff) | |
| parent | 23f187a45766057ef76baba9dc912270b403cb7d (diff) | |
| download | vcpkg-9e1d40e4dc313de2e6de0ac4f60a2df224215ae2.tar.gz vcpkg-9e1d40e4dc313de2e6de0ac4f60a2df224215ae2.zip | |
Merge branch 'master' of https://github.com/microsoft/vcpkg
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/Stopwatch.cpp | 104 | ||||
| -rw-r--r-- | toolsrc/src/commands_installation.cpp | 2 | ||||
| -rw-r--r-- | toolsrc/src/main.cpp | 2 | ||||
| -rw-r--r-- | toolsrc/src/post_build_lint.cpp | 49 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_System.cpp | 6 |
5 files changed, 154 insertions, 9 deletions
diff --git a/toolsrc/src/Stopwatch.cpp b/toolsrc/src/Stopwatch.cpp new file mode 100644 index 000000000..035d54c2b --- /dev/null +++ b/toolsrc/src/Stopwatch.cpp @@ -0,0 +1,104 @@ +#include "Stopwatch.h" +#include "vcpkg_Checks.h" + +namespace vcpkg +{ + Stopwatch Stopwatch::createUnstarted() + { + return Stopwatch(); + } + + Stopwatch Stopwatch::createStarted() + { + return Stopwatch().start(); + } + + bool Stopwatch::isRunning() const + { + return this->m_isRunning; + } + + Stopwatch& Stopwatch::start() + { + Checks::check_exit(!this->m_isRunning, "This stopwatch is already running."); + this->m_isRunning = true; + this->m_startTick = std::chrono::high_resolution_clock::now(); + return *this; + } + + Stopwatch& Stopwatch::stop() + { + auto tick = std::chrono::high_resolution_clock::now(); + Checks::check_exit(this->m_isRunning, "This stopwatch is already stopped."); + this->m_isRunning = false; + this->m_elapsedNanos += tick - this->m_startTick; + return *this; + } + + Stopwatch& Stopwatch::reset() + { + this->m_elapsedNanos = std::chrono::nanoseconds(); + this->m_isRunning = false; + return *this; + } + + std::string Stopwatch::toString() const + { + using std::chrono::hours; + using std::chrono::minutes; + using std::chrono::seconds; + using std::chrono::milliseconds; + using std::chrono::microseconds; + using std::chrono::nanoseconds; + using std::chrono::duration_cast; + + auto nanos = elapsedNanos(); + auto nanos_as_double = static_cast<double>(nanos.count()); + + if (duration_cast<hours>(nanos) > hours()) + { + auto t = nanos_as_double / duration_cast<nanoseconds>(hours(1)).count(); + return Strings::format("%.4g h", t); + } + + if (duration_cast<minutes>(nanos) > minutes()) + { + auto t = nanos_as_double / duration_cast<nanoseconds>(minutes(1)).count(); + return Strings::format("%.4g min", t); + } + + if (duration_cast<seconds>(nanos) > seconds()) + { + auto t = nanos_as_double / duration_cast<nanoseconds>(seconds(1)).count(); + return Strings::format("%.4g s", t); + } + + if (duration_cast<milliseconds>(nanos) > milliseconds()) + { + auto t = nanos_as_double / duration_cast<nanoseconds>(milliseconds(1)).count(); + return Strings::format("%.4g ms", t); + } + + if (duration_cast<microseconds>(nanos) > microseconds()) + { + auto t = nanos_as_double / duration_cast<nanoseconds>(microseconds(1)).count(); + return Strings::format("%.4g micros", t); + } + + return Strings::format("%.4g ns", nanos_as_double); + } + + Stopwatch::Stopwatch() : m_isRunning(false), m_elapsedNanos(), m_startTick() + { + } + + std::chrono::nanoseconds Stopwatch::elapsedNanos() const + { + if (this->m_isRunning) + { + return std::chrono::high_resolution_clock::now() - this->m_startTick + this->m_elapsedNanos; + } + + return this->m_elapsedNanos; + } +} diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 6fe6aa9a1..7e7da9e3f 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -31,7 +31,7 @@ namespace vcpkg port_dir.generic_wstring(), ports_cmake_script_path.generic_wstring()); - System::Stopwatch timer; + System::Stopwatch2 timer; timer.start(); int return_code = System::cmd_execute(command); timer.stop(); diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index f3d68f5dd..2200cd105 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -153,7 +153,7 @@ static void loadConfig() } } -static System::Stopwatch g_timer; +static System::Stopwatch2 g_timer; static std::string trim_path_from_command_line(const std::string& full_command_line) { diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 2b2812d73..1905b48f9 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -4,6 +4,7 @@ #include <iterator> #include <functional> #include "vcpkg_System.h" +#include <set> namespace fs = std::tr2::sys; @@ -279,16 +280,43 @@ namespace vcpkg static lint_status check_architecture(const std::string& expected_architecture, const std::vector<fs::path>& files) { + // static const std::regex machine_regex = std::regex(R"###([0-9A-F]+ machine \([^)]+\))###"); + + // Parenthesis is there to avoid some other occurrences of the word "machine". Those don't match the expected regex. + static const std::string machine_string_scan = "machine ("; + std::vector<file_and_arch> binaries_with_invalid_architecture; + std::set<fs::path> binaries_with_no_architecture(files.cbegin(), files.cend()); + for (const fs::path& f : files) { - const std::wstring cmd_line = Strings::wformat(LR"("%s" /headers "%s" | findstr machine)", DUMPBIN_EXE.native(), f.native()); + const std::wstring cmd_line = Strings::wformat(LR"("%s" /headers "%s")", DUMPBIN_EXE.native(), f.native()); System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); - if (Strings::case_insensitive_ascii_find(ec_data.output, expected_architecture) == ec_data.output.end()) + const std::string& s = ec_data.output; + + for (size_t start, end, idx = s.find(machine_string_scan); idx != std::string::npos; idx = s.find(machine_string_scan, end)) { - binaries_with_invalid_architecture.push_back({f, ec_data.output}); + // Skip the space directly in front of "machine" and find the previous one. Get the index of the char after it. + // Go no further than a newline + start = std::max(s.find_last_of('\n', idx - 2) + 1, s.find_last_of(' ', idx - 2) + 1); + + // Find the first close-parenthesis. Get the index of the char after it + // Go no futher than a newline + end = std::min(s.find_first_of('\n', idx) + 1, s.find_first_of(')', idx) + 1); + + std::string machine_line(s.substr(start, end - start)); + + if (Strings::case_insensitive_ascii_find(machine_line, expected_architecture) != machine_line.end()) + { + binaries_with_no_architecture.erase(f); + } + else + { + binaries_with_invalid_architecture.push_back({f, machine_line}); + break; // If one erroneous entry is found, we can abort this file + } } } @@ -299,7 +327,20 @@ namespace vcpkg for (const file_and_arch& b : binaries_with_invalid_architecture) { System::println(" %s", b.file.generic_string()); - System::println("Expected %s, but was:\n %s", expected_architecture, b.actual_arch); + System::println("Expected %s, but was: %s", expected_architecture, b.actual_arch); + } + System::println(""); + + return lint_status::ERROR; + } + + if (!binaries_with_no_architecture.empty()) + { + System::println(System::color::warning, "Unable to detect architecture in the following files:"); + System::println(""); + for (const fs::path& b : binaries_with_no_architecture) + { + System::println(" %s", b.generic_string()); } System::println(""); diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp index 4dc37857d..cc7080069 100644 --- a/toolsrc/src/vcpkg_System.cpp +++ b/toolsrc/src/vcpkg_System.cpp @@ -90,20 +90,20 @@ namespace vcpkg {namespace System return ret; } - void Stopwatch::start() + void Stopwatch2::start() { static_assert(sizeof(start_time) == sizeof(LARGE_INTEGER), ""); QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&start_time)); } - void Stopwatch::stop() + void Stopwatch2::stop() { QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&end_time)); QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(&freq)); } - double Stopwatch::microseconds() const + double Stopwatch2::microseconds() const { return (reinterpret_cast<const LARGE_INTEGER*>(&end_time)->QuadPart - reinterpret_cast<const LARGE_INTEGER*>(&start_time)->QuadPart) * 1000000.0 / reinterpret_cast<const LARGE_INTEGER*>(&freq)->QuadPart; |
