mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-29 03:34:26 +08:00
Introduce GlobalState struct
This commit is contained in:
parent
8fc510e1f9
commit
e237682cad
@ -12,8 +12,6 @@
|
||||
|
||||
namespace vcpkg
|
||||
{
|
||||
extern bool g_feature_packages;
|
||||
|
||||
struct Dependency
|
||||
{
|
||||
Features depend;
|
||||
|
13
toolsrc/include/vcpkg_GlobalState.h
Normal file
13
toolsrc/include/vcpkg_GlobalState.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <vcpkg_Chrono.h>
|
||||
|
||||
namespace vcpkg
|
||||
{
|
||||
struct GlobalState
|
||||
{
|
||||
static ElapsedTime timer;
|
||||
static bool debugging;
|
||||
static bool feature_packages;
|
||||
};
|
||||
}
|
@ -6,8 +6,6 @@
|
||||
|
||||
namespace vcpkg
|
||||
{
|
||||
extern bool g_debugging;
|
||||
|
||||
StatusParagraphs database_load_check(const VcpkgPaths& paths);
|
||||
|
||||
void write_update(const VcpkgPaths& paths, const StatusParagraph& p);
|
||||
|
@ -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())
|
||||
{
|
||||
|
@ -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";
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
10
toolsrc/src/vcpkg_GlobalState.cpp
Normal file
10
toolsrc/src/vcpkg_GlobalState.cpp
Normal file
@ -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;
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -161,6 +161,7 @@
|
||||
<ClInclude Include="..\include\vcpkg_Chrono.h" />
|
||||
<ClInclude Include="..\include\triplet.h" />
|
||||
<ClInclude Include="..\include\vcpkglib.h" />
|
||||
<ClInclude Include="..\include\vcpkg_GlobalState.h" />
|
||||
<ClInclude Include="..\include\vcpkg_Parse.h" />
|
||||
<ClInclude Include="..\include\vcpkg_Checks.h" />
|
||||
<ClInclude Include="..\include\VcpkgCmdArguments.h" />
|
||||
@ -227,6 +228,7 @@
|
||||
<ClCompile Include="..\src\StatusParagraph.cpp" />
|
||||
<ClCompile Include="..\src\StatusParagraphs.cpp" />
|
||||
<ClCompile Include="..\src\triplet.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg_GlobalState.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg_Parse.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg_Checks.cpp" />
|
||||
<ClCompile Include="..\src\VcpkgCmdArguments.cpp" />
|
||||
|
@ -177,6 +177,9 @@
|
||||
<ClCompile Include="..\src\vcpkg_Parse.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\vcpkg_GlobalState.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\include\SourceParagraph.h">
|
||||
@ -302,5 +305,8 @@
|
||||
<ClInclude Include="..\include\vcpkg_Parse.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\vcpkg_GlobalState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user