Bug 898554 - Automatic mock-or-not commands in b2g build, r=aki
☠☠ backed out by 4ef9ebab4dc2 ☠ ☠
authorSteve Fink <sfink@mozilla.com>
Wed, 28 May 2014 11:05:58 -0700
changeset 2853 b2069bb5736ea2d6c645a1950fc6cdbbcbb9fce4
parent 2852 bb52596257c5f420b98f9ae0018c64a9712f9bcf
child 2854 e4d388ff871eab39f4f89130f789750274033900
push id2134
push usersfink@mozilla.com
push dateMon, 16 Jun 2014 19:55:58 +0000
reviewersaki
bugs898554
Bug 898554 - Automatic mock-or-not commands in b2g build, r=aki
mozharness/mozilla/mock.py
scripts/b2g_build.py
scripts/spidermonkey_build.py
--- a/mozharness/mozilla/mock.py
+++ b/mozharness/mozilla/mock.py
@@ -22,17 +22,17 @@ Nothing to remove.'
 # MockMixin {{{1
 class MockMixin(object):
     """Provides methods to setup and interact with mock environments.
     https://wiki.mozilla.org/ReleaseEngineering/Applications/Mock
 
     This is dependent on ScriptMixin
     """
     done_mock_setup = False
-    mock_enabled = False
+    active_mock_target = None
 
     def init_mock(self, mock_target):
         "Initialize mock environment defined by `mock_target`"
         cmd = ['mock_mozilla', '-r', mock_target, '--init']
         return super(MockMixin, self).run_command(cmd, halt_on_failure=True,
                                                   fatal_exit_code=3)
 
     def install_mock_packages(self, mock_target, packages):
@@ -61,31 +61,33 @@ class MockMixin(object):
             super(MockMixin, self).run_command(cmd, halt_on_failure=True,
                                                fatal_exit_code=3)
             super(MockMixin, self).run_command(
                 ['mock_mozilla', '-r', mock_target, '--shell',
                  'chown -R mock_mozilla %s' % dest],
                 halt_on_failure=True,
                 fatal_exit_code=3)
 
-    def enable_mock(self):
+    def enable_mock(self, config=None):
         """Wrap self.run_command and self.get_output_from_command to run inside
         the mock environment given by self.config['mock_target']"""
-        if not 'mock_target' in self.config:
+        if not config:
+            config = self.config
+        if not 'mock_target' in config:
             return
-        self.mock_enabled = True
+        self.active_mock_target = config['mock_target']
         self.run_command = self.run_command_m
         self.get_output_from_command = self.get_output_from_command_m
 
     def disable_mock(self):
         """Restore self.run_command and self.get_output_from_command to their
         original versions. This is the opposite of self.enable_mock()"""
-        if not 'mock_target' in self.config:
+        if not self.active_mock_target:
             return
-        self.mock_enabled = False
+        self.active_mock_target = None
         self.run_command = super(MockMixin, self).run_command
         self.get_output_from_command = super(MockMixin, self).get_output_from_command
 
     def _do_mock_command(self, func, mock_target, command, cwd=None, env=None, **kwargs):
         """Internal helper for preparing commands to run under mock. Used by
         run_mock_command and get_mock_output_from_command."""
         cmd = ['mock_mozilla', '-r', mock_target, '-q']
         if cwd:
@@ -218,25 +220,25 @@ class MockMixin(object):
                 # exist, so we need to delete them here first
                 self.info("Deleting old mock files")
                 self.delete_mock_files(t, mock_files)
             self.copy_mock_files(t, mock_files)
 
         self.done_mock_setup = True
 
     def run_command_m(self, *args, **kwargs):
-        """Executes self.run_mock_command if self.config['mock_target'] is set,
+        """Executes self.run_mock_command if self.active_mock_target is set,
         otherwise executes self.run_command."""
-        if 'mock_target' in self.config:
+        if self.active_mock_target:
             self.setup_mock()
-            return self.run_mock_command(self.config['mock_target'], *args, **kwargs)
+            return self.run_mock_command(self.active_mock_target, *args, **kwargs)
         else:
             return super(MockMixin, self).run_command(*args, **kwargs)
 
     def get_output_from_command_m(self, *args, **kwargs):
         """Executes self.get_mock_output_from_command if
