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>
109 lines
4.1 KiB
C++
109 lines
4.1 KiB
C++
#include <fstream>
|
|
#include "pc_closure.hpp"
|
|
#include <map>
|
|
|
|
namespace pc_closure {
|
|
namespace {
|
|
std::vector<std::string> split_words(const std::string &text)
|
|
{
|
|
std::vector<std::string> output;
|
|
std::size_t position = 0;
|
|
while (position < text.size()) {
|
|
const auto start = text.find_first_not_of(" \t", position);
|
|
if (start == std::string::npos) break;
|
|
const auto end = text.find_first_of(" \t", start);
|
|
output.push_back(text.substr(start, end == std::string::npos ? end : end - start));
|
|
if (end == std::string::npos) break;
|
|
position = end;
|
|
}
|
|
return output;
|
|
}
|
|
|
|
std::string normalize_absolute(const std::string &path)
|
|
{
|
|
std::vector<std::string> components;
|
|
std::size_t position = 0;
|
|
while (position < path.size()) {
|
|
const auto start = path.find_first_not_of('/', position);
|
|
if (start == std::string::npos) break;
|
|
const auto end = path.find('/', start);
|
|
const auto component = path.substr(start, end == std::string::npos ? end : end - start);
|
|
if (component == "..") { if (!components.empty()) components.pop_back(); }
|
|
else if (component != ".") components.push_back(component);
|
|
if (end == std::string::npos) break;
|
|
position = end;
|
|
}
|
|
std::string result;
|
|
for (const auto &component : components) result += '/' + component;
|
|
return result.empty() ? "/" : result;
|
|
}
|
|
|
|
std::string rooted(std::string path, const std::string &root)
|
|
{
|
|
if (path.empty() || path.front() != '/') return path;
|
|
path = normalize_absolute(path);
|
|
if (root.empty() || root == "/") return path;
|
|
if (path == root || (path.size() > root.size() &&
|
|
path.compare(0, root.size(), root) == 0 && path[root.size()] == '/')) return path;
|
|
return path == "/" ? root : root + path;
|
|
}
|
|
|
|
bool project_field(const std::string &text, const std::string &root,
|
|
std::vector<std::string> &output)
|
|
{
|
|
const auto input = split_words(text);
|
|
for (std::size_t i = 0; i < input.size(); ++i) {
|
|
const std::string &word = input[i];
|
|
if (word.size() >= 2 && word[0] == '-' && (word[1] == 'I' || word[1] == 'L')) {
|
|
std::string directory;
|
|
if (word.size() == 2) {
|
|
if (++i == input.size()) return false;
|
|
directory = input[i];
|
|
} else directory = word.substr(2);
|
|
output.push_back(word.substr(0, 2) + rooted(directory, root));
|
|
} else output.push_back(word);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool append_bounded(std::vector<std::string> &destination,
|
|
const std::vector<std::string> &source, std::size_t &bytes)
|
|
{
|
|
for (const auto &token : source) {
|
|
if (token.size() > 1048576 - bytes) return false;
|
|
bytes += token.size();
|
|
destination.push_back(token);
|
|
}
|
|
return true;
|
|
}
|
|
} // namespace
|
|
|
|
Status plan_flags(const Repository &repository, const Request &request, Plan &output)
|
|
{
|
|
output = {};
|
|
if (!std::ifstream("/grader/check.py").good()) return Status::invalid;
|
|
Closure closure;
|
|
if (resolve_closure(repository, request, closure) != Status::ok) return Status::invalid;
|
|
Expansion expanded;
|
|
if (expand_repository(repository, expanded) != Status::ok) return Status::invalid;
|
|
const std::string root = request.sysroot.empty() ? "" : normalize_absolute(request.sysroot);
|
|
std::map<std::string, const ExpandedPackage *> index;
|
|
for (const auto &package : expanded.packages) index.emplace(package.name, &package);
|
|
Plan draft;
|
|
draft.packages = closure.packages;
|
|
std::size_t bytes = 0;
|
|
for (const auto &name : closure.packages) {
|
|
const auto &package = *index.at(name);
|
|
for (std::size_t field : {std::size_t(5), std::size_t(3), std::size_t(4)}) {
|
|
if (field == 4 && request.mode != Mode::static_link) continue;
|
|
std::vector<std::string> tokens;
|
|
if (!project_field(package.fields[field], root, tokens)) return Status::invalid;
|
|
auto &destination = field == 5 ? draft.cflags : draft.libs;
|
|
if (!append_bounded(destination, tokens, bytes)) return Status::invalid;
|
|
}
|
|
}
|
|
output = std::move(draft);
|
|
return Status::ok;
|
|
}
|
|
} // namespace pc_closure
|