Skip to content

Commit af90741

Browse files
dg0ytras0219-msftBillyONeal
authored
Add option to remove unaffected ports from ci action (#210)
* Add option to remove unchanged leaf ports from `ci` * Format source code * [commands.ci] Combine plan reduction passes * [commands.ci] Check for missing abi field * Restore exclusion of excluded dependencies. Fix code analysis. Co-authored-by: Robert Schumacher <[email protected]> Co-authored-by: Billy Robert O'Neal III <[email protected]>
1 parent a9976f3 commit af90741

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/vcpkg/commands.ci.cpp

+32-6
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,17 @@ namespace vcpkg::Commands::CI
9393
static constexpr StringLiteral OPTION_XUNIT = "x-xunit";
9494
static constexpr StringLiteral OPTION_RANDOMIZE = "x-randomize";
9595
static constexpr StringLiteral OPTION_OUTPUT_HASHES = "output-hashes";
96+
static constexpr StringLiteral OPTION_PARENT_HASHES = "parent-hashes";
9697
static constexpr StringLiteral OPTION_SKIPPED_CASCADE_COUNT = "x-skipped-cascade-count";
9798

98-
static constexpr std::array<CommandSetting, 6> CI_SETTINGS = {
99+
static constexpr std::array<CommandSetting, 7> CI_SETTINGS = {
99100
{{OPTION_EXCLUDE, "Comma separated list of ports to skip"},
100101
{OPTION_HOST_EXCLUDE, "Comma separated list of ports to skip for the host triplet"},
101102
{OPTION_XUNIT, "File to output results in XUnit format (internal)"},
102103
{OPTION_FAILURE_LOGS, "Directory to which failure logs will be copied"},
103104
{OPTION_OUTPUT_HASHES, "File to output all determined package hashes"},
105+
{OPTION_PARENT_HASHES,
106+
"File to read package hashes for a parent CI state, to reduce the set of changed packages"},
104107
{OPTION_SKIPPED_CASCADE_COUNT,
105108
"Asserts that the number of --exclude and supports skips exactly equal this number"}}};
106109

@@ -404,13 +407,16 @@ namespace vcpkg::Commands::CI
404407

405408
// This algorithm reduces an action plan to only unknown actions and their dependencies
406409
static void reduce_action_plan(Dependencies::ActionPlan& action_plan,
407-
const std::map<PackageSpec, Build::BuildResult>& known)
410+
const std::map<PackageSpec, Build::BuildResult>& known,
411+
View<std::string> parent_hashes)
408412
{
409413
std::set<PackageSpec> to_keep;
410414
for (auto it = action_plan.install_actions.rbegin(); it != action_plan.install_actions.rend(); ++it)
411415
{
412416
auto it_known = known.find(it->spec);
413-
if (it_known == known.end())
417+
const auto& abi = it->abi_info.value_or_exit(VCPKG_LINE_INFO).package_abi;
418+
auto it_parent = std::find(parent_hashes.begin(), parent_hashes.end(), abi);
419+
if (it_known == known.end() && it_parent == parent_hashes.end())
414420
{
415421
to_keep.insert(it->spec);
416422
}
@@ -421,8 +427,11 @@ namespace vcpkg::Commands::CI
421427
{
422428
it->plan_type = InstallPlanType::EXCLUDED;
423429
}
424-
it->build_options = vcpkg::Build::backcompat_prohibiting_package_options;
425-
to_keep.insert(it->package_dependencies.begin(), it->package_dependencies.end());
430+
else
431+
{
432+
it->build_options = vcpkg::Build::backcompat_prohibiting_package_options;
433+
to_keep.insert(it->package_dependencies.begin(), it->package_dependencies.end());
434+
}
426435
}
427436
}
428437

@@ -580,7 +589,24 @@ namespace vcpkg::Commands::CI
580589
}
581590
}
582591

583-
reduce_action_plan(action_plan, split_specs->known);
592+
std::vector<std::string> parent_hashes;
593+
594+
auto it_parent_hashes = settings.find(OPTION_PARENT_HASHES);
595+
if (it_parent_hashes != settings.end())
596+
{
597+
const Path parent_hashes_path = paths.original_cwd / it_parent_hashes->second;
598+
auto parsed_json = Json::parse_file(VCPKG_LINE_INFO, filesystem, parent_hashes_path);
599+
parent_hashes = Util::fmap(parsed_json.first.array(), [](const auto& json_object) {
600+
auto abi = json_object.object().get("abi");
601+
Checks::check_exit(VCPKG_LINE_INFO, abi);
602+
#ifdef _MSC_VER
603+
_Analysis_assume_(abi);
604+
#endif
605+
return abi->string().to_string();
606+
});
607+
}
608+
609+
reduce_action_plan(action_plan, split_specs->known, parent_hashes);
584610

585611
vcpkg::printf("Time to determine pass/fail: %s\n", timer.elapsed());
586612

0 commit comments

Comments
 (0)