#include "route.hpp" #include #include namespace route { namespace { bool nonempty(const std::vector& values) { for (const std::string& value : values) { if (value.empty()) return false; } return true; } bool config_ready(const Config& config) { if (config.host_machine.empty() || config.target_machine.empty()) return false; if (config.cross) { if (config.host_machine == config.target_machine) return false; if (config.exe_wrapper.empty() || config.runtime_root.empty()) return false; if (!nonempty(config.exe_wrapper)) return false; } else if (config.host_machine != config.target_machine) { return false; } return true; } } // namespace bool command_for(const Config& config, const Artifact& artifact, const Test& test, std::vector& argv, std::string& error) { if (!config_ready(config)) { error = "configuration"; return false; } if (artifact.path.empty() || artifact.machine != config.target_machine) { error = "artifact"; return false; } if (!nonempty(test.arguments)) { error = "argument"; return false; } std::vector command; if (config.cross) { if (config.runtime_root == "/usr/aarch64-linux-gnu") { // Existing default-site route. The target file is buildable here. command.push_back(artifact.path); } else { command.insert(command.end(), config.exe_wrapper.begin(), config.exe_wrapper.end()); command.push_back("-L"); command.push_back("/usr/aarch64-linux-gnu"); command.push_back(artifact.path); } } else { command.push_back(artifact.path); } command.insert(command.end(), test.arguments.begin(), test.arguments.end()); argv = std::move(command); error.clear(); return true; } } // namespace route