From df843dae9595706712c35f3d21a895df7ee34aba Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Wed, 3 Jun 2020 13:56:28 +0200 Subject: [PATCH 1/2] Expose execroot from Cabal wrapper To enable cc_wrapper to determine the path to the `_solib_` directory also when executing outside the execroot directory. --- haskell/private/cabal_wrapper.py.tpl | 1 + haskell/private/cc_wrapper.py.tpl | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/haskell/private/cabal_wrapper.py.tpl b/haskell/private/cabal_wrapper.py.tpl index f0da53cb1..c3199c8e0 100755 --- a/haskell/private/cabal_wrapper.py.tpl +++ b/haskell/private/cabal_wrapper.py.tpl @@ -140,6 +140,7 @@ with tmpdir() as distdir: # absolute ones before doing so (using $execroot). old_cwd = os.getcwd() os.chdir(srcdir) + os.putenv("RULES_HASKELL_EXEC_ROOT", old_cwd) os.putenv("HOME", "/var/empty") os.putenv("TMPDIR", os.path.join(distdir, "tmp")) os.putenv("TMP", os.path.join(distdir, "tmp")) diff --git a/haskell/private/cc_wrapper.py.tpl b/haskell/private/cc_wrapper.py.tpl index 84b96de5c..7540ddf80 100644 --- a/haskell/private/cc_wrapper.py.tpl +++ b/haskell/private/cc_wrapper.py.tpl @@ -711,17 +711,17 @@ def find_solib_rpath(rpaths, output): """ for rpath in rpaths: components = rpath.replace("\\", "/").split("/") - solib_rpath = [] + solib_rpath = "" for comp in components: - solib_rpath.append(comp) - if comp.startswith("_solib_"): - return "/".join(solib_rpath) + solib_rpath = os.path.join(solib_rpath, comp) + if comp.startswith("_solib_") and os.path.isdir(resolve_rpath(solib_rpath, output)[1]): + return solib_rpath if is_temporary_output(output): # GHC generates temporary libraries outside the execroot. In that case # the Bazel generated RPATHs are not forwarded, and the solib directory # is not visible on the command-line. - for (root, dirnames, _) in breadth_first_walk("."): + for (root, dirnames, _) in breadth_first_walk(os.environ.get("RULES_HASKELL_EXEC_ROOT", ".")): if "_solib_{:cpu:}" in dirnames: return os.path.join(root, "_solib_{:cpu:}") From 97647ccb9bf2da1cff648cb159a11eea09371801 Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Wed, 3 Jun 2020 15:29:03 +0200 Subject: [PATCH 2/2] Avoid exceeding MAX_PATH on Windows in Cabal wrapper --- haskell/private/cabal_wrapper.py.tpl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/haskell/private/cabal_wrapper.py.tpl b/haskell/private/cabal_wrapper.py.tpl index c3199c8e0..89d0dbb7d 100755 --- a/haskell/private/cabal_wrapper.py.tpl +++ b/haskell/private/cabal_wrapper.py.tpl @@ -121,10 +121,16 @@ def tmpdir(): # Executables are placed into `/build//`. # Libraries are placed into `/build/`. I.e. there is an # extra subdirectory for libraries. - if component.startswith("exe:"): - distdir = tempfile.mkdtemp(dir=os.path.dirname(os.path.dirname(pkgroot))) + # + # On Windows we don't do dynamic linking and prefer shorter paths to avoid + # exceeding `MAX_PATH`. + if "%{is_windows}" == "True": + distdir = tempfile.mkdtemp() else: - distdir = tempfile.mkdtemp(dir=os.path.dirname(pkgroot)) + if component.startswith("exe:"): + distdir = tempfile.mkdtemp(dir=os.path.dirname(os.path.dirname(pkgroot))) + else: + distdir = tempfile.mkdtemp(dir=os.path.dirname(pkgroot)) try: yield distdir finally: @@ -166,7 +172,7 @@ with tmpdir() as distdir: # absolute paths refer the temporary directory that GHC uses for # intermediate template Haskell outputs. `cc_wrapper` should improved # in that regard. - "--builddir=" + os.path.relpath(distdir), \ + "--builddir=" + (os.path.relpath(distdir) if "%{is_windows}" != "True" else distdir), \ "--prefix=" + pkgroot, \ "--libdir=" + libdir, \ "--dynlibdir=" + dynlibdir, \