build-remote: Use std::set for feature sets

This commit is contained in:
Shea Levy 2017-01-10 10:29:06 -05:00
parent bff3ad767e
commit d771c28613

View file

@ -3,7 +3,7 @@
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <vector> #include <set>
#include <memory> #include <memory>
#include <tuple> #include <tuple>
#include <iomanip> #include <iomanip>
@ -24,8 +24,8 @@ static void handle_alarm(int sig) {
} }
class machine { class machine {
const std::vector<string> supportedFeatures; const std::set<string> supportedFeatures;
const std::vector<string> mandatoryFeatures; const std::set<string> mandatoryFeatures;
public: public:
const string hostName; const string hostName;
@ -35,22 +35,18 @@ public:
const unsigned long long speedFactor; const unsigned long long speedFactor;
bool enabled; bool enabled;
bool allSupported(const std::vector<string> & features) const { bool allSupported(const std::set<string> & features) const {
return std::all_of(features.begin(), features.end(), return std::all_of(features.begin(), features.end(),
[&](const string & feature) { [&](const string & feature) {
return std::find(supportedFeatures.begin(), return supportedFeatures.count(feature) ||
supportedFeatures.end(), mandatoryFeatures.count(feature);
feature) != supportedFeatures.end() ||
std::find(mandatoryFeatures.begin(),
mandatoryFeatures.end(),
feature) != mandatoryFeatures.end();
}); });
} }
bool mandatoryMet(const std::vector<string> & features) const { bool mandatoryMet(const std::set<string> & features) const {
return std::all_of(mandatoryFeatures.begin(), mandatoryFeatures.end(), return std::all_of(mandatoryFeatures.begin(), mandatoryFeatures.end(),
[&](const string & feature) { [&](const string & feature) {
return std::find(features.begin(), features.end(), feature) != features.end(); return features.count(feature);
}); });
} }
@ -96,11 +92,11 @@ static std::vector<machine> read_conf() {
stoull(tokens[3]), stoull(tokens[3]),
sz >= 5 ? stoull(tokens[4]) : 1LL, sz >= 5 ? stoull(tokens[4]) : 1LL,
sz >= 6 ? sz >= 6 ?
tokenizeString<std::vector<string>>(tokens[5], ",") : tokenizeString<std::set<string>>(tokens[5], ",") :
std::vector<string>{}, std::set<string>{},
sz >= 7 ? sz >= 7 ?
tokenizeString<std::vector<string>>(tokens[6], ",") : tokenizeString<std::set<string>>(tokens[6], ",") :
std::vector<string>{}); std::set<string>{});
} }
} }
confFile.close(); confFile.close();
@ -160,8 +156,8 @@ int main (int argc, char * * argv)
auto neededSystem = tokens[1]; auto neededSystem = tokens[1];
drvPath = tokens[2]; drvPath = tokens[2];
auto requiredFeatures = sz == 3 ? auto requiredFeatures = sz == 3 ?
std::vector<string>{} : std::set<string>{} :
tokenizeString<std::vector<string>>(tokens[3], ","); tokenizeString<std::set<string>>(tokens[3], ",");
auto canBuildLocally = amWilling && (neededSystem == localSystem); auto canBuildLocally = amWilling && (neededSystem == localSystem);
/* Error ignored here, will be caught later */ /* Error ignored here, will be caught later */