From 3f4d3922f281d918870f8c82d34534b1459c5ff6 Mon Sep 17 00:00:00 2001 From: bryan Date: Fri, 16 Oct 2026 13:28:41 -0700 Subject: [PATCH 1/2] jbang: add 0.142.0 The platform-independent bundle from GitHub releases (bash launcher + jbang.jar) under /usr/share/jbang, with a /usr/bin wrapper that pins JAVA_HOME to the packaged jdk so jbang never downloads a JDK. Declares needs {dns, internet} for consumers: resolving //DEPS from Maven Central is jbang's job. The Standalone test runs a self-contained script with --offline, so it cannot pass by reaching the network. Refs #899. Co-Authored-By: Claude Opus 5.5 --- packages/jbang/build.ncl | 89 ++++++++++++++++++++++++++++++++++++++++ packages/jbang/build.sh | 28 +++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 packages/jbang/build.ncl create mode 100755 packages/jbang/build.sh diff --git a/packages/jbang/build.ncl b/packages/jbang/build.ncl new file mode 100644 index 000000000..725b0e331 --- /dev/null +++ b/packages/jbang/build.ncl @@ -0,0 +1,89 @@ +let { Attrs, BuildSpec, Local, Needs, OutputBin, OutputData, Source, Test, .. } = import "minimal.ncl" in +let base = import "../base/build.ncl" in +let bash = import "../bash/build.ncl" in +let coreutils = import "../coreutils/build.ncl" in +let jdk = import "../jdk/build.ncl" in + +let version = "0.142.0" in +{ + name = "jbang", + # JBang runs single-file Java programs (`jbang hello.java`), resolving any + # `//DEPS` from Maven Central. The platform-independent bundle is a bash + # launcher plus one jar. + # + # Prebuilt, not built from source: jbang builds with Gradle and resolves its + # dependencies from Maven Central, so a hermetic source build is not possible + # today. Same shape as maven / gradle / jdtls. + build_deps = [ + { file = "build.sh" } | Local, + { + url = "https://github.com/jbangdev/jbang/releases/download/v%{version}/jbang-%{version}.tar", + sha256 = "43aaeb9bc30d9331ed57952a872b80dab3dafe8e927f0f7a90a3c8e67d08eaac", + } | Source, + base, + ], + runtime_deps = [ + bash, # bin/jbang is a bash script (#!/usr/bin/env bash, BASH_SOURCE, [[ ]]) + coreutils, # env, uname, dirname, readlink in the launcher + jdk, # the wrapper pins JAVA_HOME here so jbang never downloads a JDK + ], + # Not for jbang's own build (that is offline): this is the abstract network + # dep a package that builds WITH jbang inherits. jbang's job is resolving + # `//DEPS` from Maven Central (and, for `//JAVA ` other than the packaged + # jdk, downloading a JDK), like curl/go/pnpm/uv. A script with no `//DEPS` + # runs fully offline; see the run_script test. + needs = + { + dns = {}, + internet = {}, + } | Needs, + + cmd = "./build.sh", + build_args = { + include version, + }, + + outputs = { + jbang = { glob = "usr/bin/jbang" } | OutputBin, + launcher = { glob = "usr/share/jbang/bin/jbang" } | OutputBin, + jbang_home = { glob = "usr/share/jbang/**", allow_executable = true } | OutputData, + }, + + attrs = + { + upstream_version = version, + license_spdx = "MIT", + binary_from = "https://github.com/jbangdev/jbang/releases", + source_provenance = { + category = 'GithubRepo, + owner = "jbangdev", + repo = "jbang", + }, + } | Attrs, + + tests = { + jbang_version = + { + class = 'Standalone, + test_deps = [base], + cmds = [ + ["/bin/bash", "-c", "jbang --version 2>&1 | grep -qF '%{version}'"], + ], + } | Test, + + # Compile and run a self-contained script with --offline, so any attempt to + # reach the network (dependency resolution, JDK download) fails the test + # instead of passing silently. JBANG_DIR keeps jbang's cache in the test's + # cwd rather than ~/.jbang. + run_script = + { + class = 'Standalone, + test_deps = [base], + cmds = [ + ["/bin/bash", "-c", "printf 'class hello {\\n public static void main(String[] args) {\\n System.out.println(\"hello \" + String.join(\",\", args));\\n }\\n}\\n' > hello.java"], + ["/bin/bash", "-c", "JBANG_DIR=\"$PWD/jbang-home\" jbang --offline hello.java a b > out.txt"], + ["/bin/bash", "-c", "grep -qx 'hello a,b' out.txt"], + ], + } | Test, + }, +} | BuildSpec diff --git a/packages/jbang/build.sh b/packages/jbang/build.sh new file mode 100755 index 000000000..9b6e7a5b8 --- /dev/null +++ b/packages/jbang/build.sh @@ -0,0 +1,28 @@ +#!/bin/sh +set -ex + +# The platform-independent bundle: bin/jbang (bash launcher), bin/jbang.jar, +# plus .cmd/.ps1 launchers for Windows. +tar -xof "jbang-${MINIMAL_ARG_VERSION}.tar" +SRC="jbang-${MINIMAL_ARG_VERSION}" + +INSTALL="$OUTPUT_DIR/usr/share/jbang" +mkdir -p "$OUTPUT_DIR/usr/bin" "$INSTALL/bin" +install -m 0755 "$SRC/bin/jbang" "$INSTALL/bin/jbang" +install -m 0644 "$SRC/bin/jbang.jar" "$INSTALL/bin/jbang.jar" +install -m 0644 "$SRC/version.txt" "$INSTALL/version.txt" + +# Wrapper. The upstream launcher looks for a JDK in $JAVA_HOME, then javac +# on PATH, and only if both fail does it DOWNLOAD one from foojay.io into +# ~/.jbang. Point JAVA_HOME at the packaged jdk (unless the caller set one) +# so the download path is never taken. +cat > "$OUTPUT_DIR/usr/bin/jbang" << 'EOF' +#!/bin/sh +export JAVA_HOME="${JAVA_HOME:-/usr/lib/jvm}" +exec /usr/share/jbang/bin/jbang "$@" +EOF +chmod 0755 "$OUTPUT_DIR/usr/bin/jbang" + +# Fail closed if the bundle layout changes. +test -s "$INSTALL/bin/jbang.jar" +grep -qx "${MINIMAL_ARG_VERSION}" "$INSTALL/version.txt" From b690eb8a91546df6926311c8ddd1badd1c217291 Mon Sep 17 00:00:00 2001 From: bryan Date: Wed, 21 Oct 2026 17:15:29 -0700 Subject: [PATCH 2/2] jbang: wire JBANG_DIR to a session state dir jbang keeps its cache, compiled jars and downloaded JDKs in JBANG_DIR, which defaults to ~/.jbang. Co-Authored-By: Claude Opus 5.5 --- packages/jbang/build.ncl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/jbang/build.ncl b/packages/jbang/build.ncl index 725b0e331..0ef504bae 100644 --- a/packages/jbang/build.ncl +++ b/packages/jbang/build.ncl @@ -54,6 +54,12 @@ let version = "0.142.0" in upstream_version = version, license_spdx = "MIT", binary_from = "https://github.com/jbangdev/jbang/releases", + # jbang keeps its script cache, compiled jars and any downloaded JDKs in + # JBANG_DIR (default ~/.jbang, which a session may not be able to write). + env_state_wiring = { + env_var = "JBANG_DIR", + prefix = "jbang", + }, source_provenance = { category = 'GithubRepo, owner = "jbangdev",