--- 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: