brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.3 KiB · 0ac392c Raw
188 lines · bash
1#!/bin/bash2#===-- 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-exception7#8#===------------------------------------------------------------------------===#9#10# Create branches and release candidates for the LLVM release.11#12#===------------------------------------------------------------------------===#13 14set -e15 16projects="llvm bolt clang cmake compiler-rt libcxx libcxxabi libclc clang-tools-extra polly lldb lld openmp libunwind mlir flang runtimes third-party"17 18release=""19rc=""20yyyymmdd=$(date +'%Y%m%d')21snapshot=""22template='${PROJECT}-${RELEASE}${RC}.src.tar.xz'23 24usage() {25cat <<EOF26Export the Git sources and build tarballs from them.27 28Usage: $(basename $0) [-release|--release <major>.<minor>.<patch>]29                      [-rc|--rc <num>]30                      [-final|--final]31                      [-git-ref|--git-ref <git-ref>]32                      [-template|--template <template>]33 34Flags:35 36  -release  | --release <major>.<minor>.<patch>    The version number of the release37  -rc       | --rc <num>                           The release candidate number38  -final    | --final                              When provided, this option will disable the rc flag39  -git-ref  | --git-ref <git-ref>                  (optional) Use <git-ref> to determine the release and don't export the test-suite files40  -template | --template <template>                (optional) Possible placeholders: \$PROJECT \$YYYYMMDD \$GIT_REF \$RELEASE \$RC.41                                                   Defaults to '${template}'.42 43The following list shows the filenames (with <placeholders>) for the artifacts44that are being generated (given that you don't touch --template).45 46$(echo "$projects "| sed 's/\([a-z-]\+\) /  * \1-<RELEASE><RC>.src.tar.xz \n/g')47 48Additional files being generated:49 50  * llvm-project-<RELEASE><RC>.src.tar.xz    (the complete LLVM source project)51  * test-suite-<RELEASE><RC>.src.tar.xz      (only when not using --git-ref)52 53To ease the creation of snapshot builds, we also provide these files54 55  * llvm-release-<YYYYMMDD>.txt        (contains the <RELEASE> as a text)56  * llvm-rc-<YYYYMMDD>.txt             (contains the rc version passed to the invocation of $(basename $0))57  * llvm-git-revision-<YYYYMMDD>.txt   (contains the current git revision sha1)58 59Example values for the placeholders:60 61  * <RELEASE>  -> 13.0.062  * <YYYYMMDD> -> 20210414   (the date when executing this script)63  * <RC>       -> rc4        (will be empty when using --git-ref)64 65In order to generate snapshots of the upstream main branch you could do this for example:66 67  $(basename $0) --git-ref upstream/main --template '\${PROJECT}-\${YYYYMMDD}.src.tar.xz'68 69EOF70}71 72template_file() {73    export PROJECT=$1 YYYYMMDD=$yyyymmdd RC=$rc RELEASE=$release GIT_REF=$git_rev74    basename $(echo $template | envsubst '$PROJECT $RELEASE $RC $YYYYMMDD $GIT_REF')75    unset PROJECT YYYYMMDD RC RELEASE GIT_REF76}77 78export_sources() {79    local tag="llvmorg-$release"80 81    llvm_src_dir=$(readlink -f $(dirname "$(readlink -f "$0")")/../../..)82    [ -d $llvm_src_dir/.git ] || ( echo "No git repository at $llvm_src_dir" ; exit 1 )83 84    # Determine the release by fetching the version from LLVM's CMakeLists.txt85    # in the specified git ref.86    if [ -n "$snapshot" ]; then87        release=$(git -C $llvm_src_dir show $snapshot:cmake/Modules/LLVMVersion.cmake | grep -ioP 'set\(\s*LLVM_VERSION_(MAJOR|MINOR|PATCH)\s\K[0-9]+' | paste -sd '.')88    fi89    90    tag="llvmorg-$release"91 92    if [ "$rc" = "final" ]; then93        rc=""94    else95        tag="$tag-$rc"96    fi97 98    target_dir=$(pwd)99 100    echo "Creating tarball for llvm-project ..."101    pushd $llvm_src_dir/102    tree_id=$tag103    [ -n "$snapshot" ] && tree_id="$snapshot"104    echo "Tree ID to archive: $tree_id"105 106    # This might be a surprise but a package like clang or compiler-rt don't107    # know about the LLVM version itself. That's why we also export a the108    # llvm-version*-<YYYYMMDD> and llvm-git*-<YYYYMMDD> files.109    git_rev=$(git rev-parse $tree_id)110    echo "git revision: $git_rev"111    echo "$release" > $target_dir/llvm-release-$yyyymmdd.txt112    echo "$rc" > $target_dir/llvm-rc-$yyyymmdd.txt113    echo "$git_rev" > $target_dir/llvm-git-revision-$yyyymmdd.txt114    115    git archive --prefix=llvm-project-$release$rc.src/ $tree_id . | xz -T0 >$target_dir/$(template_file llvm-project)116    popd117 118    if [ -z "$snapshot" ]; then119        if [ ! -d test-suite-$release$rc.src ]; then120            echo "Fetching LLVM test-suite source ..."121            mkdir -p test-suite-$release$rc.src122            curl -L https://github.com/llvm/test-suite/archive/$tag.tar.gz | \123                tar -C test-suite-$release$rc.src --strip-components=1 -xzf -124        fi125        echo "Creating tarball for test-suite ..."126        XZ_OPT="-T0" tar --sort=name --owner=0 --group=0 \127            --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \128            -cJf test-suite-$release$rc.src.tar.xz test-suite-$release$rc.src129    fi130 131    for proj in $projects; do132        echo "Creating tarball for $proj ..."133        pushd $llvm_src_dir/$proj134        git archive --prefix=$proj-$release$rc.src/ $tree_id . | xz -T0 >$target_dir/$(template_file $proj)135        popd136    done137}138 139while [ $# -gt 0 ]; do140    case $1 in141        -release | --release )142            shift143            release=$1144            ;;145        -rc | --rc )146            shift147            rc="rc$1"148            ;;149        -final | --final )150            rc="final"151            ;;152        -git-ref | --git-ref )153            shift154            snapshot="$1"155            ;;156        -template | --template )157            shift158            template="$1"159            ;;160        -h | -help | --help )161            usage162            exit 0163            ;;164        * )165            echo "unknown option: $1"166            usage167            exit 1168            ;;169    esac170    shift171done172 173if [ -n "$snapshot" ]; then 174    if [[ "$rc" != "" || "$release" != "" ]]; then175        echo "error: must not specify -rc or -release when creating a snapshot"176        exit 1177    fi178elif [ -z "$release" ]; then179    echo "error: need to specify a release version"180    exit 1181fi182 183# Make sure umask is not overly restrictive.184umask 0022185 186export_sources187exit 0188