/
mulle-project-properties-plist
executable file
·616 lines (478 loc) · 12.1 KB
/
mulle-project-properties-plist
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
#! /usr/bin/env mulle-bash
# shellcheck shell=bash
[ "${TRACE}" = 'YES' -o "${MULLE_PROJECT_PACMAN_TRACE}" = 'YES' ] && set -x && : "$0" "$@"
MULLE_EXECUTABLE_VERSION="0.0.1"
if [ -z "${MULLE_PROJECT_LIBEXEC_DIR}" ]
then
r_get_libexec_dir "${MULLE_EXECUTABLE}" "mulle-project" "mulle-project-git.sh"
MULLE_PROJECT_LIBEXEC_DIR="${RVAL}"
fi
print_flags()
{
echo " --mulle : add some mulle hacks"
options_technical_flags_usage \
" : "
}
usage()
{
[ $# -ne 0 ] && log_error "$*"
cat <<EOF >&2
Usage:
${MULLE_USAGE_NAME} [flags]
Create a "properties.plist" file for mulle-template-composer and
mulle-readme-make.
Flags:
EOF
print_flags | LC_ALL=C sort >&2
exit 1
}
read_project_environment()
{
log_entry "read_project_environment" "$@"
if [ -f ".mulle/etc/env/environment-project.sh" ]
then
log_fluff "Reading project settings"
. ".mulle/etc/env/environment-project.sh"
fi
if [ -z "${PROJECT_TYPE}" ]
then
if [ -f ".mulle/share/env/environment-project.sh" ]
then
log_fluff "Reading v2 project settings"
. ".mulle/share/env/environment-project.sh"
fi
fi
}
get_url()
{
log_entry "get_url" "$@"
local repository
local known_domains
known_domains="`mulle-domain -s list`"
local scheme domain host scm user repo branch tag
local remote
.for remote in `git remote 2> /dev/null`
.do
url="`git remote get-url "${remote}"`"
# check if known domain
if ! eval "`mulle-domain -s parse-url "${url}"`"
then
.continue
fi
if find_line "${known_domains}" "${domain}"
then
repository="`mulle-domain -s compose-url --domain "${domain}" \
--scm "none" \
--user "${user}" \
--repo "${repo}" \
--tag "${tag}" `"
.break
fi
.done
if [ -z "${repository}" ]
then
r_basename "${PWD}"
name="${RVAL}"
r_dirname "${PWD}"
r_basename "${RVAL}"
user="${RVAL}"
repository="https://github.com/${user}/${name}"
fi
echo "${repository}"
}
get_homepage()
{
log_entry "get_homepage" "$@"
if [ ! -z "${PROJECT_HOMEPAGE}" ]
then
echo "${PROJECT_HOMEPAGE}"
return 0
fi
get_url
}
get_projectname()
{
if [ -z "${PROJECT_NAME}" ]
then
PROJECT_NAME="`mulle-sde -s env get PROJECT_NAME 2> /dev/null`"
if [ -z "${PROJECT_NAME}" ]
then
r_basename "${PWD}"
PROJECT_NAME="${RVAL}"
fi
fi
PROJECT_NAME="${PROJECT_NAME:-unknown}"
printf "%s\n" "${PROJECT_NAME}"
}
get_organization()
{
if [ -z "${ORGANIZATION}" ]
then
ORGANIZATION="`mulle-sde -s env get PROJECT_ORGANIZATION 2> /dev/null`"
if [ -z "${ORGANIZATION}" ]
then
r_dirname "${PWD}"
r_basename "${RVAL}"
if [ "${OPTION_MULLE}" = 'YES' ]
then
case "${RVAL}" in
srcS)
RVAL="mulle-sde"
;;
src?)
RVAL="mulle-nat"
;;
esac
fi
ORGANIZATION="${RVAL}"
fi
fi
ORGANIZATION="${ORGANIZATION:-${GITHUB_USER:-mulle-nat}}"
printf "%s\n" "${ORGANIZATION}"
}
get_description_4()
{
rexekutor head -4 "$1" \
| grep -E '^####' \
| head -1 \
| tr -d $'\r' \
| sed -e 's/^####//' -e 's/^ //g'
}
get_description_2()
{
rexekutor sed -e '/^[[:space:]]*$/d' "$1" \
| head -2 \
| tr -d $'\r' \
| tail -1
}
get_readme_description()
{
local filename="${1:-README.md}"
if [ ! -f "${filename}" ]
then
return 1
fi
if ! get_description_4 "${filename}"
then
get_description_2 "${filename}"
fi
}
get_description()
{
log_entry "get_description" "$@"
if [ ! -z "${DESC}" ]
then
printf "%s\n" "${DESC}"
else
get_readme_description
fi
}
find_description()
(
log_entry "find_description" "$@"
local projectname="$1"
local item
local filename
if [ -z "${MULLE_FETCH_SEARCH_PATH}" ]
then
MULLE_FETCH_SEARCH_PATH="`mulle-sde env get MULLE_FETCH_SEARCH_PATH`"
fi
log_debug "MULLE_FETCH_SEARCH_PATH: ${MULLE_FETCH_SEARCH_PATH}"
# hack (?) for amalgamated clib dependencies
case "${projectname}" in
*@*)
projectname="${projectname%%@*}"
;;
esac
.foreachpath item in ${MULLE_FETCH_SEARCH_PATH}
.do
r_filepath_concat "${item}" "${projectname}" "README.md"
filename="${RVAL}"
# MEMO: too oldschool, should look into properties
if get_readme_description "${filename}"
then
.break
fi
.done
)
get_license_text()
{
log_entry "get_license_text" "$@"
if [ -f LICENSE ]
then
head -1 LICENSE
else
if [ -f LICENSE.txt ]
then
head -1 LICENSE.txt
fi
fi
}
get_license()
{
log_entry "get_license" "$@"
local line
# grep LICENSE.txt
line="`get_license_text`"
case "${line}" in
*BSD*3*)
echo "BSD-3-Clause"
;;
*)
echo "UNLICENSED" # dunno
;;
esac
}
print_license()
{
log_entry "print_license" "$@"
RVAL="`get_license`"
r_escaped_singlequotes "${RVAL}"
printf "license=('%s')\n" "${RVAL}"
}
print_homepage()
{
log_entry "print_homepage" "$@"
printf "%s\n" " homepage=\"`get_homepage`\";"
}
#search_plist()
#{
# local plistname="$1"
# local sep="$2"
#
# local item
# local searchpath
#
# r_colon_concat "." "${MULLE_TEMPLATE_COMPOSER_SEARCHPATH}"
# searchpath="${RVAL}"
#
# .foreachpath item in ${searchpath}
# .do
# r_filepath_concat "${item}" "${plistname}.plist"
# if [ -f "${RVAL}" ]
# then
# log_verbose "Found plist \"${RVAL}\""
# printf "%s%s" "`cat "${RVAL}"`" "${sep}"
# return 0
# fi
# .done
#
# return 1
#}
print_project()
{
local sep="$1"
# if search_plist "project" "${sep}"
# then
# return
# fi
cat <<EOF
project =
{
description="${PROJECT_DESCRIPTION:-`get_description`}";
domain="${PROJECT_DOMAIN:-github}";
name="${PROJECT_NAME:-`get_projectname`}";
user="${PROJECT_ORGANIZATION:-`get_organization`}";
repo="${PROJECT_NAME:-`get_projectname`}";
EOF
print_homepage
cat <<EOF
license="${PROJECT_LICENSE:-`get_license`}";
}${sep}
EOF
}
print_dependencies()
{
log_entry "print_dependencies" "$@"
local title="$1"
local sep="$2"
local qualifier="$3"
# if search_plist "dependencies" "${sep}"
# then
# return
# fi
if [ ! -d .mulle/etc/sourcetree -a ! -d .mulle/share/sourcetree ]
then
return
fi
local lines
# ignore embedded
lines=`rexekutor mulle-sde ${MULLE_TECHNICAL_FLAGS} \
${MULLE_SDE_FLAGS} \
dependency list --columnar \
-- \
--dedupe-mode url-filename \
--qualifier "${qualifier}" \
--output-eval \
--output-no-column \
--output-no-header \
--force-format "%a;%u\\n"` || exit 1
if [ -z "${lines}" ]
then
return
fi
printf "${title} =\n("
local name
local url
local line
local sep2
local scheme domain host scm user repo branch tag
local repo_url
local description
sep2=$'\n'
.foreachline line in ${lines}
.do
printf "${sep2} {\n"
name="${line%%;*}"
url="${line#*;}"
eval "`mulle-domain -s parse-url "${url}"`"
repo_url="`mulle-domain -s compose-url --domain "${domain}" \
--scm "none" \
--user "${user}" \
--repo "${repo}" `"
description="`find_description "${repo}" `"
if [ ! -z "${description}" ]
then
r_escaped_doublequotes "${description}"
printf " description=\"%s\";\n" "${RVAL}"
fi
r_escaped_doublequotes "${domain}"
printf " domain=\"%s\";\n" "${RVAL}"
r_escaped_doublequotes "${name}"
printf " name=\"%s\";\n" "${RVAL}"
r_escaped_doublequotes "${repo:-${name}}"
printf " repo=\"%s\";\n" "${RVAL}"
r_escaped_doublequotes "${repo_url:-${url}}"
printf " url=\"%s\";\n" "${RVAL}"
r_escaped_doublequotes "${user}"
printf " user=\"%s\";\n" "${RVAL}"
printf " }"
sep2=$',\n'
.done
printf "\n)${sep}\n"
}
_print_plist()
{
log_entry "_print_plist" "$@"
local qualifier="$1"
local amalgamated_qualifier="$2"
local embedded_qualifier="$3"
print_project ';'
print_dependencies 'dependencies' ';' "${qualifier}"
if [ ! -z "${amalgamated_qualifier}" ]
then
print_dependencies 'amalgamated' ';' "${amalgamated_qualifier}"
fi
if [ ! -z "${embedded_qualifier}" ]
then
print_dependencies 'embedded' ';' "${embedded_qualifier}"
fi
}
print_plist()
{
log_entry "print_plist" "$@"
printf '{\n'
_print_plist "$@" | sed 's/^/ /'
printf '}\n'
}
main()
{
local OPTION_OUTPUT_FILE="-"
local OPTION_CHECKSUM='YES'
local OPTION_MULLE='NO'
local OPTION_QUALIFIER='MATCHES share AND MATCHES build'
local OPTION_AMALGAMATED_QUALIFIER='NOT MATCHES share-shirk AND NOT MATCHES build'
local OPTION_EMBEDDED_QUALIFIER='MATCHES share-shirk AND NOT MATCHES build'
MULLE_TEMPLATE_COMPOSER_SEARCHPATH="${MULLE_TEMPLATE_COMPOSER_SEARCHPATH:-\
"includes\
:../includes\
:../../includes\
"}"
#
# simple flag handling
#
while [ $# -ne 0 ]
do
if options_technical_flags "$1"
then
shift
continue
fi
case "$1" in
-f|--force)
MULLE_FLAG_MAGNUM_FORCE='YES'
;;
-h*|--help|help)
usage
;;
--I)
[ $# -eq 1 ] && fail "Missing argument to \"$1\""
shift
MULLE_TEMPLATE_COMPOSER_SEARCHPATH="$1"
;;
--mulle)
OPTION_MULLE='YES'
if [ "${OPTION_AUTHOR}" = 'DEFAULT' ]
then
OPTION_AUTHOR='YES'
fi
;;
-o|--output-file)
[ $# -eq 1 ] && fail "Missing argument to \"$1\""
shift
OPTION_OUTPUT_FILE="$1"
;;
-q|--qualifier)
[ $# -eq 1 ] && fail "Missing argument to \"$1\""
shift
OPTION_QUALIFIER="$1"
;;
--amalgamated-qualifier)
[ $# -eq 1 ] && fail "Missing argument to \"$1\""
shift
OPTION_AMALGAMATED_QUALIFIER="$1"
;;
--embedded-qualifier)
[ $# -eq 1 ] && fail "Missing argument to \"$1\""
shift
OPTION_EMBEDDED_QUALIFIER="$1"
;;
--no-amalgamated)
OPTION_AMALGAMATED_QUALIFIER=""
;;
--no-embedded)
OPTION_EMBEDDED_QUALIFIER=""
;;
--version)
printf "%s\n" "${MULLE_EXECUTABLE_VERSION}"
exit 0
;;
-*)
usage "Unknown flag \"$1\""
;;
*)
break
;;
esac
shift
done
options_setup_trace "${MULLE_TRACE}" && set -x
read_project_environment
if [ -f .mulle/etc/project/formula-info.sh ]
then
. .mulle/etc/project/formula-info.sh
fi
local text
if [ "${OPTION_OUTPUT_FILE}" = '-' ]
then
print_plist "${OPTION_QUALIFIER}" \
"${OPTION_AMALGAMATED_QUALIFIER}" \
"${OPTION_EMBEDDED_QUALIFIER}"
else
text="`print_plist "${OPTION_QUALIFIER}" \
"${OPTION_AMALGAMATED_QUALIFIER}" \
"${OPTION_EMBEDDED_QUALIFIER}" `" || return 1
redirect_exekutor "${OPTION_OUTPUT_FILE}" echo "${text}"
fi
}
call_with_flags "main" "${MULLE_PROJECT_PACMAN_FLAGS}" "$@"