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

Side by Side Diff: pylib/gyp/generator/analyzer.py

Issue 429243003: Updates analyzer to output to a file (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/analyzer/gyptest-analyzer.new.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2014 Google Inc. All rights reserved. 1 # Copyright (c) 2014 Google Inc. 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 """ 5 """
6 This script is intended for use as a GYP_GENERATOR. It takes as input (by way of 6 This script is intended for use as a GYP_GENERATOR. It takes as input (by way of
7 the generator flag config_path) the path of a json file that dictates the files 7 the generator flag config_path) the path of a json file that dictates the files
8 and targets to search for. The following keys are supported: 8 and targets to search for. The following keys are supported:
9 files: list of paths (relative) of the files to search for. 9 files: list of paths (relative) of the files to search for.
10 targets: list of targets to search for. The target names are unqualified. 10 targets: list of targets to search for. The target names are unqualified.
11 11
12 The following (as JSON) is output: 12 The following is output:
13 error: only supplied if there is an error. 13 error: only supplied if there is an error.
14 warning: only supplied if there is a warning.
14 targets: the set of targets passed in via targets that either directly or 15 targets: the set of targets passed in via targets that either directly or
15 indirectly depend upon the set of paths supplied in files. 16 indirectly depend upon the set of paths supplied in files.
16 status: indicates if any of the supplied files matched at least one target. 17 status: indicates if any of the supplied files matched at least one target.
18
19 If the generator flag analyzer_output_path is specified, output is written
20 there. Otherwise output is written to stdout.
17 """ 21 """
18 22
19 import gyp.common 23 import gyp.common
20 import gyp.ninja_syntax as ninja_syntax 24 import gyp.ninja_syntax as ninja_syntax
21 import json 25 import json
22 import os 26 import os
23 import posixpath 27 import posixpath
24 import sys 28 import sys
25 29
26 debug = False 30 debug = False
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 directly on indirectly) on the matched files. 290 directly on indirectly) on the matched files.
287 all_targets: mapping from target name to Target. 291 all_targets: mapping from target name to Target.
288 possible_targets: targets to search from.""" 292 possible_targets: targets to search from."""
289 found = [] 293 found = []
290 for target in possible_targets: 294 for target in possible_targets:
291 if _DoesTargetDependOn(all_targets[target], all_targets): 295 if _DoesTargetDependOn(all_targets[target], all_targets):
292 # possible_targets was initially unqualified, keep it unqualified. 296 # possible_targets was initially unqualified, keep it unqualified.
293 found.append(gyp.common.ParseQualifiedTarget(target)[1]) 297 found.append(gyp.common.ParseQualifiedTarget(target)[1])
294 return found 298 return found
295 299
300 def _WriteOutput(params, **values):
301 """Writes the output, either to stdout or a file is specified."""
302 output_path = params.get('generator_flags', {}).get(
303 'analyzer_output_path', None)
304 if not output_path:
305 print json.dumps(values)
306 return
307 try:
308 f = open(output_path, 'w')
309 f.write(json.dumps(values) + '\n')
310 f.close()
311 except IOError as e:
312 print 'Error writing to output file', output_path, str(e)
313
296 def CalculateVariables(default_variables, params): 314 def CalculateVariables(default_variables, params):
297 """Calculate additional variables for use in the build (called by gyp).""" 315 """Calculate additional variables for use in the build (called by gyp)."""
298 flavor = gyp.common.GetFlavor(params) 316 flavor = gyp.common.GetFlavor(params)
299 if flavor == 'mac': 317 if flavor == 'mac':
300 default_variables.setdefault('OS', 'mac') 318 default_variables.setdefault('OS', 'mac')
301 elif flavor == 'win': 319 elif flavor == 'win':
302 default_variables.setdefault('OS', 'win') 320 default_variables.setdefault('OS', 'win')
303 # Copy additional generator configuration data from VS, which is shared 321 # Copy additional generator configuration data from VS, which is shared
304 # by the Windows Ninja generator. 322 # by the Windows Ninja generator.
305 import gyp.generator.msvs as msvs_generator 323 import gyp.generator.msvs as msvs_generator
(...skipping 29 matching lines...) Expand all
335 353
336 all_targets, matched = __GenerateTargets(target_list, target_dicts, 354 all_targets, matched = __GenerateTargets(target_list, target_dicts,
337 toplevel_dir, 355 toplevel_dir,
338 frozenset(config.files)) 356 frozenset(config.files))
339 357
340 # Set of targets that refer to one of the files. 358 # Set of targets that refer to one of the files.
341 if config.look_for_dependency_only: 359 if config.look_for_dependency_only:
342 print found_dependency_string if matched else no_dependency_string 360 print found_dependency_string if matched else no_dependency_string
343 return 361 return
344 362
363 warning = None
345 if matched: 364 if matched:
346 unqualified_mapping = _GetUnqualifiedToQualifiedMapping( 365 unqualified_mapping = _GetUnqualifiedToQualifiedMapping(
347 all_targets, config.targets) 366 all_targets, config.targets)
348 if len(unqualified_mapping) != len(config.targets): 367 if len(unqualified_mapping) != len(config.targets):
349 not_found = [] 368 not_found = []
350 for target in config.targets: 369 for target in config.targets:
351 if not target in unqualified_mapping: 370 if not target in unqualified_mapping:
352 not_found.append(target) 371 not_found.append(target)
353 raise Exception('Unable to find all targets: ' + str(not_found)) 372 warning = 'Unable to find all targets: ' + str(not_found)
354 qualified_targets = [unqualified_mapping[x] for x in config.targets] 373 qualified_targets = []
374 for target in config.targets:
375 if target in unqualified_mapping:
376 qualified_targets.append(unqualified_mapping[target])
355 output_targets = _GetTargetsDependingOn(all_targets, qualified_targets) 377 output_targets = _GetTargetsDependingOn(all_targets, qualified_targets)
356 else: 378 else:
357 output_targets = [] 379 output_targets = []
358 380
359 print json.dumps( 381 result_dict = { 'targets': output_targets,
360 {'targets': output_targets, 382 'status': found_dependency_string if matched else
361 'status': found_dependency_string if matched else no_dependency_string }) 383 no_dependency_string }
384 if warning:
385 result_dict['warning'] = warning
386 _WriteOutput(params, **result_dict)
362 387
363 except Exception as e: 388 except Exception as e:
364 print json.dumps({'error': str(e)}) 389 _WriteOutput(params, error=str(e))
OLDNEW
« no previous file with comments | « no previous file | test/analyzer/gyptest-analyzer.new.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698