platforms.py (1713B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 6 import re 7 8 from taskgraph.util.attributes import keymatch 9 10 # platform family is extracted from build platform by taking the alphabetic prefix 11 # and then translating win -> windows 12 _platform_re = re.compile(r"^[a-z]*") 13 _renames = {"win": "windows"} 14 15 16 _archive_formats = { 17 "linux": ".tar.xz", 18 "macosx": ".tar.gz", 19 "windows": ".zip", 20 } 21 22 _executable_extension = { 23 "linux": "", 24 "macosx": "", 25 "windows": ".exe", 26 } 27 28 _architectures = { 29 r"linux64\b(?!-aarch64).*": "x86_64", 30 r"linux64-aarch64\b.*": "aarch64", 31 r"macosx64\b.*": "macos-x86_64-aarch64", 32 r"win32\b.*": "x86", 33 r"win64\b(?!-aarch64).*": "x86_64", 34 r"win64-aarch64\b.*": "aarch64", 35 } 36 37 38 def platform_family(build_platform): 39 """Given a build platform, return the platform family (linux, macosx, etc.)""" 40 family = _platform_re.match(build_platform).group(0) 41 return _renames.get(family, family) 42 43 44 def archive_format(build_platform): 45 """Given a build platform, return the archive format used on the platform.""" 46 return _archive_formats[platform_family(build_platform)] 47 48 49 def executable_extension(build_platform): 50 """Given a build platform, return the executable extension used on the platform.""" 51 return _executable_extension[platform_family(build_platform)] 52 53 54 def architecture(build_platform): 55 matches = keymatch(_architectures, build_platform) 56 if len(matches) == 1: 57 return matches[0] 58 raise Exception(f"Could not determine architecture of platform `{build_platform}`.")