Bundled JDK changes for the release process. This is a fixed version
that should not break CI this time...

- Make the default Bazel release artifacts include the bundled JDK.
- Create additional Bazel release artifacts without a bundled JDK.

Tested by running "bazel build //scripts/..." in a clean checkout and
one with this patch in, then diffing the entire bazel-out folder and
manually inspecting the resulting files (zips, tar.gz, deb, rpm) to make
sure that they contain the right files. Looks all good now, so let's try
again.

PiperOrigin-RevId: 154544164
diff --git a/scripts/packages/BUILD b/scripts/packages/BUILD
index 1ebe901..a5318b9 100644
--- a/scripts/packages/BUILD
+++ b/scripts/packages/BUILD
@@ -17,16 +17,20 @@
     srcs = select({
         "//src:windows": [],
         "//src:windows_msvc": [],
+        "//src:freebsd": [],
         "//src:darwin": [
-            ":install.sh",
+            ":with-jdk/install.sh",
+            ":without-jdk/install.sh",
             ":generate-package-info",
         ],
         "//src:darwin_x86_64": [
-            ":install.sh",
+            ":with-jdk/install.sh",
+            ":without-jdk/install.sh",
             ":generate-package-info",
         ],
         "//conditions:default": [
-            ":install.sh",
+            ":with-jdk/install.sh",
+            ":without-jdk/install.sh",
             ":generate-package-info",
             "//:bazel-distfile",
             "//scripts/packages/debian:bazel-debian",
@@ -64,29 +68,43 @@
 
 genrule(
     name = "rename-bazel-bin",
-    srcs = ["//src:bazel"],
-    outs = ["bazel-real"],
-    cmd = "cp $< $@",
+    srcs = ["//src:bazel_with_jdk"],
+    outs = ["with-jdk/bazel-real"],
+    cmd = "mkdir -p $$(dirname $@); cp $< $@",
 )
 
 genrule(
-    name = "rename-bazel-sh",
+    name = "rename-bazel-bin-without-jdk",
+    srcs = ["//src:bazel"],
+    outs = ["without-jdk/bazel-real"],
+    cmd = "mkdir -p $$(dirname $@); cp $< $@",
+)
+
+genrule(
+    name = "bazel-sh-with-jdk",
     srcs = ["bazel.sh"],
-    outs = ["bazel"],
-    cmd = "cp $< $@",
+    outs = ["with-jdk/bazel"],
+    cmd = "mkdir -p $$(dirname $@); cp $< $@",
+)
+
+genrule(
+    name = "bazel-sh-without-jdk",
+    srcs = ["bazel.sh"],
+    outs = ["without-jdk/bazel"],
+    cmd = "mkdir -p $$(dirname $@); cp $< $@",
 )
 
 load(":self_extract_binary.bzl", "self_extract_binary")
 
-self_extract_binary(
-    name = "install.sh",
+[self_extract_binary(
+    name = "%s/install.sh" % kind,
     flatten_resources = [
-        ":bazel-real",
-        ":bazel",
+        ":%s/bazel-real" % kind,
+        ":%s/bazel" % kind,
         "//scripts:bash_completion",
     ],
     launcher = ":launcher_bin.sh",
-)
+) for kind in ("with-jdk", "without-jdk")]
 
 genrule(
     name = "embedded_label",
diff --git a/scripts/packages/debian/BUILD b/scripts/packages/debian/BUILD
index bc4119b..6048692 100644
--- a/scripts/packages/debian/BUILD
+++ b/scripts/packages/debian/BUILD
@@ -9,12 +9,12 @@
 pkg_tar(
     name = "bazel-bin",
     files = [
-        "//scripts/packages:bazel",
-        "//scripts/packages:bazel-real",
+        "//scripts/packages:without-jdk/bazel",
+        "//scripts/packages:without-jdk/bazel-real",
     ],
     mode = "0755",
     package_dir = "/usr/bin",
-    strip_prefix = "/scripts/packages",
+    strip_prefix = "/scripts/packages/without-jdk",
 )
 
 pkg_tar(
diff --git a/scripts/packages/fedora/BUILD b/scripts/packages/fedora/BUILD
index 2ee91d0..2124f3a 100644
--- a/scripts/packages/fedora/BUILD
+++ b/scripts/packages/fedora/BUILD
@@ -13,9 +13,9 @@
     changelog = "//:changelog-file",
     data = [
         "//scripts:bash_completion",
-        "//scripts/packages:bazel",
         "//scripts/packages:bazel.bazelrc",
-        "//scripts/packages:bazel-real",
+        "//scripts/packages:without-jdk/bazel",
+        "//scripts/packages:without-jdk/bazel-real",
     ],
     spec_file = "bazel.spec",
     version_file = "//scripts/packages:version.txt",
diff --git a/scripts/packages/self_extract_binary.bzl b/scripts/packages/self_extract_binary.bzl
index 425a203..75f1927 100644
--- a/scripts/packages/self_extract_binary.bzl
+++ b/scripts/packages/self_extract_binary.bzl
@@ -75,18 +75,21 @@
 
 self_extract_binary = rule(
     _self_extract_binary,
-    executable = True,
     attrs = {
         "launcher": attr.label(
-            mandatory=True,
-            allow_files=True,
-            single_file=True),
-        "empty_files": attr.string_list(default=[]),
+            mandatory = True,
+            allow_files = True,
+            single_file = True,
+        ),
+        "empty_files": attr.string_list(default = []),
         "resources": attr.label_list(
-            default=[],
-            allow_files=True),
+            default = [],
+            allow_files = True,
+        ),
         "flatten_resources": attr.label_list(
-            default=[],
-            allow_files=True),
-        },
-    )
+            default = [],
+            allow_files = True,
+        ),
+    },
+    executable = True,
+)