rules_haskell icon indicating copy to clipboard operation
rules_haskell copied to clipboard

Incorrect/insufficient PATH given to bazel commands

Open symbiont-alexey-babkin opened this issue 2 years ago • 4 comments

Describe the bug The PATH that bazel is using for running commands with exec env - ... is incomplete (does not include /usr/local/bin)

To Reproduce Unfortunately I dont know how to repro this on another system

Expected behavior The PATH should contain /usr/local/bin

Environment

  • OS name + version: macos Monterrey 12.3.1
  • Bazel version: bazel 4.2.1-homebrew
  • Version of the rules: from the WORKSPACE file: (not sure where else to look for the version)
    git_repository(
     name = "rules_haskell",
     commit = "9772e524e5ba58a78b96d174dabbad6f537f496c",
     remote = "https://github.com/tweag/rules_haskell",
     shallow_since = "1642550400 +0200",
    

)```

Additional context

ERROR: /private/var/tmp/<edited>/1170ab3930346df84a66666fcbe60ee6/external/stackage/BUILD.bazel:5099:22: HaskellCabalLibrary @stackage//:transformers-compat failed: (Exit 127): sandbox-exec failed: error executing command
  (cd /private/var/tmp/<edited>/1170ab3930346df84a66666fcbe60ee6/sandbox/darwin-sandbox/19/execroot/<edited> && \
  exec env - \
    CC_WRAPPER_CC_PATH=external/local_config_cc/cc_wrapper.sh \
    CC_WRAPPER_CPU=darwin \
    CC_WRAPPER_PLATFORM=darwin \
    LANG=en_US.UTF-8 \
    PATH=external/pgconfig:/usr/bin:/bin:/usr/sbin \
    RULES_HASKELL_DOCDIR_PATH=external/rules_haskell_ghc_darwin_amd64/doc/html/libraries/base-4.14.1.0 \
    RULES_HASKELL_GHC_PATH=external/rules_haskell_ghc_darwin_amd64/bin/ghc \
    RULES_HASKELL_GHC_PKG_PATH=external/rules_haskell_ghc_darwin_amd64/bin/ghc-pkg \
    RULES_HASKELL_LIBDIR_PATH=external/rules_haskell_ghc_darwin_amd64/lib \
    SDKROOT=macosx \
    TMPDIR=/var/folders/x2/8mrjytds7zgb0yyk8vybgxhh0000gn/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/<edited>/1170ab3930346df84a66666fcbe60ee6/sandbox/darwin-sandbox/19/sandbox.sb /var/tmp/<edited>/install/db00fccbfc3e36ce55d88a25a435209a/process-wrapper '--timeout=0' '--kill_delay=15' bazel-out/host/bin/external/rules_haskell/haskell/cabal_wrapper bazel-out/darwin-opt/bin/external/stackage/transformers-compat_cabal_wrapper_args.json)
env: python: No such file or directory

Looks like bazel is trying to use python command, but it's not in /usr/bin (only python3 is as per recent deprecation of python2 on macos)

So one of theoretical fixes to this is some way to modify this PATH that this command is using, but I don't know how to do that. Any ideas welcome.

Thank you

symbiont-alexey-babkin avatar Apr 29 '22 15:04 symbiont-alexey-babkin

Hi, I think this issue may have been fixed by PR #1702. Could you try setting the commit of the above git_repository rule to the current head of rules_haskell: df5aeb7169021d88ef7bdf2a1d7655838cd1b375 ?

ylecornec avatar May 04 '22 06:05 ylecornec

Thank you @ylecornec , it looks like 5.1.0 fixes this problem. My company is still using the old 4.2.1 version though. So there is no way to add to the internal PATH in 4.2.1 for this command that fails for me?

symbiont-alexey-babkin avatar May 04 '22 14:05 symbiont-alexey-babkin

I don't think there is a way to directly add to the PATH at the moment.

One other thing to try would be to declare an hermetic python toolchain using rules_python by writing the following near the beginning of the WORKSPACE file (before setting up rules_haskell):

rules_python_version = "bd1a78de9faee19e3a91d3fa3bae2be9e33b1955"

http_archive(
    name = "rules_python",
    sha256 = "f58e32f67d1ee89e215661d0bd18d84078d5d829320747fc98beab855ed88a51",
    strip_prefix = "rules_python-{}".format(rules_python_version),
    url = "https://github.com/bazelbuild/rules_python/archive/{}.zip".format(rules_python_version),
)

load("@rules_python//python:repositories.bzl", "python_register_toolchains")

python_register_toolchains(
    name = "rules_haskell_python_local",
    # Available versions are listed in @rules_python//python:versions.bzl.
    # We recommend using the same version your team is already standardized on.
    python_version = "3.9",
)

The issue must not be the one I was thinking of because the fix was supposed to work on 4.2.1, but I have some questions to double check:

  • Does Bazel 5.1.0 fixes the problem on its own or is upgrading rules_haskell also needed ?
  • Is the error message using Bazel 4.2.1 and a recent rules_haskell the same as before ?

ylecornec avatar May 06 '22 12:05 ylecornec

Hi, thanks again

I only needed to upgrade to 5.1.0 to fix this problem, no changes beside it.

I was using recent rules_haskell as far as i know.

Another interesting thing is that 4.2.1 works for my colleague with a similar setup. He outputted his internal bazel PATH and it is different from mine (contains more dirs). Which is why I was thinking there was a way to alter the PATH on mine.

symbiont-alexey-babkin avatar May 06 '22 12:05 symbiont-alexey-babkin

Closing, since it was resolved by a Bazel upgrade and we no longer support Bazel 4 on the main branch.

avdv avatar Aug 02 '23 09:08 avdv