aboutsummaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorMaxim Sobolev <sobomax@FreeBSD.org>2001-12-05 08:13:40 +0000
committerMaxim Sobolev <sobomax@FreeBSD.org>2001-12-05 08:13:40 +0000
commit9da70731a8d166d5ccf341771bd1bbf379ea07ed (patch)
tree3f31083f5248698fd41ca4850983814da041449e /Tools
parentc43bef046c872ffb4d7283b774efaae362afeb29 (diff)
downloadports-9da70731a8d166d5ccf341771bd1bbf379ea07ed.tar.gz
ports-9da70731a8d166d5ccf341771bd1bbf379ea07ed.zip
Make the tool working even if there is a symlink in a given path to a port's
file. For example I'm usually keeping all working directories in /tmp using WRKDIRPREFIX, while for the quick access to a port's files creating a symlink to this directory in skeleton's dir (i.e. ports/foo/bar/src --> /tmp/usr/ports/foo/bar/work/bar-0.0) and with this patch the tool correctly works when I'm specifying `src/foo.c' as an argument.
Notes
Notes: svn path=/head/; revision=51066
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/scripts/patchtool.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/Tools/scripts/patchtool.py b/Tools/scripts/patchtool.py
index 3e28abd39335..ec786d332534 100755
--- a/Tools/scripts/patchtool.py
+++ b/Tools/scripts/patchtool.py
@@ -108,7 +108,7 @@ def locateportdir(path, wrkdirprefix= '', strict = False):
#
# Get value of a make(1) variable called varname. Optionally maintain a cache
# for resolved varname:makepath pairs to speed-up operation if the same variable
-# from the exactly same file is requiested repeatedly (invocation of make(1) is
+# from the exactly same file is requested repeatedly (invocation of make(1) is
# very expensive operation...)
#
def querymakevar(varname, path = 'Makefile', strict = False, cache = {}):
@@ -456,6 +456,31 @@ class PatchesCollection:
return self.patches.values()
+#
+# Resolve all symbolic links in the given path to a file
+#
+def truepath(path):
+ if not os.path.isfile(path):
+ raise IOError(errno.ENOENT, path)
+
+ result = ''
+ while len(path) > 0:
+ path, lastcomp = os.path.split(path)
+ if len(lastcomp) == 0:
+ lastcomp = path
+ path = ''
+ result = os.path.join(lastcomp, result)
+ if len(path) == 0:
+ break
+ if os.path.islink(path):
+ linkto = os.path.normpath(os.readlink(path))
+ if linkto[0] != '/':
+ path = os.path.join(path, linkto)
+ else:
+ path = linkto
+ return result[:-1]
+
+
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], 'afui')
@@ -508,6 +533,8 @@ def generate(args, automatic, force, ignoremtime):
raise IOError(errno.ENOENT, filepath)
# Not reached #
+ filepath = truepath(filepath)
+
wrkdirprefix = querymakevar('WRKDIRPREFIX', Vars.ETC_MAKE_CONF, False)
portdir = locateportdir(os.path.dirname(filepath), wrkdirprefix, True)
wrksrc = querymakevar('WRKSRC', portdir, True)