Skip to content

Commit

Permalink
[ci] Add --x-skipped-cascade-count in support of asserting about casc…
Browse files Browse the repository at this point in the history
…ade count requested in microsoft/vcpkg#20074 (comment) (#188)
  • Loading branch information
BillyONeal authored Sep 10, 2021
1 parent 7155b71 commit 3550bb0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
13 changes: 13 additions & 0 deletions azure-pipelines/end-to-end-tests-dir/ci.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
. $PSScriptRoot/../end-to-end-tests-prelude.ps1

# Not a number
Run-Vcpkg ci $Triplet --x-skipped-cascade-count=fish
Throw-IfNotFailed

# Negative
Run-Vcpkg ci $Triplet --x-skipped-cascade-count=-1
Throw-IfNotFailed

# Clearly not the correct answer
Run-Vcpkg ci $Triplet --x-skipped-cascade-count=1000
Throw-IfNotFailed
47 changes: 40 additions & 7 deletions src/vcpkg/commands.ci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ namespace vcpkg::Commands::CI
static constexpr StringLiteral OPTION_FAILURE_LOGS = "failure-logs";
static constexpr StringLiteral OPTION_XUNIT = "x-xunit";
static constexpr StringLiteral OPTION_RANDOMIZE = "x-randomize";
static constexpr StringLiteral OPTION_SKIPPED_CASCADE_COUNT = "x-skipped-cascade-count";

static constexpr std::array<CommandSetting, 4> CI_SETTINGS = {
static constexpr std::array<CommandSetting, 5> CI_SETTINGS = {
{{OPTION_EXCLUDE, "Comma separated list of ports to skip"},
{OPTION_HOST_EXCLUDE, "Comma separated list of ports to skip for the host triplet"},
{OPTION_XUNIT, "File to output results in XUnit format (internal)"},
{OPTION_FAILURE_LOGS, "Directory to which failure logs will be copied"}}};
{OPTION_FAILURE_LOGS, "Directory to which failure logs will be copied"},
{OPTION_SKIPPED_CASCADE_COUNT,
"Asserts that the number of --exclude and supports skips exactly equal this number"}}};

static constexpr std::array<CommandSwitch, 2> CI_SWITCHES = {{
{OPTION_DRY_RUN, "Print out plan without execution"},
Expand Down Expand Up @@ -276,6 +279,7 @@ namespace vcpkg::Commands::CI
std::map<PackageSpec, std::vector<std::string>> features;
Dependencies::ActionPlan plan;
std::map<PackageSpec, std::string> abi_map;
int cascade_count = 0;
};

static bool supported_for_triplet(const CMakeVars::CMakeVarProvider& var_provider,
Expand Down Expand Up @@ -388,6 +392,7 @@ namespace vcpkg::Commands::CI
[&](const PackageSpec& spec) { return Util::Sets::contains(will_fail, spec); }))
{
state = "cascade";
ret->cascade_count++;
ret->known.emplace(p->spec, BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES);
will_fail.emplace(p->spec);
}
Expand Down Expand Up @@ -438,11 +443,12 @@ namespace vcpkg::Commands::CI
return ret;
}

static std::set<std::string> parse_exclusions(const ParsedArguments& options, StringLiteral opt)
static std::set<std::string> parse_exclusions(const std::unordered_map<std::string, std::string>& settings,
StringLiteral opt)
{
std::set<std::string> exclusions_set;
auto it_exclusions = options.settings.find(opt);
if (it_exclusions != options.settings.end())
auto it_exclusions = settings.find(opt);
if (it_exclusions != settings.end())
{
auto exclusions = Strings::split(it_exclusions->second, ',');
exclusions_set.insert(std::make_move_iterator(exclusions.begin()),
Expand All @@ -452,6 +458,23 @@ namespace vcpkg::Commands::CI
return exclusions_set;
}

static Optional<int> parse_skipped_cascade_count(const std::unordered_map<std::string, std::string>& settings)
{
auto opt = settings.find(OPTION_SKIPPED_CASCADE_COUNT);
if (opt == settings.end())
{
return nullopt;
}

auto result = Strings::strto<int>(opt->second);
Checks::check_exit(VCPKG_LINE_INFO, result.has_value(), "%s must be an integer", OPTION_SKIPPED_CASCADE_COUNT);
Checks::check_exit(VCPKG_LINE_INFO,
result.value_or_exit(VCPKG_LINE_INFO) >= 0,
"%s must be non-negative",
OPTION_SKIPPED_CASCADE_COUNT);
return result;
}

void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet, Triplet host_triplet)
{
if (args.command_arguments.size() != 1)
Expand All @@ -464,8 +487,9 @@ namespace vcpkg::Commands::CI

BinaryCache binary_cache{args};
Triplet target_triplet = Triplet::from_canonical_name(std::string(args.command_arguments[0]));
auto exclusions_set = parse_exclusions(options, OPTION_EXCLUDE);
auto host_exclusions_set = parse_exclusions(options, OPTION_HOST_EXCLUDE);
auto exclusions_set = parse_exclusions(settings, OPTION_EXCLUDE);
auto host_exclusions_set = parse_exclusions(settings, OPTION_HOST_EXCLUDE);
auto skipped_cascade_count = parse_skipped_cascade_count(settings);

const auto is_dry_run = Util::Sets::contains(options.switches, OPTION_DRY_RUN);

Expand Down Expand Up @@ -543,6 +567,15 @@ namespace vcpkg::Commands::CI
target_triplet,
host_triplet);

if (auto skipped_cascade_count_ptr = skipped_cascade_count.get())
{
Checks::check_exit(VCPKG_LINE_INFO,
*skipped_cascade_count_ptr == split_specs->cascade_count,
"Expected %d cascaded failures, but there were %d cascaded failures.",
*skipped_cascade_count_ptr,
split_specs->cascade_count);
}

auto& action_plan = split_specs->plan;

if (is_dry_run)
Expand Down

0 comments on commit 3550bb0

Please sign in to comment.