IVGCVSW-7638  Update Build Tool to use the armnn that it is contained in

  * Added a flag to sym link the source instead of making a git clone

Signed-off-by: Tracy Narine <tracy.narine@arm.com>
Change-Id: I9f4cde8528f250e946fcbf00921f28eb62bbaa31
diff --git a/build-tool/README.md b/build-tool/README.md
index 34063f7..0bfadd8 100644
--- a/build-tool/README.md
+++ b/build-tool/README.md
@@ -169,6 +169,8 @@
 | --cl-backend              | **flag:** build Arm NN with the OpenCL backend (GPU acceleration from ACL)                                                                                                                                                                                                                                              |
 | --ref-backend             | **flag:** build Arm NN with the reference backend<br/>**Should be used for verification purposes only.<br/>Does not provide any performance acceleration.**                                                                                                                                                             |
 | --debug                   | **flag:** build Arm NN (and ACL) with debug turned on (optional: defaults to off)                                                                                                                                                                                                                                       |
+| --clean                   | **flag:** remove previous Arm NN and ACL build prior to script execution (optional: defaults to off)                                                                                                                                                                                                                    |
+| --symlink-armnn           | **flag:** instead of cloning, make a symbolic link from the armnn directory containing the build-tool to the source directory                                                                                                                                                                                           |
 | --armnn-cmake-args=       | **option:** provide additional comma-separated CMake arguments string for building Arm NN (optional)<br/>String should start and end with **single quotes** ```'```<br/>Please refer to **armnn/cmake/GlobalConfig.cmake**                                                                                              |
 | --acl-scons-params=       | **option**: provide additional comma-separated scons parameters string for building ACL (optional)<br/>String should start and end with **single quotes** ```'```<br/>ACL provide [documentation](https://arm-software.github.io/ComputeLibrary/latest/how_to_build.xhtml#S1_1_build_options) for their build options   |
 
diff --git a/build-tool/scripts/build-armnn.sh b/build-tool/scripts/build-armnn.sh
index b973a62..18e59e1 100755
--- a/build-tool/scripts/build-armnn.sh
+++ b/build-tool/scripts/build-armnn.sh
@@ -12,7 +12,10 @@
 set -o pipefail # Catch non zero exit codes within pipelines.
 set -o errexit  # Catch and propagate non zero exit codes.
 
-rel_path=$(dirname "$0") # relative path from where script is executed to script location
+rel_path=$(dirname "$0") 			# relative path from where script is executed to script location
+abs_script_path=$(cd "$rel_path" ; pwd -P) 	# absolute path to script directory
+abs_btool_path=$(dirname "$abs_script_path")	# absolute path to build-tool directory
+abs_armnn_path=$(dirname "$abs_btool_path")	# absolute path to armnn directory
 
 build_acl()
 {
@@ -263,6 +266,8 @@
     provide additional comma-separated scons parameters string for building ACL (optional)
   --num-threads=<INTEGER>
     specify number of threads/cores to build dependencies with (optional: defaults to number of online CPU cores on host)
+  --symlink-armnn
+    instead of cloning, make a symbolic link from the armnn directory containing the build-tool to the source directory
   -h, --help
     print brief usage information and exit
   -x
@@ -302,6 +307,7 @@
 flag_clean=0
 flag_debug=0
 flag_jni=0
+flag_symlink_armnn=0
 
 # Empty strings for optional additional args by default
 armnn_cmake_args=""
@@ -318,7 +324,7 @@
   exit 1
 fi
 
-args=$(getopt -ohx -l tflite-classic-delegate,tflite-opaque-delegate,tflite-parser,onnx-parser,all,target-arch:,neon-backend,cl-backend,ref-backend,clean,debug,armnn-cmake-args:,acl-scons-params:,num-threads:,help -n "$name"   -- "$@")
+args=$(getopt -ohx -l tflite-classic-delegate,tflite-opaque-delegate,tflite-parser,onnx-parser,all,target-arch:,neon-backend,cl-backend,ref-backend,clean,debug,armnn-cmake-args:,acl-scons-params:,num-threads:,symlink-armnn,help -n "$name"   -- "$@")
 eval set -- "$args"
 while [ $# -gt 0 ]; do
   if [ -n "${opt_prev:-}" ]; then
@@ -394,6 +400,10 @@
     opt_prev=num_threads
     ;;
 
+  --symlink-armnn)
+    flag_symlink_armnn=1
+    ;;
+    
   -h | --help)
     usage
     exit 0
@@ -449,11 +459,23 @@
 
 # Download Arm NN if not done already in a previous execution of this script
 # Check if Arm NN source directory exists AND that it is a repository (not empty)
+made_symlink_armnn=0
 if [ -d "$ARMNN_SRC" ] && check_if_repository "$ARMNN_SRC"; then
   echo -e "\n***** Arm NN source repository already located at $ARMNN_SRC. Skipping cloning of Arm NN. *****"
 else
-  # Download latest release branch of Arm NN
-  download_armnn
+  # Use sym link or download latest release branch of Arm NN
+  if [ "$flag_symlink_armnn" -eq 1 ]; then
+    if check_if_repository "$abs_armnn_path"; then
+      ln -s "$abs_armnn_path" "$SOURCE_DIR"/armnn
+      made_symlink_armnn=1
+      echo -e "\n***** Arm NN source repository using symbolic link to: $abs_armnn_path *****"
+    else
+      echo "Arm NN directory found is not a repository: $abs_armnn_path"
+      exit 1
+    fi
+  else
+    download_armnn
+  fi
 fi
 
 # Download ACL if not done already in a previous execution of this script
@@ -506,6 +528,9 @@
 echo "            num-threads: $NUM_THREADS"
 echo "         root directory: $ROOT_DIR"
 echo "       source directory: $SOURCE_DIR"
+if [ "$made_symlink_armnn" -eq 1 ]; then
+  echo "armnn symlink directory: $abs_armnn_path"
+fi
 echo "        build directory: $BUILD_DIR"
 echo "        armnn build dir: $ARMNN_BUILD_TARGET"
 echo -e "\nScript execution will begin in 10 seconds..."