KeepGoing="no"
# the actual name of the directive that enabled keep-going mode
KeepGoingDirective=""
+
#
# The script checks that the version of astyle is TargetAstyleVersion.
# if it isn't, the default behaviour is to not perform the formatting stage
# * SHA1/etc: Check commits added after the specified git commit.
UpdateContributorsSince=auto
+# --only-changed-since point
+OnlyChangedSince=""
+
printUsage () {
- echo "Usage: $0 [option...]"
- echo "options:"
- echo " --keep-going|-k"
- echo " --check-and-update-copyright <yes|no>"
- echo " --update-contributors-since <never|auto|revision>"
- echo " --with-astyle </path/to/astyle/executable>"
+cat <<USAGE_
+Usage: $0 [option...]
+options:
+--check-and-update-copyright <yes|no> (default: yes)
+--help|-h
+--keep-going|-k (default: stop on error)
+--only-changed-since <fork|commit> (default: apply to all files)
+--update-contributors-since <never|auto|revision> (default: auto)
+--with-astyle </path/to/astyle/executable> (default: astyle-${TargetAstyleVersion} or astyle)
+
+USAGE_
+}
+
+printHelp () {
+
+cat <<HELP_INTRO_
+This script applies Squid mandatory code style guidelines and generates
+various files derived from Squid sources.
+HELP_INTRO_
+
+printUsage
+
+cat <<HELP_MAIN_
+--help, -h
+
+Print this information and exit.
+
+--only-changed-since <"fork"|commit>
+
+When specifieid, the script only examines for formatting changes those
+files that have changed since the specified git reference point. The
+argument is either a git commit (fed to "git diff") or a special keyword
+"fork". Common commit values include HEAD^, master, origin/master, and the
+branch the current one was forked off. When "fork" is specified, the
+script will look for files changed since the current branch was forked off
+upstream/master (according to "git merge-base --fork-point").
+
+This option does not disable some repository-wide file generation and
+repository-wide non-formatting checks/adjustments.
+
+--update-contributors-since <never|auto|revision>
+
+Configures how to sync CONTRIBUTORS with the current git branch commits:
+* never: Do not update CONTRIBUTORS at all.
+* auto: Check commits added since the last similar update.
+* SHA1/etc: Check commits added after the specified git commit.
+
+--with-astyle </path/to/astyle/executable>
+
+Squid code style guidelines require astyle version $TargetAstyleVersion.
+The path to the astyle binary can be specified using this command line
+option or by exporting the ASTYLE environment variable. If both are
+specified, the command-line option wins.
+
+External dependencies:
+
+* Astyle. See the --with-astyle command line option above.
+* gperf (if you modify certain source files)
+
+HELP_MAIN_
}
# command-line options
then
printUsage
echo "Error: Option $1 expects a yes or no argument but got $2"
- exit 1;
+ exit 1
fi
CheckAndUpdateCopyright=$2
shift 2
then
printUsage
echo "Error: Option $1 expects an argument."
- exit 1;
+ exit 1
fi
UpdateContributorsSince="$2"
- shift 2;
+ shift 2
;;
--help|-h)
- printUsage
- exit 0;
+ printHelp
+ exit 0
;;
--with-astyle)
ASTYLE=$2
shift 2
;;
+ --only-changed-since)
+ OnlyChangedSince="$2"
+ shift 2
+ ;;
*)
printUsage
echo "Unsupported command-line option: $1"
- exit 1;
+ exit 1
;;
esac
done
# an error code seen by a KeepGoing-aware command (or zero)
SeenErrors=0
-
if ! git diff --quiet; then
echo "There are unstaged changes. This script may modify sources."
echo "Stage changes to avoid permanent losses when things go bad."
exit 1
fi
+# usage: <well-known program name> <program argument(s)> <candidate name>...
+# Finds the first working program among the given candidate program names.
+# The found program name is returned via the $FoundProgram global:
+FoundProgram=""
+findProgram ()
+{
+ wellKnown="$1"
+ shift
+ options="$1"
+ shift
+
+ for candidate in $*
+ do
+ if "$candidate" $options < /dev/null > /dev/null 2> /dev/null
+ then
+ echo "Found ${wellKnown}-like program: $candidate"
+ FoundProgram="$candidate"
+ return 0
+ fi
+ done
+
+ echo "ERROR: Failed to find a ${wellKnown}-like program; tried: $*"
+ FoundProgram=""
+ return 1
+}
+
made="generated" # a hack: prevents $GeneratedByMe searches matching this file
GeneratedByMe="This file is $made by scripts/source-maintenance.sh."
-${ASTYLE} --version >/dev/null 2>/dev/null
-result=$?
-if test $result -gt 0 ; then
- echo "ERROR: cannot run ${ASTYLE}"
- exit 1
+if [ "x$ASTYLE" != "x" ] ; then
+ if ! "${ASTYLE}" --version > /dev/null 2> /dev/null ; then
+ echo "ERROR: Cannot run user-supplied astyle: ${ASTYLE}"
+ exit 1
+ fi
+else
+ findProgram astyle --version astyle-${TargetAstyleVersion} astyle || exit $?
+ ASTYLE=$FoundProgram
fi
-ASVER=`${ASTYLE} --version 2>&1 | grep -o -E "[0-9.]+"`
+
+ASVER=`"${ASTYLE}" --version 2>&1 | grep -o -E "[0-9.]+"`
if test "${ASVER}" != "${TargetAstyleVersion}" ; then
if test "${ASTYLE}" = "astyle" ; then
echo "Astyle version problem. You have ${ASVER} instead of ${TargetAstyleVersion}"
echo "Formatting anyway, please double check output before submitting"
fi
else
- echo "Found astyle ${ASVER}. Formatting..."
+ echo "Detected expected astyle version: ${ASVER}"
fi
CppFormatter=''
if test "${ASVER}"; then
CppFormatter="./scripts/format-cpp.pl --with-astyle ${ASTYLE}"
fi
+if test "x$OnlyChangedSince" = "xfork" ; then
+ ForkPoint=`git merge-base --fork-point upstream/master`
+ if test "x$ForkPoint" = "x" ; then
+ echo "Could not identify fork point - sometimes it happens"
+ echo "Please specify commit-id explicitly"
+ exit 1
+ fi
+ OnlyChangedSince="$ForkPoint"
+fi
+
if test $CheckAndUpdateCopyright = yes
then
COPYRIGHT_YEARS=`date +"1996-%Y"`
# in KeepGoing mode, remembers errors and hides them from callers
run_ ()
{
- "$@" && return; # return on success
+ "$@" && return 0 # return on success
error=$?
if test $KeepGoing = no; then
source="$1"
destination="doc/debug-messages.tmp"
+ if test "x$OnlyChangedSince" != "x"; then
+ # Skipping collection due to --only-changed-since.
+ # processDebugMessages() will warn.
+ return 0
+ fi
+
# Merge multi-line debugs() into one-liners and remove '//...' comments.
awk 'BEGIN { found=0; dbgLine=""; } {
if ($0 ~ /[ \t]debugs[ \t]*\(/)
source="doc/debug-messages.tmp"
destination="doc/debug-messages.dox"
+ if test "x$OnlyChangedSince" != "x"; then
+ echo "WARNING: Skipping update of $destination due to --only-changed-since"
+ return 0
+ fi
+
if test '!' -s "$source"; then
echo "ERROR: Failed to find debugs() message IDs"
- return 1;
+ return 1
fi
repeatedIds=`awk '{print $1}' $source | sort -n | uniq -d`
echo "ERROR: Repeated debugs() message IDs:"
echo "$repeatedIds"
echo ""
- return 1;
+ return 1
fi
repeatedGists=`awk '{$1=""; print substr($0,2)}' $source | sort | uniq -d`
echo "ERROR: Repeated debugs() message gists:"
echo "$repeatedGists"
echo ""
- return 1;
+ return 1
fi
cat scripts/boilerplate.h > $destination
{
destination="doc/debug-sections.txt"
+ if test "x$OnlyChangedSince" != "x"; then
+ echo "WARNING: Skipping update of $destination due to --only-changed-since"
+ return 0
+ fi
+
LC_ALL=C sort -u < doc/debug-sections.tmp > doc/debug-sections.tmp2
+
cat scripts/boilerplate.h > $destination
echo "" >> $destination
cat doc/debug-sections.tmp2 >> $destination
#
# Scan for file-specific actions
#
-for FILENAME in `git ls-files`; do
+
+ # The two git commands below will also list any files modified during the
+ # current run (e.g., src/http/RegisteredHeadersHash.cci or icons/icon.am).
+ FilesToOperateOn=""
+ if test "x$OnlyChangedSince" != "x" ; then
+ FilesToOperateOn=`git diff --name-only $OnlyChangedSince`
+ gitResult=$?
+ if test $gitResult -ne 0 ; then
+ echo "ERROR: Cannot use --only-changed-since reference point: $OnlyChangedSince"
+ echo "Consider using a git commit SHA (from git log) instead"
+ return $gitResult
+ fi
+ else
+ FilesToOperateOn=`git ls-files`
+ gitResult=$?
+ # a bit paranoid but protects the empty $FilesToOperateOn check below
+ if test $gitResult -ne 0 ; then
+ echo "ERROR: Cannot find source code file names"
+ return $gitResult
+ fi
+ fi
+ if test "x$FilesToOperateOn" = "x"; then
+ echo "WARNING: No files to scan and format"
+ return 0
+ fi
+
+for FILENAME in $FilesToOperateOn; do
skip_copyright_check=""
# skip subdirectories, git ls-files is recursive
cciFile=`echo $gperfFile | sed 's/[.]gperf$/.cci/'`
if test $gperfFile -ot $cciFile; then
- return 0;
+ return 0
fi
generateRawGperfFile $gperfFile > $cciFile.unformatted || return
{
if test "x$UpdateContributorsSince" = xnever
then
- return 0; # successfully did nothing, as requested
+ return 0 # successfully did nothing, as requested
fi
vettedCommitPhraseRegex='[Rr]eference point for automated CONTRIBUTORS updates'
if test "x$humanSha" = x && test "x$botSha" = x
then
echo "ERROR: Unable to determine the commit to start contributors extraction from"
- return 1;
+ return 1
fi
# find the latest commit among the above one or two commits
# Run formatting
srcFormat || exit 1
-rm -f boilerplate_fix.sed
+test -e boilerplate_fix.sed && rm -f boilerplate_fix.sed
exit $SeenErrors