diff options
author | sobomax <sobomax@FreeBSD.org> | 2001-12-05 16:13:40 +0800 |
---|---|---|
committer | sobomax <sobomax@FreeBSD.org> | 2001-12-05 16:13:40 +0800 |
commit | 83662ac396598fcd88fa4bdae70347788e21e09f (patch) | |
tree | ae7c12c7604ba64f2e2e80ea1e8877164b831409 /Tools | |
parent | ed5fe18742111882989e2ceba1c338a1e37722d9 (diff) | |
download | freebsd-ports-gnome-83662ac396598fcd88fa4bdae70347788e21e09f.tar.gz freebsd-ports-gnome-83662ac396598fcd88fa4bdae70347788e21e09f.tar.zst freebsd-ports-gnome-83662ac396598fcd88fa4bdae70347788e21e09f.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.
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/scripts/patchtool.py | 29 |
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) |