| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import sys | 6 import sys |
| 7 | 7 |
| 8 import fieldtrial_to_struct | 8 import fieldtrial_to_struct |
| 9 | 9 |
| 10 def _hex(ch): | 10 def _hex(ch): |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 seen = set() | 25 seen = set() |
| 26 duplicates = set() | 26 duplicates = set() |
| 27 for entry in entries: | 27 for entry in entries: |
| 28 if entry in seen: | 28 if entry in seen: |
| 29 duplicates.add(entry) | 29 duplicates.add(entry) |
| 30 else: | 30 else: |
| 31 seen.add(entry) | 31 seen.add(entry) |
| 32 return duplicates | 32 return duplicates |
| 33 | 33 |
| 34 def _CheckForDuplicateFeatures(enable_features, disable_features): | 34 def _CheckForDuplicateFeatures(enable_features, disable_features): |
| 35 enable_features = [f.split('<')[0] for f in enable_features] |
| 35 enable_features_set = set(enable_features) | 36 enable_features_set = set(enable_features) |
| 36 if len(enable_features_set) != len(enable_features): | 37 if len(enable_features_set) != len(enable_features): |
| 37 raise Exception('Duplicate feature(s) in enable_features: ' + | 38 raise Exception('Duplicate feature(s) in enable_features: ' + |
| 38 ', '.join(_FindDuplicates(enable_features))) | 39 ', '.join(_FindDuplicates(enable_features))) |
| 40 |
| 41 disable_features = [f.split('<')[0] for f in disable_features] |
| 39 disable_features_set = set(disable_features) | 42 disable_features_set = set(disable_features) |
| 40 if len(disable_features_set) != len(disable_features): | 43 if len(disable_features_set) != len(disable_features): |
| 41 raise Exception('Duplicate feature(s) in disable_features: ' + | 44 raise Exception('Duplicate feature(s) in disable_features: ' + |
| 42 ', '.join(_FindDuplicates(disable_features))) | 45 ', '.join(_FindDuplicates(disable_features))) |
| 46 |
| 43 features_in_both = enable_features_set.intersection(disable_features_set) | 47 features_in_both = enable_features_set.intersection(disable_features_set) |
| 44 if len(features_in_both) > 0: | 48 if len(features_in_both) > 0: |
| 45 raise Exception('Conflicting features set as both enabled and disabled: ' + | 49 raise Exception('Conflicting features set as both enabled and disabled: ' + |
| 46 ', '.join(features_in_both)) | 50 ', '.join(features_in_both)) |
| 47 | 51 |
| 48 # Generate a list of command-line switches to enable field trials for the | 52 # Generate a list of command-line switches to enable field trials for the |
| 49 # provided config_path and platform. | 53 # provided config_path and platform. |
| 50 def GenerateArgs(config_path, platform): | 54 def GenerateArgs(config_path, platform): |
| 51 try: | 55 try: |
| 52 with open(config_path, 'r') as config_file: | 56 with open(config_path, 'r') as config_file: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 72 if 'params' in experiment: | 76 if 'params' in experiment: |
| 73 for param in experiment['params']: | 77 for param in experiment['params']: |
| 74 param_list.append(param['key']) | 78 param_list.append(param['key']) |
| 75 param_list.append(param['value']) | 79 param_list.append(param['value']) |
| 76 if len(param_list): | 80 if len(param_list): |
| 77 # Escape the variables for the command-line. | 81 # Escape the variables for the command-line. |
| 78 selected_study = [_escape(x) for x in selected_study] | 82 selected_study = [_escape(x) for x in selected_study] |
| 79 param_list = [_escape(x) for x in param_list] | 83 param_list = [_escape(x) for x in param_list] |
| 80 param = '%s:%s' % ('.'.join(selected_study), '/'.join(param_list)) | 84 param = '%s:%s' % ('.'.join(selected_study), '/'.join(param_list)) |
| 81 params.append(param) | 85 params.append(param) |
| 82 if 'enable_features' in experiment: | 86 for feature in experiment.get('enable_features', []): |
| 83 enable_features.extend(experiment['enable_features']) | 87 enable_features.append(feature + '<' + study_name) |
| 84 if 'disable_features' in experiment: | 88 for feature in experiment.get('disable_features', []): |
| 85 disable_features.extend(experiment['disable_features']) | 89 disable_features.append(feature + '<' + study_name) |
| 86 | 90 |
| 87 if not len(studies): | 91 if not len(studies): |
| 88 return [] | 92 return [] |
| 89 _CheckForDuplicateFeatures(enable_features, disable_features) | 93 _CheckForDuplicateFeatures(enable_features, disable_features) |
| 90 args = ['--force-fieldtrials=%s' % '/'.join(studies)] | 94 args = ['--force-fieldtrials=%s' % '/'.join(studies)] |
| 91 if len(params): | 95 if len(params): |
| 92 args.append('--force-fieldtrial-params=%s' % ','.join(params)) | 96 args.append('--force-fieldtrial-params=%s' % ','.join(params)) |
| 93 if len(enable_features): | 97 if len(enable_features): |
| 94 args.append('--enable-features=%s' % ','.join(enable_features)) | 98 args.append('--enable-features="%s"' % ','.join(enable_features)) |
| 95 if len(disable_features): | 99 if len(disable_features): |
| 96 args.append('--disable-features=%s' % ','.join(disable_features)) | 100 args.append('--disable-features="%s"' % ','.join(disable_features)) |
| 97 return args | 101 return args |
| 98 | 102 |
| 99 def main(): | 103 def main(): |
| 100 if len(sys.argv) < 3: | 104 if len(sys.argv) < 3: |
| 101 print 'Usage: fieldtrial_util.py [config_path] [platform]' | 105 print 'Usage: fieldtrial_util.py [config_path] [platform]' |
| 102 exit(-1) | 106 exit(-1) |
| 103 | 107 |
| 104 supported_platforms = ['android', 'chromeos', 'ios', 'linux', 'mac', 'win'] | 108 supported_platforms = ['android', 'chromeos', 'ios', 'linux', 'mac', 'win'] |
| 105 if sys.argv[2] not in supported_platforms: | 109 if sys.argv[2] not in supported_platforms: |
| 106 print ('\'%s\' is an unknown platform. Supported platforms: %s' % | 110 print ('\'%s\' is an unknown platform. Supported platforms: %s' % |
| 107 (sys.argv[2], supported_platforms)) | 111 (sys.argv[2], supported_platforms)) |
| 108 exit(-1) | 112 exit(-1) |
| 109 | 113 |
| 110 print GenerateArgs(sys.argv[1], sys.argv[2]) | 114 print GenerateArgs(sys.argv[1], sys.argv[2]) |
| 111 | 115 |
| 112 if __name__ == '__main__': | 116 if __name__ == '__main__': |
| 113 main() | 117 main() |
| OLD | NEW |