annotate sources/utility_functions.sh @ 1815:191dfad915ba draft

Fix from Geoff Salmon for hang (sha1sum reading stdin) when new gather_patches function returns nothing for a given package.
author Rob Landley <rob@landley.net>
date Wed, 18 Nov 2015 09:18:44 -0600
parents c654511d227c
children
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
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 # 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
6
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 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
8 {
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 # 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
10 [ -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
11 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
12
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 # 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
14 [ -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
15 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
16 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
17
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 # 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
19
1081
e992bc65b048 Remove unnecessary "function" label from shell functions.
Rob Landley <rob@landley.net>
parents: 1035
diff changeset
20 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
21 {
1815
191dfad915ba Fix from Geoff Salmon for hang (sha1sum reading stdin) when new gather_patches function returns nothing for a given package.
Rob Landley <rob@landley.net>
parents: 1624
diff changeset
22 sha1sum /dev/null "$@" | tail -n +2 | awk '{print $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
23 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
24
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 # 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
26 # (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
27
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 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
29 {
1161
eec0d43778cc Output dienow's error message to stderr.
Rob Landley <rob@landley.net>
parents: 1113
diff changeset
30 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
31 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
32 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
33
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 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
35 TOPSHELL=$$
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
36
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
37 dienow()
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
38 {
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
39 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
40 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
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
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
43 # 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
44 # 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
45
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
46 dotprogress()
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 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
49 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
50 do
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
51 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
52 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
53 then
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
54 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
55 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
56 fi
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
57 done
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
58 echo
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
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
61 # 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
62
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
63 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
64 {
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
65 # 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
66 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
67
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
68 # 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
69 [ -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
70 }
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 # 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
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 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
75 {
1113
e5ace7f9f4d4 More trouble than its worth for FORK and QUIET to be separate knobs.
Rob Landley <rob@landley.net>
parents: 1083
diff changeset
76 [ -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
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
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
79 # 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
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 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
82 {
1172
6766f92a6c61 Make BUILD_VERBOSE a little more verbose.
Rob Landley <rob@landley.net>
parents: 1161
diff changeset
83 [ -z "$BUILD_VERBOSE" ] || echo "$*"
6766f92a6c61 Make BUILD_VERBOSE a little more verbose.
Rob Landley <rob@landley.net>
parents: 1161
diff changeset
84
919
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
85 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
86 then
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
87 eval "$*"
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
88 else
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
89 eval "$*" &
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
90 fi
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
91 }
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
92
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
93 # 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
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 killtree()
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
96 {
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
97 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
98
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
99 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
100 do
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
101 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
102 shift
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
103 done
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
104
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
105 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
106 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
107 then
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
108 # 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
109 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
110 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
111 fi
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 # 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
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 # 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
117 # 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
118
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
119 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
120 {
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
121 # 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
122 # 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
123 # 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
124
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
125 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
126 do
1224
f0d7f84ec51a Dereference symlink path segments in record-commands.sh.
Rob Landley <rob@landley.net>
parents: 1211
diff changeset
127 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
128 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
129 do
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
130 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
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 # 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
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 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
135 done
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
136 done
8b69eeb17ebf Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff changeset
137 }
941
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
138
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
139 # 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
140
941
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
141 check_prerequisite()
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
142 {
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
143 if [ -z "$(which "$1")" ]
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
144 then
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
145 [ -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
146 dienow
941
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
147 fi
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
148 }
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
149
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
150 # 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
151 # identical files into hardlinks
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
152
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
153 collapse_hardlinks()
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
154 {
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
155 SHA1LIST=""
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
156 find "$1" -type f | while read FILE
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
157 do
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
158 echo "$FILE"
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
159 SHA1=$(sha1file "$FILE")
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
160 MATCH=$(echo "$SHA1LIST" | grep "^$SHA1")
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
161 if [ -z "$MATCH" ]
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
162 then
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
163 # 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
164 SHA1LIST="$SHA1LIST
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
165 $SHA1 $FILE"
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
166 else
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
167 FILE2="$(echo "$MATCH" | sed 's/[^ ]* //')"
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
168 cmp -s "$FILE" "$FILE2" || continue
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
169 ln -f "$FILE" "$FILE2" || dienow
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
170 fi
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
171 done
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
172 }
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
173
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
174 # 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
175
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
176 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
177 {
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
178 [ "$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
179 }