1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-07 18:36:08 +02:00

Merge branch 'nd/warn-more-for-devs'

The build procedure "make DEVELOPER=YesPlease" learned to enable a
bit more warning options depending on the compiler used to help
developers more.  There also is "make DEVOPTS=tokens" knob
available now, for those who want to help fixing warnings we
usually ignore, for example.

* nd/warn-more-for-devs:
  Makefile: add a DEVOPTS to get all of -Wextra
  Makefile: add a DEVOPTS to suppress -Werror under DEVELOPER
  Makefile: detect compiler and enable more warnings in DEVELOPER=1
  connect.c: mark die_initial_contact() NORETURN
This commit is contained in:
Junio C Hamano 2018-05-08 15:59:21 +09:00
commit e998e7a188
4 changed files with 117 additions and 11 deletions

View File

@ -464,6 +464,26 @@ all::
# When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
# the global variable _wpgmptr containing the absolute path of the current
# executable (this is the case on Windows).
#
# Define DEVELOPER to enable more compiler warnings. Compiler version
# and family are auto detected, but could be overridden by defining
# COMPILER_FEATURES (see config.mak.dev)
#
# When DEVELOPER is set, DEVOPTS can be used to control compiler
# options. This variable contains keywords separated by
# whitespace. The following keywords are are recognized:
#
# no-error:
#
# suppresses the -Werror that implicitly comes with
# DEVELOPER=1. Useful for getting the full set of errors
# without immediately dying, or for logging them.
#
# extra-all:
#
# The DEVELOPER mode enables -Wextra with a few exceptions. By
# setting this flag the exceptions are removed, and all of
# -Wextra is used.
GIT-VERSION-FILE: FORCE
@$(SHELL_PATH) ./GIT-VERSION-GEN
@ -472,15 +492,6 @@ GIT-VERSION-FILE: FORCE
# CFLAGS and LDFLAGS are for the users to override from the command line.
CFLAGS = -g -O2 -Wall
DEVELOPER_CFLAGS = -Werror \
-Wdeclaration-after-statement \
-Wno-format-zero-length \
-Wold-style-definition \
-Woverflow \
-Wpointer-arith \
-Wstrict-prototypes \
-Wunused \
-Wvla
LDFLAGS =
ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
ALL_LDFLAGS = $(LDFLAGS)
@ -1098,7 +1109,7 @@ include config.mak.uname
-include config.mak
ifdef DEVELOPER
CFLAGS += $(DEVELOPER_CFLAGS)
include config.mak.dev
endif
comma := ,

42
config.mak.dev Normal file
View File

@ -0,0 +1,42 @@
ifeq ($(filter no-error,$(DEVOPTS)),)
CFLAGS += -Werror
endif
CFLAGS += -Wdeclaration-after-statement
CFLAGS += -Wno-format-zero-length
CFLAGS += -Wold-style-definition
CFLAGS += -Woverflow
CFLAGS += -Wpointer-arith
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wunused
CFLAGS += -Wvla
ifndef COMPILER_FEATURES
COMPILER_FEATURES := $(shell ./detect-compiler $(CC))
endif
ifneq ($(filter clang4,$(COMPILER_FEATURES)),)
CFLAGS += -Wtautological-constant-out-of-range-compare
endif
ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang4,$(COMPILER_FEATURES))),)
CFLAGS += -Wextra
# if a function is public, there should be a prototype and the right
# header file should be included. If not, it should be static.
CFLAGS += -Wmissing-prototypes
ifeq ($(filter extra-all,$(DEVOPTS)),)
# These are disabled because we have these all over the place.
CFLAGS += -Wno-empty-body
CFLAGS += -Wno-missing-field-initializers
CFLAGS += -Wno-sign-compare
CFLAGS += -Wno-unused-function
CFLAGS += -Wno-unused-parameter
endif
endif
# uninitialized warnings on gcc 4.9.2 in xdiff/xdiffi.c and config.c
# not worth fixing since newer compilers correctly stop complaining
ifneq ($(filter gcc4,$(COMPILER_FEATURES)),)
ifeq ($(filter gcc5,$(COMPILER_FEATURES)),)
CFLAGS += -Wno-uninitialized
endif
endif

View File

@ -48,7 +48,7 @@ int check_ref_type(const struct ref *ref, int flags)
return check_ref(ref->name, flags);
}
static void die_initial_contact(int unexpected)
static NORETURN void die_initial_contact(int unexpected)
{
/*
* A hang-up after seeing some response from the other end

53
detect-compiler Executable file
View File

@ -0,0 +1,53 @@
#!/bin/sh
#
# Probe the compiler for vintage, version, etc. This is used for setting
# optional make knobs under the DEVELOPER knob.
CC="$*"
# we get something like (this is at least true for gcc and clang)
#
# FreeBSD clang version 3.4.1 (tags/RELEASE...)
get_version_line() {
$CC -v 2>&1 | grep ' version '
}
get_family() {
get_version_line | sed 's/^\(.*\) version [0-9][^ ]* .*/\1/'
}
get_version() {
get_version_line | sed 's/^.* version \([0-9][^ ]*\) .*/\1/'
}
print_flags() {
family=$1
version=$(get_version | cut -f 1 -d .)
# Print a feature flag not only for the current version, but also
# for any prior versions we encompass. This avoids needing to do
# numeric comparisons in make, which are awkward.
while test "$version" -gt 0
do
echo $family$version
version=$((version - 1))
done
}
case "$(get_family)" in
gcc)
print_flags gcc
;;
clang)
print_flags clang
;;
"FreeBSD clang")
print_flags clang
;;
"Apple LLVM")
print_flags clang
;;
*)
: unknown compiler family
;;
esac