blob: 5a7866827ae128206ee70dae2da66d821e436c4e [file] [log] [blame]
Eric Newberryfe0d0142017-11-29 13:22:48 -07001#!/bin/bash
2
3if [[ -f repos.conf ]]; then
4 source repos.conf
5fi
6
7# Check out the repository of the specified package from Gerrit or a local repository.
8#
9# Parameters:
10# name of package used in repository names (e.g., ndn-cxx or NFD)
11# name of package used in variable names (e.g., NDNCXX or NFD)
12#
13# This function changes the working directory to the directory containing the package source.
14prepare_repo() {
15 local PACKAGE_NAME=$1
16 local PACKAGE_VAR=PACKAGE_$2
17 local PACKAGE_SOURCE=${!PACKAGE_VAR}
18 if [[ -z $PACKAGE_SOURCE ]]; then
19 PACKAGE_SOURCE=branch:master
20 fi
21
22 local SOURCE=${PACKAGE_SOURCE%%:*}
23 local LOCATION=${PACKAGE_SOURCE#*:}
24 if [[ $SOURCE == branch || $SOURCE == gerrit ]]; then
25 if [[ $SOURCE == branch ]]; then
26 local GERRIT_BRANCH=$LOCATION
27 else
28 local GERRIT_CHANGE=${LOCATION%%,*}
29 local GERRIT_PATCHSET=${LOCATION#*,}
30 local GERRIT_BRANCH="refs/changes/$(printf '%02d' $(($GERRIT_CHANGE % 100)))/$GERRIT_CHANGE/$GERRIT_PATCHSET"
31 fi
32
33 echo "Checking out from Gerrit: $GERRIT_BRANCH"
34 cd prepare
35 git init $PACKAGE_NAME
36 cd $PACKAGE_NAME
37 git pull --depth 1 https://gerrit.named-data.net/$PACKAGE_NAME $GERRIT_BRANCH
38 elif [[ $SOURCE == local ]]; then
39 echo "Using local copy of $PACKAGE_NAME"
40 if [[ ! -d packages/$PACKAGE_NAME ]]; then
41 echo "ERROR: No local copy of package $PACKAGE_NAME could be found in prepare"
42 exit 1
43 fi
44 cp -r packages/$PACKAGE_NAME prepare
45 cd prepare/$PACKAGE_NAME
46 else
47 echo "SYNTAX ERROR: Package $PACKAGE_NAME has incorrectly formatted source: $PACKAGE_SOURCE"
48 exit 2
49 fi
50}