-        self.config['mock_target'] is set, otherwise executes
+        self.active_mock_target is set, otherwise executes
         self.get_output_from_command."""
-        if 'mock_target' in self.config:
+        if self.active_mock_target:
             self.setup_mock()
-            return self.get_mock_output_from_command(self.config['mock_target'], *args, **kwargs)
+            return self.get_mock_output_from_command(self.active_mock_target, *args, **kwargs)
         else:
             return super(MockMixin, self).get_output_from_command(*args, **kwargs)
--- a/scripts/b2g_build.py
+++ b/scripts/b2g_build.py
@@ -945,95 +945,89 @@ class B2GBuild(LocalesMixin, MockMixin, 
             env['L10NBASEDIR'] = dirs['abs_l10n_dir']
             env['MOZ_CHROME_MULTILOCALE'] = " ".join(self.query_locales())
             if 'PATH' not in env:
                 env['PATH'] = os.environ.get('PATH')
             env['PATH'] += ':%s' % os.path.join(dirs['compare_locales_dir'], 'scripts')
             env['PYTHONPATH'] = os.environ.get('PYTHONPATH', '')
             env['PYTHONPATH'] += ':%s' % os.path.join(dirs['compare_locales_dir'], 'lib')
 
-        if 'mock_target' in gecko_config:
-            # initialize mock
+        self.enable_mock(config=gecko_config)
+        if self.active_mock_target:
             self.setup_mock(gecko_config['mock_target'], gecko_config['mock_packages'], gecko_config.get('mock_files'))
-            if self.config['ccache']:
-                self.run_mock_command(gecko_config['mock_target'], 'ccache -z', cwd=dirs['work_dir'], env=env)
+
+        if self.config['ccache']:
+            self.run_command('ccache -z', cwd=dirs['work_dir'], env=env)
 
-            for cmd in cmds:
-                retval = self.run_mock_command(gecko_config['mock_target'], cmd, cwd=dirs['work_dir'], env=env, error_list=B2GMakefileErrorList)
-                if retval != 0:
-                    break
-            if self.config['ccache']:
-                self.run_mock_command(gecko_config['mock_target'], 'ccache -s', cwd=dirs['work_dir'], env=env)
-        else:
-            if self.config['ccache']:
-                self.run_command('ccache -z', cwd=dirs['work_dir'], env=env)
-            for cmd in cmds:
-                retval = self.run_command(cmd, cwd=dirs['work_dir'], env=env, error_list=B2GMakefileErrorList)
-                if retval != 0:
-                    break
-            if self.config['ccache']:
-                self.run_command('ccache -s', cwd=dirs['work_dir'], env=env)
+        for cmd in cmds:
+            retval = self.run_command(cmd, cwd=dirs['work_dir'], env=env, error_list=B2GMakefileErrorList)
+            if retval != 0:
+                break
+
+        if self.config['ccache']:
+            self.run_command('ccache -s', cwd=dirs['work_dir'], env=env)
 
         if retval != 0:
             self.fatal("failed to build", exit_code=2)
 
+        self.disable_mock()
+
         buildid = self.query_buildid()
         self.set_buildbot_property('buildid', buildid, write_to_file=True)
 
     def build_symbols(self):
         dirs = self.query_abs_dirs()
         gecko_config = self.load_gecko_config()
         if gecko_config.get('config_version', 0) < 1:
             self.info("Skipping build_symbols for old configuration")
             return
 
         cmd = ['./build.sh', 'buildsymbols']
         env = self.query_build_env()
 
-        if 'mock_target' in gecko_config:
-            # initialize mock
+        self.enable_mock(config=gecko_config)
+        if self.active_mock_target:
             self.setup_mock(gecko_config['mock_target'], gecko_config['mock_packages'], gecko_config.get('mock_files'))
-            retval = self.run_mock_command(gecko_config['mock_target'], cmd, cwd=dirs['work_dir'], env=env, error_list=B2GMakefileErrorList)
-        else:
-            retval = self.run_command(cmd, cwd=dirs['work_dir'], env=env, error_list=B2GMakefileErrorList)
+
+        retval = self.run_command(cmd, cwd=dirs['work_dir'], env=env, error_list=B2GMakefileErrorList)
 
         if retval != 0:
             self.fatal("failed to build symbols", exit_code=2)
 
         if self.query_is_nightly():
             # Upload symbols
             self.info("Uploading symbols")
             cmd = ['./build.sh', 'uploadsymbols']
-            if 'mock_target' in gecko_config:
-                retval = self.run_mock_command(gecko_config['mock_target'], cmd, cwd=dirs['work_dir'], env=env, error_list=B2GMakefileErrorList)
-            else:
-                retval = self.run_command(cmd, cwd=dirs['work_dir'], env=env, error_list=B2GMakefileErrorList)
+            retval = self.run_command(cmd, cwd=dirs['work_dir'], env=env, error_list=B2GMakefileErrorList)
 
             if retval != 0:
                 self.fatal("failed to upload symbols", exit_code=2)
 
+        self.disable_mock()
+
     def make_updates(self):
         if not self.query_is_nightly():
             self.info("Not a nightly build. Skipping...")
             return
         dirs = self.query_abs_dirs()
         gecko_config = self.load_gecko_config()
         cmd = self.make_updates_cmd[:]
         env = self.query_build_env()
 
-        if 'mock_target' in gecko_config:
-            # initialize mock
+        self.enable_mock(config=gecko_config)
+        if self.active_mock_target:
             self.setup_mock(gecko_config['mock_target'], gecko_config['mock_packages'], gecko_config.get('mock_files'))
-            retval = self.run_mock_command(gecko_config['mock_target'], cmd, cwd=dirs['work_dir'], env=env, error_list=B2GMakefileErrorList)
-        else:
-            retval = self.run_command(cmd, cwd=dirs['work_dir'], env=env, error_list=B2GMakefileErrorList)
+
+        retval = self.run_command(cmd, cwd=dirs['work_dir'], env=env, error_list=B2GMakefileErrorList)
 
         if retval != 0:
             self.fatal("failed to create complete update", exit_code=2)
 
+        self.disable_mock()
+
         # Sign the updates
         self.sign_updates()
 
     def sign_updates(self):
         if 'MOZ_SIGNING_SERVERS' not in os.environ:
             self.info("Skipping signing since no MOZ_SIGNING_SERVERS set")
             return
 
--- a/scripts/spidermonkey_build.py
+++ b/scripts/spidermonkey_build.py
@@ -237,17 +237,17 @@ class SpidermonkeyBuild(MockMixin,
         else:
             return self.config['upload_ssh_server']
 
     def query_upload_ssh_key(self):
         if self.buildbot_config and 'properties' in self.buildbot_config:
             key = self.buildbot_config['properties']['upload_ssh_key']
         else:
             key = self.config['upload_ssh_key']
-        if self.mock_enabled and not key.startswith("/"):
+        if self.active_mock_target and not key.startswith("/"):
             key = "/home/mock_mozilla/.ssh/" + key
         return key
 
     def query_upload_ssh_user(self):
         if self.buildbot_config and 'properties' in self.buildbot_config:
             return self.buildbot_config['properties']['upload_ssh_user']
         else:
             return self.config['upload_ssh_user']