From a721db2c1fbfc1b87065b0b43e32249117e53242 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 16:06:36 -0800 Subject: Refactor: create new Paragraphs.h/cpp --- toolsrc/src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'toolsrc/src/main.cpp') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 2200cd105..22c45e5ab 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -12,6 +12,7 @@ #include "vcpkg_Files.h" #include "vcpkg_System.h" #include "vcpkg_Input.h" +#include "Paragraphs.h" using namespace vcpkg; @@ -115,7 +116,7 @@ static void loadConfig() std::string config_contents = Files::get_contents(localappdata / "vcpkg" / "config").get_or_throw(); std::unordered_map keys; - auto pghs = parse_paragraphs(config_contents); + auto pghs = Paragraphs::parse_paragraphs(config_contents); if (pghs.size() > 0) keys = pghs[0]; -- cgit v1.2.3 From c91d8e41b60653b652b11c641f7a5b3d3eab7f6b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:31:41 -0800 Subject: Introduce vcpkg_info.h/cpp --- toolsrc/src/main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'toolsrc/src/main.cpp') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 22c45e5ab..70527ca1d 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -13,6 +13,7 @@ #include "vcpkg_System.h" #include "vcpkg_Input.h" #include "Paragraphs.h" +#include "vcpkg_info.h" using namespace vcpkg; @@ -192,7 +193,7 @@ int wmain(const int argc, const wchar_t* const* const argv) Flush(); }); - TrackProperty("version", version()); + TrackProperty("version", Info::version()); const std::string trimmed_command_line = trim_path_from_command_line(Strings::utf16_to_utf8(GetCommandLineW())); TrackProperty("cmdline", trimmed_command_line); @@ -234,10 +235,10 @@ int wmain(const int argc, const wchar_t* const* const argv) std::cerr << "vcpkg.exe has crashed.\n" << "Please send an email to:\n" - << " vcpkg@microsoft.com\n" + << " " << Info::email() << "\n" << "containing a brief summary of what you were trying to do and the following data blob:\n" << "\n" - << "Version=" << version() << "\n" + << "Version=" << Info::version() << "\n" << "EXCEPTION='" << exc_msg << "'\n" << "CMD=\n"; for (int x = 0; x < argc; ++x) -- cgit v1.2.3 From a1d9478103cfc88b1a3ea3960bdd7a75dea8d0d6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:38:39 -0800 Subject: Don't #include "vcpkg.h" --- toolsrc/src/main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'toolsrc/src/main.cpp') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 70527ca1d..f937be7f1 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -5,7 +5,6 @@ #include #include #include -#include "vcpkg.h" #include "vcpkg_Commands.h" #include "metrics.h" #include -- cgit v1.2.3 From 1310e9e052de50a8d53bc9b88696f8b6c61bece6 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Mon, 12 Dec 2016 14:03:13 -0800 Subject: Add SQM User Id to metrics --- toolsrc/src/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'toolsrc/src/main.cpp') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index f937be7f1..5e9dcf7ff 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -197,6 +197,7 @@ int wmain(const int argc, const wchar_t* const* const argv) const std::string trimmed_command_line = trim_path_from_command_line(Strings::utf16_to_utf8(GetCommandLineW())); TrackProperty("cmdline", trimmed_command_line); loadConfig(); + TrackProperty("sqmuser", GetSQMUser()); const vcpkg_cmd_arguments args = vcpkg_cmd_arguments::create_from_command_line(argc, argv); -- cgit v1.2.3 From aad0cc4c042aad87b2b52eded0e465ed01e799c1 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 16 Dec 2016 19:40:58 -0800 Subject: Files::get_contents() -> Files::read_contents() --- toolsrc/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src/main.cpp') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 5e9dcf7ff..7703c541f 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -113,7 +113,7 @@ static void loadConfig() try { - std::string config_contents = Files::get_contents(localappdata / "vcpkg" / "config").get_or_throw(); + std::string config_contents = Files::read_contents(localappdata / "vcpkg" / "config").get_or_throw(); std::unordered_map keys; auto pghs = Paragraphs::parse_paragraphs(config_contents); -- cgit v1.2.3 From df2a05e8546281135c6ea12430734d74371bcf46 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Jan 2017 17:35:33 -0800 Subject: Introduce Command namespace. Refactoring --- toolsrc/src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'toolsrc/src/main.cpp') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 7703c541f..8490dc81b 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -21,7 +21,7 @@ bool g_debugging = false; void invalid_command(const std::string& cmd) { System::println(System::color::error, "invalid command: %s", cmd); - print_usage(); + Commands::Helpers::print_usage(); exit(EXIT_FAILURE); } @@ -30,11 +30,11 @@ static void inner(const vcpkg_cmd_arguments& args) TrackProperty("command", args.command); if (args.command.empty()) { - print_usage(); + Commands::Helpers::print_usage(); exit(EXIT_FAILURE); } - if (auto command_function = find_command(args.command, get_available_commands_type_c())) + if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_c())) { return command_function(args); } @@ -66,7 +66,7 @@ static void inner(const vcpkg_cmd_arguments& args) int exit_code = _wchdir(paths.root.c_str()); Checks::check_exit(exit_code == 0, "Changing the working dir failed"); - if (auto command_function = find_command(args.command, get_available_commands_type_b())) + if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_b())) { return command_function(args, paths); } @@ -91,7 +91,7 @@ static void inner(const vcpkg_cmd_arguments& args) Input::check_triplet(default_target_triplet, paths); - if (auto command_function = find_command(args.command, get_available_commands_type_a())) + if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_a())) { return command_function(args, paths, default_target_triplet); } -- cgit v1.2.3 From cc8851144a871931b93d84bd962364159ad1c424 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Jan 2017 22:03:57 -0800 Subject: Reorganize commands, each in its own namespace Additionally, functions related to a command can now live in the same namespace --- toolsrc/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src/main.cpp') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 8490dc81b..08e65391f 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -21,7 +21,7 @@ bool g_debugging = false; void invalid_command(const std::string& cmd) { System::println(System::color::error, "invalid command: %s", cmd); - Commands::Helpers::print_usage(); + Commands::Help::print_usage(); exit(EXIT_FAILURE); } @@ -30,7 +30,7 @@ static void inner(const vcpkg_cmd_arguments& args) TrackProperty("command", args.command); if (args.command.empty()) { - Commands::Helpers::print_usage(); + Commands::Help::print_usage(); exit(EXIT_FAILURE); } -- cgit v1.2.3 From 9b8afccc9db0959cb3a47d77fd0255096011e245 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 24 Jan 2017 19:08:51 -0800 Subject: Properly convert wchar to char before printing --- toolsrc/src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'toolsrc/src/main.cpp') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 08e65391f..b78319167 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -13,6 +13,7 @@ #include "vcpkg_Input.h" #include "Paragraphs.h" #include "vcpkg_info.h" +#include "vcpkg_Strings.h" using namespace vcpkg; @@ -242,7 +243,7 @@ int wmain(const int argc, const wchar_t* const* const argv) << "EXCEPTION='" << exc_msg << "'\n" << "CMD=\n"; for (int x = 0; x < argc; ++x) - std::cerr << argv[x] << "|\n"; + std::cerr << Strings::utf16_to_utf8(argv[x]) << "|\n"; std::cerr << "\n"; } -- cgit v1.2.3 From 31ddf1a80393d825925cf45b4573710423d14233 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 25 Jan 2017 19:34:25 -0800 Subject: Rename main.cpp to vcpkg.cpp --- toolsrc/src/main.cpp | 249 --------------------------------------------------- 1 file changed, 249 deletions(-) delete mode 100644 toolsrc/src/main.cpp (limited to 'toolsrc/src/main.cpp') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp deleted file mode 100644 index b78319167..000000000 --- a/toolsrc/src/main.cpp +++ /dev/null @@ -1,249 +0,0 @@ -#define WIN32_LEAN_AND_MEAN -#include - -#include -#include -#include -#include -#include "vcpkg_Commands.h" -#include "metrics.h" -#include -#include "vcpkg_Files.h" -#include "vcpkg_System.h" -#include "vcpkg_Input.h" -#include "Paragraphs.h" -#include "vcpkg_info.h" -#include "vcpkg_Strings.h" - -using namespace vcpkg; - -bool g_debugging = false; - -void invalid_command(const std::string& cmd) -{ - System::println(System::color::error, "invalid command: %s", cmd); - Commands::Help::print_usage(); - exit(EXIT_FAILURE); -} - -static void inner(const vcpkg_cmd_arguments& args) -{ - TrackProperty("command", args.command); - if (args.command.empty()) - { - Commands::Help::print_usage(); - exit(EXIT_FAILURE); - } - - if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_c())) - { - return command_function(args); - } - - fs::path vcpkg_root_dir; - if (args.vcpkg_root_dir != nullptr) - { - vcpkg_root_dir = fs::absolute(Strings::utf8_to_utf16(*args.vcpkg_root_dir)); - } - else - { - auto vcpkg_root_dir_env = System::wdupenv_str(L"VCPKG_ROOT"); - - if (!vcpkg_root_dir_env.empty()) - { - vcpkg_root_dir = fs::absolute(vcpkg_root_dir_env); - } - else - { - vcpkg_root_dir = Files::find_file_recursively_up(fs::absolute(System::get_exe_path_of_current_process()), ".vcpkg-root"); - } - } - - Checks::check_exit(!vcpkg_root_dir.empty(), "Error: Could not detect vcpkg-root."); - - const expected expected_paths = vcpkg_paths::create(vcpkg_root_dir); - Checks::check_exit(!expected_paths.error_code(), "Error: Invalid vcpkg root directory %s: %s", vcpkg_root_dir.string(), expected_paths.error_code().message()); - const vcpkg_paths paths = expected_paths.get_or_throw(); - int exit_code = _wchdir(paths.root.c_str()); - Checks::check_exit(exit_code == 0, "Changing the working dir failed"); - - if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_b())) - { - return command_function(args, paths); - } - - triplet default_target_triplet; - if (args.target_triplet != nullptr) - { - default_target_triplet = triplet::from_canonical_name(*args.target_triplet); - } - else - { - const auto vcpkg_default_triplet_env = System::wdupenv_str(L"VCPKG_DEFAULT_TRIPLET"); - if (!vcpkg_default_triplet_env.empty()) - { - default_target_triplet = triplet::from_canonical_name(Strings::utf16_to_utf8(vcpkg_default_triplet_env)); - } - else - { - default_target_triplet = triplet::X86_WINDOWS; - } - } - - Input::check_triplet(default_target_triplet, paths); - - if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_a())) - { - return command_function(args, paths, default_target_triplet); - } - - return invalid_command(args.command); -} - -static void loadConfig() -{ - fs::path localappdata; - { - // Config path in AppDataLocal - wchar_t* localappdatapath = nullptr; - if (S_OK != SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &localappdatapath)) - __fastfail(1); - localappdata = localappdatapath; - CoTaskMemFree(localappdatapath); - } - - try - { - std::string config_contents = Files::read_contents(localappdata / "vcpkg" / "config").get_or_throw(); - - std::unordered_map keys; - auto pghs = Paragraphs::parse_paragraphs(config_contents); - if (pghs.size() > 0) - keys = pghs[0]; - - for (size_t x = 1; x < pghs.size(); ++x) - { - for (auto&& p : pghs[x]) - keys.insert(p); - } - - auto user_id = keys["User-Id"]; - auto user_time = keys["User-Since"]; - Checks::check_throw(!user_id.empty() && !user_time.empty(), ""); // Use as goto to the catch statement - - SetUserInformation(user_id, user_time); - return; - } - catch (...) - { - } - - // config file not found, could not be read, or invalid - std::string user_id, user_time; - InitUserInformation(user_id, user_time); - SetUserInformation(user_id, user_time); - try - { - std::error_code ec; - fs::create_directory(localappdata / "vcpkg", ec); - std::ofstream(localappdata / "vcpkg" / "config", std::ios_base::out | std::ios_base::trunc) - << "User-Id: " << user_id << "\n" - << "User-Since: " << user_time << "\n"; - } - catch (...) - { - } -} - -static System::Stopwatch2 g_timer; - -static std::string trim_path_from_command_line(const std::string& full_command_line) -{ - Checks::check_exit(full_command_line.size() > 0, "Internal failure - cannot have empty command line"); - - if (full_command_line[0] == '"') - { - auto it = std::find(full_command_line.cbegin() + 1, full_command_line.cend(), '"'); - if (it != full_command_line.cend()) // Skip over the quote - ++it; - while (it != full_command_line.cend() && *it == ' ') // Skip over a space - ++it; - return std::string(it, full_command_line.cend()); - } - - auto it = std::find(full_command_line.cbegin(), full_command_line.cend(), ' '); - while (it != full_command_line.cend() && *it == ' ') - ++it; - return std::string(it, full_command_line.cend()); -} - -int wmain(const int argc, const wchar_t* const* const argv) -{ - if (argc == 0) - std::abort(); - - std::cout.sync_with_stdio(false); - std::cout.imbue(std::locale::classic()); - - g_timer.start(); - atexit([]() - { - g_timer.stop(); - TrackMetric("elapsed_us", g_timer.microseconds()); - Flush(); - }); - - TrackProperty("version", Info::version()); - - const std::string trimmed_command_line = trim_path_from_command_line(Strings::utf16_to_utf8(GetCommandLineW())); - TrackProperty("cmdline", trimmed_command_line); - loadConfig(); - TrackProperty("sqmuser", GetSQMUser()); - - const vcpkg_cmd_arguments args = vcpkg_cmd_arguments::create_from_command_line(argc, argv); - - if (args.printmetrics != opt_bool::unspecified) - SetPrintMetrics(args.printmetrics == opt_bool::enabled); - if (args.sendmetrics != opt_bool::unspecified) - SetSendMetrics(args.sendmetrics == opt_bool::enabled); - - if (args.debug != opt_bool::unspecified) - { - g_debugging = (args.debug == opt_bool::enabled); - } - - if (g_debugging) - { - inner(args); - exit(EXIT_FAILURE); - } - - std::string exc_msg; - try - { - inner(args); - exit(EXIT_FAILURE); - } - catch (std::exception& e) - { - exc_msg = e.what(); - } - catch (...) - { - exc_msg = "unknown error(...)"; - } - TrackProperty("error", exc_msg); - std::cerr - << "vcpkg.exe has crashed.\n" - << "Please send an email to:\n" - << " " << Info::email() << "\n" - << "containing a brief summary of what you were trying to do and the following data blob:\n" - << "\n" - << "Version=" << Info::version() << "\n" - << "EXCEPTION='" << exc_msg << "'\n" - << "CMD=\n"; - for (int x = 0; x < argc; ++x) - std::cerr << Strings::utf16_to_utf8(argv[x]) << "|\n"; - std::cerr - << "\n"; -} -- cgit v1.2.3