|
| 1 | +#!/bin/bash -eu |
| 2 | + |
| 3 | +set -o pipefail |
| 4 | +IFS=$'\n\t' |
| 5 | + |
| 6 | +# This is a script that builds our platform assemblies, and copies them to the |
| 7 | +# repository used to create API reference documentation. |
| 8 | + |
| 9 | +APIDROP_REMOTE=https://apidrop.visualstudio.com/binaries/_git/binaries |
| 10 | +APIDROP_REPOSITORY= |
| 11 | +BUILD=1 |
| 12 | +PUSH= |
| 13 | +CHECKOUT= |
| 14 | + |
| 15 | +GREEN=$(tput setaf 2 2>/dev/null || true) |
| 16 | +YELLOW=$(tput setaf 3 2>/dev/null || true) |
| 17 | +MAGENTA=$(tput setaf 5 2>/dev/null || true) |
| 18 | +BLUE=$(tput setaf 6 2>/dev/null || true) |
| 19 | +RED=$(tput setaf 9 2>/dev/null || true) |
| 20 | +CLEAR=$(tput sgr0 2>/dev/null || true) |
| 21 | + |
| 22 | +BACKGROUND_COLOR=$GREEN |
| 23 | +BRANCH_COLOR=$BLUE |
| 24 | +LINK_COLOR=$MAGENTA |
| 25 | +PATH_COLOR=$BLUE |
| 26 | +NOTICE_COLOR=$YELLOW |
| 27 | +REMOTE_COLOR=$MAGENTA |
| 28 | +PLATFORM_COLOR=$BLUE |
| 29 | + |
| 30 | +while ! test -z "${1:-}"; do |
| 31 | + case $1 in |
| 32 | + --help | -\? | -h) |
| 33 | + echo "$(basename "$0"):" |
| 34 | + echo " Builds the current checkout, and copies the product assemblies to apidrop.visualstudio.com's binaries repository to update the API docs." |
| 35 | + echo "" |
| 36 | + echo " Options:" |
| 37 | + echo " -h --help Show this help" |
| 38 | + echo " -v --verbose Make verbose" |
| 39 | + echo " -a --apidrop-repository= Specify the local path to the binaries repository ($REMOTE_COLOR$APIDROP_REMOTE$CLEAR)." |
| 40 | + echo " -p --push If specified, push the commit with the updated assemblies to the binaries repository (otherwise this will have to be done manually)." |
| 41 | + echo " -s --skip-build If specified, any existing build will be used instead of rebuilding the checkout." |
| 42 | + echo " -c --checkout= The path to the dotnet/macios checkout to use." |
| 43 | + exit 0 |
| 44 | + ;; |
| 45 | + -v | --verbose) |
| 46 | + set -x |
| 47 | + shift |
| 48 | + ;; |
| 49 | + -a=* | --apidrop-repository=*) |
| 50 | + APIDROP_REPOSITORY="${1//*=/}" |
| 51 | + shift |
| 52 | + ;; |
| 53 | + -a | --apidrop-repository) |
| 54 | + APIDROP_REPOSITORY="${2:-}" |
| 55 | + shift 2 |
| 56 | + ;; |
| 57 | + -p | --push) |
| 58 | + PUSH=1 |
| 59 | + shift |
| 60 | + ;; |
| 61 | + -c | --checkout) |
| 62 | + CHECKOUT="${2:-}" |
| 63 | + shift 2 |
| 64 | + ;; |
| 65 | + -c=* | --checkout=*) |
| 66 | + CHECKOUT="${1//*=/}" |
| 67 | + shift |
| 68 | + ;; |
| 69 | + -s | --skip-build) |
| 70 | + BUILD= |
| 71 | + shift |
| 72 | + ;; |
| 73 | + *) |
| 74 | + echo "${RED}$(basename "$0"): Unknown option: $MAGENTA$1$RED. Pass --help to view the available options.${CLEAR}" |
| 75 | + exit 1 |
| 76 | + ;; |
| 77 | + esac |
| 78 | +done |
| 79 | + |
| 80 | +echo "${BACKGROUND_COLOR}$(basename "$0"): Build the current macios checkout and copy the product assemblies to the apidrop.visualstudio.com's binaries repository to update the API docs... Pass --help for help." |
| 81 | + |
| 82 | +if test -n "${CHECKOUT:-}"; then |
| 83 | + cd "$CHECKOUT" |
| 84 | +fi |
| 85 | + |
| 86 | +cd "$(git rev-parse --show-toplevel)" |
| 87 | +MACIOS_PATH=$(pwd) |
| 88 | + |
| 89 | +if [ -n "$(git status --porcelain --ignore-submodule)" ]; then |
| 90 | + echo "${RED}Working directory is not clean:${CLEAR}" |
| 91 | + git status --ignore-submodule | sed 's/^/ /' |
| 92 | + exit 1 |
| 93 | +fi |
| 94 | + |
| 95 | +if test -z "$APIDROP_REPOSITORY"; then |
| 96 | + echo "${NOTICE_COLOR}The path to the apidrop repository was not found, so looking for it...${CLEAR}" |
| 97 | + while [[ "$(pwd)" != "/" ]]; do |
| 98 | + cd .. |
| 99 | + if test -d apidrop.visualstudio.com/binaries; then |
| 100 | + cd apidrop.visualstudio.com/binaries |
| 101 | + if REMOTE=$(git remote get-url origin); then |
| 102 | + if [[ "$REMOTE" == "$APIDROP_REMOTE" ]]; then |
| 103 | + APIDROP_REPOSITORY=$(pwd) |
| 104 | + echo "${BACKGROUND_COLOR} Located the apidrop repository: ${PATH_COLOR}$APIDROP_REPOSITORY${CLEAR}" |
| 105 | + break |
| 106 | + fi |
| 107 | + echo "${NOTICE_COLOR} Discarded the git checkout in ${PATH_COLOR}$(pwd)${NOTICE_COLOR}, because its remote $REMOTE_COLOR$REMOTE$NOTICE_COLOR does not match the expected remote $REMOTE_COLOR$APIDROP_REMOTE$NOTICE_COLOR.${CLEAR}" |
| 108 | + else |
| 109 | + echo "${NOTICE_COLOR} Discarded the directory ${PATH_COLOR}$(pwd)${NOTICE_COLOR}, because it's not a git checkout.${CLEAR}" |
| 110 | + fi |
| 111 | + cd ../.. |
| 112 | + fi |
| 113 | + done |
| 114 | + if test -z "$APIDROP_REPOSITORY"; then |
| 115 | + echo "${RED}Could not find a local checkout of the $REMOTE_COLOR$APIDROP_REMOTE$RED repository. Check it out, and then pass the path using ${BACKGROUND_COLOR}--apidrop-repository=/path/to/checkout${RED}.${CLEAR}" |
| 116 | + exit 1 |
| 117 | + fi |
| 118 | +else |
| 119 | + echo "${BACKGROUND_COLOR}Using the directory $PATH_COLOR$APIDROP_REPOSITORY$BACKGROUND_COLOR as the checkout for the $REMOTE_COLOR$APIDROP_REMOTE$BACKGROUND_COLOR repository.${CLEAR}" |
| 120 | +fi |
| 121 | + |
| 122 | +cd "$MACIOS_PATH" |
| 123 | + |
| 124 | +if test -n "$BUILD"; then |
| 125 | + echo "${BACKGROUND_COLOR}Building macios (pass --skip-build to skip)...${CLEAR}" |
| 126 | + ( |
| 127 | + make reset |
| 128 | + make git-clean-all |
| 129 | + git clean -xfd |
| 130 | + ./configure |
| 131 | + make all -j8 |
| 132 | + make install -j8 |
| 133 | + ) 2>&1 | sed 's/^/ /' |
| 134 | +else |
| 135 | + echo "${BACKGROUND_COLOR}Skipped building macios...${CLEAR}" |
| 136 | +fi |
| 137 | + |
| 138 | +TMPFILE=$(mktemp) |
| 139 | +make -C "$MACIOS_PATH"/tools/devops print-variable-value-to-file "FILE=$TMPFILE" VARIABLE=XCODE_VERSION |
| 140 | +XCODE_VERSION=$(cat "$TMPFILE") |
| 141 | +make -C "$MACIOS_PATH"/tools/devops print-variable-value-to-file "FILE=$TMPFILE" VARIABLE=DOTNET_TFM |
| 142 | +DOTNET_TFM=$(cat "$TMPFILE") |
| 143 | +make -C "$MACIOS_PATH"/tools/devops print-variable-value-to-file "FILE=$TMPFILE" VARIABLE=DOTNET_PLATFORMS |
| 144 | +DOTNET_PLATFORMS=$(cat "$TMPFILE") |
| 145 | +rm -f "$TMPFILE" |
| 146 | + |
| 147 | +BINARIES_BRANCH=$DOTNET_TFM-xcode$XCODE_VERSION |
| 148 | + |
| 149 | +echo "${BACKGROUND_COLOR}Copying assemblies to the branch ${BRANCH_COLOR}${BINARIES_BRANCH}${BACKGROUND_COLOR} in the binaries repository (${PATH_COLOR}${APIDROP_REPOSITORY}${BACKGROUND_COLOR})...${CLEAR}" |
| 150 | +cd "$APIDROP_REPOSITORY" |
| 151 | +git checkout master |
| 152 | +git pull |
| 153 | +if ! git checkout -b "$BINARIES_BRANCH"; then |
| 154 | + echo "${RED}Failed to checkout the branch $BRANCH_COLOR$BINARIES_BRANCH$RED in $PATH_COLOR$APIDROP_REPOSITORY$RED - if the branch already exists, please delete it first.$CLEAR" |
| 155 | + exit 1 |
| 156 | +fi |
| 157 | +mkdir -p "$APIDROP_REPOSITORY/dotnet-macios/" |
| 158 | + |
| 159 | +cd "$MACIOS_PATH" |
| 160 | + |
| 161 | +NETVERSION=${DOTNET_TFM//net/} |
| 162 | +COMMIT_MESSAGE="Add updated assemblies for .NET $NETVERSION:" |
| 163 | +IFS=' '; for platform in $DOTNET_PLATFORMS; do |
| 164 | + PLATFORM_UPPERCASE=$(echo "$platform" | tr '[:lower:]' '[:upper:]') |
| 165 | + PLATFORM_LOWERCASE=$(echo "$platform" | tr '[:upper:]' '[:lower:]') |
| 166 | + |
| 167 | + OSVERSION=$(grep "^${PLATFORM_UPPERCASE}_NUGET_OS_VERSION=" Make.versions | sed 's/.*=//') |
| 168 | + COMMIT_MESSAGE="$COMMIT_MESSAGE $platform $OSVERSION," |
| 169 | + |
| 170 | + DIR=$APIDROP_REPOSITORY/dotnet-macios/net-$PLATFORM_LOWERCASE-$OSVERSION-$NETVERSION |
| 171 | + mkdir -p "$DIR" |
| 172 | + cp "_build/Microsoft.$platform.Ref.net${NETVERSION}_$OSVERSION/ref/net$NETVERSION/Microsoft.$platform.dll" "$DIR/" |
| 173 | + cp "_build/Microsoft.$platform.Ref.net${NETVERSION}_$OSVERSION/ref/net$NETVERSION/Microsoft.$platform.xml" "$DIR/" |
| 174 | + echo "${BACKGROUND_COLOR} Copied $PLATFORM_COLOR$platform$BACKGROUND_COLOR assemblies to $PATH_COLOR$DIR$CLEAR" |
| 175 | +done |
| 176 | + |
| 177 | +# remove the last character (",") |
| 178 | +COMMIT_MESSAGE="${COMMIT_MESSAGE/%?}" |
| 179 | + |
| 180 | +echo "${BACKGROUND_COLOR}Creating the commit in the binaries repository (${PATH_COLOR}${APIDROP_REPOSITORY}${BACKGROUND_COLOR})...${CLEAR}" |
| 181 | +cd "$APIDROP_REPOSITORY/dotnet-macios/" |
| 182 | +git add . |
| 183 | +git commit -m "$COMMIT_MESSAGE" |
| 184 | + |
| 185 | +if test -n "$PUSH"; then |
| 186 | + git push |
| 187 | + echo "${BACKGROUND_COLOR}Pushed a commit with the updated assemblies to the ${BRANCH_COLOR}$BINARIES_BRANCH${BACKGROUND_COLOR} branch in ${PATH_COLOR}${APIDROP_REPOSITORY}${BACKGROUND_COLOR}.${CLEAR}" |
| 188 | + echo "${BACKGROUND_COLOR}A commit has been created and pushed in ${PATH_COLOR}${APIDROP_REPOSITORY}${BACKGROUND_COLOR}.${CLEAR}" |
| 189 | +else |
| 190 | + echo "${BACKGROUND_COLOR}A commit that is ready to be pushed has been created in ${PATH_COLOR}${APIDROP_REPOSITORY}${BACKGROUND_COLOR}.${CLEAR}" |
| 191 | +fi |
| 192 | + |
| 193 | +echo "${BACKGROUND_COLOR}Please read the instructions (${LINK_COLOR}update-api-docs.md${BACKGROUND_COLOR}) for the next steps.${CLEAR}" |
0 commit comments