summaryrefslogtreecommitdiff
path: root/tools/gyp/tools
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2011-12-03 21:26:50 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2011-12-03 21:28:17 +0100
commite90623edc2befb06602ff8c3e01809ba0a21d593 (patch)
tree142a84aa010f924262925eb2b959d292d6624576 /tools/gyp/tools
parent49ba55b10045969d9dba89ee11a53ca2d35d8f7f (diff)
downloadandroid-node-v8-e90623edc2befb06602ff8c3e01809ba0a21d593.tar.gz
android-node-v8-e90623edc2befb06602ff8c3e01809ba0a21d593.tar.bz2
android-node-v8-e90623edc2befb06602ff8c3e01809ba0a21d593.zip
gyp: upgrade to r1103
Diffstat (limited to 'tools/gyp/tools')
-rwxr-xr-xtools/gyp/tools/graphviz.py11
-rwxr-xr-x[-rw-r--r--]tools/gyp/tools/pretty_gyp.py296
-rwxr-xr-xtools/gyp/tools/pretty_sln.py9
-rwxr-xr-xtools/gyp/tools/pretty_vcproj.py28
4 files changed, 188 insertions, 156 deletions
diff --git a/tools/gyp/tools/graphviz.py b/tools/gyp/tools/graphviz.py
index 7f7166802b..326ae221cf 100755
--- a/tools/gyp/tools/graphviz.py
+++ b/tools/gyp/tools/graphviz.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -83,13 +83,18 @@ def WriteGraph(edges):
print '}'
-if __name__ == '__main__':
+def main():
if len(sys.argv) < 2:
print >>sys.stderr, __doc__
print >>sys.stderr
print >>sys.stderr, 'usage: %s target1 target2...' % (sys.argv[0])
- sys.exit(1)
+ return 1
edges = LoadEdges('dump.json', sys.argv[1:])
WriteGraph(edges)
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/tools/gyp/tools/pretty_gyp.py b/tools/gyp/tools/pretty_gyp.py
index 04c79012ee..3749792aac 100644..100755
--- a/tools/gyp/tools/pretty_gyp.py
+++ b/tools/gyp/tools/pretty_gyp.py
@@ -1,142 +1,154 @@
-#!/usr/bin/env python
-# Copyright (c) 2009 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-# This file pretty-prints the contents of a GYP file.
-
-import sys
-import re
-
-input = []
-if len(sys.argv) > 1:
- input_file = open(sys.argv[1])
- input = input_file.read().splitlines()
- input_file.close()
-else:
- input = sys.stdin.read().splitlines()
-
-# This is used to remove comments when we're counting braces.
-comment_re = re.compile(r'\s*#.*')
-
-# This is used to remove quoted strings when we're counting braces.
-# It takes into account quoted quotes, and makes sure that the quotes
-# match.
-# NOTE: It does not handle quotes that span more than one line, or
-# cases where an escaped quote is preceeded by an escaped backslash.
-quote_re_str = r'(?P<q>[\'"])(.*?)(?<![^\\][\\])(?P=q)'
-quote_re = re.compile(quote_re_str)
-
-def comment_replace(matchobj):
- return matchobj.group(1) + matchobj.group(2) + '#' * len(matchobj.group(3))
-
-def mask_comments(input):
- # This is used to mask the quoted strings so we skip braces inside
- # quoted strings.
- search_re = re.compile(r'(.*?)(#)(.*)')
- return [search_re.sub(comment_replace, line) for line in input]
-
-def quote_replace(matchobj):
- return "%s%s%s%s" % (matchobj.group(1),
- matchobj.group(2),
- 'x'*len(matchobj.group(3)),
- matchobj.group(2))
-
-def mask_quotes(input):
- # This is used to mask the quoted strings so we skip braces inside
- # quoted strings.
- search_re = re.compile(r'(.*?)' + quote_re_str)
- return [search_re.sub(quote_replace, line) for line in input]
-
-def do_split(input, masked_input, search_re):
- output = []
- mask_output = []
- for (line, masked_line) in zip(input, masked_input):
- m = search_re.match(masked_line)
- while m:
- split = len(m.group(1))
- line = line[:split] + r'\n' + line[split:]
- masked_line = masked_line[:split] + r'\n' + masked_line[split:]
- m = search_re.match(masked_line)
- output.extend(line.split(r'\n'))
- mask_output.extend(masked_line.split(r'\n'))
- return (output, mask_output)
-
-# This masks out the quotes and comments, and then splits appropriate
-# lines (lines that matche the double_*_brace re's above) before
-# indenting them below.
-def split_double_braces(input):
- # These are used to split lines which have multiple braces on them, so
- # that the indentation looks prettier when all laid out (e.g. closing
- # braces make a nice diagonal line).
- double_open_brace_re = re.compile(r'(.*?[\[\{\(,])(\s*)([\[\{\(])')
- double_close_brace_re = re.compile(r'(.*?[\]\}\)],?)(\s*)([\]\}\)])')
-
- masked_input = mask_quotes(input)
- masked_input = mask_comments(masked_input)
-
- (output, mask_output) = do_split(input, masked_input, double_open_brace_re)
- (output, mask_output) = do_split(output, mask_output, double_close_brace_re)
-
- return output
-
-# This keeps track of the number of braces on a given line and returns
-# the result. It starts at zero and subtracts for closed braces, and
-# adds for open braces.
-def count_braces(line):
- open_braces = ['[', '(', '{']
- close_braces = [']', ')', '}']
- closing_prefix_re = re.compile(r'(.*?[^\s\]\}\)]+.*?)([\]\}\)],?)\s*$')
- cnt = 0
- stripline = comment_re.sub(r'', line)
- stripline = quote_re.sub(r"''", stripline)
- for char in stripline:
- for brace in open_braces:
- if char == brace:
- cnt += 1
- for brace in close_braces:
- if char == brace:
- cnt -= 1
-
- after = False
- if cnt > 0:
- after = True
-
- # This catches the special case of a closing brace having something
- # other than just whitespace ahead of it -- we don't want to
- # unindent that until after this line is printed so it stays with
- # the previous indentation level.
- if cnt < 0 and closing_prefix_re.match(stripline):
- after = True
- return (cnt, after)
-
-# This does the main work of indenting the input based on the brace counts.
-def prettyprint_input(lines):
- indent = 0
- basic_offset = 2
- last_line = ""
- for line in lines:
- if comment_re.match(line):
- print line
- else:
- line = line.strip('\r\n\t ') # Otherwise doesn't strip \r on Unix.
- if len(line) > 0:
- (brace_diff, after) = count_braces(line)
- if brace_diff != 0:
- if after:
- print " " * (basic_offset * indent) + line
- indent += brace_diff
- else:
- indent += brace_diff
- print " " * (basic_offset * indent) + line
- else:
- print " " * (basic_offset * indent) + line
- else:
- print ""
- last_line = line
-
-# Split up the double braces.
-lines = split_double_braces(input)
-
-# Indent and print the output.
-prettyprint_input(lines)
+#!/usr/bin/env python
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Pretty-prints the contents of a GYP file."""
+
+import sys
+import re
+
+
+# Regex to remove comments when we're counting braces.
+COMMENT_RE = re.compile(r'\s*#.*')
+
+# Regex to remove quoted strings when we're counting braces.
+# It takes into account quoted quotes, and makes sure that the quotes match.
+# NOTE: It does not handle quotes that span more than one line, or
+# cases where an escaped quote is preceeded by an escaped backslash.
+quote_re_str = r'(?P<q>[\'"])(.*?)(?<![^\\][\\])(?P=q)'
+QUOTE_RE = re.compile(QUOTE_RE_STR)
+
+
+def comment_replace(matchobj):
+ return matchobj.group(1) + matchobj.group(2) + '#' * len(matchobj.group(3))
+
+
+def mask_comments(input):
+ """Mask the quoted strings so we skip braces inside quoted strings."""
+ search_re = re.compile(r'(.*?)(#)(.*)')
+ return [search_re.sub(comment_replace, line) for line in input]
+
+
+def quote_replace(matchobj):
+ return "%s%s%s%s" % (matchobj.group(1),
+ matchobj.group(2),
+ 'x'*len(matchobj.group(3)),
+ matchobj.group(2))
+
+
+def mask_quotes(input):
+ """Mask the quoted strings so we skip braces inside quoted strings."""
+ search_re = re.compile(r'(.*?)' + QUOTE_RE_STR)
+ return [search_re.sub(quote_replace, line) for line in input]
+
+
+def do_split(input, masked_input, search_re):
+ output = []
+ mask_output = []
+ for (line, masked_line) in zip(input, masked_input):
+ m = search_re.match(masked_line)
+ while m:
+ split = len(m.group(1))
+ line = line[:split] + r'\n' + line[split:]
+ masked_line = masked_line[:split] + r'\n' + masked_line[split:]
+ m = search_re.match(masked_line)
+ output.extend(line.split(r'\n'))
+ mask_output.extend(masked_line.split(r'\n'))
+ return (output, mask_output)
+
+
+def split_double_braces(input):
+ """Masks out the quotes and comments, and then splits appropriate
+ lines (lines that matche the double_*_brace re's above) before
+ indenting them below.
+
+ These are used to split lines which have multiple braces on them, so
+ that the indentation looks prettier when all laid out (e.g. closing
+ braces make a nice diagonal line).
+ """
+ double_open_brace_re = re.compile(r'(.*?[\[\{\(,])(\s*)([\[\{\(])')
+ double_close_brace_re = re.compile(r'(.*?[\]\}\)],?)(\s*)([\]\}\)])')
+
+ masked_input = mask_quotes(input)
+ masked_input = mask_comments(masked_input)
+
+ (output, mask_output) = do_split(input, masked_input, double_open_brace_re)
+ (output, mask_output) = do_split(output, mask_output, double_close_brace_re)
+
+ return output
+
+
+def count_braces(line):
+ """keeps track of the number of braces on a given line and returns the result.
+
+ It starts at zero and subtracts for closed braces, and adds for open braces.
+ """
+ open_braces = ['[', '(', '{']
+ close_braces = [']', ')', '}']
+ closing_prefix_re = re.compile(r'(.*?[^\s\]\}\)]+.*?)([\]\}\)],?)\s*$')
+ cnt = 0
+ stripline = COMMENT_RE.sub(r'', line)
+ stripline = QUOTE_RE.sub(r"''", stripline)
+ for char in stripline:
+ for brace in open_braces:
+ if char == brace:
+ cnt += 1
+ for brace in close_braces:
+ if char == brace:
+ cnt -= 1
+
+ after = False
+ if cnt > 0:
+ after = True
+
+ # This catches the special case of a closing brace having something
+ # other than just whitespace ahead of it -- we don't want to
+ # unindent that until after this line is printed so it stays with
+ # the previous indentation level.
+ if cnt < 0 and closing_prefix_re.match(stripline):
+ after = True
+ return (cnt, after)
+
+
+def prettyprint_input(lines):
+ """Does the main work of indenting the input based on the brace counts."""
+ indent = 0
+ basic_offset = 2
+ last_line = ""
+ for line in lines:
+ if COMMENT_RE.match(line):
+ print line
+ else:
+ line = line.strip('\r\n\t ') # Otherwise doesn't strip \r on Unix.
+ if len(line) > 0:
+ (brace_diff, after) = count_braces(line)
+ if brace_diff != 0:
+ if after:
+ print " " * (basic_offset * indent) + line
+ indent += brace_diff
+ else:
+ indent += brace_diff
+ print " " * (basic_offset * indent) + line
+ else:
+ print " " * (basic_offset * indent) + line
+ else:
+ print ""
+ last_line = line
+
+
+def main():
+ if len(sys.argv) > 1:
+ data = open(sys.argv[1]).read().splitlines()
+ else:
+ data = sys.stdin.read().splitlines()
+ # Split up the double braces.
+ lines = split_double_braces(data)
+
+ # Indent and print the output.
+ prettyprint_input(lines)
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/tools/gyp/tools/pretty_sln.py b/tools/gyp/tools/pretty_sln.py
index 0741fff177..7013f2b660 100755
--- a/tools/gyp/tools/pretty_sln.py
+++ b/tools/gyp/tools/pretty_sln.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.5
+#!/usr/bin/env python
# Copyright (c) 2009 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -153,7 +153,7 @@ def main():
# check if we have exactly 1 parameter.
if len(sys.argv) < 2:
print 'Usage: %s "c:\\path\\to\\project.sln"' % sys.argv[0]
- return
+ return 1
(projects, deps) = ParseSolution(sys.argv[1])
PrintDependencies(projects, deps)
@@ -161,7 +161,8 @@ def main():
if '--recursive' in sys.argv:
PrintVCProj(projects)
+ return 0
-if __name__ == '__main__':
- main()
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/tools/gyp/tools/pretty_vcproj.py b/tools/gyp/tools/pretty_vcproj.py
index 292a39f7cf..ba65bf2386 100755
--- a/tools/gyp/tools/pretty_vcproj.py
+++ b/tools/gyp/tools/pretty_vcproj.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.5
+#!/usr/bin/env python
# Copyright (c) 2009 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -23,14 +23,16 @@ from xml.dom.minidom import Node
REPLACEMENTS = dict()
ARGUMENTS = None
-class CmpTuple:
+
+class CmpTuple(object):
"""Compare function between 2 tuple."""
def __call__(self, x, y):
(key1, value1) = x
(key2, value2) = y
return cmp(key1, key2)
-class CmpNode:
+
+class CmpNode(object):
"""Compare function between 2 xml nodes."""
def get_string(self, node):
@@ -57,6 +59,7 @@ class CmpNode:
def __call__(self, x, y):
return cmp(self.get_string(x), self.get_string(y))
+
def PrettyPrintNode(node, indent=0):
if node.nodeType == Node.TEXT_NODE:
if node.data.strip():
@@ -90,6 +93,7 @@ def PrettyPrintNode(node, indent=0):
PrettyPrintNode(sub_node, indent=indent+2)
print '%s</%s>' % (' '*indent, node.nodeName)
+
def FlattenFilter(node):
"""Returns a list of all the node and sub nodes."""
node_list = []
@@ -107,6 +111,7 @@ def FlattenFilter(node):
return node_list
+
def FixFilenames(filenames, current_directory):
new_list = []
for filename in filenames:
@@ -121,8 +126,9 @@ def FixFilenames(filenames, current_directory):
new_list.append(os.path.abspath(filename))
return new_list
+
def AbsoluteNode(node):
- # Make all the properties we know about in this node absolute.
+ """Makes all the properties we know about in this node absolute."""
if node.attributes:
for (name, value) in node.attributes.items():
if name in ['InheritedPropertySheets', 'RelativePath',
@@ -136,8 +142,9 @@ def AbsoluteNode(node):
if not value:
node.removeAttribute(name)
+
def CleanupVcproj(node):
- # For each sub node, we call recursively this function.
+ """For each sub node, we call recursively this function."""
for sub_node in node.childNodes:
AbsoluteNode(sub_node)
CleanupVcproj(sub_node)
@@ -192,6 +199,7 @@ def CleanupVcproj(node):
continue
node.appendChild(new_node)
+
def GetConfiguationNodes(vcproj):
#TODO(nsylvain): Find a better way to navigate the xml.
nodes = []
@@ -203,6 +211,7 @@ def GetConfiguationNodes(vcproj):
return nodes
+
def GetChildrenVsprops(filename):
dom = parse(filename)
if dom.documentElement.attributes:
@@ -231,6 +240,7 @@ def SeekToNode(node1, child2):
# No match. We give up.
return None
+
def MergeAttributes(node1, node2):
# No attributes to merge?
if not node2.attributes:
@@ -255,6 +265,7 @@ def MergeAttributes(node1, node2):
if name == 'InheritedPropertySheets':
node1.removeAttribute(name)
+
def MergeProperties(node1, node2):
MergeAttributes(node1, node2)
for child2 in node2.childNodes:
@@ -264,6 +275,7 @@ def MergeProperties(node1, node2):
else:
node1.appendChild(child2.cloneNode(True))
+
def main(argv):
global REPLACEMENTS
global ARGUMENTS
@@ -274,7 +286,7 @@ def main(argv):
if len(argv) < 2:
print ('Usage: %s "c:\\path\\to\\vcproj.vcproj" [key1=value1] '
'[key2=value2]' % argv[0])
- return
+ return 1
# Parse the keys
for i in range(2, len(argv)):
@@ -311,6 +323,8 @@ def main(argv):
# user.
#print dom.toprettyxml(newl="\n")
PrettyPrintNode(dom.documentElement)
+ return 0
+
if __name__ == '__main__':
- main(sys.argv)
+ sys.exit(main(sys.argv))