OLD | NEW |
(Empty) | |
| 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 Verifies that the 'Profile' attribute in VCLinker is extracted properly. |
| 9 """ |
| 10 |
| 11 import TestGyp |
| 12 |
| 13 import os |
| 14 import re |
| 15 import sys |
| 16 |
| 17 |
| 18 def GetLdFlags(target): |
| 19 """GetLdFlags returns the value of ldflags from the specified .ninja file |
| 20 |
| 21 Load the ninja file find the 'ldflags' key. Then concats lines when the |
| 22 preceeding one ended with '$'.""" |
| 23 |
| 24 paths = ['linker-flags', 'out', 'Default','obj'] |
| 25 file_path = test.workpath(*paths + [target]) |
| 26 |
| 27 try: |
| 28 lines = open(file_path, 'r').readlines() |
| 29 |
| 30 except IOError, err: |
| 31 print 'Failed to open %s with %s.' % (file_path, err) |
| 32 return None |
| 33 |
| 34 ldflags = None |
| 35 appending = False |
| 36 for line in lines: |
| 37 if line[:9] == 'ldflags =': |
| 38 appending = True |
| 39 line = line[10:] |
| 40 ldflags = '' |
| 41 if appending: |
| 42 line = line.strip() |
| 43 if line[-1] == '$': |
| 44 ldflags += line[:-1] |
| 45 else: |
| 46 ldflags += line |
| 47 break |
| 48 return ldflags |
| 49 |
| 50 |
| 51 def GetLdSwitch(target, arg): |
| 52 """GetLdSwitch extract the uses of <arg> from ldflags.""" |
| 53 |
| 54 ldflags = GetLdFlags(target) |
| 55 parser = re.compile('(%s((:\\S*)|(=\\S*))?)' % arg) |
| 56 itr = parser.finditer(ldflags) |
| 57 return [i.group(0) for i in itr] |
| 58 |
| 59 |
| 60 def VerifyLdSwitch(target, arg, val): |
| 61 """VerifyLdSwitch of <arg> exactly matches <val>""" |
| 62 |
| 63 found = GetLdSwitch(target, arg) |
| 64 if val == found: |
| 65 return True |
| 66 |
| 67 print 'Target %s expected %s got %s' % (target, val, found) |
| 68 return False |
| 69 |
| 70 |
| 71 if sys.platform == 'win32': |
| 72 test = TestGyp.TestGyp(formats=['ninja']) |
| 73 CHDIR = 'linker-flags' |
| 74 test.run_gyp('profile.gyp', chdir=CHDIR) |
| 75 test.build('profile.gyp', test.ALL, chdir=CHDIR) |
| 76 |
| 77 # Verify it's turned on once when enabled in an EXE |
| 78 if not VerifyLdSwitch('test_ninja_profile_true.ninja', |
| 79 '/PROFILE', ['/PROFILE']): |
| 80 test.fail_test() |
| 81 |
| 82 # Verify it's turned on once when enabled in an DLL |
| 83 if not VerifyLdSwitch('test_ninja_profile_dll_true.ninja', |
| 84 '/PROFILE', ['/PROFILE']): |
| 85 test.fail_test() |
| 86 |
| 87 # Verify it's not used by default in an EXE |
| 88 if not VerifyLdSwitch('test_ninja_profile_no.ninja', '/PROFILE', []): |
| 89 test.fail_test() |
| 90 |
| 91 # Verify it's not used when disabled in a DLL |
| 92 if not VerifyLdSwitch('test_ninja_profile_dll_false.ninja', |
| 93 '/PROFILE', []): |
| 94 test.fail_test() |
| 95 test.pass_test() |
OLD | NEW |