COMP: only use Project/build if Project directory is writable (#1693)

This commit is contained in:
Mark Olesen 2020-05-12 09:35:54 +02:00
parent d4e31093fd
commit ed3c6bcb63
2 changed files with 55 additions and 41 deletions

View File

@ -69,7 +69,7 @@ expandPath()
(cd "$1" && pwd -P) (cd "$1" && pwd -P)
elif [ -n "$1" ] elif [ -n "$1" ]
then then
(cd $(dirname "$1") && pwd -P) (cd "$(dirname "$1")" && pwd -P)
else else
pwd -P pwd -P
fi fi
@ -89,15 +89,15 @@ expandPath()
# - WM_PROJECT_DIR, HOME # - WM_PROJECT_DIR, HOME
findTarget() findTarget()
{ {
local project=$(expandPath $WM_PROJECT_DIR) local project=$(expandPath "$WM_PROJECT_DIR")
local home=$(expandPath $HOME) local home=$(expandPath "$HOME")
local reldir="${1:-.}" local reldir="${1:-.}"
local absdir=$(expandPath $reldir) local absdir=$(expandPath "$reldir")
while [ -n "$absdir" ] while [ -n "$absdir" ]
do do
case "$absdir" in case "$absdir" in
($project | $home | /) ("$project" | "$home" | /)
break break
;; ;;
esac esac
@ -113,7 +113,7 @@ findTarget()
fi fi
done done
echo "Error: no Make directory for $(expandPath $1)" 1>&2 echo "Error: no Make directory for $(expandPath "$1")" 1>&2
echo 1>&2 echo 1>&2
return 1 return 1
} }
@ -133,14 +133,14 @@ cdSource()
echo " Searching up directories tree for Make directory" 1>&2 echo " Searching up directories tree for Make directory" 1>&2
dir=$(findTarget .) || exit 1 # Fatal dir=$(findTarget .) || exit 1 # Fatal
cd $dir 2>/dev/null || { cd "$dir" 2>/dev/null || {
echo "$Script error: could not change to directory '$dir'" 1>&2 echo "$Script error: could not change to directory '$dir'" 1>&2
exit 1 exit 1
} }
unset targetType unset targetType
fi fi
[ -r $MakeDir/files ] || { [ -r "$MakeDir"/files ] || {
echo "$Script error: file '$MakeDir/files' does not exist in $PWD" 1>&2 echo "$Script error: file '$MakeDir/files' does not exist in $PWD" 1>&2
exit 1 exit 1
} }
@ -158,23 +158,29 @@ cdSource()
# - WM_PROJECT_DIR, WM_OPTIONS # - WM_PROJECT_DIR, WM_OPTIONS
findObjectDir() findObjectDir()
{ {
local project=$(expandPath $WM_PROJECT_DIR) local project="$(expandPath "$WM_PROJECT_DIR")"
local absdir=$(expandPath ${1:-.}) local absdir="$(expandPath "${1:-.}")"
local objectsDir local appDir relativeDir objectsDir
case "$absdir" in # Treat project/ builds as out-of-source
("$project"/*) relativeDir="${absdir#${project}/}"
local buildPath=$WM_PROJECT_DIR/build/${WM_OPTIONS} if [ "$relativeDir" != "$absdir" ]
objectsDir=$buildPath$(echo $absdir | sed s%$project%% ) then
;; [ -w "$WM_PROJECT_DIR" ] && \
(*) objectsDir="${WM_PROJECT_DIR}/build/${WM_OPTIONS}/${relativeDir}"
local path=$absdir fi
local appDir=.
# Default (local) build directory
if [ -z "$objectsDir" ]
then
relativeDir="$absdir"
appDir=.
[ -d Make ] || appDir=$(findTarget .) || exit 1 # Fatal [ -d Make ] || appDir=$(findTarget .) || exit 1 # Fatal
absdir=$(expandPath $appDir/.) absdir=$(expandPath "$appDir"/.)
objectsDir=$appDir/Make/${WM_OPTIONS}$(echo $path | sed s%$absdir%% )
;; relativeDir="${relativeDir#${absdir}}"
esac objectsDir="${appDir}/Make/${WM_OPTIONS}${relativeDir}"
fi
echo "$objectsDir" echo "$objectsDir"
} }
@ -191,7 +197,7 @@ findObjectDir()
# - WM_PROJECT_DIR, WM_OPTIONS # - WM_PROJECT_DIR, WM_OPTIONS
removeObjectDir() removeObjectDir()
{ {
local objectsDir=$(findObjectDir ${1:-.}) local objectsDir="$(findObjectDir "${1:-.}")"
if [ -d "$objectsDir" ] if [ -d "$objectsDir" ]
then then
rm -rf "$objectsDir" 2>/dev/null rm -rf "$objectsDir" 2>/dev/null
@ -344,7 +350,7 @@ if [ -n "$BASH_VERSION" ]
then then
depToSource() depToSource()
{ {
local sourceFile=${1%.dep} local sourceFile="${1%.dep}"
sourceFile="${sourceFile/build\/${WM_OPTIONS}\//}" sourceFile="${sourceFile/build\/${WM_OPTIONS}\//}"
sourceFile="${sourceFile/build\/${WM_OPTIONS}${WM_MPLIB}\//}" sourceFile="${sourceFile/build\/${WM_OPTIONS}${WM_MPLIB}\//}"
sourceFile="${sourceFile/Make\/${WM_OPTIONS}\//}" sourceFile="${sourceFile/Make\/${WM_OPTIONS}\//}"
@ -355,13 +361,11 @@ then
else else
depToSource() depToSource()
{ {
local sourceFile=$(echo ${1%.dep} | \ echo "${1%.dep}" | sed \
sed -e s%build/${WM_OPTIONS}/%% \ -e "s%build/${WM_OPTIONS}/%%" \
-e s%build/${WM_OPTIONS}${WM_MPLIB}/%% \ -e "s%build/${WM_OPTIONS}${WM_MPLIB}/%%" \
-e s%Make/${WM_OPTIONS}/%% \ -e "s%Make/${WM_OPTIONS}/%%" \
-e s%Make/${WM_OPTIONS}${WM_MPLIB}/%% ) -e "s%Make/${WM_OPTIONS}${WM_MPLIB}/%%"
echo "$sourceFile"
} }
fi fi

View File

@ -558,22 +558,32 @@ fi
# files and options being built in parallel # files and options being built in parallel
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
objectsDir="$MakeDir/$WM_OPTIONS" # Mini-version of findObjectDir
case "$PWD" in unset objectsDir
("$WM_PROJECT_DIR"/*)
buildPath="$WM_PROJECT_DIR/build/${WM_OPTIONS}" # Handle project/{applications,src} as out-of-source build
objectsDir=$buildPath$(echo $PWD | sed s%$WM_PROJECT_DIR%% ) relativeDir="${PWD#${WM_PROJECT_DIR}/}"
;; if [ "$relativeDir" != "$PWD" ]
esac then
[ -w "$WM_PROJECT_DIR" ] && \
objectsDir="${WM_PROJECT_DIR}/build/${WM_OPTIONS}/${relativeDir}"
fi
# Default (local) build directory
if [ -z "$objectsDir" ]
then
objectsDir="$MakeDir/$WM_OPTIONS"
fi
( (
unset MAKEFLAGS unset MAKEFLAGS
mkdir -p $objectsDir mkdir -p "$objectsDir"
# Pre-build the $WM_OPTIONS/options file # Pre-build the $WM_OPTIONS/options file
# which is included when building the $WM_OPTIONS/files file # which is included when building the $WM_OPTIONS/files file
$make -s -f $WM_DIR/makefiles/files \ $make -s -f $WM_DIR/makefiles/files \
MAKE_DIR=$MakeDir OBJECTS_DIR=$objectsDir $objectsDir/options MAKE_DIR="$MakeDir" OBJECTS_DIR="$objectsDir" "$objectsDir"/options
$make -s -f $WM_DIR/makefiles/files \ $make -s -f $WM_DIR/makefiles/files \
MAKE_DIR=$MakeDir OBJECTS_DIR=$objectsDir MAKE_DIR=$MakeDir OBJECTS_DIR=$objectsDir