# HG changeset patch # User Sylvestre Ledru # Date 1544122282 0 # Node ID 25282bb38b69e0abc5e16d700c38f18824bf7552 # Parent d940c84afc22ebd81c7c986270ee021ac6b88229 Bug 1510458 - Ride along: simplify the declaration (else after a return) r=ahal Depends on D13709 Differential Revision: https://phabricator.services.mozilla.com/D13710 diff --git a/python/mozbuild/mozbuild/mach_commands.py b/python/mozbuild/mozbuild/mach_commands.py --- a/python/mozbuild/mozbuild/mach_commands.py +++ b/python/mozbuild/mozbuild/mach_commands.py @@ -559,19 +559,18 @@ class Warnings(MachCommandBase): warning['flag'], warning['message'])) def join_ensure_dir(self, dir1, dir2): dir1 = mozpath.normpath(dir1) dir2 = mozpath.normsep(dir2) joined_path = mozpath.join(dir1, dir2) if os.path.isdir(joined_path): return joined_path - else: - print('Specified directory not found.') - return None + print('Specified directory not found.') + return None @CommandProvider class GTestCommands(MachCommandBase): @Command('gtest', category='testing', description='Run GTest unit tests (C++ tests).') @CommandArgument('gtest_filter', default=b"*", nargs='?', metavar='gtest_filter', help="test_filter is a ':'-separated list of wildcard patterns (called the positive patterns)," "optionally followed by a '-' and another ':'-separated pattern list (called the negative patterns).") @@ -2197,19 +2196,19 @@ class StaticAnalysis(MachCommandBase): else: rc = self._get_clang_tools(verbose=verbose) if rc != 0: return rc if path is None: return self._run_clang_format_diff(self._clang_format_diff, self._clang_format_path, show) - else: - if assume_filename: - return self._run_clang_format_in_console(self._clang_format_path, path, assume_filename) + + if assume_filename: + return self._run_clang_format_in_console(self._clang_format_path, path, assume_filename) return self._run_clang_format_path(self._clang_format_path, show, path) def _verify_checker(self, item): check = item['name'] test_file_path = mozpath.join(self._clang_tidy_base_path, "test", check) test_file_path_cpp = test_file_path + '.cpp' test_file_path_json = test_file_path + '.json' @@ -2354,36 +2353,36 @@ class StaticAnalysis(MachCommandBase): pass return (0, config, ran_configure) def _build_compile_db(self, verbose=False): self._compile_db = mozpath.join(self.topobjdir, 'compile_commands.json') if os.path.exists(self._compile_db): return 0 - else: - rc, config, ran_configure = self._get_config_environment() + + rc, config, ran_configure = self._get_config_environment() + if rc != 0: + return rc + + if ran_configure: + # Configure may have created the compilation database if the + # mozconfig enables building the CompileDB backend by default, + # So we recurse to see if the file exists once again. + return self._build_compile_db(verbose=verbose) + + if config: + print('Looks like a clang compilation database has not been ' + 'created yet, creating it now...') + builder = Build(self._mach_context) + rc = builder.build_backend(['CompileDB'], verbose=verbose) if rc != 0: return rc - - if ran_configure: - # Configure may have created the compilation database if the - # mozconfig enables building the CompileDB backend by default, - # So we recurse to see if the file exists once again. - return self._build_compile_db(verbose=verbose) - - if config: - print('Looks like a clang compilation database has not been ' - 'created yet, creating it now...') - builder = Build(self._mach_context) - rc = builder.build_backend(['CompileDB'], verbose=verbose) - if rc != 0: - return rc - assert os.path.exists(self._compile_db) - return 0 + assert os.path.exists(self._compile_db) + return 0 def _build_export(self, jobs, verbose=False): def on_line(line): self.log(logging.INFO, 'build_output', {'line': line}, '{line}') builder = Build(self._mach_context) # First install what we can through install manifests. rc = builder._run_make(directory=self.topobjdir, target='pre-export', @@ -2464,18 +2463,18 @@ class StaticAnalysis(MachCommandBase): return 0 job, _ = self.platform if job is None: raise Exception('The current platform isn\'t supported. ' 'Currently only the following platforms are ' 'supported: win32/win64, linux64 and macosx64.') - else: - job += '-clang-tidy' + + job += '-clang-tidy' # We want to unpack data in the clang-tidy mozbuild folder currentWorkingDir = os.getcwd() os.chdir(self._clang_tools_path) rc = self._artifact_manager.artifact_toolchain(verbose=verbose, skip_cache=skip_cache, from_build=[job], no_unpack=False, @@ -2542,44 +2541,44 @@ class StaticAnalysis(MachCommandBase): if rc != 0: return rc infer_path = mozpath.join(self._mach_context.state_dir, 'infer') self._infer_path = mozpath.join(infer_path, 'infer', 'bin', 'infer' + config.substs.get('BIN_SUFFIX', '')) if os.path.exists(self._infer_path) and not force: return 0 + + if os.path.isdir(infer_path) and download_if_needed: + # The directory exists, perhaps it's corrupted? Delete it + # and start from scratch. + shutil.rmtree(infer_path) + return self._get_infer(force=force, skip_cache=skip_cache, + verbose=verbose, + download_if_needed=download_if_needed) + os.mkdir(infer_path) + self._artifact_manager = PackageFrontend(self._mach_context) + if not download_if_needed: + return 0 + job, _ = self.platform + if job != 'linux64': + return -1 else: - if os.path.isdir(infer_path) and download_if_needed: - # The directory exists, perhaps it's corrupted? Delete it - # and start from scratch. - shutil.rmtree(infer_path) - return self._get_infer(force=force, skip_cache=skip_cache, - verbose=verbose, - download_if_needed=download_if_needed) - os.mkdir(infer_path) - self._artifact_manager = PackageFrontend(self._mach_context) - if not download_if_needed: - return 0 - job, _ = self.platform - if job != 'linux64': - return -1 - else: - job += '-infer' - # We want to unpack data in the infer mozbuild folder - currentWorkingDir = os.getcwd() - os.chdir(infer_path) - rc = self._artifact_manager.artifact_toolchain(verbose=verbose, - skip_cache=skip_cache, - from_build=[job], - no_unpack=False, - retry=0) - # Change back the cwd - os.chdir(currentWorkingDir) - return rc + job += '-infer' + # We want to unpack data in the infer mozbuild folder + currentWorkingDir = os.getcwd() + os.chdir(infer_path) + rc = self._artifact_manager.artifact_toolchain(verbose=verbose, + skip_cache=skip_cache, + from_build=[job], + no_unpack=False, + retry=0) + # Change back the cwd + os.chdir(currentWorkingDir) + return rc def _run_clang_format_diff(self, clang_format_diff, clang_format, show): # Run clang-format on the diff # Note that this will potentially miss a lot things from subprocess import Popen, PIPE, check_output, CalledProcessError diff_process = Popen(self._get_clang_format_diff_command(), stdout=PIPE) args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format] diff --git a/python/mozbuild/mozbuild/mach_commands.py.1510458-3.later b/python/mozbuild/mozbuild/mach_commands.py.1510458-3.later new file mode 100644 --- /dev/null +++ b/python/mozbuild/mozbuild/mach_commands.py.1510458-3.later @@ -0,0 +1,33 @@ +--- mach_commands.py ++++ mach_commands.py +@@ -1926,23 +1925,23 @@ class StaticAnalysis(MachCommandBase): + 'JAVA_TOOL_OPTIONS': '-Dfile.encoding=utf-8', + } + if suppress_output: + devnull = open(os.devnull, 'w') + return subprocess.call( + infer_args + [gradle] + args, + env=dict(os.environ, **extra_env), + cwd=cwd, stdout=devnull, stderr=subprocess.STDOUT, close_fds=True) +- else: +- return self.run_process( +- infer_args + [gradle] + args, +- append_env=extra_env, +- pass_thru=True, # Allow user to run gradle interactively. +- ensure_exit_code=False, # Don't throw on non-zero exit code. +- cwd=cwd) ++ ++ return self.run_process( ++ infer_args + [gradle] + args, ++ append_env=extra_env, ++ pass_thru=True, # Allow user to run gradle interactively. ++ ensure_exit_code=False, # Don't throw on non-zero exit code. ++ cwd=cwd) + + @StaticAnalysisSubCommand('static-analysis', 'autotest', + 'Run the auto-test suite in order to determine that' + ' the analysis did not regress.') + @CommandArgument('--dump-results', '-d', default=False, action='store_true', + help='Generate the baseline for the regression test. Based on' + ' this baseline we will test future results.') + @CommandArgument('--intree-tool', '-i', default=False, action='store_true',