summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-25 17:22:56 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-25 17:22:56 +0000
commit792b343b9752c379c27e92f94190746c20e82c69 (patch)
tree040d3d4eed66d3bcc6fae7beee165f52c23b103d
parentd5d080547d562a5f37e854dac468ff71ae46c4f3 (diff)
downloadchromium_src-792b343b9752c379c27e92f94190746c20e82c69.zip
chromium_src-792b343b9752c379c27e92f94190746c20e82c69.tar.gz
chromium_src-792b343b9752c379c27e92f94190746c20e82c69.tar.bz2
grit_info: Explicitly make __file__ relative to the current directory.
__file__ is relative if grit_info is called like `python ../tools/grit/grit_info.py`, but not if it's invoked from python code like `import grit_info; grit_info.DoMain()`. And that confuses the xcode project generator, which will complain about hash collisions if these paths are serialized in absolute form. BUG=82230 TEST=none Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=86551 Review URL: http://codereview.chromium.org/7066030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86647 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-xtools/grit/grit_info.py85
1 files changed, 84 insertions, 1 deletions
diff --git a/tools/grit/grit_info.py b/tools/grit/grit_info.py
index c0e0ed8..81176e1 100755
--- a/tools/grit/grit_info.py
+++ b/tools/grit/grit_info.py
@@ -14,6 +14,89 @@ import sys
from grit import grd_reader
from grit import util
+##############################################################################
+# os.path.relpath is python 2.6 only. Some bots still run 2.5 only, so I took
+# the relpath implementation from the python source.
+# TODO(thakis): Once we're on 2.6 everywhere, remove this and use
+# os.path.relpath directly.
+
+# http://docs.python.org/license.html
+# PSF LICENSE AGREEMENT FOR PYTHON 2.7.1
+#
+# 1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"),
+# and the Individual or Organization ("Licensee") accessing and otherwise using
+# Python 2.7.1 software in source or binary form and its associated
+# documentation.
+#
+# 2. Subject to the terms and conditions of this License Agreement, PSF hereby
+# grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
+# analyze, test, perform and/or display publicly, prepare derivative works,
+# distribute, and otherwise use Python 2.7.1 alone or in any derivative version,
+# provided, however, that PSF's License Agreement and PSF's notice of copyright,
+# i.e., "Copyright c 2001-2010 Python Software Foundation; All Rights Reserved"
+# are retained in Python 2.7.1 alone or in any derivative version prepared by
+# Licensee.
+#
+# 3. In the event Licensee prepares a derivative work that is based on or
+# incorporates Python 2.7.1 or any part thereof, and wants to make the
+# derivative work available to others as provided herein, then Licensee hereby
+# agrees to include in any such work a brief summary of the changes made to
+# Python 2.7.1.
+#
+# 4. PSF is making Python 2.7.1 available to Licensee on an "AS IS" basis. PSF
+# MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
+# BUT NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY
+# OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
+# PYTHON 2.7.1 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
+#
+# 5.1 PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 2.7.1 FOR
+# ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF
+# MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 2.7.1, OR ANY DERIVATIVE
+# THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
+#
+# 6. This License Agreement will automatically terminate upon a material breach
+# of its terms and conditions.
+#
+# 7. Nothing in this License Agreement shall be deemed to create any
+# relationship of agency, partnership, or joint venture between PSF and
+# Licensee. This License Agreement does not grant permission to use PSF
+# trademarks or trade name in a trademark sense to endorse or promote products
+# or services of Licensee, or any third party.
+#
+# 8. By copying, installing or otherwise using Python 2.7.1, Licensee agrees to
+# be bound by the terms and conditions of this License Agreement.
+
+# http://svn.python.org/view/python/trunk/Lib/genericpath.py?view=markup
+def commonprefix(m):
+ "Given a list of pathnames, returns the longest common leading component"
+ if not m: return ''
+ s1 = min(m)
+ s2 = max(m)
+ for i, c in enumerate(s1):
+ if c != s2[i]:
+ return s1[:i]
+ return s1
+
+
+# http://svn.python.org/view/python/trunk/Lib/posixpath.py?view=markup
+def relpath(path, start=os.path.curdir):
+ """Return a relative version of a path"""
+
+ if not path:
+ raise ValueError("no path specified")
+
+ start_list = os.path.abspath(start).split(os.path.sep)
+ path_list = os.path.abspath(path).split(os.path.sep)
+
+ # Work out how much of the filepath is shared by start and path.
+ i = len(commonprefix([start_list, path_list]))
+
+ rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:]
+ if not rel_list:
+ return curdir
+ return os.path.join(*rel_list)
+##############################################################################
+
def Outputs(filename, defines):
grd = grd_reader.Parse(
@@ -66,7 +149,7 @@ def Inputs(filename, defines):
# Add in the grit source files. If one of these change, we want to re-run
# grit.
- grit_root_dir = os.path.dirname(__file__)
+ grit_root_dir = relpath(os.path.dirname(__file__), os.getcwd())
for root, dirs, filenames in os.walk(grit_root_dir):
grit_src = [os.path.join(root, f) for f in filenames
if f.endswith('.py') or f == 'resource_ids']