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

Side by Side Diff: tools/gn/bin/gyp_flag_compare.py

Issue 1319063004: Make gyp_flag_compare.py work on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright 2014 The Chromium Authors. All rights reserved. 3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Given the output of -t commands from a ninja build for a gyp and GN generated 7 """Given the output of -t commands from a ninja build for a gyp and GN generated
8 build, report on differences between the command lines.""" 8 build, report on differences between the command lines."""
9 9
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 if x.startswith('-g') and x != '-g0': 62 if x.startswith('-g') and x != '-g0':
63 have_some_symbols = True 63 have_some_symbols = True
64 if not have_some_symbols and '-g0' in command_line: 64 if not have_some_symbols and '-g0' in command_line:
65 command_line.remove('-g0') 65 command_line.remove('-g0')
66 66
67 # Rename -g2 to -g. 67 # Rename -g2 to -g.
68 if '-g2' in command_line: 68 if '-g2' in command_line:
69 command_line[command_line.index('-g2')] = '-g' 69 command_line[command_line.index('-g2')] = '-g'
70 70
71 71
72 def GetFlags(lines): 72 def GetFlags(lines, build_dir):
73 """Turn a list of command lines into a semi-structured dict.""" 73 """Turn a list of command lines into a semi-structured dict."""
74 is_win = sys.platform == 'win32'
74 flags_by_output = {} 75 flags_by_output = {}
75 for line in lines: 76 for line in lines:
76 # TODO(scottmg): Hacky way of getting only cc for now. 77 command_line = shlex.split(line.strip(), posix=not is_win)[1:]
77 if 'clang' not in line:
78 continue
79
80 command_line = shlex.split(line.strip())[1:]
81 78
82 output_name = FindAndRemoveArgWithValue(command_line, '-o') 79 output_name = FindAndRemoveArgWithValue(command_line, '-o')
83 dep_name = FindAndRemoveArgWithValue(command_line, '-MF') 80 dep_name = FindAndRemoveArgWithValue(command_line, '-MF')
84 81
85 NormalizeSymbolArguments(command_line) 82 NormalizeSymbolArguments(command_line)
86 83
87 command_line = MergeSpacedArgs(command_line, '-Xclang') 84 command_line = MergeSpacedArgs(command_line, '-Xclang')
88 85
89 defines = [x for x in command_line if x.startswith('-D')]
90 include_dirs = [x for x in command_line if x.startswith('-I')]
91 dash_f = [x for x in command_line if x.startswith('-f')]
92 warnings = [x for x in command_line if x.startswith('-W')]
93 cc_file = [x for x in command_line if x.endswith('.cc') or 86 cc_file = [x for x in command_line if x.endswith('.cc') or
94 x.endswith('.c') or 87 x.endswith('.c') or
95 x.endswith('.cpp')] 88 x.endswith('.cpp')]
96 if len(cc_file) != 1: 89 if len(cc_file) != 1:
97 print 'Skipping %s' % command_line 90 print 'Skipping %s' % command_line
98 continue 91 continue
99 assert len(cc_file) == 1 92 assert len(cc_file) == 1
93
94 if is_win:
95 rsp_file = [x for x in command_line if x.endswith('.rsp')]
96 assert len(rsp_file) <= 1
97 if rsp_file:
98 rsp_file = os.path.join(build_dir, rsp_file[0][1:])
99 with open(rsp_file, "r") as open_rsp_file:
100 command_line = shlex.split(open_rsp_file, posix=False)
101
102 defines = [x for x in command_line if x.startswith('-D')]
103 include_dirs = [x for x in command_line if x.startswith('-I')]
104 dash_f = [x for x in command_line if x.startswith('-f')]
105 warnings = \
106 [x for x in command_line if x.startswith('/wd' if is_win else '-W')]
100 others = [x for x in command_line if x not in defines and \ 107 others = [x for x in command_line if x not in defines and \
101 x not in include_dirs and \ 108 x not in include_dirs and \
102 x not in dash_f and \ 109 x not in dash_f and \
103 x not in warnings and \ 110 x not in warnings and \
104 x not in cc_file] 111 x not in cc_file]
105 112
113 for index, value in enumerate(include_dirs):
114 if value == '-Igen':
115 continue
116 path = value[2:]
117 if not os.path.isabs(path):
118 path = os.path.join(build_dir, path)
119 include_dirs[index] = '-I' + os.path.normpath(path)
120
121 # GYP supports paths above the source root like <(DEPTH)/../foo while such
122 # paths are unsupported by gn. But gn allows to use system-absolute paths
123 # instead (paths that start with single '/'). Normalize all paths.
124 cc_file = [os.path.normpath(os.path.join(build_dir, cc_file[0]))]
125
106 # Filter for libFindBadConstructs.so having a relative path in one and 126 # Filter for libFindBadConstructs.so having a relative path in one and
107 # absolute path in the other. 127 # absolute path in the other.
108 others_filtered = [] 128 others_filtered = []
109 for x in others: 129 for x in others:
110 if x.startswith('-Xclang ') and x.endswith('libFindBadConstructs.so'): 130 if x.startswith('-Xclang ') and x.endswith('libFindBadConstructs.so'):
111 others_filtered.append( 131 others_filtered.append(
112 '-Xclang ' + 132 '-Xclang ' +
113 os.path.join(os.getcwd(), 133 os.path.join(os.getcwd(),
114 os.path.normpath( 134 os.path.normpath(
115 os.path.join('out/gn_flags', x.split(' ', 1)[1])))) 135 os.path.join('out/gn_flags', x.split(' ', 1)[1]))))
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 190
171 def main(): 191 def main():
172 if len(sys.argv) != 2 and len(sys.argv) != 3: 192 if len(sys.argv) != 2 and len(sys.argv) != 3:
173 print 'usage: %s gyp_target gn_target' % __file__ 193 print 'usage: %s gyp_target gn_target' % __file__
174 print ' or: %s target' % __file__ 194 print ' or: %s target' % __file__
175 return 1 195 return 1
176 196
177 if len(sys.argv) == 2: 197 if len(sys.argv) == 2:
178 sys.argv.append(sys.argv[1]) 198 sys.argv.append(sys.argv[1])
179 199
180 print >>sys.stderr, 'Regenerating...' 200 gn_out_dir = 'out/gn_flags'
201 print >> sys.stderr, 'Regenerating in %s...' % gn_out_dir
181 # Currently only Release, non-component. 202 # Currently only Release, non-component.
182 Run('gn gen out/gn_flags --args="is_debug=false is_component_build=false"') 203 Run('gn gen %s --args="is_debug=false is_component_build=false"' % gn_out_dir)
204 gn = Run('ninja -C %s -t commands %s' % (gn_out_dir, sys.argv[2]))
205 if sys.platform == 'win32':
206 # On Windows flags are stored in .rsp files which are created during build.
207 print >> sys.stderr, 'Building in %s...' % gn_out_dir
208 Run('ninja -C %s -d keeprsp %s' % (gn_out_dir, sys.argv[2]))
209
183 os.environ.pop('GYP_DEFINES', None) 210 os.environ.pop('GYP_DEFINES', None)
211 # Remove environment variables required by gn but conflicting with GYP.
212 # Relevant if Windows toolchain isn't provided by depot_tools.
213 os.environ.pop('GYP_MSVS_OVERRIDE_PATH', None)
214 os.environ.pop('WINDOWSSDKDIR', None)
215
216 gyp_out_dir = 'out_gyp_flags/Release'
217 print >> sys.stderr, 'Regenerating in %s...' % gyp_out_dir
184 Run('python build/gyp_chromium -Goutput_dir=out_gyp_flags -Gconfig=Release') 218 Run('python build/gyp_chromium -Goutput_dir=out_gyp_flags -Gconfig=Release')
185 gn = Run('ninja -C out/gn_flags -t commands %s' % sys.argv[2]) 219 gyp = Run('ninja -C %s -t commands %s' % (gyp_out_dir, sys.argv[1]))
186 gyp = Run('ninja -C out_gyp_flags/Release -t commands %s' % sys.argv[1]) 220 if sys.platform == 'win32':
187 all_gyp_flags = GetFlags(gyp.splitlines()) 221 # On Windows flags are stored in .rsp files which are created during build.
188 all_gn_flags = GetFlags(gn.splitlines()) 222 print >> sys.stderr, 'Building in %s...' % gyp_out_dir
223 Run('ninja -C %s -d keeprsp %s' % (gyp_out_dir, sys.argv[2]))
224
225 all_gyp_flags = GetFlags(gyp.splitlines(),
226 os.path.join(os.getcwd(), gyp_out_dir))
227 all_gn_flags = GetFlags(gn.splitlines(),
228 os.path.join(os.getcwd(), gn_out_dir))
189 gyp_files = set(all_gyp_flags.keys()) 229 gyp_files = set(all_gyp_flags.keys())
190 gn_files = set(all_gn_flags.keys()) 230 gn_files = set(all_gn_flags.keys())
191 different_source_list = gyp_files != gn_files 231 different_source_list = gyp_files != gn_files
192 if different_source_list: 232 if different_source_list:
193 print 'Different set of sources files:' 233 print 'Different set of sources files:'
194 print ' In gyp, not in GN:\n %s' % '\n '.join( 234 print ' In gyp, not in GN:\n %s' % '\n '.join(
195 sorted(gyp_files - gn_files)) 235 sorted(gyp_files - gn_files))
196 print ' In GN, not in gyp:\n %s' % '\n '.join( 236 print ' In GN, not in gyp:\n %s' % '\n '.join(
197 sorted(gn_files - gyp_files)) 237 sorted(gn_files - gyp_files))
198 print '\nNote that flags will only be compared for files in both sets.\n' 238 print '\nNote that flags will only be compared for files in both sets.\n'
199 file_list = gyp_files & gn_files 239 file_list = gyp_files & gn_files
200 files_with_given_differences = {} 240 files_with_given_differences = {}
201 for filename in sorted(file_list): 241 for filename in sorted(file_list):
202 gyp_flags = all_gyp_flags[filename] 242 gyp_flags = all_gyp_flags[filename]
203 gn_flags = all_gn_flags[filename] 243 gn_flags = all_gn_flags[filename]
204 differences = CompareLists(gyp_flags, gn_flags, 'dash_f') 244 differences = CompareLists(gyp_flags, gn_flags, 'dash_f')
205 differences += CompareLists(gyp_flags, gn_flags, 'defines') 245 differences += CompareLists(gyp_flags, gn_flags, 'defines')
206 differences += CompareLists(gyp_flags, gn_flags, 'include_dirs') 246 differences += CompareLists(gyp_flags, gn_flags, 'include_dirs')
207 differences += CompareLists(gyp_flags, gn_flags, 'warnings', dont_care_gn=[ 247 differences += CompareLists(gyp_flags, gn_flags, 'warnings',
208 # More conservative warnings in GN we consider to be OK. 248 # More conservative warnings in GN we consider to be OK.
209 '-Wendif-labels', 249 dont_care_gyp=[
210 '-Wextra', 250 '/wd4091', # 'keyword' : ignored on left of 'type' when no variable
211 '-Wsign-compare', 251 # is declared.
212 ]) 252 '/wd4456', # Declaration hides previous local declaration.
253 '/wd4457', # Declaration hides function parameter.
254 '/wd4458', # Declaration hides class member.
255 '/wd4459', # Declaration hides global declaration.
256 '/wd4702', # Unreachable code.
257 '/wd4800', # Forcing value to bool 'true' or 'false'.
258 '/wd4838', # Conversion from 'type' to 'type' requires a narrowing
259 # conversion.
260 ] if sys.platform == 'win32' else None,
261 dont_care_gn=[
262 '-Wendif-labels',
263 '-Wextra',
264 '-Wsign-compare',
265 ] if not sys.platform == 'win32' else None)
213 differences += CompareLists(gyp_flags, gn_flags, 'other') 266 differences += CompareLists(gyp_flags, gn_flags, 'other')
214 if differences: 267 if differences:
215 files_with_given_differences.setdefault(differences, []).append(filename) 268 files_with_given_differences.setdefault(differences, []).append(filename)
216 269
217 for diff, files in files_with_given_differences.iteritems(): 270 for diff, files in files_with_given_differences.iteritems():
218 print '\n'.join(sorted(files)) 271 print '\n'.join(sorted(files))
219 print diff 272 print diff
220 273
221 print 'Total differences:', g_total_differences 274 print 'Total differences:', g_total_differences
222 # TODO(scottmg): Return failure on difference once we're closer to identical. 275 # TODO(scottmg): Return failure on difference once we're closer to identical.
223 return 0 276 return 0
224 277
225 278
226 if __name__ == '__main__': 279 if __name__ == '__main__':
227 sys.exit(main()) 280 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698