dirkbaechle avatar dirkbaechle committed b02a7c4

- fixes for MinGW under Windows, mainly skipping MSVS-specific tests

Comments (0)

Files changed (30)

src/engine/SCons/Tool/mingw.py

         
 
     # Most of mingw is the same as gcc and friends...
-    gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas', 'm4']
+    gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas', 'gfortran', 'm4']
     for tool in gnu_tools:
         SCons.Tool.Tool(tool)(env)
 
     env['OBJSUFFIX'] = '.o'
     env['LIBPREFIX'] = 'lib'
     env['LIBSUFFIX'] = '.a'
+    env['PROGSUFFIX'] = '.exe'
 
 def exists(env):
     return find(env)

test/AS/ASFLAGS.py

 
 
 if sys.platform == 'win32':
-
+    import SCons.Tool.MSCommon as msc
+    
     o = ' -x'
-
     o_c = ' -x'
+    if not msc.msvc_exists():
+        o_c = ' -x -c'
 
     test.write('mylink.py', r"""
 import sys
 else:
 
     o = ' -x'
-
     o_c = ' -x -c'
 
     test.write('mylink.py', r"""

test/AS/ASPPFLAGS.py

 
 
 if sys.platform == 'win32':
+    import SCons.Tool.MSCommon as msc
 
     o = ' -x'
-
     o_c = ' -x'
+    if not msc.msvc_exists():
+        o_c = ' -x -c'
 
     test.write('mylink.py', r"""
 import sys

test/AS/as-live.py

 if not x86:
     test.skip_test("skipping as test on non-x86 platform '%s'\n" % sys.platform)
 
-
-
+namelbl = "name"
+testccc = """ccc = aaa.Clone(CPPPATH=['.'])
+ccc.Program(target = 'ccc', source = ['ccc.S', 'ccc_main.c'])
+"""
+if sys.platform == "win32":
+    namelbl = "_name"
+    testccc = ""
+    
 test.write("wrapper.py", """\
 import os
 import sys
 
 test.write('SConstruct', """\
 aaa = Environment()
+aaa.Program(target = 'aaa', source = ['aaa.s', 'aaa_main.c'])
 bbb = aaa.Clone(AS = r'%(_python_)s wrapper.py ' + WhereIs('as'))
-ccc = aaa.Clone(CPPPATH=['.'])
-aaa.Program(target = 'aaa', source = ['aaa.s', 'aaa_main.c'])
 bbb.Program(target = 'bbb', source = ['bbb.s', 'bbb_main.c'])
-ccc.Program(target = 'ccc', source = ['ccc.S', 'ccc_main.c'])
+%(testccc)s
 """ % locals())
 
 test.write('aaa.s', 
 """        .file   "aaa.s"
 .data
 .align 4
-.globl name
-name:
+.globl %(namelbl)s
+%(namelbl)s:
         .ascii	"aaa.s"
         .byte	0
-""")
+""" % locals())
 
 test.write('bbb.s', """\
 .file   "bbb.s"
 .data
 .align 4
-.globl name
-name:
+.globl %(namelbl)s
+%(namelbl)s:
         .ascii	"bbb.s"
         .byte	0
-""")
+""" % locals())
 
 test.write('ccc.h', """\
 #define STRING  "ccc.S"
 
 test.run(program = test.workpath('aaa'), stdout =  "aaa_main.c aaa.s\n")
 test.run(program = test.workpath('bbb'), stdout =  "bbb_main.c bbb.s\n")
-test.run(program = test.workpath('ccc'), stdout =  "ccc_main.c ccc.S\n")
 
-test.must_match('wrapper.out', "wrapper.py: bbb.s\n")
-
-test.write("ccc.h", """\
-#define STRING  "ccc.S 2"
-""")
-
-test.run()
-test.run(program = test.workpath('ccc'), stdout =  "ccc_main.c ccc.S 2\n")
+if sys.platform != "win32":
+    test.run(program = test.workpath('ccc'), stdout =  "ccc_main.c ccc.S\n")
+    
+    test.must_match('wrapper.out', "wrapper.py: bbb.s\n")
+    
+    test.write("ccc.h", """\
+    #define STRING  "ccc.S 2"
+    """)
+    
+    test.run()
+    test.run(program = test.workpath('ccc'), stdout =  "ccc_main.c ccc.S 2\n")
 
 test.unlink('wrapper.out')
 
-
-
 test.pass_test()
 
 # Local Variables:
         args = args[2:]
         continue
     args = args[1:]
-    if a[0] != '/':
+    if not a[0] in '-/':
         if not inf:
             inf = a
         continue

test/CC/CCFLAGS.py

 import sys
 import TestSCons
 
+_obj = TestSCons._obj
+
 if sys.platform == 'win32':
-    _obj = '.obj'
-    fooflags = '/nologo -DFOO'
-    barflags = '/nologo -DBAR'
+    import SCons.Tool.MSCommon as msc
+    
+    if not msc.msvc_exists():
+        fooflags = '-DFOO'
+        barflags = '-DBAR'
+    else:
+        fooflags = '/nologo -DFOO'
+        barflags = '/nologo -DBAR'
 else:
-    _obj = '.o'
     fooflags = '-DFOO'
     barflags = '-DBAR'
 

test/CC/CFLAGS.py

 test.must_not_contain_any_line(test.stdout(), ["-xyz"])
 test.must_contain_all_lines(test.stdout(), ["-abc"])
 
+_obj = TestSCons._obj
 
 # Test passing CFLAGS to C compiler by actually compiling programs
 if sys.platform == 'win32':
-    _obj = '.obj'
-    fooflags = '/nologo -DFOO'
-    barflags = '/nologo -DBAR'
+    import SCons.Tool.MSCommon as msc
+    
+    if not msc.msvc_exists():
+        fooflags = '-DFOO'
+        barflags = '-DBAR'
+    else:
+        fooflags = '/nologo -DFOO'
+        barflags = '/nologo -DBAR'
 else:
-    _obj = '.o'
     fooflags = '-DFOO'
     barflags = '-DBAR'
 
     msg = "Skipping test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
+
 #####
 # Test the basics
 

test/LINK/SHLINKCOMSTR.py

 the displayed linker string for programs using shared libraries.
 """
 
+import sys
 import TestSCons
 
 _python_ = TestSCons._python_
 
 test.must_match('test3.dll', "test1.c\ntest2.c\n")
 
-
-# Now test an actual compile and link.  Since MS Windows
-# resets the link actions, this could fail even if the above
-# test passed.
-test.write('SConstruct', """
-env = Environment(CXXCOMSTR    = 'Compiling $TARGET ...',
-                  SHLINKCOMSTR   = 'Shared-Linking $TARGET ...')
-env.SharedLibrary('test', 'test.cpp')
-""")
-test.write('test.cpp', """
-int i;
-""")
-
-test.run()
-if ("Shared-Linking" not in test.stdout()):
-    test.fail_test()
-
-
+if sys.platform == "win32":
+    import SCons.Tool.MSCommon as msc
+    if msc.msvc_exists():
+        # Now test an actual compile and link.  Since MS Windows
+        # resets the link actions, this could fail even if the above
+        # test passed.
+        test.write('SConstruct', """
+        env = Environment(CXXCOMSTR    = 'Compiling $TARGET ...',
+                          SHLINKCOMSTR   = 'Shared-Linking $TARGET ...')
+        env.SharedLibrary('test', 'test.cpp')
+        """)
+        test.write('test.cpp', """
+        int i;
+        """)
+        
+        test.run()
+        if ("Shared-Linking" not in test.stdout()):
+            test.fail_test()
 
 test.pass_test()
 

test/Libs/LIBPREFIXES.py

 
 if sys.platform == 'win32':
     _lib = '.lib'
+    import SCons.Tool.MSCommon as msc
+    if not msc.msvc_exists():
+        _lib = '.a'
 else:
     _lib = '.a'
 

test/Libs/LIBS.py

 if sys.platform == 'win32':
     _exe = '.exe'
     bar_lib = 'bar.lib'
+    import SCons.Tool.MSCommon as msc
+    if not msc.msvc_exists():
+        bar_lib = 'libbar.a'
 else:
     _exe = ''
     bar_lib = 'libbar.a'

test/Libs/LIBSUFFIXES.py

 
 if sys.platform == 'win32':
     lib_ = ''
+    import SCons.Tool.MSCommon as msc
+    if not msc.msvc_exists():
+        lib_ = 'lib'
 else:
     lib_ = 'lib'
 

test/Libs/SharedLibraryIxes.py

 test.write('SConstruct', """
 import sys
 isWindows = sys.platform == 'win32'
+isMingw = False
+if isWindows:
+    import SCons.Tool.MSCommon as msc
+    if not msc.msvc_exists():
+        # We can't seem to find any MSVC version, so we assume
+        # that MinGW is installed instead. Accordingly, we use the
+        # standard gcc/g++ conventions for lib prefixes and suffixes
+        # in the following...
+        isWindows = False
+        isMingw = True
 
 env = Environment()
 
 prog_obj = env.SharedObject(source='prog.c')
 
 #
-# The following functions define all the different way that one can
-# use link againt a shared library.
+# The following functions define all the different ways that one can
+# use to link against a shared library.
 #
 def nodeInSrc(source, lib, libname):
     return (source+lib, '')
     # provide the full name of the library since scons can not know
     # which of the non-standard extension to use.
     # 
-    # Note that this is not necessarally SHLIBPREFIX and
+    # Note that this is not necessarily SHLIBPREFIX and
     # SHLIBSUFFIX. These are the ixes of the target library, not the
-    # ixes of the library that we are linking againt.
+    # ixes of the library that we are linking against.
     return (source, libname)
 
-libmethods = [
-    nodeInSrc, pathInSrc, nodeInLib, pathInLib, 
-    nameInLib ]
+libmethods = [nodeInSrc, pathInSrc, nodeInLib, pathInLib]
+# We skip the nameInLib test for MinGW...it would fail, due to
+# the Tool's internal naming conventions
+if not isMingw:
+    libmethods.extend([nameInLib])
 
 def buildAndlinkAgainst(builder, target, source,  method, lib, libname, **kw):
-    '''Build a target using a given builder while linking againt a given
+    '''Build a target using a given builder while linking against a given
     library using a specified method for linking against the library.'''
 
     # On Windows, we have to link against the .lib file.
             if str(l)[-4:] == '.lib':
                 lib = [l]
                 break
+    # If we use MinGW and create a SharedLibrary, we get two targets: a DLL,
+    # and the import lib created by the "--out-implib" parameter. We always
+    # want to link against the second one, in order to prevent naming issues
+    # for the linker command line...
+    if isMingw and len(lib) > 1:
+        lib = lib[1:]
+        
+    # Apply the naming method to be tested and call the specified Builder.
     (source, LIBS) = method(source, lib, libname)
     #build = builder(target=target, source=source, LIBS=LIBS, **kw)
     kw = kw.copy()

test/MSVC/PCH-source.py

     msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
 
 test.write('SConstruct', """\
 env = Environment(tools=['msvc', 'mslink'])

test/MSVC/PCHSTOP-errors.py

     msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
 
 
 SConstruct_path = test.workpath('SConstruct')

test/MSVC/TARGET_ARCH.py

     msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
+
 test.write('SConstruct', """
 env_64 = Environment(tools=['default', 'msvc'],
                   TARGET_ARCH = 'amd64')

test/MSVC/batch-longlines.py

     msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
+
 _python_ = TestSCons._python_
 
 for i in xrange(1,200):

test/MSVC/embed-manifest.py

     msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
+
 test.write('SConstruct', """\
 env=Environment(WINDOWS_EMBED_MANIFEST=True)
 env.Append(CCFLAGS = '/MD')

test/MSVC/hierarchical.py

     msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
 
 
 test.subdir('src', 'build', 'out')

test/MSVC/msvc.py

     msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
+
 #####
 # Test the basics
 

test/MSVC/multiple-pdb.py

     msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
+
 test.write('SConstruct', """\
 env = Environment(PDB = '${TARGET.base}.pdb')
 env.Program('test1.cpp')

test/MSVC/pch-spaces-subdir.py

     msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
+
 test.write('Main.cpp', """\
 #include "Precompiled.h"
 

test/MSVC/pdb-VariantDir-path.py

     msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
+
 test.subdir('src')
 
 test.write('SConstruct', """\

test/MSVC/pdb-manifest.py

     msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
+
 test.write('SConstruct', """\
 env = Environment()
 

test/MSVC/query_vcbat.py

     msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test\n"
+    test.skip_test(msg)
+
 #####
 # Test the basics
 

test/MSVS/CPPPATH-Dirs.py

     msg = "Skipping Visual Studio test on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvs_exists():
+    msg = "No MSVS toolchain found...skipping test\n"
+    test.skip_test(msg)
 
 SConscript_contents = """\
 env = Environment()

test/Win32/mingw.py

 assert env['CC'] == 'gcc'
 env.StaticLibrary('static', 'static.cpp')
 env.SharedLibrary('shared', 'shared.cpp')
-env.SharedLibrary('cshared', ['cshared.c', 'cshared.def'])
+env.SharedLibrary('cshared', ['cshared.c', 'cshared.def'], WINDOWS_INSERT_DEF=1)
 env.Program('test', ['test.cpp', env.RES('resource.rc', CPPPATH=['header'])], LIBS=['static', 'shared', 'cshared'], LIBPATH=['.'])
 """)
 
 test.fail_test(test.stdout().find('cshared.def') == -1)
 test.fail_test(test.stdout().find('-Wl,--output-def,cshared.def') != -1)
 # ensure the target def got generated for the shared.dll:
-test.fail_test(not os.path.exists(test.workpath('shared.def')))
+test.fail_test(not os.path.exists(test.workpath('cshared.def')))
+test.fail_test(os.path.exists(test.workpath('shared.def')))
 test.run(program=test.workpath('test.exe'), stdout='test.cpp\nshared.cpp\nstatic.cpp\ncshared.c\n2001 resource.rc\n')
 
 # ensure that modifying the header causes the resource to be rebuilt:

test/Win32/win32pathmadness.py

     msg = "Skipping Windows path tests on non-Windows platform '%s'\n" % sys.platform
     test.skip_test(msg)
 
+import SCons.Tool.MSCommon as msc
+if not msc.msvc_exists():
+    msg = "No MSVC toolchain found...skipping test'\n"
+    test.skip_test(msg)
+
 test.subdir('src', 'build', 'include', 'src2')
 
 test.write('src/SConstruct', """

test/long-lines/live.py

     arflag = ' /LIBPATH:' + test.workpath()
     linkflag_init = '/LIBPATH:' + test.workpath()
     linkflag = ' /LIBPATH:' + test.workpath()
+    import SCons.Tool.MSCommon as msc
+    if not msc.msvc_exists():
+        lib_shared_dll = 'shared.dll'
+        lib_static_lib = 'libstatic.a'
+        arflag_init = 'r'
+        arflag = 'o'
+        linkflag_init = '-L' + test.workpath()
+        linkflag = ' -L' + test.workpath()    
 elif sys.platform == 'cygwin':
     lib_static_lib = 'libstatic.a'
     lib_shared_dll ='shared.dll'

test/sconsign/script/dblite.py

 
 test = TestSConsign.TestSConsign(match = TestSConsign.match_re)
 
+_exe = TestSConsign._exe
+_obj = TestSConsign._obj
+
 CC = test.detect('CC', norm=1)
 LINK = test.detect('LINK', norm=1)
 if LINK is None: LINK = CC
 # canonicalized to use / as the separator.
 
 sub1_hello_c    = 'sub1/hello.c'
-sub1_hello_obj  = 'sub1/hello.obj'
+sub1_hello_obj  = 'sub1/hello%s' % _obj
 
 test.write('SConstruct', """
 SConsignFile('my_sconsign')
 Decider('timestamp-newer')
-env1 = Environment(PROGSUFFIX = '.exe', OBJSUFFIX = '.obj')
+env1 = Environment()
 env1.Program('sub1/hello.c')
 env2 = env1.Clone(CPPPATH = ['sub2'])
 env2.Program('sub2/hello.c')
 date_re = r'\S+ \S+ [ \d]\d \d\d:\d\d:\d\d \d\d\d\d'
 
 if sys.platform == 'win32':
-    manifest = r"""
+    import SCons.Tool.MSCommon as msc
+    if msc.msvc_exists():
+        manifest = r"""
 embedManifestExeCheck\(target, source, env\)"""
+    else:
+        manifest = ''
 else:
     manifest = ''
 
 expect = r"""=== sub1:
-hello.exe: %(sig_re)s \d+ \d+
+hello%(_exe)s: %(sig_re)s \d+ \d+
         %(sub1_hello_obj)s: %(sig_re)s \d+ \d+
         %(LINK)s: None \d+ \d+
         %(sig_re)s \[.*%(manifest)s\]
-hello.obj: %(sig_re)s \d+ \d+
+hello%(_obj)s: %(sig_re)s \d+ \d+
         %(sub1_hello_c)s: None \d+ \d+
         %(CC)s: None \d+ \d+
         %(sig_re)s \[.*\]
 """ % locals()
 
 expect_r = """=== sub1:
-hello.exe: %(sig_re)s '%(date_re)s' \d+
+hello%(_exe)s: %(sig_re)s '%(date_re)s' \d+
         %(sub1_hello_obj)s: %(sig_re)s '%(date_re)s' \d+
         %(LINK)s: None '%(date_re)s' \d+
         %(sig_re)s \[.*%(manifest)s\]
-hello.obj: %(sig_re)s '%(date_re)s' \d+
+hello%(_obj)s: %(sig_re)s '%(date_re)s' \d+
         %(sub1_hello_c)s: None '%(date_re)s' \d+
         %(CC)s: None '%(date_re)s' \d+
         %(sig_re)s \[.*\]
 """ % locals()
 
-common_flags = '-e hello.exe -e hello.obj -d sub1'
+common_flags = '-e hello%(_exe)s -e hello%(_obj)s -d sub1' % locals()
 
 test.run_sconsign(arguments = "%s my_sconsign" % common_flags,
                   stdout = expect)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.