Add remaining changes for bootstrap build on OpenBSD.

I have tested these changes via a bootstrap build on OpenBSD 6.6-current (amd64 architecture). The resulting `bazel` binary appeared to work in some simple testing involving `cc_library`, `cc_binary`, `java_library`, and `java_binary`.

Known issues/limitations:

- Building a `java_binary`'s deploy JAR fails because the `singlejar` tool fails to build. I intend to investigate soon.

- Running Bazel requires a `--host_javabase=@local_jdk//:jdk` flag.

- Sandboxing is unsupported.

This change, split out of the larger PR https://github.com/bazelbuild/bazel/pull/10274, is part of the OpenBSD port in https://github.com/bazelbuild/bazel/issues/10250. Most of the changes in that larger PR have already been committed via several smaller PRs (see the PRs linked from https://github.com/bazelbuild/bazel/issues/10250). This PR collects the remaining changes.

Closes #10567.

PiperOrigin-RevId: 290745757
diff --git a/src/BUILD b/src/BUILD
index a85a9ac..ab7c6a3 100644
--- a/src/BUILD
+++ b/src/BUILD
@@ -6,8 +6,9 @@
 
 exports_files(["jdeps_modules.golden"])
 
-# Keep only the first 32 chars (a hex md5sum) and no trailing newline.
-md5_cmd = "set -e -o pipefail && echo $(SRCS) | sort | xargs %s | %s | head -c 32 > $@"
+# We avoid using the `head` tool's `-c` option, since it does not exist on
+# OpenBSD; here we use `dd` instead.
+md5_cmd = "set -e -o pipefail && echo $(SRCS) | sort | xargs %s | %s | dd bs=32 count=1 > $@"
 
 # TODO(bazel-team): find a better way to handle dylib extensions.
 filegroup(
@@ -40,6 +41,7 @@
         "//src/conditions:darwin": md5_cmd % ("/sbin/md5", "/sbin/md5"),
         "//src/conditions:darwin_x86_64": md5_cmd % ("/sbin/md5", "/sbin/md5"),
         "//src/conditions:freebsd": md5_cmd % ("/sbin/md5", "/sbin/md5"),
+        "//src/conditions:openbsd": md5_cmd % ("/bin/md5", "/bin/md5"),
         "//conditions:default": md5_cmd % ("md5sum", "md5sum"),
     }),
 ) for suffix, embedded_tools_target in {
@@ -354,8 +356,8 @@
         ],
     }),
     outs = ["package" + suffix + ".zip"],
-    cmd = "$(location :package-bazel.sh) $@ " + ("" if embed else "''") + " $(SRCS)",
-    tools = ["package-bazel.sh"],
+    cmd = "$(location :package_bazel_on_host_platform) $@ " + ("" if embed else "''") + " $(SRCS)",
+    tools = [":package_bazel_on_host_platform"],
 ) for suffix, embed in [
     ("_jdk_allmodules", True),
     ("_jdk_minimal", True),
@@ -365,6 +367,16 @@
 ]]
 
 genrule(
+    name = "package_bazel_on_host_platform",
+    srcs = ["package-bazel.sh"],
+    outs = ["package-bazel-on-host-platform.sh"],
+    cmd = select({
+        "//src/conditions:openbsd": "cat $(SRCS) | sed -e 's@#!/bin/bash@#!/usr/local/bin/bash@' > $@",
+        "//conditions:default": "cp $(SRCS) $@",
+    }),
+)
+
+genrule(
     name = "platforms_archive",
     srcs = ["@platforms//:srcs"],
     outs = ["platforms.zip"],