Clean up and simplify logic. TODO: scons -c isn't removing the .di files. Mainly...
[scons.git] / test / MSVS / vs-14.1-exec.py
blob2accaafab61b914d37c1460a08c0329354cbf6b4
1 #!/usr/bin/env python
3 # __COPYRIGHT__
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Test that we can actually build a simple program using our generated
29 Visual Studio 14.1 project (.vcxproj) and solution (.sln) files
30 using Visual Studio 14.1 (Professional edition).
31 """
33 import os
34 import sys
36 import TestSConsMSVS
38 test = TestSConsMSVS.TestSConsMSVS()
40 if sys.platform != 'win32':
41 msg = "Skipping Visual Studio test on non-Windows platform '%s'\n" % sys.platform
42 test.skip_test(msg)
44 msvs_version = '14.1'
46 if msvs_version not in test.msvs_versions():
47 msg = "Visual Studio %s not installed; skipping test.\n" % msvs_version
48 test.skip_test(msg)
52 # Let SCons figure out the Visual Studio environment variables for us and
53 # print out a statement that we can exec to suck them into our external
54 # environment so we can execute devenv and really try to build something.
56 test.run(arguments = '-n -q -Q -f -', stdin = """\
57 env = Environment(tools = ['msvc'], MSVS_VERSION='%(msvs_version)s')
58 if env.WhereIs('cl'):
59 print("os.environ.update(%%s)" %% repr(env['ENV']))
60 """ % locals())
62 if test.stdout() == "":
63 msg = "Visual Studio %s missing cl.exe; skipping test.\n" % msvs_version
64 test.skip_test(msg)
66 exec(test.stdout())
70 test.subdir('sub dir')
72 test.write(['sub dir', 'SConstruct'], """\
73 env=Environment(MSVS_VERSION = '%(msvs_version)s')
75 env.MSVSProject(target = 'foo.vcxproj',
76 srcs = ['foo.c'],
77 buildtarget = 'foo.exe',
78 variant = 'Release',
79 DebugSettings = {'LocalDebuggerCommandArguments':'echo "<foo.c>" > output.txt'})
80 env.Program('foo.c')
81 """ % locals())
83 test.write(['sub dir', 'foo.c'], r"""
84 #include <stdio.h>
85 int
86 main(int argc, char *argv)
88 printf("foo.c\n");
89 exit (0);
91 """)
93 test.run(chdir='sub dir', arguments='.')
95 test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj'))
97 import SCons.Platform.win32
98 system_dll_path = os.path.join( SCons.Platform.win32.get_system_root(), 'System32' )
99 os.environ['PATH'] = os.environ['PATH'] + os.pathsep + system_dll_path
101 test.run(chdir='sub dir',
102 program=[test.get_msvs_executable(msvs_version)],
103 arguments=['foo.sln', '/build', 'Release'])
105 test.run(program=test.workpath('sub dir', 'foo'), stdout="foo.c\n")
106 test.validate_msvs_file(test.workpath('sub dir', 'foo.vcxproj.user'))
108 test.pass_test()
110 # Local Variables:
111 # tab-width:4
112 # indent-tabs-mode:nil
113 # End:
114 # vim: set expandtab tabstop=4 shiftwidth=4: