Add support for building with Bazel
This change adds support for in Gerrit tree and standalone Bazel build
modes, using bazlets.
To build a single plugin, run:
$ bazel build example-simpleSshCommand
INFO: Found 1 target...
Target //example-simpleSshCommand:example-simpleSshCommand up-to-date:
bazel-genfiles/example-simpleSshCommand/example-simpleSshCommand.jar
INFO: Elapsed time: 0.171s, Critical Path: 0.07s
To build all plugins at once, run:
$ bazel build :all
INFO: Found 1 target...
Target //:all up-to-date:
bazel-genfiles/all.zip
INFO: Elapsed time: 0.326s, Critical Path: 0.21s
$ unzip -t
bazel-genfiles/all.zip
Archive: bazel-genfiles/all.zip
testing: example-simpleSshCommand.jar OK
Change-Id: I5ec70eec2492e1d2bd3e968135ba8206abf82c22
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0dc79e7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+bazel-bin
+bazel-examples
+bazel-genfiles
+bazel-out
+bazel-testlogs
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..16bf5ea
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,14 @@
+genrule(
+ name = "all",
+ srcs = [
+ "//example-simpleSshCommand",
+ ],
+ outs = ["all.zip"],
+ cmd = " && ".join([
+ "p=$$PWD",
+ "t=$$(mktemp -d || mktemp -d -t bazel-tmp)",
+ "cp $(SRCS) $$t",
+ "cd $$t",
+ "zip -qr $$p/$@ .",
+ ]),
+)
diff --git a/README b/README
index b8a2844..3024def 100644
--- a/README
+++ b/README
@@ -1,7 +1,41 @@
-Build
-=====
+Bazel Build
+===========
-This plugin is built with Buck.
+This plugin can be built with Bazel
+
+
+Build standalone
+----------------
+
+To build all the example plugins, issue the following command:
+
+
+ bazel build :all
+
+
+The output for all the example plugins is created in
+
+
+ bazel-genfiles/all.zip
+
+
+To build a specific example plugin, issue the following command:
+
+
+ bazel build example-<example>
+
+
+The output for the example is created in
+
+
+ bazel-genfiles/example-<example>/example-<example>.jar
+
+
+
+Buck Build
+==========
+
+This plugin can be built with Buck.
Two build modes are supported: Standalone and in Gerrit tree. Standalone
build mode is recommended, as this mode doesn't require local Gerrit
diff --git a/WORKSPACE b/WORKSPACE
new file mode 100644
index 0000000..4317784
--- /dev/null
+++ b/WORKSPACE
@@ -0,0 +1,26 @@
+workspace(name = "examples")
+
+load("//:bazlets.bzl", "load_bazlets")
+
+load_bazlets(
+ commit = "0f87babe07a555425d829c6e7951e296e9e24579",
+ # local_path = "/home/<user>/projects/bazlets",
+)
+
+# Release Plugin API
+load(
+ "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
+ "gerrit_api",
+)
+
+# Snapshot Plugin API
+#load(
+# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
+# "gerrit_api_maven_local",
+#)
+
+# Load release Plugin API
+gerrit_api()
+
+# Load snapshot Plugin API
+#gerrit_api_maven_local()
diff --git a/bazlets.bzl b/bazlets.bzl
new file mode 100644
index 0000000..e14e488
--- /dev/null
+++ b/bazlets.bzl
@@ -0,0 +1,17 @@
+NAME = "com_googlesource_gerrit_bazlets"
+
+def load_bazlets(
+ commit,
+ local_path = None
+ ):
+ if not local_path:
+ native.git_repository(
+ name = NAME,
+ remote = "https://gerrit.googlesource.com/bazlets",
+ commit = commit,
+ )
+ else:
+ native.local_repository(
+ name = NAME,
+ path = local_path,
+ )
diff --git a/example-simpleSshCommand/BUILD b/example-simpleSshCommand/BUILD
new file mode 100644
index 0000000..51102db
--- /dev/null
+++ b/example-simpleSshCommand/BUILD
@@ -0,0 +1,12 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+gerrit_plugin(
+ name = "example-simpleSshCommand",
+ srcs = glob(["src/main/java/**/*.java"]),
+ manifest_entries = [
+ "Gerrit-PluginName: example-simpleSshCommand",
+ "Gerrit-SshModule: com.googlesource.gerrit.plugins.examples.simplesshcommand.SshModule",
+ "Implementation-Title: Example Simple SSH Command",
+ ],
+ resources = glob(["src/main/resources/**/*"]),
+)
diff --git a/tools/bazel.rc b/tools/bazel.rc
new file mode 100644
index 0000000..4ed16cf
--- /dev/null
+++ b/tools/bazel.rc
@@ -0,0 +1,2 @@
+build --workspace_status_command=./tools/workspace-status.sh
+test --build_tests_only
diff --git a/tools/bzl/BUILD b/tools/bzl/BUILD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tools/bzl/BUILD
diff --git a/tools/bzl/plugin.bzl b/tools/bzl/plugin.bzl
new file mode 100644
index 0000000..2b1df8c
--- /dev/null
+++ b/tools/bzl/plugin.bzl
@@ -0,0 +1,4 @@
+load(
+ "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl",
+ "gerrit_plugin",
+)
diff --git a/tools/workspace-status.sh b/tools/workspace-status.sh
new file mode 100755
index 0000000..34dd869
--- /dev/null
+++ b/tools/workspace-status.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# This script will be run by bazel when the build process starts to
+# generate key-value information that represents the status of the
+# workspace. The output should be like
+#
+# KEY1 VALUE1
+# KEY2 VALUE2
+#
+# If the script exits with non-zero code, it's considered as a failure
+# and the output will be discarded.
+
+function rev() {
+ cd $1; git describe --always --match "v[0-9].*" --dirty
+}
+
+for p in example-* ; do
+ test -d "$p" || continue
+ # special treatment of nested example plugins
+ echo STABLE_BUILD_$(echo $(basename $p)_LABEL|tr '[a-z]' '[A-Z]' ) $(rev $p)
+done