@@ -273,6 +273,9 @@ path_basename() {
273
273
# we avoid use `dirname -- ${1}`, because it's too slow
274
274
path_directory () {
275
275
local path=" ${1} "
276
+ if test_z " ${path} " ; then
277
+ raise " invalid empty path in path_directory()."
278
+ fi
276
279
local oldifs=" ${IFS} "
277
280
IFS=' /'
278
281
set -- ${path}
@@ -317,42 +320,59 @@ path_is_absolute() {
317
320
318
321
# get relative path, e.g $(path_relative ${rootdir} ${absolute_path}`
319
322
path_relative () {
320
- local source=$1
321
- local target=$2
323
+ local source=" ${1} "
324
+ local target=" ${2} "
325
+ if test_z " ${source} " || test_z " ${target} " ; then
326
+ raise " invalid empty path in path_relative()"
327
+ fi
328
+
329
+ # patch missing "./"
330
+ source=${source# ./ }
331
+ source=${source# .}
332
+ target=${target# ./ }
333
+ target=${target# .}
334
+ if test_z " ${source} " ; then
335
+ _ret=" ${target} "
336
+ return
337
+ fi
322
338
323
- local common_part= $source
339
+ # find common path
324
340
local result=" "
325
-
341
+ local common_part= $source
326
342
while test_eq " ${target# $common_part } " " ${target} " ; do
327
343
# no match, means that candidate common part is not correct
328
344
# go up one level (reduce common part)
329
345
path_directory " ${common_part} " ; common_part=" ${_ret} "
330
346
# and record that we went back, with correct / handling
331
- if test_z $ result; then
347
+ if test_z " ${ result} " ; then
332
348
result=" .."
333
349
else
334
- result=" ../$result "
350
+ result=" ../${ result} "
335
351
fi
336
352
done
337
353
338
- if test_eq $ common_part " /" ; then
354
+ if test_eq " ${ common_part} " " /" ; then
339
355
# special case for root (no common path)
340
- result=" $result /"
356
+ result=" ${ result} /"
341
357
fi
342
358
343
359
# since we now have identified the common part,
344
360
# compute the non-common part
345
361
local forward_part=" ${target# $common_part } "
346
362
347
363
# and now stick all parts together
348
- if test_nz $result && test_nz $forward_part ; then
349
- result=" $result$forward_part "
350
- elif test_nz $forward_part ; then
351
- # remote extra '/', e.g. "/xxx" => "xxx"
364
+ if test_nz " ${result} " && test_nz " ${forward_part} " ; then
365
+ result=" ${result}${forward_part} "
366
+ elif test_nz " ${forward_part} " ; then
352
367
result=" ${forward_part#*/ } "
353
368
fi
354
369
355
- _ret=" $result "
370
+ # same directory?
371
+ if test_z " ${result} " && test_eq " ${source} " " ${target} " ; then
372
+ result=" ."
373
+ fi
374
+
375
+ _ret=" ${result} "
356
376
}
357
377
358
378
path_sourcekind () {
@@ -911,7 +931,9 @@ option() {
911
931
fi
912
932
return
913
933
fi
914
- _xmake_sh_options=" ${_xmake_sh_options} ${name} "
934
+ if ! _map_has " options" " ${name} _name" ; then
935
+ _xmake_sh_options=" ${_xmake_sh_options} ${name} "
936
+ fi
915
937
_map_set " options" " ${name} _name" " ${name} "
916
938
_map_set " options" " ${name} _description" " ${description} "
917
939
_map_set " options" " ${name} _default" " ${default} "
@@ -1187,7 +1209,9 @@ target() {
1187
1209
if ! ${_loading_targets} ; then
1188
1210
return
1189
1211
fi
1190
- _xmake_sh_targets=" ${_xmake_sh_targets} ${name} "
1212
+ if ! _map_has " targets" " ${name} _name" ; then
1213
+ _xmake_sh_targets=" ${_xmake_sh_targets} ${name} "
1214
+ fi
1191
1215
_map_set " targets" " ${name} _name" " ${name} "
1192
1216
return 0
1193
1217
}
0 commit comments