Skip to content

Instantly share code, notes, and snippets.

@rpavlik
Last active February 23, 2016 19:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpavlik/c5e17cd01dd1c9fe16f7 to your computer and use it in GitHub Desktop.
Save rpavlik/c5e17cd01dd1c9fe16f7 to your computer and use it in GitHub Desktop.
run-clang-tidy wrapper for Jenkins
/run-clang-tidy.py
/hudson*
#!/bin/bash
# Yep, gonna suggest you "pipe it to your shell" - if you trust me.
# Will install in the current directory - just like Jenkins expects.
# wget -O - https://gist.githubusercontent.com/rpavlik/c5e17cd01dd1c9fe16f7/raw/.install.sh | bash -s
# is the command to run.
REPOURL=https://gist.github.com/c5e17cd01dd1c9fe16f7.git
UPDATE=true
if [ ! -f "jenkins-clang-tidy-update" ]; then
UPDATE=false
echo "*** Doing initial clone of the Jenkins run-clang-tidy tools gist repo..."
# Have to do this in a temp directory, because Jenkins conveniently puts that
# one-liner installer into a shell script in the destination directory, which
# really harshes Git's mellow when it's trying to clone.
MYTEMP=$(mktemp --directory)
trap 'rm -rf "${MYTEMP}"' EXIT
REPO="${MYTEMP}/repo"
(
cd "${MYTEMP}"
git clone "${REPOURL}" repo
)
# Now, we can move the git repo contents into the tool directory and git will be fine.
# Move the git metadata, the only important part: we'll recreate the rest with a reset.
mv ${REPO}/.git .
# Do a hard reset from the git metadata to recreate a working copy.
git reset --hard > /dev/null
fi
updatescript=jenkins-clang-tidy-update
if $UPDATE; then
echo "*** Updating existing install of the Jenkins run-clang-tidy tools"
./${updatescript}
else
echo "*** Finishing install of the Jenkins run-clang-tidy tools"
# the first pass is a git pull which we can skip
./${updatescript} --second-pass
fi
#!/bin/bash
#RUN_CLANG_TIDY_BASE=http://llvm.org/svn/llvm-project/clang-tools-extra/trunk/clang-tidy/tool
RUN_CLANG_TIDY_BASE=https://raw.githubusercontent.com/llvm-mirror/clang-tools-extra/master/clang-tidy/tool
RUN_CLANG_TIDY_FILE=run-clang-tidy.py
get_script() {
echo "Downloading potentially updated script file $1/$2"
wget --timestamping "$1/$2"
chmod +x "$2"
}
(
cd $(dirname $0)
if [ "x$1" == "x" ]; then
# This is our initial pass through the updater.
# We've cloned the tool repo already, let's pull it.
git pull
exec ./$(basename $0) --second-pass
else
# Second pass through the updater, finish updating.
get_script "${RUN_CLANG_TIDY_BASE}" "${RUN_CLANG_TIDY_FILE}"
fi
)
#!/bin/bash
# Must run only a single job at a time to avoid confusing log parser
# Must filter out lines starting with clang-tidy to avoid confusing log parser.
# Allows specifying a non-default clang-tidy binary to let you update from whatever shipped with the distro.
MY_CLANG_TIDY=${CLANG_TIDY:-$(which clang-tidy)}
run-clang-tidy.py -j=1 -clang-tidy-binary ${MY_CLANG_TIDY} "$@" | grep -v "^clang-tidy"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment