Jürg Billeter pushed to branch master at BuildStream / buildstream
Commits:
-
c87bb592
by Jürg Billeter at 2019-01-10T09:43:37Z
-
26e33346
by Jürg Billeter at 2019-01-10T12:50:15Z
-
06deb4c4
by Jürg Billeter at 2019-01-10T12:50:15Z
-
0c2a66b3
by Jürg Billeter at 2019-01-10T13:06:02Z
-
f86bc760
by Jürg Billeter at 2019-01-10T13:34:56Z
8 changed files:
- buildstream/_options/optionarch.py
- buildstream/_platform/platform.py
- buildstream/element.py
- + tests/format/option-arch-alias/element.bst
- + tests/format/option-arch-alias/project.conf
- + tests/format/option-arch-unknown/element.bst
- + tests/format/option-arch-unknown/project.conf
- tests/format/optionarch.py
Changes:
| ... | ... | @@ -17,6 +17,8 @@ |
| 17 | 17 |
# Authors:
|
| 18 | 18 |
# Tristan Van Berkom <tristan vanberkom codethink co uk>
|
| 19 | 19 |
|
| 20 |
+from .. import _yaml
|
|
| 21 |
+from .._exceptions import LoadError, LoadErrorReason, PlatformError
|
|
| 20 | 22 |
from .._platform import Platform
|
| 21 | 23 |
from .optionenum import OptionEnum
|
| 22 | 24 |
|
| ... | ... | @@ -41,7 +43,34 @@ class OptionArch(OptionEnum): |
| 41 | 43 |
super(OptionArch, self).load(node, allow_default_definition=False)
|
| 42 | 44 |
|
| 43 | 45 |
def load_default_value(self, node):
|
| 44 |
- return Platform.get_host_arch()
|
|
| 46 |
+ arch = Platform.get_host_arch()
|
|
| 47 |
+ |
|
| 48 |
+ default_value = None
|
|
| 49 |
+ |
|
| 50 |
+ for index, value in enumerate(self.values):
|
|
| 51 |
+ try:
|
|
| 52 |
+ canonical_value = Platform.canonicalize_arch(value)
|
|
| 53 |
+ if default_value is None and canonical_value == arch:
|
|
| 54 |
+ default_value = value
|
|
| 55 |
+ # Do not terminate the loop early to ensure we validate
|
|
| 56 |
+ # all values in the list.
|
|
| 57 |
+ except PlatformError as e:
|
|
| 58 |
+ provenance = _yaml.node_get_provenance(node, key='values', indices=[index])
|
|
| 59 |
+ prefix = ""
|
|
| 60 |
+ if provenance:
|
|
| 61 |
+ prefix = "{}: ".format(provenance)
|
|
| 62 |
+ raise LoadError(LoadErrorReason.INVALID_DATA,
|
|
| 63 |
+ "{}Invalid value for {} option '{}': {}"
|
|
| 64 |
+ .format(prefix, self.OPTION_TYPE, self.name, e))
|
|
| 65 |
+ |
|
| 66 |
+ if default_value is None:
|
|
| 67 |
+ # Host architecture is not supported by the project.
|
|
| 68 |
+ # Do not raise an error here as the user may override it.
|
|
| 69 |
+ # If the user does not override it, an error will be raised
|
|
| 70 |
+ # by resolve()/validate().
|
|
| 71 |
+ default_value = arch
|
|
| 72 |
+ |
|
| 73 |
+ return default_value
|
|
| 45 | 74 |
|
| 46 | 75 |
def resolve(self):
|
| 47 | 76 |
|
| ... | ... | @@ -77,20 +77,17 @@ class Platform(): |
| 77 | 77 |
def get_host_os():
|
| 78 | 78 |
return os.uname()[0]
|
| 79 | 79 |
|
| 80 |
- # get_host_arch():
|
|
| 80 |
+ # canonicalize_arch():
|
|
| 81 | 81 |
#
|
| 82 |
- # This returns the architecture of the host machine. The possible values
|
|
| 83 |
- # map from uname -m in order to be a OS independent list.
|
|
| 82 |
+ # This returns the canonical, OS-independent architecture name
|
|
| 83 |
+ # or raises a PlatformError if the architecture is unknown.
|
|
| 84 | 84 |
#
|
| 85 |
- # Returns:
|
|
| 86 |
- # (string): String representing the architecture
|
|
| 87 | 85 |
@staticmethod
|
| 88 |
- def get_host_arch():
|
|
| 89 |
- # get the hardware identifier from uname
|
|
| 90 |
- uname_machine = os.uname()[4]
|
|
| 91 |
- uname_to_arch = {
|
|
| 86 |
+ def canonicalize_arch(arch):
|
|
| 87 |
+ aliases = {
|
|
| 88 |
+ "aarch32": "aarch32",
|
|
| 92 | 89 |
"aarch64": "aarch64",
|
| 93 |
- "aarch64_be": "aarch64-be",
|
|
| 90 |
+ "aarch64-be": "aarch64-be",
|
|
| 94 | 91 |
"amd64": "x86-64",
|
| 95 | 92 |
"arm": "aarch32",
|
| 96 | 93 |
"armv8l": "aarch64",
|
| ... | ... | @@ -99,17 +96,34 @@ class Platform(): |
| 99 | 96 |
"i486": "x86-32",
|
| 100 | 97 |
"i586": "x86-32",
|
| 101 | 98 |
"i686": "x86-32",
|
| 99 |
+ "power-isa-be": "power-isa-be",
|
|
| 100 |
+ "power-isa-le": "power-isa-le",
|
|
| 102 | 101 |
"ppc64": "power-isa-be",
|
| 103 | 102 |
"ppc64le": "power-isa-le",
|
| 104 | 103 |
"sparc": "sparc-v9",
|
| 105 | 104 |
"sparc64": "sparc-v9",
|
| 106 |
- "x86_64": "x86-64"
|
|
| 105 |
+ "sparc-v9": "sparc-v9",
|
|
| 106 |
+ "x86-32": "x86-32",
|
|
| 107 |
+ "x86-64": "x86-64"
|
|
| 107 | 108 |
}
|
| 109 |
+ |
|
| 108 | 110 |
try:
|
| 109 |
- return uname_to_arch[uname_machine]
|
|
| 111 |
+ return aliases[arch.replace('_', '-')]
|
|
| 110 | 112 |
except KeyError:
|
| 111 |
- raise PlatformError("uname gave unsupported machine architecture: {}"
|
|
| 112 |
- .format(uname_machine))
|
|
| 113 |
+ raise PlatformError("Unknown architecture: {}".format(arch))
|
|
| 114 |
+ |
|
| 115 |
+ # get_host_arch():
|
|
| 116 |
+ #
|
|
| 117 |
+ # This returns the architecture of the host machine. The possible values
|
|
| 118 |
+ # map from uname -m in order to be a OS independent list.
|
|
| 119 |
+ #
|
|
| 120 |
+ # Returns:
|
|
| 121 |
+ # (string): String representing the architecture
|
|
| 122 |
+ @staticmethod
|
|
| 123 |
+ def get_host_arch():
|
|
| 124 |
+ # get the hardware identifier from uname
|
|
| 125 |
+ uname_machine = os.uname()[4]
|
|
| 126 |
+ return Platform.canonicalize_arch(uname_machine)
|
|
| 113 | 127 |
|
| 114 | 128 |
##################################################################
|
| 115 | 129 |
# Sandbox functions #
|
| ... | ... | @@ -2441,11 +2441,17 @@ class Element(Plugin): |
| 2441 | 2441 |
# Sandbox config, unlike others, has fixed members so we should validate them
|
| 2442 | 2442 |
_yaml.node_validate(sandbox_config, ['build-uid', 'build-gid', 'build-os', 'build-arch'])
|
| 2443 | 2443 |
|
| 2444 |
+ build_arch = self.node_get_member(sandbox_config, str, 'build-arch', default=None)
|
|
| 2445 |
+ if build_arch:
|
|
| 2446 |
+ build_arch = Platform.canonicalize_arch(build_arch)
|
|
| 2447 |
+ else:
|
|
| 2448 |
+ build_arch = host_arch
|
|
| 2449 |
+ |
|
| 2444 | 2450 |
return SandboxConfig(
|
| 2445 | 2451 |
self.node_get_member(sandbox_config, int, 'build-uid'),
|
| 2446 | 2452 |
self.node_get_member(sandbox_config, int, 'build-gid'),
|
| 2447 | 2453 |
self.node_get_member(sandbox_config, str, 'build-os', default=host_os),
|
| 2448 |
- self.node_get_member(sandbox_config, str, 'build-arch', default=host_arch))
|
|
| 2454 |
+ build_arch)
|
|
| 2449 | 2455 |
|
| 2450 | 2456 |
# This makes a special exception for the split rules, which
|
| 2451 | 2457 |
# elements may extend but whos defaults are defined in the project.
|
| 1 |
+kind: autotools
|
|
| 2 |
+variables:
|
|
| 3 |
+ result: "Nothing"
|
|
| 4 |
+ (?):
|
|
| 5 |
+ - machine_arch == "arm":
|
|
| 6 |
+ result: "Army"
|
|
| 7 |
+ - machine_arch == "x86_64":
|
|
| 8 |
+ result: "X86-64y"
|
| 1 |
+name: test
|
|
| 2 |
+ |
|
| 3 |
+options:
|
|
| 4 |
+ machine_arch:
|
|
| 5 |
+ type: arch
|
|
| 6 |
+ description: The machine architecture
|
|
| 7 |
+ values:
|
|
| 8 |
+ - arm
|
|
| 9 |
+ - x86_64
|
| 1 |
+kind: autotools
|
|
| 2 |
+variables:
|
|
| 3 |
+ result: "Nothing"
|
|
| 4 |
+ (?):
|
|
| 5 |
+ - machine_arch == "aarch32":
|
|
| 6 |
+ result: "Army"
|
|
| 7 |
+ - machine_arch == "aarch64":
|
|
| 8 |
+ result: "Aarchy"
|
|
| 9 |
+ - machine_arch == "x86-128":
|
|
| 10 |
+ result: "X86-128y"
|
| 1 |
+name: test
|
|
| 2 |
+ |
|
| 3 |
+options:
|
|
| 4 |
+ machine_arch:
|
|
| 5 |
+ type: arch
|
|
| 6 |
+ description: The machine architecture
|
|
| 7 |
+ values:
|
|
| 8 |
+ - aarch32
|
|
| 9 |
+ - aarch64
|
|
| 10 |
+ - x86-128
|
| ... | ... | @@ -75,3 +75,47 @@ def test_unsupported_arch(cli, datafiles): |
| 75 | 75 |
])
|
| 76 | 76 |
|
| 77 | 77 |
result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
|
| 78 |
+ |
|
| 79 |
+ |
|
| 80 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
| 81 |
+def test_alias(cli, datafiles):
|
|
| 82 |
+ |
|
| 83 |
+ with override_uname_arch("arm"):
|
|
| 84 |
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch-alias')
|
|
| 85 |
+ result = cli.run(project=project, silent=True, args=[
|
|
| 86 |
+ 'show',
|
|
| 87 |
+ '--deps', 'none',
|
|
| 88 |
+ '--format', '%{vars}',
|
|
| 89 |
+ 'element.bst'
|
|
| 90 |
+ ])
|
|
| 91 |
+ |
|
| 92 |
+ result.assert_success()
|
|
| 93 |
+ |
|
| 94 |
+ |
|
| 95 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
| 96 |
+def test_unknown_host_arch(cli, datafiles):
|
|
| 97 |
+ |
|
| 98 |
+ with override_uname_arch("x86_128"):
|
|
| 99 |
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch')
|
|
| 100 |
+ result = cli.run(project=project, silent=True, args=[
|
|
| 101 |
+ 'show',
|
|
| 102 |
+ '--deps', 'none',
|
|
| 103 |
+ '--format', '%{vars}',
|
|
| 104 |
+ 'element.bst'
|
|
| 105 |
+ ])
|
|
| 106 |
+ |
|
| 107 |
+ result.assert_main_error(ErrorDomain.PLATFORM, None)
|
|
| 108 |
+ |
|
| 109 |
+ |
|
| 110 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
| 111 |
+def test_unknown_project_arch(cli, datafiles):
|
|
| 112 |
+ |
|
| 113 |
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch-unknown')
|
|
| 114 |
+ result = cli.run(project=project, silent=True, args=[
|
|
| 115 |
+ 'show',
|
|
| 116 |
+ '--deps', 'none',
|
|
| 117 |
+ '--format', '%{vars}',
|
|
| 118 |
+ 'element.bst'
|
|
| 119 |
+ ])
|
|
| 120 |
+ |
|
| 121 |
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
|
