Skip to content

Commit c8a6a3d

Browse files
authored
Deduplicate hashing in grdk_hash
2 parents 2613e1f + 531bb86 commit c8a6a3d

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

src/vcpkg/commands.build.cpp

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,47 +1279,42 @@ namespace vcpkg
12791279
return result;
12801280
}
12811281

1282-
static std::string grdk_hash(const Filesystem& fs,
1283-
Cache<Path, Optional<std::string>>& grdk_cache,
1284-
const PreBuildInfo& pre_build_info)
1282+
static Optional<Path> get_grdk_header_path(const PreBuildInfo& pre_build_info)
12851283
{
12861284
// Handles new layouts for October 2025 or later.
12871285
if (auto game_dk_xbox_latest = pre_build_info.gamedk_xbox_latest_path.get())
12881286
{
1289-
const auto gxdk_header_path = *game_dk_xbox_latest / "xbox/include/gxdk.h";
1290-
const auto& maybe_header_hash = grdk_cache.get_lazy(gxdk_header_path, [&]() -> Optional<std::string> {
1291-
auto maybe_hash = Hash::get_file_hash(fs, gxdk_header_path, Hash::Algorithm::Sha256);
1292-
if (auto hash = maybe_hash.get())
1293-
{
1294-
return std::move(*hash);
1295-
}
1296-
else
1297-
{
1298-
return nullopt;
1299-
}
1300-
});
1301-
1302-
if (auto header_hash = maybe_header_hash.get())
1303-
{
1304-
return *header_hash;
1305-
}
1287+
return *game_dk_xbox_latest / "xbox/include/gxdk.h";
13061288
}
13071289

13081290
// Handles old layouts for April 2025 or earlier for backwards compatibility.
13091291
if (auto game_dk_latest = pre_build_info.gamedk_latest_path.get())
13101292
{
1311-
const auto grdk_header_path = *game_dk_latest / "GRDK/gameKit/Include/grdk.h";
1312-
const auto& maybe_header_hash = grdk_cache.get_lazy(grdk_header_path, [&]() -> Optional<std::string> {
1313-
auto maybe_hash = Hash::get_file_hash(fs, grdk_header_path, Hash::Algorithm::Sha256);
1314-
if (auto hash = maybe_hash.get())
1315-
{
1316-
return std::move(*hash);
1317-
}
1318-
else
1319-
{
1320-
return nullopt;
1321-
}
1322-
});
1293+
return *game_dk_latest / "GRDK/gameKit/Include/grdk.h";
1294+
}
1295+
1296+
return nullopt;
1297+
}
1298+
1299+
static std::string grdk_hash(const Filesystem& fs,
1300+
Cache<Path, Optional<std::string>>& grdk_cache,
1301+
const PreBuildInfo& pre_build_info)
1302+
{
1303+
auto maybe_gxdk_header_path = get_grdk_header_path(pre_build_info);
1304+
if (auto gxdk_header_path = maybe_gxdk_header_path.get())
1305+
{
1306+
const auto& maybe_header_hash =
1307+
grdk_cache.get_lazy(*gxdk_header_path, [&fs, gxdk_header_path]() -> Optional<std::string> {
1308+
auto maybe_hash = Hash::get_file_hash(fs, *gxdk_header_path, Hash::Algorithm::Sha256);
1309+
if (auto hash = maybe_hash.get())
1310+
{
1311+
return std::move(*hash);
1312+
}
1313+
else
1314+
{
1315+
return nullopt;
1316+
}
1317+
});
13231318

13241319
if (auto header_hash = maybe_header_hash.get())
13251320
{

0 commit comments

Comments
 (0)