feat(graph): validate Windows path case and reserved names
This commit is contained in:
1 parent
b55aca328a
commit
7772697a48
6 files changed
+115
-9
No files matched your search
@@ -2109,6 +2109,41 @@ lower_project_graph(const ProjectDescription &description,
|
||||
graph.targets.push_back(std::move(summary));
|
||||
}
|
||||
|
||||
// Windows targets live on a case-insensitive filesystem with reserved device names.
|
||||
if (Void::Str::to_lower_ascii(description.profile.os) == "windows") {
|
||||
static constexpr const char *kReserved[] = {
|
||||
"CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7",
|
||||
"COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"};
|
||||
std::map<std::string, std::string, std::less<>> seen_outputs;
|
||||
for (const auto &target : graph.targets) {
|
||||
std::string stem = target.name;
|
||||
if (const auto dot = stem.find('.'); dot != std::string::npos) {
|
||||
stem.resize(dot);
|
||||
}
|
||||
const std::string upper_stem = [&] {
|
||||
std::string s = stem;
|
||||
std::ranges::transform(s, s.begin(), [](char c) {
|
||||
return static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
|
||||
});
|
||||
return s;
|
||||
}();
|
||||
if (std::ranges::find(kReserved, upper_stem) != std::end(kReserved)) {
|
||||
return std::unexpected{
|
||||
make_error(std::format("target '{}' uses the reserved Windows device name '{}'",
|
||||
target.name, upper_stem))};
|
||||
}
|
||||
for (const auto &output : target.primary_outputs) {
|
||||
const std::string lower = Void::Str::to_lower_ascii(output.filename().string());
|
||||
const auto [it, inserted] = seen_outputs.emplace(lower, output.string());
|
||||
if (!inserted && it->second != output.string()) {
|
||||
return std::unexpected{make_error(
|
||||
std::format("Windows output collision: '{}' and '{}' differ only by case",
|
||||
it->second, output.string()))};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return graph;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user