From 564160e126f525dda52f27044d29b479088da191 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 19 Dec 2022 21:12:29 +0200 Subject: [PATCH] Improve architecture name matching It will now treat x86_64 as a more specific match than just x86. --- source/architecture.cpp | 29 +++++++++++++++-------------- source/architecture.h | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/source/architecture.cpp b/source/architecture.cpp index 2efcd5e..48c6a20 100644 --- a/source/architecture.cpp +++ b/source/architecture.cpp @@ -177,7 +177,7 @@ Architecture::Architecture(Builder &b, const string &spec): } } -bool Architecture::match_name(const string &pattern) const +bool Architecture::match_name(const string &pattern, unsigned *quality) const { bool negate = (pattern[0]=='!'); vector parts = split(pattern.substr(negate), "-"); @@ -187,31 +187,32 @@ bool Architecture::match_name(const string &pattern) const if((p=="32" && bits==32) || (p=="64" && bits==64)) ; else if(p!=type && p!=cpu && p!=fpu && p!=system && p!=toolchain) + { + if(quality) + *quality = 0; return negate; + } } + + if(quality) + *quality = parts.size(); return !negate; } string Architecture::best_match(const vector &names) const { string best; - unsigned best_size = 0; + unsigned best_quality = 0; for(const string &n: names) - if(match_name(n)) - { - /* TODO Do full parse and alias resolution here? Otherwise x86 and - x86_64 are treated as equally good, even though the latter is more - specific. */ - unsigned size = 1; - for(char c: n) - size += (c=='-'); - - if(size>best_size) + { + unsigned quality; + if(match_name(n, &quality)) + if(quality>best_quality) { best = n; - best_size = size; + best_quality = quality; } - } + } return best; } diff --git a/source/architecture.h b/source/architecture.h index 7f3c4b2..776de85 100644 --- a/source/architecture.h +++ b/source/architecture.h @@ -44,7 +44,7 @@ public: const std::string &get_cpu() const { return cpu; } const std::string &get_fpu() const { return fpu; } const std::string &get_toolchain() const { return toolchain; } - bool match_name(const std::string &) const; + bool match_name(const std::string &, unsigned * = 0) const; std::string best_match(const std::vector &) const; bool is_native() const { return native; } bool is_cross() const { return !cross_prefix.empty(); } -- 2.43.0