Home | History | Annotate | Download | only in win
      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 """
      8 Make sure function-level linking setting is extracted properly.
      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 = 'compiler-flags'
     19   test.run_gyp('function-level-linking.gyp', chdir=CHDIR)
     20   test.build('function-level-linking.gyp', test.ALL, chdir=CHDIR)
     21 
     22   def CheckForSectionString(binary, search_for, should_exist):
     23     output = test.run_dumpbin('/headers', binary)
     24     if should_exist and search_for not in output:
     25       print 'Did not find "%s" in %s' % (search_for, binary)
     26       test.fail_test()
     27     elif not should_exist and search_for in output:
     28       print 'Found "%s" in %s (and shouldn\'t have)' % (search_for, binary)
     29       test.fail_test()
     30 
     31   def Object(proj, obj):
     32     sep = '.' if test.format == 'ninja' else '\\'
     33     return 'obj\\%s%s%s' % (proj, sep, obj)
     34 
     35   look_for = '''COMDAT; sym= "int __cdecl comdat_function'''
     36 
     37   # When function level linking is on, the functions should be listed as
     38   # separate comdat entries.
     39 
     40   CheckForSectionString(
     41       test.built_file_path(Object('test_fll_on', 'function-level-linking.obj'),
     42                            chdir=CHDIR),
     43       look_for,
     44       should_exist=True)
     45 
     46   CheckForSectionString(
     47       test.built_file_path(Object('test_fll_off', 'function-level-linking.obj'),
     48                            chdir=CHDIR),
     49       look_for,
     50       should_exist=False)
     51 
     52   test.pass_test()
     53