~alpine/aports

testing/bazel: new aport v1 PROPOSED

Wolf: 1
 testing/bazel: new aport

 6 files changed, 268 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.alpinelinux.org/~alpine/aports/patches/4132/mbox | git am -3
Learn more about email & git

[PATCH] testing/bazel: new aport Export this patch

---
 ...-Redefine-strdupa-to-be-valid-C-code.patch | 26 +++++++
 .../0002-Do-not-use-prebuilt-binaries.patch   | 35 +++++++++
 ...er-local_jdk-instead-of-remote_jdk11.patch | 75 +++++++++++++++++++
 ...sh_completion-compatible-with-busybo.patch | 28 +++++++
 ...l-for-generating-the-bash-completion.patch | 34 +++++++++
 testing/bazel/APKBUILD                        | 70 +++++++++++++++++
 6 files changed, 268 insertions(+)
 create mode 100644 testing/bazel/0001-Redefine-strdupa-to-be-valid-C-code.patch
 create mode 100644 testing/bazel/0002-Do-not-use-prebuilt-binaries.patch
 create mode 100644 testing/bazel/0003-Prefer-local_jdk-instead-of-remote_jdk11.patch
 create mode 100644 testing/bazel/0004-Make-generate_bash_completion-compatible-with-busybo.patch
 create mode 100644 testing/bazel/0005-Use-nojdk-bazel-for-generating-the-bash-completion.patch
 create mode 100644 testing/bazel/APKBUILD

diff --git a/testing/bazel/0001-Redefine-strdupa-to-be-valid-C-code.patch b/testing/bazel/0001-Redefine-strdupa-to-be-valid-C-code.patch
new file mode 100644
index 0000000000..d7c1cb5503
--- /dev/null
+++ b/testing/bazel/0001-Redefine-strdupa-to-be-valid-C-code.patch
@@ -0,0 +1,26 @@
From b3a9f1898e341f184e43acaf1b6e3ec0844e358b Mon Sep 17 00:00:00 2001
From: Wolf <wolf@wolfsden.cz>
Date: Wed, 20 Jul 2022 02:00:51 +0200
Subject: [PATCH 1/5] Redefine strdupa to be valid C++ code

---
 src/main/tools/linux-sandbox-pid1.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/main/tools/linux-sandbox-pid1.cc b/src/main/tools/linux-sandbox-pid1.cc
index b6f4f3d665..c2f5ae6d42 100644
--- a/src/main/tools/linux-sandbox-pid1.cc
+++ b/src/main/tools/linux-sandbox-pid1.cc
@@ -43,6 +43,9 @@
 
 #include <string>
 
+#undef strdupa
+#define	strdupa(x)	strcpy((char*)alloca(strlen(x)+1),x)
+
 #ifndef MS_REC
 // Some systems do not define MS_REC in sys/mount.h. We might be able to grab it
 // from linux/fs.h instead (cf. #2667).
-- 
2.36.2

diff --git a/testing/bazel/0002-Do-not-use-prebuilt-binaries.patch b/testing/bazel/0002-Do-not-use-prebuilt-binaries.patch
new file mode 100644
index 0000000000..dffbf923f0
--- /dev/null
+++ b/testing/bazel/0002-Do-not-use-prebuilt-binaries.patch
@@ -0,0 +1,35 @@
From 9ef2af37544e8be7774b40d82c33d473455bccdc Mon Sep 17 00:00:00 2001
From: Wolf <wolf@wolfsden.cz>
Date: Wed, 20 Jul 2022 02:00:52 +0200
Subject: [PATCH 2/5] Do not use prebuilt binaries

Prebuilt binaries (ijar, singlejar) for linux are glibc specific,
meaning they do not work on alpine. Change the select to use _cc_binary
version instead.
---
 tools/jdk/BUILD.tools | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tools/jdk/BUILD.tools b/tools/jdk/BUILD.tools
