From b7bb7390ba43b0026e71b0465a3e3e41161ae594 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Fri, 8 Dec 2023 10:43:59 +0000 Subject: [PATCH] Bug 1867459 - Avoiding silently dismissing uses of CPU_ARCH. r=firefox-build-system-reviewers,sergesanspaille In many cases, using CONFIG["CPU_ARCH"] will silently do the unexpected thing now that it doesn't exist anymore. In case there are in-flight patches using it, it's better to avoid those causing subtle problems after a rebase by making most uses of the variable throw an exception. Differential Revision: https://phabricator.services.mozilla.com/D195158 --- build/moz.configure/init.configure | 1 + build/moz.configure/util.configure | 6 ++++++ python/mozbuild/mozbuild/configure/constants.py | 14 ++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/build/moz.configure/init.configure b/build/moz.configure/init.configure index dde3fa2ad386..11e22ee53682 100644 --- a/build/moz.configure/init.configure +++ b/build/moz.configure/init.configure @@ -825,6 +825,7 @@ set_config("OS_TARGET", target_variables.OS_TARGET) add_old_configure_assignment("OS_TARGET", target_variables.OS_TARGET) set_config("OS_ARCH", target_variables.OS_ARCH) add_old_configure_assignment("OS_ARCH", target_variables.OS_ARCH) +obsolete_config("CPU_ARCH", replacement="TARGET_CPU") set_config("INTEL_ARCHITECTURE", target_variables.INTEL_ARCHITECTURE) set_config("TARGET_CPU", target.cpu) add_old_configure_assignment("TARGET_CPU", target.cpu) diff --git a/build/moz.configure/util.configure b/build/moz.configure/util.configure index e307ae282f3e..3f6c83c5aea3 100644 --- a/build/moz.configure/util.configure +++ b/build/moz.configure/util.configure @@ -515,6 +515,12 @@ def project_flag(env=None, set_as_define=False, **kwargs): set_define(env, option_implementation) +@template +@imports(_from="mozbuild.configure.constants", _import="RaiseErrorOnUse") +def obsolete_config(name, *, replacement): + set_config(name, RaiseErrorOnUse(f"{name} is obsolete. Use {replacement} instead.")) + + # Hacks related to old-configure # ============================== diff --git a/python/mozbuild/mozbuild/configure/constants.py b/python/mozbuild/mozbuild/configure/constants.py index 5b6fb92bcfbc..d69d9c08efbe 100644 --- a/python/mozbuild/mozbuild/configure/constants.py +++ b/python/mozbuild/mozbuild/configure/constants.py @@ -7,6 +7,20 @@ from collections import OrderedDict from mozbuild.util import EnumString +class RaiseErrorOnUse(str): + def __init__(self, msg): + self.msg = msg + + def __eq__(self, other): + raise RuntimeError(self.msg) + + def __ne__(self, other): + self.__eq__(other) + + def __repr__(self): + return f"{self.__class__.__name__}({self.msg!r})" + + class CompilerType(EnumString): POSSIBLE_VALUES = ( "clang",