Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: tools/variations/fieldtrial_util.py

Issue 1209743002: Generate a static struct from fieldtrial_testing_config (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@codegen_nested_structs
Patch Set: fix gn build Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 8
9 def _hex(ch): 9 def _hex(ch):
10 hv = hex(ord(ch)).replace('0x', '') 10 hv = hex(ord(ch)).replace('0x', '')
11 hv.zfill(2) 11 hv.zfill(2)
12 return hv.upper() 12 return hv.upper()
13 13
14 # URL escapes the delimiter characters from the output. urllib.quote is not 14 # URL escapes the delimiter characters from the output. urllib.quote is not
15 # used because it cannot escape '.'. 15 # used because it cannot escape '.'.
16 def _escape(str): 16 def _escape(str):
17 result = str 17 result = str
18 # Must perform replace on '%' first before the others. 18 # Must perform replace on '%' first before the others.
19 for c in '%:/.,': 19 for c in '%:/.,':
20 result = result.replace(c, '%' + _hex(c)) 20 result = result.replace(c, '%' + _hex(c))
21 return result 21 return result
22 22
23 # Generate a list of command-line switches to enable field trials defined in 23 # Generate a list of command-line switches to enable field trials defined in
24 # fieldtrial_testing_config_*.json. 24 # fieldtrial_testing_config_*.json.
25 def GenerateArgs(base_config_path, platform_config_path=None): 25 def GenerateArgs(config_path):
26 print config_path
26 try: 27 try:
27 with open(base_config_path, 'r') as base_file: 28 with open(config_path, 'r') as base_file:
28 variations = json.load(base_file) 29 variations = json.load(base_file)
29 if platform_config_path:
30 try:
31 with open(platform_config_path, 'r') as platform_file:
32 platform_specifics = json.load(platform_file)
33 variations.update(platform_specifics)
34 except (IOError, ValueError):
35 pass
36 except (IOError, ValueError): 30 except (IOError, ValueError):
37 return [] 31 return []
38 32
39 field_trials = [] 33 field_trials = []
40 params = [] 34 params = []
41 for trial, groups in variations.iteritems(): 35 for trial, groups in variations.iteritems():
42 if not len(groups): 36 if not len(groups):
43 continue 37 continue
44 # For now, only take the first group. 38 # For now, only take the first group.
45 group = groups[0] 39 group = groups[0]
(...skipping 18 matching lines...) Expand all
64 return args 58 return args
65 59
66 def main(): 60 def main():
67 if len(sys.argv) < 3: 61 if len(sys.argv) < 3:
68 print 'Usage: fieldtrial_util.py [base_config_path] [platform_config_path]' 62 print 'Usage: fieldtrial_util.py [base_config_path] [platform_config_path]'
69 exit(-1) 63 exit(-1)
70 print GenerateArgs(sys.argv[1], sys.argv[2]) 64 print GenerateArgs(sys.argv[1], sys.argv[2])
71 65
72 if __name__ == '__main__': 66 if __name__ == '__main__':
73 main() 67 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698