aboutsummaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorRenato Golin <rengolin@gmail.com>2016-04-26 11:02:23 +0100
committerRenato Golin <rengolin@gmail.com>2016-04-26 11:02:23 +0100
commit94cc104f044261f74fbff3ff587855df1a05f64d (patch)
tree7c6664fdf7e7fab54fea926b1fc6196a09b6540f /helpers
Initial Commit, moving from dev-private and removing private stuff
Diffstat (limited to 'helpers')
-rw-r--r--helpers/README.txt61
-rwxr-xr-xhelpers/git-delete-remote-branch20
-rwxr-xr-xhelpers/git-hist155
-rwxr-xr-xhelpers/git-pull56
-rwxr-xr-xhelpers/git-push42
-rwxr-xr-xhelpers/git-rebase-all49
-rwxr-xr-xhelpers/git-refresh31
-rwxr-xr-xhelpers/git-svn-commit60
-rwxr-xr-xhelpers/git-which-branch12
-rwxr-xr-xhelpers/llvm-arm-dis42
-rwxr-xr-xhelpers/llvm-branch177
-rwxr-xr-xhelpers/llvm-build109
-rwxr-xr-xhelpers/llvm-common60
-rwxr-xr-xhelpers/llvm-doc17
-rwxr-xr-xhelpers/llvm-irtonew22
-rwxr-xr-xhelpers/llvm-lit16
-rwxr-xr-xhelpers/llvm-prepare87
-rwxr-xr-xhelpers/llvm-projs150
-rwxr-xr-xhelpers/llvm-reset28
-rwxr-xr-xhelpers/llvm-sync103
20 files changed, 1297 insertions, 0 deletions
diff --git a/helpers/README.txt b/helpers/README.txt
new file mode 100644
index 0000000..1875f7a
--- /dev/null
+++ b/helpers/README.txt
@@ -0,0 +1,61 @@
+LLVM Development Helpers
+========================
+
+These files do almost all needed actions for developing LLVM/Clang. They
+create the initial source tree, build and test LLVM, coordinate branches
+across repositories, control Git/Svn upstream/origin repositories, etc.
+
+All scripts assume you use one of two development modes:
+
+1. Read-Write Git-Svn Mode:
+
+In this mode, all repositories will be based on Git-Svn and setup that way,
+with the LLVM SVN repo as the source, the official LLVM Git repo as 'upstream',
+a Linaro git repository as 'origin' (populated at prepare phase).
+
+The origin repo is meant to be a back-up and share across Linaro developers,
+and since this is public, even external developers. We may use branches on
+those repos for Jenkins / Buildbot testing in the future.
+
+All commits will be done via Git-Svn (dcommit) and git-svn-commit will check
+if the repo is up-to-date before doing so. It'll also warn if you have more
+than one commit, or if you try to commit from master. The former can be
+forced, but not the latter.
+
+2. Read-Only Git Mode:
+
+In this mode, the prepare script doesn't setup Git-Svn, and relies only on
+LLVM's public Git repo for read-only checkout. You can still have your own
+local branches, but they will be de-coupled from the Linaro git tree (unless
+you cherry-pick or rebase from them manually).
+
+This type of repo is meant for dev boards, benchmarks and stress tests.
+
+Environment Variables
+---------------------
+
+These scripts rely on three environment variables:
+
+LLVM_SRC : The path to the LLVM source directory. All other repos will be
+ checked out relative to it in ($LLVM_SRC/../<project>) and linked
+ to the right place inside $LLVM_SRC. It is recommended that you
+ set it to a place where all source dirs will be, and only those,
+ for example ~/devel/llvm/src/llvm.
+LLVM_BLD : The path to the (out-of-tree) directory for the release+asserts
+ build. It is recommended that you set it two levels down from the
+ source dirs, so you can have multiple build directories (debug,
+ no-asserts, lld, etc), example ~/devel/llvm/build/llvm.
+LLVM_GITRW : Git-Read-Write mode, which also means using Git-Svn or not.
+ Values can be 'yes' or 'no'.
+
+Dependencies
+------------
+
+In order to fully use these scripts, you're going to need to install a few
+dependencies. Since people use different Linux distributions, the scripts
+don't even try to install that automatically. The dependencies are:
+
+Scripts/Build: libjson-perl cmake ninja-build perl python2.7 ccache
+LLVM: libxml2-dev zlib1g-dev libtinfo-dev python-sphinx binutils-gold
+Test-Suite: python-virtualenv bison groff gawk
+
diff --git a/helpers/git-delete-remote-branch b/helpers/git-delete-remote-branch
new file mode 100755
index 0000000..4d03a12
--- /dev/null
+++ b/helpers/git-delete-remote-branch
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+
+# This script removes a remote branch. Not that it's hard to do it, but
+# it's a very obtuse syntax from git and not straightforward. It's also
+# good to have some safety checks.
+#
+# Syntax: git-delete-remote-branch <remote> <branch>
+
+remote=$1
+branch=$2
+if [[ $remote = 'upstream' ]]; then
+ echo "Remote cannot be upstream"
+ exit 1
+fi
+if [[ $branch = 'master' ]]; then
+ echo "Branch cannot be master"
+ exit 1
+fi
+
+git push $remote :$branch
diff --git a/helpers/git-hist b/helpers/git-hist
new file mode 100755
index 0000000..8feed74
--- /dev/null
+++ b/helpers/git-hist
@@ -0,0 +1,155 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Cwd;
+
+my (@data, @authors, @repos, @changed) = ((), (), (), ());
+# Syntax: git-hist [author (default: whoami)] [number of weeks (default 10 / all 0)]";
+my $author = `whoami`;
+my $weeks = 10;
+my $rootdir = getcwd;
+my $totalcommits = 0;
+if (scalar @ARGV) {
+ foreach my $arg (@ARGV) {
+ if ($arg =~ /^\d+$/) {
+ $weeks = $arg;
+ } else {
+ $author = $arg;
+ }
+ }
+}
+chomp($author);
+
+# Make sure there are repositories to use
+if (-d ".git") {
+ push @repos, ".";
+} else {
+ opendir(my $dh, ".") || die "can't open local dir: $!";
+ @repos = grep { /^[^\.]/ && -d "$_/.git" } readdir($dh);
+ closedir $dh;
+}
+die "Directory (or subs) not git repo\n" unless (scalar @repos);
+&main();
+exit;
+
+#####################################################
+sub main() {
+ # Each week
+ my $week = 0;
+ while ($week <= $weeks) {
+ # Adjust for non-zero week list
+ $week++ if ($weeks != 0 and $week == 0);
+ print "\rParsing week: $week" if $week;
+ my $commits = 0;
+ # For each repo
+ for my $repo (@repos) {
+ #print "REPO: $repo\n";
+ my $log = &get_weeklog($repo, $author, $week);
+ #print "LOG: [$log]\n";
+ my $this = &get_commits($log);
+ #print "COMMITS: $this\n";
+ if ($this and ! &find($repo, \@changed)) {
+ #print "ADDING REPO\n";
+ push @changed, $repo;
+ }
+ &get_authors($log);
+ $commits += $this;
+ }
+ push @data, $commits;
+ last if ($weeks == 0);
+ $week++;
+ }
+ print "\n\n";
+
+ # Log
+ &print_report();
+}
+
+######################
+sub print_report() {
+ return if ($weeks > 0 && scalar @data != $weeks);
+
+ # Weekly histogram
+ for my $week (0..$weeks-1) {
+ printf("%02d week [%02d]: ", $week, $data[$week]);
+ for (1..$data[$week]) {
+ print "*";
+ }
+ print "\n";
+ }
+
+ # Summary
+ print "\nTotal commits: ";
+ printf("%3d", $totalcommits);
+ print "\n Repositories: ";
+ printf("%3d ", scalar @changed);
+ &dump(\@changed);
+ print "\n Authors: ";
+ printf("%3d ", scalar @authors);
+ &dump(\@authors);
+ print "\n";
+}
+
+######################
+sub get_weeklog() {
+ my ($repo, $author, $week) = @_;
+ # Author
+ my $cmd = "git shortlog -s -n ".
+ "--author='$author' ";
+ # And week (if available)
+ if ($week) {
+ my $prev = $week-1;
+ $cmd .= "--since='$week.week' ".
+ "--until='$prev.week'";
+ }
+ # Run command
+ chdir($repo);
+ my $log = `$cmd`;
+ chdir($rootdir);
+ return $log;
+}
+
+######################
+sub get_commits() {
+ my ($log) = @_;
+ my $commits = 0;
+ foreach my $line (split(/\n/, $log)) {
+ my ($this) = ($line =~ /(\d+)/);
+ $commits += $this;
+ }
+ $totalcommits += $commits;
+ return $commits;
+}
+
+######################
+sub get_authors() {
+ my ($log) = @_;
+ foreach my $line (split(/\n/, $log)) {
+ my ($author) = ($line =~ /\d+\s+(\w.*)/);
+ if (!&find($author, \@authors)) {
+ push @authors, $author;
+ }
+ }
+}
+
+######################
+sub find() {
+ my ($elm, $array) = @_;
+ foreach my $e (@$array) {
+ return 1 if ($e eq $elm);
+ }
+ return 0;
+}
+
+######################
+sub dump() {
+ my ($array) = @_;
+ return if (!scalar @{$array});
+ my $out = "";
+ foreach my $i (@$array) {
+ $out .= "$i, ";
+ }
+ $out =~ s/, $//;
+ print $out;
+}
diff --git a/helpers/git-pull b/helpers/git-pull
new file mode 100755
index 0000000..3dbd3e1
--- /dev/null
+++ b/helpers/git-pull
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+
+# This script pulls a specific branch from the origin repository, making sure
+# not to keep the prefix. If the branch already exists, try to merge. If not,
+# check out from origin.
+#
+# Syntax: git-pull linaro-local/[branch] -f
+
+. llvm-common
+
+branch=$1
+if [[ $branch = '' ]]; then
+ branch=`get_branch`
+fi
+force=$2
+if [[ $force != '-f' ]]; then
+ force=
+fi
+
+if [[ $branch = 'master' ]]; then
+ echo "Can't pull the master branch."
+ echo "Use git-refresh instead."
+ exit 1
+fi
+
+prefix="linaro-local/"
+if echo $branch | grep -q linaro-local; then
+ prefix=""
+fi
+
+safe_run git-refresh
+
+if git branch -a | not grep -q $branch; then
+ echo "Branch '$branch' doesn't exist in this repository"
+ exit 2
+fi
+
+# If the branch exists already, merge
+if git branch | grep -q $branch; then
+ if [[ $force = '-f' ]]; then
+ echo " + Force check out $branch"
+ safe_run git checkout master
+ safe_run git branch -D $branch
+ safe_run git checkout -b $branch origin/$prefix$branch
+ exit 0
+ fi
+
+ echo " + Merging the origin branch..."
+ if not git merge --ff-only origin/$prefix$branch; then
+ echo "Error merging the branch. Use -f to force."
+ exit 1
+ fi
+# If not, just check out the branch
+else
+ safe_run git checkout -b $branch origin/$prefix$branch
+fi
diff --git a/helpers/git-push b/helpers/git-push
new file mode 100755
index 0000000..2869dcf
--- /dev/null
+++ b/helpers/git-push
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+
+# This script pushes the current branch to the origin repository.
+# As an added bonus, it refreshes the local master branch from
+# the origin, to make sure your branch is in sync with the master of the
+# repo you're pushing to.
+#
+# Syntax: git-push [branch (default=current)]
+
+. llvm-common
+
+branch=
+if [[ $1 != '' ]]; then
+ if [[ `git branch | grep $1` = '' ]]; then
+ echo "Branch '$1' doesn't exist in this repository"
+ exit 2
+ fi
+ branch=$1
+else
+ branch=`get_branch`
+fi
+
+if [[ $branch = 'master' ]]; then
+ echo "Can't push the master branch."
+ echo "Use git-refresh instead."
+ exit 1
+fi
+
+prefix="linaro-local/"
+if echo $branch | grep -q linaro-local; then
+ prefix=""
+fi
+
+echo " ++ Refresh Master from Upstream"
+safe_run git-refresh
+
+echo " ++ Rebase to new master"
+safe_run git checkout $branch
+safe_run git rebase master
+
+echo " ++ Push $branch to Origin"
+safe_run git push -u origin +$branch:$prefix$branch
diff --git a/helpers/git-rebase-all b/helpers/git-rebase-all
new file mode 100755
index 0000000..6b09246
--- /dev/null
+++ b/helpers/git-rebase-all
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+# This script rebases all branches based on the current master. It does not
+# pull upstream master beforehand. If you need a fresh master, use git-refresh.
+# If you want to rebase only one branch, use the first argument for that.
+# To protect broken branches from being merged (and forcing a manual merge),
+# rename it to <name>-disabled and it'll be skipped.
+#
+# Syntax: git-rebase-all [branch (default=all)]
+
+. llvm-common
+
+echo "Rebasing all branches"
+branch=`get_branch`
+
+if [[ `git diff | head -1` != '' ]]; then
+ echo "You have uncommitted changes in your repo, bailing"
+ echo "Please, stash your changes and run this script again"
+ exit 2
+fi
+
+if [[ $1 != '' ]]; then
+ if [[ `git branch | grep $1` = '' ]]; then
+ echo "Branch '$1' doesn't exist in this repository"
+ exit 3
+ fi
+ branch=$1
+fi
+
+branches=`get_branches`
+for br in $branches; do
+ if [[ $br != 'master' && `echo $br | grep "^disabled"` == '' ]]; then
+ safe_run git checkout $br
+ git rebase master
+ if [[ $? != 0 ]]; then
+ echo "Rebase failed, aborting rebase..."
+ safe_run git rebase --abort
+ safe_run git checkout master
+ exit 1
+ fi
+ safe_run git checkout master
+ fi
+done
+
+final_branch=`get_branch`
+if [[ $branch != $final_branch ]]; then
+ echo "Back to original branch"
+ safe_run git checkout $branch
+fi
diff --git a/helpers/git-refresh b/helpers/git-refresh
new file mode 100755
index 0000000..d27fea5
--- /dev/null
+++ b/helpers/git-refresh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+# This script refreshes the local repository with the contents of the
+# upstream repository. The main usage of this is to pull the
+# master branch, and sync git-svn if necessary.
+#
+# Syntax: git-refresh [all]
+
+. llvm-common
+
+# Update from origin to upstream
+safe_run git checkout master
+echo " + Fetching origin..."
+safe_run git fetch origin
+if is_git_svn; then
+ echo " + Rebasing SVN master..."
+ safe_run git svn rebase -l
+else
+ echo " + Rebasing master..."
+ safe_run git pull
+fi
+
+# Fetch all other remotes
+if [[ $1 = 'all' ]]; then
+ for remote in `git remote`; do
+ if [ "$remote" != "origin" ]; then
+ echo " + Fetching remote $remote..."
+ safe_run git fetch $remote
+ fi
+ done
+fi
diff --git a/helpers/git-svn-commit b/helpers/git-svn-commit
new file mode 100755
index 0000000..49cb0d3
--- /dev/null
+++ b/helpers/git-svn-commit
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+
+# This script commits to SVN via Git-Svn dcommit. It also adds some checks to
+# make sure you're not trying to commit from master, and warns about multiple
+# commits, as they're not always intentional and could mean you're trying to
+# commit from the wrong branch.
+#
+# The script will refresh your master and branches to make sure you have an
+# up-to-date branch before committing, as that would mess up your local svn
+# setup or would at least block your commit from going through.
+
+. llvm-common
+
+force=no
+if [[ $1 = '-f' ]]; then
+ force=yes
+fi
+
+branch=`get_branch`
+if [[ $branch = 'master' ]]; then
+ echo " --- Can't commit master branch"
+ exit 1
+fi
+revs=`git log --pretty=oneline --abbrev-commit --graph --decorate | grep -n master | head -1 | cut -d ":" -f 1`
+revs=$((revs-1))
+if [[ $revs = 0 ]]; then
+ echo " --- No patches in current branch"
+ exit 1
+fi
+if [[ $revs != 1 && $force != 'yes' ]]; then
+ echo " --- Too many patches in current branch, use -f to force commit"
+ exit 1
+fi
+
+# Prepare
+safe_run git-refresh
+safe_run git checkout $branch
+safe_run git rebase master
+
+# Actuall SVN commit. Try to recover once.
+git svn dcommit
+if [[ $? != 0 ]]; then
+ echo " == SVN COMMIT ERROR =="
+ # If we're in the base dir, try it again.
+ if [ -d .git/svn ]; then
+ echo "We're in base dir, cleaning SVN info and trying again"
+ rm -rf .git/svn
+ safe_run git svn rebase
+ safe_run git svn dcommit
+ else
+ echo "Not in base dir, won't try anything. But if you"
+ echo "saw the message 'resource out of date', remove"
+ echo "the .git/svn directory and trying again."
+ exit 1
+ fi
+fi
+
+# Refresh / rebase to avoid future conflicts
+safe_run git-refresh
+safe_run git-rebase-all
diff --git a/helpers/git-which-branch b/helpers/git-which-branch
new file mode 100755
index 0000000..6ff2cc3
--- /dev/null
+++ b/helpers/git-which-branch
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+
+# Simple wrapper for getting the current branch on a git repo.
+
+. llvm-common
+
+if is_git > /dev/null 2>&1; then
+ get_branch
+else
+ echo "You're not in a git repository"
+ exit 1
+fi
diff --git a/helpers/llvm-arm-dis b/helpers/llvm-arm-dis
new file mode 100755
index 0000000..a0267bf
--- /dev/null
+++ b/helpers/llvm-arm-dis
@@ -0,0 +1,42 @@
+#!/usr/bin/env perl
+
+# This script uses llvm-mc to disassemble byte patterns into possible
+# x86/x86_64/arm/aarch64 instructions, trying to find a way to represent
+# that in any of the instruction sets.
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+#vpush-vpop.s:@ CHECK-ARM: vpop {s8, s9, s10, s11, s12} @ encoding: [0x05,0x4a,0xbd,0xec]
+#vpush-vpop.s:@ CHECK-THUMB: vpush {d8, d9, d10, d11, d12} @ encoding: [0x2d,0xed,0x0a,0x8b]
+my $syntax = "Syntax: $0 0xFFFF(FFFF)\n";
+my @hexs = &fix_endian($ARGV[0]);
+#die Dumper \@hexs;
+
+foreach (@hexs) {
+ my $code = $_->{'code'};
+ my $arch = $_->{'arch'};
+ print "$arch: $code: ";
+ print `echo "$code" | llvm-mc -disassemble -triple $arch`;
+}
+
+sub fix_endian() {
+ my ($hex) = @_;
+
+ my ($a, $b, $c, $d) = ($hex =~ /^0?x?(\w{2})(\w{2})(\w{0,2})(\w{0,2})$/);
+ print "$a $b $c $d\n";
+ die $syntax unless $a and $b; # at least two bytes
+ die $syntax if $c and not $d; # two or four bytes
+ # ARM/T2/x86
+ if ($c) {
+ return (
+ { 'code' => "0x$d 0x$c 0x$b 0x$a", 'arch' => "armv7" },
+ { 'code' => "0x$b 0x$a 0x$d 0x$c", 'arch' => "thumbv7" },
+ { 'code' => "0x$d 0x$c 0x$b 0x$a", 'arch' => "i686" },
+ { 'code' => "0x$d 0x$c 0x$b 0x$a", 'arch' => "x86_64" }
+ );
+ } else {
+ return ( { 'code' => "0x$b 0x$a", 'arch' => "thumb" } );
+ }
+}
diff --git a/helpers/llvm-branch b/helpers/llvm-branch
new file mode 100755
index 0000000..3ed3cef
--- /dev/null
+++ b/helpers/llvm-branch
@@ -0,0 +1,177 @@
+#!/usr/bin/env bash
+
+# This script helps you check which branches are checked out on git and make
+# sure they're coherent with the feature you're developing. For instance,
+# if a feature spans across both LLVM and Clang, you could name the branch on
+# each repo the same and use this script to seamlessly move between them.
+
+# Syntax: llvm-branch [-d] [branch]
+# -d: delete chosen branch
+# branch: find on llvm and clang and check it out
+# Without arguments, the script lists all branches and highlight the current one
+
+. llvm-common
+
+function print_branches() {
+ local current=$1
+ shift
+ local space=0
+ for each in $*; do
+ if [[ $space = 1 ]]; then
+ echo -n " "
+ fi
+ if [[ $each = $current ]]; then
+ echo -n "[$each]"
+ else
+ echo -n $each
+ fi
+ space=1
+ done
+}
+
+function has() {
+ if [[ $1 = '' || $2 = '' ]]; then
+ echo no
+ return
+ fi
+ local item=$1
+ shift
+ for each in $*; do
+ if [[ $item = $each ]]; then
+ echo yes
+ return
+ fi
+ done
+ echo no
+}
+
+function switch() {
+ SRC=$1
+ branch=$2
+ in=$3
+ if [ -d $SRC ]; then
+ cd $SRC
+ pwd
+ if [[ $in = 'yes' ]]; then
+ if [[ $DEL = '' ]]; then
+ safe_run git checkout $branch
+ else
+ safe_run git checkout master
+ safe_run git branch $DEL $branch
+ fi
+ else
+ if [[ $DEL = '' ]]; then
+ safe_run git checkout master
+ fi
+ fi
+ fi
+}
+
+# Gather info
+cd $LLVM_SRC
+llvm_branch=`get_branch`
+llvm_branches=`get_branches`
+
+CLANG_SRC=$LLVM_SRC/tools/clang
+if [ -d $CLANG_SRC ]; then
+ cd $CLANG_SRC
+ clang_branch=`get_branch`
+ clang_branches=`get_branches`
+fi
+
+RT_SRC=$LLVM_SRC/projects/compiler-rt
+if [ -d $RT_SRC ]; then
+ cd $RT_SRC
+ rt_branch=`get_branch`
+ rt_branches=`get_branches`
+fi
+
+CXX_SRC=$LLVM_SRC/projects/libcxx
+if [ -d $CXX_SRC ]; then
+ cd $CXX_SRC
+ cxx_branch=`get_branch`
+ cxx_branches=`get_branches`
+fi
+
+CXXABI_SRC=$LLVM_SRC/projects/libcxxabi
+if [ -d $CXXABI_SRC ]; then
+ cd $CXXABI_SRC
+ cxxabi_branch=`get_branch`
+ cxxabi_branches=`get_branches`
+fi
+
+UNW_SRC=$LLVM_SRC/projects/libunwind
+if [ -d $UNW_SRC ]; then
+ cd $UNW_SRC
+ unw_branch=`get_branch`
+ unw_branches=`get_branches`
+fi
+
+# Delete chosen branch
+DEL=''
+if [[ $1 = '-d' || $1 = '-D' ]]; then
+ DEL=$1
+ shift
+fi
+
+# No branch chosen, list all
+if [[ $1 = '' ]]; then
+ echo -n "LLVM branches: "
+ print_branches $llvm_branch $llvm_branches
+ echo
+ if [ -d $CLANG_SRC ]; then
+ echo -n "Clang branches: "
+ print_branches $clang_branch $clang_branches
+ echo
+ fi
+ if [ -d $RT_SRC ]; then
+ echo -n "Compiler-RT branches: "
+ print_branches $rt_branch $rt_branches
+ echo
+ fi
+ if [ -d $CXX_SRC ]; then
+ echo -n "LibC++ branches: "
+ print_branches $cxx_branch $cxx_branches
+ echo
+ fi
+ if [ -d $CXXABI_SRC ]; then
+ echo -n "LibC++ABI branches: "
+ print_branches $cxxabi_branch $cxxabi_branches
+ echo
+ fi
+ if [ -d $UNW_SRC ]; then
+ echo -n "LibUnwind branches: "
+ print_branches $unw_branch $unw_branches
+ echo
+ fi
+ exit
+fi
+
+# Search for branch name
+branch=$1
+
+if [[ $DEL = 1 && $branch = 'master' ]]; then
+ echo "Cannot delete the master branch"
+ exit 1
+fi
+
+# Check which projects the branch is
+in_llvm=`has $branch $llvm_branches`
+in_clang=`has $branch $clang_branches`
+in_rt=`has $branch $rt_branches`
+in_cxx=`has $branch $cxx_branches`
+in_cxxabi=`has $branch $cxxabi_branches`
+in_unw=`has $branch $unw_branches`
+if [[ $in_clang = 'no' && $in_llvm = 'no' && $in_rt = 'no' && \
+ $in_cxx = 'no' && $in_cxxabi = 'no' && $in_unw = 'no' ]]; then
+ echo "Branch $branch doesn't exist on any repository"
+ exit 1
+fi
+
+# DO IT
+switch $LLVM_SRC $branch $in_llvm
+switch $CLANG_SRC $branch $in_clang
+switch $RT_SRC $branch $in_rt
+switch $CXX_SRC $branch $in_cxx
+switch $CXXABI_SRC $branch $in_cxxabi
+switch $UNW_SRC $branch $in_unw
diff --git a/helpers/llvm-build b/helpers/llvm-build
new file mode 100755
index 0000000..8d2fab4
--- /dev/null
+++ b/helpers/llvm-build
@@ -0,0 +1,109 @@
+#!/usr/bin/env bash
+
+# This script helps you build LLVM. It can update the repositories first,
+# run the check-all after and even install it in your system. Since the
+# LLVM tree changes constantly, it's recommended that you run this script
+# with update+check at least once a week, and most importantly, before you
+# begin a big change, to make sure the repos are current and stable.
+
+. llvm-common
+
+## CMD line options and defaults
+CPUs=`grep -c proc /proc/cpuinfo`
+build_dir=$LLVM_BLD
+install_dir=$LLVM_BLD/../../install
+build_type=Release
+shared=
+targets=
+prog=`basename $0`
+syntax="Syntax: $prog [-u(pdate)] [-c(check-all)] [-i(nstall)] [-d(debug)]"
+update=false
+check=false
+master=false
+debug=false
+inst=false
+while getopts "ucimd" opt; do
+ case $opt in
+ u)
+ update=true
+ ;;
+ c)
+ check=true
+ ;;
+ i)
+ inst=true
+ ;;
+ m)
+ master=true
+ ;;
+ d)
+ debug=true
+ build_dir=$LLVM_BLD/../debug
+ ;;
+ *)
+ echo $syntax
+ exit 1
+ ;;
+ esac
+done
+
+## Run llvm-sync before
+if $update; then
+ echo " + Updating Repositories"
+ safe_run llvm-sync -a
+fi
+
+## Make sure all branches are on master
+if $master; then
+ echo " + Checking out master"
+ safe_run llvm-branch master
+fi
+
+## Choose between make and ninja
+make=make
+ninja=
+if which ninja 2>&1 > /dev/null; then
+ make=ninja
+ ninja="-G Ninja"
+fi
+
+## Debug mode, make it lighter
+if $debug; then
+ build_type=Debug
+ shared=-DBUILD_SHARED_LIBS=True
+ targets=-DLLVM_TARGETS_TO_BUILD="ARM;X86;AArch64"
+fi
+
+## Make sure sure build dir is there
+if [ ! -d $build_dir ]; then
+ mkdir -p $builddir
+fi
+cd $build_dir
+
+## Re-run CMake file files are damaged / not there
+if [ ! -f build.ninja ] && [ ! -f Makefile ]; then
+ echo " + Configuring Build"
+ safe_run cmake $ninja $LLVM_SRC \
+ -DCMAKE_BUILD_TYPE=$build_type \
+ -DLLVM_BUILD_TESTS=True \
+ -DLLVM_ENABLE_ASSERTIONS=True \
+ -DPYTHON_EXECUTABLE=/usr/bin/python2 \
+ -DCMAKE_INSTALL_PREFIX=$install_dir \
+ $targets $shared
+fi
+
+## Build
+echo " + Building LLVM"
+safe_run $make -j$CPUs
+
+## Check
+if $check; then
+ echo " + Running Tests"
+ safe_run $make check-all
+fi
+
+## Install
+if $inst; then
+ echo " + Installing on the System"
+ safe_run $make install
+fi
diff --git a/helpers/llvm-common b/helpers/llvm-common
new file mode 100755
index 0000000..5cf3f4a
--- /dev/null
+++ b/helpers/llvm-common
@@ -0,0 +1,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
+}
diff --git a/helpers/llvm-doc b/helpers/llvm-doc
new file mode 100755
index 0000000..d8d507f
--- /dev/null
+++ b/helpers/llvm-doc
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+# Helper script for re-compiling the documentation after changes.
+
+if [ ! -f index.rst ]; then
+ echo "You must be at the LLVM Docs directory to use this script"
+ exit -1
+fi
+
+SYNTAX="`basename $0` <doc.rst>"
+if [[ $1 = '' ]]; then
+ echo $SYNTAX
+ exit -1
+fi
+DOC=$1
+
+sphinx-build -b html -d _build/doctrees . _build/html $DOC
diff --git a/helpers/llvm-irtonew b/helpers/llvm-irtonew
new file mode 100755
index 0000000..4e798a4
--- /dev/null
+++ b/helpers/llvm-irtonew
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+# This script moves IR from the old syntax to the new one.
+# The three biggest changes is to:
+# 1. Move "load type object" to "load type, type* object"
+# 2. Move "GEP type object" to "GEP type, type* object"
+# 3. Clean up metadata
+
+if (!$ARGV[0] or !-f $ARGV[0]) {
+ die "Syntax: llvm-irtonew file.ll\n";
+}
+open(FH, $ARGV[0]) || die "Can't open file '$ARGV[0]': $!\n";
+foreach my $line (<FH>) {
+ $line =~ s/ load (.*)\* %/ load $1, $1* %/;
+ $line =~ s/ getelementptr (.*)\* %/ getelementptr $1, $1* %/;
+ $line =~ s/,? ?!.*//;
+ print $line;
+}
+close FH;
diff --git a/helpers/llvm-lit b/helpers/llvm-lit
new file mode 100755
index 0000000..32143fb
--- /dev/null
+++ b/helpers/llvm-lit
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+# Helper script for running a single LIT test inside the build tree.
+
+if [[ $1 = '' ]]; then
+ echo "Syntax: $0 test-dir"
+ exit -1
+fi
+DIR=$1
+
+$LLVM_SRC/utils/lit/lit.py \
+ --param build_mode=. \
+ -sv \
+ --param llvm_site_config=$LLVM_BLD/test/lit.site.cfg \
+ --param llvm_unit_site_config=$LLVM_BLD/test/Unit/lit.site.cfg \
+ $DIR
diff --git a/helpers/llvm-prepare b/helpers/llvm-prepare
new file mode 100755
index 0000000..204bfa4
--- /dev/null
+++ b/helpers/llvm-prepare
@@ -0,0 +1,87 @@
+#!/usr/bin/env bash
+
+# This script creates the source tree as the other LLVM scripts would like to
+# find. It's recommended that you use this script before all, and keep the
+# format correct, so all the other scripts work accordingly. This script
+# honours the LLVM_GITRW requirement and creates the appropriate type.
+
+. llvm-common
+
+function prepare() {
+ src=$1
+ link=$2
+ origin=$3
+ svn=$4
+ dir=`basename $src`
+ # Clone Linaro repo
+ if [ ! -d $src/.git ]; then
+ mkdir -p $src
+ cd $src/..
+ safe_run git clone $origin $dir
+ fi
+ # Link with upstream SVN
+ if [[ $LLVM_GITRW = 'yes' && ! -d $src/.git/svn ]]; then
+ cd $src
+ safe_run git svn init $svn --username=$LLVM_SVNUSER
+ safe_run git config svn-remote.svn.fetch :refs/remotes/origin/master
+ safe_run git svn fetch
+ fi
+ # Create the symlink into LLVM's source
+ if [[ $link != "no" && ! -x $link ]]; then
+ cd $src
+ ln -sf $src $link
+ fi
+}
+
+echo " + Setting up LLVM"
+prepare $LLVM_SRC $LLVM_SRC \
+ ssh://$LLVM_GITUSER@review.linaro.org:29418/toolchain/llvm/llvm \
+ https://llvm.org/svn/llvm-project/llvm/trunk
+echo " + Setting up Clang"
+prepare $LLVM_SRC/../clang $LLVM_SRC/tools/clang \
+ ssh://$LLVM_GITUSER@review.linaro.org:29418/toolchain/llvm/clang \
+ https://llvm.org/svn/llvm-project/cfe/trunk
+echo " + Setting up Clang Tools Extra"
+prepare $LLVM_SRC/../clang-tools-extra $LLVM_SRC/../clang/tools/extra \
+ ssh://$LLVM_GITUSER@review.linaro.org:29418/toolchain/llvm/clang-tools-extra \
+ https://llvm.org/svn/llvm-project/clang-tools-extra/trunk
+echo " + Setting up Compiler-RT"
+prepare $LLVM_SRC/../compiler-rt $LLVM_SRC/projects/compiler-rt \
+ ssh://$LLVM_GITUSER@review.linaro.org:29418/toolchain/llvm/compiler-rt \
+ https://llvm.org/svn/llvm-project/compiler-rt/trunk
+echo " + Setting up LLD Linker"
+prepare $LLVM_SRC/../lld $LLVM_SRC/tools/lld \
+ ssh://$LLVM_GITUSER@review.linaro.org:29418/toolchain/llvm/lld \
+ https://llvm.org/svn/llvm-project/lld/trunk
+echo " + Setting up LibC++"
+prepare $LLVM_SRC/../libcxx no \
+ ssh://$LLVM_GITUSER@review.linaro.org:29418/toolchain/llvm/libcxx \
+ https://llvm.org/svn/llvm-project/libcxx/trunk
+echo " + Setting up LibC++ABI"
+prepare $LLVM_SRC/../libcxxabi no \
+ ssh://$LLVM_GITUSER@review.linaro.org:29418/toolchain/llvm/libcxxabi \
+ https://llvm.org/svn/llvm-project/libcxxabi/trunk
+echo " + Setting up LibUnwind"
+prepare $LLVM_SRC/../libunwind $LLVM_SRC/projects/libunwind \
+ ssh://$LLVM_GITUSER@review.linaro.org:29418/toolchain/llvm/libunwind \
+ https://llvm.org/svn/llvm-project/libunwind/trunk
+echo " + Setting up LLDB Debugger"
+prepare $LLVM_SRC/../lldb $LLVM_SRC/tools/lldb \
+ ssh://$LLVM_GITUSER@review.linaro.org:29418/toolchain/llvm/lldb \
+ https://llvm.org/svn/llvm-project/lldb/trunk
+echo " + Setting up Test Suite"
+prepare $LLVM_SRC/../test-suite $LLVM_SRC/projects/test-suite \
+ ssh://$LLVM_GITUSER@review.linaro.org:29418/toolchain/llvm/test-suite \
+ https://llvm.org/svn/llvm-project/test-suite/trunk
+echo " + Setting up LNT Test harness"
+prepare $LLVM_SRC/../lnt $LLVM_SRC/projects/lnt \
+ ssh://$LLVM_GITUSER@review.linaro.org:29418/toolchain/llvm/lnt \
+ https://llvm.org/svn/llvm-project/lnt/trunk
+echo " + Setting up Zorg Buildbot Config"
+prepare $LLVM_SRC/../zorg $LLVM_SRC/projects/zorg \
+ ssh://$LLVM_GITUSER@review.linaro.org:29418/toolchain/llvm/zorg \
+ https://llvm.org/svn/llvm-project/zorg/trunk
+
+mkdir -p $LLVM_BLD
+
+echo " + Done"
diff --git a/helpers/llvm-projs b/helpers/llvm-projs
new file mode 100755
index 0000000..e0ff2da
--- /dev/null
+++ b/helpers/llvm-projs
@@ -0,0 +1,150 @@
+#!/usr/bin/env bash
+
+# This script keeps track of all projects that are linked to the llvm src
+# directory. It can detect, enable, disable and map to specific projects,
+# so different builds get to see the source dir as they saw originally.
+
+. llvm-common
+
+prog=`basename $0`
+syntax() {
+ echo "Syntax: $prog {+/-}[clang|rt|libs|tools|test]"
+ echo " noarg: list linked projects"
+ echo " {+/-}: link / unlik projects (default: link)"
+}
+
+# Dirs and links into LLVM
+clang_dir=clang
+clang_link=tools/clang
+rt_dir=compiler-rt
+rt_link=projects/compiler-rt
+libcxx_dir=libcxx
+libcxx_link=projects/libcxx
+libcxxabi_dir=libcxxabi
+libcxxabi_link=projects/libcxxabi
+libunwind_dir=libunwind
+libunwind_link=projects/libunwind
+lld_dir=lld
+lld_link=tools/lld
+lldb_dir=lldb
+lldb_link=tools/lldb
+tests_dir=test-suite
+tests_link=projects/test-suite
+
+# Check if link exists
+has() {
+ link=$1
+ [ -s "$LLVM_SRC/$link" ]
+}
+
+# Initialise status
+init() {
+ link=$1
+ if has $link; then
+ echo "true";
+ else
+ echo "false"
+ fi
+}
+
+# Link/Unlink upon need
+update() {
+ dir=$1
+ link=$2
+ need=$3
+ if $need; then
+ ln -sf $LLVM_SRC/../$dir $LLVM_SRC/$link
+ else
+ rm -f $LLVM_SRC/$link
+ fi
+}
+
+# Lists linked projects and quit
+list_all() {
+ echo "Projects linked:"
+ has $clang_link && echo " + Clang"
+ has $rt_link && echo " + Compiler-RT"
+ has $libcxx_link && echo " + LibC++"
+ has $libcxxabi_link && echo " + LibC++abi"
+ has $libunwind_link && echo " + LibUnwind"
+ has $lld_link && echo " + LLD"
+ has $lldb_link && echo " + LLDB"
+ has $tests_link && echo " + Test-Suite"
+ echo
+}
+
+# No args, list
+if [ "$1" = "" ]; then
+ echo "Use $prog -h for options"
+ echo
+ list_all
+ exit
+fi
+
+# Need/not need
+clang=`init $clang_link`
+rt=`init $rt_link`
+libcxx=`init $libcxx_link`
+libcxxabi=`init $libcxxabi_link`
+libunwind=`init $libunwind_link`
+lld=`init $lld_link`
+lldb=`init $lldb_link`
+tests=`init $tests_link`
+
+# Check all needed projects
+while ! test -z $1; do
+ opt=$1
+ sign=${opt:0:1}
+ flag=true
+ if [ "$sign" = "-" ]; then
+ flag=false
+ opt=${opt:1}
+ fi
+ if [ "$sign" = "+" ]; then
+ opt=${opt:1}
+ fi
+
+ case $opt in
+ clang)
+ clang=$flag
+ ;;
+ rt)
+ rt=$flag
+ ;;
+ libs)
+ libcxx=$flag
+ libcxxabi=$flag
+ libunwind=$flag
+ ;;
+ tools)
+ lld=$flag
+ lldb=$flag
+ ;;
+ test)
+ tests=$flag
+ ;;
+ list)
+ list_all
+ exit
+ ;;
+ -h)
+ syntax
+ exit
+ ;;
+ *)
+ syntax
+ exit 1
+ esac
+ shift
+done
+
+# Update links
+update $tests_dir $tests_link $tests
+update $lldb_dir $lldb_link $lldb
+update $lld_dir $lld_link $lld
+update $libunwind_dir $libunwind_link $libunwind
+update $libcxxabi_dir $libcxxabi_link $libcxxabi
+update $libcxx_dir $libcxx_link $libcxx
+update $rt_dir $rt_link $rt
+update $clang_dir $clang_link $clang
+list_all
diff --git a/helpers/llvm-reset b/helpers/llvm-reset
new file mode 100755
index 0000000..f219cd8
--- /dev/null
+++ b/helpers/llvm-reset
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+
+# Helper script for fixing Git-Svn problems.
+
+. llvm-common
+
+reset_git_svn() {
+ name=$1
+ dir=$2
+ if [[ -d $dir && -d $dir/.git/svn ]]; then
+ echo " + Resetting $name"
+ cd $dir
+ rm -rf .git/svn
+ safe_run git svn rebase -l
+ fi
+}
+
+reset_git_svn LLVM $LLVM_SRC
+reset_git_svn Clang $LLVM_SRC/../clang
+reset_git_svn Compiler-RT $LLVM_SRC/../compiler-rt
+reset_git_svn Libc++ $LLVM_SRC/../libcxx
+reset_git_svn Libc++abi $LLVM_SRC/../libcxxabi
+reset_git_svn LibUnwind $LLVM_SRC/../libunwind
+reset_git_svn Linker $LLVM_SRC/../lld
+reset_git_svn Debugger $LLVM_SRC/../lldb
+reset_git_svn LNT $LLVM_SRC/../lnt
+reset_git_svn Zorg $LLVM_SRC/../zorg
+reset_git_svn Test-Suite $LLVM_SRC/../test-suite
diff --git a/helpers/llvm-sync b/helpers/llvm-sync
new file mode 100755
index 0000000..bd46404
--- /dev/null
+++ b/helpers/llvm-sync
@@ -0,0 +1,103 @@
+#!/usr/bin/env bash
+
+# This script checks out all repositories from upstream and pushes master
+# to the origin repo on Linaro's Git server, rebasing all local branches,
+# but *not* pushing them, too.
+
+. llvm-common
+
+function repo_sync () {
+ if [ ! -d $2 ]; then return; fi
+ echo " + Updating $1"
+ cd $2
+ branch=`get_branch`
+ safe_run git-refresh
+ safe_run git-rebase-all $branch
+}
+
+prog=`basename $0`
+syntax="Syntax: $prog [-compiler(r)T] [-(l)ibs] [-Lin(k)er] [-(d)ebugger] [-(t)ests] [-(w)eb pages] [-(a)ll]"
+rt=false
+libs=false
+linker=false
+debug=false
+tests=false
+web=false
+
+while getopts "rlkdtwa" opt; do
+ case $opt in
+ r)
+ rt=true
+ ;;
+ l)
+ libs=true
+ ;;
+ k)
+ linker=true
+ ;;
+ d)
+ debug=true
+ ;;
+ t)
+ tests=true
+ ;;
+ w)
+ web=true
+ ;;
+ a)
+ rt=true
+ libs=true
+ linker=true
+ debug=true
+ tests=true
+ ;;
+ *)
+ echo $syntax
+ exit 1
+ ;;
+ esac
+done
+
+# Compulsory updates
+repo_sync LLVM $LLVM_SRC
+repo_sync Clang $LLVM_SRC/../clang
+
+# Optional updates
+if $rt; then
+ repo_sync RT $LLVM_SRC/../compiler-rt
+fi
+
+if $libs; then
+ repo_sync LibC++ $LLVM_SRC/../libcxx
+ repo_sync LibC++ABI $LLVM_SRC/../libcxxabi
+ repo_sync LibUnwind $LLVM_SRC/../libunwind
+fi
+
+if $linker; then
+ repo_sync Linker $LLVM_SRC/../lld
+fi
+
+if $debug; then
+ repo_sync Debugger $LLVM_SRC/../lldb
+fi
+
+if $tests; then
+ repo_sync Test-Suite $LLVM_SRC/../test-suite
+ repo_sync LNT $LLVM_SRC/../lnt
+ repo_sync Zorg $LLVM_SRC/../zorg
+fi
+
+# These are pure SVN repos, not enabled with -a
+# You have to manually force with -w
+if $web; then
+ if [ -d $LLVM_SRC/../www ]; then
+ echo " + Updating WWW"
+ cd $LLVM_SRC/../www
+ svn up
+ fi
+ if [ -d $LLVM_SRC/../pubs ]; then
+ echo " + Updating Pubs"
+ cd $LLVM_SRC/../pubs
+ svn up
+ fi
+fi