Commit ed3c6bcb authored by Mark Olesen's avatar Mark Olesen
Browse files

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

parent d4e31093
......@@ -69,7 +69,7 @@ expandPath()
(cd "$1" && pwd -P)
elif [ -n "$1" ]
then
(cd $(dirname "$1") && pwd -P)
(cd "$(dirname "$1")" && pwd -P)
else
pwd -P
fi
......@@ -89,15 +89,15 @@ expandPath()
# - WM_PROJECT_DIR, HOME
findTarget()
{
local project=$(expandPath $WM_PROJECT_DIR)
local home=$(expandPath $HOME)
local project=$(expandPath "$WM_PROJECT_DIR")
local home=$(expandPath "$HOME")
local reldir="${1:-.}"
local absdir=$(expandPath $reldir)
local absdir=$(expandPath "$reldir")
while [ -n "$absdir" ]
do
case "$absdir" in
($project | $home | /)
("$project" | "$home" | /)
break
;;
esac
......@@ -113,7 +113,7 @@ findTarget()
fi
done
echo "Error: no Make directory for $(expandPath $1)" 1>&2
echo "Error: no Make directory for $(expandPath "$1")" 1>&2
echo 1>&2
return 1
}
......@@ -133,14 +133,14 @@ cdSource()
echo " Searching up directories tree for Make directory" 1>&2
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
exit 1
}
unset targetType
fi
[ -r $MakeDir/files ] || {
[ -r "$MakeDir"/files ] || {
echo "$Script error: file '$MakeDir/files' does not exist in $PWD" 1>&2
exit 1
}
......@@ -158,23 +158,29 @@ cdSource()
# - WM_PROJECT_DIR, WM_OPTIONS
findObjectDir()
{
local project=$(expandPath $WM_PROJECT_DIR)
local absdir=$(expandPath ${1:-.})
local objectsDir
local project="$(expandPath "$WM_PROJECT_DIR")"
local absdir="$(expandPath "${1:-.}")"
local appDir relativeDir objectsDir
# Treat project/ builds as out-of-source
relativeDir="${absdir#${project}/}"
if [ "$relativeDir" != "$absdir" ]
then
[ -w "$WM_PROJECT_DIR" ] && \
objectsDir="${WM_PROJECT_DIR}/build/${WM_OPTIONS}/${relativeDir}"
fi
case "$absdir" in
("$project"/*)
local buildPath=$WM_PROJECT_DIR/build/${WM_OPTIONS}
objectsDir=$buildPath$(echo $absdir | sed s%$project%% )
;;
(*)
local path=$absdir
local appDir=.
# Default (local) build directory
if [ -z "$objectsDir" ]
then
relativeDir="$absdir"
appDir=.
[ -d Make ] || appDir=$(findTarget .) || exit 1 # Fatal
absdir=$(expandPath $appDir/.)
objectsDir=$appDir/Make/${WM_OPTIONS}$(echo $path | sed s%$absdir%% )
;;
esac
absdir=$(expandPath "$appDir"/.)
relativeDir="${relativeDir#${absdir}}"
objectsDir="${appDir}/Make/${WM_OPTIONS}${relativeDir}"
fi
echo "$objectsDir"
}
......@@ -191,7 +197,7 @@ findObjectDir()
# - WM_PROJECT_DIR, WM_OPTIONS
removeObjectDir()
{
local objectsDir=$(findObjectDir ${1:-.})
local objectsDir="$(findObjectDir "${1:-.}")"
if [ -d "$objectsDir" ]
then
rm -rf "$objectsDir" 2>/dev/null
......@@ -344,7 +350,7 @@ if [ -n "$BASH_VERSION" ]
then
depToSource()
{
local sourceFile=${1%.dep}
local sourceFile="${1%.dep}"
sourceFile="${sourceFile/build\/${WM_OPTIONS}\//}"
sourceFile="${sourceFile/build\/${WM_OPTIONS}${WM_MPLIB}\//}"
sourceFile="${sourceFile/Make\/${WM_OPTIONS}\//}"
......@@ -355,13 +361,11 @@ then
else
depToSource()
{
local sourceFile=$(echo ${1%.dep} | \
sed -e s%build/${WM_OPTIONS}/%% \
-e s%build/${WM_OPTIONS}${WM_MPLIB}/%% \
-e s%Make/${WM_OPTIONS}/%% \
-e s%Make/${WM_OPTIONS}${WM_MPLIB}/%% )
echo "$sourceFile"
echo "${1%.dep}" | sed \
-e "s%build/${WM_OPTIONS}/%%" \
-e "s%build/${WM_OPTIONS}${WM_MPLIB}/%%" \
-e "s%Make/${WM_OPTIONS}/%%" \
-e "s%Make/${WM_OPTIONS}${WM_MPLIB}/%%"
}
fi
......
......@@ -558,22 +558,32 @@ fi
# files and options being built in parallel
#------------------------------------------------------------------------------
objectsDir="$MakeDir/$WM_OPTIONS"
case "$PWD" in
("$WM_PROJECT_DIR"/*)
buildPath="$WM_PROJECT_DIR/build/${WM_OPTIONS}"
objectsDir=$buildPath$(echo $PWD | sed s%$WM_PROJECT_DIR%% )
;;
esac
# Mini-version of findObjectDir
unset objectsDir
# Handle project/{applications,src} as out-of-source build
relativeDir="${PWD#${WM_PROJECT_DIR}/}"
if [ "$relativeDir" != "$PWD" ]
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
mkdir -p $objectsDir
mkdir -p "$objectsDir"
# Pre-build the $WM_OPTIONS/options file
# which is included when building the $WM_OPTIONS/files file
$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_DIR=$MakeDir OBJECTS_DIR=$objectsDir
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment