blob: 400ab828ad7ccb0e493097f9e351b48c54954af7 [file] [log] [blame]
Philipp Schrader41011a12022-03-13 12:49:32 -07001load("@bazel_skylib//rules:write_file.bzl", "write_file")
2
3TEMPLATE = """\
4#!/bin/bash
5
6# --- begin runfiles.bash initialization v2 ---
7# Copy-pasted from the Bazel Bash runfiles library v2.
8set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
9source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
10 source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
11 source "$0.runfiles/$f" 2>/dev/null || \
12 source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
13 source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
14 { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
15# --- end runfiles.bash initialization v2 ---
16
17add_ld_library_path_for() {
18 local file="$1"
19 local dir
20 local resolved_file
21 if ! resolved_file="$(rlocation "postgresql_amd64/$file")"; then
22 echo "Couldn't find file postgresql_amd64/${file}" >&2
23 exit 1
24 fi
25 dir="$(dirname "${resolved_file}")"
26 export LD_LIBRARY_PATH="${dir}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
27}
28
29add_ld_library_path_for usr/lib/x86_64-linux-gnu/libbsd.so.0.11.3
30add_ld_library_path_for lib/x86_64-linux-gnu/libreadline.so.8.1
31
32exec $(rlocation postgresql_amd64/usr/lib/postgresql/13/bin/%s) "$@"
33"""
34
35[(
36 write_file(
37 name = "generate_%s_wrapper" % binary,
38 out = "%s.sh" % binary,
39 content = [TEMPLATE % binary],
40 ),
41 sh_binary(
42 name = binary,
43 srcs = ["%s.sh" % binary],
44 data = glob([
45 "usr/lib/**/*",
46 "lib/**/*",
47 ]),
48 visibility = ["//visibility:public"],
49 deps = [
50 "@bazel_tools//tools/bash/runfiles",
51 ],
52 ),
53) for binary in (
54 "postgres",
Philipp Schrader4fb10da2022-03-18 20:22:33 -070055 "psql",
Philipp Schrader41011a12022-03-13 12:49:32 -070056 "initdb",
57)]