File: orig-tar.sh

package info (click to toggle)
llvm-toolchain-snapshot 1%3A21~%2B%2B20250322080030%2B20b5728b7b1c-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,124,544 kB
  • sloc: cpp: 7,505,721; ansic: 1,401,938; asm: 1,017,251; python: 245,190; f90: 90,563; objc: 70,565; lisp: 42,033; pascal: 17,419; sh: 9,997; ml: 5,073; perl: 4,734; awk: 3,523; makefile: 3,358; javascript: 2,251; xml: 892; fortran: 679
file content (185 lines) | stat: -rwxr-xr-x 5,937 bytes parent folder | download | duplicates (4)
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
#!/bin/sh
# This script will create the following tarball:
# llvm-toolchain-XX_XX\~+20200120101212+de4b2a7fad6.orig.tar.xz

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.
        CURRENT_VERSION="$(grep -oP 'set\(\s*LLVM_VERSION_(MAJOR|MINOR|PATCH)\s\K[0-9]+' cmake/Modules/LLVMVersion.cmake | paste -sd '.')"
    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')"
    echo "CURRENT = ${CURRENT_VERSION}"
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/ build/ build-llvm/

cd ../
BASE="llvm-toolchain-${MAJOR_VERSION}_${VERSION}"
FILENAME="${BASE}.orig.tar.xz"
cp -R llvm-toolchain-integration-test-suite llvm-project/integration-test-suite
# Argument to compress faster (for the cost of time)
export XZ_OPT="-4 -T$(nproc)"
echo "Compressing to $FILENAME"
time tar Jcf $CURRENT_PATH/"$FILENAME" --exclude .git --exclude .gitattributes --exclude .git-blame-ignore-revs --exclude .gitignore --exclude .github --exclude build-llvm --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