Skip to content

Commit

Permalink
feat: locate real bazel relative to WORKSPACE (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
whilp authored Sep 12, 2020
1 parent c9a5639 commit 3d4a5ae
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions home/bin/bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import os
import pathlib
import platform
import stat
import sys
Expand All @@ -11,8 +12,14 @@ DEFAULT_VERSION = "3.4.1"

def main(args, env):
real = None
root = pathlib.Path(os.getcwd()).resolve()
workspace = get_workspace(root)
if workspace is None:
return

candidates = ["tools/bazel-real", ".bazel/bin/bazel-real"]
for candidate in candidates:
candidate = workspace/candidate
if executable(candidate):
real = candidate
break
Expand All @@ -24,6 +31,14 @@ def main(args, env):
env["PYTHONNOUSERSITE"] = "yes"
os.execve(real, args, env)

def get_workspace(root, last=None):
workspace = root / "WORKSPACE"
if workspace.exists():
return root
if root == last:
return None
return get_workspace(root.parent, root)


def fetch(real):
version = bazelversion()
Expand Down

0 comments on commit 3d4a5ae

Please sign in to comment.