diff --git a/.gitignore b/.gitignore index 003d607fd1..e1954660f3 100644 --- a/.gitignore +++ b/.gitignore @@ -274,8 +274,9 @@ __pycache__/ .vscode/ buildtrees/ +build*/ downloads/ -installed/ +installed*/ packages/ scripts/buildsystems/tmp/ *.exe diff --git a/scripts/internalCI.ps1 b/scripts/internalCI.ps1 index 16ce4fc7a6..37f4f35a48 100644 --- a/scripts/internalCI.ps1 +++ b/scripts/internalCI.ps1 @@ -1,5 +1,7 @@ $ErrorActionPreference = "Stop" +rm TEST-internal-ci.xml -errorAction SilentlyContinue + New-Item -type directory downloads -errorAction SilentlyContinue | Out-Null ./scripts/bootstrap.ps1 if (-not $?) { throw $? } @@ -7,21 +9,14 @@ if (-not $?) { throw $? } # Clear out any intermediate files from the previous build if (Test-Path buildtrees) { - Get-ChildItem buildtrees/*/* | ? { $_.Name -ne "src" -and $_.Extension -ne ".log"} | Remove-Item -Recurse -Force + Get-ChildItem buildtrees/*/* | ? { $_.Name -ne "src" } | Remove-Item -Recurse -Force } # Purge any outdated packages ./vcpkg remove --outdated --recurse if (-not $?) { throw $? } -./vcpkg.exe install azure-storage-cpp cpprestsdk:x64-windows-static cpprestsdk:x86-uwp +./vcpkg.exe install azure-storage-cpp cpprestsdk:x64-windows-static cpprestsdk:x86-uwp ` +bond cryptopp zlib expat sdl2 curl sqlite3 libuv protobuf:x64-windows sfml opencv:x64-windows uwebsockets uwebsockets:x64-windows-static ` +opencv:x86-uwp boost:x86-uwp --keep-going "--x-xunit=TEST-internal-ci.xml" if (-not $?) { throw $? } - -./vcpkg.exe install bond cryptopp zlib expat sdl2 curl sqlite3 libuv protobuf:x64-windows sfml opencv:x64-windows uwebsockets uwebsockets:x64-windows-static -if (-not $?) { throw $? } - -./vcpkg.exe install opencv:x86-uwp boost:x86-uwp -if (-not $?) { throw $? } - -# ./vcpkg.exe install folly:x64-windows -# if (-not $?) { throw $? } diff --git a/toolsrc/include/vcpkg/base/chrono.h b/toolsrc/include/vcpkg/base/chrono.h index b525852f2f..c791f53fa1 100644 --- a/toolsrc/include/vcpkg/base/chrono.h +++ b/toolsrc/include/vcpkg/base/chrono.h @@ -7,18 +7,37 @@ namespace vcpkg::Chrono { class ElapsedTime { - public: - static ElapsedTime create_started(); + using duration = std::chrono::high_resolution_clock::time_point::duration; - constexpr ElapsedTime() : m_start_tick() {} + public: + constexpr ElapsedTime() : m_duration() {} + constexpr ElapsedTime(duration d) : m_duration(d) {} template - TimeUnit elapsed() const + TimeUnit as() const { - return std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - this->m_start_tick); + return std::chrono::duration_cast(m_duration); } - double microseconds() const { return elapsed>().count(); } + std::string to_string() const; + + private: + std::chrono::high_resolution_clock::time_point::duration m_duration; + }; + + class ElapsedTimer + { + public: + static ElapsedTimer create_started(); + + constexpr ElapsedTimer() : m_start_tick() {} + + ElapsedTime elapsed() const + { + return ElapsedTime(std::chrono::high_resolution_clock::now() - this->m_start_tick); + } + + double microseconds() const { return elapsed().as>().count(); } std::string to_string() const; diff --git a/toolsrc/include/vcpkg/globalstate.h b/toolsrc/include/vcpkg/globalstate.h index 7cea361cf7..40ec7958e8 100644 --- a/toolsrc/include/vcpkg/globalstate.h +++ b/toolsrc/include/vcpkg/globalstate.h @@ -9,11 +9,11 @@ namespace vcpkg { struct GlobalState { - static Util::LockGuarded timer; + static Util::LockGuarded timer; static std::atomic debugging; static std::atomic feature_packages; static std::atomic g_init_console_cp; static std::atomic g_init_console_output_cp; }; -} \ No newline at end of file +} diff --git a/toolsrc/include/vcpkg/install.h b/toolsrc/include/vcpkg/install.h index 28896adee8..2e92764dc5 100644 --- a/toolsrc/include/vcpkg/install.h +++ b/toolsrc/include/vcpkg/install.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -25,7 +26,7 @@ namespace vcpkg::Install PackageSpec spec; Build::ExtendedBuildResult build_result; - std::string timing; + vcpkg::Chrono::ElapsedTime timing; const Dependencies::AnyAction* action; }; @@ -36,6 +37,7 @@ namespace vcpkg::Install std::string total_elapsed_time; void print() const; + std::string xunit_results() const; }; struct InstallDir diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 5642f937ce..04d44c414b 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -255,7 +255,7 @@ int main(const int argc, const char* const* const argv) { if (argc == 0) std::abort(); - *GlobalState::timer.lock() = Chrono::ElapsedTime::create_started(); + *GlobalState::timer.lock() = Chrono::ElapsedTimer::create_started(); #if defined(_WIN32) GlobalState::g_init_console_cp = GetConsoleCP(); diff --git a/toolsrc/src/vcpkg/base/chrono.cpp b/toolsrc/src/vcpkg/base/chrono.cpp index 5d28909fc9..f0e4502312 100644 --- a/toolsrc/src/vcpkg/base/chrono.cpp +++ b/toolsrc/src/vcpkg/base/chrono.cpp @@ -50,12 +50,14 @@ namespace vcpkg::Chrono return Strings::format("%.4g ns", nanos_as_double); } - ElapsedTime ElapsedTime::create_started() + ElapsedTimer ElapsedTimer::create_started() { - ElapsedTime t; + ElapsedTimer t; t.m_start_tick = std::chrono::high_resolution_clock::now(); return t; } - std::string ElapsedTime::to_string() const { return format_time_userfriendly(elapsed()); } + std::string ElapsedTime::to_string() const { return format_time_userfriendly(as()); } + + std::string ElapsedTimer::to_string() const { return elapsed().to_string(); } } diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index 6ef72b639d..b8f122b274 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -67,7 +67,7 @@ namespace vcpkg::Build::Command const Build::BuildPackageConfig build_config{ *scf, spec.triplet(), fs::path{port_dir}, build_package_options, features_as_set}; - const auto build_timer = Chrono::ElapsedTime::create_started(); + const auto build_timer = Chrono::ElapsedTimer::create_started(); const auto result = Build::build_package(paths, build_config, status_db); System::println("Elapsed time for package %s: %s", spec.to_string(), build_timer.to_string()); @@ -323,7 +323,7 @@ namespace vcpkg::Build const auto cmd_set_environment = make_build_env_cmd(pre_build_info, toolset); const std::string command = Strings::format(R"(%s && %s)", cmd_set_environment, cmd_launch_cmake); - const auto timer = Chrono::ElapsedTime::create_started(); + const auto timer = Chrono::ElapsedTimer::create_started(); const int return_code = System::cmd_execute_clean(command); const auto buildtimeus = timer.microseconds(); diff --git a/toolsrc/src/vcpkg/commands.ci.cpp b/toolsrc/src/vcpkg/commands.ci.cpp index 8f79b83e13..f2e984bf89 100644 --- a/toolsrc/src/vcpkg/commands.ci.cpp +++ b/toolsrc/src/vcpkg/commands.ci.cpp @@ -63,9 +63,11 @@ namespace vcpkg::Commands::CI }; static const std::string OPTION_EXCLUDE = "--exclude"; + static const std::string OPTION_XUNIT = "--x-xunit"; - static const std::array CI_SETTINGS = {{ + static const std::array CI_SETTINGS = {{ {OPTION_EXCLUDE, "Comma separated list of ports to skip"}, + {OPTION_XUNIT, "File to output results in XUnit format (internal)"}, }}; const CommandStructure COMMAND_STRUCTURE = { @@ -114,6 +116,18 @@ namespace vcpkg::Commands::CI result.summary.print(); } + auto it_xunit = options.settings.find(OPTION_XUNIT); + if (it_xunit != options.settings.end()) + { + std::string xunit_doc = "\n"; + + for (auto&& result : results) + xunit_doc += result.summary.xunit_results(); + + xunit_doc += "\n"; + paths.get_filesystem().write_contents(fs::u8path(it_xunit->second), xunit_doc); + } + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/vcpkg/commands.integrate.cpp b/toolsrc/src/vcpkg/commands.integrate.cpp index f13a999fa6..66c5eb5a91 100644 --- a/toolsrc/src/vcpkg/commands.integrate.cpp +++ b/toolsrc/src/vcpkg/commands.integrate.cpp @@ -257,7 +257,7 @@ CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=%s")", std::error_code ec; const bool was_deleted = fs.remove(path, ec); - Checks::check_exit(VCPKG_LINE_INFO, !ec, "Error: Unable to remove user-wide integration: %d", ec.message()); + Checks::check_exit(VCPKG_LINE_INFO, !ec, "Error: Unable to remove user-wide integration: %s", ec.message()); if (was_deleted) { diff --git a/toolsrc/src/vcpkg/commands.portsdiff.cpp b/toolsrc/src/vcpkg/commands.portsdiff.cpp index 0277c8bdb1..6752715e4c 100644 --- a/toolsrc/src/vcpkg/commands.portsdiff.cpp +++ b/toolsrc/src/vcpkg/commands.portsdiff.cpp @@ -151,14 +151,14 @@ namespace vcpkg::Commands::PortsDiff const std::vector& added_ports = setp.only_left; if (!added_ports.empty()) { - System::println("\nThe following %d ports were added:", added_ports.size()); + System::println("\nThe following %zd ports were added:", added_ports.size()); do_print_name_and_version(added_ports, current_names_and_versions); } const std::vector& removed_ports = setp.only_right; if (!removed_ports.empty()) { - System::println("\nThe following %d ports were removed:", removed_ports.size()); + System::println("\nThe following %zd ports were removed:", removed_ports.size()); do_print_name_and_version(removed_ports, previous_names_and_versions); } @@ -168,7 +168,7 @@ namespace vcpkg::Commands::PortsDiff if (!updated_ports.empty()) { - System::println("\nThe following %d ports were updated:", updated_ports.size()); + System::println("\nThe following %zd ports were updated:", updated_ports.size()); for (const UpdatedPort& p : updated_ports) { System::println(" - %-14s %-16s", p.port, p.version_diff.to_string()); diff --git a/toolsrc/src/vcpkg/globalstate.cpp b/toolsrc/src/vcpkg/globalstate.cpp index 43230fa4bb..149401b2c1 100644 --- a/toolsrc/src/vcpkg/globalstate.cpp +++ b/toolsrc/src/vcpkg/globalstate.cpp @@ -4,7 +4,7 @@ namespace vcpkg { - Util::LockGuarded GlobalState::timer; + Util::LockGuarded GlobalState::timer; std::atomic GlobalState::debugging(false); std::atomic GlobalState::feature_packages(false); diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp index 0888e21d55..76dc7a527d 100644 --- a/toolsrc/src/vcpkg/install.cpp +++ b/toolsrc/src/vcpkg/install.cpp @@ -484,18 +484,18 @@ namespace vcpkg::Install { std::vector results; - const auto timer = Chrono::ElapsedTime::create_started(); + const auto timer = Chrono::ElapsedTimer::create_started(); size_t counter = 0; const size_t package_count = action_plan.size(); for (const auto& action : action_plan) { - const auto build_timer = Chrono::ElapsedTime::create_started(); + const auto build_timer = Chrono::ElapsedTimer::create_started(); counter++; const PackageSpec& spec = action.spec(); const std::string display_name = spec.to_string(); - System::println("Starting package %d/%d: %s", counter, package_count, display_name); + System::println("Starting package %zd/%zd: %s", counter, package_count, display_name); results.emplace_back(spec, &action); @@ -521,8 +521,8 @@ namespace vcpkg::Install Checks::unreachable(VCPKG_LINE_INFO); } - results.back().timing = build_timer.to_string(); - System::println("Elapsed time for package %s: %s", display_name, build_timer.to_string()); + results.back().timing = build_timer.elapsed(); + System::println("Elapsed time for package %s: %s", display_name, results.back().timing.to_string()); } return InstallSummary{std::move(results), timer.to_string()}; @@ -533,6 +533,7 @@ namespace vcpkg::Install static const std::string OPTION_NO_DOWNLOADS = "--no-downloads"; static const std::string OPTION_RECURSE = "--recurse"; static const std::string OPTION_KEEP_GOING = "--keep-going"; + static const std::string OPTION_XUNIT = "--x-xunit"; static const std::array INSTALL_SWITCHES = {{ {OPTION_DRY_RUN, "Do not actually build or install"}, @@ -541,7 +542,9 @@ namespace vcpkg::Install {OPTION_RECURSE, "Allow removal of packages as part of installation"}, {OPTION_KEEP_GOING, "Continue installing packages on failure"}, }}; - static const std::array INSTALL_SETTINGS; + static const std::array INSTALL_SETTINGS = {{ + {OPTION_XUNIT, "File to output results in XUnit format (Internal use)"}, + }}; std::vector get_all_port_names(const VcpkgPaths& paths) { @@ -555,7 +558,7 @@ namespace vcpkg::Install Help::create_example_string("install zlib zlib:x64-windows curl boost"), 1, SIZE_MAX, - {INSTALL_SWITCHES, {}}, + {INSTALL_SWITCHES, INSTALL_SETTINGS}, &get_all_port_names, }; @@ -627,7 +630,7 @@ namespace vcpkg::Install library_target_pair.second.erase(library_target_pair.second.begin() + 4, library_target_pair.second.end()); System::println(" find_package(%s REQUIRED)\n" - " # Note: %d targets were omitted\n" + " # Note: %zd targets were omitted\n" " target_link_libraries(main PRIVATE %s)\n", library_target_pair.first, omitted, @@ -735,6 +738,17 @@ namespace vcpkg::Install summary.print(); } + auto it_xunit = options.settings.find(OPTION_XUNIT); + if (it_xunit != options.settings.end()) + { + std::string xunit_doc = "\n"; + + xunit_doc += summary.xunit_results(); + + xunit_doc += "\n"; + paths.get_filesystem().write_contents(fs::u8path(it_xunit->second), xunit_doc); + } + for (auto&& result : summary.results) { if (!result.action) continue; @@ -751,7 +765,7 @@ namespace vcpkg::Install } SpecSummary::SpecSummary(const PackageSpec& spec, const Dependencies::AnyAction* action) - : spec(spec), build_result{BuildResult::NULLVALUE, nullptr}, timing("0"), action(action) + : spec(spec), build_result{BuildResult::NULLVALUE, nullptr}, action(action) { } @@ -770,4 +784,41 @@ namespace vcpkg::Install } return nullptr; } + + std::string InstallSummary::xunit_results() const + { + std::string xunit_doc; + for (auto&& result : results) + { + std::string inner_block; + const char* result_string = ""; + switch (result.build_result.code) + { + case BuildResult::POST_BUILD_CHECKS_FAILED: + case BuildResult::FILE_CONFLICTS: + case BuildResult::BUILD_FAILED: + result_string = "Fail"; + inner_block = Strings::format("", + to_string(result.build_result.code)); + break; + case BuildResult::EXCLUDED: + case BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES: + result_string = "Skip"; + inner_block = + Strings::format("", to_string(result.build_result.code)); + break; + case BuildResult::SUCCEEDED: result_string = "Pass"; break; + default: Checks::exit_fail(VCPKG_LINE_INFO); + } + + xunit_doc += Strings::format(R"(%s)" + "\n", + result.spec, + result.spec, + result.timing.as().count(), + result_string, + inner_block); + } + return xunit_doc; + } } diff --git a/toolsrc/src/vcpkg/postbuildlint.cpp b/toolsrc/src/vcpkg/postbuildlint.cpp index 0532bce586..2b427737a8 100644 --- a/toolsrc/src/vcpkg/postbuildlint.cpp +++ b/toolsrc/src/vcpkg/postbuildlint.cpp @@ -479,7 +479,7 @@ namespace vcpkg::PostBuildLint } System::println(System::Color::warning, - "Mismatching number of debug and release binaries. Found %d for debug but %d for release.", + "Mismatching number of debug and release binaries. Found %zd for debug but %zd for release.", debug_count, release_count); System::println("Debug binaries");