amos 913d3c367f Add the usable task catalog and admit batch 6 tasks
All 161 task packages, including the 21 batch 6 C++17 tasks that passed
gates 1/2, are now in Git. rollout.catalog builds docs/task-catalog.{json,md}
from the task packages, a fresh trace5 calibration (128/128 PASS), every
verified controller receipt on the current task digest, documented holds
and digest-bound difficulty reviews. 123 tasks are usable (6 HARD),
5 are on hold and 33 still need a subprocess-only grader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 17:43:15 +08:00

108 lines
4.9 KiB
C++

#include "module_plan.h"
#include <algorithm>
#include <map>
#include <set>
#include <utility>
namespace bootplan {
namespace {
bool basename_ok(const std::string &name) {
if (name.size() < 5 || name.size() > 128 ||
name.compare(name.size() - 5, 5, ".conf") != 0) return false;
for (unsigned char byte : name) {
if (!((byte >= 'a' && byte <= 'z') || (byte >= 'A' && byte <= 'Z') ||
(byte >= '0' && byte <= '9') || byte == '_' || byte == '-' || byte == '.')) return false;
}
return true;
}
bool option_ok(const std::string &token) {
if (token.empty()) return false;
for (unsigned char byte : token) {
if (!((byte >= 'a' && byte <= 'z') || (byte >= 'A' && byte <= 'Z') ||
(byte >= '0' && byte <= '9') || byte == '_' || byte == '.' || byte == ',' ||
byte == '=' || byte == ':' || byte == '+' || byte == '/' || byte == '-')) return false;
}
return true;
}
}
Error compile_configuration(const std::vector<Directory> &directories,
const std::vector<std::string> &available,
Configuration &output) {
output = Configuration{};
if (directories.size() > 5 || available.size() > 256) return Error::invalid;
Configuration next;
std::set<std::string> modules;
for (const auto &raw : available) {
std::string module;
if (!canonical_module(raw, module) || !modules.insert(module).second) return Error::invalid;
}
next.available.assign(modules.begin(), modules.end());
std::size_t files = 0, bytes = 0;
std::map<std::string, const File *> selected;
for (const Directory &directory : directories) {
if (directory.size() > 64) return Error::invalid;
files += directory.size();
if (files > 128) return Error::invalid;
std::set<std::string> names;
for (const File &file : directory) {
if (!basename_ok(file.basename) || !names.insert(file.basename).second ||
file.text.size() > 65536) return Error::invalid;
bytes += file.text.size();
if (bytes > 262144) return Error::invalid;
for (unsigned char byte : file.text) if (byte > 127) return Error::invalid;
selected.emplace(file.basename, &file);
}
}
std::set<std::string> blacklisted;
std::map<std::string, std::vector<std::string>> options;
std::map<std::string, Dependency> dependencies;
for (const auto &entry : selected) {
next.selected_files.push_back(entry.first);
std::vector<std::vector<std::string>> rows;
if (statements(entry.second->text, rows) != Error::none) return Error::invalid;
for (const auto &tokens : rows) {
std::string module;
if (tokens.size() < 2 || !canonical_module(tokens[1], module)) return Error::invalid;
if (tokens[0] == "blacklist") {
if (tokens.size() != 2) return Error::invalid;
blacklisted.insert(module);
} else if (tokens[0] == "options") {
if (tokens.size() < 3) return Error::invalid;
for (std::size_t index = 2; index < tokens.size(); ++index) {
if (!option_ok(tokens[index])) return Error::invalid;
options[module].push_back(tokens[index]);
}
} else if (tokens[0] == "softdep") {
if (dependencies.count(module)) return Error::invalid;
Dependency dependency;
dependency.module = module;
bool saw_pre = false, saw_post = false;
unsigned section = 0;
for (std::size_t index = 2; index < tokens.size(); ++index) {
const std::string &token = tokens[index];
if (token == "pre:") {
if (saw_pre || saw_post) return Error::invalid;
saw_pre = true; section = 1;
} else if (token == "post:") {
if (saw_post) return Error::invalid;
saw_post = true; section = 2;
} else {
std::string target;
if (!section || !canonical_module(token, target)) return Error::invalid;
(section == 1 ? dependency.pre : dependency.post).push_back(std::move(target));
}
}
if (!saw_pre && !saw_post) return Error::invalid;
dependencies.emplace(module, std::move(dependency));
} else return Error::invalid;
}
}
next.blacklist.assign(blacklisted.begin(), blacklisted.end());
for (auto &entry : options) next.options.push_back(OptionGroup{entry.first, std::move(entry.second)});
for (auto &entry : dependencies) next.dependencies.push_back(std::move(entry.second));
output = std::move(next);
return Error::none;
}
}