cluster/tools/rook-s3cmd-config: build using bazel
This turns the existing script into a proper sh_binary, and injects
dependencies (kubectl and jq) as deps into it.
This change also pulls in BUILDfiles for jq, and a dep (oniguruma) into
//third_party, and adds buildable external repositories for them.
The jq/oniguruma BUILDfiles are lifted from
https://github.com/attilaolah/bazel-tools/.
Change-Id: If2e548bd60a8fd34e4f3be767ae59c6b2f2286d9
diff --git a/third_party/jq/BUILD b/third_party/jq/BUILD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/third_party/jq/BUILD
diff --git a/third_party/jq/BUILD.external b/third_party/jq/BUILD.external
new file mode 100644
index 0000000..e26c0fb
--- /dev/null
+++ b/third_party/jq/BUILD.external
@@ -0,0 +1,78 @@
+# Copyright 2019 Google LLC
+# Copyright 2020 Sergiusz 'q3k' Bazanski
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# The jq binary.
+cc_binary(
+ name = "jq",
+ srcs = [
+ ":source_files",
+ ],
+ copts = [
+ "-Iexternal/com_github_kkos_oniguruma/src",
+ "-Wno-cpp",
+ "-Wno-unused-function",
+ "-Wno-unused-variable",
+ ],
+ visibility = ["//visibility:public"],
+ deps = [
+ "@com_github_kkos_oniguruma//:oniguruma",
+ ],
+)
+
+# Generate the source files.
+# This will run ./configure and extract a host-dependent confdefs.h file, then
+# prefix each .h acd .c file with '#include "confdefs.h"'.
+genrule(
+ name = "source_files",
+ srcs = glob(["**"]),
+ outs = ["build/" + f for f in glob(
+ [
+ "src/*.h",
+ "src/*.c",
+ ],
+ exclude = [
+ "src/inject_errors.c",
+ ],
+ )] + [
+ # The extracted confdefs.h.
+ "build/src/confdefs.h",
+ # The generated builtin.inc.
+ "build/src/builtin.inc",
+ ],
+ cmd =
+ # Run ./configure && make src/builtin.inc.
+ "( " +
+ " cd external/com_github_stedolan_jq; " +
+ " ./configure > /dev/null 2> /dev/null; " +
+ " make src/builtin.inc > /dev/null; " +
+ "); " +
+ # Extract confdefs.h from config.log.
+ "grep '^/\\* confdefs.h \\*/$$' external/com_github_stedolan_jq/config.log -A1000 " +
+ " | head -n -1 > \"$(@D)\"/build/src/confdefs.h; " +
+ # Prefix each output file with an include of confdefs.h.
+ "OUTS=\"$(OUTS)\"; for FILE in $$OUTS; do " +
+ " touch \"$$FILE\"; " +
+ " BASENAME=\"$$(basename $$FILE)\"; " +
+ " if [ \"$$BASENAME\" != \"confdefs.h\" ]; then " +
+ " echo '#include \"confdefs.h\"' > \"$$FILE\"; " +
+ " cat external/com_github_stedolan_jq/src/\"$$BASENAME\" >> \"$$FILE\"; " +
+ " fi; " +
+ # Replace non-relative references.
+ " sed -e 's|^#include \"src/|#include \"|g' -i \"$$FILE\"; " +
+ "done; " +
+ # Copy builtin.inc and version.h without modificaitons.
+ "cp external/com_github_stedolan_jq/src/builtin.inc \"$(@D)\"/build/src/builtin.inc; ",
+)
+
diff --git a/third_party/jq/README.md b/third_party/jq/README.md
new file mode 100644
index 0000000..223de52
--- /dev/null
+++ b/third_party/jq/README.md
@@ -0,0 +1,6 @@
+third\_party: jq
+================
+
+Upstream: https://github.com/stedolan/jq
+
+Pulled in by WORKSPACE (com\_github\_stedolan\_jq), BUILD.external used as root BUILDfile for external repository.