diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-08-23 16:17:53 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-08-24 16:29:40 -0700 |
| commit | e237682cad4eaa582a10b5ad03a59ca6449e0795 (patch) | |
| tree | 6850152901be7ab8ea7462fac572850d68a2dbde /toolsrc/src | |
| parent | 8fc510e1f946208409bd8ba1159b2e19bf553909 (diff) | |
| download | vcpkg-e237682cad4eaa582a10b5ad03a59ca6449e0795.tar.gz vcpkg-e237682cad4eaa582a10b5ad03a59ca6449e0795.zip | |
Introduce GlobalState struct
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/Paragraphs.cpp | 3 | ||||
| -rw-r--r-- | toolsrc/src/SourceParagraph.cpp | 1 | ||||
| -rw-r--r-- | toolsrc/src/VcpkgCmdArguments.cpp | 3 | ||||
| -rw-r--r-- | toolsrc/src/commands_search.cpp | 3 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg.cpp | 14 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_Build.cpp | 7 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_GlobalState.cpp | 10 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_System.cpp | 9 | ||||
| -rw-r--r-- | toolsrc/src/vcpkglib.cpp | 2 |
9 files changed, 32 insertions, 20 deletions
diff --git a/toolsrc/src/Paragraphs.cpp b/toolsrc/src/Paragraphs.cpp index 3a30f66a3..a7dee4fd3 100644 --- a/toolsrc/src/Paragraphs.cpp +++ b/toolsrc/src/Paragraphs.cpp @@ -3,6 +3,7 @@ #include "ParagraphParseResult.h" #include "Paragraphs.h" #include "vcpkg_Files.h" +#include "vcpkg_GlobalState.h" #include "vcpkg_Util.h" using namespace vcpkg::Parse; @@ -210,7 +211,7 @@ namespace vcpkg::Paragraphs if (auto vector_pghs = pghs.get()) { auto csf = SourceControlFile::parse_control_file(std::move(*vector_pghs)); - if (!g_feature_packages) + if (!GlobalState::feature_packages) { if (auto ptr = csf.get()) { diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index 54f34cbd3..c69770ae1 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -13,7 +13,6 @@ namespace vcpkg { using namespace vcpkg::Parse; - bool g_feature_packages = false; namespace Fields { static const std::string BUILD_DEPENDS = "Build-Depends"; diff --git a/toolsrc/src/VcpkgCmdArguments.cpp b/toolsrc/src/VcpkgCmdArguments.cpp index ebf4c5fc5..a72e5226f 100644 --- a/toolsrc/src/VcpkgCmdArguments.cpp +++ b/toolsrc/src/VcpkgCmdArguments.cpp @@ -3,6 +3,7 @@ #include "VcpkgCmdArguments.h" #include "metrics.h" #include "vcpkg_Commands.h" +#include "vcpkg_GlobalState.h" #include "vcpkg_System.h" namespace vcpkg @@ -119,7 +120,7 @@ namespace vcpkg } if (arg == "--featurepackages") { - g_feature_packages = true; + GlobalState::feature_packages = true; continue; } diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index b1bd7ea6f..529d52a8b 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -3,6 +3,7 @@ #include "Paragraphs.h" #include "SourceParagraph.h" #include "vcpkg_Commands.h" +#include "vcpkg_GlobalState.h" #include "vcpkg_System.h" #include "vcpkglib.h" @@ -90,7 +91,7 @@ namespace vcpkg::Commands::Search if (!sources_and_errors.errors.empty()) { - if (vcpkg::g_debugging) + if (GlobalState::debugging) { print_error_message(sources_and_errors.errors); } diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 738b7b284..3ccb33aad 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -6,6 +6,7 @@ #include "vcpkg_Chrono.h" #include "vcpkg_Commands.h" #include "vcpkg_Files.h" +#include "vcpkg_GlobalState.h" #include "vcpkg_Input.h" #include "vcpkg_Strings.h" #include "vcpkg_System.h" @@ -184,17 +185,16 @@ static std::string trim_path_from_command_line(const std::string& full_command_l return std::string(it, full_command_line.cend()); } -static ElapsedTime g_timer; - int wmain(const int argc, const wchar_t* const* const argv) { if (argc == 0) std::abort(); - g_timer = ElapsedTime::create_started(); + GlobalState::timer = ElapsedTime::create_started(); + atexit([]() { - auto elapsed_us = g_timer.microseconds(); + auto elapsed_us = GlobalState::timer.microseconds(); Metrics::track_metric("elapsed_us", elapsed_us); - g_debugging = false; + GlobalState::debugging = false; Metrics::flush(); }); @@ -209,9 +209,9 @@ int wmain(const int argc, const wchar_t* const* const argv) if (auto p = args.printmetrics.get()) Metrics::set_print_metrics(*p); if (auto p = args.sendmetrics.get()) Metrics::set_send_metrics(*p); - if (auto p = args.debug.get()) g_debugging = *p; + if (auto p = args.debug.get()) GlobalState::debugging = *p; - if (g_debugging) + if (GlobalState::debugging) { inner(args); Checks::exit_fail(VCPKG_LINE_INFO); diff --git a/toolsrc/src/vcpkg_Build.cpp b/toolsrc/src/vcpkg_Build.cpp index ca89ccf37..d4632afaa 100644 --- a/toolsrc/src/vcpkg_Build.cpp +++ b/toolsrc/src/vcpkg_Build.cpp @@ -8,6 +8,7 @@ #include "vcpkg_Chrono.h" #include "vcpkg_Commands.h" #include "vcpkg_Enums.h" +#include "vcpkg_GlobalState.h" #include "vcpkg_System.h" #include "vcpkg_optional.h" #include "vcpkglib.h" @@ -77,7 +78,7 @@ namespace vcpkg::Build std::wstring make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset) { const wchar_t* tonull = L" >nul"; - if (g_debugging) + if (GlobalState::debugging) { tonull = L""; } @@ -155,7 +156,7 @@ namespace vcpkg::Build const auto cmd_set_environment = make_build_env_cmd(pre_build_info, toolset); std::string features; - if (g_feature_packages) + if (GlobalState::feature_packages) { if (config.feature_list) { @@ -212,7 +213,7 @@ namespace vcpkg::Build { return {BuildResult::POST_BUILD_CHECKS_FAILED, {}}; } - if (g_feature_packages) + if (GlobalState::feature_packages) { if (config.feature_list) { diff --git a/toolsrc/src/vcpkg_GlobalState.cpp b/toolsrc/src/vcpkg_GlobalState.cpp new file mode 100644 index 000000000..cae2b2f8e --- /dev/null +++ b/toolsrc/src/vcpkg_GlobalState.cpp @@ -0,0 +1,10 @@ +#include "pch.h" + +#include "vcpkg_GlobalState.h" + +namespace vcpkg +{ + ElapsedTime GlobalState::timer; + bool GlobalState::debugging = false; + bool GlobalState::feature_packages = false; +} diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp index 2ad120e4c..2d6246d19 100644 --- a/toolsrc/src/vcpkg_System.cpp +++ b/toolsrc/src/vcpkg_System.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "vcpkg_Checks.h" +#include "vcpkg_GlobalState.h" #include "vcpkg_System.h" #include "vcpkglib.h" @@ -94,7 +95,7 @@ namespace vcpkg::System }; // Flush stdout before launching external process - fflush(nullptr); + fflush(nullptr); std::wstring env_cstr; @@ -151,7 +152,7 @@ namespace vcpkg::System int cmd_execute(const CWStringView cmd_line) { // Flush stdout before launching external process - fflush(nullptr); + fflush(nullptr); // Basically we are wrapping it in quotes const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s")###", cmd_line); @@ -302,7 +303,7 @@ namespace vcpkg::Debug { void println(const CStringView message) { - if (g_debugging) + if (GlobalState::debugging) { System::println("[DEBUG] %s", message); } @@ -310,7 +311,7 @@ namespace vcpkg::Debug void println(const System::Color c, const CStringView message) { - if (g_debugging) + if (GlobalState::debugging) { System::println(c, "[DEBUG] %s", message); } diff --git a/toolsrc/src/vcpkglib.cpp b/toolsrc/src/vcpkglib.cpp index 6e90695de..b52f49d62 100644 --- a/toolsrc/src/vcpkglib.cpp +++ b/toolsrc/src/vcpkglib.cpp @@ -9,8 +9,6 @@ namespace vcpkg { - bool g_debugging = false; - static StatusParagraphs load_current_database(Files::Filesystem& fs, const fs::path& vcpkg_dir_status_file, const fs::path& vcpkg_dir_status_file_old) |
