Sergio Slobodrian | c2d86fb | 2017-07-18 20:35:46 -0400 | [diff] [blame] | 1 | #!/bin/bash |
Zack Williams | 41513bf | 2018-07-07 20:08:35 -0700 | [diff] [blame] | 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
Sergio Slobodrian | c2d86fb | 2017-07-18 20:35:46 -0400 | [diff] [blame] | 15 | |
| 16 | tagName=$1 |
| 17 | |
| 18 | if ( find /src -maxdepth 0 -empty | read v ); |
| 19 | then |
| 20 | echo "Error: Must mount Go source code into /src directory" |
| 21 | exit 990 |
| 22 | fi |
| 23 | |
| 24 | # Grab Go package name |
| 25 | pkgName="$(go list -e -f '{{.ImportComment}}' 2>/dev/null || true)" |
| 26 | |
| 27 | if [ -z "$pkgName" ]; |
| 28 | then |
| 29 | if [ -f "/src/glide.yaml" ] |
| 30 | then |
| 31 | pkgName="$(glide name)" |
| 32 | elif [ -f "/src/Godeps/Godeps.json" ] |
| 33 | then |
| 34 | pkgName="$(cat /src/Godeps/Godeps.json | jq --raw-output '.ImportPath')" |
| 35 | else |
| 36 | url=$(git config --get remote.origin.url) |
| 37 | if [[ "$url" == http* ]] |
| 38 | then |
| 39 | pkgName=$(echo ${url} | sed -E 's|https?://(.+)|\1|') |
| 40 | elif [[ "$url" == git@* ]] |
| 41 | then |
| 42 | pkgName=$(echo ${url} | sed -E 's|git@(.+):(.+).git|\1/\2|') |
| 43 | fi |
| 44 | fi |
| 45 | fi |
| 46 | |
| 47 | if [ -z "$pkgName" ]; |
| 48 | then |
| 49 | echo "Error: Must add canonical import path to root package" |
| 50 | exit 992 |
| 51 | fi |
| 52 | |
| 53 | # Grab just first path listed in GOPATH |
| 54 | goPath="${GOPATH%%:*}" |
| 55 | |
| 56 | # Construct Go package path |
| 57 | pkgPath="$goPath/src/$pkgName" |
| 58 | |
| 59 | # Set-up src directory tree in GOPATH |
| 60 | mkdir -p "$(dirname "$pkgPath")" |
| 61 | |
| 62 | # Link source dir into GOPATH |
| 63 | ln -sf /src "$pkgPath" |
| 64 | |
| 65 | # change work dir to |
| 66 | cd $pkgPath |
| 67 | |
| 68 | echo "--------------------------------------" |
| 69 | echo "* Resolve dependencies" |
| 70 | if [ -e "$pkgPath/vendor" ]; |
| 71 | then |
| 72 | echo "unsing vendor folder" |
| 73 | elif [ -d "$pkgPath/Godeps" ]; |
| 74 | then |
| 75 | gpm install |
| 76 | elif [ -d "$pkgPath/Godeps/_workspace" ]; |
| 77 | then |
| 78 | # Add local godeps dir to GOPATH |
| 79 | GOPATH=$pkgPath/Godeps/_workspace:$GOPATH |
| 80 | elif [ -f "$pkgPath/glide.yaml" ]; |
| 81 | then |
| 82 | glide install |
| 83 | else |
| 84 | # Get all package dependencies |
| 85 | go get -t -d -v ./... |
| 86 | fi |