Skip to content

Commit b65ebd8

Browse files
committed
Construct repository relative paths for absolute and relative paths
1 parent bc8d408 commit b65ebd8

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

haskell/private/pkgdb_to_bzl.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
def resolve(path, pkgroot):
3737
"""Resolve references to ${pkgroot} with the given value, resolve $topdir with `topdir`"""
3838
if path.find("${pkgroot}") != -1:
39-
return path.strip("\"").replace("${pkgroot}", pkgroot)
39+
norm_path = os.path.normpath(path.strip("\"").replace("${pkgroot}", pkgroot))
40+
if not os.path.isabs(norm_path) and norm_path.startswith('..'):
41+
return resolve(path, os.path.realpath(pkgroot))
42+
else:
43+
return norm_path
4044
elif path.startswith("$topdir"):
4145
return os.path.normpath(path.replace("$topdir", topdir)).replace('\\', '/')
4246
else:
@@ -48,12 +52,12 @@ def path_to_label(path, pkgroot):
4852
# determine if the given path is inside the repository root
4953
# if it is not, return None to signal it needs to be symlinked into the
5054
# repository
51-
real_path = os.path.realpath(resolve(path, pkgroot))
52-
relative_path = os.path.relpath(real_path, start=repo_root)
55+
norm_path = os.path.normpath(resolve(path, pkgroot))
56+
relative_path = os.path.relpath(norm_path, start=repo_root)
5357

5458
return None if relative_path.startswith('..') else relative_path.replace('\\', '/')
5559

56-
topdir_relative_path = path.replace(pkgroot, "$topdir")
60+
topdir_relative_path = path.replace(os.path.realpath(pkgroot), "$topdir")
5761
if topdir_relative_path.find("$topdir") != -1:
5862
return os.path.normpath(topdir_relative_path.replace("$topdir", topdir)).replace('\\', '/')
5963

@@ -104,15 +108,16 @@ def hs_library_pattern(name, mode = "static", profiling = False):
104108
# Accumulate package id to package name mappings.
105109
pkg_id_map = []
106110

111+
# pkgroot is not part of .conf files. It's a computed value. It is
112+
# defined to be the directory enclosing the package database
113+
# directory.
114+
pkgroot = os.path.dirname(package_conf_dir)
115+
116+
107117
for conf in glob.glob(os.path.join(package_conf_dir, '*.conf')):
108118
with open(conf, 'r') as f:
109119
pkg = package_configuration.parse_package_configuration(f)
110120

111-
# pkgroot is not part of .conf files. It's a computed value. It is
112-
# defined to be the directory enclosing the package database
113-
# directory.
114-
pkgroot = os.path.dirname(os.path.dirname(os.path.realpath(conf)))
115-
116121
pkg_id_map.append((pkg.name, pkg.id))
117122

118123
# Haddock handling

0 commit comments

Comments
 (0)