Skip to content

Commit

Permalink
Make disable_warnings() disable all warnings
Browse files Browse the repository at this point in the history
...including the optional ones. Previously, those were independent.

This is more intuitive, and it seems unlikely that you'd want some of
the optional warnings printed without having general warnings printed.

This is a small API behavior change, so the major version will be bumped
to 5 at the next release. Programs that enabled optional warnings
without enabling general warnings will be affected.

This means that all warnings now go through the same code path, which
will come in handy for later changes (making the warnings available in a
list, though with stderr printing still enabled by default).

Add some more documentation for the Kconfig.__init__() 'warn' parameter
and the enable_redun_warnings() function as well, and clean up the
variable naming a bit.
  • Loading branch information
ulfalizer committed May 1, 2018
1 parent 2d50563 commit 8983f7e
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions kconfiglib.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,12 @@ class Kconfig(object):
"""
__slots__ = (
"_choices",
"_print_undef_assign",
"_print_redun_assign",
"_print_warnings",
"_set_re_match",
"_unset_re_match",
"_warn_no_prompt",
"_warn_for_no_prompt",
"_warn_for_redun_assign",
"_warn_for_undef_assign",
"_warnings_enabled",
"config_prefix",
"const_syms",
"defconfig_list",
Expand Down Expand Up @@ -561,6 +561,9 @@ def __init__(self, filename="Kconfig", warn=True):
stderr. This can be changed later with
Kconfig.enable/disable_warnings(). It is provided as a constructor
argument since warnings might be generated during parsing.
See the other Kconfig.enable_*_warnings() functions as well, which
enable or suppress certain warnings when warnings are enabled.
"""
self.srctree = os.environ.get("srctree")

Expand All @@ -581,9 +584,9 @@ def __init__(self, filename="Kconfig", warn=True):
_RE_ASCII).match


self._print_warnings = warn
self._print_undef_assign = False
self._print_redun_assign = True
self._warnings_enabled = warn
self._warn_for_undef_assign = False
self._warn_for_redun_assign = True

self.syms = {}
self.const_syms = {}
Expand Down Expand Up @@ -687,7 +690,7 @@ def __init__(self, filename="Kconfig", warn=True):
# Build Symbol._dependents for all symbols
self._build_dep()

self._warn_no_prompt = True
self._warn_for_no_prompt = True

@property
def mainmenu_text(self):
Expand Down Expand Up @@ -737,15 +740,15 @@ def load_config(self, filename, replace=True):
"""
# Disable the warning about assigning to symbols without prompts. This
# is normal and expected within a .config file.
self._warn_no_prompt = False
self._warn_for_no_prompt = False

# This stub only exists to make sure _warn_no_prompt gets reenabled
# This stub only exists to make sure _warn_for_no_prompt gets reenabled
try:
self._load_config(filename, replace)
except UnicodeDecodeError as e:
_decoding_error(e, filename)
finally:
self._warn_no_prompt = True
self._warn_for_no_prompt = True

def _load_config(self, filename, replace):
with self._open(filename) as f:
Expand Down Expand Up @@ -1283,7 +1286,7 @@ def unset_values(self):
Resets the user values of all symbols, as if Kconfig.load_config() or
Symbol.set_value() had never been called.
"""
self._warn_no_prompt = False
self._warn_for_no_prompt = False
try:
# set_value() already rejects undefined symbols, and they don't
# need to be invalidated (because their value never changes), so we
Expand All @@ -1294,46 +1297,49 @@ def unset_values(self):
for choice in self._choices:
choice.unset_value()
finally:
self._warn_no_prompt = True
self._warn_for_no_prompt = True

def enable_warnings(self):
"""
See Kconfig.__init__().
"""
self._print_warnings = True
self._warnings_enabled = True

def disable_warnings(self):
"""
See Kconfig.__init__().
"""
self._print_warnings = False
self._warnings_enabled = False

def enable_undef_warnings(self):
"""
Enables warnings for assignments to undefined symbols. Printed to
stderr. Disabled by default since they tend to be spammy for Kernel
configurations (and mostly suggests cleanups).
"""
self._print_undef_assign = True
self._warn_for_undef_assign = True

def disable_undef_warnings(self):
"""
See enable_undef_assign().
"""
self._print_undef_assign = False
self._warn_for_undef_assign = False

def enable_redun_warnings(self):
"""
Enables warnings for redundant assignments to symbols. Printed to
stderr. Enabled by default.
Enables warnings for duplicated assignments in .config files that all
set the same value.
These warnings are enabled by default. Disabling them might be helpful
in certain cases when merging configurations.
"""
self._print_redun_assign = True
self._warn_for_redun_assign = True

def disable_redun_warnings(self):
"""
See enable_redun_warnings().
"""
self._print_redun_assign = False
self._warn_for_redun_assign = False

def __repr__(self):
"""
Expand All @@ -1346,11 +1352,11 @@ def __repr__(self):
"srctree not set" if self.srctree is None else
'srctree "{}"'.format(self.srctree),
'config symbol prefix "{}"'.format(self.config_prefix),
"warnings " + ("enabled" if self._print_warnings else "disabled"),
"warnings " + ("enabled" if self._warnings_enabled else "disabled"),
"undef. symbol assignment warnings " +
("enabled" if self._print_undef_assign else "disabled"),
("enabled" if self._warn_for_undef_assign else "disabled"),
"redundant symbol assignment warnings " +
("enabled" if self._print_redun_assign else "disabled")
("enabled" if self._warn_for_redun_assign else "disabled")
)))

#
Expand Down Expand Up @@ -2529,14 +2535,14 @@ def _parse_error(self, msg):
def _warn(self, msg, filename=None, linenr=None):
# For printing general warnings

if self._print_warnings:
if self._warnings_enabled:
_stderr_msg("warning: " + msg, filename, linenr)

def _warn_undef_assign(self, msg, filename=None, linenr=None):
# See the class documentation

if self._print_undef_assign:
_stderr_msg("warning: " + msg, filename, linenr)
if self._warn_for_undef_assign:
self._warn(msg, filename, linenr)

def _warn_undef_assign_load(self, name, val, filename, linenr):
# Special version for load_config()
Expand All @@ -2548,8 +2554,8 @@ def _warn_undef_assign_load(self, name, val, filename, linenr):
def _warn_redun_assign(self, msg, filename=None, linenr=None):
# See the class documentation

if self._print_redun_assign:
_stderr_msg("warning: " + msg, filename, linenr)
if self._warn_for_redun_assign:
self._warn(msg, filename, linenr)

class Symbol(object):
"""
Expand Down Expand Up @@ -3364,7 +3370,7 @@ def _rec_invalidate_if_has_prompt(self):
self._rec_invalidate()
return

if self.kconfig._warn_no_prompt:
if self.kconfig._warn_for_no_prompt:
self.kconfig._warn(_name_and_loc(self) + " has no prompt, meaning "
"user values have no effect on it")

Expand Down

0 comments on commit 8983f7e

Please sign in to comment.