-
Notifications
You must be signed in to change notification settings - Fork 4
/
msvc.py
1898 lines (1544 loc) · 55.3 KB
/
msvc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import ctypes
from ctypes.wintypes import (
BOOL,
DWORD,
LPCVOID,
LPCWSTR,
LPVOID,
UINT,
INT
)
try:
_winreg = __import__('winreg')
except ImportError:
_winreg = __import__('_winreg')
POINTER = ctypes.POINTER
CHAR = INT
PUINT = POINTER(UINT)
LPDWORD = POINTER(DWORD)
_version = ctypes.windll.version
_GetFileVersionInfoSize = _version.GetFileVersionInfoSizeW
_GetFileVersionInfoSize.restype = DWORD
_GetFileVersionInfoSize.argtypes = [LPCWSTR, LPDWORD]
_GetFileVersionInfo = _version.GetFileVersionInfoW
_GetFileVersionInfo.restype = BOOL
_GetFileVersionInfo.argtypes = [LPCWSTR, DWORD, DWORD, LPVOID]
_VerQueryValue = _version.VerQueryValueW
_VerQueryValue.restype = BOOL
_VerQueryValue.argtypes = [LPCVOID, LPCWSTR, POINTER(LPVOID), PUINT]
# noinspection PyPep8Naming
class VS_FIXEDFILEINFO(ctypes.Structure):
_fields_ = [
("dwSignature", DWORD), # will be 0xFEEF04BD
("dwStrucVersion", DWORD),
("dwFileVersionMS", DWORD),
("dwFileVersionLS", DWORD),
("dwProductVersionMS", DWORD),
("dwProductVersionLS", DWORD),
("dwFileFlagsMask", DWORD),
("dwFileFlags", DWORD),
("dwFileOS", DWORD),
("dwFileType", DWORD),
("dwFileSubtype", DWORD),
("dwFileDateMS", DWORD),
("dwFileDateLS", DWORD)
]
def _get_file_version(filename):
dw_len = _GetFileVersionInfoSize(filename, None)
if not dw_len:
raise ctypes.WinError()
lp_data = (CHAR * dw_len)()
if not _GetFileVersionInfo(filename, 0, ctypes.sizeof(lp_data), lp_data):
raise ctypes.WinError()
u_len = UINT()
lpffi = POINTER(VS_FIXEDFILEINFO)()
lplp_buffer = ctypes.cast(ctypes.pointer(lpffi), POINTER(LPVOID))
if not _VerQueryValue(lp_data, "\\", lplp_buffer, ctypes.byref(u_len)):
raise ctypes.WinError()
ffi = lpffi.contents
return (
ffi.dwFileVersionMS >> 16,
ffi.dwFileVersionMS & 0xFFFF,
ffi.dwFileVersionLS >> 16,
ffi.dwFileVersionLS & 0xFFFF,
)
def _get_reg_value(path, key):
d = _read_reg_values(path)
if key in d:
return d[key]
return ''
def _read_reg_keys(key):
if isinstance(key, tuple):
root = key[0]
key = key[1]
else:
root = _winreg.HKEY_LOCAL_MACHINE
key = 'SOFTWARE\\Wow6432Node\\Microsoft\\' + key
try:
handle = _winreg.OpenKeyEx(root, key)
except _winreg.error:
return []
res = []
for i in range(_winreg.QueryInfoKey(handle)[0]):
res += [_winreg.EnumKey(handle, i)]
return res
def _read_reg_values(key):
if isinstance(key, tuple):
root = key[0]
key = key[1]
else:
root = _winreg.HKEY_LOCAL_MACHINE
key = 'SOFTWARE\\Wow6432Node\\Microsoft\\' + key
try:
handle = _winreg.OpenKeyEx(root, key)
except _winreg.error:
return {}
res = {}
for i in range(_winreg.QueryInfoKey(handle)[1]):
name, value, _ = _winreg.EnumValue(handle, i)
res[_convert_mbcs(name)] = _convert_mbcs(value)
return res
def _convert_mbcs(s):
dec = getattr(s, "decode", None)
if dec is not None:
try:
s = dec("mbcs")
except UnicodeError:
pass
return s
# I have separated the environment into several classes
# Environment - the main environment class.
# the environment class is what is going to get used. this handles all of the
# non specific bits of the environment. all of the rest of the classes are
# brought together in the environment to form a complete build environment.
# NETInfo - Any .NET related environment settings
# WindowsSDKInfo - Any Windows SDK environment settings
# VisualStudioInfo - Any VisualStudios environment settings (if applicable)
# VisualCInfo - Any VisualC environment settings
# PythonInfo - This class really isnt for environment settings as such.
# It is more of a convenience class. it will get things like a list of the
# includes specific to the python build. the architecture of the version of
# python that is running stuff along those lines.
class PythonInfo(object):
@property
def architecture(self):
return 'x64' if sys.maxsize > 2 ** 32 else 'x86'
@property
def version(self):
return '.'.join(str(ver) for ver in sys.version_info)
@property
def dependency(self):
return 'Python%d%d.lib' % sys.version_info[:2]
@property
def includes(self):
python_path = os.path.dirname(sys.executable)
python_include = os.path.join(python_path, 'include')
python_includes = [python_include]
for root, dirs, files in os.walk(python_include):
for d in dirs:
python_includes += [os.path.join(root, d)]
return python_includes
@property
def libraries(self):
python_path = os.path.dirname(sys.executable)
python_lib = os.path.join(python_path, 'libs')
python_libs = [python_lib]
for root, dirs, files in os.walk(python_lib):
for d in dirs:
python_libs += [os.path.join(root, d)]
return python_libs
python_info = PythonInfo()
class VisualCInfo(object):
def __init__(self, platform, strict_version, minimum_version):
self.platform = platform
self.strict_version = strict_version
self.minimum_version = minimum_version
self.__installed_versions = None
@property
def f_sharp_path(self):
reg_path = (
_winreg.HKEY_LOCAL_MACHINE,
'SOFTWARE\Wow6432Node\Microsoft\\VisualStudio\\'
'{0:.1f}\\Setup\\F#'.format(self.version)
)
f_sharp_path = _get_reg_value(reg_path, 'ProductDir')
if f_sharp_path and os.path.exists(f_sharp_path):
return f_sharp_path
path = r'C:\Program Files (x86)\Microsoft SDKs\F#'
if os.path.exists(path):
versions = os.listdir(path)
max_ver = 0.0
found_version = ''
for version in versions:
try:
ver = float(version)
except ValueError:
continue
if ver > max_ver:
max_ver = ver
found_version = version
f_sharp_path = os.path.join(
path,
found_version,
'Framework',
'v' + found_version
)
if os.path.exists(f_sharp_path):
return f_sharp_path
@property
def ide_install_directory(self):
directory = self.install_directory
ide_directory = os.path.abspath(os.path.join(directory, '..'))
ide_directory = os.path.join(ide_directory, 'Common7', 'IDE', 'VC')
if os.path.exists(ide_directory):
return ide_directory
@property
def install_directory(self):
"""
Visual C path
:return: Visual C path
"""
return self._installed_c_paths[self.version]['base']
@property
def _installed_c_paths(self):
if self.__installed_versions is None:
self.__installed_versions = {}
reg_path = (
_winreg.HKEY_CLASSES_ROOT,
'Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache'
)
paths = []
for key in _read_reg_values(reg_path):
if 'cl.exe' in key:
value = _get_reg_value(reg_path, key)
if 'C++ Compiler Driver' in value:
paths += [key]
for path in paths:
if not os.path.exists(path):
continue
if '\\VC\\bin' in path:
version = path.split('\\VC\\bin')[0]
else:
version = path.split('\\bin\\Host')[0]
version = os.path.split(version)[1]
version = version.replace(
'Microsoft Visual Studio',
''
).strip()
base_version = float(int(version.split('.')[0]))
base_path = path.split('\\VC\\')[0] + '\\VC'
if os.path.exists(os.path.join(base_path, 'include')):
vc_root = base_path
else:
vc_root = path.split('\\bin\\')[0]
self.__installed_versions[version] = dict(
base=base_path,
root=vc_root
)
self.__installed_versions[base_version] = dict(
base=base_path,
root=vc_root
)
reg_path = (
_winreg.HKEY_LOCAL_MACHINE,
'SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7'
)
for key in _read_reg_values(reg_path):
try:
version = float(key)
except ValueError:
continue
path = _get_reg_value(reg_path, key)
if (
(
os.path.exists(path) and
version not in self.__installed_versions
) or version == 15.0
):
if version == 15.0:
version = 14.0
if not os.path.split(path)[1] == 'VC':
path = os.path.join(path, 'VC')
self.__installed_versions[version] = dict(
base=path,
root=path
)
self.__installed_versions[key] = dict(
base=path,
root=path
)
return self.__installed_versions
@property
def version(self):
"""
Visual C version
Sometimes when building extension in python the version of the compiler
that was used to compile Python has to also be used to compile an
extension. I have this system set so it will automatically pick the
most recent compiler installation. this can be overridden in 2 ways.
The first way being that the compiler version that built Python has to
be used. The second way is you can set a minimum compiler version to
use.
:return: found Visual C version
"""
py_version = sys.version_info[:2]
if py_version in ((2, 6), (2, 7), (3, 0), (3, 1), (3, 2)):
min_visual_c_version = 9.0
elif py_version in ((3, 3), (3, 4)):
min_visual_c_version = 10.0
elif py_version in ((3, 5), (3, 6), (3, 7)):
min_visual_c_version = 14.0
else:
raise RuntimeError(
'This library does not support '
'python version %d.%d' % py_version
)
max_version = 0.0
if self.strict_version is not None:
if self.strict_version < min_visual_c_version:
raise RuntimeError(
'The set minimum compiler version is lower then the '
'required compiler version for Python'
)
if self.strict_version not in self._installed_c_paths:
raise RuntimeError(
'No Compatible Visual C version found.'
)
return self.strict_version
elif self.minimum_version is not None:
for version in self._installed_c_paths:
if not isinstance(version, float):
continue
if version >= self.minimum_version:
max_version = max(max_version, version)
else:
for version in self._installed_c_paths:
if not isinstance(version, float):
continue
if version >= min_visual_c_version:
max_version = max(max_version, version)
if max_version == 0:
raise RuntimeError(
'No Compatible Visual C\\C++ version found.'
)
return max_version
@property
def tools_version(self):
version = os.path.split(self.tools_install_directory)[1]
if not version.split('.')[-1].isdigit():
version = str(self.version)
return version
@property
def toolset_version(self):
"""
The platform toolset gets written to the solution file. this instructs
the compiler to use the matching MSVCPxxx.dll file.
:return: one of the following
Visual C Visual Studio Returned Value
VC 15.0 - VS 2017: v141
VC 14.0 - VS 2015: v140
VC 12.0 - VS 2013: v120
VC 11.0 - VS 2012: v110
VC 10.0 - VS 2010: v100
VC 9.0 - VS 2008: v90
"""
toolsets = {
15.0: 'v141',
14.0: 'v140',
12.0: 'v120',
11.0: 'v110',
10.0: 'v100',
9.0: 'v90'
}
return toolsets[self.version]
@property
def msvc_dll_version(self):
msvc_dll_path = self.msvc_dll_path
if msvc_dll_path:
for f in os.listdir(msvc_dll_path):
if f.endswith('dll'):
version = _get_file_version(os.path.join(msvc_dll_path, f))
return '.'.join(str(ver) for ver in version)
@property
def msvc_dll_path(self):
x64 = self.platform == 'x64'
folder_names = (
'Microsoft.VC{0}.CRT'.format(self.toolset_version[1:]),
)
if self.toolset_version == 'v140':
folder_names += ('Microsoft.VC141.CRT',)
redist_path = self.tools_redist_directory
for root, dirs, files in os.walk(redist_path):
def pass_directory():
for item in ('onecore', 'arm', 'spectre'):
if item in root.lower():
return True
return False
if pass_directory():
continue
for folder_name in folder_names:
if folder_name in dirs:
if x64 and ('amd64' in root or 'x64' in root):
return os.path.join(root, folder_name)
elif (
not x64 and
'amd64' not in root
and 'x64' not in root
):
return os.path.join(root, folder_name)
@property
def tools_redist_directory(self):
tools_install_path = self.tools_install_directory
if 'MSVC' in tools_install_path:
redist_path = tools_install_path.replace('Tools', 'Redist')
if 'BuildTools' in tools_install_path:
redist_path = redist_path.replace('BuildRedist', 'BuildTools')
else:
redist_path = os.path.join(tools_install_path, 'Redist')
if not os.path.exists(redist_path):
redist_path = os.path.split(redist_path)[0]
max_ver = (0, 0, 0)
for f in os.listdir(redist_path):
if os.path.isdir(os.path.join(redist_path, f)):
try:
ver = tuple(int(ver) for ver in f.split('.'))
except ValueError:
continue
if ver > max_ver:
max_ver = ver
if max_ver != (0, 0, 0):
return os.path.join(
redist_path,
'.'.join(str(ver) for ver in max_ver)
)
else:
return ''
else:
return redist_path
@property
def tools_install_directory(self):
"""
Visual C compiler tools path.
:return: Path to the compiler tools
"""
vc_version = self.version
if vc_version >= 14.0:
vc_tools_path = self._installed_c_paths[vc_version]['root']
else:
vc_tools_path = self._installed_c_paths[vc_version]['base']
lib_path = os.path.join(vc_tools_path, 'lib')
if not os.path.exists(lib_path):
tools_path = os.path.join(vc_tools_path, 'Tools', 'MSVC')
if os.path.exists(tools_path):
versions = os.listdir(tools_path)
max_version = (0, 0, 0)
found_version = ''
for version in versions:
try:
ver = tuple(
int(vr) for vr in version.split('.')
)
except ValueError:
continue
if ver > max_version:
max_version = ver
found_version = version
vc_tools_path = os.path.join(
tools_path,
found_version
)
return vc_tools_path
@property
def msbuild_version(self):
"""
MSBuild versions are specific to the Visual C version
:return: MSBuild version, 3.5, 4.0, 12, 14, 15
"""
vc_version = self.version
if vc_version == 9.0:
return 3.5
if vc_version in (10.0, 11.0):
return 4.0
else:
return vc_version
@property
def msbuild_path(self):
program_files = os.environ.get(
'ProgramFiles(x86)',
'C:\\Program Files (x86)'
)
ms_build_path = os.path.join(
program_files,
'MSBuild',
'{0:.1f}'.format(self.version),
'bin'
)
if self.platform == 'x64':
if os.path.exists(os.path.join(ms_build_path, 'x64')):
ms_build_path = os.path.join(ms_build_path, 'x64')
else:
ms_build_path = os.path.join(ms_build_path, 'amd64')
elif os.path.exists(os.path.join(ms_build_path, 'x86')):
ms_build_path = os.path.join(ms_build_path, 'x86')
if os.path.exists(ms_build_path):
return ms_build_path
@property
def html_help_path(self):
reg_path = (
_winreg.HKEY_LOCAL_MACHINE,
'SOFTWARE\\Wow6432Node\\Microsoft\Windows\\'
'CurrentVersion\\App Paths\\hhw.exe'
)
html_help_path = _get_reg_value(reg_path, 'Path')
if html_help_path and os.path.exists(html_help_path):
return html_help_path
if os.path.exists(r'C:\Program Files (x86)\HTML Help Workshop'):
return r'C:\Program Files (x86)\HTML Help Workshop'
@property
def path(self):
tools_path = self.tools_install_directory
base_path = os.path.join(tools_path, 'bin')
path = []
f_sharp_path = self.f_sharp_path
msbuild_path = self.msbuild_path
if self.platform == 'x64':
perf_tools_path = os.path.join(
self.tools_install_directory,
'Team Tools',
'Performance Toolsx64'
)
else:
perf_tools_path = os.path.join(
self.tools_install_directory,
'Team Tools',
'Performance Tools'
)
if msbuild_path is not None:
path += [msbuild_path]
if os.path.exists(perf_tools_path):
path += [perf_tools_path]
if f_sharp_path is not None:
path += [f_sharp_path]
html_help_path = self.html_help_path
if html_help_path is not None:
path += [html_help_path]
bin_path = os.path.join(
base_path,
'Host' + self.platform,
self.platform
)
if not os.path.exists(bin_path):
if self.platform == 'x64':
bin_path = os.path.join(base_path, 'x64')
if not os.path.exists(bin_path):
bin_path = os.path.join(base_path, 'amd64')
else:
bin_path = os.path.join(base_path, 'x86')
if not os.path.exists(bin_path):
bin_path = base_path
if os.path.exists(bin_path):
path += [bin_path]
return path
@property
def atlmfc_lib_path(self):
atlmfc_path = self.atlmfc_path
if not atlmfc_path:
return
atlmfc = os.path.join(atlmfc_path, 'lib')
if self.platform == 'x64':
atlmfc_path = os.path.join(atlmfc, 'x64')
if not os.path.exists(atlmfc_path):
atlmfc_path = os.path.join(atlmfc, 'amd64')
else:
atlmfc_path = os.path.join(atlmfc, 'x86')
if not os.path.exists(atlmfc_path):
atlmfc_path = atlmfc
if os.path.exists(atlmfc_path):
return atlmfc_path
@property
def lib(self):
tools_path = self.tools_install_directory
path = os.path.join(tools_path, 'lib')
if self.platform == 'x64':
lib_path = os.path.join(path, 'x64')
if not os.path.exists(lib_path):
lib_path = os.path.join(path, 'amd64')
else:
lib_path = os.path.join(path, 'x86')
if not os.path.exists(lib_path):
lib_path = path
lib = []
if os.path.exists(lib_path):
lib += [lib_path]
atlmfc_path = self.atlmfc_lib_path
if atlmfc_path is not None:
lib += [atlmfc_path]
return lib
@property
def lib_path(self):
tools_path = self.tools_install_directory
path = os.path.join(tools_path, 'lib')
if self.platform == 'x64':
lib = os.path.join(path, 'x64')
if not os.path.exists(lib):
lib = os.path.join(path, 'amd64')
else:
lib = os.path.join(path, 'x86')
if not os.path.exists(lib):
lib = path
references_path = os.path.join(lib, 'store', 'references')
lib_path = []
if os.path.exists(lib):
lib_path += [lib]
atlmfc_path = self.atlmfc_lib_path
if atlmfc_path is not None:
lib_path += [atlmfc_path]
if os.path.exists(references_path):
lib_path += [references_path]
return lib_path
# LIB:
# C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib
# C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\lib
@property
def atlmfc_path(self):
tools_path = self.tools_install_directory
atlmfc_path = os.path.join(tools_path, 'ATLMFC')
if os.path.exists(atlmfc_path):
return atlmfc_path
@property
def atlmfc_include_path(self):
atlmfc_path = self.atlmfc_path
if atlmfc_path:
atlmfc_path = os.path.join(atlmfc_path, 'include')
if os.path.exists(atlmfc_path):
return atlmfc_path
@property
def include(self):
tools_path = self.tools_install_directory
include_path = os.path.join(tools_path, 'include')
atlmfc_path = self.atlmfc_include_path
include = []
if os.path.exists(include_path):
include += [include_path]
if atlmfc_path is not None:
include += [atlmfc_path]
return include
def __iter__(self):
ide_install_directory = self.ide_install_directory
tools_install_directory = self.tools_install_directory
install_directory = self.install_directory
if ide_install_directory:
ide_install_directory += '\\'
if tools_install_directory:
tools_install_directory += '\\'
if install_directory:
install_directory += '\\'
env = dict(
VCIDEInstallDir=ide_install_directory,
VCToolsVersion=self.tools_version,
VCToolsInstallDir=tools_install_directory,
VCINSTALLDIR=install_directory,
VCToolsRedistDir=self.tools_redist_directory,
Path=self.path,
LIB=self.lib,
Include=self.include,
LIBPATH=self.lib_path,
FSHARPINSTALLDIR=self.f_sharp_path
)
for key, value in env.items():
if value is not None and value:
if isinstance(value, list):
value = os.pathsep.join(value)
yield key, str(value)
class VisualStudioInfo(object):
def __init__(self, c_info):
self.c_info = c_info
@property
def install_directory(self):
return os.path.abspath(
os.path.join(self.c_info.install_directory, '..')
)
@property
def dev_env_directory(self):
return os.path.join(self.install_directory, 'Common7', 'IDE')
@property
def common_tools(self):
return os.path.join(self.install_directory, 'Common7', 'Tools')
@property
def path(self):
path = [self.dev_env_directory, self.common_tools]
collection_tools_dir = _get_reg_value(
'VisualStudio\\VSPerf',
'CollectionToolsDir'
)
if collection_tools_dir and os.path.exists(collection_tools_dir):
path += [collection_tools_dir]
vs_ide_path = self.dev_env_directory
test_window_path = os.path.join(
vs_ide_path,
'CommonExtensions',
'Microsoft',
'TestWindow'
)
vs_tdb_path = os.path.join(
vs_ide_path,
'VSTSDB',
'Deploy'
)
if os.path.exists(vs_tdb_path):
path += [vs_tdb_path]
if os.path.exists(test_window_path):
path += [test_window_path]
return path
@property
def version(self):
return self.c_info.version
def __iter__(self):
install_directory = self.install_directory
dev_env_directory = self.dev_env_directory
if install_directory:
install_directory += '\\'
if dev_env_directory:
dev_env_directory += '\\'
env = dict(
Path=self.path,
VSINSTALLDIR=install_directory,
DevEnvDir=dev_env_directory,
VisualStudioVersion=self.version
)
env['VS{0:.0f}0COMNTOOLS'.format(self.c_info.version)] = (
self.common_tools
)
for key, value in env.items():
if value is not None and value:
if isinstance(value, list):
value = os.pathsep.join(value)
yield key, str(value)
class WindowsSDKInfo(object):
def __init__(self, platform, vc_version):
self.platform = platform
self.vc_version = vc_version
@property
def extension_sdk_directory(self):
version = self.version
if version.startswith('10'):
version = '10.0'
sdk_path = _get_reg_value(
'Microsoft SDKs\\Windows\\v' + version,
'InstallationFolder'
)
if sdk_path:
sdk_path = sdk_path.replace(
'Windows Kits',
'Microsoft SDKs\\Windows Kits'
)
extension_path = os.path.join(sdk_path[:-1], 'ExtensionSDKs')
if os.path.exists(extension_path):
return extension_path
@property
def lib_version(self):
return self.sdk_version
@property
def ver_bin_path(self):
bin_path = self.bin_path[:-1]
ver_bin_path = os.path.join(bin_path, self.version)
if os.path.exists(ver_bin_path):
return ver_bin_path
else:
return bin_path
@property
def mssdk(self):
return self.directory
@property
def ucrt_version(self):
return self.sdk_version[:-1]
@property
def ucrt_sdk_directory(self):
directory = self.directory
if directory:
return directory + '\\'
@property
def bin_path(self):
directory = self.directory
if directory:
bin_path = os.path.join(
self.directory,
'bin'
)
return bin_path + '\\'
@property
def lib(self):
directory = self.directory
if not directory:
return []
version = self.version
lib = []
base_lib = os.path.join(
directory,
'lib',
version,
)
if not os.path.exists(base_lib):
base_lib = os.path.join(
directory,
'lib'
)
if os.path.exists(base_lib):
if self.platform == 'x64':
if os.path.exists(os.path.join(base_lib, 'x64')):