tools/variations/fieldtrial_util.py
def MergeFeaturesAndFieldTrialsArgs(args):
  """Merges duplicate features and field trials arguments.

  Merges multiple instances of --enable-features, --disable-features,
  --force-fieldtrials and --force-fieldtrial-params. Any such merged flags are
  moved to the end of the returned list. The original argument ordering is
  otherwise maintained.
  TODO(crbug.com/1033090): Add functionality to handle duplicate flags using the
  Foo<Bar syntax. Currently, the implementation considers e.g. 'Foo', 'Foo<Bar'
  and 'Foo<Baz' to be different. Also add functionality to handle cases where
  the same trial is specified with different groups via --force-fieldtrials,
  which isn't currently unhandled.

  Args:
    args: An iterable of strings representing command line arguments.

  Returns:
    A new list of strings representing the merged command line arguments.
  """
  merged_args = []
  disable_features = set()
  enable_features = set()
  force_fieldtrials = set()
  force_fieldtrial_params = set()
  for arg in args:
    if arg.startswith('--disable-features='):
      disable_features.update(arg.split('=', 1)[1].split(','))
    elif arg.startswith('--enable-features='):
      enable_features.update(arg.split('=', 1)[1].split(','))
    elif arg.startswith('--force-fieldtrials='):
      # A trailing '/' is optional. Do not split by '/' as that would separate
      # each group name from the corresponding trial name.
      force_fieldtrials.add(arg.split('=', 1)[1].rstrip('/'))
    elif arg.startswith('--force-fieldtrial-params='):
      force_fieldtrial_params.update(arg.split('=', 1)[1].split(','))
    else:
      merged_args.append(arg)

  # Sort arguments to ensure determinism.
  if disable_features:
    merged_args.append('--disable-features=%s' % ','.join(
        sorted(disable_features)))
  if enable_features:
    merged_args.append('--enable-features=%s' % ','.join(
        sorted(enable_features)))
  if force_fieldtrials:
    merged_args.append('--force-fieldtrials=%s' % '/'.join(
        sorted(force_fieldtrials)))
  if force_fieldtrial_params:
    merged_args.append('--force-fieldtrial-params=%s' % ','.join(
        sorted(force_fieldtrial_params)))

  return merged_args
Merges duplicate features and field trials arguments.

  Merges multiple instances of --enable-features, --disable-features,
  --force-fieldtrials and --force-fieldtrial-params. Any such merged flags are
  moved to the end of the returned list. The original argument ordering is
  otherwise maintained.
  TODO(crbug.com/1033090): Add functionality to handle duplicate flags using the
  Foo<Bar syntax. Currently, the implementation considers e.g. 'Foo', 'Foo<Bar'
  and 'Foo<Baz' to be different. Also add functionality to handle cases where
  the same trial is specified with different groups via --force-fieldtrials,
  which isn't currently unhandled.

  Args:
    args: An iterable of strings representing command line arguments.

  Returns:
    A new list of strings representing the merged command line arguments.
  
Merges duplicate features and field trials arguments.
Merges duplicate features and field trials arguments .
def MergeFeaturesAndFieldTrialsArgs(args):
  merged_args = []
  disable_features = set()
  enable_features = set()
  force_fieldtrials = set()
  force_fieldtrial_params = set()
  for arg in args:
    if arg.startswith('--disable-features='):
      disable_features.update(arg.split('=', 1)[1].split(','))
    elif arg.startswith('--enable-features='):
      enable_features.update(arg.split('=', 1)[1].split(','))
    elif arg.startswith('--force-fieldtrials='):
      force_fieldtrials.add(arg.split('=', 1)[1].rstrip('/'))
    elif arg.startswith('--force-fieldtrial-params='):
      force_fieldtrial_params.update(arg.split('=', 1)[1].split(','))
    else:
      merged_args.append(arg)
  if disable_features:
    merged_args.append('--disable-features=%s' % ','.join(
        sorted(disable_features)))
  if enable_features:
    merged_args.append('--enable-features=%s' % ','.join(
        sorted(enable_features)))
  if force_fieldtrials:
    merged_args.append('--force-fieldtrials=%s' % '/'.join(
        sorted(force_fieldtrials)))
  if force_fieldtrial_params:
    merged_args.append('--force-fieldtrial-params=%s' % ','.join(
        sorted(force_fieldtrial_params)))
  return merged_args
def MergeFeaturesAndFieldTrialsArgs ( args ) : merged_args = [ ] disable_features = set ( ) enable_features = set ( ) force_fieldtrials = set ( ) force_fieldtrial_params = set ( ) for arg in args : if arg . startswith ( '--disable-features=' ) : disable_features . update ( arg . split ( '=' , 1 ) [ 1 ] . split ( ',' ) ) elif arg . startswith ( '--enable-features=' ) : enable_features . update ( arg . split ( '=' , 1 ) [ 1 ] . split ( ',' ) ) elif arg . startswith ( '--force-fieldtrials=' ) : force_fieldtrials . add ( arg . split ( '=' , 1 ) [ 1 ] . rstrip ( '/' ) ) elif arg . startswith ( '--force-fieldtrial-params=' ) : force_fieldtrial_params . update ( arg . split ( '=' , 1 ) [ 1 ] . split ( ',' ) ) else : merged_args . append ( arg ) if disable_features : merged_args . append ( '--disable-features=%s' % ',' . join ( sorted ( disable_features ) ) ) if enable_features : merged_args . append ( '--enable-features=%s' % ',' . join ( sorted ( enable_features ) ) ) if force_fieldtrials : merged_args . append ( '--force-fieldtrials=%s' % '/' . join ( sorted ( force_fieldtrials ) ) ) if force_fieldtrial_params : merged_args . append ( '--force-fieldtrial-params=%s' % ',' . join ( sorted ( force_fieldtrial_params ) ) ) return merged_args
Merges duplicate features and field trials arguments.
Merges duplicate features and field trials arguments .
"""Merges duplicate features and field trials arguments.

  Merges multiple instances of --enable-features, --disable-features,
  --force-fieldtrials and --force-fieldtrial-params. Any such merged flags are
  moved to the end of the returned list. The original argument ordering is
  otherwise maintained.
  TODO(crbug.com/1033090): Add functionality to handle duplicate flags using the
  Foo<Bar syntax. Currently, the implementation considers e.g. 'Foo', 'Foo<Bar'
  and 'Foo<Baz' to be different. Also add functionality to handle cases where
  the same trial is specified with different groups via --force-fieldtrials,
  which isn't currently unhandled.

  Args:
    args: An iterable of strings representing command line arguments.

  Returns:
    A new list of strings representing the merged command line arguments.
  """ # A trailing '/' is optional. Do not split by '/' as that would separate # each group name from the corresponding trial name. # Sort arguments to ensure determinism.
A new list of strings representing the merged command line arguments.
A new list of strings representing the merged command line arguments .
args
An iterable of strings representing command line arguments.
An iterable of strings representing command line arguments .