blob: 13d681a68c428da6fb37f276603571ff4bf80d76 [file] [log] [blame]
Sergio Slobodrianc2d86fb2017-07-18 20:35:46 -04001#!/bin/bash
Zack Williams41513bf2018-07-07 20:08:35 -07002# 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 Slobodrianc2d86fb2017-07-18 20:35:46 -040015
16tagName=$1
17
18if ( find /src -maxdepth 0 -empty | read v );
19then
20 echo "Error: Must mount Go source code into /src directory"
21 exit 990
22fi
23
24# Grab Go package name
25pkgName="$(go list -e -f '{{.ImportComment}}' 2>/dev/null || true)"
26
27if [ -z "$pkgName" ];
28then
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
45fi
46
47if [ -z "$pkgName" ];
48then
49 echo "Error: Must add canonical import path to root package"
50 exit 992
51fi
52
53# Grab just first path listed in GOPATH
54goPath="${GOPATH%%:*}"
55
56# Construct Go package path
57pkgPath="$goPath/src/$pkgName"
58
59# Set-up src directory tree in GOPATH
60mkdir -p "$(dirname "$pkgPath")"
61
62# Link source dir into GOPATH
63ln -sf /src "$pkgPath"
64
65# change work dir to
66cd $pkgPath
67
68echo "--------------------------------------"
69echo "* Resolve dependencies"
70if [ -e "$pkgPath/vendor" ];
71then
72 echo "unsing vendor folder"
73elif [ -d "$pkgPath/Godeps" ];
74then
75 gpm install
76elif [ -d "$pkgPath/Godeps/_workspace" ];
77then
78 # Add local godeps dir to GOPATH
79 GOPATH=$pkgPath/Godeps/_workspace:$GOPATH
80elif [ -f "$pkgPath/glide.yaml" ];
81then
82 glide install
83else
84 # Get all package dependencies
85 go get -t -d -v ./...
86fi