1#!/usr/bin/env python
2
3# Copyright (c) 2012 Google Inc. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""Unit tests for the MSVSSettings.py file."""
8
9import StringIO
10import unittest
11import gyp.MSVSSettings as MSVSSettings
12
13
14class TestSequenceFunctions(unittest.TestCase):
15
16  def setUp(self):
17    self.stderr = StringIO.StringIO()
18
19  def _ExpectedWarnings(self, expected):
20    """Compares recorded lines to expected warnings."""
21    self.stderr.seek(0)
22    actual = self.stderr.read().split('\n')
23    actual = [line for line in actual if line]
24    self.assertEqual(sorted(expected), sorted(actual))
25
26  def testValidateMSVSSettings_tool_names(self):
27    """Tests that only MSVS tool names are allowed."""
28    MSVSSettings.ValidateMSVSSettings(
29        {'VCCLCompilerTool': {},
30         'VCLinkerTool': {},
31         'VCMIDLTool': {},
32         'foo': {},
33         'VCResourceCompilerTool': {},
34         'VCLibrarianTool': {},
35         'VCManifestTool': {},
36         'ClCompile': {}},
37        self.stderr)
38    self._ExpectedWarnings([
39        'Warning: unrecognized tool foo',
40        'Warning: unrecognized tool ClCompile'])
41
42  def testValidateMSVSSettings_settings(self):
43    """Tests that for invalid MSVS settings."""
44    MSVSSettings.ValidateMSVSSettings(
45        {'VCCLCompilerTool': {
46            'AdditionalIncludeDirectories': 'folder1;folder2',
47            'AdditionalOptions': ['string1', 'string2'],
48            'AdditionalUsingDirectories': 'folder1;folder2',
49            'AssemblerListingLocation': 'a_file_name',
50            'AssemblerOutput': '0',
51            'BasicRuntimeChecks': '5',
52            'BrowseInformation': 'fdkslj',
53            'BrowseInformationFile': 'a_file_name',
54            'BufferSecurityCheck': 'true',
55            'CallingConvention': '-1',
56            'CompileAs': '1',
57            'DebugInformationFormat': '2',
58            'DefaultCharIsUnsigned': 'true',
59            'Detect64BitPortabilityProblems': 'true',
60            'DisableLanguageExtensions': 'true',
61            'DisableSpecificWarnings': 'string1;string2',
62            'EnableEnhancedInstructionSet': '1',
63            'EnableFiberSafeOptimizations': 'true',
64            'EnableFunctionLevelLinking': 'true',
65            'EnableIntrinsicFunctions': 'true',
66            'EnablePREfast': 'true',
67            'Enableprefast': 'bogus',
68            'ErrorReporting': '1',
69            'ExceptionHandling': '1',
70            'ExpandAttributedSource': 'true',
71            'FavorSizeOrSpeed': '1',
72            'FloatingPointExceptions': 'true',
73            'FloatingPointModel': '1',
74            'ForceConformanceInForLoopScope': 'true',
75            'ForcedIncludeFiles': 'file1;file2',
76            'ForcedUsingFiles': 'file1;file2',
77            'GeneratePreprocessedFile': '1',
78            'GenerateXMLDocumentationFiles': 'true',
79            'IgnoreStandardIncludePath': 'true',
80            'InlineFunctionExpansion': '1',
81            'KeepComments': 'true',
82            'MinimalRebuild': 'true',
83            'ObjectFile': 'a_file_name',
84            'OmitDefaultLibName': 'true',
85            'OmitFramePointers': 'true',
86            'OpenMP': 'true',
87            'Optimization': '1',
88            'PrecompiledHeaderFile': 'a_file_name',
89            'PrecompiledHeaderThrough': 'a_file_name',
90            'PreprocessorDefinitions': 'string1;string2',
91            'ProgramDataBaseFileName': 'a_file_name',
92            'RuntimeLibrary': '1',
93            'RuntimeTypeInfo': 'true',
94            'ShowIncludes': 'true',
95            'SmallerTypeCheck': 'true',
96            'StringPooling': 'true',
97            'StructMemberAlignment': '1',
98            'SuppressStartupBanner': 'true',
99            'TreatWChar_tAsBuiltInType': 'true',
100            'UndefineAllPreprocessorDefinitions': 'true',
101            'UndefinePreprocessorDefinitions': 'string1;string2',
102            'UseFullPaths': 'true',
103            'UsePrecompiledHeader': '1',
104            'UseUnicodeResponseFiles': 'true',
105            'WarnAsError': 'true',
106            'WarningLevel': '1',
107            'WholeProgramOptimization': 'true',
108            'XMLDocumentationFileName': 'a_file_name',
109            'ZZXYZ': 'bogus'},
110         'VCLinkerTool': {
111             'AdditionalDependencies': 'file1;file2',
112             'AdditionalLibraryDirectories': 'folder1;folder2',
113             'AdditionalManifestDependencies': 'file1;file2',
114             'AdditionalOptions': 'a string1',
115             'AddModuleNamesToAssembly': 'file1;file2',
116             'AllowIsolation': 'true',
117             'AssemblyDebug': '2',
118             'AssemblyLinkResource': 'file1;file2',
119             'BaseAddress': 'a string1',
120             'CLRImageType': '2',
121             'CLRThreadAttribute': '2',
122             'CLRUnmanagedCodeCheck': 'true',
123             'DataExecutionPrevention': '2',
124             'DelayLoadDLLs': 'file1;file2',
125             'DelaySign': 'true',
126             'Driver': '2',
127             'EmbedManagedResourceFile': 'file1;file2',
128             'EnableCOMDATFolding': '2',
129             'EnableUAC': 'true',
130             'EntryPointSymbol': 'a string1',
131             'ErrorReporting': '2',
132             'FixedBaseAddress': '2',
133             'ForceSymbolReferences': 'file1;file2',
134             'FunctionOrder': 'a_file_name',
135             'GenerateDebugInformation': 'true',
136             'GenerateManifest': 'true',
137             'GenerateMapFile': 'true',
138             'HeapCommitSize': 'a string1',
139             'HeapReserveSize': 'a string1',
140             'IgnoreAllDefaultLibraries': 'true',
141             'IgnoreDefaultLibraryNames': 'file1;file2',
142             'IgnoreEmbeddedIDL': 'true',
143             'IgnoreImportLibrary': 'true',
144             'ImportLibrary': 'a_file_name',
145             'KeyContainer': 'a_file_name',
146             'KeyFile': 'a_file_name',
147             'LargeAddressAware': '2',
148             'LinkIncremental': '2',
149             'LinkLibraryDependencies': 'true',
150             'LinkTimeCodeGeneration': '2',
151             'ManifestFile': 'a_file_name',
152             'MapExports': 'true',
153             'MapFileName': 'a_file_name',
154             'MergedIDLBaseFileName': 'a_file_name',
155             'MergeSections': 'a string1',
156             'MidlCommandFile': 'a_file_name',
157             'ModuleDefinitionFile': 'a_file_name',
158             'OptimizeForWindows98': '1',
159             'OptimizeReferences': '2',
160             'OutputFile': 'a_file_name',
161             'PerUserRedirection': 'true',
162             'Profile': 'true',
163             'ProfileGuidedDatabase': 'a_file_name',
164             'ProgramDatabaseFile': 'a_file_name',
165             'RandomizedBaseAddress': '2',
166             'RegisterOutput': 'true',
167             'ResourceOnlyDLL': 'true',
168             'SetChecksum': 'true',
169             'ShowProgress': '2',
170             'StackCommitSize': 'a string1',
171             'StackReserveSize': 'a string1',
172             'StripPrivateSymbols': 'a_file_name',
173             'SubSystem': '2',
174             'SupportUnloadOfDelayLoadedDLL': 'true',
175             'SuppressStartupBanner': 'true',
176             'SwapRunFromCD': 'true',
177             'SwapRunFromNet': 'true',
178             'TargetMachine': '2',
179             'TerminalServerAware': '2',
180             'TurnOffAssemblyGeneration': 'true',
181             'TypeLibraryFile': 'a_file_name',
182             'TypeLibraryResourceID': '33',
183             'UACExecutionLevel': '2',
184             'UACUIAccess': 'true',
185             'UseLibraryDependencyInputs': 'true',
186             'UseUnicodeResponseFiles': 'true',
187             'Version': 'a string1'},
188         'VCMIDLTool': {
189             'AdditionalIncludeDirectories': 'folder1;folder2',
190             'AdditionalOptions': 'a string1',
191             'CPreprocessOptions': 'a string1',
192             'DefaultCharType': '1',
193             'DLLDataFileName': 'a_file_name',
194             'EnableErrorChecks': '1',
195             'ErrorCheckAllocations': 'true',
196             'ErrorCheckBounds': 'true',
197             'ErrorCheckEnumRange': 'true',
198             'ErrorCheckRefPointers': 'true',
199             'ErrorCheckStubData': 'true',
200             'GenerateStublessProxies': 'true',
201             'GenerateTypeLibrary': 'true',
202             'HeaderFileName': 'a_file_name',
203             'IgnoreStandardIncludePath': 'true',
204             'InterfaceIdentifierFileName': 'a_file_name',
205             'MkTypLibCompatible': 'true',
206             'notgood': 'bogus',
207             'OutputDirectory': 'a string1',
208             'PreprocessorDefinitions': 'string1;string2',
209             'ProxyFileName': 'a_file_name',
210             'RedirectOutputAndErrors': 'a_file_name',
211             'StructMemberAlignment': '1',
212             'SuppressStartupBanner': 'true',
213             'TargetEnvironment': '1',
214             'TypeLibraryName': 'a_file_name',
215             'UndefinePreprocessorDefinitions': 'string1;string2',
216             'ValidateParameters': 'true',
217             'WarnAsError': 'true',
218             'WarningLevel': '1'},
219         'VCResourceCompilerTool': {
220             'AdditionalOptions': 'a string1',
221             'AdditionalIncludeDirectories': 'folder1;folder2',
222             'Culture': '1003',
223             'IgnoreStandardIncludePath': 'true',
224             'notgood2': 'bogus',
225             'PreprocessorDefinitions': 'string1;string2',
226             'ResourceOutputFileName': 'a string1',
227             'ShowProgress': 'true',
228             'SuppressStartupBanner': 'true',
229             'UndefinePreprocessorDefinitions': 'string1;string2'},
230         'VCLibrarianTool': {
231             'AdditionalDependencies': 'file1;file2',
232             'AdditionalLibraryDirectories': 'folder1;folder2',
233             'AdditionalOptions': 'a string1',
234             'ExportNamedFunctions': 'string1;string2',
235             'ForceSymbolReferences': 'a string1',
236             'IgnoreAllDefaultLibraries': 'true',
237             'IgnoreSpecificDefaultLibraries': 'file1;file2',
238             'LinkLibraryDependencies': 'true',
239             'ModuleDefinitionFile': 'a_file_name',
240             'OutputFile': 'a_file_name',
241             'SuppressStartupBanner': 'true',
242             'UseUnicodeResponseFiles': 'true'},
243         'VCManifestTool': {
244             'AdditionalManifestFiles': 'file1;file2',
245             'AdditionalOptions': 'a string1',
246             'AssemblyIdentity': 'a string1',
247             'ComponentFileName': 'a_file_name',
248             'DependencyInformationFile': 'a_file_name',
249             'GenerateCatalogFiles': 'true',
250             'InputResourceManifests': 'a string1',
251             'ManifestResourceFile': 'a_file_name',
252             'OutputManifestFile': 'a_file_name',
253             'RegistrarScriptFile': 'a_file_name',
254             'ReplacementsFile': 'a_file_name',
255             'SuppressStartupBanner': 'true',
256             'TypeLibraryFile': 'a_file_name',
257             'UpdateFileHashes': 'truel',
258             'UpdateFileHashesSearchPath': 'a_file_name',
259             'UseFAT32Workaround': 'true',
260             'UseUnicodeResponseFiles': 'true',
261             'VerboseOutput': 'true'}},
262        self.stderr)
263    self._ExpectedWarnings([
264        'Warning: for VCCLCompilerTool/BasicRuntimeChecks, '
265        'index value (5) not in expected range [0, 4)',
266        'Warning: for VCCLCompilerTool/BrowseInformation, '
267        "invalid literal for int() with base 10: 'fdkslj'",
268        'Warning: for VCCLCompilerTool/CallingConvention, '
269        'index value (-1) not in expected range [0, 3)',
270        'Warning: for VCCLCompilerTool/DebugInformationFormat, '
271        'converted value for 2 not specified.',
272        'Warning: unrecognized setting VCCLCompilerTool/Enableprefast',
273        'Warning: unrecognized setting VCCLCompilerTool/ZZXYZ',
274        'Warning: for VCLinkerTool/TargetMachine, '
275        'converted value for 2 not specified.',
276        'Warning: unrecognized setting VCMIDLTool/notgood',
277        'Warning: unrecognized setting VCResourceCompilerTool/notgood2',
278        'Warning: for VCManifestTool/UpdateFileHashes, '
279        "expected bool; got 'truel'"
280        ''])
281
282  def testValidateMSBuildSettings_settings(self):
283    """Tests that for invalid MSBuild settings."""
284    MSVSSettings.ValidateMSBuildSettings(
285        {'ClCompile': {
286            'AdditionalIncludeDirectories': 'folder1;folder2',
287            'AdditionalOptions': ['string1', 'string2'],
288            'AdditionalUsingDirectories': 'folder1;folder2',
289            'AssemblerListingLocation': 'a_file_name',
290            'AssemblerOutput': 'NoListing',
291            'BasicRuntimeChecks': 'StackFrameRuntimeCheck',
292            'BrowseInformation': 'false',
293            'BrowseInformationFile': 'a_file_name',
294            'BufferSecurityCheck': 'true',
295            'BuildingInIDE': 'true',
296            'CallingConvention': 'Cdecl',
297            'CompileAs': 'CompileAsC',
298            'CompileAsManaged': 'Pure',
299            'CreateHotpatchableImage': 'true',
300            'DebugInformationFormat': 'ProgramDatabase',
301            'DisableLanguageExtensions': 'true',
302            'DisableSpecificWarnings': 'string1;string2',
303            'EnableEnhancedInstructionSet': 'StreamingSIMDExtensions',
304            'EnableFiberSafeOptimizations': 'true',
305            'EnablePREfast': 'true',
306            'Enableprefast': 'bogus',
307            'ErrorReporting': 'Prompt',
308            'ExceptionHandling': 'SyncCThrow',
309            'ExpandAttributedSource': 'true',
310            'FavorSizeOrSpeed': 'Neither',
311            'FloatingPointExceptions': 'true',
312            'FloatingPointModel': 'Precise',
313            'ForceConformanceInForLoopScope': 'true',
314            'ForcedIncludeFiles': 'file1;file2',
315            'ForcedUsingFiles': 'file1;file2',
316            'FunctionLevelLinking': 'false',
317            'GenerateXMLDocumentationFiles': 'true',
318            'IgnoreStandardIncludePath': 'true',
319            'InlineFunctionExpansion': 'OnlyExplicitInline',
320            'IntrinsicFunctions': 'false',
321            'MinimalRebuild': 'true',
322            'MultiProcessorCompilation': 'true',
323            'ObjectFileName': 'a_file_name',
324            'OmitDefaultLibName': 'true',
325            'OmitFramePointers': 'true',
326            'OpenMPSupport': 'true',
327            'Optimization': 'Disabled',
328            'PrecompiledHeader': 'NotUsing',
329            'PrecompiledHeaderFile': 'a_file_name',
330            'PrecompiledHeaderOutputFile': 'a_file_name',
331            'PreprocessKeepComments': 'true',
332            'PreprocessorDefinitions': 'string1;string2',
333            'PreprocessOutputPath': 'a string1',
334            'PreprocessSuppressLineNumbers': 'false',
335            'PreprocessToFile': 'false',
336            'ProcessorNumber': '33',
337            'ProgramDataBaseFileName': 'a_file_name',
338            'RuntimeLibrary': 'MultiThreaded',
339            'RuntimeTypeInfo': 'true',
340            'ShowIncludes': 'true',
341            'SmallerTypeCheck': 'true',
342            'StringPooling': 'true',
343            'StructMemberAlignment': '1Byte',
344            'SuppressStartupBanner': 'true',
345            'TrackerLogDirectory': 'a_folder',
346            'TreatSpecificWarningsAsErrors': 'string1;string2',
347            'TreatWarningAsError': 'true',
348            'TreatWChar_tAsBuiltInType': 'true',
349            'UndefineAllPreprocessorDefinitions': 'true',
350            'UndefinePreprocessorDefinitions': 'string1;string2',
351            'UseFullPaths': 'true',
352            'UseUnicodeForAssemblerListing': 'true',
353            'WarningLevel': 'TurnOffAllWarnings',
354            'WholeProgramOptimization': 'true',
355            'XMLDocumentationFileName': 'a_file_name',
356            'ZZXYZ': 'bogus'},
357         'Link': {
358             'AdditionalDependencies': 'file1;file2',
359             'AdditionalLibraryDirectories': 'folder1;folder2',
360             'AdditionalManifestDependencies': 'file1;file2',
361             'AdditionalOptions': 'a string1',
362             'AddModuleNamesToAssembly': 'file1;file2',
363             'AllowIsolation': 'true',
364             'AssemblyDebug': '',
365             'AssemblyLinkResource': 'file1;file2',
366             'BaseAddress': 'a string1',
367             'BuildingInIDE': 'true',
368             'CLRImageType': 'ForceIJWImage',
369             'CLRSupportLastError': 'Enabled',
370             'CLRThreadAttribute': 'MTAThreadingAttribute',
371             'CLRUnmanagedCodeCheck': 'true',
372             'CreateHotPatchableImage': 'X86Image',
373             'DataExecutionPrevention': 'false',
374             'DelayLoadDLLs': 'file1;file2',
375             'DelaySign': 'true',
376             'Driver': 'NotSet',
377             'EmbedManagedResourceFile': 'file1;file2',
378             'EnableCOMDATFolding': 'false',
379             'EnableUAC': 'true',
380             'EntryPointSymbol': 'a string1',
381             'FixedBaseAddress': 'false',
382             'ForceFileOutput': 'Enabled',
383             'ForceSymbolReferences': 'file1;file2',
384             'FunctionOrder': 'a_file_name',
385             'GenerateDebugInformation': 'true',
386             'GenerateMapFile': 'true',
387             'HeapCommitSize': 'a string1',
388             'HeapReserveSize': 'a string1',
389             'IgnoreAllDefaultLibraries': 'true',
390             'IgnoreEmbeddedIDL': 'true',
391             'IgnoreSpecificDefaultLibraries': 'a_file_list',
392             'ImageHasSafeExceptionHandlers': 'true',
393             'ImportLibrary': 'a_file_name',
394             'KeyContainer': 'a_file_name',
395             'KeyFile': 'a_file_name',
396             'LargeAddressAware': 'false',
397             'LinkDLL': 'true',
398             'LinkErrorReporting': 'SendErrorReport',
399             'LinkStatus': 'true',
400             'LinkTimeCodeGeneration': 'UseLinkTimeCodeGeneration',
401             'ManifestFile': 'a_file_name',
402             'MapExports': 'true',
403             'MapFileName': 'a_file_name',
404             'MergedIDLBaseFileName': 'a_file_name',
405             'MergeSections': 'a string1',
406             'MidlCommandFile': 'a_file_name',
407             'MinimumRequiredVersion': 'a string1',
408             'ModuleDefinitionFile': 'a_file_name',
409             'MSDOSStubFileName': 'a_file_name',
410             'NoEntryPoint': 'true',
411             'OptimizeReferences': 'false',
412             'OutputFile': 'a_file_name',
413             'PerUserRedirection': 'true',
414             'PreventDllBinding': 'true',
415             'Profile': 'true',
416             'ProfileGuidedDatabase': 'a_file_name',
417             'ProgramDatabaseFile': 'a_file_name',
418             'RandomizedBaseAddress': 'false',
419             'RegisterOutput': 'true',
420             'SectionAlignment': '33',
421             'SetChecksum': 'true',
422             'ShowProgress': 'LinkVerboseREF',
423             'SpecifySectionAttributes': 'a string1',
424             'StackCommitSize': 'a string1',
425             'StackReserveSize': 'a string1',
426             'StripPrivateSymbols': 'a_file_name',
427             'SubSystem': 'Console',
428             'SupportNobindOfDelayLoadedDLL': 'true',
429             'SupportUnloadOfDelayLoadedDLL': 'true',
430             'SuppressStartupBanner': 'true',
431             'SwapRunFromCD': 'true',
432             'SwapRunFromNET': 'true',
433             'TargetMachine': 'MachineX86',
434             'TerminalServerAware': 'false',
435             'TrackerLogDirectory': 'a_folder',
436             'TreatLinkerWarningAsErrors': 'true',
437             'TurnOffAssemblyGeneration': 'true',
438             'TypeLibraryFile': 'a_file_name',
439             'TypeLibraryResourceID': '33',
440             'UACExecutionLevel': 'AsInvoker',
441             'UACUIAccess': 'true',
442             'Version': 'a string1'},
443         'ResourceCompile': {
444             'AdditionalIncludeDirectories': 'folder1;folder2',
445             'AdditionalOptions': 'a string1',
446             'Culture': '0x236',
447             'IgnoreStandardIncludePath': 'true',
448             'NullTerminateStrings': 'true',
449             'PreprocessorDefinitions': 'string1;string2',
450             'ResourceOutputFileName': 'a string1',
451             'ShowProgress': 'true',
452             'SuppressStartupBanner': 'true',
453             'TrackerLogDirectory': 'a_folder',
454             'UndefinePreprocessorDefinitions': 'string1;string2'},
455         'Midl': {
456             'AdditionalIncludeDirectories': 'folder1;folder2',
457             'AdditionalOptions': 'a string1',
458             'ApplicationConfigurationMode': 'true',
459             'ClientStubFile': 'a_file_name',
460             'CPreprocessOptions': 'a string1',
461             'DefaultCharType': 'Signed',
462             'DllDataFileName': 'a_file_name',
463             'EnableErrorChecks': 'EnableCustom',
464             'ErrorCheckAllocations': 'true',
465             'ErrorCheckBounds': 'true',
466             'ErrorCheckEnumRange': 'true',
467             'ErrorCheckRefPointers': 'true',
468             'ErrorCheckStubData': 'true',
469             'GenerateClientFiles': 'Stub',
470             'GenerateServerFiles': 'None',
471             'GenerateStublessProxies': 'true',
472             'GenerateTypeLibrary': 'true',
473             'HeaderFileName': 'a_file_name',
474             'IgnoreStandardIncludePath': 'true',
475             'InterfaceIdentifierFileName': 'a_file_name',
476             'LocaleID': '33',
477             'MkTypLibCompatible': 'true',
478             'OutputDirectory': 'a string1',
479             'PreprocessorDefinitions': 'string1;string2',
480             'ProxyFileName': 'a_file_name',
481             'RedirectOutputAndErrors': 'a_file_name',
482             'ServerStubFile': 'a_file_name',
483             'StructMemberAlignment': 'NotSet',
484             'SuppressCompilerWarnings': 'true',
485             'SuppressStartupBanner': 'true',
486             'TargetEnvironment': 'Itanium',
487             'TrackerLogDirectory': 'a_folder',
488             'TypeLibFormat': 'NewFormat',
489             'TypeLibraryName': 'a_file_name',
490             'UndefinePreprocessorDefinitions': 'string1;string2',
491             'ValidateAllParameters': 'true',
492             'WarnAsError': 'true',
493             'WarningLevel': '1'},
494         'Lib': {
495             'AdditionalDependencies': 'file1;file2',
496             'AdditionalLibraryDirectories': 'folder1;folder2',
497             'AdditionalOptions': 'a string1',
498             'DisplayLibrary': 'a string1',
499             'ErrorReporting': 'PromptImmediately',
500             'ExportNamedFunctions': 'string1;string2',
501             'ForceSymbolReferences': 'a string1',
502             'IgnoreAllDefaultLibraries': 'true',
503             'IgnoreSpecificDefaultLibraries': 'file1;file2',
504             'LinkTimeCodeGeneration': 'true',
505             'MinimumRequiredVersion': 'a string1',
506             'ModuleDefinitionFile': 'a_file_name',
507             'Name': 'a_file_name',
508             'OutputFile': 'a_file_name',
509             'RemoveObjects': 'file1;file2',
510             'SubSystem': 'Console',
511             'SuppressStartupBanner': 'true',
512             'TargetMachine': 'MachineX86i',
513             'TrackerLogDirectory': 'a_folder',
514             'TreatLibWarningAsErrors': 'true',
515             'UseUnicodeResponseFiles': 'true',
516             'Verbose': 'true'},
517         'Manifest': {
518             'AdditionalManifestFiles': 'file1;file2',
519             'AdditionalOptions': 'a string1',
520             'AssemblyIdentity': 'a string1',
521             'ComponentFileName': 'a_file_name',
522             'EnableDPIAwareness': 'fal',
523             'GenerateCatalogFiles': 'truel',
524             'GenerateCategoryTags': 'true',
525             'InputResourceManifests': 'a string1',
526             'ManifestFromManagedAssembly': 'a_file_name',
527             'notgood3': 'bogus',
528             'OutputManifestFile': 'a_file_name',
529             'OutputResourceManifests': 'a string1',
530             'RegistrarScriptFile': 'a_file_name',
531             'ReplacementsFile': 'a_file_name',
532             'SuppressDependencyElement': 'true',
533             'SuppressStartupBanner': 'true',
534             'TrackerLogDirectory': 'a_folder',
535             'TypeLibraryFile': 'a_file_name',
536             'UpdateFileHashes': 'true',
537             'UpdateFileHashesSearchPath': 'a_file_name',
538             'VerboseOutput': 'true'},
539         'ProjectReference': {
540             'LinkLibraryDependencies': 'true',
541             'UseLibraryDependencyInputs': 'true'},
542         'ManifestResourceCompile': {
543             'ResourceOutputFileName': 'a_file_name'},
544         '': {
545             'EmbedManifest': 'true',
546             'GenerateManifest': 'true',
547             'IgnoreImportLibrary': 'true',
548             'LinkIncremental': 'false'}},
549        self.stderr)
550    self._ExpectedWarnings([
551        'Warning: unrecognized setting ClCompile/Enableprefast',
552        'Warning: unrecognized setting ClCompile/ZZXYZ',
553        'Warning: unrecognized setting Manifest/notgood3',
554        'Warning: for Manifest/GenerateCatalogFiles, '
555        "expected bool; got 'truel'",
556        'Warning: for Lib/TargetMachine, unrecognized enumerated value '
557        'MachineX86i',
558        "Warning: for Manifest/EnableDPIAwareness, expected bool; got 'fal'"])
559
560  def testConvertToMSBuildSettings_empty(self):
561    """Tests an empty conversion."""
562    msvs_settings = {}
563    expected_msbuild_settings = {}
564    actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
565        msvs_settings,
566        self.stderr)
567    self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
568    self._ExpectedWarnings([])
569
570  def testConvertToMSBuildSettings_minimal(self):
571    """Tests a minimal conversion."""
572    msvs_settings = {
573        'VCCLCompilerTool': {
574            'AdditionalIncludeDirectories': 'dir1',
575            'AdditionalOptions': '/foo',
576            'BasicRuntimeChecks': '0',
577            },
578        'VCLinkerTool': {
579            'LinkTimeCodeGeneration': '1',
580            'ErrorReporting': '1',
581            'DataExecutionPrevention': '2',
582            },
583        }
584    expected_msbuild_settings = {
585        'ClCompile': {
586            'AdditionalIncludeDirectories': 'dir1',
587            'AdditionalOptions': '/foo',
588            'BasicRuntimeChecks': 'Default',
589            },
590        'Link': {
591            'LinkTimeCodeGeneration': 'UseLinkTimeCodeGeneration',
592            'LinkErrorReporting': 'PromptImmediately',
593            'DataExecutionPrevention': 'true',
594            },
595        }
596    actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
597        msvs_settings,
598        self.stderr)
599    self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
600    self._ExpectedWarnings([])
601
602  def testConvertToMSBuildSettings_warnings(self):
603    """Tests conversion that generates warnings."""
604    msvs_settings = {
605        'VCCLCompilerTool': {
606            'AdditionalIncludeDirectories': '1',
607            'AdditionalOptions': '2',
608            # These are incorrect values:
609            'BasicRuntimeChecks': '12',
610            'BrowseInformation': '21',
611            'UsePrecompiledHeader': '13',
612            'GeneratePreprocessedFile': '14'},
613        'VCLinkerTool': {
614            # These are incorrect values:
615            'Driver': '10',
616            'LinkTimeCodeGeneration': '31',
617            'ErrorReporting': '21',
618            'FixedBaseAddress': '6'},
619        'VCResourceCompilerTool': {
620            # Custom
621            'Culture': '1003'}}
622    expected_msbuild_settings = {
623        'ClCompile': {
624            'AdditionalIncludeDirectories': '1',
625            'AdditionalOptions': '2'},
626        'Link': {},
627        'ResourceCompile': {
628            # Custom
629            'Culture': '0x03eb'}}
630    actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
631        msvs_settings,
632        self.stderr)
633    self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
634    self._ExpectedWarnings([
635        'Warning: while converting VCCLCompilerTool/BasicRuntimeChecks to '
636        'MSBuild, index value (12) not in expected range [0, 4)',
637        'Warning: while converting VCCLCompilerTool/BrowseInformation to '
638        'MSBuild, index value (21) not in expected range [0, 3)',
639        'Warning: while converting VCCLCompilerTool/UsePrecompiledHeader to '
640        'MSBuild, index value (13) not in expected range [0, 3)',
641        'Warning: while converting VCCLCompilerTool/GeneratePreprocessedFile to '
642        'MSBuild, value must be one of [0, 1, 2]; got 14',
643
644        'Warning: while converting VCLinkerTool/Driver to '
645        'MSBuild, index value (10) not in expected range [0, 4)',
646        'Warning: while converting VCLinkerTool/LinkTimeCodeGeneration to '
647        'MSBuild, index value (31) not in expected range [0, 5)',
648        'Warning: while converting VCLinkerTool/ErrorReporting to '
649        'MSBuild, index value (21) not in expected range [0, 3)',
650        'Warning: while converting VCLinkerTool/FixedBaseAddress to '
651        'MSBuild, index value (6) not in expected range [0, 3)',
652        ])
653
654  def testConvertToMSBuildSettings_full_synthetic(self):
655    """Tests conversion of all the MSBuild settings."""
656    msvs_settings = {
657        'VCCLCompilerTool': {
658            'AdditionalIncludeDirectories': 'folder1;folder2;folder3',
659            'AdditionalOptions': 'a_string',
660            'AdditionalUsingDirectories': 'folder1;folder2;folder3',
661            'AssemblerListingLocation': 'a_file_name',
662            'AssemblerOutput': '0',
663            'BasicRuntimeChecks': '1',
664            'BrowseInformation': '2',
665            'BrowseInformationFile': 'a_file_name',
666            'BufferSecurityCheck': 'true',
667            'CallingConvention': '0',
668            'CompileAs': '1',
669            'DebugInformationFormat': '4',
670            'DefaultCharIsUnsigned': 'true',
671            'Detect64BitPortabilityProblems': 'true',
672            'DisableLanguageExtensions': 'true',
673            'DisableSpecificWarnings': 'd1;d2;d3',
674            'EnableEnhancedInstructionSet': '0',
675            'EnableFiberSafeOptimizations': 'true',
676            'EnableFunctionLevelLinking': 'true',
677            'EnableIntrinsicFunctions': 'true',
678            'EnablePREfast': 'true',
679            'ErrorReporting': '1',
680            'ExceptionHandling': '2',
681            'ExpandAttributedSource': 'true',
682            'FavorSizeOrSpeed': '0',
683            'FloatingPointExceptions': 'true',
684            'FloatingPointModel': '1',
685            'ForceConformanceInForLoopScope': 'true',
686            'ForcedIncludeFiles': 'file1;file2;file3',
687            'ForcedUsingFiles': 'file1;file2;file3',
688            'GeneratePreprocessedFile': '1',
689            'GenerateXMLDocumentationFiles': 'true',
690            'IgnoreStandardIncludePath': 'true',
691            'InlineFunctionExpansion': '2',
692            'KeepComments': 'true',
693            'MinimalRebuild': 'true',
694            'ObjectFile': 'a_file_name',
695            'OmitDefaultLibName': 'true',
696            'OmitFramePointers': 'true',
697            'OpenMP': 'true',
698            'Optimization': '3',
699            'PrecompiledHeaderFile': 'a_file_name',
700            'PrecompiledHeaderThrough': 'a_file_name',
701            'PreprocessorDefinitions': 'd1;d2;d3',
702            'ProgramDataBaseFileName': 'a_file_name',
703            'RuntimeLibrary': '0',
704            'RuntimeTypeInfo': 'true',
705            'ShowIncludes': 'true',
706            'SmallerTypeCheck': 'true',
707            'StringPooling': 'true',
708            'StructMemberAlignment': '1',
709            'SuppressStartupBanner': 'true',
710            'TreatWChar_tAsBuiltInType': 'true',
711            'UndefineAllPreprocessorDefinitions': 'true',
712            'UndefinePreprocessorDefinitions': 'd1;d2;d3',
713            'UseFullPaths': 'true',
714            'UsePrecompiledHeader': '1',
715            'UseUnicodeResponseFiles': 'true',
716            'WarnAsError': 'true',
717            'WarningLevel': '2',
718            'WholeProgramOptimization': 'true',
719            'XMLDocumentationFileName': 'a_file_name'},
720        'VCLinkerTool': {
721            'AdditionalDependencies': 'file1;file2;file3',
722            'AdditionalLibraryDirectories': 'folder1;folder2;folder3',
723            'AdditionalLibraryDirectories_excluded': 'folder1;folder2;folder3',
724            'AdditionalManifestDependencies': 'file1;file2;file3',
725            'AdditionalOptions': 'a_string',
726            'AddModuleNamesToAssembly': 'file1;file2;file3',
727            'AllowIsolation': 'true',
728            'AssemblyDebug': '0',
729            'AssemblyLinkResource': 'file1;file2;file3',
730            'BaseAddress': 'a_string',
731            'CLRImageType': '1',
732            'CLRThreadAttribute': '2',
733            'CLRUnmanagedCodeCheck': 'true',
734            'DataExecutionPrevention': '0',
735            'DelayLoadDLLs': 'file1;file2;file3',
736            'DelaySign': 'true',
737            'Driver': '1',
738            'EmbedManagedResourceFile': 'file1;file2;file3',
739            'EnableCOMDATFolding': '0',
740            'EnableUAC': 'true',
741            'EntryPointSymbol': 'a_string',
742            'ErrorReporting': '0',
743            'FixedBaseAddress': '1',
744            'ForceSymbolReferences': 'file1;file2;file3',
745            'FunctionOrder': 'a_file_name',
746            'GenerateDebugInformation': 'true',
747            'GenerateManifest': 'true',
748            'GenerateMapFile': 'true',
749            'HeapCommitSize': 'a_string',
750            'HeapReserveSize': 'a_string',
751            'IgnoreAllDefaultLibraries': 'true',
752            'IgnoreDefaultLibraryNames': 'file1;file2;file3',
753            'IgnoreEmbeddedIDL': 'true',
754            'IgnoreImportLibrary': 'true',
755            'ImportLibrary': 'a_file_name',
756            'KeyContainer': 'a_file_name',
757            'KeyFile': 'a_file_name',
758            'LargeAddressAware': '2',
759            'LinkIncremental': '1',
760            'LinkLibraryDependencies': 'true',
761            'LinkTimeCodeGeneration': '2',
762            'ManifestFile': 'a_file_name',
763            'MapExports': 'true',
764            'MapFileName': 'a_file_name',
765            'MergedIDLBaseFileName': 'a_file_name',
766            'MergeSections': 'a_string',
767            'MidlCommandFile': 'a_file_name',
768            'ModuleDefinitionFile': 'a_file_name',
769            'OptimizeForWindows98': '1',
770            'OptimizeReferences': '0',
771            'OutputFile': 'a_file_name',
772            'PerUserRedirection': 'true',
773            'Profile': 'true',
774            'ProfileGuidedDatabase': 'a_file_name',
775            'ProgramDatabaseFile': 'a_file_name',
776            'RandomizedBaseAddress': '1',
777            'RegisterOutput': 'true',
778            'ResourceOnlyDLL': 'true',
779            'SetChecksum': 'true',
780            'ShowProgress': '0',
781            'StackCommitSize': 'a_string',
782            'StackReserveSize': 'a_string',
783            'StripPrivateSymbols': 'a_file_name',
784            'SubSystem': '2',
785            'SupportUnloadOfDelayLoadedDLL': 'true',
786            'SuppressStartupBanner': 'true',
787            'SwapRunFromCD': 'true',
788            'SwapRunFromNet': 'true',
789            'TargetMachine': '3',
790            'TerminalServerAware': '2',
791            'TurnOffAssemblyGeneration': 'true',
792            'TypeLibraryFile': 'a_file_name',
793            'TypeLibraryResourceID': '33',
794            'UACExecutionLevel': '1',
795            'UACUIAccess': 'true',
796            'UseLibraryDependencyInputs': 'false',
797            'UseUnicodeResponseFiles': 'true',
798            'Version': 'a_string'},
799        'VCResourceCompilerTool': {
800            'AdditionalIncludeDirectories': 'folder1;folder2;folder3',
801            'AdditionalOptions': 'a_string',
802            'Culture': '1003',
803            'IgnoreStandardIncludePath': 'true',
804            'PreprocessorDefinitions': 'd1;d2;d3',
805            'ResourceOutputFileName': 'a_string',
806            'ShowProgress': 'true',
807            'SuppressStartupBanner': 'true',
808            'UndefinePreprocessorDefinitions': 'd1;d2;d3'},
809        'VCMIDLTool': {
810            'AdditionalIncludeDirectories': 'folder1;folder2;folder3',
811            'AdditionalOptions': 'a_string',
812            'CPreprocessOptions': 'a_string',
813            'DefaultCharType': '0',
814            'DLLDataFileName': 'a_file_name',
815            'EnableErrorChecks': '2',
816            'ErrorCheckAllocations': 'true',
817            'ErrorCheckBounds': 'true',
818            'ErrorCheckEnumRange': 'true',
819            'ErrorCheckRefPointers': 'true',
820            'ErrorCheckStubData': 'true',
821            'GenerateStublessProxies': 'true',
822            'GenerateTypeLibrary': 'true',
823            'HeaderFileName': 'a_file_name',
824            'IgnoreStandardIncludePath': 'true',
825            'InterfaceIdentifierFileName': 'a_file_name',
826            'MkTypLibCompatible': 'true',
827            'OutputDirectory': 'a_string',
828            'PreprocessorDefinitions': 'd1;d2;d3',
829            'ProxyFileName': 'a_file_name',
830            'RedirectOutputAndErrors': 'a_file_name',
831            'StructMemberAlignment': '3',
832            'SuppressStartupBanner': 'true',
833            'TargetEnvironment': '1',
834            'TypeLibraryName': 'a_file_name',
835            'UndefinePreprocessorDefinitions': 'd1;d2;d3',
836            'ValidateParameters': 'true',
837            'WarnAsError': 'true',
838            'WarningLevel': '4'},
839        'VCLibrarianTool': {
840            'AdditionalDependencies': 'file1;file2;file3',
841            'AdditionalLibraryDirectories': 'folder1;folder2;folder3',
842            'AdditionalLibraryDirectories_excluded': 'folder1;folder2;folder3',
843            'AdditionalOptions': 'a_string',
844            'ExportNamedFunctions': 'd1;d2;d3',
845            'ForceSymbolReferences': 'a_string',
846            'IgnoreAllDefaultLibraries': 'true',
847            'IgnoreSpecificDefaultLibraries': 'file1;file2;file3',
848            'LinkLibraryDependencies': 'true',
849            'ModuleDefinitionFile': 'a_file_name',
850            'OutputFile': 'a_file_name',
851            'SuppressStartupBanner': 'true',
852            'UseUnicodeResponseFiles': 'true'},
853        'VCManifestTool': {
854            'AdditionalManifestFiles': 'file1;file2;file3',
855            'AdditionalOptions': 'a_string',
856            'AssemblyIdentity': 'a_string',
857            'ComponentFileName': 'a_file_name',
858            'DependencyInformationFile': 'a_file_name',
859            'EmbedManifest': 'true',
860            'GenerateCatalogFiles': 'true',
861            'InputResourceManifests': 'a_string',
862            'ManifestResourceFile': 'my_name',
863            'OutputManifestFile': 'a_file_name',
864            'RegistrarScriptFile': 'a_file_name',
865            'ReplacementsFile': 'a_file_name',
866            'SuppressStartupBanner': 'true',
867            'TypeLibraryFile': 'a_file_name',
868            'UpdateFileHashes': 'true',
869            'UpdateFileHashesSearchPath': 'a_file_name',
870            'UseFAT32Workaround': 'true',
871            'UseUnicodeResponseFiles': 'true',
872            'VerboseOutput': 'true'}}
873    expected_msbuild_settings = {
874        'ClCompile': {
875            'AdditionalIncludeDirectories': 'folder1;folder2;folder3',
876            'AdditionalOptions': 'a_string /J',
877            'AdditionalUsingDirectories': 'folder1;folder2;folder3',
878            'AssemblerListingLocation': 'a_file_name',
879            'AssemblerOutput': 'NoListing',
880            'BasicRuntimeChecks': 'StackFrameRuntimeCheck',
881            'BrowseInformation': 'true',
882            'BrowseInformationFile': 'a_file_name',
883            'BufferSecurityCheck': 'true',
884            'CallingConvention': 'Cdecl',
885            'CompileAs': 'CompileAsC',
886            'DebugInformationFormat': 'EditAndContinue',
887            'DisableLanguageExtensions': 'true',
888            'DisableSpecificWarnings': 'd1;d2;d3',
889            'EnableEnhancedInstructionSet': 'NotSet',
890            'EnableFiberSafeOptimizations': 'true',
891            'EnablePREfast': 'true',
892            'ErrorReporting': 'Prompt',
893            'ExceptionHandling': 'Async',
894            'ExpandAttributedSource': 'true',
895            'FavorSizeOrSpeed': 'Neither',
896            'FloatingPointExceptions': 'true',
897            'FloatingPointModel': 'Strict',
898            'ForceConformanceInForLoopScope': 'true',
899            'ForcedIncludeFiles': 'file1;file2;file3',
900            'ForcedUsingFiles': 'file1;file2;file3',
901            'FunctionLevelLinking': 'true',
902            'GenerateXMLDocumentationFiles': 'true',
903            'IgnoreStandardIncludePath': 'true',
904            'InlineFunctionExpansion': 'AnySuitable',
905            'IntrinsicFunctions': 'true',
906            'MinimalRebuild': 'true',
907            'ObjectFileName': 'a_file_name',
908            'OmitDefaultLibName': 'true',
909            'OmitFramePointers': 'true',
910            'OpenMPSupport': 'true',
911            'Optimization': 'Full',
912            'PrecompiledHeader': 'Create',
913            'PrecompiledHeaderFile': 'a_file_name',
914            'PrecompiledHeaderOutputFile': 'a_file_name',
915            'PreprocessKeepComments': 'true',
916            'PreprocessorDefinitions': 'd1;d2;d3',
917            'PreprocessSuppressLineNumbers': 'false',
918            'PreprocessToFile': 'true',
919            'ProgramDataBaseFileName': 'a_file_name',
920            'RuntimeLibrary': 'MultiThreaded',
921            'RuntimeTypeInfo': 'true',
922            'ShowIncludes': 'true',
923            'SmallerTypeCheck': 'true',
924            'StringPooling': 'true',
925            'StructMemberAlignment': '1Byte',
926            'SuppressStartupBanner': 'true',
927            'TreatWarningAsError': 'true',
928            'TreatWChar_tAsBuiltInType': 'true',
929            'UndefineAllPreprocessorDefinitions': 'true',
930            'UndefinePreprocessorDefinitions': 'd1;d2;d3',
931            'UseFullPaths': 'true',
932            'WarningLevel': 'Level2',
933            'WholeProgramOptimization': 'true',
934            'XMLDocumentationFileName': 'a_file_name'},
935        'Link': {
936            'AdditionalDependencies': 'file1;file2;file3',
937            'AdditionalLibraryDirectories': 'folder1;folder2;folder3',
938            'AdditionalManifestDependencies': 'file1;file2;file3',
939            'AdditionalOptions': 'a_string',
940            'AddModuleNamesToAssembly': 'file1;file2;file3',
941            'AllowIsolation': 'true',
942            'AssemblyDebug': '',
943            'AssemblyLinkResource': 'file1;file2;file3',
944            'BaseAddress': 'a_string',
945            'CLRImageType': 'ForceIJWImage',
946            'CLRThreadAttribute': 'STAThreadingAttribute',
947            'CLRUnmanagedCodeCheck': 'true',
948            'DataExecutionPrevention': '',
949            'DelayLoadDLLs': 'file1;file2;file3',
950            'DelaySign': 'true',
951            'Driver': 'Driver',
952            'EmbedManagedResourceFile': 'file1;file2;file3',
953            'EnableCOMDATFolding': '',
954            'EnableUAC': 'true',
955            'EntryPointSymbol': 'a_string',
956            'FixedBaseAddress': 'false',
957            'ForceSymbolReferences': 'file1;file2;file3',
958            'FunctionOrder': 'a_file_name',
959            'GenerateDebugInformation': 'true',
960            'GenerateMapFile': 'true',
961            'HeapCommitSize': 'a_string',
962            'HeapReserveSize': 'a_string',
963            'IgnoreAllDefaultLibraries': 'true',
964            'IgnoreEmbeddedIDL': 'true',
965            'IgnoreSpecificDefaultLibraries': 'file1;file2;file3',
966            'ImportLibrary': 'a_file_name',
967            'KeyContainer': 'a_file_name',
968            'KeyFile': 'a_file_name',
969            'LargeAddressAware': 'true',
970            'LinkErrorReporting': 'NoErrorReport',
971            'LinkTimeCodeGeneration': 'PGInstrument',
972            'ManifestFile': 'a_file_name',
973            'MapExports': 'true',
974            'MapFileName': 'a_file_name',
975            'MergedIDLBaseFileName': 'a_file_name',
976            'MergeSections': 'a_string',
977            'MidlCommandFile': 'a_file_name',
978            'ModuleDefinitionFile': 'a_file_name',
979            'NoEntryPoint': 'true',
980            'OptimizeReferences': '',
981            'OutputFile': 'a_file_name',
982            'PerUserRedirection': 'true',
983            'Profile': 'true',
984            'ProfileGuidedDatabase': 'a_file_name',
985            'ProgramDatabaseFile': 'a_file_name',
986            'RandomizedBaseAddress': 'false',
987            'RegisterOutput': 'true',
988            'SetChecksum': 'true',
989            'ShowProgress': 'NotSet',
990            'StackCommitSize': 'a_string',
991            'StackReserveSize': 'a_string',
992            'StripPrivateSymbols': 'a_file_name',
993            'SubSystem': 'Windows',
994            'SupportUnloadOfDelayLoadedDLL': 'true',
995            'SuppressStartupBanner': 'true',
996            'SwapRunFromCD': 'true',
997            'SwapRunFromNET': 'true',
998            'TargetMachine': 'MachineARM',
999            'TerminalServerAware': 'true',
1000            'TurnOffAssemblyGeneration': 'true',
1001            'TypeLibraryFile': 'a_file_name',
1002            'TypeLibraryResourceID': '33',
1003            'UACExecutionLevel': 'HighestAvailable',
1004            'UACUIAccess': 'true',
1005            'Version': 'a_string'},
1006        'ResourceCompile': {
1007            'AdditionalIncludeDirectories': 'folder1;folder2;folder3',
1008            'AdditionalOptions': 'a_string',
1009            'Culture': '0x03eb',
1010            'IgnoreStandardIncludePath': 'true',
1011            'PreprocessorDefinitions': 'd1;d2;d3',
1012            'ResourceOutputFileName': 'a_string',
1013            'ShowProgress': 'true',
1014            'SuppressStartupBanner': 'true',
1015            'UndefinePreprocessorDefinitions': 'd1;d2;d3'},
1016        'Midl': {
1017            'AdditionalIncludeDirectories': 'folder1;folder2;folder3',
1018            'AdditionalOptions': 'a_string',
1019            'CPreprocessOptions': 'a_string',
1020            'DefaultCharType': 'Unsigned',
1021            'DllDataFileName': 'a_file_name',
1022            'EnableErrorChecks': 'All',
1023            'ErrorCheckAllocations': 'true',
1024            'ErrorCheckBounds': 'true',
1025            'ErrorCheckEnumRange': 'true',
1026            'ErrorCheckRefPointers': 'true',
1027            'ErrorCheckStubData': 'true',
1028            'GenerateStublessProxies': 'true',
1029            'GenerateTypeLibrary': 'true',
1030            'HeaderFileName': 'a_file_name',
1031            'IgnoreStandardIncludePath': 'true',
1032            'InterfaceIdentifierFileName': 'a_file_name',
1033            'MkTypLibCompatible': 'true',
1034            'OutputDirectory': 'a_string',
1035            'PreprocessorDefinitions': 'd1;d2;d3',
1036            'ProxyFileName': 'a_file_name',
1037            'RedirectOutputAndErrors': 'a_file_name',
1038            'StructMemberAlignment': '4',
1039            'SuppressStartupBanner': 'true',
1040            'TargetEnvironment': 'Win32',
1041            'TypeLibraryName': 'a_file_name',
1042            'UndefinePreprocessorDefinitions': 'd1;d2;d3',
1043            'ValidateAllParameters': 'true',
1044            'WarnAsError': 'true',
1045            'WarningLevel': '4'},
1046        'Lib': {
1047            'AdditionalDependencies': 'file1;file2;file3',
1048            'AdditionalLibraryDirectories': 'folder1;folder2;folder3',
1049            'AdditionalOptions': 'a_string',
1050            'ExportNamedFunctions': 'd1;d2;d3',
1051            'ForceSymbolReferences': 'a_string',
1052            'IgnoreAllDefaultLibraries': 'true',
1053            'IgnoreSpecificDefaultLibraries': 'file1;file2;file3',
1054            'ModuleDefinitionFile': 'a_file_name',
1055            'OutputFile': 'a_file_name',
1056            'SuppressStartupBanner': 'true',
1057            'UseUnicodeResponseFiles': 'true'},
1058        'Manifest': {
1059            'AdditionalManifestFiles': 'file1;file2;file3',
1060            'AdditionalOptions': 'a_string',
1061            'AssemblyIdentity': 'a_string',
1062            'ComponentFileName': 'a_file_name',
1063            'GenerateCatalogFiles': 'true',
1064            'InputResourceManifests': 'a_string',
1065            'OutputManifestFile': 'a_file_name',
1066            'RegistrarScriptFile': 'a_file_name',
1067            'ReplacementsFile': 'a_file_name',
1068            'SuppressStartupBanner': 'true',
1069            'TypeLibraryFile': 'a_file_name',
1070            'UpdateFileHashes': 'true',
1071            'UpdateFileHashesSearchPath': 'a_file_name',
1072            'VerboseOutput': 'true'},
1073        'ManifestResourceCompile': {
1074            'ResourceOutputFileName': 'my_name'},
1075        'ProjectReference': {
1076            'LinkLibraryDependencies': 'true',
1077            'UseLibraryDependencyInputs': 'false'},
1078        '': {
1079            'EmbedManifest': 'true',
1080            'GenerateManifest': 'true',
1081            'IgnoreImportLibrary': 'true',
1082            'LinkIncremental': 'false'}}
1083    actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
1084        msvs_settings,
1085        self.stderr)
1086    self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
1087    self._ExpectedWarnings([])
1088
1089  def testConvertToMSBuildSettings_actual(self):
1090    """Tests the conversion of an actual project.
1091
1092    A VS2008 project with most of the options defined was created through the
1093    VS2008 IDE.  It was then converted to VS2010.  The tool settings found in
1094    the .vcproj and .vcxproj files were converted to the two dictionaries
1095    msvs_settings and expected_msbuild_settings.
1096
1097    Note that for many settings, the VS2010 converter adds macros like
1098    %(AdditionalIncludeDirectories) to make sure than inherited values are
1099    included.  Since the Gyp projects we generate do not use inheritance,
1100    we removed these macros.  They were:
1101        ClCompile:
1102            AdditionalIncludeDirectories:  ';%(AdditionalIncludeDirectories)'
1103            AdditionalOptions:  ' %(AdditionalOptions)'
1104            AdditionalUsingDirectories:  ';%(AdditionalUsingDirectories)'
1105            DisableSpecificWarnings: ';%(DisableSpecificWarnings)',
1106            ForcedIncludeFiles:  ';%(ForcedIncludeFiles)',
1107            ForcedUsingFiles:  ';%(ForcedUsingFiles)',
1108            PreprocessorDefinitions:  ';%(PreprocessorDefinitions)',
1109            UndefinePreprocessorDefinitions:
1110                ';%(UndefinePreprocessorDefinitions)',
1111        Link:
1112            AdditionalDependencies:  ';%(AdditionalDependencies)',
1113            AdditionalLibraryDirectories:  ';%(AdditionalLibraryDirectories)',
1114            AdditionalManifestDependencies:
1115                ';%(AdditionalManifestDependencies)',
1116            AdditionalOptions:  ' %(AdditionalOptions)',
1117            AddModuleNamesToAssembly:  ';%(AddModuleNamesToAssembly)',
1118            AssemblyLinkResource:  ';%(AssemblyLinkResource)',
1119            DelayLoadDLLs:  ';%(DelayLoadDLLs)',
1120            EmbedManagedResourceFile:  ';%(EmbedManagedResourceFile)',
1121            ForceSymbolReferences:  ';%(ForceSymbolReferences)',
1122            IgnoreSpecificDefaultLibraries:
1123                ';%(IgnoreSpecificDefaultLibraries)',
1124        ResourceCompile:
1125            AdditionalIncludeDirectories:  ';%(AdditionalIncludeDirectories)',
1126            AdditionalOptions:  ' %(AdditionalOptions)',
1127            PreprocessorDefinitions:  ';%(PreprocessorDefinitions)',
1128        Manifest:
1129            AdditionalManifestFiles:  ';%(AdditionalManifestFiles)',
1130            AdditionalOptions:  ' %(AdditionalOptions)',
1131            InputResourceManifests:  ';%(InputResourceManifests)',
1132    """
1133    msvs_settings = {
1134        'VCCLCompilerTool': {
1135            'AdditionalIncludeDirectories': 'dir1',
1136            'AdditionalOptions': '/more',
1137            'AdditionalUsingDirectories': 'test',
1138            'AssemblerListingLocation': '$(IntDir)\\a',
1139            'AssemblerOutput': '1',
1140            'BasicRuntimeChecks': '3',
1141            'BrowseInformation': '1',
1142            'BrowseInformationFile': '$(IntDir)\\e',
1143            'BufferSecurityCheck': 'false',
1144            'CallingConvention': '1',
1145            'CompileAs': '1',
1146            'DebugInformationFormat': '4',
1147            'DefaultCharIsUnsigned': 'true',
1148            'Detect64BitPortabilityProblems': 'true',
1149            'DisableLanguageExtensions': 'true',
1150            'DisableSpecificWarnings': 'abc',
1151            'EnableEnhancedInstructionSet': '1',
1152            'EnableFiberSafeOptimizations': 'true',
1153            'EnableFunctionLevelLinking': 'true',
1154            'EnableIntrinsicFunctions': 'true',
1155            'EnablePREfast': 'true',
1156            'ErrorReporting': '2',
1157            'ExceptionHandling': '2',
1158            'ExpandAttributedSource': 'true',
1159            'FavorSizeOrSpeed': '2',
1160            'FloatingPointExceptions': 'true',
1161            'FloatingPointModel': '1',
1162            'ForceConformanceInForLoopScope': 'false',
1163            'ForcedIncludeFiles': 'def',
1164            'ForcedUsingFiles': 'ge',
1165            'GeneratePreprocessedFile': '2',
1166            'GenerateXMLDocumentationFiles': 'true',
1167            'IgnoreStandardIncludePath': 'true',
1168            'InlineFunctionExpansion': '1',
1169            'KeepComments': 'true',
1170            'MinimalRebuild': 'true',
1171            'ObjectFile': '$(IntDir)\\b',
1172            'OmitDefaultLibName': 'true',
1173            'OmitFramePointers': 'true',
1174            'OpenMP': 'true',
1175            'Optimization': '3',
1176            'PrecompiledHeaderFile': '$(IntDir)\\$(TargetName).pche',
1177            'PrecompiledHeaderThrough': 'StdAfx.hd',
1178            'PreprocessorDefinitions': 'WIN32;_DEBUG;_CONSOLE',
1179            'ProgramDataBaseFileName': '$(IntDir)\\vc90b.pdb',
1180            'RuntimeLibrary': '3',
1181            'RuntimeTypeInfo': 'false',
1182            'ShowIncludes': 'true',
1183            'SmallerTypeCheck': 'true',
1184            'StringPooling': 'true',
1185            'StructMemberAlignment': '3',
1186            'SuppressStartupBanner': 'false',
1187            'TreatWChar_tAsBuiltInType': 'false',
1188            'UndefineAllPreprocessorDefinitions': 'true',
1189            'UndefinePreprocessorDefinitions': 'wer',
1190            'UseFullPaths': 'true',
1191            'UsePrecompiledHeader': '0',
1192            'UseUnicodeResponseFiles': 'false',
1193            'WarnAsError': 'true',
1194            'WarningLevel': '3',
1195            'WholeProgramOptimization': 'true',
1196            'XMLDocumentationFileName': '$(IntDir)\\c'},
1197        'VCLinkerTool': {
1198            'AdditionalDependencies': 'zx',
1199            'AdditionalLibraryDirectories': 'asd',
1200            'AdditionalManifestDependencies': 's2',
1201            'AdditionalOptions': '/mor2',
1202            'AddModuleNamesToAssembly': 'd1',
1203            'AllowIsolation': 'false',
1204            'AssemblyDebug': '1',
1205            'AssemblyLinkResource': 'd5',
1206            'BaseAddress': '23423',
1207            'CLRImageType': '3',
1208            'CLRThreadAttribute': '1',
1209            'CLRUnmanagedCodeCheck': 'true',
1210            'DataExecutionPrevention': '0',
1211            'DelayLoadDLLs': 'd4',
1212            'DelaySign': 'true',
1213            'Driver': '2',
1214            'EmbedManagedResourceFile': 'd2',
1215            'EnableCOMDATFolding': '1',
1216            'EnableUAC': 'false',
1217            'EntryPointSymbol': 'f5',
1218            'ErrorReporting': '2',
1219            'FixedBaseAddress': '1',
1220            'ForceSymbolReferences': 'd3',
1221            'FunctionOrder': 'fssdfsd',
1222            'GenerateDebugInformation': 'true',
1223            'GenerateManifest': 'false',
1224            'GenerateMapFile': 'true',
1225            'HeapCommitSize': '13',
1226            'HeapReserveSize': '12',
1227            'IgnoreAllDefaultLibraries': 'true',
1228            'IgnoreDefaultLibraryNames': 'flob;flok',
1229            'IgnoreEmbeddedIDL': 'true',
1230            'IgnoreImportLibrary': 'true',
1231            'ImportLibrary': 'f4',
1232            'KeyContainer': 'f7',
1233            'KeyFile': 'f6',
1234            'LargeAddressAware': '2',
1235            'LinkIncremental': '0',
1236            'LinkLibraryDependencies': 'false',
1237            'LinkTimeCodeGeneration': '1',
1238            'ManifestFile':
1239            '$(IntDir)\\$(TargetFileName).2intermediate.manifest',
1240            'MapExports': 'true',
1241            'MapFileName': 'd5',
1242            'MergedIDLBaseFileName': 'f2',
1243            'MergeSections': 'f5',
1244            'MidlCommandFile': 'f1',
1245            'ModuleDefinitionFile': 'sdsd',
1246            'OptimizeForWindows98': '2',
1247            'OptimizeReferences': '2',
1248            'OutputFile': '$(OutDir)\\$(ProjectName)2.exe',
1249            'PerUserRedirection': 'true',
1250            'Profile': 'true',
1251            'ProfileGuidedDatabase': '$(TargetDir)$(TargetName).pgdd',
1252            'ProgramDatabaseFile': 'Flob.pdb',
1253            'RandomizedBaseAddress': '1',
1254            'RegisterOutput': 'true',
1255            'ResourceOnlyDLL': 'true',
1256            'SetChecksum': 'false',
1257            'ShowProgress': '1',
1258            'StackCommitSize': '15',
1259            'StackReserveSize': '14',
1260            'StripPrivateSymbols': 'd3',
1261            'SubSystem': '1',
1262            'SupportUnloadOfDelayLoadedDLL': 'true',
1263            'SuppressStartupBanner': 'false',
1264            'SwapRunFromCD': 'true',
1265            'SwapRunFromNet': 'true',
1266            'TargetMachine': '1',
1267            'TerminalServerAware': '1',
1268            'TurnOffAssemblyGeneration': 'true',
1269            'TypeLibraryFile': 'f3',
1270            'TypeLibraryResourceID': '12',
1271            'UACExecutionLevel': '2',
1272            'UACUIAccess': 'true',
1273            'UseLibraryDependencyInputs': 'true',
1274            'UseUnicodeResponseFiles': 'false',
1275            'Version': '333'},
1276        'VCResourceCompilerTool': {
1277            'AdditionalIncludeDirectories': 'f3',
1278            'AdditionalOptions': '/more3',
1279            'Culture': '3084',
1280            'IgnoreStandardIncludePath': 'true',
1281            'PreprocessorDefinitions': '_UNICODE;UNICODE2',
1282            'ResourceOutputFileName': '$(IntDir)/$(InputName)3.res',
1283            'ShowProgress': 'true'},
1284        'VCManifestTool': {
1285            'AdditionalManifestFiles': 'sfsdfsd',
1286            'AdditionalOptions': 'afdsdafsd',
1287            'AssemblyIdentity': 'sddfdsadfsa',
1288            'ComponentFileName': 'fsdfds',
1289            'DependencyInformationFile': '$(IntDir)\\mt.depdfd',
1290            'EmbedManifest': 'false',
1291            'GenerateCatalogFiles': 'true',
1292            'InputResourceManifests': 'asfsfdafs',
1293            'ManifestResourceFile':
1294            '$(IntDir)\\$(TargetFileName).embed.manifest.resfdsf',
1295            'OutputManifestFile': '$(TargetPath).manifestdfs',
1296            'RegistrarScriptFile': 'sdfsfd',
1297            'ReplacementsFile': 'sdffsd',
1298            'SuppressStartupBanner': 'false',
1299            'TypeLibraryFile': 'sfsd',
1300            'UpdateFileHashes': 'true',
1301            'UpdateFileHashesSearchPath': 'sfsd',
1302            'UseFAT32Workaround': 'true',
1303            'UseUnicodeResponseFiles': 'false',
1304            'VerboseOutput': 'true'}}
1305    expected_msbuild_settings = {
1306        'ClCompile': {
1307            'AdditionalIncludeDirectories': 'dir1',
1308            'AdditionalOptions': '/more /J',
1309            'AdditionalUsingDirectories': 'test',
1310            'AssemblerListingLocation': '$(IntDir)a',
1311            'AssemblerOutput': 'AssemblyCode',
1312            'BasicRuntimeChecks': 'EnableFastChecks',
1313            'BrowseInformation': 'true',
1314            'BrowseInformationFile': '$(IntDir)e',
1315            'BufferSecurityCheck': 'false',
1316            'CallingConvention': 'FastCall',
1317            'CompileAs': 'CompileAsC',
1318            'DebugInformationFormat': 'EditAndContinue',
1319            'DisableLanguageExtensions': 'true',
1320            'DisableSpecificWarnings': 'abc',
1321            'EnableEnhancedInstructionSet': 'StreamingSIMDExtensions',
1322            'EnableFiberSafeOptimizations': 'true',
1323            'EnablePREfast': 'true',
1324            'ErrorReporting': 'Queue',
1325            'ExceptionHandling': 'Async',
1326            'ExpandAttributedSource': 'true',
1327            'FavorSizeOrSpeed': 'Size',
1328            'FloatingPointExceptions': 'true',
1329            'FloatingPointModel': 'Strict',
1330            'ForceConformanceInForLoopScope': 'false',
1331            'ForcedIncludeFiles': 'def',
1332            'ForcedUsingFiles': 'ge',
1333            'FunctionLevelLinking': 'true',
1334            'GenerateXMLDocumentationFiles': 'true',
1335            'IgnoreStandardIncludePath': 'true',
1336            'InlineFunctionExpansion': 'OnlyExplicitInline',
1337            'IntrinsicFunctions': 'true',
1338            'MinimalRebuild': 'true',
1339            'ObjectFileName': '$(IntDir)b',
1340            'OmitDefaultLibName': 'true',
1341            'OmitFramePointers': 'true',
1342            'OpenMPSupport': 'true',
1343            'Optimization': 'Full',
1344            'PrecompiledHeader': 'NotUsing',  # Actual conversion gives ''
1345            'PrecompiledHeaderFile': 'StdAfx.hd',
1346            'PrecompiledHeaderOutputFile': '$(IntDir)$(TargetName).pche',
1347            'PreprocessKeepComments': 'true',
1348            'PreprocessorDefinitions': 'WIN32;_DEBUG;_CONSOLE',
1349            'PreprocessSuppressLineNumbers': 'true',
1350            'PreprocessToFile': 'true',
1351            'ProgramDataBaseFileName': '$(IntDir)vc90b.pdb',
1352            'RuntimeLibrary': 'MultiThreadedDebugDLL',
1353            'RuntimeTypeInfo': 'false',
1354            'ShowIncludes': 'true',
1355            'SmallerTypeCheck': 'true',
1356            'StringPooling': 'true',
1357            'StructMemberAlignment': '4Bytes',
1358            'SuppressStartupBanner': 'false',
1359            'TreatWarningAsError': 'true',
1360            'TreatWChar_tAsBuiltInType': 'false',
1361            'UndefineAllPreprocessorDefinitions': 'true',
1362            'UndefinePreprocessorDefinitions': 'wer',
1363            'UseFullPaths': 'true',
1364            'WarningLevel': 'Level3',
1365            'WholeProgramOptimization': 'true',
1366            'XMLDocumentationFileName': '$(IntDir)c'},
1367        'Link': {
1368            'AdditionalDependencies': 'zx',
1369            'AdditionalLibraryDirectories': 'asd',
1370            'AdditionalManifestDependencies': 's2',
1371            'AdditionalOptions': '/mor2',
1372            'AddModuleNamesToAssembly': 'd1',
1373            'AllowIsolation': 'false',
1374            'AssemblyDebug': 'true',
1375            'AssemblyLinkResource': 'd5',
1376            'BaseAddress': '23423',
1377            'CLRImageType': 'ForceSafeILImage',
1378            'CLRThreadAttribute': 'MTAThreadingAttribute',
1379            'CLRUnmanagedCodeCheck': 'true',
1380            'DataExecutionPrevention': '',
1381            'DelayLoadDLLs': 'd4',
1382            'DelaySign': 'true',
1383            'Driver': 'UpOnly',
1384            'EmbedManagedResourceFile': 'd2',
1385            'EnableCOMDATFolding': 'false',
1386            'EnableUAC': 'false',
1387            'EntryPointSymbol': 'f5',
1388            'FixedBaseAddress': 'false',
1389            'ForceSymbolReferences': 'd3',
1390            'FunctionOrder': 'fssdfsd',
1391            'GenerateDebugInformation': 'true',
1392            'GenerateMapFile': 'true',
1393            'HeapCommitSize': '13',
1394            'HeapReserveSize': '12',
1395            'IgnoreAllDefaultLibraries': 'true',
1396            'IgnoreEmbeddedIDL': 'true',
1397            'IgnoreSpecificDefaultLibraries': 'flob;flok',
1398            'ImportLibrary': 'f4',
1399            'KeyContainer': 'f7',
1400            'KeyFile': 'f6',
1401            'LargeAddressAware': 'true',
1402            'LinkErrorReporting': 'QueueForNextLogin',
1403            'LinkTimeCodeGeneration': 'UseLinkTimeCodeGeneration',
1404            'ManifestFile': '$(IntDir)$(TargetFileName).2intermediate.manifest',
1405            'MapExports': 'true',
1406            'MapFileName': 'd5',
1407            'MergedIDLBaseFileName': 'f2',
1408            'MergeSections': 'f5',
1409            'MidlCommandFile': 'f1',
1410            'ModuleDefinitionFile': 'sdsd',
1411            'NoEntryPoint': 'true',
1412            'OptimizeReferences': 'true',
1413            'OutputFile': '$(OutDir)$(ProjectName)2.exe',
1414            'PerUserRedirection': 'true',
1415            'Profile': 'true',
1416            'ProfileGuidedDatabase': '$(TargetDir)$(TargetName).pgdd',
1417            'ProgramDatabaseFile': 'Flob.pdb',
1418            'RandomizedBaseAddress': 'false',
1419            'RegisterOutput': 'true',
1420            'SetChecksum': 'false',
1421            'ShowProgress': 'LinkVerbose',
1422            'StackCommitSize': '15',
1423            'StackReserveSize': '14',
1424            'StripPrivateSymbols': 'd3',
1425            'SubSystem': 'Console',
1426            'SupportUnloadOfDelayLoadedDLL': 'true',
1427            'SuppressStartupBanner': 'false',
1428            'SwapRunFromCD': 'true',
1429            'SwapRunFromNET': 'true',
1430            'TargetMachine': 'MachineX86',
1431            'TerminalServerAware': 'false',
1432            'TurnOffAssemblyGeneration': 'true',
1433            'TypeLibraryFile': 'f3',
1434            'TypeLibraryResourceID': '12',
1435            'UACExecutionLevel': 'RequireAdministrator',
1436            'UACUIAccess': 'true',
1437            'Version': '333'},
1438        'ResourceCompile': {
1439            'AdditionalIncludeDirectories': 'f3',
1440            'AdditionalOptions': '/more3',
1441            'Culture': '0x0c0c',
1442            'IgnoreStandardIncludePath': 'true',
1443            'PreprocessorDefinitions': '_UNICODE;UNICODE2',
1444            'ResourceOutputFileName': '$(IntDir)%(Filename)3.res',
1445            'ShowProgress': 'true'},
1446        'Manifest': {
1447            'AdditionalManifestFiles': 'sfsdfsd',
1448            'AdditionalOptions': 'afdsdafsd',
1449            'AssemblyIdentity': 'sddfdsadfsa',
1450            'ComponentFileName': 'fsdfds',
1451            'GenerateCatalogFiles': 'true',
1452            'InputResourceManifests': 'asfsfdafs',
1453            'OutputManifestFile': '$(TargetPath).manifestdfs',
1454            'RegistrarScriptFile': 'sdfsfd',
1455            'ReplacementsFile': 'sdffsd',
1456            'SuppressStartupBanner': 'false',
1457            'TypeLibraryFile': 'sfsd',
1458            'UpdateFileHashes': 'true',
1459            'UpdateFileHashesSearchPath': 'sfsd',
1460            'VerboseOutput': 'true'},
1461        'ProjectReference': {
1462            'LinkLibraryDependencies': 'false',
1463            'UseLibraryDependencyInputs': 'true'},
1464        '': {
1465            'EmbedManifest': 'false',
1466            'GenerateManifest': 'false',
1467            'IgnoreImportLibrary': 'true',
1468            'LinkIncremental': ''
1469            },
1470        'ManifestResourceCompile': {
1471            'ResourceOutputFileName':
1472            '$(IntDir)$(TargetFileName).embed.manifest.resfdsf'}
1473        }
1474    actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
1475        msvs_settings,
1476        self.stderr)
1477    self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
1478    self._ExpectedWarnings([])
1479
1480
1481if __name__ == '__main__':
1482  unittest.main()
1483