Skip to content

Commit

Permalink
Bug 1309505 - Add warning flags to gyp build, r=franziskus
Browse files Browse the repository at this point in the history
--HG--
extra : rebase_source : 385432bb1b10fdabc168d2c8b395e51569f5a54b
extra : amend_source : 1141abc219ebe425792155d4ee3b35386fcfe83c
  • Loading branch information
martinthomson committed Oct 21, 2016
1 parent 2bebb99 commit 853ff70
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 18 deletions.
7 changes: 2 additions & 5 deletions automation/taskcluster/scripts/build_gyp.sh
Expand Up @@ -11,11 +11,8 @@ fi
hg_clone https://hg.mozilla.org/projects/nspr nspr default

# Build.
cd nss && ./build.sh -g
if [ $? != 0 ]; then
exit 1
fi
nss/build.sh -g -v

# Package.
cd .. && mkdir artifacts
mkdir artifacts
tar cvfjh artifacts/dist.tar.bz2 dist
29 changes: 22 additions & 7 deletions build.sh
Expand Up @@ -6,19 +6,29 @@
#
# -c = clean before build
# -g = force a rebuild of gyp (and NSPR, because why not)
# -v = verbose build

set -e

CWD=$(cd $(dirname $0); pwd -P)
OBJ_DIR=$(make platform)
OBJ_DIR=$(cd "$CWD";make platform)
DIST_DIR="$CWD/../dist/$OBJ_DIR"

if [ -n "$CCC" ] && [ -z "$CXX" ]; then
export CXX="$CCC"
fi

while [ $# -gt 0 ]; do
case $1 in
-c) CLEAN=1 ;;
-g) REBUILD_GYP=1 ;;
-v) VERBOSE=1 ;;
esac
shift
done

# -c = clean first
if [ "$1" = "-c" ]; then
if [ "$CLEAN" = 1 ]; then
rm -rf "$CWD/out"
fi

Expand All @@ -27,20 +37,22 @@ if [ "$BUILD_OPT" = "1" ]; then
else
TARGET=Debug
fi
TARGET_DIR="$CWD/out/$TARGET"
if [ "$USE_64" != "1" ]; then
if [ "$USE_64" == "1" ]; then
TARGET="${TARGET}_x64"
else
GYP_PARAMS="-Dtarget_arch=ia32"
fi
TARGET_DIR="$CWD/out/$TARGET"

# These steps can take a while, so don't overdo them.
# Force a redo with -g.
if [ "$1" = "-g" -o ! -d "$TARGET_DIR" ]; then
if [ "$REBUILD_GYP" = 1 -o ! -d "$TARGET_DIR" ]; then
# Build NSPR.
make NSS_GYP=1 install_nspr
make -C "$CWD" NSS_GYP=1 install_nspr

# Run gyp.
PKG_CONFIG_PATH="$CWD/../nspr/$OBJ_DIR/config" $SCANBUILD \
gyp -f ninja $GYP_PARAMS --depth=. --generator-output="." nss.gyp
gyp -f ninja $GYP_PARAMS --depth="$CWD" --generator-output="." "$CWD/nss.gyp"
fi

# Run ninja.
Expand All @@ -52,4 +64,7 @@ else
echo "Please install ninja" 1>&2
exit 1
fi
if [ "$VERBOSE" = 1 ]; then
NINJA="$NINJA -v"
fi
$NINJA -C "$TARGET_DIR"
25 changes: 19 additions & 6 deletions coreconf/config.gypi
Expand Up @@ -86,15 +86,17 @@
'dll_prefix': '<(dll_prefix)',
'dll_suffix': '<(dll_suffix)',
'cc_is_clang%': '<(cc_is_clang)',
# Some defaults
'disable_tests%': 0,
'disable_chachapoly%': 0,
'disable_dbm%': 0,
'disable_libpkix%': 0,
'ssl_enable_zlib%': 1,
'use_asan%': 0,
'disable_werror%': 0,
'mozilla_client%': 0,
'moz_fold_libs%': 0,
'moz_folded_library_name%': '',
'ssl_enable_zlib%': 1,
'use_asan%': 0,
},
'target_defaults': {
# Settings specific to targets should go here.
Expand Down Expand Up @@ -226,12 +228,9 @@
'-fno-common',
'-pipe',
],
# TODO:
# 'GCC_TREAT_WARNINGS_AS_ERRORS'
# 'WARNING_CFLAGS'
},
'conditions': [
['OS=="linux" or OS=="android"', {
[ 'OS=="linux" or OS=="android"', {
'defines': [
'LINUX2_1',
'LINUX',
Expand Down Expand Up @@ -262,6 +261,11 @@
}],
],
}],
[ 'disable_werror==0 and (OS=="linux" or OS=="mac")', {
'cflags': [
'<!@(<(python) <(DEPTH)/coreconf/werror.py)',
],
}],
[ 'OS=="android" and mozilla_client==0', {
'defines': [
'NO_SYSINFO',
Expand Down Expand Up @@ -298,6 +302,15 @@
],
'cflags': [
'-W3',
'-w44267', # Disable C4267: conversion from 'size_t' to 'type', possible loss of data
'-w44244', # Disable C4244: conversion from 'type1' to 'type2', possible loss of data
'-w44018', # Disable C4018: 'expression' : signed/unsigned mismatch
'-w44312', # Disable C4312: 'type cast': conversion from 'type1' to 'type2' of greater size
],
'conditions': [
[ 'disable_werror==0', {
'cflags': ['-WX']
}]
],
}],
[ 'disable_dbm==1', {
Expand Down
54 changes: 54 additions & 0 deletions coreconf/werror.py
@@ -0,0 +1,54 @@
#!/usr/bin/env python

import os
import subprocess

def main():
cc = os.environ.get('CC', 'cc')
sink = open(os.devnull, 'wb')
cc_is_clang = 'clang' in subprocess.check_output([cc, '--version'], stderr=sink)

def warning_supported(warning):
return subprocess.call([cc, '-x', 'c', '-E', '-Werror',
'-W%s' % warning, os.devnull], stdout=sink, stderr=sink) == 0
def can_enable():
# This would be a problem
if not warning_supported('all'):
return False

# If we aren't clang, make sure we have gcc 4.8 at least
if not cc_is_clang:
try:
v = subprocess.check_output([cc, '-dumpversion'], stderr=sink)
v = v.strip(' \r\n').split('.')
if v[0] < 4 or (v[0] == 4 and v[1] < 8):
# gcc 4.8 minimum
return False
except OSError:
return False
return True

if not can_enable():
print('-DNSS_NO_GCC48')
return

print('-Werror')
print('-Wall')

def set_warning(warning, contra=''):
if warning_supported(warning):
print('-W%s%s' % (contra, warning))

if cc_is_clang:
# clang is unable to handle glib's expansion of strcmp and similar for
# optimized builds, so disable the resulting errors.
# See https://llvm.org/bugs/show_bug.cgi?id=20144
for w in ['array-bounds', 'unevaluated-expression',
'parentheses-equality']:
set_warning(w, 'no-')
print('-Qunused-arguments')

# set_warning('shadow') # Bug 1309068

if __name__ == '__main__':
main()

0 comments on commit 853ff70

Please sign in to comment.