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