Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. set -eu
  4.  
  5. PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
  6. SRC_DIR=$(realpath "${PWD}/..")
  7. CXX_SRC=${SRC_DIR}/cpp
  8.  
  9. # The following can be set
  10. : "${CMAKE:=cmake}"
  11.  
  12. error() {
  13. echo "$@" >&2
  14. exit 1
  15. }
  16.  
  17. check_installed() {
  18. which "$1" > /dev/null
  19. }
  20.  
  21. parse_argv() {
  22. check_installed docopts || error "docopts is missing, install with 'pip install docopts'"
  23.  
  24. # Parse the argv into an associative array stored in a local variable named
  25. # __args. We cannot write in the `args` implicit scoped variable due to
  26. # redefinition and shadowing.
  27. eval "$(docopts -A __args -V - -h - : "$@" <<EOF
  28. Usage: $0 [options] <build_dir>
  29.  
  30. Prepare a cmake build directory for arrow.
  31.  
  32. Options:
  33. --cc=<compiler> Set C compiler [default: cc].
  34. --cxx=<compiler> Set C++ compiler [default: c++].
  35. --cxx-flags=<extra> Set extra compiler flags.
  36. --generator=<gen> CMake generator type [default: Ninja].
  37.  
  38. --build-type=<build> CMake build type [default: DEBUG].
  39. --warn-level=<level> Warning level, possible options are EVERYTHING,
  40. CHECKIN, PRODUCTION [default: CHECKIN].
  41. --cmake-extra=<args> CMake extra argument to pass.
  42.  
  43. --with-tests=<opt> Activate tests [default: ON].
  44. --with-benchmarks=<opt> Activate benchmarks [default: ON].
  45. --with-python=<opt> Activate python bindings [default: ON].
  46. --with-parquet=<opt> Activate parquet component [default: ON].
  47. --with-gandiva=<opt> Activate gandiva component [default: ON].
  48. --with-plasma=<opt> Activate plasma component [default: ON].
  49. --with-flight=<opt> Activate flight component [default: OFF].
  50. --with-asan=<opt> Activate ASAN sanitization [default: OFF].
  51.  
  52. --force Delete exisiting build dir if found.
  53. --trace Trace this script.
  54. --help Show help options.
  55. ----
  56. EOF
  57. )"
  58.  
  59. # copy __args into args
  60. # disable shellcheck since __args is defined in the previous eval.
  61. # shellcheck disable=SC2154
  62. for k in "${!__args[@]}"; do args+=(["$k"]=${__args["$k"]}); done
  63. # enable `set -x` if tracing is requested
  64. if [[ "${args[--trace]}" == "true" ]]; then set -x; fi
  65. }
  66.  
  67. build_cmake_argv() {
  68. # Define generator
  69. cmake_argv+=("-G${args[--generator]}")
  70.  
  71. # toolchain
  72. export "CC=${args[--cc]}"
  73. export "CXX=${args[--cxx]}"
  74.  
  75. if [[ ! -z "${args[--cxx-flags]:-}" ]]; then
  76. cmake_argv+=("-DARROW_CXXFLAGS=${args[--cxx-flags]}")
  77. fi
  78.  
  79. # Build type
  80. cmake_argv+=("-DCMAKE_BUILD_TYPE=${args[--build-type]}")
  81. cmake_argv+=("-DARROW_BUILD_TESTS=${args[--with-tests]}")
  82. cmake_argv+=("-DARROW_BUILD_BENCHMARKS=${args[--with-benchmarks]}")
  83. cmake_argv+=("-DBUILD_WARNING_LEVEL=${args[--warn-level]}")
  84. cmake_argv+=("-DARROW_USE_ASAN=${args[--with-asan]}")
  85.  
  86. # Components
  87. cmake_argv+=("-DARROW_PYTHON=${args[--with-python]}")
  88. cmake_argv+=("-DARROW_PARQUET=${args[--with-parquet]}")
  89. cmake_argv+=("-DARROW_GANDIVA=${args[--with-gandiva]}")
  90. cmake_argv+=("-DARROW_PLASMA=${args[--with-plasma]}")
  91. cmake_argv+=("-DARROW_FLIGHT=${args[--with-flight]}")
  92.  
  93. # conda-ism
  94. if [[ ! -z "${CONDA_PREFIX:-}" ]]; then
  95. local arrow_home=${CONDA_PREFIX}
  96. for v in ARROW_HOME ARROW_BUILD_TOOLCHAIN PARQUET_HOME BOOST_HOME; do
  97. export "${v}=${arrow_home}"
  98. done
  99.  
  100. cmake_argv+=("-DCMAKE_INSTALL_PREFIX=${arrow_home}")
  101. cmake_argv+=("-DCMAKE_INSTALL_LIBDIR=lib")
  102. fi
  103.  
  104. if [[ ! -z "${args[--cmake-extra]:-}" ]]; then
  105. cmake_argv+=(${args[--cmake-extra]})
  106. fi
  107.  
  108. cmake_argv+=("$CXX_SRC")
  109. }
  110.  
  111. invoke_cmake() {
  112. local build_dir=${args[<build_dir>]}
  113. local force=${args[--force]}
  114.  
  115. # Deal with existing build_dir
  116. if [[ -e "$build_dir" ]]; then
  117. if [[ "$force" != "true" ]]; then
  118. error "$build_dir already exists, pass --force to override"
  119. fi
  120.  
  121. rm -r "$build_dir"
  122. fi
  123.  
  124. # CMake 3.13 supports the `-B<build_dir>` option, until then we resort to the
  125. # old pushd/popd mechanism.
  126. mkdir "$build_dir"
  127. pushd "$build_dir"
  128. "${CMAKE}" "${cmake_argv[@]}"
  129. popd
  130. }
  131.  
  132. arrow_create_cpp_build() {
  133. # The following local variables are captured by lexical scope due to bash
  134. # incapacity to accept/return array variables (without using nameref which
  135. # are found only in bash 4.3 and later).
  136.  
  137. # Parse docopts arguments into `args` associative map.
  138. declare -A args
  139. # Define a local array to store cmake arguments.
  140. declare -a cmake_argv
  141.  
  142. parse_argv "$@"
  143.  
  144. build_cmake_argv
  145.  
  146. invoke_cmake
  147. }
  148.  
  149. main() {
  150. arrow_create_cpp_build "$@"
  151. }
  152.  
  153. # Invoke main only if the script is executed and not sourced.
  154. [[ "${BASH_SOURCE[0]}" != "${0}" ]] || main "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement