# Copyright 2015 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. from __future__ import print_function import json import sys import fieldtrial_to_struct def _hex(ch): hv = hex(ord(ch)).replace('0x', '') hv.zfill(2) return hv.upper() # URL escapes the delimiter characters from the output. urllib.quote is not # used because it cannot escape '.'. def _escape(str): result = str # Must perform replace on '%' first before the others. for c in '%:/.,': result = result.replace(c, '%' + _hex(c)) return result def _FindDuplicates(entries): seen = set() duplicates = set() for entry in entries: if entry in seen: duplicates.add(entry) else: seen.add(entry) return duplicates def _CheckForDuplicateFeatures(enable_features, disable_features): enable_features = [f.split('<')[0] for f in enable_features] enable_features_set = set(enable_features) if len(enable_features_set) != len(enable_features): raise Exception('Duplicate feature(s) in enable_features: ' + ', '.join(_FindDuplicates(enable_features))) disable_features = [f.split('<')[0] for f in disable_features] disable_features_set = set(disable_features) if len(disable_features_set) != len(disable_features): raise Exception('Duplicate feature(s) in disable_features: ' + ', '.join(_FindDuplicates(disable_features))) features_in_both = enable_features_set.intersection(disable_features_set) if len(features_in_both) > 0: raise Exception('Conflicting features set as both enabled and disabled: ' + ', '.join(features_in_both)) def _FindFeaturesOverriddenByArgs(args): """Returns a list of the features enabled or disabled by the flags in args.""" overridden_features = [] for arg in args: if (arg.startswith('--enable-features=') or arg.startswith('--disable-features=')): _, _, arg_val = arg.partition('=') overridden_features.extend(arg_val.split(',')) return [f.split('<')[0] for f in overridden_features] 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= 4 and sys.argv[3] == 'shell_cmd' supported_platforms = ['android', 'android_webview', 'chromeos', 'ios', 'linux', 'mac', 'windows'] if sys.argv[2] not in supported_platforms: print('\'%s\' is an unknown platform. Supported platforms: %s' % (sys.argv[2], supported_platforms)) exit(-1) generated_args = GenerateArgs(sys.argv[1], sys.argv[2]) if print_shell_cmd: print(" ".join(map((lambda arg: '"{0}"'.format(arg)), generated_args))) else: print(generated_args) if __name__ == '__main__': main()