annotate sources/utility_functions.sh @ 1376:a6d18adf198d

Added tag 1.0.2 for changeset a9685aea2a2c
author Rob Landley <rob@landley.net>
date Tue, 14 Jun 2011 20:48:07 -0500
parents 9252453c40d0
children e26390768b3c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
919
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 #!/bin/echo "This file is sourced, not run"
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
2
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 # This file contains generic functions, presumably reusable in other contexts.
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
4
1175
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
5 # Unset all environment variables that we don't know about, in case some crazy
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
6 # person already exported $CROSS_COMPILE, $ARCH, $CDPATH, or who knows what
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
7 # else. It's hard to know what might drive some package crazy, so use a
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
8 # whitelist.
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
9
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
10 sanitize_environment()
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
11 {
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
12 # Which variables are set in config?
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
13
1179
c364e01dcdc6 Make the environment sanitize logic slightly more robust in the face of multi-line environment variable values.
Rob Landley <rob@landley.net>
parents: 1175
diff changeset
14 TEMP=$(echo $(sed -n 's/.*export[ \t]*\([^=]*\)=.*/\1/p' config) | sed 's/ /,/g')
1175
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
15
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
16 # What other variables should we keep?
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
17
1211
e0c2ba5cc233 If environment sanitizing lets TOOLCHAIN_PREFIX through, it should let HOST_ARCH through too. And while we're at it, separate inherited variables from locally defined ones.
Rob Landley <rob@landley.net>
parents: 1207
diff changeset
18 TEMP="$TEMP,LANG,PATH,SHELL,TERM,USER,USERNAME,LOGNAME,PWD,EDITOR,HOME,DISPLAY,_"
e0c2ba5cc233 If environment sanitizing lets TOOLCHAIN_PREFIX through, it should let HOST_ARCH through too. And while we're at it, separate inherited variables from locally defined ones.
Rob Landley <rob@landley.net>
parents: 1207
diff changeset
19 TEMP="$TEMP,TOPSHELL,START_TIME,STAGE_NAME,TOOLCHAIN_PREFIX,HOST_ARCH"
1175
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
20
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
21 # Unset any variable we don't recognize. It can screw up the build.
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
22
1179
c364e01dcdc6 Make the environment sanitize logic slightly more robust in the face of multi-line environment variable values.
Rob Landley <rob@landley.net>
parents: 1175
diff changeset
23 for i in $(env | sed -n 's/=.*//p')
1175
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
24 do
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
25 is_in_list $i "$TEMP" && continue
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
26 [ "${i:0:7}" == "DISTCC_" ] && continue
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
27 [ "${i:0:7}" == "CCACHE_" ] && continue
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
28
1179
c364e01dcdc6 Make the environment sanitize logic slightly more robust in the face of multi-line environment variable values.
Rob Landley <rob@landley.net>
parents: 1175
diff changeset
29 unset $i 2>/dev/null
1175
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
30 done
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
31 }
886a2ea90bc1 Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents: 1172
diff changeset
32
984
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
33 # Assign (export) a variable only if current value is blank
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
34
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
35 export_if_blank()
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
36 {
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
37 [ -z "$(eval "echo \"\${${1/=*/}}\"")" ] && export "$1"
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
38 }
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
39
919
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
40 # Create a blank directory at first argument, deleting existing contents if any
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
41
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 blank_tempdir()
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
43 {
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
44 # sanity test: never rm -rf something we don't own.
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
45 [ -z "$1" ] && dienow
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
46 touch -c "$1" || dienow
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
47
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
48 # Delete old directory, create new one.
1035
a3716680a825 NO_CLEANUP should prevent blank_tempdir from deleting stuff.
Rob Landley <rob@landley.net>
parents: 984
diff changeset
49 [ -z "$NO_CLEANUP" ] && rm -rf "$1"
919
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
50 mkdir -p "$1" || dienow
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
51 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
52
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
53 # output the sha1sum of a file
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
54
1081
e992bc65b048 Remove unnecessary "function" label from shell functions.
Rob Landley <rob@landley.net>
parents: 1035
diff changeset
55 sha1file()
919
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
56 {
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
57 sha1sum "$@" | awk '{print $1}'
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
58 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
59
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
60 # dienow() is an exit function that works properly even from a subshell.
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
61 # (actually_dienow is run in the parent shell via signal handler.)
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
62
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
63 actually_dienow()
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
64 {
1161
eec0d43778cc Output dienow's error message to stderr.
Rob Landley <rob@landley.net>
parents: 1113
diff changeset
65 echo -e "\n\e[31mExiting due to errors ($ARCH_NAME $STAGE_NAME $PACKAGE)\e[0m" >&2
919
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
66 exit 1
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
67 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
68
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
69 trap actually_dienow SIGUSR1
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
70 TOPSHELL=$$
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
71
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
72 dienow()
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
73 {
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
74 kill -USR1 $TOPSHELL
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
75 exit 1
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
76 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
77
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
78 # Turn a bunch of output lines into a much quieter series of periods,
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
79 # roughly one per screenfull
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
80
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
81 dotprogress()
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
82 {
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
83 x=0
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
84 while read i
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
85 do
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
86 x=$[$x + 1]
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
87 if [[ "$x" -eq 25 ]]
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
88 then
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
89 x=0
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
90 echo -n .
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
91 fi
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
92 done
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
93 echo
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
94 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
95
1358
9252453c40d0 Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
96 # Announce an action to the world
919
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
97
1358
9252453c40d0 Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
98 announce()
919
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
99 {
1358
9252453c40d0 Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
100 # Write a line to the log file with easily greppable header
9252453c40d0 Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
101 echo "=== $1 ($ARCH_NAME $STAGE_NAME)"
9252453c40d0 Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
102
9252453c40d0 Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
103 # Set the title bar of the current xterm
9252453c40d0 Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
104 [ -z "$NO_TITLE_BAR" ] && echo -en "\033]2;$ARCH_NAME $STAGE_NAME $1\007"
919
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
105 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
106
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
107 # Filter out unnecessary noise, keeping just lines starting with "==="
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
108
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
109 maybe_quiet()
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
110 {
1113
e5ace7f9f4d4 More trouble than its worth for FORK and QUIET to be separate knobs.
Rob Landley <rob@landley.net>
parents: 1083
diff changeset
111 [ -z "$FORK" ] && cat || grep "^==="
919
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
112 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
113
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
114 # Run a command background if FORK is set, in foreground otherwise
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
115
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
116 maybe_fork()
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
117 {
1172
6766f92a6c61 Make BUILD_VERBOSE a little more verbose.
Rob Landley <rob@landley.net>
parents: 1161
diff changeset
118 [ -z "$BUILD_VERBOSE" ] || echo "$*"
6766f92a6c61 Make BUILD_VERBOSE a little more verbose.
Rob Landley <rob@landley.net>
parents: 1161
diff changeset
119
919
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
120 if [ -z "$FORK" ]
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
121 then
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
122 eval "$*"
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
123 else
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
124 eval "$*" &
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
125 fi
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
126 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
127
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
128 # Kill a process and all its decendants
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
129
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
130 killtree()
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
131 {
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
132 local KIDS=""
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
133
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
134 while [ $# -ne 0 ]
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
135 do
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
136 KIDS="$KIDS $(pgrep -P$1)"
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
137 shift
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
138 done
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
139
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
140 KIDS="$(echo -n $KIDS)"
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
141 if [ ! -z "$KIDS" ]
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
142 then
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
143 # Depth first kill avoids reparent_to_init hiding stuff.
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
144 killtree $KIDS
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
145 kill $KIDS 2>/dev/null
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
146 fi
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
147 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
148
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
149 # Search a colon-separated path for files matching a pattern.
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
150
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
151 # Arguments are 1) path to search, 2) pattern, 3) command to run on each file.
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
152 # During command, $DIR/$FILE points to file found.
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
153
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
154 path_search()
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
155 {
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
156 # For each each $PATH element, loop through each file in that directory,
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
157 # and create a symlink to the wrapper with that name. In the case of
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
158 # duplicates, keep the first one.
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
159
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
160 echo "$1" | sed 's/:/\n/g' | while read DIR
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
161 do
1224
f0d7f84ec51a Dereference symlink path segments in record-commands.sh.
Rob Landley <rob@landley.net>
parents: 1211
diff changeset
162 find "$DIR/" -maxdepth 1 -mindepth 1 -name "$2" | sed 's@.*/@@' | \
919
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
163 while read FILE
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
164 do
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
165 eval "$3"
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
166
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
167 # Output is verbose. Pipe it to dotprogress.
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
168
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
169 echo $FILE
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
170 done
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
171 done
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
172 }
941
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
173
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
174 # Abort if we haven't got a prerequisite in the $PATH
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
175
941
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
176 check_prerequisite()
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
177 {
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
178 if [ -z "$(which "$1")" ]
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
179 then
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
180 [ -z "$FAIL_QUIET" ] && echo No "$1" in '$PATH'. >&2
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
181 dienow
941
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
182 fi
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
183 }
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
184
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
185 # Search through all the files under a directory and collapse together
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
186 # identical files into hardlinks
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
187
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
188 collapse_hardlinks()
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
189 {
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
190 SHA1LIST=""
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
191 find "$1" -type f | while read FILE
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
192 do
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
193 echo "$FILE"
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
194 SHA1=$(sha1file "$FILE")
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
195 MATCH=$(echo "$SHA1LIST" | grep "^$SHA1")
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
196 if [ -z "$MATCH" ]
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
197 then
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
198 # Yes, the quote spanning two lines here is intentional
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
199 SHA1LIST="$SHA1LIST
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
200 $SHA1 $FILE"
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
201 else
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
202 FILE2="$(echo "$MATCH" | sed 's/[^ ]* //')"
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
203 cmp -s "$FILE" "$FILE2" || continue
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
204 ln -f "$FILE" "$FILE2" || dienow
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
205 fi
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
206 done
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
207 }
1082
255488af0bbb Convert unstable() to is_in_list() taking the list to check as the second argument.
Rob Landley <rob@landley.net>
parents: 1081
diff changeset
208
255488af0bbb Convert unstable() to is_in_list() taking the list to check as the second argument.
Rob Landley <rob@landley.net>
parents: 1081
diff changeset
209 # Check if $1 is in the comma separated list $2
255488af0bbb Convert unstable() to is_in_list() taking the list to check as the second argument.
Rob Landley <rob@landley.net>
parents: 1081
diff changeset
210
255488af0bbb Convert unstable() to is_in_list() taking the list to check as the second argument.
Rob Landley <rob@landley.net>
parents: 1081
diff changeset
211 is_in_list()
255488af0bbb Convert unstable() to is_in_list() taking the list to check as the second argument.
Rob Landley <rob@landley.net>
parents: 1081
diff changeset
212 {
1083
cb4dbdb7f2cd Make BUILD_STATIC take comma separated list of packages, or "all" or "none". Default behavior should remain the same.
Rob Landley <rob@landley.net>
parents: 1082
diff changeset
213 [ "$2" == all ] || [ ! -z "$(echo ,"$2", | grep ,"$1",)" ]
1082
255488af0bbb Convert unstable() to is_in_list() taking the list to check as the second argument.
Rob Landley <rob@landley.net>
parents: 1081
diff changeset
214 }