From a669bc807e0749475b86c607da3282f9517543f1 Mon Sep 17 00:00:00 2001 From: Andi-Bogdan Postelnicu Date: Tue, 12 Nov 2019 14:01:46 +0000 Subject: [PATCH] Bug 1406309 - add `AUTOCLOBBER` for our static-analysis targets. r=bastien Differential Revision: https://phabricator.services.mozilla.com/D52169 --- .../mozbuild/code-analysis/mach_commands.py | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py index e5bc6fd3abf2..a9e0d7c19098 100644 --- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py +++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py @@ -35,6 +35,8 @@ import mozpack.path as mozpath from mozversioncontrol import get_repository_object +from mozbuild.controller.clobber import Clobberer + # Function used to run clang-format on a batch of files. It is a helper function # in order to integrate into the futures ecosystem clang-format. @@ -60,6 +62,19 @@ def map_file_to_source(abs_path, source): return None +def prompt_bool(prompt, limit=5): + ''' Prompts the user with prompt and requires a boolean value. ''' + from distutils.util import strtobool + + for _ in range(limit): + try: + return strtobool(raw_input(prompt + "[Y/N]\n")) + except ValueError: + print("ERROR! Please enter a valid option! Please use any of the following:" + " Y, N, True, False, 1, 0") + return False + + class StaticAnalysisSubCommand(SubCommand): def __call__(self, func): after = SubCommand.__call__(self, func) @@ -1735,7 +1750,22 @@ class StaticAnalysis(MachCommandBase): try: config = self.config_environment except Exception: - print('Looks like configure has not run yet, running it now...') + self.log(logging.WARNING, 'static-analysis', {}, + "Looks like configure has not run yet, running it now...") + + clobber = Clobberer(self.topsrcdir, self.topobjdir) + + if clobber.clobber_needed(): + choice = prompt_bool( + "Configuration has changed and Clobber is needed. " + "Do you want to proceed?" + ) + if not choice: + self.log(logging.ERROR, 'static-analysis', {}, + "Without Clobber we cannot continue execution!") + return (1, None, None) + os.environ["AUTOCLOBBER"] = "1" + rc = builder.configure() if rc != 0: return (rc, config, ran_configure)