index ad3e61e41a..7586fc22de 100644
--- a/tools/jdk/BUILD.tools
+++ b/tools/jdk/BUILD.tools
@@ -168,7 +168,6 @@ alias(
 alias(
     name = "ijar_prebuilt_binary_or_cc_binary",
     actual = select({
-        "//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux",
         "//src/conditions:darwin": ":ijar_prebuilt_binary_darwin",
         "//src/conditions:windows": ":ijar_prebuilt_binary_windows",
         "//conditions:default": "@remote_java_tools//:ijar_cc_binary",
@@ -198,7 +197,6 @@ alias(
 alias(
     name = "singlejar_prebuilt_or_cc_binary",
     actual = select({
-        "//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux",
         "//src/conditions:darwin": ":prebuilt_singlejar_darwin",
         "//src/conditions:windows": ":prebuilt_singlejar_windows",
         "//conditions:default": "@remote_java_tools//:singlejar_cc_bin",
-- 
2.36.2

diff --git a/testing/bazel/0003-Prefer-local_jdk-instead-of-remote_jdk11.patch b/testing/bazel/0003-Prefer-local_jdk-instead-of-remote_jdk11.patch
new file mode 100644
index 0000000000..036605df1e
--- /dev/null
+++ b/testing/bazel/0003-Prefer-local_jdk-instead-of-remote_jdk11.patch
@@ -0,0 +1,75 @@
From aca9cad3673e96d907633e7d7d3a6cf24f4128bc Mon Sep 17 00:00:00 2001
From: Wolf <wolf@wolfsden.cz>
Date: Wed, 20 Jul 2022 02:00:52 +0200
Subject: [PATCH 3/5] Prefer local_jdk instead of remote_jdk11

---
 .../devtools/build/lib/rules/java/JavaOptions.java     |  2 +-
 tools/jdk/BUILD.tools                                  |  2 +-
 tools/jdk/default_java_toolchain.bzl                   | 10 +++++-----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java
index 7794ef22c1..693f640131 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java
@@ -511,7 +511,7 @@ public class JavaOptions extends FragmentOptions {
 
   @Option(
       name = "tool_java_runtime_version",
-      defaultValue = "remotejdk_11",
+      defaultValue = "local_jdk",
       documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
       effectTags = {OptionEffectTag.UNKNOWN},
       help = "The Java runtime version used to execute tools during the build")
diff --git a/tools/jdk/BUILD.tools b/tools/jdk/BUILD.tools
index 7586fc22de..8edd0f9619 100644
--- a/tools/jdk/BUILD.tools
+++ b/tools/jdk/BUILD.tools
@@ -328,7 +328,7 @@ alias(
 
 alias(
     name = "host_jdk",
-    actual = ":remote_jdk11",
+    actual = "@local_jdk//:jdk",
 )
 
 bootclasspath(
diff --git a/tools/jdk/default_java_toolchain.bzl b/tools/jdk/default_java_toolchain.bzl
index ed64035b5e..28e34e79af 100644
--- a/tools/jdk/default_java_toolchain.bzl
+++ b/tools/jdk/default_java_toolchain.bzl
@@ -98,7 +98,7 @@ DEFAULT_TOOLCHAIN_CONFIGURATION = dict(
         "@remote_java_tools//:java_compiler_jar",
         "@remote_java_tools//:jdk_compiler_jar",
     ],
-    java_runtime = "@bazel_tools//tools/jdk:remote_jdk11",
+    java_runtime = "@local_jdk//:jdk",
 )
 
 # The 'vanilla' toolchain is an unsupported alternative to the default.
@@ -137,9 +137,9 @@ PREBUILT_TOOLCHAIN_CONFIGURATION = dict(
         "@remote_java_tools//:java_compiler_jar",
         "@remote_java_tools//:jdk_compiler_jar",
     ],
-    ijar = ["@bazel_tools//tools/jdk:ijar_prebuilt_binary"],
-    singlejar = ["@bazel_tools//tools/jdk:prebuilt_singlejar"],
-    java_runtime = "@bazel_tools//tools/jdk:remote_jdk11",
+    ijar = ["@remote_java_tools//:ijar_cc_binary"],
+    singlejar = ["@remote_java_tools//:singlejar_cc_bin"],
+    java_runtime = "@local_jdk//:jdk",
 )
 
 # The new toolchain is using all the tools from sources.
@@ -158,7 +158,7 @@ NONPREBUILT_TOOLCHAIN_CONFIGURATION = dict(
     ],
     ijar = ["@remote_java_tools//:ijar_cc_binary"],
     singlejar = ["@remote_java_tools//:singlejar_cc_bin"],
-    java_runtime = "@bazel_tools//tools/jdk:remote_jdk11",
+    java_runtime = "@local_jdk//:jdk",
 )
 
 def default_java_toolchain(name, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, toolchain_definition = True, **kwargs):
-- 
2.36.2

diff --git a/testing/bazel/0004-Make-generate_bash_completion-compatible-with-busybo.patch b/testing/bazel/0004-Make-generate_bash_completion-compatible-with-busybo.patch
new file mode 100644
index 0000000000..529edcc232
--- /dev/null
+++ b/testing/bazel/0004-Make-generate_bash_completion-compatible-with-busybo.patch
@@ -0,0 +1,28 @@
From 8bc9172da437ae156716f3e7d2da5298b86e663c Mon Sep 17 00:00:00 2001
From: Wolf <wolf@wolfsden.cz>
Date: Wed, 20 Jul 2022 02:00:53 +0200
Subject: [PATCH 4/5] Make generate_bash_completion compatible with busybox

Under busybox, expr does not accept -- (since it is not defined to take
any options, I would say it makes sense), so remove it from the script
generating bash completion.
---
 scripts/generate_bash_completion.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/generate_bash_completion.sh b/scripts/generate_bash_completion.sh
index 778810570c..46a3965f85 100755
--- a/scripts/generate_bash_completion.sh
+++ b/scripts/generate_bash_completion.sh
@@ -34,7 +34,7 @@ die() {
 }
 
 get_optarg() {
-  expr -- "${1}" : "[^=]*=\\(.*\\)"
+  expr "${1}" : "[^=]*=\\(.*\\)"
 }
 
 append=
-- 
2.36.2

diff --git a/testing/bazel/0005-Use-nojdk-bazel-for-generating-the-bash-completion.patch b/testing/bazel/0005-Use-nojdk-bazel-for-generating-the-bash-completion.patch
new file mode 100644
index 0000000000..23aa0e6125
--- /dev/null
+++ b/testing/bazel/0005-Use-nojdk-bazel-for-generating-the-bash-completion.patch
@@ -0,0 +1,34 @@
From 0b5d318335175ec0b1dfb96b05aaf19e452a1853 Mon Sep 17 00:00:00 2001
From: Wolf <wolf@wolfsden.cz>
Date: Wed, 20 Jul 2022 02:00:53 +0200
Subject: [PATCH 5/5] Use nojdk bazel for generating the bash completion

---
 scripts/BUILD | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/BUILD b/scripts/BUILD
index c477439950..7fc19a58e0 100644
--- a/scripts/BUILD
+++ b/scripts/BUILD
@@ -12,7 +12,7 @@ genrule(
     outs = ["bazel-complete.bash"],
     cmd = " ".join([
         "$(location :generate_bash_completion.sh)",
-        "--bazel=$(location //src:bazel)",
+        "--bazel=$(location //src:bazel_nojdk)",
         "--output=$@",
         "--prepend=$(location bazel-complete-header.bash)",
         "--prepend=$(location bazel-complete-template.bash)",
@@ -20,7 +20,7 @@ genrule(
     output_to_bindir = 1,
     tools = [
         ":generate_bash_completion.sh",
-        "//src:bazel",
+        "//src:bazel_nojdk",
     ],
     visibility = ["//scripts/packages:__subpackages__"],
 )
-- 
2.36.2

diff --git a/testing/bazel/APKBUILD b/testing/bazel/APKBUILD
new file mode 100644
index 0000000000..4d33058a73
--- /dev/null
+++ b/testing/bazel/APKBUILD
@@ -0,0 +1,70 @@
# Maintainer: Gray Wolf <wolf@wolfsden.cz>
pkgname=bazel
pkgver=5.2.0
pkgrel=0
pkgdesc="Bazel is an open-source build and test tool"
url="https://bazel.build/"
arch="all"
license="Apache-2.0"
depends="bash openjdk11-jdk"
makedepends="linux-headers python3 unzip zip"
checkdepends=""
install=""
# Bazel binary is thin C++ client with zip file embedded into the binary,
# stripping breaks that: https://github.com/bazelbuild/bazel/issues/11842
options="!strip"
subpackages="$pkgname-bash-completion"
source="
	https://github.com/bazelbuild/bazel/releases/download/$pkgver/bazel-$pkgver-dist.zip
	0001-Redefine-strdupa-to-be-valid-C-code.patch
	0002-Do-not-use-prebuilt-binaries.patch
	0003-Prefer-local_jdk-instead-of-remote_jdk11.patch
	0004-Make-generate_bash_completion-compatible-with-busybo.patch
	0005-Use-nojdk-bazel-for-generating-the-bash-completion.patch
"
builddir="$srcdir/"

build() {
	EMBED_LABEL=$pkgver-$pkgrel \
	EXTRA_BAZEL_ARGS=--tool_java_runtime_version=local_jdk \
		./compile.sh

	./output/bazel build //scripts:bazel-complete.bash
	cp bazel-bin/scripts/bazel-complete.bash output/

	./output/bazel clean --expunge
}

check() {
	./output/bazel build $(\
		./output/bazel query --noshow_progress '//examples/...' \
			| grep -vF \
				-e /android/ \
				-e /windows/ \
				-e :hello-error-prone \
	)
	./output/bazel test \
		//examples/cpp:hello-success_test \
		//examples/java-native/src/test/java/com/example/myproject:custom \
		//examples/java-native/src/test/java/com/example/myproject:hello \
		//examples/java-starlark/src/test/java/com/example/myproject:pass \
		//examples/py_native:test \
		//examples/shell:test

	./output/bazel clean --expunge
}

package() {
	install -Dm 755 -t "$pkgdir/usr/bin" output/bazel
	install -Dm 644 output/bazel-complete.bash \
		"$pkgdir/usr/share/bash-completion/completions/bazel"
}

sha512sums="
3b585b930db2be9e24db033a508d7f974ce8f4fa4139c0c58b315c1454f1530ed68f1798da35168ab7432bf06acc5fa3dea5f23989e33fe331ac8fd10e6b4d6c  bazel-5.2.0-dist.zip
fee02af79bd420451c6acde0cf842396cb89cf8aa739642755c28aed9fd107f501d5c130b77e15949d5cbb7a40127fd30420fbd1195d2c9e7f6426cd1b80d34b  0001-Redefine-strdupa-to-be-valid-C-code.patch
ad00887caa5d5f2281129fc102df1e0c5a5bf4744ba4bbb804bb7c4e4d001193da19d78d803c3cfcfa2ec5f447534ddee0658bfe3cadb68dfab1aacbaf7961f7  0002-Do-not-use-prebuilt-binaries.patch
801e046b745a78a7844d66d972fcc8d5d5d4d4802090d2e5abee38726f930b5718eae81036f33fdfc40f8e24d446fa4d8323f03831d919417a2328515c5d33db  0003-Prefer-local_jdk-instead-of-remote_jdk11.patch
95995d681aab3506671d318fe11ce9b95fd8ba6dacfbb654e481ceb04abebf014cb5eb676907410e7ea09bdebea21a43f74bfba0ce4ba7114d4fa9c4f009da4b  0004-Make-generate_bash_completion-compatible-with-busybo.patch
fb219155d302f42135da2e9f1bc943c3988619f557da6004adacbff880744eaa8e64c111913202efe830d26bd55a6565e0b1e80717cccdd56124b8fc8a4bd8bf  0005-Use-nojdk-bazel-for-generating-the-bash-completion.patch
"
-- 
2.36.2