Skip to content

Instantly share code, notes, and snippets.

@kwk
Last active December 11, 2023 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwk/168a0c82f7acb666b20c5c1a30e517db to your computer and use it in GitHub Desktop.
Save kwk/168a0c82f7acb666b20c5c1a30e517db to your computer and use it in GitHub Desktop.
Make llvm-snapshot-builder obsolete

The llvm-snapshot-builder is overly complex to maintain in the RPM build process. Here's a script and its output that could be included with %include version.spec.inc in the main llvm.spec file.

The output could look like this:

[INFO] Get the source tarball
[INFO] Source tarball already exists: llvm-project.tar.xz
[INFO] Grab git revision from tarball
[INFO] Extract the llvm/CMakeLists.txt file from the source tarball
[INFO] Parse llvm/CMakeLists.txt for the LLVM version
%global maj_ver 18
%global min_ver 0
%global patch_ver 0

%global llvm_snapshot_version            18.0.0
%global llvm_snapshot_version_tag        18.0.0~pre20231211.gb2cc4b994e5fb8
%global llvm_snapshot_version_major      18
%global llvm_snapshot_version_minor      0
%global llvm_snapshot_version_patch      0
%global llvm_snapshot_yyyymmdd           20231211
%global llvm_snapshot_git_revision       b2cc4b994e5fb85053b1acedec5ea0d1d42e5ec4
%global llvm_snapshot_git_revision_short b2cc4b994e5fb8
%global llvm_snapshot_version_suffix     pre20231211.gb2cc4b994e5fb8
%global llvm_snapshot_changelog_entry    Mon Dec 11 2023 LLVM snapshot - 18.0.0~pre20231211.gb2cc4b994e5fb8

NOTE: The lines prefixed with [INFO] are written to stderr. Therefore the stdout output can be redirected (>, or tee) to version.spec.inc directly.

#!/usr/bin/bash
set -e
set +x
# This is important for systems that have a different local but want to produce
# a valid changelog date.
LANG=en_EN
function loginfo() {
local msg=$1
>&2 echo "[INFO]" $msg
}
loginfo "Get the source tarball"
llvm_snapshot_yyyymmdd=$(date +%Y%m%d)
tarball_url=https://github.com/kwk/llvm-daily-fedora-rpms/releases/download/source-snapshot/llvm-project-${llvm_snapshot_yyyymmdd}.src.tar.xz
tarball=llvm-project.tar.xz
if [ -e $tarball ]; then
loginfo "Source tarball already exists: $tarball"
else
loginfo "Downloading source tarball $tarball from $tarball_url"
curl -sL -o $tarball ${tarball_url}
fi
loginfo "Grab git revision from tarball"
llvm_snapshot_git_revision=$(xzcat $tarball | git get-tar-commit-id)
llvm_snapshot_git_revision_short=$(echo "${llvm_snapshot_git_revision:0:14}")
loginfo "Extract the llvm/CMakeLists.txt file from the source tarball"
tar -xf $tarball "llvm-project*.src/llvm/CMakeLists.txt"
loginfo "Parse llvm/CMakeLists.txt for the LLVM version"
llvm_snapshot_version=$(grep -ioP 'set\(\s*LLVM_VERSION_(MAJOR|MINOR|PATCH)\s\K[0-9]+' llvm-project-*.src/llvm/CMakeLists.txt | paste -sd '.')
llvm_snapshot_version_major=$(echo $llvm_snapshot_version | cut -f1 -d.)
llvm_snapshot_version_minor=$(echo $llvm_snapshot_version | cut -f2 -d.)
llvm_snapshot_version_patch=$(echo $llvm_snapshot_version | cut -f3 -d.)
llvm_snapshot_version_suffix=pre${llvm_snapshot_yyyymmdd}.g${llvm_snapshot_git_revision_short}
llvm_snapshot_version_tag=${llvm_snapshot_version}~${llvm_snapshot_version_suffix}
llvm_snapshot_changelog_entry="$(date +'%a %b %d %Y') LLVM snapshot - ${llvm_snapshot_version_tag}"
cat <<EOF
%global maj_ver ${llvm_snapshot_version_major}
%global min_ver ${llvm_snapshot_version_minor}
%global patch_ver ${llvm_snapshot_version_patch}
%global llvm_snapshot_version ${llvm_snapshot_version}
%global llvm_snapshot_version_tag ${llvm_snapshot_version_tag}
%global llvm_snapshot_version_major ${llvm_snapshot_version_major}
%global llvm_snapshot_version_minor ${llvm_snapshot_version_minor}
%global llvm_snapshot_version_patch ${llvm_snapshot_version_patch}
%global llvm_snapshot_yyyymmdd ${llvm_snapshot_yyyymmdd}
%global llvm_snapshot_git_revision ${llvm_snapshot_git_revision}
%global llvm_snapshot_git_revision_short ${llvm_snapshot_git_revision_short}
%global llvm_snapshot_version_suffix ${llvm_snapshot_version_suffix}
%global llvm_snapshot_changelog_entry ${llvm_snapshot_changelog_entry}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment