msvs_common.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. ##
  3. ## Copyright (c) 2014 The WebM project authors. All Rights Reserved.
  4. ##
  5. ## Use of this source code is governed by a BSD-style license
  6. ## that can be found in the LICENSE file in the root of the source
  7. ## tree. An additional intellectual property rights grant can be found
  8. ## in the file PATENTS. All contributing project authors may
  9. ## be found in the AUTHORS file in the root of the source tree.
  10. ##
  11. if [ "$(uname -o 2>/dev/null)" = "Cygwin" ] \
  12. && cygpath --help >/dev/null 2>&1; then
  13. FIXPATH='cygpath -m'
  14. else
  15. FIXPATH='echo_path'
  16. fi
  17. die() {
  18. echo "${self_basename}: $@" >&2
  19. exit 1
  20. }
  21. die_unknown(){
  22. echo "Unknown option \"$1\"." >&2
  23. echo "See ${self_basename} --help for available options." >&2
  24. exit 1
  25. }
  26. echo_path() {
  27. for path; do
  28. echo "$path"
  29. done
  30. }
  31. # Output one, possibly changed based on the system, path per line.
  32. fix_path() {
  33. $FIXPATH "$@"
  34. }
  35. # Corrects the paths in file_list in one pass for efficiency.
  36. # $1 is the name of the array to be modified.
  37. fix_file_list() {
  38. if [ "${FIXPATH}" = "echo_path" ] ; then
  39. # When used with echo_path, fix_file_list is a no-op. Avoid warning about
  40. # unsupported 'declare -n' when it is not important.
  41. return 0
  42. elif [ "${BASH_VERSINFO}" -lt 4 ] ; then
  43. echo "Cygwin path conversion has failed. Please use a version of bash"
  44. echo "which supports nameref (-n), introduced in bash 4.3"
  45. return 1
  46. fi
  47. declare -n array_ref=$1
  48. files=$(fix_path "${array_ref[@]}")
  49. local IFS=$'\n'
  50. array_ref=($files)
  51. }
  52. generate_uuid() {
  53. local hex="0123456789ABCDEF"
  54. local i
  55. local uuid=""
  56. local j
  57. #93995380-89BD-4b04-88EB-625FBE52EBFB
  58. for ((i=0; i<32; i++)); do
  59. (( j = $RANDOM % 16 ))
  60. uuid="${uuid}${hex:$j:1}"
  61. done
  62. echo "${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}"
  63. }
  64. indent1=" "
  65. indent=""
  66. indent_push() {
  67. indent="${indent}${indent1}"
  68. }
  69. indent_pop() {
  70. indent="${indent%${indent1}}"
  71. }
  72. tag_attributes() {
  73. for opt in "$@"; do
  74. optval="${opt#*=}"
  75. [ -n "${optval}" ] ||
  76. die "Missing attribute value in '$opt' while generating $tag tag"
  77. echo "${indent}${opt%%=*}=\"${optval}\""
  78. done
  79. }
  80. open_tag() {
  81. local tag=$1
  82. shift
  83. if [ $# -ne 0 ]; then
  84. echo "${indent}<${tag}"
  85. indent_push
  86. tag_attributes "$@"
  87. echo "${indent}>"
  88. else
  89. echo "${indent}<${tag}>"
  90. indent_push
  91. fi
  92. }
  93. close_tag() {
  94. local tag=$1
  95. indent_pop
  96. echo "${indent}</${tag}>"
  97. }
  98. tag() {
  99. local tag=$1
  100. shift
  101. if [ $# -ne 0 ]; then
  102. echo "${indent}<${tag}"
  103. indent_push
  104. tag_attributes "$@"
  105. indent_pop
  106. echo "${indent}/>"
  107. else
  108. echo "${indent}<${tag}/>"
  109. fi
  110. }