File: orig-tar.sh

package info (click to toggle)
llvm-toolchain-snapshot 1%3A13~%2B%2B20210418105309%2Ba0898f0cecc7-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,180,760 kB
  • sloc: cpp: 5,125,598; ansic: 878,822; asm: 532,328; python: 182,254; objc: 71,880; lisp: 29,622; sh: 24,255; f90: 23,940; pascal: 9,361; perl: 7,481; ml: 5,432; awk: 3,523; makefile: 2,734; xml: 953; cs: 573; fortran: 539; javascript: 460
file content (195 lines) | stat: -rwxr-xr-x 6,369 bytes parent folder | download | duplicates (2)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/sh
# This script will create the following tarballs:
# llvm-toolchain-snapshot-3.2_3.2repack.orig-clang.tar.bz2
# llvm-toolchain-snapshot-3.2_3.2repack.orig-clang-extra.tar.bz2
# llvm-toolchain-snapshot-3.2_3.2repack.orig-compiler-rt.tar.bz2
# llvm-toolchain-snapshot-3.2_3.2repack.orig-lld.tar.bz2
# llvm-toolchain-snapshot-3.2_3.2repack.orig-lldb.tar.bz2
# llvm-toolchain-snapshot-3.2_3.2repack.orig-polly.tar.bz2
# llvm-toolchain-snapshot-3.2_3.2repack.orig-openmp.tar.bz2
# llvm-toolchain-snapshot-3.2_3.2repack.orig-libcxx.tar.bz2
# llvm-toolchain-snapshot-3.2_3.2repack.orig-libcxxabi.tar.bz2
# llvm-toolchain-snapshot-3.2_3.2repack.orig.tar.bz2

set -e

# commands:
#  sh 9/debian/orig-tar.sh release/9.x
#  sh 9/debian/orig-tar.sh 9.0.0 rc3
#  sh 9/debian/orig-tar.sh 9.0.1 rc3
# Stable release
#  sh 9/debian/orig-tar.sh 9.0.0 9.0.0


# To create an rc1 release:
# sh 9/debian/orig-tar.sh release/9.x
CURRENT_PATH=$(pwd)
EXPORT_PATH=$(pwd)

if test -n "${JENKINS_HOME}"; then
    # For apt.llvm.org, reuse the same repo
    echo "Built from Jenkins. Will export the repo in $HOME/"
    EXPORT_PATH="$HOME/"
fi

GIT_BASE_URL=https://github.com/llvm/llvm-project
GIT_TOOLCHAIN_CHECK=https://github.com/opencollab/llvm-toolchain-integration-test-suite.git

reset_repo ()
{
    cd $1
    git clean -qfd
    git checkout .
    git remote update > /dev/null
    git reset --hard origin/main > /dev/null
    git clean -qfd
    git checkout main > /dev/null
    git pull
    cd -
}

PATH_DEBIAN="$(pwd)/$(dirname $0)/../"
cd "$PATH_DEBIAN"

git stash && git pull && git stash apply || true

MAJOR_VERSION=$(dpkg-parsechangelog | sed -rne "s,^Version: 1:([0-9]+).*,\1,p")
if test -z "$MAJOR_VERSION"; then
    echo "Could not detect the major version"
    exit 1
fi

CURRENT_VERSION=$(dpkg-parsechangelog | sed -rne "s,^Version: 1:([0-9.]+)(~|-)(.*),\1,p")
if test -z "$CURRENT_VERSION"; then
    echo "Could not detect the full version"
    exit 1
fi

cd - &> /dev/null
echo "MAJOR_VERSION=$MAJOR_VERSION / CURRENT_VERSION=$CURRENT_VERSION"
if test -n "$1"; then
# https://github.com/llvm/llvm-project/tree/release/9.x
# For example: sh 4.0/debian/orig-tar.sh release/9.x
    BRANCH=$1
    if ! echo "$1"|grep -q release/; then
        # The first argument is NOT a branch, means that it is a stable release
        FINAL_RELEASE=true
        EXACT_VERSION=$1
    fi
else
    # No argument, we need trunk
    cd "$PATH_DEBIAN"
    SOURCE=$(dpkg-parsechangelog |grep ^Source|awk '{print $2}')
    cd - &> /dev/null
    if test "$SOURCE" != "llvm-toolchain-snapshot"; then
       echo "Checkout of the main is only available for llvm-toolchain-snapshot"
       exit 1
    fi
    BRANCH="main"
fi

if test -n "$1" -a -n "$2"; then
# https://github.com/llvm/llvm-project/releases/tag/llvmorg-9.0.0
# For example: sh 4.0/debian/orig-tar.sh 4.0.1 rc3
# or  sh 9/debian/orig-tar.sh 9.0.0
    TAG=$2
    RCRELEASE="true"
    EXACT_VERSION=$1
