diff --git a/mx.py b/mx.py index 7afc7cdc..b735d829 100755 --- a/mx.py +++ b/mx.py @@ -581,6 +581,7 @@ def __init__(self, parents=None): "projects and store it in the given . If is 'default', the compilation database will " "be stored in the parent directory of the repository containing the primary suite. This option " "can also be configured using the MX_COMPDB environment variable. Use --compdb none to disable.") + self.add_argument('--arch', action='store', dest='arch', help='force use the specified architecture', choices=['arm64', 'aarch64', 'amd64', 'sparcv9']) if not is_windows(): # Time outs are (currently) implemented with Unix specific functionality @@ -679,6 +680,9 @@ def _parse_cmd_line(self, opts, firstParse): except IOError as e: abort('Error opening {} specified by --exec-log: {}'.format(opts.exec_log, e)) + if opts.arch and opts.arch != get_arch(): + warn('overriding detected architecture ({}) with {}'.format(get_arch(), opts.arch)) + else: parser = ArgParser(parents=[self]) parser.add_argument('commandAndArgs', nargs=REMAINDER, metavar='command args...') @@ -1735,7 +1739,7 @@ def _make_config(platformDependent=False, jdkDependent=None): if release not in jdk_releases: jdk_releases.append(release) if platformDependent: - config.append(get_os() + '-' + get_arch()) + config.append(get_os() + '-' + get_effective_arch()) if jdk_releases: config.append('jdk' + '+'.join(jdk_releases)) config = '-'.join(config) @@ -1790,7 +1794,7 @@ def get_output_root(self, platformDependent=False, jdkDependent=None): else: self._outputRoot = self.getMxCompatibility().getSuiteOutputRoot(self) if platformDependent: - return os.path.join(self._outputRoot, get_os() + '-' + get_arch()) + return os.path.join(self._outputRoot, get_os() + '-' + get_effective_arch()) else: return self._outputRoot @@ -2215,7 +2219,7 @@ def _init_imports(self): import_dict = entry imported_suite_name = import_dict.get('name', '') if import_dict.get('ignore', False): - log("Ignoring '{}' on your platform ({}/{})".format(imported_suite_name, get_os(), get_arch())) + log("Ignoring '{}' on your platform ({}/{})".format(imported_suite_name, get_os(), get_effective_arch())) continue if import_dict.get('dynamic', False) and imported_suite_name not in (name for name, _ in get_dynamic_imports()): continue @@ -2337,13 +2341,13 @@ def _pop_os_arch(attrs, context): os_key = '' os_attrs = os_arch.pop(os_key, None) if os_attrs: - arch_attrs = os_attrs.pop(get_arch(), None) + arch_attrs = os_attrs.pop(get_effective_arch(), None) if not arch_attrs: arch_attrs = os_attrs.pop('', None) if arch_attrs: return arch_attrs else: - warn("No platform-specific definition is available for {} for your architecture ({})".format(context, get_arch())) + warn("No platform-specific definition is available for {} for your architecture ({})".format(context, get_effective_arch())) else: warn("No platform-specific definition is available for {} for your OS ({})".format(context, get_os())) return None @@ -3837,6 +3841,12 @@ def _separatedCygpathW2U(p): return p return os.pathsep.join(map(_cygpathW2U, p.split(';'))) +def get_effective_arch(): + if _opts.arch is not None: + return _opts.arch + + return get_effective_arch() + def get_arch(): machine = platform.uname()[4] if machine in ['aarch64']: @@ -3853,14 +3863,9 @@ def get_arch(): except OSError: # sysctl is not available pass - if machine == 'arm64' and is_darwin(): - # temporary workaround for arm64 (aarch64) based macOS systems (e.g. M1 processor) - # some libraries don't have a macOS arm64 build yet (e.g. ASYNC_PROFILER), - # but they can run as amd64 with Rosetta2 - return 'amd64' abort('unknown or unsupported architecture: os=' + get_os() + ', machine=' + machine) -mx_subst.results_substitutions.register_no_arg('arch', get_arch) +mx_subst.results_substitutions.register_no_arg('arch', get_effective_arch) def vc_system(kind, abortOnError=True): for vc in _vc_systems: @@ -5384,7 +5389,7 @@ def default_filename(self): @classmethod def platformName(cls): - return '{os}_{arch}'.format(os=get_os(), arch=get_arch()) + return '{os}_{arch}'.format(os=get_os(), arch=get_effective_arch()) """ Provide remoteName of distribution. diff --git a/mx_benchmark.py b/mx_benchmark.py index 287b8211..0cb73b96 100644 --- a/mx_benchmark.py +++ b/mx_benchmark.py @@ -151,7 +151,7 @@ def libraryPath(self): async_profiler_lib = mx.library("ASYNC_PROFILER_{}".format(self.version())) if not async_profiler_lib.is_available(): raise mx.abort("'--profiler {}' is not supported on '{}/{}' because the '{}' library is not available." - .format(self.name(), mx.get_os(), mx.get_arch(), async_profiler_lib.name)) + .format(self.name(), mx.get_os(), mx.get_effective_arch(), async_profiler_lib.name)) libraryDirectory = async_profiler_lib.get_path(True) innerDir = [f for f in os.listdir(libraryDirectory) if os.path.isdir(os.path.join(libraryDirectory, f))][0] @@ -2259,7 +2259,7 @@ def buildFlags(self): return "" def machineArch(self): - return mx.get_arch() + return mx.get_effective_arch() def machinePlatform(self): return platform.platform() diff --git a/mx_cmake.py b/mx_cmake.py index 761f2e88..1b87939c 100644 --- a/mx_cmake.py +++ b/mx_cmake.py @@ -144,7 +144,7 @@ class CMakeNinjaBuildTask(mx_native.NinjaBuildTask): def __init__(self, args, project, *otherargs, **kwargs): super(CMakeNinjaBuildTask, self).__init__(args, project, *otherargs, **kwargs) self._cmake_config_file = os.path.join(project.suite.get_mx_output_dir(), 'cmakeConfig', - mx.get_os() + '-' + mx.get_arch() if project.isPlatformDependent() else '', + mx.get_os() + '-' + mx.get_effective_arch() if project.isPlatformDependent() else '', type(project).__name__, project._extra_artifact_discriminant(), self.name) diff --git a/mx_fetchjdk.py b/mx_fetchjdk.py index a8cbc60c..635e99e0 100644 --- a/mx_fetchjdk.py +++ b/mx_fetchjdk.py @@ -427,7 +427,7 @@ class _JdkBinary(object): def __init__(self, jdk_id, version, filename, url, source): self._jdk_id = jdk_id self._version = version - platform = mx.get_os() + '-' + mx.get_arch() + platform = mx.get_os() + '-' + mx.get_effective_arch() keywords = {'version': version, 'platform': platform} self._filename = _instantiate(filename, keywords, source) keywords['filename'] = self._filename diff --git a/mx_javamodules.py b/mx_javamodules.py index c455a94c..0d17dab7 100644 --- a/mx_javamodules.py +++ b/mx_javamodules.py @@ -1027,7 +1027,7 @@ def __exit__(self, exc_type, exc_value, traceback): # attribute of module-info.class. target_os = mx.get_os() target_os = 'macos' if target_os == 'darwin' else target_os - target_arch = mx.get_arch() + target_arch = mx.get_effective_arch() jmod_args.append('--target-platform={}-{}'.format(target_os, target_arch)) if exists(jdk_jmod): with ZipFile(jdk_jmod, 'r') as zf: diff --git a/mx_native.py b/mx_native.py index f1d75ede..278cc52f 100644 --- a/mx_native.py +++ b/mx_native.py @@ -80,7 +80,7 @@ def target(self): @property def is_native(self): - return self.target_arch == mx.get_arch() + return self.target_arch == mx.get_effective_arch() @property def is_available(self): @@ -185,8 +185,8 @@ def __init__(self, suite, name, subDir, srcDirs, deps, workingSets, d, **kwargs) if 'multiarch' in kwargs: multiarch = mx.Suite._pop_list(kwargs, 'multiarch', context) self.multiarch = list(set(mx_subst.results_substitutions.substitute(arch) for arch in multiarch)) - if mx.get_arch() not in self.multiarch: - mx.abort('"multiarch" must contain the host architecture "{}"'.format(mx.get_arch()), context) + if mx.get_effective_arch() not in self.multiarch: + mx.abort('"multiarch" must contain the host architecture "{}"'.format(mx.get_effective_arch()), context) else: self.multiarch = [] super(MultiarchProject, self).__init__(suite, name, subDir, srcDirs, deps, workingSets, d, **kwargs) @@ -210,14 +210,14 @@ def newestOutput(self): return MultiarchBuildTask(self, args) else: - return self._build_task(mx.get_arch(), args) + return self._build_task(mx.get_effective_arch(), args) @abc.abstractmethod def _build_task(self, target_arch, args): """:rtype: TargetArchBuildTask""" def getArchivableResults(self, use_relpath=True, single=False): - for target_arch in self.multiarch if self._use_multiarch else [mx.get_arch()]: + for target_arch in self.multiarch if self._use_multiarch else [mx.get_effective_arch()]: toolchain = _Toolchain.for_(target_arch) target_arch_path = toolchain.target if self.multiarch else '' if toolchain.is_native or not single: @@ -392,7 +392,7 @@ class NinjaBuildTask(TargetArchBuildTask): require special consideration. """ - def __init__(self, args, project, target_arch=mx.get_arch(), ninja_targets=None): + def __init__(self, args, project, target_arch=mx.get_effective_arch(), ninja_targets=None): super(NinjaBuildTask, self).__init__(args, project, target_arch) self._reason = None self._manifest = mx.join(self.out_dir, Ninja.default_manifest) @@ -656,7 +656,7 @@ def __init__(self, suite, name, subDir, srcDirs, deps, workingSets, d, kind, **k self.include_dirs = [include_dir] if kind == 'static_lib': - self.libs = [mx.join(self.out_dir, mx.get_arch(), self._target)] + self.libs = [mx.join(self.out_dir, mx.get_effective_arch(), self._target)] @property def _target(self):