1#!/bin/sh
2#===-- tag.sh - Tag the LLVM release candidates ----------------------------===#
3#
4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5# See https://llvm.org/LICENSE.txt for license information.
6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7#
8#===------------------------------------------------------------------------===#
9#
10# Create branches and release candidates for the LLVM release.
11#
12#===------------------------------------------------------------------------===#
13
14set -e
15
16projects="llvm clang compiler-rt libcxx libcxxabi libclc clang-tools-extra polly lldb lld openmp libunwind flang"
17
18release=""
19rc=""
20
21usage() {
22    echo "Export the Git sources and build tarballs from them"
23    echo "usage: `basename $0`"
24    echo " "
25    echo "  -release <num> The version number of the release"
26    echo "  -rc <num>      The release candidate number"
27    echo "  -final         The final tag"
28}
29
30export_sources() {
31    release_no_dot=`echo $release | sed -e 's,\.,,g'`
32    tag="llvmorg-$release"
33
34    if [ "$rc" = "final" ]; then
35        rc=""
36    else
37        tag="$tag-$rc"
38    fi
39
40    llvm_src_dir=$(readlink -f $(dirname "$(readlink -f "$0")")/../../..)
41    [ -d $llvm_src_dir/.git ] || ( echo "No git repository at $llvm_src_dir" ; exit 1 )
42
43    echo $tag
44    target_dir=$(pwd)
45
46    echo "Creating tarball for llvm-project ..."
47    pushd $llvm_src_dir/
48    git archive --prefix=llvm-project-$release$rc.src/ $tag . | xz >$target_dir/llvm-project-$release$rc.src.tar.xz
49    popd
50
51    if [ ! -d test-suite-$release$rc.src ]
52    then
53      echo "Fetching LLVM test-suite source ..."
54      mkdir -p test-suite-$release$rc.src
55      curl -L https://github.com/llvm/test-suite/archive/$tag.tar.gz | \
56          tar -C test-suite-$release$rc.src --strip-components=1 -xzf -
57    fi
58    echo "Creating tarball for test-suite ..."
59    tar --sort=name --owner=0 --group=0 \
60        --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \
61        -cJf test-suite-$release$rc.src.tar.xz test-suite-$release$rc.src
62
63    for proj in $projects; do
64        echo "Creating tarball for $proj ..."
65        pushd $llvm_src_dir/$proj
66        git archive --prefix=$proj-$release$rc.src/ $tag . | xz >$target_dir/$proj-$release$rc.src.tar.xz
67        popd
68    done
69}
70
71while [ $# -gt 0 ]; do
72    case $1 in
73        -release | --release )
74            shift
75            release=$1
76            ;;
77        -rc | --rc )
78            shift
79            rc="rc$1"
80            ;;
81        -final | --final )
82            rc="final"
83            ;;
84        -h | -help | --help )
85            usage
86            exit 0
87            ;;
88        * )
89            echo "unknown option: $1"
90            usage
91            exit 1
92            ;;
93    esac
94    shift
95done
96
97if [ "x$release" = "x" ]; then
98    echo "error: need to specify a release version"
99    exit 1
100fi
101
102# Make sure umask is not overly restrictive.
103umask 0022
104
105export_sources
106exit 0
107