install.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/bin/bash
  2. #################################################################################
  3. # NxWidgets/tools/install.sh
  4. #
  5. # Copyright (C) 2012 Gregory Nutt. All rights reserved.
  6. # Author: Gregory Nutt <gnutt@nuttx.org>
  7. #
  8. # Redistribution and use in source and binary forms, with or without
  9. # modification, are permitted provided that the following conditions
  10. # are met:
  11. #
  12. # 1. Redistributions of source code must retain the above copyright
  13. # notice, this list of conditions and the following disclaimer.
  14. # 2. Redistributions in binary form must reproduce the above copyright
  15. # notice, this list of conditions and the following disclaimer in
  16. # the documentation and/or other materials provided with the
  17. # distribution.
  18. # 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
  19. # me be used to endorse or promote products derived from this software
  20. # without specific prior written permission.
  21. #
  22. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. # POSSIBILITY OF SUCH DAMAGE.
  34. #
  35. #################################################################################
  36. #
  37. # set -x
  38. # Functions
  39. function ShowUsage()
  40. {
  41. echo ""
  42. echo "Install a unit test in the NuttX source tree"
  43. echo ""
  44. echo "USAGE: $0 <apps-directory-path> <test-sub-directory>"
  45. echo ""
  46. echo "Where:"
  47. echo " <apps-directory-path> is the full, absolute path to the NuttX apps/ directory"
  48. echo " <test-sub-directory> is the name of a sub-directory in the UnitTests directory"
  49. echo ""
  50. }
  51. function ShowTests()
  52. {
  53. for testdir in ${UNITTEST_DIRPATH}/*; do
  54. subdir=`basename ${testdir}`
  55. if [ -d "${UNITTEST_DIRPATH}/${subdir}" ]; then
  56. if [ -f "${UNITTEST_DIRPATH}/${subdir}/Makefile" ]; then
  57. echo $subdir
  58. fi
  59. fi
  60. done
  61. }
  62. # Input parameters
  63. APPS_DIRPATH=$1
  64. TEST_SUBDIR=$2
  65. if [ -z "${APPS_DIRPATH}" ]; then
  66. echo "Missing required arguments"
  67. ShowUsage
  68. exit 1
  69. fi
  70. if [ -z "${TEST_SUBDIR}" ]; then
  71. echo "Missing required argument <test-sub-directory>"
  72. ShowUsage
  73. exit 1
  74. fi
  75. # Make sure that we know where we are and where we are going
  76. WD=`pwd`
  77. if [ -x install.sh ]; then
  78. UNITTEST_DIRPATH="${WD}/../UnitTests"
  79. TOOLS_DIRPATH="${WD}"
  80. else
  81. if [ -x tools/install.sh ]; then
  82. UNITTEST_DIRPATH="${WD}/UnitTests"
  83. TOOLS_DIRPATH="${WD}/tools"
  84. else
  85. echo "This script must be executed in the NxWidgets or NxWidgets/tools directory"
  86. ShowUsage
  87. exit 1
  88. fi
  89. fi
  90. if [ ! -d "${APPS_DIRPATH}" ]; then
  91. echo "Directory ${APPS_DIRPATH} does not exist"
  92. ShowUsage
  93. exit 1
  94. fi
  95. if [ ! -f "${APPS_DIRPATH}/Makefile" ]; then
  96. echo "Directory ${APPS_DIRPATH} does not look like a NuttX apps directory"
  97. ShowUsage
  98. exit 1
  99. fi
  100. TEST_PATH="${UNITTEST_DIRPATH}/${TEST_SUBDIR}"
  101. if [ ! -d "${TEST_PATH}" ]; then
  102. echo "Directory ${TEST_PATH} does not exist"
  103. ShowUsage
  104. ShowTests
  105. exit 1
  106. fi
  107. if [ ! -f "${TEST_PATH}/Makefile" ]; then
  108. echo "Directory ${TEST_PATH} does not look like a unit test directory"
  109. ShowUsage
  110. ShowTests
  111. exit 1
  112. fi
  113. # Check if the symbolic link "external" exists in the NuttX apps directory
  114. if [ -e "${APPS_DIRPATH}/external" ]; then
  115. echo "${APPS_DIRPATH}/external already exists..."
  116. if [ -h "${APPS_DIRPATH}/external" ]; then
  117. echo " Removing the old symbolic link."
  118. rm "${APPS_DIRPATH}/external" || \
  119. { echo " ERROR: Failed to remove old symbolic link"; \
  120. exit 1;
  121. }
  122. else
  123. echo " ERROR: But it is not a symbolic link!"
  124. echo " Please remove ${APPS_DIRPATH}/external"
  125. echo " and run this script again"
  126. fi
  127. fi
  128. # Then set up the symbolic link "external" in the NuttX apps to point to the
  129. # UnitTest subdirectory
  130. echo "Creating symbolic link"
  131. echo " - To ${TEST_PATH}"
  132. echo " - At ${APPS_DIRPATH}/external"
  133. ln -s "${TEST_PATH}" "${APPS_DIRPATH}/external" || \
  134. { echo "Failed to create symbollic link"; \
  135. exit 1;
  136. }