OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012 Google Inc. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """ | 7 """ |
8 Make sure we generate a manifest file when linking binaries, including | 8 Make sure we generate a manifest file when linking binaries, including |
9 handling AdditionalManifestFiles. | 9 handling AdditionalManifestFiles. |
10 """ | 10 """ |
11 | 11 |
12 import TestGyp | 12 import TestGyp |
13 | 13 |
14 import sys | 14 import sys |
15 | 15 |
16 if sys.platform == 'win32': | 16 if sys.platform == 'win32': |
| 17 import pywintypes |
| 18 import win32api |
| 19 import winerror |
| 20 |
| 21 RT_MANIFEST = 24 |
| 22 |
| 23 class LoadLibrary(object): |
| 24 """Context manager for loading and releasing binaries in Windows. |
| 25 Yields the handle of the binary loaded.""" |
| 26 def __init__(self, path): |
| 27 self._path = path |
| 28 self._handle = None |
| 29 |
| 30 def __enter__(self): |
| 31 self._handle = win32api.LoadLibrary(self._path) |
| 32 return self._handle |
| 33 |
| 34 def __exit__(self, type, value, traceback): |
| 35 win32api.FreeLibrary(self._handle) |
| 36 |
| 37 def extract_manifest(path, resource_name): |
| 38 """Reads manifest from |path| and returns it as a string. |
| 39 Returns None is there is no such manifest.""" |
| 40 with LoadLibrary(path) as handle: |
| 41 try: |
| 42 return win32api.LoadResource(handle, RT_MANIFEST, resource_name) |
| 43 except pywintypes.error as error: |
| 44 if error.args[0] == winerror.ERROR_RESOURCE_DATA_NOT_FOUND: |
| 45 return None |
| 46 else: |
| 47 raise |
| 48 |
17 test = TestGyp.TestGyp(formats=['msvs', 'ninja']) | 49 test = TestGyp.TestGyp(formats=['msvs', 'ninja']) |
18 | 50 |
19 CHDIR = 'linker-flags' | 51 CHDIR = 'linker-flags' |
20 test.run_gyp('generate-manifest.gyp', chdir=CHDIR) | 52 test.run_gyp('generate-manifest.gyp', chdir=CHDIR) |
21 test.build('generate-manifest.gyp', test.ALL, chdir=CHDIR) | 53 test.build('generate-manifest.gyp', test.ALL, chdir=CHDIR) |
22 test.built_file_must_exist('test_manifest_exe.exe.manifest', chdir=CHDIR) | |
23 test.built_file_must_exist('test_manifest_dll.dll.manifest', chdir=CHDIR) | |
24 | 54 |
25 # Must contain the Win7 support GUID, but not the Vista one (from | 55 def test_manifest(filename, generate_manifest, embedded_manifest, |
26 # extra2.manifest). | 56 extra_manifest): |
27 extra1_manifest = test.built_file_path( | 57 exe_file = test.built_file_path(filename, chdir=CHDIR) |
28 'test_manifest_extra1.exe.manifest', chdir=CHDIR) | 58 if not generate_manifest: |
29 test.must_contain(extra1_manifest, '35138b9a-5d96-4fbd-8e2d-a2440225f93a') | 59 test.must_not_exist(exe_file + '.manifest') |
30 test.must_not_contain(extra1_manifest, 'e2011457-1546-43c5-a5fe-008deee3d3f0') | 60 manifest = extract_manifest(exe_file, 1) |
| 61 test.fail_test(manifest) |
| 62 return |
| 63 if embedded_manifest: |
| 64 manifest = extract_manifest(exe_file, 1) |
| 65 test.fail_test(not manifest) |
| 66 else: |
| 67 test.must_exist(exe_file + '.manifest') |
| 68 manifest = test.read(exe_file + '.manifest') |
| 69 test.fail_test(not manifest) |
| 70 test.fail_test(extract_manifest(exe_file, 1)) |
| 71 if generate_manifest: |
| 72 test.must_contain_any_line(manifest, 'requestedExecutionLevel') |
| 73 if extra_manifest: |
| 74 test.must_contain_any_line(manifest, |
| 75 '35138b9a-5d96-4fbd-8e2d-a2440225f93a') |
| 76 test.must_contain_any_line(manifest, |
| 77 'e2011457-1546-43c5-a5fe-008deee3d3f0') |
31 | 78 |
32 # Must contain both. | 79 test_manifest('test_generate_manifest_true.exe', |
33 extra2_manifest = test.built_file_path( | 80 generate_manifest=True, |
34 'test_manifest_extra2.exe.manifest', chdir=CHDIR) | 81 embedded_manifest=False, |
35 test.must_contain(extra2_manifest, '35138b9a-5d96-4fbd-8e2d-a2440225f93a') | 82 extra_manifest=False) |
36 test.must_contain(extra2_manifest, 'e2011457-1546-43c5-a5fe-008deee3d3f0') | 83 test_manifest('test_generate_manifest_false.exe', |
37 | 84 generate_manifest=False, |
38 # Same as extra2, but using list syntax instead. | 85 embedded_manifest=False, |
39 extra_list_manifest = test.built_file_path( | 86 extra_manifest=False) |
40 'test_manifest_extra_list.exe.manifest', chdir=CHDIR) | 87 test_manifest('test_generate_manifest_default.exe', |
41 test.must_contain(extra_list_manifest, '35138b9a-5d96-4fbd-8e2d-a2440225f93a') | 88 generate_manifest=True, |
42 test.must_contain(extra_list_manifest, 'e2011457-1546-43c5-a5fe-008deee3d3f0') | 89 embedded_manifest=False, |
43 | 90 extra_manifest=False) |
| 91 test_manifest('test_generate_manifest_true_as_embedded.exe', |
| 92 generate_manifest=True, |
| 93 embedded_manifest=True, |
| 94 extra_manifest=False) |
| 95 test_manifest('test_generate_manifest_false_as_embedded.exe', |
| 96 generate_manifest=False, |
| 97 embedded_manifest=True, |
| 98 extra_manifest=False) |
| 99 test_manifest('test_generate_manifest_default_as_embedded.exe', |
| 100 generate_manifest=True, |
| 101 embedded_manifest=True, |
| 102 extra_manifest=False) |
| 103 test_manifest('test_generate_manifest_true_with_extra_manifest.exe', |
| 104 generate_manifest=True, |
| 105 embedded_manifest=False, |
| 106 extra_manifest=True) |
| 107 test_manifest('test_generate_manifest_false_with_extra_manifest.exe', |
| 108 generate_manifest=False, |
| 109 embedded_manifest=False, |
| 110 extra_manifest=True) |
| 111 test_manifest('test_generate_manifest_true_with_extra_manifest_list.exe', |
| 112 generate_manifest=True, |
| 113 embedded_manifest=False, |
| 114 extra_manifest=True) |
| 115 test_manifest('test_generate_manifest_false_with_extra_manifest_list.exe', |
| 116 generate_manifest=False, |
| 117 embedded_manifest=False, |
| 118 extra_manifest=True) |
44 test.pass_test() | 119 test.pass_test() |
OLD | NEW |