From f424cf319f7d9548d51918abf5959a814313b4fe Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 16 Dec 2022 00:39:37 +0800 Subject: fix path relative in configure --- configure | 46 +++++++++++++++++++++++++++++++++------------- core/src/demo/xmake.sh | 3 ++- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/configure b/configure index 1ef58fc77..833c385a4 100755 --- a/configure +++ b/configure @@ -273,6 +273,9 @@ path_basename() { # we avoid use `dirname -- ${1}`, because it's too slow path_directory() { local path="${1}" + if test_z "${path}"; then + raise "invalid empty path in path_directory()." + fi local oldifs="${IFS}" IFS='/' set -- ${path} @@ -317,27 +320,40 @@ path_is_absolute() { # get relative path, e.g $(path_relative ${rootdir} ${absolute_path}` path_relative() { - local source=$1 - local target=$2 + local source="${1}" + local target="${2}" + if test_z "${source}" || test_z "${target}"; then + raise "invalid empty path in path_relative()" + fi + + # patch missing "./" + source=${source#./} + source=${source#.} + target=${target#./} + target=${target#.} + if test_z "${source}"; then + _ret="${target}" + return + fi - local common_part=$source + # find common path local result="" - + local common_part=$source while test_eq "${target#$common_part}" "${target}"; do # no match, means that candidate common part is not correct # go up one level (reduce common part) path_directory "${common_part}"; common_part="${_ret}" # and record that we went back, with correct / handling - if test_z $result; then + if test_z "${result}"; then result=".." else - result="../$result" + result="../${result}" fi done - if test_eq $common_part "/"; then + if test_eq "${common_part}" "/"; then # special case for root (no common path) - result="$result/" + result="${result}/" fi # since we now have identified the common part, @@ -345,14 +361,18 @@ path_relative() { local forward_part="${target#$common_part}" # and now stick all parts together - if test_nz $result && test_nz $forward_part; then - result="$result$forward_part" - elif test_nz $forward_part; then - # remote extra '/', e.g. "/xxx" => "xxx" + if test_nz "${result}" && test_nz "${forward_part}"; then + result="${result}${forward_part}" + elif test_nz "${forward_part}"; then result="${forward_part#*/}" fi - _ret="$result" + # same directory? + if test_z "${result}" && test_eq "${source}" "${target}"; then + result="." + fi + + _ret="${result}" } path_sourcekind() { diff --git a/core/src/demo/xmake.sh b/core/src/demo/xmake.sh index be352f1f0..e3c6abd44 100755 --- a/core/src/demo/xmake.sh +++ b/core/src/demo/xmake.sh @@ -22,4 +22,5 @@ target "demo" add_ldflags "-static-libgcc" fi - + # add install files + add_installfiles "${projectdir}/(xmake/**.lua)" "share" -- cgit v1.3.1