aboutsummaryrefslogtreecommitdiff
path: root/helpers/llvm-common
blob: 5cf3f4ae2ea871cf020373f2dc57b9e9b16903ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash

# The common script is only meant to be included from other LLVM helper scripts

if [[ $LLVM_SRC = '' ]]; then
  echo "Please, define \$LLVM_SRC"
  exit -1
fi
if [[ $LLVM_BLD = '' ]]; then
  echo "Please, define \$LLVM_BLD"
  exit -1
fi
if [[ $LLVM_GITRW = '' ]]; then
  echo "Please, define \$LLVM_GITRW"
  exit -1
fi
if [[ $LLVM_GITRW = 'yes' ]]; then
  if [[ $LLVM_SVNUSER = '' ]] || [[ $LLVM_GITUSER = '' ]]; then
    echo "Please, define \$LLVM_GITUSER and \$LLVM_SVNUSER when using GITRW=yes"
    echo "GITUSER is your Linaro git user, SVNUSER is your LLVM commit user"
    exit 1
  fi
fi

get_branch() {
  branch=`git rev-parse --abbrev-ref HEAD`
  if [[ $? != 0 ]]; then
    local dir=`pwd`
  	echo "Source dir '$dir' is not in a git repository" 1>&2
	  exit -1
  fi
  echo $branch
}

get_branches() {
  branches=`git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)'`
  if [[ $? != 0 ]]; then
    local dir=`pwd`
  	echo "Source dir '$dir' is not in a git repository" 1>&2
	  exit -1
  fi
  echo $branches
}

safe_run() {
  CMD="$*"
  $CMD
  if [[ $? != 0 ]]; then
	  echo "'$CMD' failed, bailing out"
    exit 1
  fi
}

is_git() {
  test -d `git rev-parse --show-toplevel`/.git
}

is_git_svn() {
  test -f `git rev-parse --show-toplevel`/.git/svn/.metadata
}