1 #!/usr/bin/env python 2 3 # Copyright (c) 2013 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 """ 8 Make sure a relink is performed when a .def file is touched. 9 """ 10 11 import TestGyp 12 13 import sys 14 15 if sys.platform == 'win32': 16 test = TestGyp.TestGyp(formats=['msvs', 'ninja']) 17 18 CHDIR = 'linker-flags' 19 target = 'test_deffile_dll_ok' 20 def_contents = test.read('linker-flags/deffile.def') 21 22 # This first build makes sure everything is up to date. 23 test.run_gyp('deffile.gyp', chdir=CHDIR) 24 test.build('deffile.gyp', target, chdir=CHDIR) 25 test.up_to_date('deffile.gyp', target, chdir=CHDIR) 26 27 def HasExport(binary, export): 28 full_path = test.built_file_path(binary, chdir=CHDIR) 29 output = test.run_dumpbin('/exports', full_path) 30 return export in output 31 32 # Verify that only one function is exported. 33 if not HasExport('test_deffile_dll_ok.dll', 'AnExportedFunction'): 34 test.fail_test() 35 if HasExport('test_deffile_dll_ok.dll', 'AnotherExportedFunction'): 36 test.fail_test() 37 38 # Add AnotherExportedFunction to the def file, then rebuild. If it doesn't 39 # relink the DLL, then the subsequent check for AnotherExportedFunction will 40 # fail. 41 new_def_contents = def_contents + "\n AnotherExportedFunction" 42 test.write('linker-flags/deffile.def', new_def_contents) 43 test.build('deffile.gyp', target, chdir=CHDIR) 44 test.up_to_date('deffile.gyp', target, chdir=CHDIR) 45 46 if not HasExport('test_deffile_dll_ok.dll', 'AnExportedFunction'): 47 test.fail_test() 48 if not HasExport('test_deffile_dll_ok.dll', 'AnotherExportedFunction'): 49 test.fail_test() 50 51 test.pass_test() 52