)]}'
{
  "commit": "f45c330acecd21cdd6731135facdf1f2368817bd",
  "tree": "b57c6fda89ede213465f01c99afead83ba7b9530",
  "parents": [
    "e3c75e909b0aa21b917196a17d6088f66edfcc73"
  ],
  "author": {
    "name": "UebelAndre",
    "email": "github@uebelandre.com",
    "time": "Mon Nov 16 02:30:22 2026 -0800"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Mon Nov 16 11:30:22 2026 +0100"
  },
  "message": "Added Posix Shell implementation of Runfiles. (#49)\n\nThis change adds `runfiles.sh`, the runfiles library in POSIX shell, and\nmakes `runfiles.bash` a thin wrapper that sources it. One implementation\nserves both the existing `bazel_tools/tools/bash/runfiles/runfiles.bash`\nsnippets and scripts that run under dash, ash or busybox sh. The public\nAPI is unchanged: `rlocation`, `runfiles_export_envvars`,\n`runfiles_current_repository` and `runfiles_rlocation_checked`.\n\n## Under bash\n\nNothing changes for callers. The caller\u0027s repository comes from\n`BASH_SOURCE`, the functions are exported with `export -f`, and the\n`use_bash_launcher` launcher keeps working.\n\n## Under any other shell\n\nEvery script sources the library itself, since functions cannot be\nexported across `exec`, and `runfiles_current_repository \"$0\"` takes the\nscript\u0027s path, since there is no `BASH_SOURCE`. A launcher that runs\nunder a non-bash `sh_toolchain` follows in #78.\n\n## Initialization snippet v4\n\nOne snippet body serves both entry points: it resolves the library\u0027s\nlocation before sourcing it instead of sourcing each candidate in turn,\nand aborts the script if the library fails to load rather than leaving\nit without `rlocation`. The bash and POSIX versions differ only in the\npath they look for and in `pipefail`, which not every shell has. The\nlauncher uses the bash one; v3 keeps working.\n\n## Performance\n\nLookups against a runfiles directory are one `stat`. Lookups against a\nmanifest use one `awk` process per lookup when awk is available (`AWK`\nnames the program), so the cost does not grow with the manifest; without\nawk, or with `RULES_SHELL_RUNFILES_USE_AWK\u003d0`, a shell loop searches\ninstead and nothing is forked. The snippets find the library the same\nway. `shell/runfiles/README.md` has the details and a table produced by\n`bazel run //tests/runfiles:benchmark`.\n\n## Compatibility\n\nThe library needs Bazel 7.4 for its root symlinks; on Bazel 7 the\n`//shell/runfiles` alias still resolves to Bazel\u0027s bundled library.\n\n---\n\n# Usage\n\n## 1. Depend on the runfiles library from your build rule\n\n```python\nsh_binary(\n    name \u003d \"my_binary\",\n    # ...\n    deps \u003d [\"@rules_shell//shell/runfiles\"],\n)\n```\n\n## 2. Source the runfiles library\n\nThe library defines `rlocation`, which you would need to look up its own\nlocation, so insert a snippet at the top of your main script. Bash\nscripts:\n\n```shell\n# --- begin runfiles.bash initialization v4 ---\n# Copy-pasted from the Bazel Bash runfiles library v4.\nset -uo pipefail; set +e; f\u003dbazel_tools/tools/bash/runfiles/runfiles.bash; _rf_p\u003d; _rf_a\u003d\nif [ -n \"${AWK:-}\" ] || [ \"${RULES_SHELL_RUNFILES_USE_AWK:-}\" !\u003d 0 ]; then _rf_a\u003d1; fi\n_rf_d() { [ -f \"$1/$f\" ] \u0026\u0026 _rf_p\u003d\"$1/$f\"; }\n_rf_m() { [ -f \"$1\" ] || return 1; if [ -n \"$_rf_a\" ]; then \\\n  _rf_p\u003d$(${AWK:-awk} -v k\u003d\"$f \" \u0027index($0,k)\u003d\u003d1{print substr($0,length(k)+1);m\u003d1;exit}END{exit !m}\u0027 \"$1\" 2\u003e/dev/null) \u0026\u0026 return; fi; \\\n  while IFS\u003d read -r _rf_l || [ -n \"$_rf_l\" ]; do \\\n  case \"$_rf_l\" in \"$f \"*) _rf_p\u003d\"${_rf_l#\"$f \"}\"; return;; esac; done \u003c \"$1\"; return 1; }\n_rf_d \"${RUNFILES_DIR:-/dev/null}\" || _rf_m \"${RUNFILES_MANIFEST_FILE:-/dev/null}\" || \\\n  _rf_d \"$0.runfiles\" || _rf_m \"$0.runfiles_manifest\" || _rf_m \"$0.exe.runfiles_manifest\" || \\\n  { echo\u003e\u00262 \"ERROR: cannot find $f\"; exit 1; }\n# shellcheck disable\u003dSC1090\n. \"$_rf_p\" || { echo\u003e\u00262 \"ERROR: cannot source $_rf_p\"; exit 1; }; f\u003d; unset -f _rf_d _rf_m; unset _rf_l _rf_p _rf_a; set -e\n# --- end runfiles.bash initialization v4 ---\n```\n\nPOSIX shell scripts:\n\n```shell\n# --- begin runfiles.sh initialization v4 ---\n# Copy-pasted from the Bazel POSIX shell runfiles library v4.\nset -u; set +e; f\u003drules_shell/shell/runfiles/runfiles.sh; _rf_p\u003d; _rf_a\u003d\nif [ -n \"${AWK:-}\" ] || [ \"${RULES_SHELL_RUNFILES_USE_AWK:-}\" !\u003d 0 ]; then _rf_a\u003d1; fi\n_rf_d() { [ -f \"$1/$f\" ] \u0026\u0026 _rf_p\u003d\"$1/$f\"; }\n_rf_m() { [ -f \"$1\" ] || return 1; if [ -n \"$_rf_a\" ]; then \\\n  _rf_p\u003d$(${AWK:-awk} -v k\u003d\"$f \" \u0027index($0,k)\u003d\u003d1{print substr($0,length(k)+1);m\u003d1;exit}END{exit !m}\u0027 \"$1\" 2\u003e/dev/null) \u0026\u0026 return; fi; \\\n  while IFS\u003d read -r _rf_l || [ -n \"$_rf_l\" ]; do \\\n  case \"$_rf_l\" in \"$f \"*) _rf_p\u003d\"${_rf_l#\"$f \"}\"; return;; esac; done \u003c \"$1\"; return 1; }\n_rf_d \"${RUNFILES_DIR:-/dev/null}\" || _rf_m \"${RUNFILES_MANIFEST_FILE:-/dev/null}\" || \\\n  _rf_d \"$0.runfiles\" || _rf_m \"$0.runfiles_manifest\" || _rf_m \"$0.exe.runfiles_manifest\" || \\\n  { echo\u003e\u00262 \"ERROR: cannot find $f\"; exit 1; }\n# shellcheck disable\u003dSC1090\n. \"$_rf_p\" || { echo\u003e\u00262 \"ERROR: cannot source $_rf_p\"; exit 1; }; f\u003d; unset -f _rf_d _rf_m; unset _rf_l _rf_p _rf_a; set -e\n# --- end runfiles.sh initialization v4 ---\n```\n\n## 3. Use `rlocation` to look up runfile paths\n\n```shell\ncat \"$(rlocation my_workspace/path/to/my/data.txt)\"\n```\n\n---------\n\nCo-authored-by: Fabian Meumertzheim \u003cfabian@meumertzhe.im\u003e",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "6bec8738f35e4be83b32a0c5401353ddb171a452",
      "old_mode": 33188,
      "old_path": ".bazelci/presubmit.yml",
      "new_id": "8b59eaf5f102f648478fe8445fec04b698165166",
      "new_mode": 33188,
      "new_path": ".bazelci/presubmit.yml"
    },
    {
      "type": "modify",
      "old_id": "f0aafac0235a873c9aed31a6806d1f4d6a38b5ed",
      "old_mode": 33188,
      "old_path": ".bcr/presubmit.yml",
      "new_id": "a25822ccbbbf9cff7fc722ee5c15b6d36a8dc2fb",
      "new_mode": 33188,
      "new_path": ".bcr/presubmit.yml"
    },
    {
      "type": "modify",
      "old_id": "4fa13cb2eb8782585903dd69d3c4431e916b7a89",
      "old_mode": 33188,
      "old_path": "MODULE.bazel",
      "new_id": "fa509eadca11a3f8c960d629f4110e8dd78d0596",
      "new_mode": 33188,
      "new_path": "MODULE.bazel"
    },
    {
      "type": "modify",
      "old_id": "dba20d9c6b5cf89c8b7f16610538a8de3dc0216f",
      "old_mode": 33188,
      "old_path": "shell/private/sh_executable.bzl",
      "new_id": "d16183dc4d850f3e46fa90344d3f7811774a2a47",
      "new_mode": 33188,
      "new_path": "shell/private/sh_executable.bzl"
    },
    {
      "type": "modify",
      "old_id": "63e6feeddc0d1a4fdfc94da7d24fa1f46c1bc9bb",
      "old_mode": 33188,
      "old_path": "shell/runfiles/BUILD",
      "new_id": "d936f4e876db1076f27e9a79ee12a7bd18918bb1",
      "new_mode": 33188,
      "new_path": "shell/runfiles/BUILD"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "6dba3e39b16c52f5436a7c5d82c4b0a081f4ebba",
      "new_mode": 33188,
      "new_path": "shell/runfiles/README.md"
    },
    {
      "type": "modify",
      "old_id": "5b08416e10d267fe79b6234cac2d040d55d85755",
      "old_mode": 33188,
      "old_path": "shell/runfiles/runfiles.bash",
      "new_id": "8ece2a0e1a58a25d70479f0cc112ec47c9166ea4",
      "new_mode": 33188,
      "new_path": "shell/runfiles/runfiles.bash"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "93660cf69c896afb39fa15f44730c28b6db27188",
      "new_mode": 33188,
      "new_path": "shell/runfiles/runfiles.sh"
    },
    {
      "type": "modify",
      "old_id": "ce37244c8d2c5bfa1b88cb6631bb2103d8e2a221",
      "old_mode": 33261,
      "old_path": "tests/bcr/test.sh",
      "new_id": "4160dde53cf8e4e2da834422917081ff4dea4e0a",
      "new_mode": 33261,
      "new_path": "tests/bcr/test.sh"
    },
    {
      "type": "modify",
      "old_id": "0e1d4c4a07a21b69566dd8f0f633c37a91cc5ce0",
      "old_mode": 33188,
      "old_path": "tests/runfiles/BUILD",
      "new_id": "f641c507fab3e5ce4d6fca7cbb33c82d6b2d2d2c",
      "new_mode": 33188,
      "new_path": "tests/runfiles/BUILD"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "791e4f30eced0cc420262ed78fab49cec99b8380",
      "new_mode": 33261,
      "new_path": "tests/runfiles/benchmark.sh"
    },
    {
      "type": "modify",
      "old_id": "fd11d97a6d43be913766e4f743e711c9ed19c639",
      "old_mode": 33261,
      "old_path": "tests/runfiles/runfiles_test.bash",
      "new_id": "c4daf4ad396317e9f38a6176aa0554f3590f4afa",
      "new_mode": 33261,
      "new_path": "tests/runfiles/runfiles_test.bash"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "671f39a778a21f690990ccc96d2d250907c98a4c",
      "new_mode": 33261,
      "new_path": "tests/runfiles/runfiles_test.sh"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "f3b0f237251f4720ae18d344cfded87207374f93",
      "new_mode": 33261,
      "new_path": "tests/runfiles/runfiles_test_under_bash.sh"
    }
  ]
}
