Bug 1172574 - Allow for setting prefs in mach run for scratch_user;r=gps draft
authorBrian Grinstead <bgrinstead@mozilla.com>
Fri, 28 Jul 2017 15:38:22 -0700
changeset 617895 3c2e6f33567448c19defafb656e6cb9f3a729391
parent 617496 16ffc1d05422a81099ce8b9b59de66dde4c8b2f0
child 617896 fb8a1bdc77afd00019f9149add4ae054d6362ac0
push id71145
push userbgrinstead@mozilla.com
push dateFri, 28 Jul 2017 22:39:01 +0000
reviewersgps
bugs1172574
milestone56.0a1
Bug 1172574 - Allow for setting prefs in mach run for scratch_user;r=gps Prefs can be set with `./mach run --setpref foo=bar` or in the ~/.mozbuild/machrc file as: [runprefs] foo=bar MozReview-Commit-ID: HO3tdFi9ffi
python/mach/mach/config.py
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
--- a/python/mach/mach/config.py
+++ b/python/mach/mach/config.py
@@ -295,16 +295,17 @@ class ConfigSettings(collections.Mapping
 
         @reraise_attribute_error
         def __delattr__(self, k):
             self.__delitem__(k)
 
 
     def __init__(self):
         self._config = RawConfigParser()
+        self._config.optionxform = str
 
         self._settings = {}
         self._sections = {}
         self._finalized = False
         self.loaded_files = set()
 
     def load_file(self, filename):
         self.load_files([filename])
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,22 @@ 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 +1259,18 @@ 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('--setpref', action='append', default=[], group=prog_group,
+        help='Set the specified pref before starting the program. Can be set multiple times. Prefs can also be set in ~/.mozbuild/machrc in the [runprefs] section - see `./mach settings` for more information.')
 
     @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 +1284,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, 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, Preferences
 
             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
@@ -1314,21 +1324,30 @@ class RunProgram(MachCommandBase):
                 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'])
             if no_profile_option_given and not noprofile:
+                prefs = { }
+                prefs.update(self._mach_context.settings.runprefs)
+                prefs.update([p.split('=', 1) for p in setpref])
+                for pref in prefs:
+                    prefs[pref] = Preferences.cast(prefs[pref])
+
                 path = os.path.join(self.topobjdir, 'tmp', 'scratch_user')
-                if not os.path.isdir(path):
-                    os.makedirs(path)
+                profile = Profile(path, preferences=prefs)
                 args.append('-profile')
-                args.append(path)
+                args.append(profile.profile)
+
+            if not no_profile_option_given and setpref:
+                print("setpref is only supported if a profile is not specified")
+                return 1
 
         extra_env = {
             'MOZ_DEVELOPER_REPO_DIR': self.topsrcdir,
             'MOZ_DEVELOPER_OBJ_DIR': self.topobjdir,
             'RUST_BACKTRACE': '1',
         }
 
         if not enable_crash_reporter: