Bug 1172574 - Add ability to clone profiles and set prefs to |mach run| draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 26 Jul 2017 16:56:55 -0400
changeset 616189 754e3d102e4e7b9c2e1d0595612b6be70d485e16
parent 615779 e8400551c2e39f24c75a009ebed496c7acd7bf47
child 639418 55157a0d503267cb3b703d17f1cf0ffc31d6250a
push id70626
push userahalberstadt@mozilla.com
push dateWed, 26 Jul 2017 20:57:34 +0000
bugs1172574
milestone56.0a1
Bug 1172574 - Add ability to clone profiles and set prefs to |mach run| MozReview-Commit-ID: HO3tdFi9ffi
python/mozbuild/mozbuild/locale/en_US/LC_MESSAGES/runprefs.mo
python/mozbuild/mozbuild/locale/en_US/LC_MESSAGES/runprefs.po
python/mozbuild/mozbuild/mach_commands.py
new file mode 100644
index 0000000000000000000000000000000000000000..84a020d1976a96eed2b16d8f64c3d90ef20df5a2
GIT binary patch
literal 232
zc$~W@#4?ou2$+Fb28c}<AixKS<_BV5AQk}PSg3d&5PJe~J`n2x@lKFnQE6U5QEFPT
zo|ax(X-*C@zc?emsDyzbAhEbuAyEM&s*ssilCR*F31sG1D3oWU<|&jGXXd3VB;+P0
nXD9&mCg>>Srzw<Vq$;H47v%zpe7&T^BHOaWoYGVhO=185!*e_f
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/locale/en_US/LC_MESSAGES/runprefs.po
@@ -0,0 +1,10 @@
+#
+msgid ""
+msgstr ""
+
+msgid "runprefs.*.short"
+msgstr "Pass a pref into Firefox when using `mach run`"
+
+msgid "runprefs.*.full"
+msgstr ""
+"Pass a pref into Firefox when using `mach run`, of the form foo.bar=value"
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -20,16 +20,17 @@ from collections import OrderedDict
 
 import mozpack.path as mozpath
 
 from mach.decorators import (
     CommandArgument,
     CommandArgumentGroup,
     CommandProvider,
     Command,
+    SettingsProvider,
     SubCommand,
 )
 
 from mach.mixin.logging import LoggingMixin
 
 from mozbuild.base import (
     BuildEnvironmentNotFoundException,
     MachCommandBase,
@@ -1231,16 +1232,24 @@ class Install(MachCommandBase):
         if conditions.is_android(self):
             from mozrunner.devices.android_device import verify_android_device
             verify_android_device(self, verbose=verbose)
         ret = self._run_make(directory=".", target='install', ensure_exit_code=False)
         if ret == 0:
             self.notify('Install complete')
         return ret
 
+
+@SettingsProvider
+class RunSettings():
+    config_settings = [
+        ('runprefs.*', 'string'),
+    ]
+
+
 @CommandProvider
 class RunProgram(MachCommandBase):
     """Run the compiled program."""
 
     prog_group = 'the compiled program'
 
     @Command('run', category='post-build',
         description='Run the compiled program, possibly under a debugger or DMD.')
@@ -1252,16 +1261,20 @@ class RunProgram(MachCommandBase):
     @CommandArgument('--background', '-b', action='store_true', group=prog_group,
         help='Do not pass the --foreground argument by default on Mac.')
     @CommandArgument('--noprofile', '-n', action='store_true', group=prog_group,
         help='Do not pass the --profile argument by default.')
     @CommandArgument('--disable-e10s', action='store_true', group=prog_group,
         help='Run the program with electrolysis disabled.')
     @CommandArgument('--enable-crash-reporter', action='store_true', group=prog_group,
         help='Run the program with the crash reporter enabled.')
+    @CommandArgument('--profile', group=prog_group, default=None,
+        help='Run the program with a clone of the specified profile.')
+    @CommandArgument('--setpref', action='append', default=[], group=prog_group,
+        help='Run the program with the specified pref. Can be set multiple times')
 
     @CommandArgumentGroup('debugging')
     @CommandArgument('--debug', action='store_true', group='debugging',
         help='Enable the debugger. Not specifying a --debugger option will result in the default debugger being used.')
     @CommandArgument('--debugger', default=None, type=str, group='debugging',
         help='Name of debugger to use.')
     @CommandArgument('--debugger-args', default=None, metavar='params', type=str,
         group='debugging',
@@ -1275,32 +1288,33 @@ class RunProgram(MachCommandBase):
         help='Enable DMD. The following arguments have no effect without this.')
     @CommandArgument('--mode', choices=['live', 'dark-matter', 'cumulative', 'scan'], group='DMD',
          help='Profiling mode. The default is \'dark-matter\'.')
     @CommandArgument('--stacks', choices=['partial', 'full'], group='DMD',
         help='Allocation stack trace coverage. The default is \'partial\'.')
     @CommandArgument('--show-dump-stats', action='store_true', group='DMD',
         help='Show stats when doing dumps.')
     def run(self, params, remote, background, noprofile, disable_e10s,
-        enable_crash_reporter, debug, debugger, debugger_args,
-        dmd, mode, stacks, show_dump_stats):
+        enable_crash_reporter, profile, setpref, debug, debugger,
+        debugger_args, dmd, mode, stacks, show_dump_stats):
 
         if conditions.is_android(self):
             # Running Firefox for Android is completely different
             if dmd:
                 print("DMD is not supported for Firefox for Android")
                 return 1
             from mozrunner.devices.android_device import verify_android_device, run_firefox_for_android
             if not (debug or debugger or debugger_args):
                 verify_android_device(self, install=True)
                 return run_firefox_for_android(self, params)
             verify_android_device(self, install=True, debugger=True)
             args = ['']
 
         else:
+            from mozprofile import Profile
 
             try:
                 binpath = self.get_binary_path('app')
             except Exception as e:
                 print("It looks like your program isn't built.",
                     "You can run |mach build| to build it.")
                 print(e)
                 return 1
@@ -1312,23 +1326,28 @@ class RunProgram(MachCommandBase):
 
             if not remote:
                 args.append('-no-remote')
 
             if not background and sys.platform == 'darwin':
                 args.append('-foreground')
 
             no_profile_option_given = \
-                all(p not in params for p in ['-profile', '--profile', '-P'])
+                all(p not in params for p in ['-profile', '-P'])
             if no_profile_option_given and not noprofile:
-                path = os.path.join(self.topobjdir, 'tmp', 'scratch_user')
-                if not os.path.isdir(path):
-                    os.makedirs(path)
+                prefs = dict([p.split('=', 1) for p in setpref])
+                prefs.update(self._mach_context.settings.runprefs)
+
+                if profile:
+                    profile = Profile.clone(profile, preferences=prefs)
+                else:
+                    path = os.path.join(self.topobjdir, 'tmp', 'scratch_user')
+                    profile = Profile(path, preferences=prefs, restore=False)
                 args.append('-profile')
-                args.append(path)
+                args.append(profile.profile)
 
         extra_env = {
             'MOZ_DEVELOPER_REPO_DIR': self.topsrcdir,
             'MOZ_DEVELOPER_OBJ_DIR': self.topobjdir,
             'RUST_BACKTRACE': '1',
         }
 
         if not enable_crash_reporter: