File: build.sh

package info (click to toggle)
opentelemetry-cpp 1.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,372 kB
  • sloc: cpp: 96,239; sh: 1,766; makefile: 36; python: 31
file content (192 lines) | stat: -rwxr-xr-x 4,565 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
set -e

export PATH=/usr/local/bin:$PATH

##
## Install all build tools and dependencies on Mac
##
function install_mac_tools {
  if [ ! -f $BUILDTOOLS_FILE ] ; then
    $WORKSPACE_ROOT/tools/setup-buildtools-mac.sh
    echo > $BUILDTOOLS_FILE
  else
    echo "Build tools already installed. Skipping build tools installation."
  fi
}

##
## Install all build tools and dependencies on Linux
##
function install_linux_tools {
  if [ ! -f $BUILDTOOLS_FILE ] ; then
    sudo $WORKSPACE_ROOT/tools/setup-buildtools.sh
    echo > $BUILDTOOLS_FILE
  else
    echo "Build tools already installed. Skipping build tools installation."
  fi
}

##
## Build dependencies
##
function build_dependencies {
  # Build Google Benchmark
  $WORKSPACE_ROOT/tools/build-benchmark.sh
  # Build Google Test
  $WORKSPACE_ROOT/tools/build-gtest.sh
}

##
## Build specific configuration for a given platform
##
function build {
  echo "Build configuration: $BUILD_CONFIG"
  cd $WORKSPACE_ROOT
  
  export BUILD_ROOT=`pwd`/out/$PLATFORM_NAME/$BUILD_CONFIG
  mkdir -p $BUILD_ROOT
  if [ ! -w $BUILD_ROOT ] ; then
    echo "Unable to create output directory: $BUILD_ROOT"
    exit 1
  fi

  if [ -z ${USE_VCPKG} ] ; then
    # TODO: consider that dependencies may also be coming from OS or brew
    build_dependencies
  else
    echo VCPKG_ROOT=${VCPKG_ROOT}
    # Prefer ninja from VCPKG if available
    NINJA=$WORKSPACE_ROOT/`find tools/vcpkg -name ninja -type f -print -quit`
    if [ -z ${NINJA} ] ; then
      NINJA=`which ninja`
    fi
  fi

  # Build OpenTelemetry SDK
  pushd $BUILD_ROOT
  if [ -z ${NINJA} ] ; then 
    cmake $BUILD_OPTIONS $WORKSPACE_ROOT
    make
  else
    cmake -G "Ninja" $BUILD_OPTIONS $WORKSPACE_ROOT
    echo Building with NINJA=$NINJA
    $NINJA
  fi
  popd
}

function runtests {
  pushd $BUILD_ROOT
  ctest
  popd
}

##
## Clean
##
function clean {
  rm -f CMakeCache.txt *.cmake
  rm -rf out
  rm -rf .buildtools
# make clean
}

##
## Detect compiler
##
function detect_compiler {
  if [ -z "${CC}" ] ; then
    # Compiler autodetection
    if [ -z "${APPLE}" ] ; then
      # Prefer gcc for non-Apple
      if [ -f /usr/bin/gcc ] ; then
        echo "gcc   version: `gcc --version`"
        PLATFORM_NAME=`gcc -dumpmachine`-gcc-`gcc -dumpversion`
      fi
    else
      # Prefer clang on Appple platforms
      if [ -f /usr/bin/clang ] ; then
        echo "clang version: `clang --version`"
        PLATFORM_NAME=`clang -dumpmachine`-clang-`clang -dumpversion`
      fi
    fi
  else
    # Use compiler specified by ${CC} environment variable
    IFS=- read $PLATFORM_NAME $COMPILER_VERSION <<< "${CC}"
    echo "CC version: `${CC} --version`"
    PLATFORM_NAME=$PLATFORM_NAME-`${CC} -dumpversion`
  fi

  if [ -z "${PLATFORM_NAME}" ] ; then
    # Default configuration name for unknown compiler
    # could be overridden by setting env var explicitly
    PLATFORM_NAME=unknown-0
  fi
}

##
## Detect Host OS, install tools and detect compiler
##
function install_tools {

  # Marker file to signal that the tools have been already installed (save build time for incremental builds)
  BUILDTOOLS_FILE=`pwd`/.buildtools

  # Host OS detection
  OS_NAME=`uname -a`
  case "$OS_NAME" in
    *Darwin*)
      export APPLE=1
      # Set target MacOS minver
      export MACOSX_DEPLOYMENT_TARGET=10.10
      install_mac_tools ;;

    *Linux*)
      export LINUX=1
      [[ -z "$NOROOT" ]] && install_linux_tools || echo "No root. Skipping build tools installation." ;;

    *)
      echo "WARNING: unsupported OS $OS_NAME. Skipping build tools installation." ;;
  esac

  detect_compiler
}

##
## Parse arguments
##
function parse_args {
  # Build debug build by default
  if [ "$1" == "release" ] ; then
    BUILD_TYPE="release"
  else
    BUILD_TYPE="debug"
  fi
}

################################################################################################################

## Switch to workspace root directory first
DIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
WORKSPACE_ROOT=$DIR/..
cd $WORKSPACE_ROOT
echo "Current directory is `pwd`"

# Parse command line arguments
parse_args

# Install the necessary build tools if needed
[[ -z "$NOROOT" ]] && install_tools || echo "No root: skipping build tools installation."

# Build given configuration. Default configuration is ABI-stable 'nostd::' classes.
# Please refer to CMakeLists.txt for the list of supported build configurations.
BUILD_CONFIG=${1-nostd}

shift
BUILD_OPTIONS="$@"
build
runtests