Debian Codegraph @

run-command

raw
1 #!/bin/bash
2 ###############################################################################
3 # BRLTTY - A background process providing access to the console screen (when in
4 # text mode) for a blind person using a refreshable braille display.
5 #
6 # Copyright (C) 1995-2026 by The BRLTTY Developers.
7 #
8 # BRLTTY comes with ABSOLUTELY NO WARRANTY.
9 #
10 # This is free software, placed under the terms of the
11 # GNU Lesser General Public License, as published by the Free Software
12 # Foundation; either version 2.1 of the License, or (at your option) any
13 # later version. Please see the file LICENSE-LGPL for details.
14 #
15 # Web Page: http://brltty.app/
16 #
17 # This software is maintained by Dave Mielke <[email protected]>.
18 ###############################################################################
19
20 . "$(dirname "${0}")/prologue.sh"
21 commandSubdirectory=Programs
22
23 handleInitialHelpOption "${@}" <<END-OF-HELP
24 Execute the specified command, with the specified arguments,
25 such that it picks up shared objects from the BRLTTY build tree.
26
27 Syntax: ${programName} {-h | command [argument ...]}
28
29 The current working directory must be somewhere within the build tree that's to be used.
30 If it isn't then the source tree will be used.
31 If the command is just a name, i.e. it doesn't contain a slash, then it's in the ${commandSubdirectory}/ subdirectory of the tree.
32
33 Environment Variables:
34 <COMMAND>_VALGRIND_DIRECTORY=path
35 If set then write a valgrind memory usage log to a file named
36 <command>-yyyymmdd-HHMMSS.vg in the specified directory.
37 END-OF-HELP
38
39 setBuildRoot
40
41 [ "${#}" -gt 0 ] || syntaxError "missing command"
42 commandPath="${1}"
43 shift 1
44
45 commandName="${commandPath##*/}"
46 [ "${commandPath}" = "${commandName}" ] && commandPath="${buildRoot}/${commandSubdirectory}/${commandPath}"
47 [ -e "${commandPath}" ] || semanticError "command not found: ${commandPath}"
48 [ -f "${commandPath}" ] || semanticError "not a file: ${commandPath}"
49 [ -x "${commandPath}" ] || semanticError "file not executable: ${commandPath}"
50 set -- "${commandPath}" "${@}"
51
52 [ -n "${LD_LIBRARY_PATH}" ] && LD_LIBRARY_PATH=":${LD_LIBRARY_PATH}"
53 export LD_LIBRARY_PATH="${buildRoot}/${commandSubdirectory}${LD_LIBRARY_PATH}"
54
55 variablePrefix="${commandName^^?}"
56 readonly variablePrefix="${variablePrefix//-/_}"
57
58 getVariable "${variablePrefix}_VALGRIND_DIRECTORY" vgDirectory
59 readonly vgDirectory
60
61 [ -n "${vgDirectory}" ] && {
62 [ -e "${vgDirectory}" ] || semanticError "directory not found: ${vgDirectory}"
63 [ -d "${vgDirectory}" ] || semanticError "not a directory: ${vgDirectory}"
64 [ -w "${vgDirectory}" ] || semanticError "directory not writable: ${vgDirectory}"
65
66 vgFile="${vgDirectory}/${commandName}-$(date +%Y%m%d-%H%M%S).vg"
67 programMessage "valgrind log: ${vgFile}"
68
69 set -- valgrind \
70 --log-file="${vgFile}" \
71 --leak-check=full \
72 --show-reachable=yes \
73 "${@}"
74 }
75
76 exec "${@}"
77 exit "${?}"