Bug 1468547 - Re-factor gtest mach command to not invoke make when not necessary. draft
authorChris Manchester <cmanchester@mozilla.com>
Mon, 09 Jul 2018 14:28:59 -0700
changeset 815749 6f7dda6f4719ba373eb5146c76ab0ef16792d107
parent 815748 51f6a7ac5075e8f7618d2d03371447a3c6235787
push id115642
push userbmo:cmanchester@mozilla.com
push dateMon, 09 Jul 2018 21:41:32 +0000
bugs1468547
milestone63.0a1
Bug 1468547 - Re-factor gtest mach command to not invoke make when not necessary. MozReview-Commit-ID: 6j7t0YIZc8n
python/mozbuild/mozbuild/mach_commands.py
testing/gtest/Makefile.in
toolkit/library/Makefile.in
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -588,18 +588,44 @@ class GTestCommands(MachCommandBase):
     @CommandArgument('--debugger-args', default=None, metavar='params', type=str,
         group='debugging',
         help='Command-line arguments to pass to the debugger itself; split as the Bourne shell would.')
 
     def gtest(self, shuffle, jobs, gtest_filter, tbpl_parser, debug, debugger,
               debugger_args):
 
         # We lazy build gtest because it's slow to link
-        self._run_make(directory="testing/gtest", target='gtest',
-                       print_directory=False, ensure_exit_code=True)
+        try:
+            config = self.config_environment
+        except Exception:
+            print("Please run |./mach build| before |./mach gtest|.")
+            return 1
+
+        active_backend = config.substs.get('BUILD_BACKENDS', [None])[0]
+        if 'Tup' in active_backend:
+            gtest_build_path = mozpath.join(self.topobjdir, '<gtest>')
+        else:
+            # This path happens build the necessary parts of the tree in the
+            # Make backend due to the odd nature of partial tree builds.
+            gtest_build_path = mozpath.relpath(mozpath.join(self.topobjdir,
+                                                            'toolkit', 'library',
+                                                            'gtest', 'rust'),
+                                               self.topsrcdir)
+
+        os.environ[b'LINK_GTEST_DURING_COMPILE'] = b'1'
+        res = self._mach_context.commands.dispatch('build', self._mach_context,
+                                                   what=[gtest_build_path])
+        del os.environ[b'LINK_GTEST_DURING_COMPILE']
+        if res:
+            print("Could not build xul-gtest")
+            return res
+
+        if self.substs.get('MOZ_WIDGET_TOOLKIT') == 'cocoa':
+            self._run_make(directory='browser/app', target='repackage',
+                           ensure_exit_code=True)
 
         app_path = self.get_binary_path('app')
         args = [app_path, '-unittest', '--gtest_death_test_style=threadsafe'];
 
         if debug or debugger or debugger_args:
             args = self.prepend_debugger_args(args, debugger, debugger_args)
 
         cwd = os.path.join(self.topobjdir, '_tests', 'gtest')
deleted file mode 100644
--- a/testing/gtest/Makefile.in
+++ /dev/null
@@ -1,18 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-# Avoid recursive make to avoid having to add files to the gtest/ subdirectory
-# (which is third-party code), and to make the build faster.
-
-include $(topsrcdir)/config/rules.mk
-
-ifeq (browser,$(MOZ_BUILD_APP))
-ifdef COMPILE_ENVIRONMENT
-gtest::
-	$(MAKE) -C $(DEPTH)/toolkit/library gtestxul
-ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-	$(MAKE) -C $(DEPTH)/browser/app repackage
-endif
-endif
-endif
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -3,13 +3,9 @@
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 include $(topsrcdir)/toolkit/library/libxul.mk
 
 include $(topsrcdir)/config/config.mk
 
 include $(topsrcdir)/config/rules.mk
 
-.PHONY: gtestxul
-gtestxul:
-	$(MAKE) -C $(DEPTH) toolkit/library/gtest/target LINK_GTEST_DURING_COMPILE=1
-
 DUMP_SYMBOLS_FLAGS = --count-ctors