Introduce GlobalState struct
MODIFY
include/SourceParagraph.h
include/SourceParagraph.h
namespace vcpkg
{
- extern bool g_feature_packages;
-
struct Dependency
{
Features depend;

ADD
include/vcpkg_GlobalState.h
+#pragma once
+
+#include <vcpkg_Chrono.h>
+
+namespace vcpkg
+{
+ struct GlobalState
+ {
+ static ElapsedTime timer;
+ static bool debugging;
+ static bool feature_packages;
+ };
+}
\ No newline at end of file

MODIFY
include/vcpkglib.h
include/vcpkglib.h
namespace vcpkg
{
- extern bool g_debugging;
-
StatusParagraphs database_load_check(const VcpkgPaths& paths);
void write_update(const VcpkgPaths& paths, const StatusParagraph& p);

MODIFY
src/Paragraphs.cpp
src/Paragraphs.cpp
#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())
{

MODIFY
src/SourceParagraph.cpp
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";

MODIFY
src/VcpkgCmdArguments.cpp
src/VcpkgCmdArguments.cpp
#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;
}

MODIFY
src/commands_search.cpp
src/commands_search.cpp
#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);
}

MODIFY
src/vcpkg.cpp
src/vcpkg.cpp
#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);

MODIFY
src/vcpkg_Build.cpp
src/vcpkg_Build.cpp
#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)
{

ADD
src/vcpkg_GlobalState.cpp
+#include "pch.h"
+
+#include "vcpkg_GlobalState.h"
+
+namespace vcpkg
+{
+ ElapsedTime GlobalState::timer;
+ bool GlobalState::debugging = false;
+ bool GlobalState::feature_packages = false;
+}

MODIFY
src/vcpkg_System.cpp
src/vcpkg_System.cpp
#include "pch.h"
#include "vcpkg_Checks.h"
+#include "vcpkg_GlobalState.h"
#include "vcpkg_System.h"
#include "vcpkglib.h"
@@ -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);
}

MODIFY
src/vcpkglib.cpp
src/vcpkglib.cpp
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)

MODIFY
vcpkglib/vcpkglib.vcxproj
vcpkglib/vcpkglib.vcxproj
<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" />
<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" />

MODIFY
vcpkglib/vcpkglib.vcxproj.filters
vcpkglib/vcpkglib.vcxproj.filters
<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">
<ClInclude Include="..\include\vcpkg_Parse.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\include\vcpkg_GlobalState.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file

Introduce GlobalState struct