-
Notifications
You must be signed in to change notification settings - Fork 7
/
pp.main
289 lines (251 loc) · 8.8 KB
/
pp.main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# Polypkg main
pp_version="1.0.0.$pp_revision"
pp_copyright="Copyright 2018, One Identity LLC. ALL RIGHTS RESERVED."
pp_opt_debug=false
pp_opt_destdir="$DESTDIR"
pp_opt_install_script=
pp_opt_list=false
pp_opt_no_clean=false
pp_opt_no_package=false
pp_opt_only_front=false
pp_opt_platform=
pp_opt_probe=false
pp_opt_strip=false
pp_opt_save_unstripped=false
pp_opt_vas_platforms=false
pp_opt_wrkdir="`pwd`/pp.work.$$"
pp_opt_verbose=false
pp_opt_version=false
pp_opt_input="-"
pp_opt_init_vars=""
pp_opt_eval=
test -n "$PP_NO_CLEAN" && pp_opt_no_clean=true
test -n "$PP_DEBUG" && pp_opt_debug=true
test -n "$PP_VERBOSE" && pp_opt_verbose=true
#@ pp_main_cleanup(): calls backend cleanup and removes $pp_wrkdir
pp_main_cleanup () {
pp_debug "main_cleanup"
pp_remove_later_now
if $pp_opt_no_clean || test x"$pp_platform" = x"unknown"; then
: no cleanup
else
pp_backend_${pp_platform}_cleanup
$pp_errors && pp_die "Errors during cleanup"
if test -d "$pp_wrkdir"; then
if $pp_opt_debug; then
pp_debug "not removing $pp_wrkdir"
else
pp_verbose rm -rf "$pp_wrkdir"
fi
fi
fi
}
#@ pp_parseopts(args...): sets the $pp_opt_* variables from cmd line args
# exits on incorrect usage
pp_parseopts () {
typeset a n _var _val
while test $# -gt 0; do
# convert -[dilpv] to --long-options
case "$1" in
--?*=?*) n=`echo "$1" | sed -ne 's/^--\([^=]*\)=.*/\1/p'`
a=`echo "$1" | sed -ne 's/^--[^=]*=\(.*\)/\1/p'`
shift
set -- "--$n" "$a" "$@";;
--?*) : ;;
-d) shift; set -- "--debug" "$@";;
-d*) a=`echo "$1" | sed -ne 's/^-.//'`
shift; set -- "--debug" "$@";;
-i) shift; set -- "--install-script" "$@";;
-i*) a=`echo "$1" | sed -ne 's/^-.//'`
shift; set -- "--install-script" "$a" "$@";;
-l) shift; set -- "--list" "$@";;
-l*) a=`echo "$1" | sed -ne 's/^-.//'`
shift; set -- "--list" "$@";;
-p) shift; set -- "--platform" "$@";;
-p*) a=`echo "$1" | sed -ne 's/^-.//'`
shift; set -- "--platform" "$a" "$@";;
-v) shift; set -- "--verbose" "$@";;
-v*) a=`echo "$1" | sed -ne 's/^-.//'`
shift; set -- "--verbose" "$@";;
-\?) shift; set -- "--help" "$@";;
-\?*) a=`echo "$1" | sed -ne 's/^-.//'`
shift; set -- "--help" "$@";;
esac
case "$1" in
--destdir|--eval|--install-script|--platform|--wrkdir)
test $# -ge 2 || pp_error "missing argument to $1";;
esac
case "$1" in
--) shift;break;;
--debug) pp_opt_debug=true; shift;;
--destdir) pp_opt_destdir="$2"; shift;shift;;
--eval) pp_opt_eval="$2"; shift;shift;; # undoc
--install-script) pp_opt_install_script="$2"; shift;shift;;
--list) pp_opt_list=true; shift;;
--no-clean) pp_opt_no_clean=true; shift;;
--no-package) pp_opt_no_package=true; shift;;
--only-front) pp_opt_only_front=true; shift;;
--platform) pp_opt_platform="$2"; shift;shift;;
--probe) pp_opt_probe=true; shift;;
--strip) pp_opt_strip=true; shift;;
--save-unstripped) pp_opt_save_unstripped=true; shift;;
--wrkdir) pp_opt_wrkdir="$2"; shift;shift;;
--vas-platforms) pp_opt_vas_platforms=true; shift;;
--verbose) pp_opt_verbose=true; shift;;
--version) pp_opt_version=true; shift;;
--help) pp_errors=true; shift;;
-) break;;
-*) pp_error "unknown option $1"; shift;;
*) break;;
esac
done
pp_opt_input=-
if test $# -gt 0; then
pp_opt_input="$1"
shift
fi
#-- extra arguments of the form Foo=bar alter *global* vars
while test $# -gt 0; do
case "$1" in
-*) pp_error "unexpected option '$1'"
shift;;
*=*) _val="${1#*=}"
_var=${1%="$_val"}
_val=`echo "$_val"|sed -e 's/[$"\\]/\\&/g'`
pp_debug "setting $_var = \"$_val\""
pp_opt_init_vars="$pp_opt_init_vars$_var=\"$_val\";"
shift;;
*) pp_error "unexpected argument $1'"
shift;;
esac
done
test $# -gt 0 &&
pp_error "unknown argument $1"
if $pp_errors; then
cat <<. >&2
polypkg $pp_version $pp_copyright
usage: $0 [options] [input.pp] [var=value ...]
-d --debug -- write copious info to stderr
--destdir=path -- file root, defaults to \$DESTDIR
-? --help -- display this information
-i --install-script=path -- create an install helper script
-l --list -- write package filenames to stdout
--no-clean -- don't remove temporary files
--no-package -- do everything but create packages
--only-front -- only perform front-end actions
-p --platform=platform -- defaults to local platform
--probe -- print local system identifier, then exit
--strip -- strip debug symbols from binaries before
packaging (modifies files in destdir)
--save-unstripped -- save unstripped binaries to
\$name-\$version-unstripped.tar.gz
--wrkdir=path -- defaults to subdirectory of \$TMPDIR or /tmp
-v --verbose -- write info to stderr
--version -- display version and quit
.
exit 1
fi
}
#@ pp_drive(): drives the front-end, middle and backend
pp_drive () {
# initialise the front and back ends
pp_model_init
pp_frontend_init
$pp_opt_only_front || pp_backend_init
# run the front-end to generate the intermediate files
# set $pp_input_dir to be the 'include dir' if needed
pp_debug "calling frontend on $pp_opt_input"
case "$pp_opt_input" in
-) pp_input_dir=.
test -t 1<&0 &&
pp_warn "reading directives from standard input"
pp_frontend
;;
*/*) pp_input_dir=${pp_opt_input%/*}
pp_frontend <"$pp_opt_input"
;;
*) pp_input_dir=.
pp_frontend <"$pp_opt_input"
;;
esac
pp_files_ignore_others
pp_service_scan_groups
# some sanity checks after front-end processing
if test x"$pp_platform" != x"null"; then
pp_debug "sanity checks"
test -n "$pp_components" || pp_error "No components?"
pp_check_var_is_defined "name"
pp_check_var_is_defined "version"
pp_files_check_duplicates
pp_files_check_coverage
pp_die_if_errors "Errors during sanity checks"
fi
# stop now if we're only running the front
$pp_opt_only_front && return
if test x"$pp_opt_strip" = x"true"; then
pp_strip_binaries
fi
# run the back-end to generate the package
pp_debug "calling backend"
pp_backend
pp_die_if_errors "Errors during backend processing"
# copy the resulting package files to PP_PKGDESTDIR or .
for f in `pp_backend_names` -; do
test x"$f" = x"-" && continue
pp_debug "copying: $f to `pwd`"
if pp_verbose cp -r $pp_wrkdir/$f ${PP_PKGDESTDIR:-.}; then
echo "${PP_PKGDESTDIR:+$PP_PKGDESTDIR/}$f"
else
pp_error "$f: missing package"
fi
done
pp_die_if_errors "Errors during package copying"
}
#@ pp_install_script(): generate the install helper script
pp_install_script () {
pp_debug "writing install script to $pp_opt_install_script"
rm -f $pp_opt_install_script
pp_backend_install_script > $pp_opt_install_script
pp_die_if_errors "Errors during package install script"
chmod +x $pp_opt_install_script
}
#@ pp_main(): main driver function
pp_main () {
# If PP_DEV_PATH is set, then jump to that script.
# (Useful when working on polypkg source that isn't installed)
if test -n "$PP_DEV_PATH" -a x"$PP_DEV_PATH" != x"$0"; then
pp_warn "switching from $0 to $PP_DEV_PATH ..."
exec "$PP_DEV_PATH" "$@" || exit 1
fi
pp_set_expand_converter_or_reexec "$@"
pp_parseopts "$@"
if $pp_opt_version; then
#-- print version and exit
echo "polypkg $pp_version"
exit 0
fi
pp_set_platform
trap 'pp_main_cleanup' 0
pp_wrkdir="$pp_opt_wrkdir"
pp_debug "pp_wrkdir = $pp_wrkdir"
rm -rf "$pp_wrkdir"
mkdir -p "$pp_wrkdir"
pp_destdir="$pp_opt_destdir"
pp_debug "pp_destdir = $pp_destdir"
if $pp_opt_probe; then
pp_backend_init
pp_backend_probe
elif $pp_opt_vas_platforms; then
pp_backend_init
pp_backend_vas_platforms
elif test -n "$pp_opt_eval"; then
#-- execute a shell command
eval "$pp_opt_eval" || exit
else
pp_drive
if test -n "$pp_opt_install_script"; then
pp_install_script
fi
fi
exit 0
}