def test_get_default_version(self): """Test retrieval of the default visual studio version""" debug("Testing for default version %s"%self.default_version) env = DummyEnv() v1 = get_default_version(env) if v1: assert env['MSVS_VERSION'] == self.default_version, \ ("env['MSVS_VERSION'] != self.default_version", env['MSVS_VERSION'],self.default_version) assert env['MSVS']['VERSION'] == self.default_version, \ ("env['MSVS']['VERSION'] != self.default_version", env['MSVS']['VERSION'], self.default_version) assert v1 == self.default_version, (self.default_version, v1) env = DummyEnv({'MSVS_VERSION':'7.0'}) v2 = get_default_version(env) assert env['MSVS_VERSION'] == '7.0', env['MSVS_VERSION'] assert env['MSVS']['VERSION'] == '7.0', env['MSVS']['VERSION'] assert v2 == '7.0', v2 env = DummyEnv() v3 = get_default_version(env) if v3 == '7.1': override = '7.0' else: override = '7.1' env['MSVS_VERSION'] = override v3 = get_default_version(env) assert env['MSVS_VERSION'] == override, env['MSVS_VERSION'] assert env['MSVS']['VERSION'] == override, env['MSVS']['VERSION'] assert v3 == override, v3
def find_vc_product_dir(self): if not SCons.Util.can_read_reg: debug('find_vc_product_dir(): can not read registry') return None key = self.hkey_root + '\\' + self.vc_product_dir_key try: comps = read_reg(key) except WindowsError as e: debug('find_vc_product_dir(): no registry key %s' % key) else: if self.batch_file_dir_reg_relpath: comps = os.path.join(comps, self.batch_file_dir_reg_relpath) comps = os.path.normpath(comps) if os.path.exists(comps): return comps else: debug('find_vc_product_dir(): %s not on file system' % comps) d = os.environ.get(self.common_tools_var) if not d: msg = 'find_vc_product_dir(): no %s variable' debug(msg % self.common_tools_var) return None if not os.path.isdir(d): debug('find_vc_product_dir(): %s not on file system' % d) return None if self.batch_file_dir_env_relpath: d = os.path.join(d, self.batch_file_dir_env_relpath) d = os.path.normpath(d) return d
def find_vc_product_dir(self): if not SCons.Util.can_read_reg: debug('find_vc_product_dir(): can not read registry') return None key = self.hkey_root + '\\' + self.vc_product_dir_key try: comps = read_reg(key) except WindowsError, e: debug('find_vc_product_dir(): no registry key %s' % key)
def setUp(self): debug("THIS TYPE :%s"%self) global registry registry = self.registry from SCons.Tool.MSCommon.vs import reset_installed_visual_studios reset_installed_visual_studios() self.test = TestCmd.TestCmd(workdir='') # FS doesn't like the cwd to be something other than its root. os.chdir(self.test.workpath("")) self.fs = SCons.Node.FS.FS()
def find_executable(self): pdir = self.get_vc_product_dir() if not pdir: debug('find_executable(): no pdir') return None executable = os.path.join(pdir, self.executable_path) executable = os.path.normpath(executable) if not os.path.isfile(executable): debug('find_executable(): %s not on file system' % executable) return None return executable
def OpenKeyEx(self,root,key): if root == SCons.Util.HKEY_CLASSES_ROOT: mykey = 'HKEY_CLASSES_ROOT\\' + key if root == SCons.Util.HKEY_USERS: mykey = 'HKEY_USERS\\' + key if root == SCons.Util.HKEY_CURRENT_USER: mykey = 'HKEY_CURRENT_USER\\' + key if root == SCons.Util.HKEY_LOCAL_MACHINE: mykey = 'HKEY_LOCAL_MACHINE\\' + key debug("Open Key:%s"%mykey) return self.root.key(mykey)
def get_installed_sdks(): global InstalledSDKList global InstalledSDKMap if InstalledSDKList is None: InstalledSDKList = [] InstalledSDKMap = {} for sdk in SupportedSDKList: debug('trying to find SDK %s' % sdk.version) if sdk.get_sdk_dir(): debug('found SDK %s' % sdk.version) InstalledSDKList.append(sdk) InstalledSDKMap[sdk.version] = sdk return InstalledSDKList
def get_installed_visual_studios(): global InstalledVSList global InstalledVSMap if InstalledVSList is None: InstalledVSList = [] InstalledVSMap = {} for vs in SupportedVSList: debug('trying to find VS %s' % vs.version) if vs.get_executable(): debug('found VS %s' % vs.version) InstalledVSList.append(vs) InstalledVSMap[vs.version] = vs return InstalledVSList
def find_sdk_dir(self): """Try to find the MS SDK from the registry. Return None if failed or the directory does not exist. """ if not SCons.Util.can_read_reg: debug('find_sdk_dir(): can not read registry') return None hkey = self.HKEY_FMT % self.hkey_data try: sdk_dir = read_reg(hkey) except WindowsError as e: debug('find_sdk_dir(): no registry key %s' % hkey) return None if not os.path.exists(sdk_dir): debug('find_sdk_dir(): %s not on file system' % sdk_dir) return None ftc = os.path.join(sdk_dir, self.sanity_check_file) if not os.path.exists(ftc): debug("find_sdk_dir(): sanity check %s not found" % ftc) return None return sdk_dir
def find_batch_file(self): """Try to find the Visual Studio or Visual C/C++ batch file. Return None if failed or the batch file does not exist. """ pdir = self.get_vc_product_dir() if not pdir: debug('find_batch_file(): no pdir') return None batch_file = os.path.normpath(os.path.join(pdir, self.batch_file)) batch_file = os.path.normpath(batch_file) if not os.path.isfile(batch_file): debug('find_batch_file(): %s not on file system' % batch_file) return None return batch_file
def find_sdk_dir(self): """Try to find the MS SDK from the registry. Return None if failed or the directory does not exist. """ if not SCons.Util.can_read_reg: debug('find_sdk_dir(): can not read registry') return None hkey = self.HKEY_FMT % self.hkey_data try: sdk_dir = read_reg(hkey) except WindowsError, e: debug('find_sdk_dir(): no registry key %s' % hkey) return None
def generate(env): targetArch = env.get('TARGET_ARCH', 'x86') d = fetchSDKVars(targetArch, 'v7.1A') if d: env.Append(CPPDEFINES='_USING_V110_SDK71_') env.Append(CCFLAGS='/wd4091') if targetArch.endswith('64'): env.Append(LINKFLAGS=[env['LINKFLAGS'], '/SUBSYSTEM:WINDOWS,5.02']) else: # #3730: VC2012 uses SSE2 by default, but NVDA is still run on some older processers (AMD Athlon etc) which don't support this. env.Append(CCFLAGS='/arch:IA32') env.Append(LINKFLAGS=[env['LINKFLAGS'], '/SUBSYSTEM:WINDOWS,5.01']) if not d: common.debug("windowsSdk.py, Generate: No suitable SDK could be used") raise RuntimeError("Windows SDK 7.1A could not be found") #msvc.generate(env) for k, v in d.iteritems(): env.PrependENVPath(k, v, delete_existing=True)
def generate(env): targetArch=env.get('TARGET_ARCH','x86') d=fetchSDKVars(targetArch,'v7.1A') if d: env.Append(CPPDEFINES='_USING_V110_SDK71_') env.Append(CCFLAGS='/wd4091') if targetArch.endswith('64'): env.Append(LINKFLAGS=[env['LINKFLAGS'],'/SUBSYSTEM:WINDOWS,5.02']) else: # #3730: VC2012 uses SSE2 by default, but NVDA is still run on some older processers (AMD Athlon etc) which don't support this. env.Append(CCFLAGS='/arch:IA32') env.Append(LINKFLAGS=[env['LINKFLAGS'],'/SUBSYSTEM:WINDOWS,5.01']) if not d: common.debug("windowsSdk.py, Generate: No suitable SDK could be used") raise RuntimeError("Windows SDK 7.1A could not be found") #msvc.generate(env) for k, v in d.iteritems(): env.PrependENVPath(k,v,delete_existing=True)
def get_cur_sdk_dir_from_reg(): """Try to find the platform sdk directory from the registry. Return None if failed or the directory does not exist""" if not SCons.Util.can_read_reg: debug('SCons cannot read registry') return None try: val = read_reg(_CURINSTALLED_SDK_HKEY_ROOT) debug("Found current sdk dir in registry: %s" % val) except WindowsError as e: debug("Did not find current sdk in registry") return None if not os.path.exists(val): debug("Current sdk dir %s not on fs" % val) return None return val
def fetchSDKVars(targetArch,versionString): common.debug("windowsSdk.py, fetchSDKVars: Searching for SDK %s"%versionString) archSwitch=scriptSwitchByTargetArch.get(targetArch) if not archSwitch: common.debug("windowsSdk.py, fetchSDKVars: Unsupported target arch: %s"%targetArch) try: versionKey=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,r'SOFTWARE\Microsoft\Microsoft SDKs\Windows\%s'%versionString) except Exception as e: common.debug("windowsSdk.py, fetchSDKVars: failed to open registry key for version %s: %s"%(versionString,e)) return try: installDir=_winreg.QueryValueEx(versionKey,"InstallationFolder")[0] except Exception as e: common.debug("windowsSdk.py, fetchSDKVars: no InstallationFolder value in registry key: %s: %s"%(v,e)) return if versionString=='v7.1A': #V7.1A (comes with vc2012) does not come with a batch file d=dict(PATH=os.path.join(installDir,'bin'),INCLUDE=os.path.join(installDir,'include'),LIB=os.path.join(installDir,'lib')) if targetArch in ('x86_64','amd64'): d['PATH']=os.path.join(d['PATH'],'x64') d['LIB']=os.path.join(d['LIB'],'x64') return d scriptPath=os.path.join(installDir,os.path.join('bin','setenv.cmd')) if not os.path.isfile(scriptPath): common.debug("windowsSdk.py, fetchSDKVars: Script %s does not exist"%scriptPath) return p=subprocess.Popen(['cmd','/V','/c',scriptPath,archSwitch,'&&','set'],stdout=subprocess.PIPE,stderr=subprocess.PIPE) stdout,stderr=p.communicate() try: return common.parse_output(stdout) except Exception as e: common.debug("windowsSdk.py, fetchSDKVars: Error parsing script output: %s"%e) return common.debug("windowsSdk.py, fetchSDKVars: No suitable SDK could be used")
if not SCons.Util.can_read_reg: debug('find_vc_product_dir(): can not read registry') return None key = self.hkey_root + '\\' + self.vc_product_dir_key try: comps = read_reg(key) except WindowsError, e: debug('find_vc_product_dir(): no registry key %s' % key) else: if self.batch_file_dir_reg_relpath: comps = os.path.join(comps, self.batch_file_dir_reg_relpath) comps = os.path.normpath(comps) if os.path.exists(comps): return comps else: debug('find_vc_product_dir(): %s not on file system' % comps) d = os.environ.get(self.common_tools_var) if not d: msg = 'find_vc_product_dir(): no %s variable' debug(msg % self.common_tools_var) return None if not os.path.isdir(d): debug('find_vc_product_dir(): %s not on file system' % d) return None if self.batch_file_dir_env_relpath: d = os.path.join(d, self.batch_file_dir_env_relpath) d = os.path.normpath(d) return d #
def setUp(self): debug("THIS TYPE :%s"%self) global registry registry = self.registry from SCons.Tool.MSCommon.vs import reset_installed_visual_studios reset_installed_visual_studios()
"""Try to find the platform sdk directory from the registry. Return None if failed or the directory does not exist""" if not SCons.Util.can_read_reg: debug('SCons cannot read registry') return None try: val = read_reg(_CURINSTALLED_SDK_HKEY_ROOT) debug("Found current sdk dir in registry: %s" % val) except WindowsError, e: debug("Did not find current sdk in registry") return None if not os.path.exists(val): debug("Current sdk dir %s not on fs" % val) return None return val def detect_sdk(): return (len(get_installed_sdks()) > 0) def set_sdk_by_version(env, mssdk): if not SupportedSDKMap.has_key(mssdk): msg = "SDK version %s is not supported" % repr(mssdk) raise SCons.Errors.UserError, msg get_installed_sdks() sdk = InstalledSDKMap.get(mssdk) if not sdk:
def fetchSDKVars(targetArch='x86',wantedVersion=None): archSwitch=scriptSwitchByTargetArch.get(targetArch) if not archSwitch: common.debug("windowsSdk.py, fetchSDKVars: Unsupported target arch: %s"%targetArch) try: versionsKey=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,r'SOFTWARE\Microsoft\Microsoft SDKs\Windows') except Exception as e: common.debug("windowsSdk.py, fetchSDKVars: Windows SDK tool: no SDKs installed: root registry key not found, %s"%e) return None versionsKeyLen=_winreg.QueryInfoKey(versionsKey)[0] if versionsKeyLen<1: common.debug("windowsSdk.py, fetchSDKVars: No SDK versions found: root registry key empty") return None if wantedVersion: versionStrings=[wantedVersion] else: versionStrings=[x for x in (_winreg.EnumKey(versionsKey,index) for index in xrange(versionsKeyLen)) if x.startswith('v')] for v in reversed(versionStrings): try: versionKey=_winreg.OpenKey(versionsKey,v) except Exception as e: common.debug("windowsSdk.py, fetchSDKVars: failed to open registry key for version %s: %s"%(v,e)) continue try: installDir=_winreg.QueryValueEx(versionKey,"InstallationFolder")[0] except Exception as e: common.debug("windowsSdk.py, fetchSDKVars: no InstallationFolder value in registry key: %s: %s"%(v,e)) continue scriptPath=os.path.join(installDir,os.path.join('bin','setenv.cmd')) if not os.path.isfile(scriptPath): common.debug("windowsSdk.py, fetchSDKVars: Script %s does not exist"%scriptPath) continue p=subprocess.Popen(['cmd','/V','/c',scriptPath,archSwitch,'&&','set'],stdout=subprocess.PIPE,stderr=subprocess.PIPE) stdout,stderr=p.communicate() try: return common.parse_output(stdout) except Exception as e: common.debug("windowsSdk.py, fetchSDKVars: Error parsing script output: %s"%e) continue common.debug("windowsSdk.py, fetchSDKVars: No suitable SDK could be used") return None
def fetchSDKVars(targetArch, versionString): common.debug("windowsSdk.py, fetchSDKVars: Searching for SDK %s" % versionString) archSwitch = scriptSwitchByTargetArch.get(targetArch) if not archSwitch: common.debug( "windowsSdk.py, fetchSDKVars: Unsupported target arch: %s" % targetArch) try: versionKey = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Microsoft SDKs\Windows\%s' % versionString) except Exception as e: common.debug( "windowsSdk.py, fetchSDKVars: failed to open registry key for version %s: %s" % (versionString, e)) return try: installDir = _winreg.QueryValueEx(versionKey, "InstallationFolder")[0] except Exception as e: common.debug( "windowsSdk.py, fetchSDKVars: no InstallationFolder value in registry key: %s: %s" % (v, e)) return if versionString == 'v7.1A': #V7.1A (comes with vc2012) does not come with a batch file d = dict(PATH=os.path.join(installDir, 'bin'), INCLUDE=os.path.join(installDir, 'include'), LIB=os.path.join(installDir, 'lib')) if targetArch in ('x86_64', 'amd64'): d['PATH'] = os.path.join(d['PATH'], 'x64') d['LIB'] = os.path.join(d['LIB'], 'x64') return d scriptPath = os.path.join(installDir, os.path.join('bin', 'setenv.cmd')) if not os.path.isfile(scriptPath): common.debug("windowsSdk.py, fetchSDKVars: Script %s does not exist" % scriptPath) return p = subprocess.Popen( ['cmd', '/V', '/c', scriptPath, archSwitch, '&&', 'set'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() try: return common.parse_output(stdout) except Exception as e: common.debug( "windowsSdk.py, fetchSDKVars: Error parsing script output: %s" % e) return common.debug("windowsSdk.py, fetchSDKVars: No suitable SDK could be used")
def setUp(self): debug("THIS TYPE :%s" % self) global registry registry = self.registry from SCons.Tool.MSCommon.vs import reset_installed_visual_studios reset_installed_visual_studios()
def test_config_generation(self): """Test _DSPGenerator.__init__(...)""" if not self.highest_version : return # Initialize 'static' variables version_num, suite = msvs_parse_version(self.highest_version) if version_num >= 10.0: function_test = _GenerateV10DSP elif version_num >= 7.0: function_test = _GenerateV7DSP else: function_test = _GenerateV6DSP str_function_test = str(function_test.__init__) dspfile = 'test.dsp' source = 'test.cpp' # Create the cmdargs test list list_variant = ['Debug|Win32','Release|Win32', 'Debug|x64', 'Release|x64'] list_cmdargs = ['debug=True target_arch=32', 'debug=False target_arch=32', 'debug=True target_arch=x64', 'debug=False target_arch=x64'] # Tuple list : (parameter, dictionary of expected result per variant) tests_cmdargs = [(None, dict.fromkeys(list_variant, '')), ('', dict.fromkeys(list_variant, '')), (list_cmdargs[0], dict.fromkeys(list_variant, list_cmdargs[0])), (list_cmdargs, dict(zip(list_variant, list_cmdargs)))] # Run the test for each test case for param_cmdargs, expected_cmdargs in tests_cmdargs: debug('Testing %s. with :\n variant = %s \n cmdargs = "%s"' % \ (str_function_test, list_variant, param_cmdargs)) param_configs = [] expected_configs = {} for platform in ['Win32', 'x64']: for variant in ['Debug', 'Release']: variant_platform = '%s|%s' % (variant, platform) runfile = '%s\\%s\\test.exe' % (platform, variant) buildtarget = '%s\\%s\\test.exe' % (platform, variant) outdir = '%s\\%s' % (platform, variant) # Create parameter list for this variant_platform param_configs.append([variant_platform, runfile, buildtarget, outdir]) # Create expected dictionary result for this variant_platform expected_configs[variant_platform] = \ {'variant': variant, 'platform': platform, 'runfile': runfile, 'buildtarget': buildtarget, 'outdir': outdir, 'cmdargs': expected_cmdargs[variant_platform]} # Create parameter environment with final parameter dictionary param_dict = dict(zip(('variant', 'runfile', 'buildtarget', 'outdir'), [list(l) for l in zip(*param_configs)])) param_dict['cmdargs'] = param_cmdargs # Hack to be able to run the test with a 'DummyEnv' class _DummyEnv(DummyEnv): def subst(self, string) : return string env = _DummyEnv(param_dict) env['MSVSSCONSCRIPT'] = '' env['MSVS_VERSION'] = self.highest_version # Call function to test genDSP = function_test(dspfile, source, env) # Check expected result self.assertListEqual(genDSP.configs.keys(), expected_configs.keys()) for key in genDSP.configs.keys(): self.assertDictEqual(genDSP.configs[key].__dict__, expected_configs[key])
def test_config_generation(self): """Test _DSPGenerator.__init__(...)""" if not self.highest_version: return # Initialize 'static' variables version_num, suite = msvs_parse_version(self.highest_version) if version_num >= 10.0: function_test = _GenerateV10DSP elif version_num >= 7.0: function_test = _GenerateV7DSP else: function_test = _GenerateV6DSP str_function_test = str(function_test.__init__) dspfile = 'test.dsp' source = 'test.cpp' # Create the cmdargs test list list_variant = [ 'Debug|Win32', 'Release|Win32', 'Debug|x64', 'Release|x64' ] list_cmdargs = [ 'debug=True target_arch=32', 'debug=False target_arch=32', 'debug=True target_arch=x64', 'debug=False target_arch=x64' ] # Tuple list : (parameter, dictionary of expected result per variant) tests_cmdargs = [ (None, dict.fromkeys(list_variant, '')), ('', dict.fromkeys(list_variant, '')), (list_cmdargs[0], dict.fromkeys(list_variant, list_cmdargs[0])), (list_cmdargs, dict(list(zip(list_variant, list_cmdargs)))) ] # Run the test for each test case for param_cmdargs, expected_cmdargs in tests_cmdargs: debug('Testing %s. with :\n variant = %s \n cmdargs = "%s"' % \ (str_function_test, list_variant, param_cmdargs)) param_configs = [] expected_configs = {} for platform in ['Win32', 'x64']: for variant in ['Debug', 'Release']: variant_platform = '%s|%s' % (variant, platform) runfile = '%s\\%s\\test.exe' % (platform, variant) buildtarget = '%s\\%s\\test.exe' % (platform, variant) outdir = '%s\\%s' % (platform, variant) # Create parameter list for this variant_platform param_configs.append( [variant_platform, runfile, buildtarget, outdir]) # Create expected dictionary result for this variant_platform expected_configs[variant_platform] = \ {'variant': variant, 'platform': platform, 'runfile': runfile, 'buildtarget': buildtarget, 'outdir': outdir, 'cmdargs': expected_cmdargs[variant_platform]} # Create parameter environment with final parameter dictionary param_dict = dict( list( zip(('variant', 'runfile', 'buildtarget', 'outdir'), [list(l) for l in zip(*param_configs)]))) param_dict['cmdargs'] = param_cmdargs # Hack to be able to run the test with a 'DummyEnv' class _DummyEnv(DummyEnv): def subst(self, string): return string env = _DummyEnv(param_dict) env['MSVSSCONSCRIPT'] = '' env['MSVS_VERSION'] = self.highest_version # Call function to test genDSP = function_test(dspfile, source, env) # Check expected result self.assertListEqual(list(genDSP.configs.keys()), list(expected_configs.keys())) for key in list(genDSP.configs.keys()): self.assertDictEqual(genDSP.configs[key].__dict__, expected_configs[key])
def test_config_generation(self): """Test _DSPGenerator.__init__(...)""" if not self.highest_version : return # Initialize 'static' variables version_num, suite = msvs_parse_version(self.highest_version) if version_num >= 10.0: function_test = _GenerateV10DSP suffix = '.vcxproj' elif version_num >= 7.0: function_test = _GenerateV7DSP suffix = '.dsp' else: function_test = _GenerateV6DSP suffix = '.dsp' # Avoid any race conditions between the test cases when we test # actually writing the files. dspfile = 'test%s%s' % (hash(self), suffix) str_function_test = str(function_test.__init__) source = 'test.cpp' # Create the cmdargs test list list_variant = ['Debug|Win32','Release|Win32', 'Debug|x64', 'Release|x64'] list_cmdargs = ['debug=True target_arch=32', 'debug=False target_arch=32', 'debug=True target_arch=x64', 'debug=False target_arch=x64'] list_cppdefines = [['_A', '_B', 'C'], ['_B', '_C_'], ['D'], []] list_cpppaths = [[r'C:\test1'], [r'C:\test1;C:\test2'], [self.fs.Dir('subdir')], []] def TestParamsFromList(test_variant, test_list): """ Generates test data based on the parameters passed in. Returns tuple list: 1. Parameter. 2. Dictionary of expected result per variant. """ def normalizeParam(param): """ Converts the raw data based into the AddConfig function of msvs.py to the expected result. Expects the following behavior: 1. A value of None will be converted to an empty list. 2. A File or Directory object will be converted to an absolute path (because those objects can't be pickled). 3. Otherwise, the parameter will be used. """ if param is None: return [] elif isinstance(param, list): return [normalizeParam(p) for p in param] elif hasattr(param, 'abspath'): return param.abspath else: return param return [ (None, dict.fromkeys(test_variant, '')), ('', dict.fromkeys(test_variant, '')), (test_list[0], dict.fromkeys(test_variant, normalizeParam(test_list[0]))), (test_list, dict(list(zip(test_variant, [normalizeParam(x) for x in test_list])))) ] tests_cmdargs = TestParamsFromList(list_variant, list_cmdargs) tests_cppdefines = TestParamsFromList(list_variant, list_cppdefines) tests_cpppaths = TestParamsFromList(list_variant, list_cpppaths) # Run the test for each test case for param_cmdargs, expected_cmdargs in tests_cmdargs: for param_cppdefines, expected_cppdefines in tests_cppdefines: for param_cpppaths, expected_cpppaths in tests_cpppaths: debug('Testing %s. with :\n variant = %s \n cmdargs = "%s" \n cppdefines = "%s" \n cpppaths = "%s"' % \ (str_function_test, list_variant, param_cmdargs, param_cppdefines, param_cpppaths)) param_configs = [] expected_configs = {} for platform in ['Win32', 'x64']: for variant in ['Debug', 'Release']: variant_platform = '%s|%s' % (variant, platform) runfile = '%s\\%s\\test.exe' % (platform, variant) buildtarget = '%s\\%s\\test.exe' % (platform, variant) outdir = '%s\\%s' % (platform, variant) # Create parameter list for this variant_platform param_configs.append([variant_platform, runfile, buildtarget, outdir]) # Create expected dictionary result for this variant_platform expected_configs[variant_platform] = { 'variant': variant, 'platform': platform, 'runfile': runfile, 'buildtarget': buildtarget, 'outdir': outdir, 'cmdargs': expected_cmdargs[variant_platform], 'cppdefines': expected_cppdefines[variant_platform], 'cpppaths': expected_cpppaths[variant_platform], } # Create parameter environment with final parameter dictionary param_dict = dict(list(zip(('variant', 'runfile', 'buildtarget', 'outdir'), [list(l) for l in zip(*param_configs)]))) param_dict['cmdargs'] = param_cmdargs param_dict['cppdefines'] = param_cppdefines param_dict['cpppaths'] = param_cpppaths # Hack to be able to run the test with a 'DummyEnv' class _DummyEnv(DummyEnv): def subst(self, string, *args, **kwargs): return string env = _DummyEnv(param_dict) env['MSVSSCONSCRIPT'] = '' env['MSVS_VERSION'] = self.highest_version env['MSVSBUILDTARGET'] = 'target' # Call function to test genDSP = function_test(dspfile, source, env) # Check expected result self.assertListEqual(list(genDSP.configs.keys()), list(expected_configs.keys())) for key in list(genDSP.configs.keys()): self.assertDictEqual(genDSP.configs[key].__dict__, expected_configs[key]) genDSP.Build() # Delete the resulting file so we don't leave anything behind. for file in [dspfile, dspfile + '.filters']: path = os.path.realpath(file) try: os.remove(path) except OSError: pass
def fetchSDKVars(targetArch='x86', wantedVersion=None): archSwitch = scriptSwitchByTargetArch.get(targetArch) if not archSwitch: common.debug( "windowsSdk.py, fetchSDKVars: Unsupported target arch: %s" % targetArch) try: versionsKey = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Microsoft SDKs\Windows') except Exception as e: common.debug( "windowsSdk.py, fetchSDKVars: Windows SDK tool: no SDKs installed: root registry key not found, %s" % e) return None versionsKeyLen = _winreg.QueryInfoKey(versionsKey)[0] if versionsKeyLen < 1: common.debug( "windowsSdk.py, fetchSDKVars: No SDK versions found: root registry key empty" ) return None if wantedVersion: versionStrings = [wantedVersion] else: versionStrings = [ x for x in (_winreg.EnumKey(versionsKey, index) for index in xrange(versionsKeyLen)) if x.startswith('v') ] for v in reversed(versionStrings): try: versionKey = _winreg.OpenKey(versionsKey, v) except Exception as e: common.debug( "windowsSdk.py, fetchSDKVars: failed to open registry key for version %s: %s" % (v, e)) continue try: installDir = _winreg.QueryValueEx(versionKey, "InstallationFolder")[0] except Exception as e: common.debug( "windowsSdk.py, fetchSDKVars: no InstallationFolder value in registry key: %s: %s" % (v, e)) continue scriptPath = os.path.join(installDir, os.path.join('bin', 'setenv.cmd')) if not os.path.isfile(scriptPath): common.debug( "windowsSdk.py, fetchSDKVars: Script %s does not exist" % scriptPath) continue p = subprocess.Popen( ['cmd', '/V', '/c', scriptPath, archSwitch, '&&', 'set'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() try: return common.parse_output(stdout) except Exception as e: common.debug( "windowsSdk.py, fetchSDKVars: Error parsing script output: %s" % e) continue common.debug("windowsSdk.py, fetchSDKVars: No suitable SDK could be used") return None