tools/eclipse/project.sh: Use bazel query to find project.py

This script generates the configuration for the eclipse editor running
the "project.py" script (provided by a bazlet).

To find this "project.py", the script uses a bazel workaround that seems
to be failing.

https://github.com/bazelbuild/bazel/issues/2452#issuecomment-316895752
reports an alternative to the workaround above, using bazel query.

Remove the py_binary workaround and use bazel query directly.

Validate also that the script is called from gitiles root directory.

Bug: https://crbug.com/gerrit/10856
Change-Id: I91e47c2b1b167b38531f53a491683a3d47db9e00
diff --git a/tools/eclipse/BUILD b/tools/eclipse/BUILD
index f6a1b35..ec640c1 100644
--- a/tools/eclipse/BUILD
+++ b/tools/eclipse/BUILD
@@ -1,5 +1,4 @@
 load("@com_googlesource_gerrit_bazlets//tools:classpath.bzl", "classpath_collector")
-load("@com_googlesource_gerrit_bazlets//tools:py_binary_path.bzl", "py_binary_path")
 
 DEPS = [
     "//java/com/google/gitiles:servlet",
@@ -18,14 +17,3 @@
         "//javatests/com/google/gitiles:servlet_tests",
     ],
 )
-
-# TODO(davido): This is a hack:
-# https://github.com/bazelbuild/bazel/issues/2452
-# We know the py_binary rule,  but for *reasons* we cannot
-# use `buck run <rule>. Unfortunately, a query to retrieve
-# the path was removed in Bazel. So we are forced to do this
-# hack to access python script outside of the Bazel.
-py_binary_path(
-    name = "project.py",
-    py_binary_label = "@com_googlesource_gerrit_bazlets//tools/eclipse:project",
-)
diff --git a/tools/eclipse/project.sh b/tools/eclipse/project.sh
index e11daa0..03170ec 100755
--- a/tools/eclipse/project.sh
+++ b/tools/eclipse/project.sh
@@ -13,5 +13,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-bazel build tools/eclipse:project.py
-`bazel info output_base`/`cat bazel-bin/tools/eclipse/project.py.txt` -n gitiles -r .
+[ $(basename $PWD) != "gitiles" ] && echo "This script must be run from the gitiles top directory" && exit 1
+
+PROJECT_PY_PATH=$(bazel query @com_googlesource_gerrit_bazlets//tools/eclipse:project --output location | sed s/BUILD:.*//)
+[ $? -ne 0 ] && echo "Unable fo find project.py" && exit 1
+
+$PROJECT_PY_PATH/project.py -n gitiles -r .
+[ $? -eq 0 ] && echo "Eclipse configuration generated."
+