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
This commit is contained in:
Monty Taylor
2019-08-26 12:05:44 +02:00
committed by David Pursehouse
parent 3b13e77ada
commit 7d60ca3f34

View File

@@ -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)