From 0aa85088dee30615adcc7a2933fb94ea8767ec35 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 23 Jan 2024 12:52:54 -0500 Subject: [PATCH] Factor out `Machine::systemSupported` There's just enough logic (the `"builtin"` special case) that makes this worthy of its own method. --- src/build-remote/build-remote.cc | 5 ++--- src/libstore/machines.cc | 5 +++++ src/libstore/machines.hh | 6 ++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc index b6704152a..519e03242 100644 --- a/src/build-remote/build-remote.cc +++ b/src/build-remote/build-remote.cc @@ -137,9 +137,8 @@ static int main_build_remote(int argc, char * * argv) for (auto & m : machines) { debug("considering building on remote machine '%s'", m.storeUri); - if (m.enabled - && (neededSystem == "builtin" - || m.systemTypes.count(neededSystem) > 0) && + if (m.enabled && + m.systemSupported(neededSystem) && m.allSupported(requiredFeatures) && m.mandatoryMet(requiredFeatures)) { diff --git a/src/libstore/machines.cc b/src/libstore/machines.cc index 8a1da84cd..561d8d557 100644 --- a/src/libstore/machines.cc +++ b/src/libstore/machines.cc @@ -38,6 +38,11 @@ Machine::Machine(decltype(storeUri) storeUri, sshPublicHostKey(sshPublicHostKey) {} +bool Machine::systemSupported(const std::string & system) const +{ + return system == "builtin" || (systemTypes.count(system) > 0); +} + bool Machine::allSupported(const std::set & features) const { return std::all_of(features.begin(), features.end(), diff --git a/src/libstore/machines.hh b/src/libstore/machines.hh index 7dd812cf0..1bca74c28 100644 --- a/src/libstore/machines.hh +++ b/src/libstore/machines.hh @@ -19,6 +19,12 @@ struct Machine { const std::string sshPublicHostKey; bool enabled = true; + /** + * @return Whether `system` is either `"builtin"` or in + * `systemTypes`. + */ + bool systemSupported(const std::string & system) const; + /** * @return Whether `features` is a subset of the union of `supportedFeatures` and * `mandatoryFeatures`