diff options
author | Steven Knight <knight@baldmt.com> | 2001-12-21 17:46:00 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2001-12-21 17:46:00 (GMT) |
commit | 15674b6b3ee16f5979f5ceb971531d3b1f29f567 (patch) | |
tree | 7ccc14355826f31e7abf4304e6a9c7cbd9a61718 /src | |
parent | 754c465fbd31d4c9518e0bbdc20ee5021934aee9 (diff) | |
download | SCons-15674b6b3ee16f5979f5ceb971531d3b1f29f567.zip SCons-15674b6b3ee16f5979f5ceb971531d3b1f29f567.tar.gz SCons-15674b6b3ee16f5979f5ceb971531d3b1f29f567.tar.bz2 |
Provide an error message when a command isn't found.
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES.txt | 3 | ||||
-rw-r--r-- | src/engine/SCons/Builder.py | 25 | ||||
-rw-r--r-- | src/engine/SCons/BuilderTests.py | 55 |
3 files changed, 66 insertions, 17 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index cecf717..4f161e4 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -15,6 +15,9 @@ RELEASE 0.02 - - Fix to setup.py so it doesn't require a sys.argv[1] argument. + - Provide make-like warning message for "command not found" and + similar errors. + From Charles Crain: - Added support for the Install method. diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index d221629..2f93723 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -36,6 +36,7 @@ import os.path import SCons.Node.FS from SCons.Util import PathList, scons_str2nodes, scons_subst, scons_subst_list, autogenerate import string +import sys import types from UserList import UserList from UserDict import UserDict @@ -48,6 +49,10 @@ except ImportError: pass +exitvalmap = { + 2 : 127, + 13 : 126, +} if os.name == 'posix': @@ -55,7 +60,13 @@ if os.name == 'posix': pid = os.fork() if not pid: # Child process. - os.execvpe(cmd, args, env) + exitval = 127 + try: + os.execvpe(cmd, args, env) + except OSError, e: + exitval = exitvalmap[e[0]] + sys.stderr.write("scons: %s: %s\n" % (cmd, e[1])) + os._exit(exitval) else: # Parent process. pid, stat = os.waitpid(pid, 0) @@ -97,10 +108,14 @@ elif os.name == 'nt': def spawn(cmd, args, env): try: - ret = os.spawnvpe(os.P_WAIT, cmd, args, env) - except AttributeError: - cmd = pathsearch(cmd, env) - ret = os.spawnve(os.P_WAIT, cmd, args, env) + try: + ret = os.spawnvpe(os.P_WAIT, cmd, args, env) + except AttributeError: + cmd = pathsearch(cmd, env) + ret = os.spawnve(os.P_WAIT, cmd, args, env) + except OSError, e: + ret = exitvalmap[e[0]] + sys.stderr.write("scons: %s: %s\n" % (cmd, e[1])) return ret diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 5beee1a..ad13dd7 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -36,6 +36,7 @@ import unittest import TestCmd import SCons.Builder +import SCons.Errors # Initial setup of the common environment for all tests, # a temporary working directory containing a @@ -125,11 +126,18 @@ class BuilderTestCase(unittest.TestCase): containing one of each. """ + def MyBuilder(**kw): + builder = apply(SCons.Builder.Builder, (), kw) + def no_show(str): + pass + builder.action.show = no_show + return builder + python = sys.executable cmd1 = r'%s %s %s xyzzy' % (python, act_py, outfile) - builder = SCons.Builder.Builder(action = cmd1) + builder = MyBuilder(action = cmd1) r = builder.execute() assert r == 0 c = test.read(outfile, 'r') @@ -137,7 +145,7 @@ class BuilderTestCase(unittest.TestCase): cmd2 = r'%s %s %s $TARGET' % (python, act_py, outfile) - builder = SCons.Builder.Builder(action = cmd2) + builder = MyBuilder(action = cmd2) r = builder.execute(target = 'foo') assert r == 0 c = test.read(outfile, 'r') @@ -145,7 +153,7 @@ class BuilderTestCase(unittest.TestCase): cmd3 = r'%s %s %s ${TARGETS}' % (python, act_py, outfile) - builder = SCons.Builder.Builder(action = cmd3) + builder = MyBuilder(action = cmd3) r = builder.execute(target = ['aaa', 'bbb']) assert r == 0 c = test.read(outfile, 'r') @@ -153,7 +161,7 @@ class BuilderTestCase(unittest.TestCase): cmd4 = r'%s %s %s $SOURCES' % (python, act_py, outfile) - builder = SCons.Builder.Builder(action = cmd4) + builder = MyBuilder(action = cmd4) r = builder.execute(source = ['one', 'two']) assert r == 0 c = test.read(outfile, 'r') @@ -161,7 +169,7 @@ class BuilderTestCase(unittest.TestCase): cmd4 = r'%s %s %s ${SOURCES[:2]}' % (python, act_py, outfile) - builder = SCons.Builder.Builder(action = cmd4) + builder = MyBuilder(action = cmd4) r = builder.execute(source = ['three', 'four', 'five']) assert r == 0 c = test.read(outfile, 'r') @@ -169,7 +177,7 @@ class BuilderTestCase(unittest.TestCase): cmd5 = r'%s %s %s $TARGET XYZZY' % (python, act_py, outfile) - builder = SCons.Builder.Builder(action = cmd5) + builder = MyBuilder(action = cmd5) r = builder.execute(target = 'out5', env = {'ENV' : {'XYZZY' : 'xyzzy'}}) assert r == 0 c = test.read(outfile, 'r') @@ -183,7 +191,7 @@ class BuilderTestCase(unittest.TestCase): cmd6 = r'%s %s %s ${TARGETS[1]} $TARGET ${SOURCES[:2]}' % (python, act_py, outfile) - builder = SCons.Builder.Builder(action = cmd6) + builder = MyBuilder(action = cmd6) r = builder.execute(target = [Obj('111'), Obj('222')], source = [Obj('333'), Obj('444'), Obj('555')]) assert r == 0 @@ -195,7 +203,7 @@ class BuilderTestCase(unittest.TestCase): expect7 = '%s %s %s one\n%s %s %s two\n' % (python, act_py, outfile, python, act_py, outfile) - builder = SCons.Builder.Builder(action = cmd7) + builder = MyBuilder(action = cmd7) global show_string show_string = "" @@ -212,7 +220,7 @@ class BuilderTestCase(unittest.TestCase): open(kw['target'], 'w').write("function1\n") return 1 - builder = SCons.Builder.Builder(action = function1) + builder = MyBuilder(action = function1) r = builder.execute(target = outfile) assert r == 1 c = test.read(outfile, 'r') @@ -222,7 +230,7 @@ class BuilderTestCase(unittest.TestCase): def __init__(self, **kw): open(kw['out'], 'w').write("class1a\n") - builder = SCons.Builder.Builder(action = class1a) + builder = MyBuilder(action = class1a) r = builder.execute(out = outfile) assert r.__class__ == class1a c = test.read(outfile, 'r') @@ -233,7 +241,7 @@ class BuilderTestCase(unittest.TestCase): open(kw['out'], 'w').write("class1b\n") return 2 - builder = SCons.Builder.Builder(action = class1b()) + builder = MyBuilder(action = class1b()) r = builder.execute(out = outfile) assert r == 2 c = test.read(outfile, 'r') @@ -254,12 +262,35 @@ class BuilderTestCase(unittest.TestCase): def __init__(self, **kw): open(kw['out'], 'a').write("class2b\n") - builder = SCons.Builder.Builder(action = [cmd2, function2, class2a(), class2b]) + builder = MyBuilder(action = [cmd2, function2, class2a(), class2b]) r = builder.execute(out = outfile) assert r.__class__ == class2b c = test.read(outfile, 'r') assert c == "act.py: 'syzygy'\nfunction2\nclass2a\nclass2b\n", c + # Test that a nonexistent command returns 127 + builder = MyBuilder(action = python + "_XyZzY_") + r = builder.execute(out = outfile) + assert r == 127, "r == %d" % r + + if os.name == 'nt': + # NT treats execs of directories and non-executable files + # as "file not found" errors + expect = 127 + else: + expect = 126 + + # Test that trying to execute a directory returns 126 + dir, tail = os.path.split(python) + builder = MyBuilder(action = dir) + r = builder.execute(out = outfile) + assert r == expect, "r == %d" % r + + # Test that trying to execute a non-executable file returns 126 + builder = MyBuilder(action = outfile) + r = builder.execute(out = outfile) + assert r == expect, "r == %d" % r + def test_get_contents(self): """Test returning the signature contents of a Builder """ |