Skip to content

Commit

Permalink
Construct repository relative paths for absolute and relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
avdv committed Dec 4, 2023
1 parent bc8d408 commit b65ebd8
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions haskell/private/pkgdb_to_bzl.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
def resolve(path, pkgroot):
"""Resolve references to ${pkgroot} with the given value, resolve $topdir with `topdir`"""
if path.find("${pkgroot}") != -1:
return path.strip("\"").replace("${pkgroot}", pkgroot)
norm_path = os.path.normpath(path.strip("\"").replace("${pkgroot}", pkgroot))
if not os.path.isabs(norm_path) and norm_path.startswith('..'):
return resolve(path, os.path.realpath(pkgroot))
else:
return norm_path
elif path.startswith("$topdir"):
return os.path.normpath(path.replace("$topdir", topdir)).replace('\\', '/')
else:
Expand All @@ -48,12 +52,12 @@ def path_to_label(path, pkgroot):
# determine if the given path is inside the repository root
# if it is not, return None to signal it needs to be symlinked into the
# repository
real_path = os.path.realpath(resolve(path, pkgroot))
relative_path = os.path.relpath(real_path, start=repo_root)
norm_path = os.path.normpath(resolve(path, pkgroot))
relative_path = os.path.relpath(norm_path, start=repo_root)

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

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

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

# pkgroot is not part of .conf files. It's a computed value. It is
# defined to be the directory enclosing the package database
# directory.
pkgroot = os.path.dirname(package_conf_dir)


for conf in glob.glob(os.path.join(package_conf_dir, '*.conf')):
with open(conf, 'r') as f:
pkg = package_configuration.parse_package_configuration(f)

# pkgroot is not part of .conf files. It's a computed value. It is
# defined to be the directory enclosing the package database
# directory.
pkgroot = os.path.dirname(os.path.dirname(os.path.realpath(conf)))

pkg_id_map.append((pkg.name, pkg.id))

# Haddock handling
Expand Down

0 comments on commit b65ebd8

Please sign in to comment.