root/branches/Dirk_CPtr/Source/SConscript

Revision 578, 6.1 kB (checked in by allenb, 2 years ago)

- Be more verbose about when we are running the test suites.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 #!python
2 import os, os.path
3 pj = os.path.join
4 from LibraryUtils import *
5 import SCons
6
7 Import('*')
8
9 import SCons
10
11 common_lib_env = build_env.Copy()
12
13 if verbose_build:
14    print "Setting up build for libraries: ",
15
16 # On windows we do not want to remove all default libraries from the list of libraries
17 # it searches when resolving external references.
18 if GetPlatform() == "win32":
19    common_lib_env.Append(LINKFLAGS = SCons.Util.CLVar('/nodefaultlib'))
20
21 for (lib_name, library) in lib_map.iteritems():
22    if verbose_build:
23       print "Library: ", lib_name, "  tests:", library.test_files, "  unittests:", library.unittest_files
24    else:
25       print "%s"%lib_name,
26    
27    # ---- Setup and Build library --- #
28    # - Setup environment for build: library deps, custom options
29    # - Set builder for the library
30    # - Install headers if in first pass
31    lib_env = common_lib_env.Copy()
32    full_lib_name = lib_name + shared_lib_suffix
33
34    # Use ConfigInfo to find build flags for building with/against this library and it's dependencies
35    # - We have to pull our library name off the list (slight hack)   
36    default_lib_settings = LibraryInfo()
37    config_info = ConfigInfoAdapter(lib_name, lib_map, default_lib_settings,
38                                    osg_lib_suffix=shared_lib_suffix)
39
40    dep_libs = [l for l in config_info.getLibs() if l != full_lib_name]
41    lib_env.Append(CPPPATH=config_info.getIncPath(),
42                   LIBPATH=[inst_paths["lib_inst_combo"]] + config_info.getLibPath(),
43                   LIBS=dep_libs,
44                   FRAMEWORKPATH=config_info.getFrameworkPath(),
45                   FRAMEWORKS=config_info.getFrameworks())
46
47    # XXX: Apply custom options
48    #
49    # Add the define needed for declspec to know what library we are building
50    compile_define = "OSG_COMPILE%sLIB"%lib_name[3:].upper()
51    lib_env.Append(CPPDEFINES=[compile_define])
52
53    if GetPlatform() == "win32":
54
55       lib_env.Append(LIBS = ["MSVCPRT$DEBUG_CHAR", "MSVCRT$DEBUG_CHAR"])
56
57       if "debug" == combo["type"] or "hybrid" == combo["type"]:
58          lib_env["DEBUG_CHAR"]='D'
59       else:
60          lib_env["DEBUG_CHAR"]=''
61
62    shared_lib = lib_env.SharedLibrary(full_lib_name, library.source_files)
63    shared_lib_inst = lib_env.Install(inst_paths['lib_inst_combo'], shared_lib)
64      
65    # If default combo type, then make links from lib dir
66    if default_combo_type == combo["type"] and (GetPlatform() != "win32"):
67       lib_env.Install(inst_paths["lib"], shared_lib_inst)     
68    
69    # Install headers (but only do it once during variant_pass 0 )
70    if variant_pass == 0:     
71       lib_env.Install(pj(inst_paths["include"],"OpenSG"), library.header_files)
72    
73    # ---- Build Tests ---- #   
74    # Verify we have all the deps for the tests
75    #   todo: How do we verify the "other test libs"
76    have_test_deps = True
77    for n in library.osg_test_libs:
78       if not lib_map.has_key(n):
79          have_test_deps = False
80          print "   missing test dep library:", n
81    
82    if have_test_deps:
83       # Use ConfigInfo to find build flags for building applications against this library
84       config_info = ConfigInfoAdapter([lib_name] + library.osg_test_libs,
85                                        lib_map,
86                                       osg_lib_suffix=shared_lib_suffix)   
87       test_env = build_env.Copy()
88       test_env.Append(CPPPATH=library.test_cpppath + config_info.getIncPath(),
89                       LIBPATH=library.test_libpath + [inst_paths["lib_inst_combo"]] + config_info.getLibPath(),
90                       LIBS=config_info.getLibs() + library.other_test_libs,
91                       FRAMEWORKPATH=config_info.getFrameworkPath(),
92                       FRAMEWORKS=config_info.getFrameworks())
93
94       if GetPlatform() == "win32":
95
96         test_env.Append(LIBS = ["MSVCPRT$DEBUG_CHAR", "MSVCRT$DEBUG_CHAR"])
97
98         if "debug" == combo["type"] or "hybrid" == combo["type"]:
99             test_env["DEBUG_CHAR"]='D'
100         else:
101             test_env["DEBUG_CHAR"]=''
102    
103       # - Build them all in the local 'test' subdir
104       for s in library.test_files:
105          test_env.Program(target= pj("..","test",os.path.splitext(os.path.basename(s))[0]),
106                           source=s)
107    
108       # ---- Build Unit Tests ---- #   
109       # - Build them all in the unittest directory
110       if build_env["enable_unittests"] and (len(library.unittest_files) > 0):         
111          unittest_env = test_env.Copy()
112          unittest_env.Append(CPPPATH=unittest_inc,
113                              LIBPATH=unittest_libpath,
114                              LIBS=unittest_lib)
115
116          if GetPlatform() == "win32":
117
118             unittest_env.Append(LIBS = ["MSVCPRT$DEBUG_CHAR", "MSVCRT$DEBUG_CHAR"])
119
120             if "debug" == combo["type"] or "hybrid" == combo["type"]:
121                 unittest_env["DEBUG_CHAR"]='D'
122                 unittest_env["UTDBGDIR"]='dbg'
123             else:
124                 unittest_env["DEBUG_CHAR"]=''
125                 unittest_env["UTDBGDIR"]='opt'
126
127          runner_obj = unittest_env.Object(target=pj("..","unittest","run"+lib_name), source=unittest_runner)
128          runner = unittest_env.Program(pj("..","unittest","run"+lib_name),
129                                        library.unittest_files + [str(runner_obj[0])])
130
131          # Run the Test once the program is built
132          def runTest(target, source, env):
133             path = ""
134             for i in env["LIBPATH"]:
135                 path += i + os.pathsep
136             path = path[:-1]
137            
138             ev = os.environ
139             if GetPlatform() == "win32":
140                 key = "PATH"
141             elif GetPlatform() == "darwin":
142                 key = "DYLD_LIBRARY_PATH"
143             else:
144                 key = "LD_LIBRARY_PATH"
145                
146             if ev.has_key(key):
147                 ev[key] = path + os.pathsep + ev[key]
148             else:
149                 ev[key] = path
150            
151             print "TEST SUITE: [%s]"%(target[0],)
152             prog = str(target[0])
153             exit_code = os.spawnle(os.P_WAIT, prog, prog, ev)
154            
155             if exit_code != 0:
156                 Exit(exit_code)
157
158          AddPostAction(runner, runTest)
159
160      
161    # Done   
162 if not verbose_build:
163    print ""
Note: See TracBrowser for help on using the browser.