Make the message about missing SConscript files a warning, not a hard write(), so...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 1 Dec 2003 13:06:29 +0000 (13:06 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 1 Dec 2003 13:06:29 +0000 (13:06 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@851 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/scons.1
src/CHANGES.txt
src/engine/SCons/Script/SConscript.py
src/engine/SCons/Script/__init__.py
src/engine/SCons/Warnings.py
test/option--warn.py
test/option-f.py

index d726e9f6707b250557f454d02b12166bd124f4a1..034c920b8430b40d1dc3b354ce832ef2054241eb 100644 (file)
@@ -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.
index 6c36cd442cf843b85ea1e5a34a946a9f84f7339c..037b6f69e2ac08461bdecae691b171b8f37c2233 100644 (file)
@@ -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,
index 8894df7be44ab5ac26f85c333d9a4979a2b6d791..bd122d8d43dd5b7c4cd646909900ecc7f4d4bf01 100644 (file)
@@ -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)
index 0134b97da7dc063d3084475d39ef4896141b8970..0e56214139d02c2a9a070e99fcdd87db749f743b 100644 (file)
@@ -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
index cb78205a686fb33e288ffb045d2bc59392a8cab4..642683033878e5b0363e6f258290e06faea08457 100644 (file)
@@ -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.
index aa970fed8ee5fc6aa277f7cb81592d2c26d0dcbb..c8e16a97e311eb0596bdb48ffb104f85e08f1caa 100644 (file)
@@ -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()
index 2001a06bbe05f6c33d73500b3e8aef1ebba1245e..3c8dcee86e67eadc606e23e19e03499e2b409a63 100644 (file)
@@ -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()