Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1309505 - Add warning flags to gyp build, r=franziskus
--HG-- extra : rebase_source : 385432bb1b10fdabc168d2c8b395e51569f5a54b extra : amend_source : 1141abc219ebe425792155d4ee3b35386fcfe83c
- Loading branch information
1 parent
2bebb99
commit 853ff70
Showing
4 changed files
with
97 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |