From e5675d7aebcd75232e75b8c373dce2396b5b8aa8 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Mon, 1 Dec 2003 13:06:29 +0000 Subject: [PATCH] Make the message about missing SConscript files a warning, not a hard write(), so it can be ignored/disabled. (Scott Fritchie) git-svn-id: http://scons.tigris.org/svn/scons/trunk@851 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- doc/man/scons.1 | 5 ++++ src/CHANGES.txt | 3 ++ src/engine/SCons/Script/SConscript.py | 40 +++++++++++++++------------ src/engine/SCons/Script/__init__.py | 11 ++++++-- src/engine/SCons/Warnings.py | 15 ++++++---- test/option--warn.py | 17 ++++++++++++ test/option-f.py | 6 +++- 7 files changed, 70 insertions(+), 27 deletions(-) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index d726e9f6..034c920b 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -764,6 +764,11 @@ These warnings are disabled by default. Enables or disables warnings about use of deprecated features. These warnings are enabled by default. +.TP +--warn=missing-sconscript, --warn=no-missing-sconscript +Enables or disables warnings about missing SConscript files. +These warnings are enabled by default. + .TP --no-print-directory Turn off -w, even if it was turned on implicitly. diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 6c36cd44..037b6f69 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -39,6 +39,9 @@ RELEASE 0.95 - XXX - Fix the ability to use a custom _concat() function in the construction environment when calling _stripixes(). + - Make the message about ignoring a missing SConscript file into a + suppressable Warning, not a hard-coded sys.stderr.write(). + From Steven Knight: - Fix EnsureSConsVersion() so it checks against the SCons version, diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index 8894df7b..bd122d8d 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -236,8 +236,8 @@ def _SConscript(fs, *files, **kw): # number that creates a node. exec _file_ in stack[-1].globals else: - sys.stderr.write("Ignoring missing SConscript '%s'\n" % - f.path) + SCons.Warnings.warn(SCons.Warnings.MissingSConscriptWarning, + "Ignoring missing SConscript '%s'" % f.path) finally: sconscript_reading = 0 @@ -316,20 +316,19 @@ class SConsEnvironment(SCons.Environment.Base): # # Private methods of an SConsEnvironment. # - - def _check_version(self, major, minor, version_string): - """Return 0 if 'major' and 'minor' are greater than the version - in 'version_string', and 1 otherwise.""" - try: - v_major, v_minor, v_micro, release, serial = sys.version_info - except AttributeError: - version = string.split(string.split(version_string, ' ')[0], '.') - v_major = int(version[0]) - v_minor = int(re.match('\d+', version[1]).group()) - if major > v_major or (major == v_major and minor > v_minor): - return 0 - else: - return 1 + def _exceeds_version(self, major, minor, v_major, v_minor): + """Return 1 if 'major' and 'minor' are greater than the version + in 'v_major' and 'v_minor', and 0 otherwise.""" + return (major > v_major or (major == v_major and minor > v_minor)) + + def _get_major_minor(self, version_string): + """Split a version string into major and minor parts. This + is complicated by the fact that a version string can be something + like 3.2b1.""" + version = string.split(string.split(version_string, ' ')[0], '.') + v_major = int(version[0]) + v_minor = int(re.match('\d+', version[1]).group()) + return v_major, v_minor def _get_SConscript_filenames(self, ls, kw): """ @@ -429,13 +428,18 @@ class SConsEnvironment(SCons.Environment.Base): def EnsureSConsVersion(self, major, minor): """Exit abnormally if the SCons version is not late enough.""" - if not self._check_version(major,minor,SCons.__version__): + v_major, v_minor = self._get_major_minor(SCons.__version__) + if self._exceeds_version(major, minor, v_major, v_minor): print "SCons %d.%d or greater required, but you have SCons %s" %(major,minor,SCons.__version__) sys.exit(2) def EnsurePythonVersion(self, major, minor): """Exit abnormally if the Python version is not late enough.""" - if not self._check_version(major,minor,sys.version): + try: + v_major, v_minor, v_micro, release, serial = sys.version_info + except AttributeError: + v_major, v_minor = self._get_major_minor(sys.version) + if self._exceeds_version(major, minor, v_major, v_minor): v = string.split(sys.version, " ", 1)[0] print "Python %d.%d or greater required, but you have Python %s" %(major,minor,v) sys.exit(2) diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index 0134b97d..0e562141 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -352,8 +352,12 @@ def _setup_warn(arg): if len(elems) == 1 and elems[0] == 'all': class_name = "Warning" else: - class_name = string.join(map(string.capitalize, elems), '') + \ - "Warning" + def _capitalize(s): + if s[:5] == "scons": + return "SCons" + s[5:] + else: + return string.capitalize(s) + class_name = string.join(map(_capitalize, elems), '') + "Warning" try: clazz = getattr(SCons.Warnings, class_name) except AttributeError: @@ -703,8 +707,9 @@ def _main(args, parser): # Enable deprecated warnings by default. SCons.Warnings._warningOut = _scons_internal_warning - SCons.Warnings.enableWarningClass(SCons.Warnings.DeprecatedWarning) SCons.Warnings.enableWarningClass(SCons.Warnings.CorruptSConsignWarning) + SCons.Warnings.enableWarningClass(SCons.Warnings.DeprecatedWarning) + SCons.Warnings.enableWarningClass(SCons.Warnings.MissingSConscriptWarning) SCons.Warnings.enableWarningClass(SCons.Warnings.NoParallelSupportWarning) global ssoptions diff --git a/src/engine/SCons/Warnings.py b/src/engine/SCons/Warnings.py index cb78205a..64268303 100644 --- a/src/engine/SCons/Warnings.py +++ b/src/engine/SCons/Warnings.py @@ -34,24 +34,29 @@ import SCons.Errors class Warning(SCons.Errors.UserError): pass -class DeprecatedWarning(Warning): - pass -class DependencyWarning(Warning): + +class CacheWriteErrorWarning(Warning): pass class CorruptSConsignWarning(Warning): pass -class ReservedVariableWarning(Warning): +class DependencyWarning(Warning): pass -class CacheWriteErrorWarning(Warning): +class DeprecatedWarning(Warning): + pass + +class MissingSConscriptWarning(Warning): pass class NoParallelSupportWarning(Warning): pass +class ReservedVariableWarning(Warning): + pass + _warningAsException = 0 # The below is a list of 2-tuples. The first element is a class object. diff --git a/test/option--warn.py b/test/option--warn.py index aa970fed..c8e16a97 100644 --- a/test/option--warn.py +++ b/test/option--warn.py @@ -82,4 +82,21 @@ scons: warning: No dependency generated for file: not_there\.h \(included from: File ".+", line \d+, in .+ """) +test.write("SConstruct", """\ +def build(target, source, env): + pass + +env=Environment() +env['BUILDERS']['test'] = Builder(action=build) +env.test(target='foo', source='foo.c') +SConscript('no_such_file') +""") + +test.run(arguments = '--warn=missing-sconscript .', stderr = r""" +scons: warning: Ignoring missing SConscript 'no_such_file' +File ".+", line \d+, in .+ +""") + +test.run(arguments = '--warn=no-missing-sconscript .', stderr = "") + test.pass_test() diff --git a/test/option-f.py b/test/option-f.py index 2001a06b..3c8dcee8 100644 --- a/test/option-f.py +++ b/test/option-f.py @@ -86,6 +86,10 @@ print "STDIN " + os.getcwd() test.run(arguments = '-f no_such_file .', stdout = test.wrap_stdout("scons: `.' is up to date.\n"), - stderr = "Ignoring missing SConscript 'no_such_file'\n") + stderr = None) +test.fail_test(not test.match_re(test.stderr(), """ +scons: warning: Ignoring missing SConscript 'no_such_file' +File "\S+", line \d+, in .* +""")) test.pass_test() -- 2.26.2