Neels Hofmeyr | 53e758a | 2017-05-29 22:53:34 +0200 | [diff] [blame] | 1 | #!source_this_file |
| 2 | |
| 3 | # Common parts for osmo-gsm-tester jenkins build scripts. Use like in below example: |
| 4 | # |
| 5 | #-------------- |
| 6 | # #!/bin/sh |
| 7 | # set -e -x |
| 8 | # base="$PWD" |
| 9 | # name="osmo-name" |
| 10 | # . "$(dirname "$0")/jenkins-build-common.sh" |
| 11 | # |
| 12 | # build_repo libosmocore --configure --opts |
| 13 | # build_repo libosmo-foo special_branch --configure --opts |
| 14 | # build_repo osmo-bar |
| 15 | # |
| 16 | # create_bin_tgz |
| 17 | #-------------- |
| 18 | # |
| 19 | # Some explanations: |
| 20 | # |
| 21 | # To allow calling from arbitrary working directories, other scripts should |
| 22 | # source this file like shown above. |
| 23 | # |
| 24 | # Sourcing scripts must provide some variables/functions, see above. |
| 25 | # In addition, these values can optionally be passed to override: |
| 26 | # git_url, prefix, prefix_real, BUILD_NUMBER |
| 27 | # |
| 28 | # CONFIGURE_FLAGS may contain flags that should be passed to all builds' |
| 29 | # ./configure steps (useful e.g. for building in the sysmobts SDK). |
| 30 | # |
| 31 | # For each built repository, a specific git branch or hash can be provided by |
| 32 | # environment variable: OSMO_GSM_TESTER_BUILD_$repo="<git-hash>" |
| 33 | # NOTE: convert $repo's dashes to underscore. For example: |
| 34 | # OSMO_GSM_TESTER_BUILD_osmo_hlr="f001234abc" |
| 35 | # OSMO_GSM_TESTER_BUILD_libosmocore="my/branch" |
| 36 | # ("origin/" is prepended to branch names automatically) |
| 37 | |
| 38 | if [ -z "$name" -o -z "$base" ]; then |
| 39 | set +x |
| 40 | echo "Some environment variables are not provided as required by jenkins-build-common.sh. Error." |
| 41 | exit 1 |
| 42 | fi |
| 43 | |
| 44 | git_url="${git_url-"git://git.osmocom.org"}" |
| 45 | prefix="${prefix-"$base/inst-$name"}" |
| 46 | # prefix_real is usually identical with prefix, except when installing to a |
| 47 | # different $DESTDIR than /, which is the case for example when building |
| 48 | # osmo-bts within the sysmoBTS SDK |
| 49 | prefix_real="${prefix_real-"$prefix"}" |
| 50 | |
| 51 | export PKG_CONFIG_PATH="$prefix_real/lib/pkgconfig:$PKG_CONFIG_PATH" |
| 52 | export LD_LIBRARY_PATH="$prefix_real/lib:$LD_LIBRARY_PATH" |
| 53 | |
| 54 | # Show current environment. Sometimes the LESS_ vars have ansi colors making a |
| 55 | # mess, so exclude those. |
| 56 | env | grep -v "^LESS" | sort |
| 57 | |
| 58 | # clean the workspace |
| 59 | rm -f "$base/${name}"*.tgz rm -f "$base/${name}"*.md5 |
| 60 | rm -rf "$prefix_real" |
| 61 | mkdir -p "$prefix_real" |
| 62 | |
| 63 | have_repo() { |
| 64 | repo="$1" |
| 65 | branch="${2-master}" |
| 66 | |
| 67 | # Evaluate environment for instructions to build a specific git hash. |
| 68 | # Using a hash as $branch above unfortunately doesn't work. |
| 69 | branch_override_var="$(echo "OSMO_GSM_TESTER_BUILD_$repo" | sed 's/-/_/g')" |
| 70 | branch_override="$(eval "echo \$$branch_override_var")" |
| 71 | if [ -n "$branch_override" ]; then |
| 72 | branch="$branch_override" |
| 73 | fi |
| 74 | |
| 75 | cd "$base" |
Neels Hofmeyr | b398b52 | 2017-06-23 04:13:30 +0200 | [diff] [blame] | 76 | rm -rf "$repo" |
| 77 | git clone "$git_url/$repo" "$repo" |
Neels Hofmeyr | 53e758a | 2017-05-29 22:53:34 +0200 | [diff] [blame] | 78 | |
Neels Hofmeyr | b398b52 | 2017-06-23 04:13:30 +0200 | [diff] [blame] | 79 | cd "$repo" |
| 80 | |
| 81 | # Figure out whether we need to prepend origin/ to find branches in upstream. |
| 82 | # Doing this allows using git hashes instead of a branch name. |
Neels Hofmeyr | 851802b | 2017-06-23 03:52:26 +0200 | [diff] [blame] | 83 | if git rev-parse "origin/$branch"; then |
Neels Hofmeyr | 53e758a | 2017-05-29 22:53:34 +0200 | [diff] [blame] | 84 | branch="origin/$branch" |
| 85 | fi |
| 86 | |
Neels Hofmeyr | 851802b | 2017-06-23 03:52:26 +0200 | [diff] [blame] | 87 | git checkout -b build_branch "$branch" |
Neels Hofmeyr | 2581b50 | 2017-06-23 04:07:40 +0200 | [diff] [blame] | 88 | rm -rf * |
Neels Hofmeyr | 53e758a | 2017-05-29 22:53:34 +0200 | [diff] [blame] | 89 | git reset --hard "$branch" |
| 90 | |
| 91 | git rev-parse HEAD |
| 92 | |
| 93 | cd "$base" |
| 94 | } |
| 95 | |
| 96 | build_repo() { |
| 97 | # usage: build_repo <name> [<branch>] [--configure-opts [...]] |
| 98 | dep="$1" |
| 99 | branch="master" |
| 100 | if [ -z "$(echo "$2" | grep '^-')" ]; then |
| 101 | # second arg does not start with a dash, it's empty or a branch |
| 102 | branch="$2" |
| 103 | if [ -n "$branch" ]; then |
| 104 | # we had a branch arg, need to shift once more to get config options |
| 105 | shift |
| 106 | else |
| 107 | branch="master" |
| 108 | fi |
| 109 | fi |
| 110 | shift |
| 111 | configure_opts="$@" |
| 112 | |
| 113 | set +x; echo " |
| 114 | |
| 115 | ====================== $dep |
| 116 | |
| 117 | "; set -x |
| 118 | |
| 119 | |
| 120 | have_repo "$dep" "$branch" |
| 121 | |
| 122 | cd "$dep" |
| 123 | |
| 124 | echo "$(git rev-parse HEAD) $dep" >> "$prefix_real/${name}_git_hashes.txt" |
| 125 | |
| 126 | # special shim: we know the openbsc.git needs to be built in the openbsc/ subdir. |
| 127 | if [ "$dep" = "openbsc" ]; then |
| 128 | cd openbsc |
| 129 | fi |
| 130 | |
| 131 | set +x; echo; echo; set -x |
| 132 | autoreconf -fi |
| 133 | set +x; echo; echo; set -x |
| 134 | ./configure --prefix="$prefix" $CONFIGURE_FLAGS $configure_opts |
| 135 | set +x; echo; echo; set -x |
| 136 | make -j8 || make # libsmpp34 can't build in parallel |
| 137 | set +x; echo; echo; set -x |
| 138 | make install |
| 139 | } |
| 140 | |
| 141 | create_bin_tgz() { |
Neels Hofmeyr | 53e758a | 2017-05-29 22:53:34 +0200 | [diff] [blame] | 142 | # build the archive that is going to be copied to the tester |
| 143 | cd "$prefix_real" |
| 144 | this="$name.build-${BUILD_NUMBER-$(date +%Y-%m-%d_%H_%M_%S)}" |
| 145 | tar="${this}.tgz" |
| 146 | tar czf "$base/$tar" * |
| 147 | cd "$base" |
| 148 | md5sum "$tar" > "${this}.md5" |
| 149 | } |