diff options
| author | Phil Christensen <philc@microsoft.com> | 2018-12-06 15:06:28 -0800 |
|---|---|---|
| committer | Phil Christensen <philc@microsoft.com> | 2018-12-06 15:06:28 -0800 |
| commit | 7347305e8459fcc78553a9f88196e0d93eb0a8fe (patch) | |
| tree | ac9eee9ff267c6a71a83249bed7a94f02b00d9a5 /toolsrc/src/vcpkg.cpp | |
| parent | ed9357a5aafea7192932b5874264bd103fc61255 (diff) | |
| parent | 63c1b2628e958f8e02356411f032941c0c2f3bbb (diff) | |
| download | vcpkg-7347305e8459fcc78553a9f88196e0d93eb0a8fe.tar.gz vcpkg-7347305e8459fcc78553a9f88196e0d93eb0a8fe.zip | |
Merge branch 'master' of https://github.com/microsoft/vcpkg into dev/philc/3425
Diffstat (limited to 'toolsrc/src/vcpkg.cpp')
| -rw-r--r-- | toolsrc/src/vcpkg.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 06c99e9a8..3589881a7 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -33,6 +33,12 @@ using namespace vcpkg; +// 24 hours/day * 30 days/month * 6 months +static constexpr int SURVEY_INTERVAL_IN_HOURS = 24 * 30 * 6; + +// Initial survey appears after 10 days. Therefore, subtract 24 hours/day * 10 days +static constexpr int SURVEY_INITIAL_OFFSET_IN_HOURS = SURVEY_INTERVAL_IN_HOURS - 24 * 10; + void invalid_command(const std::string& cmd) { System::println(System::Color::error, "invalid command: %s", cmd); @@ -70,7 +76,7 @@ static void inner(const VcpkgCmdArguments& args) fs::path vcpkg_root_dir; if (args.vcpkg_root_dir != nullptr) { - vcpkg_root_dir = fs::stdfs::absolute(Strings::to_utf16(*args.vcpkg_root_dir)); + vcpkg_root_dir = fs::stdfs::absolute(fs::u8path(*args.vcpkg_root_dir)); } else { @@ -94,6 +100,8 @@ static void inner(const VcpkgCmdArguments& args) Checks::check_exit(VCPKG_LINE_INFO, !vcpkg_root_dir.empty(), "Error: Could not detect vcpkg-root."); + Debug::println("Using vcpkg-root: %s", vcpkg_root_dir.u8string()); + auto default_vs_path = System::get_environment_variable("VCPKG_DEFAULT_VS_PATH").value_or(""); const Expected<VcpkgPaths> expected_paths = VcpkgPaths::create(vcpkg_root_dir, default_vs_path); @@ -102,7 +110,7 @@ static void inner(const VcpkgCmdArguments& args) "Error: Invalid vcpkg root directory %s: %s", vcpkg_root_dir.string(), expected_paths.error().message()); - const VcpkgPaths paths = expected_paths.value_or_exit(VCPKG_LINE_INFO); + const VcpkgPaths& paths = expected_paths.value_or_exit(VCPKG_LINE_INFO); #if defined(_WIN32) const int exit_code = _wchdir(paths.root.c_str()); @@ -111,19 +119,19 @@ static void inner(const VcpkgCmdArguments& args) #endif Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Changing the working dir failed"); - if (args.command != "autocomplete") + if (args.command == "install" || args.command == "remove" || args.command == "export" || args.command == "update") { Commands::Version::warn_if_vcpkg_version_mismatch(paths); std::string surveydate = *GlobalState::g_surveydate.lock(); auto maybe_surveydate = Chrono::CTime::parse(surveydate); if (auto p_surveydate = maybe_surveydate.get()) { - auto delta = std::chrono::system_clock::now() - p_surveydate->to_time_point(); - // 24 hours/day * 30 days/month - if (std::chrono::duration_cast<std::chrono::hours>(delta).count() > 24 * 30) + const auto now = Chrono::CTime::get_current_date_time().value_or_exit(VCPKG_LINE_INFO); + const auto delta = now.to_time_point() - p_surveydate->to_time_point(); + if (std::chrono::duration_cast<std::chrono::hours>(delta).count() > SURVEY_INTERVAL_IN_HOURS) { std::default_random_engine generator( - static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count())); + static_cast<unsigned int>(now.to_time_point().time_since_epoch().count())); std::uniform_int_distribution<int> distribution(1, 4); if (distribution(generator) == 1) @@ -212,7 +220,9 @@ static void load_config() if (config.last_completed_survey.empty()) { - config.last_completed_survey = config.user_time; + const auto now = Chrono::CTime::parse(config.user_time).value_or_exit(VCPKG_LINE_INFO); + const Chrono::CTime offset = now.add_hours(-SURVEY_INITIAL_OFFSET_IN_HOURS); + config.last_completed_survey = offset.to_string(); } GlobalState::g_surveydate.lock()->assign(config.last_completed_survey); @@ -259,6 +269,7 @@ int main(const int argc, const char* const* const argv) #if defined(_WIN32) GlobalState::g_init_console_cp = GetConsoleCP(); GlobalState::g_init_console_output_cp = GetConsoleOutputCP(); + GlobalState::g_init_console_initialized = true; SetConsoleCP(CP_UTF8); SetConsoleOutputCP(CP_UTF8); @@ -273,6 +284,9 @@ int main(const int argc, const char* const* const argv) locked_metrics->track_property("cmdline", trimmed_command_line); #endif } + + Checks::register_console_ctrl_handler(); + load_config(); const auto vcpkg_feature_flags_env = System::get_environment_variable("VCPKG_FEATURE_FLAGS"); @@ -291,8 +305,6 @@ int main(const int argc, const char* const* const argv) if (const auto p = args.sendmetrics.get()) Metrics::g_metrics.lock()->set_send_metrics(*p); if (const auto p = args.debug.get()) GlobalState::debugging = *p; - Checks::register_console_ctrl_handler(); - if (GlobalState::debugging) { inner(args); |
