Skip to content

Commit

Permalink
Cleanup in ci.commands.cpp (#789)
Browse files Browse the repository at this point in the history
* Eliminate full_results

* Eliminate TripletSummary

* Move ci xunit processing into single block

* clang-format

Co-authored-by: Billy O'Neal <[email protected]>
  • Loading branch information
dg0yt and BillyONeal authored Nov 17, 2022
1 parent b45afb0 commit 16d6d44
Showing 1 changed file with 45 additions and 40 deletions.
85 changes: 45 additions & 40 deletions src/vcpkg/commands.ci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ namespace

namespace vcpkg::Commands::CI
{
struct TripletAndSummary
{
Triplet triplet;
InstallSummary summary;
};

static constexpr StringLiteral OPTION_DRY_RUN = "dry-run";
static constexpr StringLiteral OPTION_EXCLUDE = "exclude";
static constexpr StringLiteral OPTION_HOST_EXCLUDE = "host-exclude";
Expand Down Expand Up @@ -300,7 +294,8 @@ namespace vcpkg::Commands::CI
return result;
}

static void print_baseline_regressions(const std::map<PackageSpec, BuildResult>& results,
static void print_baseline_regressions(const std::vector<SpecSummary>& results,
const std::map<PackageSpec, BuildResult>& known,
const CiBaselineData& cidata,
const std::string& ci_baseline_file_name,
bool allow_unexpected_passing)
Expand All @@ -309,6 +304,16 @@ namespace vcpkg::Commands::CI
LocalizedString output = msg::format(msgCiBaselineRegressionHeader);
output.append_raw('\n');
for (auto&& r : results)
{
auto result = r.build_result.value_or_exit(VCPKG_LINE_INFO).code;
auto msg = format_ci_result(r.get_spec(), result, cidata, ci_baseline_file_name, allow_unexpected_passing);
if (!msg.empty())
{
has_error = true;
output.append(msg).append_raw('\n');
}
}
for (auto&& r : known)
{
auto msg = format_ci_result(r.first, r.second, cidata, ci_baseline_file_name, allow_unexpected_passing);
if (!msg.empty())
Expand Down Expand Up @@ -388,8 +393,6 @@ namespace vcpkg::Commands::CI
auto var_provider_storage = CMakeVars::make_triplet_cmake_var_provider(paths);
auto& var_provider = *var_provider_storage;

XunitWriter xunitTestResults;

const ElapsedTimer timer;
std::vector<std::string> all_port_names =
Util::fmap(provider.load_all_control_files(), Paragraphs::get_name_of_control_file);
Expand Down Expand Up @@ -497,49 +500,51 @@ namespace vcpkg::Commands::CI
auto summary = Install::perform(
args, action_plan, KeepGoing::YES, paths, status_db, binary_cache, build_logs_recorder, var_provider);

std::map<PackageSpec, BuildResult> full_results;

// Adding results for ports that were built or pulled from an archive
for (auto&& result : summary.results)
{
const auto& spec = result.get_spec();
auto& port_features = split_specs->features.at(spec);
split_specs->known.erase(spec);
auto code = result.build_result.value_or_exit(VCPKG_LINE_INFO).code;
xunitTestResults.add_test_results(
spec, code, result.timing, result.start_time, split_specs->abi_map.at(spec), port_features);
full_results.emplace(spec, code);
split_specs->known.erase(result.get_spec());
}
full_results.insert(split_specs->known.begin(), split_specs->known.end());

// Adding results for ports that were not built because they have known states
if (Util::Sets::contains(options.switches, OPTION_XUNIT_ALL))
{
for (auto&& port : split_specs->known)
{
auto& port_features = split_specs->features.at(port.first);
xunitTestResults.add_test_results(port.first,
port.second,
ElapsedTime{},
std::chrono::system_clock::time_point{},
split_specs->abi_map.at(port.first),
port_features);
}
}

TripletAndSummary result{target_triplet, std::move(summary)};

msg::write_unlocalized_text_to_stdout(Color::none, fmt::format("\nTriplet: {}\n", result.triplet));
result.summary.print();
msg::write_unlocalized_text_to_stdout(Color::none, fmt::format("\nTriplet: {}\n", target_triplet));
summary.print();

if (baseline_iter != settings.end())
{
print_baseline_regressions(full_results, cidata, baseline_iter->second, allow_unexpected_passing);
print_baseline_regressions(
summary.results, split_specs->known, cidata, baseline_iter->second, allow_unexpected_passing);
}

auto it_xunit = settings.find(OPTION_XUNIT);
if (it_xunit != settings.end())
{
XunitWriter xunitTestResults;

// Adding results for ports that were built or pulled from an archive
for (auto&& result : summary.results)
{
const auto& spec = result.get_spec();
auto& port_features = split_specs->features.at(spec);
auto code = result.build_result.value_or_exit(VCPKG_LINE_INFO).code;
xunitTestResults.add_test_results(
spec, code, result.timing, result.start_time, split_specs->abi_map.at(spec), port_features);
}

// Adding results for ports that were not built because they have known states
if (Util::Sets::contains(options.switches, OPTION_XUNIT_ALL))
{
for (auto&& port : split_specs->known)
{
const auto& spec = port.first;
auto& port_features = split_specs->features.at(spec);
xunitTestResults.add_test_results(spec,
port.second,
ElapsedTime{},
std::chrono::system_clock::time_point{},
split_specs->abi_map.at(spec),
port_features);
}
}

filesystem.write_contents(
it_xunit->second, xunitTestResults.build_xml(target_triplet), VCPKG_LINE_INFO);
}
Expand Down

0 comments on commit 16d6d44

Please sign in to comment.