fi

# Update or retrieve the repo
mkdir -p git-archive
cd git-archive
if test -d $EXPORT_PATH/llvm-project; then
    echo "Updating repo in $EXPORT_PATH/llvm-project"
    # Update it
    reset_repo $EXPORT_PATH/llvm-project
else
    # Download it
    echo "Cloning the repo in $EXPORT_PATH/llvm-project"
    git clone $GIT_BASE_URL $EXPORT_PATH/llvm-project
fi

if test -d $EXPORT_PATH/llvm-toolchain-integration-test-suite; then
    echo "Updating repo in $EXPORT_PATH/llvm-toolchain-integration-test-suite"
    # Update it
    reset_repo $EXPORT_PATH/llvm-toolchain-integration-test-suite
else
    echo "Clone llvm-toolchain-integration-test-suite into $EXPORT_PATH/llvm-toolchain-integration-test-suite"
    git clone $GIT_TOOLCHAIN_CHECK $EXPORT_PATH/llvm-toolchain-integration-test-suite
fi

cd $EXPORT_PATH/llvm-project
if test -z  "$TAG" -a -z "$FINAL_RELEASE"; then
    # Building a branch
    git checkout $BRANCH
    git reset --hard origin/$BRANCH
    if test $BRANCH != "main"; then
        VERSION=$(echo $BRANCH|cut -d/ -f2|cut -d. -f1)
        if ! echo "$MAJOR_VERSION"|grep -q "$VERSION"; then
            echo "mismatch in version: Dir=$MAJOR_VERSION Provided=$VERSION"
            exit 1
        fi
    else
        # No argument, take main. So, it can only be snapshot
        VERSION=$MAJOR_VERSION
        MAJOR_VERSION=snapshot
    fi
    if test $MAJOR_VERSION != "snapshot"; then
        # When upstream released X, they will update X to have X.0.1
        # In general, in Debian, we will keep X until X.0.1 is released (or rc in experimental)
        # However, on apt.llvm.org, we will update the version to have X.0.1
        # This code is doing that.
        MAJOR=$(grep "set(LLVM_VERSION_MAJOR" llvm/CMakeLists.txt|tr -d -c '[0-9]')
        MINOR=$(grep "set(LLVM_VERSION_MINOR" llvm/CMakeLists.txt|tr -d -c '[0-9]')
        PATCH=$(grep "set(LLVM_VERSION_PATCH" llvm/CMakeLists.txt|tr -d -c '[0-9]')
        CURRENT_VERSION="$MAJOR.$MINOR.$PATCH"
    fi
    # the + is here to make sure that this version is considered more recent than the svn
    # dpkg --compare-versions 10~svn374977-1~exp1 lt 10~+2019-svn374977-1~exp1
    # to verify that
    VERSION="${CURRENT_VERSION}~++$(date +'%Y%m%d%I%M%S')+$(git log -1 --pretty=format:'%h')"
else

    if ! echo "$EXACT_VERSION"|grep -q "$MAJOR_VERSION"; then
        echo "Mismatch in version: Dir=$MAJOR_VERSION Provided=$EXACT_VERSION"
        exit 1
    fi
    git_tag="llvmorg-$EXACT_VERSION"
    VERSION=$EXACT_VERSION
    if test -n "$TAG"; then
        git_tag="$git_tag-$TAG"
        VERSION="$VERSION~+$TAG"
    fi

    git checkout "$git_tag" > /dev/null

fi

# cleanup
rm -rf */www/

cd ../
BASE="llvm-toolchain-${MAJOR_VERSION}_${VERSION}"
FILENAME="${BASE}.orig.tar.xz"

cp -R llvm-toolchain-integration-test-suite llvm-project/integration-test-suite
echo "Compressing to $FILENAME"
tar Jcf $CURRENT_PATH/"$FILENAME" --exclude .git --transform="s|llvm-project|$BASE|" -C $EXPORT_PATH llvm-project
rm -rf llvm-project/integration-test-suite

export DEBFULLNAME="Sylvestre Ledru"
export DEBEMAIL="sylvestre@debian.org"
cd "$PATH_DEBIAN"

if test -z "$DISTRIBUTION"; then
    DISTRIBUTION="experimental"
fi

if test -n "$RCRELEASE" -o -n "$BRANCH"; then
    EXTRA_DCH_FLAGS="--force-bad-version --allow-lower-version"
fi

dch $EXTRA_DCH_FLAGS --distribution $DISTRIBUTION --newversion 1:"$VERSION"-1~exp1 "New snapshot release"

exit 0