Bug 1510458 - Ride along: simplify the declaration (else after a return) r=ahal
authorSylvestre Ledru <sledru@mozilla.com>
Thu, 06 Dec 2018 18:51:22 +0000
changeset 449537 25282bb38b69e0abc5e16d700c38f18824bf7552
parent 449536 c9f6a7c04316b139e6f128f9a3f41f1400150a68
child 449538 43833d2f4dbd49a42fc8ffb0847f768320a9402e
child 449567 a52c254930e8fd4372d2a439b8e0e6cc10a351f8
push id74330
push usersledru@mozilla.com
push dateThu, 06 Dec 2018 18:55:08 +0000
treeherderautoland@25282bb38b69 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1510458
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1510458 - Ride along: simplify the declaration (else after a return) r=ahal Depends on D13709 Differential Revision: https://phabricator.services.mozilla.com/D13710
python/mozbuild/mozbuild/mach_commands.py
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -560,19 +560,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).")
@@ -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',
@@ -2360,19 +2359,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'
@@ -2517,36 +2516,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',
@@ -2626,18 +2625,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,
@@ -2706,44 +2705,44 @@ class StaticAnalysis(MachCommandBase):
         infer_path = self.topsrcdir if intree_tool else \
             mozpath.join(self._mach_context.state_dir, 'infer')
         self._infer_path = mozpath.join(infer_path, 'infer', 'bin', 'infer' +
                                         config.substs.get('BIN_SUFFIX', ''))
         if intree_tool:
             return not os.path.exists(self._infer_path)
         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]