diff options
author | Jürg Billeter <j@bitron.ch> | 2019-01-03 18:38:47 +0100 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2019-01-10 13:50:15 +0100 |
commit | 26e33346b2771b4a9f9c710335ff5b73eff8101e (patch) | |
tree | 9dd1b67cc950714059c272c795fea6a2fe0c45e9 | |
parent | c87bb5924d3d809f6f88aec36c61dadf247e6315 (diff) | |
download | buildstream-26e33346b2771b4a9f9c710335ff5b73eff8101e.tar.gz |
_options/optionarch.py: Accept architecture aliases
Accept common architecture aliases for arch options instead of only
accepting the canonicalized, OS-independent architecture name. This
restores compatibility with existing projects and may simplify option
handling for projects that only target a single OS (and thus, do not
need OS-independent architecture names).
-rw-r--r-- | buildstream/_options/optionarch.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/buildstream/_options/optionarch.py b/buildstream/_options/optionarch.py index 1d8509cf2..0e2963c84 100644 --- a/buildstream/_options/optionarch.py +++ b/buildstream/_options/optionarch.py @@ -17,6 +17,8 @@ # Authors: # Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> +from .. import _yaml +from .._exceptions import LoadError, LoadErrorReason, PlatformError from .._platform import Platform from .optionenum import OptionEnum @@ -41,7 +43,34 @@ class OptionArch(OptionEnum): super(OptionArch, self).load(node, allow_default_definition=False) def load_default_value(self, node): - return Platform.get_host_arch() + arch = Platform.get_host_arch() + + default_value = None + + for index, value in enumerate(self.values): + try: + canonical_value = Platform.canonicalize_arch(value) + if default_value is None and canonical_value == arch: + default_value = value + # Do not terminate the loop early to ensure we validate + # all values in the list. + except PlatformError as e: + provenance = _yaml.node_get_provenance(node, key='values', indices=[index]) + prefix = "" + if provenance: + prefix = "{}: ".format(provenance) + raise LoadError(LoadErrorReason.INVALID_DATA, + "{}Invalid value for {} option '{}': {}" + .format(prefix, self.OPTION_TYPE, self.name, e)) + + if default_value is None: + # Host architecture is not supported by the project. + # Do not raise an error here as the user may override it. + # If the user does not override it, an error will be raised + # by resolve()/validate(). + default_value = arch + + return default_value def resolve(self): |