summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2019-08-26 12:05:44 +0200
committerDavid Pursehouse <dpursehouse@collab.net>2019-08-27 17:33:26 +0900
commit7d60ca3f3430f664cd76a7c3d4632e61e1c3aee3 (patch)
tree832823f509b27d20f18a01f4d82462faab506e78
parent3b13e77adabd66bf3a0f33f5d82254c5b336eea5 (diff)
Support bazelisk or bazel in tools/eclipse/project.py
It is recommended to use bazelisk instead of bazel directly, however it is also perfectly reasonable to use bazel directly. Update the eclipse script to default to looking for bazelisk then bazel, but to continue to allow explicit overrides. This should allow people who do not have bazelisk to not be broken, but people who have installed bazelisk to have it be the program run by default. This also causes whichever of the two was found to to go into .bazel_path which will influence what eclipse uses. Bug: Issue 11359 Change-Id: Ic6d63f6e52502e01236736f7ce60e98533b4a104
-rwxr-xr-xtools/eclipse/project.py37
1 files changed, 31 insertions, 6 deletions
diff --git a/tools/eclipse/project.py b/tools/eclipse/project.py
index 64e0a85218..b6668c8124 100755
--- a/tools/eclipse/project.py
+++ b/tools/eclipse/project.py
@@ -45,18 +45,43 @@ opts.add_argument('--plugins', help='create eclipse projects for plugins',
action='store_true')
opts.add_argument('--name', help='name of the generated project',
action='store', default='gerrit', dest='project_name')
-opts.add_argument('--bazel', help='name of the bazel executable',
- action='store', default='bazel', dest='bazel_exe')
+opts.add_argument('--bazel',
+ help=('name of the bazel executable. Defaults to using'
+ ' bazelisk if found, or bazel if bazlisk is not'
+ ' found.'),
+ action='store', default=None, dest='bazel_exe')
+
+def find_bazel():
+ if args.bazel_exe:
+ try:
+ return subprocess.check_output(
+ ['which', args.bazel_exe]).strip().decode('UTF-8')
+ except subprocess.CalledProcessError:
+ print('Bazel command: %s not found' % args.bazel_exe, file=sys.stderr)
+ sys.exit(1)
+ try:
+ return subprocess.check_output(
+ ['which', 'bazelisk']).strip().decode('UTF-8')
+ except subprocess.CalledProcessError:
+ try:
+ return subprocess.check_output(
+ ['which', 'bazel']).strip().decode('UTF-8')
+ except subprocess.CalledProcessError:
+ print("Neither bazelisk nor bazel found. Please see"
+ " Documentation/dev-bazel for instructions on installing"
+ " one of them.")
+ sys.exit(1)
args = opts.parse_args()
+bazel_exe = find_bazel()
def retrieve_ext_location():
return subprocess.check_output(
- [args.bazel_exe, 'info', 'output_base']).strip()
+ [bazel_exe, 'info', 'output_base']).strip()
def gen_bazel_path():
bazel = subprocess.check_output(
- ['which', args.bazel_exe]).strip().decode('UTF-8')
+ ['which', bazel_exe]).strip().decode('UTF-8')
with open(os.path.join(ROOT, ".bazel_path"), 'w') as fd:
fd.write("bazel=%s\n" % bazel)
fd.write("PATH=%s\n" % os.environ["PATH"])
@@ -65,7 +90,7 @@ def _query_classpath(target):
deps = []
t = cp_targets[target]
try:
- subprocess.check_call([args.bazel_exe, 'build', t])
+ subprocess.check_call([bazel_exe, 'build', t])
except subprocess.CalledProcessError:
exit(1)
name = 'bazel-bin/tools/eclipse/' + t.split(':')[1] + '.runtime_classpath'
@@ -277,7 +302,7 @@ try:
try:
subprocess.check_call([
- args.bazel_exe, 'build', MAIN, GWT,
+ bazel_exe, 'build', MAIN, GWT,
'//gerrit-patch-jgit:libEdit-src.jar'])
except subprocess.CalledProcessError:
exit(1)