8000 BLD: add warn-error option, adds -Werror to compiler by mattip · Pull Request #14527 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BLD: add warn-error option, adds -Werror to compiler #14527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions numpy/distutils/command/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class build(old_build):
user_options = old_build.user_options + [
('fcompiler=', None,
"specify the Fortran compiler type"),
('warn-error', None,
"turn all warnings into errors (-Werror)"),
]

help_options = old_build.help_options + [
Expand All @@ -26,6 +28,7 @@ class build(old_build):
def initialize_options(self):
old_build.initialize_options(self)
self.fcompiler = None
self.warn_error = False

def finalize_options(self):
build_scripts = self.build_scripts
Expand Down
14 changes: 12 additions & 2 deletions numpy/distutils/command/build_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ class build_clib(old_build_clib):
('inplace', 'i', 'Build in-place'),
('parallel=', 'j',
"number of parallel jobs"),
('warn-error', None,
"turn all warnings into errors (-Werror)"),
]

boolean_options = old_build_clib.boolean_options + ['inplace']
boolean_options = old_build_clib.boolean_options + ['inplace', 'warn-error']

def initialize_options(self):
old_build_clib.initialize_options(self)
self.fcompiler = None
self.inplace = 0
self.parallel = None
self.warn_error = None

def finalize_options(self):
if self.parallel:
Expand All @@ -50,7 +53,10 @@ def finalize_options(self):
except ValueError:
raise ValueError("--parallel/-j argument must be an integer")
old_build_clib.finalize_options(self)
self.set_undefined_options('build', ('parallel', 'parallel'))
self.set_undefined_options('build',
('parallel', 'parallel'),
('warn_error', 'warn_error'),
)

def have_f_sources(self):
for (lib_name, build_info) in self.libraries:
Expand Down Expand Up @@ -86,6 +92,10 @@ def run(self):
self.compiler.customize(self.distribution,
need_cxx=self.have_cxx_sources())

if self.warn_error:
self.compiler.compiler.append('-Werror')
self.compiler.compiler_so.append('-Werror')

libraries = self.libraries
self.libraries = None
self.compiler.customize_cmd(self)
Expand Down
15 changes: 14 additions & 1 deletion numpy/distutils/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,22 @@ class build_ext (old_build_ext):
"specify the Fortran compiler type"),
('parallel=', 'j',
"number of parallel jobs"),
('warn-error', None,
"turn all warnings into errors (-Werror)"),
]

help_options = old_build_ext.help_options + [
('help-fcompiler', None, "list available Fortran compilers",
show_fortran_compilers),
]

boolean_options = old_build_ext.boolean_options + ['warn-error']

def initialize_options(self):
old_build_ext.initialize_options(self)
self.fcompiler = None
self.parallel = None
self.warn_error = None

def finalize_options(self):
if self.parallel:
Expand All @@ -69,7 +74,10 @@ def finalize_options(self):
self.include_dirs.extend(incl_dirs)

old_build_ext.finalize_options(self)
self.set_undefined_options('build', ('parallel', 'parallel'))
self.set_undefined_options('build',
('parallel', 'parallel'),
('warn_error', 'warn_error'),
)

def run(self):
if not self.extensions:
Expand Down Expand Up @@ -116,6 +124,11 @@ def run(self):
force=self.force)
self.compiler.customize(self.distribution)
self.compiler.customize_cmd(self)

if self.warn_error:
self.compiler.compiler.append('-Werror')
self.compiler.compiler_so.append('-Werror')

self.compiler.show_customization()

# Setup directory for storing generated extra DLL files on Windows
Expand Down
4 changes: 4 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def main(argv):
help="Debug build")
parser.add_argument("--parallel", "-j", type=int, default=0,
help="Number of parallel jobs during build")
parser.add_argument("--warn-error", action="store_true",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about making this true by default, that will be very annoying since the build isn't clean right now in many cases. And you can't expect everyone to go fix these.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store_true means the default value is False, and when they add the --warn-error flag the value changes to True

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, never mind. been confused by that one before

help="Set -Werror to convert all compiler warnings to errors")
parser.add_argument("--show-build-log", action="store_true",
help="Show build output rather than using a log file")
parser.add_argument("--bench", action="store_true",
Expand Down Expand Up @@ -372,6 +374,8 @@ def build_project(args):
cmd += ["-j", str(args.parallel)]
if args.debug_configure:
cmd += ["build_src", "--verbose"]
if args.warn_error:
cmd += ["--warn-error"]
# Install; avoid producing eggs so numpy can be imported from dst_dir.
cmd += ['install', '--prefix=' + dst_dir,
'--single-version-externally-managed',
Expand Down
0