Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ auto discover_variants(
}
}

std::sort(result.begin(), result.end());
// StringId order is interning order, i.e. readdir order, not name order.
std::ranges::sort(result, {}, [&pool](StringId id) { return pool.get(id); });
return result;
}

Expand Down
37 changes: 37 additions & 0 deletions test/unit/test_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
#include "pup/core/layout.hpp"
#include "pup/core/string_pool.hpp"

#include <array>
#include <filesystem>
#include <fstream>
#include <random>
#include <vector>

namespace fs = std::filesystem;

Expand Down Expand Up @@ -199,3 +201,38 @@ TEST_CASE("discover_layout from build directory", "[e2e][layout]")
REQUIRE(fs::canonical(std::string(global_pool().get(result->output_root))) == fs::canonical(tmp.path() / "build").string());
}
}

SCENARIO("discover_variants orders variants by name, not by interning order", "[e2e][layout]")
{
GIVEN("build directories whose names were interned in reverse-lexicographic order")
{
// Names unique to this test, so the interning below decides their handles.
auto const names = std::array<std::string_view, 4> {
"dvar_alpha",
"dvar_bravo",
"dvar_mike",
"dvar_zeta",
};

auto tmp = TempDir {};
tmp.create_file("Tupfile.ini");
for (auto name : names) {
tmp.create_file(fs::path { name } / "tup.config");
}
for (auto i = names.size(); i-- > 0;) {
(void)global_pool().intern(names[i]);
}

WHEN("the source root is scanned for variants")
{
THEN("the variants are in lexicographic name order")
{
auto found = std::vector<std::string_view> {};
for (auto id : pup::discover_variants(tmp.path().string())) {
found.push_back(global_pool().get(id));
}
REQUIRE(found == std::vector<std::string_view>(names.begin(), names.end()));
}
}
}
}
Loading