Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a9efb6fd
Commit
a9efb6fd
authored
Oct 17, 2011
by
Mark Hammond
Browse files
Options
Browse Files
Download
Plain Diff
Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
parents
bf65c746
6c58b28f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
23 deletions
+106
-23
Lib/distutils/msvc9compiler.py
Lib/distutils/msvc9compiler.py
+57
-21
Lib/distutils/tests/test_msvc9compiler.py
Lib/distutils/tests/test_msvc9compiler.py
+45
-2
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Lib/distutils/msvc9compiler.py
View file @
a9efb6fd
...
...
@@ -627,15 +627,7 @@ class MSVCCompiler(CCompiler) :
self
.
library_filename
(
dll_name
))
ld_args
.
append
(
'/IMPLIB:'
+
implib_file
)
# Embedded manifests are recommended - see MSDN article titled
# "How to: Embed a Manifest Inside a C/C++ Application"
# (currently at http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx)
# Ask the linker to generate the manifest in the temp dir, so
# we can embed it later.
temp_manifest
=
os
.
path
.
join
(
build_temp
,
os
.
path
.
basename
(
output_filename
)
+
".manifest"
)
ld_args
.
append
(
'/MANIFESTFILE:'
+
temp_manifest
)
self
.
manifest_setup_ldargs
(
output_filename
,
build_temp
,
ld_args
)
if
extra_preargs
:
ld_args
[:
0
]
=
extra_preargs
...
...
@@ -653,21 +645,54 @@ class MSVCCompiler(CCompiler) :
# will still consider the DLL up-to-date, but it will not have a
# manifest. Maybe we should link to a temp file? OTOH, that
# implies a build environment error that shouldn't go undetected.
if
target_desc
==
CCompiler
.
EXECUTABLE
:
mfid
=
1
else
:
mfid
=
2
# Remove references to the Visual C runtime
self
.
_remove_visual_c_ref
(
temp_manifest
)
mfinfo
=
self
.
manifest_get_embed_info
(
target_desc
,
ld_args
)
if
mfinfo
is
not
None
:
mffilename
,
mfid
=
mfinfo
out_arg
=
'-outputresource:%s;%s'
%
(
output_filename
,
mfid
)
try
:
self
.
spawn
([
'mt.exe'
,
'-nologo'
,
'-manifest'
,
temp_manifest
,
out_arg
])
mffilename
,
out_arg
])
except
DistutilsExecError
as
msg
:
raise
LinkError
(
msg
)
else
:
log
.
debug
(
"skipping %s (up-to-date)"
,
output_filename
)
def
manifest_setup_ldargs
(
self
,
output_filename
,
build_temp
,
ld_args
):
# If we need a manifest at all, an embedded manifest is recommended.
# See MSDN article titled
# "How to: Embed a Manifest Inside a C/C++ Application"
# (currently at http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx)
# Ask the linker to generate the manifest in the temp dir, so
# we can check it, and possibly embed it, later.
temp_manifest
=
os
.
path
.
join
(
build_temp
,
os
.
path
.
basename
(
output_filename
)
+
".manifest"
)
ld_args
.
append
(
'/MANIFESTFILE:'
+
temp_manifest
)
def
manifest_get_embed_info
(
self
,
target_desc
,
ld_args
):
# If a manifest should be embedded, return a tuple of
# (manifest_filename, resource_id). Returns None if no manifest
# should be embedded. See http://bugs.python.org/issue7833 for why
# we want to avoid any manifest for extension modules if we can)
for
arg
in
ld_args
:
if
arg
.
startswith
(
"/MANIFESTFILE:"
):
temp_manifest
=
arg
.
split
(
":"
,
1
)[
1
]
break
else
:
# no /MANIFESTFILE so nothing to do.
return
None
if
target_desc
==
CCompiler
.
EXECUTABLE
:
# by default, executables always get the manifest with the
# CRT referenced.
mfid
=
1
else
:
# Extension modules try and avoid any manifest if possible.
mfid
=
2
temp_manifest
=
self
.
_remove_visual_c_ref
(
temp_manifest
)
if
temp_manifest
is
None
:
return
None
return
temp_manifest
,
mfid
def
_remove_visual_c_ref
(
self
,
manifest_file
):
try
:
# Remove references to the Visual C runtime, so they will
...
...
@@ -676,6 +701,8 @@ class MSVCCompiler(CCompiler) :
# runtimes are not in WinSxS folder, but in Python's own
# folder), the runtimes do not need to be in every folder
# with .pyd's.
# Returns either the filename of the modified manifest or
# None if no manifest should be embedded.
manifest_f
=
open
(
manifest_file
)
try
:
manifest_buf
=
manifest_f
.
read
()
...
...
@@ -688,9 +715,18 @@ class MSVCCompiler(CCompiler) :
manifest_buf = re.sub(pattern, "", manifest_buf)
pattern = "
<
dependentAssembly
>
\
s
*</
dependentAssembly
>
"
manifest_buf = re.sub(pattern, "", manifest_buf)
# Now see if any other assemblies are referenced - if not, we
# don't want a manifest embedded.
pattern = re.compile(
r"""<assemblyIdentity.*?name=(?:"
|
')(.+?)(?:"|'
)
"""
r"""
.
*
?
(
?
:
/>|</
assemblyIdentity
>
)
""", re.DOTALL)
if re.search(pattern, manifest_buf) is None:
return None
manifest_f = open(manifest_file, 'w')
try:
manifest_f.write(manifest_buf)
return manifest_file
finally:
manifest_f.close()
except IOError:
...
...
Lib/distutils/tests/test_msvc9compiler.py
View file @
a9efb6fd
...
...
@@ -7,7 +7,36 @@ from distutils.errors import DistutilsPlatformError
from
distutils.tests
import
support
from
test.support
import
run_unittest
_MANIFEST
=
"""
\
# A manifest with the only assembly reference being the msvcrt assembly, so
# should have the assembly completely stripped. Note that although the
# assembly has a <security> reference the assembly is removed - that is
# currently a "feature", not a bug :)
_MANIFEST_WITH_ONLY_MSVC_REFERENCE
=
"""
\
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false">
</requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
version="9.0.21022.8" processorArchitecture="x86"
publicKeyToken="XXXX">
</assemblyIdentity>
</dependentAssembly>
</dependency>
</assembly>
"""
# A manifest with references to assemblies other than msvcrt. When processed,
# this assembly should be returned with just the msvcrt part removed.
_MANIFEST_WITH_MULTIPLE_REFERENCES
=
"""
\
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
...
...
@@ -115,7 +144,7 @@ class msvc9compilerTestCase(support.TempdirManager,
manifest
=
os
.
path
.
join
(
tempdir
,
'manifest'
)
f
=
open
(
manifest
,
'w'
)
try
:
f
.
write
(
_MANIFEST
)
f
.
write
(
_MANIFEST
_WITH_MULTIPLE_REFERENCES
)
finally
:
f
.
close
()
...
...
@@ -133,6 +162,20 @@ class msvc9compilerTestCase(support.TempdirManager,
# makes sure the manifest was properly cleaned
self
.
assertEqual
(
content
,
_CLEANED_MANIFEST
)
def
test_remove_entire_manifest
(
self
):
from
distutils.msvc9compiler
import
MSVCCompiler
tempdir
=
self
.
mkdtemp
()
manifest
=
os
.
path
.
join
(
tempdir
,
'manifest'
)
f
=
open
(
manifest
,
'w'
)
try
:
f
.
write
(
_MANIFEST_WITH_ONLY_MSVC_REFERENCE
)
finally
:
f
.
close
()
compiler
=
MSVCCompiler
()
got
=
compiler
.
_remove_visual_c_ref
(
manifest
)
self
.
assertIs
(
got
,
None
)
def
test_suite
():
return
unittest
.
makeSuite
(
msvc9compilerTestCase
)
...
...
Misc/NEWS
View file @
a9efb6fd
...
...
@@ -10,6 +10,10 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
- Issue #7833: Extension modules built using distutils on Windows will no
longer include a "manifest" to prevent them failing at import time in some
embedded situations.
- PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
- Add internal API for static strings (_Py_identifier et al.).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment