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

Unified Diff: pylib/gyp/generator/analyzer.py

Issue 445113002: Style changes for analyzer (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pylib/gyp/generator/analyzer.py
===================================================================
--- pylib/gyp/generator/analyzer.py (revision 1962)
+++ pylib/gyp/generator/analyzer.py (working copy)
@@ -64,22 +64,17 @@
'CONFIGURATION_NAME']:
generator_default_variables[unused] = ''
+
def _ToGypPath(path):
"""Converts a path to the format used by gyp."""
if os.sep == '\\' and os.altsep == '/':
return path.replace('\\', '/')
return path
-def __ExtractBasePath(target):
- """Extracts the path components of the specified gyp target path."""
- last_index = target.rfind('/')
- if last_index == -1:
- return ''
- return target[0:(last_index + 1)]
-def __ResolveParent(path, base_path_components):
+def _ResolveParent(path, base_path_components):
"""Resolves |path|, which starts with at least one '../'. Returns an empty
- string if the path shouldn't be considered. See __AddSources() for a
+ string if the path shouldn't be considered. See _AddSources() for a
description of |base_path_components|."""
depth = 0
while path.startswith('../'):
@@ -94,7 +89,8 @@
return '/'.join(base_path_components[0:len(base_path_components) - depth]) + \
'/' + path
-def __AddSources(sources, base_path, base_path_components, result):
+
+def _AddSources(sources, base_path, base_path_components, result):
"""Extracts valid sources from |sources| and adds them to |result|. Each
source file is relative to |base_path|, but may contain '..'. To make
resolving '..' easier |base_path_components| contains each of the
@@ -109,7 +105,7 @@
org_source = source
source = source[0] + source[1:].replace('//', '/')
if source.startswith('../'):
- source = __ResolveParent(source, base_path_components)
+ source = _ResolveParent(source, base_path_components)
if len(source):
result.append(source)
continue
@@ -117,12 +113,14 @@
if debug:
print 'AddSource', org_source, result[len(result) - 1]
-def __ExtractSourcesFromAction(action, base_path, base_path_components,
- results):
+
+def _ExtractSourcesFromAction(action, base_path, base_path_components,
+ results):
if 'inputs' in action:
- __AddSources(action['inputs'], base_path, base_path_components, results)
+ _AddSources(action['inputs'], base_path, base_path_components, results)
-def __ExtractSources(target, target_dict, toplevel_dir):
+
+def _ExtractSources(target, target_dict, toplevel_dir):
# |target| is either absolute or relative and in the format of the OS. Gyp
# source paths are always posix. Convert |target| to a posix path relative to
# |toplevel_dir_|. This is done to make it easy to build source paths.
@@ -134,7 +132,7 @@
base_path = posixpath.dirname(base_path)
base_path_components = base_path.split('/')
- # Add a trailing '/' so that __AddSources() can easily build paths.
+ # Add a trailing '/' so that _AddSources() can easily build paths.
if len(base_path):
base_path += '/'
@@ -143,20 +141,21 @@
results = []
if 'sources' in target_dict:
- __AddSources(target_dict['sources'], base_path, base_path_components,
- results)
+ _AddSources(target_dict['sources'], base_path, base_path_components,
+ results)
# Include the inputs from any actions. Any changes to these effect the
# resulting output.
if 'actions' in target_dict:
for action in target_dict['actions']:
- __ExtractSourcesFromAction(action, base_path, base_path_components,
- results)
+ _ExtractSourcesFromAction(action, base_path, base_path_components,
+ results)
if 'rules' in target_dict:
for rule in target_dict['rules']:
- __ExtractSourcesFromAction(rule, base_path, base_path_components, results)
+ _ExtractSourcesFromAction(rule, base_path, base_path_components, results)
return results
+
class Target(object):
"""Holds information about a particular target:
deps: set of the names of direct dependent targets.
@@ -165,6 +164,7 @@
self.deps = set()
self.match_status = MATCH_STATUS_TBD
+
class Config(object):
"""Details what we're looking for
look_for_dependency_only: if true only search for a target listing any of
@@ -219,6 +219,7 @@
except IOError:
raise Exception('Unable to open file', file_path)
+
def _WasBuildFileModified(build_file, data, files):
"""Returns true if the build file |build_file| is either in |files| or
one of the files included by |build_file| is in |files|."""
@@ -242,7 +243,8 @@
return True
return False
-def __GenerateTargets(data, target_list, target_dicts, toplevel_dir, files):
+
+def _GenerateTargets(data, target_list, target_dicts, toplevel_dir, files):
"""Generates a dictionary with the key the name of a target and the value a
Target. |toplevel_dir| is the root of the source tree. If the sources of
a target match that of |files|, then |target.matched| is set to True.
@@ -278,8 +280,8 @@
target.match_status = MATCH_STATUS_MATCHES
matched = True
else:
- sources = __ExtractSources(target_name, target_dicts[target_name],
- toplevel_dir)
+ sources = _ExtractSources(target_name, target_dicts[target_name],
+ toplevel_dir)
for source in sources:
if source in files:
target.match_status = MATCH_STATUS_MATCHES
@@ -292,6 +294,7 @@
return targets, matched
+
def _GetUnqualifiedToQualifiedMapping(all_targets, to_find):
"""Returns a mapping (dictionary) from unqualified name to qualified name for
all the targets in |to_find|."""
@@ -308,6 +311,7 @@
return result
return result
+
def _DoesTargetDependOn(target, all_targets):
"""Returns true if |target| or any of its dependencies matches the supplied
set of paths. This updates |matches| of the Targets as it recurses.
@@ -327,6 +331,7 @@
dep_target.match_status = MATCH_STATUS_DOESNT_MATCH
return False
+
def _GetTargetsDependingOn(all_targets, possible_targets):
"""Returns the list of targets in |possible_targets| that depend (either
directly on indirectly) on the matched files.
@@ -339,6 +344,7 @@
found.append(gyp.common.ParseQualifiedTarget(target)[1])
return found
+
def _WriteOutput(params, **values):
"""Writes the output, either to stdout or a file is specified."""
output_path = params.get('generator_flags', {}).get(
@@ -353,6 +359,7 @@
except IOError as e:
print 'Error writing to output file', output_path, str(e)
+
def CalculateVariables(default_variables, params):
"""Calculate additional variables for use in the build (called by gyp)."""
flavor = gyp.common.GetFlavor(params)
@@ -375,6 +382,7 @@
operating_system = 'linux' # Keep this legacy behavior for now.
default_variables.setdefault('OS', operating_system)
+
def GenerateOutput(target_list, target_dicts, data, params):
"""Called by gyp as the final stage. Outputs results."""
config = Config()
@@ -406,9 +414,9 @@
break
if not matched:
- all_targets, matched = __GenerateTargets(data, target_list, target_dicts,
- toplevel_dir,
- frozenset(config.files))
+ all_targets, matched = _GenerateTargets(data, target_list, target_dicts,
+ toplevel_dir,
+ frozenset(config.files))
# Set of targets that refer to one of the files.
if config.look_for_dependency_only:
« 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