Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
870adffd
Commit
870adffd
authored
May 12, 2009
by
Tarek Ziadé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed #5977: distutils build_ext.get_outputs was not using the inplace option
parent
cb0eb9b3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
45 deletions
+85
-45
command/build_ext.py
command/build_ext.py
+45
-42
tests/test_build_ext.py
tests/test_build_ext.py
+40
-3
No files found.
command/build_ext.py
View file @
870adffd
...
...
@@ -311,38 +311,38 @@ class build_ext (Command):
# Setup the CCompiler object that we'll use to do all the
# compiling and linking
self
.
compiler
=
new_compiler
(
compiler
=
self
.
compiler
,
self
.
_
compiler
=
new_compiler
(
compiler
=
self
.
compiler
,
verbose
=
self
.
verbose
,
dry_run
=
self
.
dry_run
,
force
=
self
.
force
)
customize_compiler
(
self
.
compiler
)
customize_compiler
(
self
.
_
compiler
)
# If we are cross-compiling, init the compiler now (if we are not
# cross-compiling, init would not hurt, but people may rely on
# late initialization of compiler even if they shouldn't...)
if
os
.
name
==
'nt'
and
self
.
plat_name
!=
get_platform
():
self
.
compiler
.
initialize
(
self
.
plat_name
)
self
.
_
compiler
.
initialize
(
self
.
plat_name
)
# And make sure that any compile/link-related options (which might
# come from the command-line or from the setup script) are set in
# that CCompiler object -- that way, they automatically apply to
# all compiling and linking done here.
if
self
.
include_dirs
is
not
None
:
self
.
compiler
.
set_include_dirs
(
self
.
include_dirs
)
self
.
_
compiler
.
set_include_dirs
(
self
.
include_dirs
)
if
self
.
define
is
not
None
:
# 'define' option is a list of (name,value) tuples
for
(
name
,
value
)
in
self
.
define
:
self
.
compiler
.
define_macro
(
name
,
value
)
self
.
_
compiler
.
define_macro
(
name
,
value
)
if
self
.
undef
is
not
None
:
for
macro
in
self
.
undef
:
self
.
compiler
.
undefine_macro
(
macro
)
self
.
_
compiler
.
undefine_macro
(
macro
)
if
self
.
libraries
is
not
None
:
self
.
compiler
.
set_libraries
(
self
.
libraries
)
self
.
_
compiler
.
set_libraries
(
self
.
libraries
)
if
self
.
library_dirs
is
not
None
:
self
.
compiler
.
set_library_dirs
(
self
.
library_dirs
)
self
.
_
compiler
.
set_library_dirs
(
self
.
library_dirs
)
if
self
.
rpath
is
not
None
:
self
.
compiler
.
set_runtime_library_dirs
(
self
.
rpath
)
self
.
_
compiler
.
set_runtime_library_dirs
(
self
.
rpath
)
if
self
.
link_objects
is
not
None
:
self
.
compiler
.
set_link_objects
(
self
.
link_objects
)
self
.
_
compiler
.
set_link_objects
(
self
.
link_objects
)
# Now actually compile and link everything.
self
.
build_extensions
()
...
...
@@ -446,9 +446,7 @@ class build_ext (Command):
# "build" tree.
outputs
=
[]
for
ext
in
self
.
extensions
:
fullname
=
self
.
get_ext_fullname
(
ext
.
name
)
outputs
.
append
(
os
.
path
.
join
(
self
.
build_lib
,
self
.
get_ext_filename
(
fullname
)))
outputs
.
append
(
self
.
get_ext_fullpath
(
ext
.
name
))
return
outputs
def
build_extensions
(
self
):
...
...
@@ -473,24 +471,9 @@ class build_ext (Command):
"a list of source filenames"
)
%
ext
.
name
sources
=
list
(
sources
)
fullname
=
self
.
get_ext_fullname
(
ext
.
name
)
if
self
.
inplace
:
# ignore build-lib -- put the compiled extension into
# the source tree along with pure Python modules
modpath
=
string
.
split
(
fullname
,
'.'
)
package
=
string
.
join
(
modpath
[
0
:
-
1
],
'.'
)
base
=
modpath
[
-
1
]
build_py
=
self
.
get_finalized_command
(
'build_py'
)
package_dir
=
build_py
.
get_package_dir
(
package
)
ext_filename
=
os
.
path
.
join
(
package_dir
,
self
.
get_ext_filename
(
base
))
else
:
ext_filename
=
os
.
path
.
join
(
self
.
build_lib
,
self
.
get_ext_filename
(
fullname
))
ext_path
=
self
.
get_ext_fullpath
(
ext
.
name
)
depends
=
sources
+
ext
.
depends
if
not
(
self
.
force
or
newer_group
(
depends
,
ext_
filename
,
'newer'
)):
if
not
(
self
.
force
or
newer_group
(
depends
,
ext_
path
,
'newer'
)):
log
.
debug
(
"skipping '%s' extension (up-to-date)"
,
ext
.
name
)
return
else
:
...
...
@@ -521,13 +504,13 @@ class build_ext (Command):
for
undef
in
ext
.
undef_macros
:
macros
.
append
((
undef
,))
objects
=
self
.
compiler
.
compile
(
sources
,
output_dir
=
self
.
build_temp
,
macros
=
macros
,
include_dirs
=
ext
.
include_dirs
,
debug
=
self
.
debug
,
extra_postargs
=
extra_args
,
depends
=
ext
.
depends
)
objects
=
self
.
_
compiler
.
compile
(
sources
,
output_dir
=
self
.
build_temp
,
macros
=
macros
,
include_dirs
=
ext
.
include_dirs
,
debug
=
self
.
debug
,
extra_postargs
=
extra_args
,
depends
=
ext
.
depends
)
# XXX -- this is a Vile HACK!
#
...
...
@@ -548,10 +531,10 @@ class build_ext (Command):
extra_args
=
ext
.
extra_link_args
or
[]
# Detect target language, if not provided
language
=
ext
.
language
or
self
.
compiler
.
detect_language
(
sources
)
language
=
ext
.
language
or
self
.
_
compiler
.
detect_language
(
sources
)
self
.
compiler
.
link_shared_object
(
objects
,
ext_
filename
,
self
.
_
compiler
.
link_shared_object
(
objects
,
ext_
path
,
libraries
=
self
.
get_libraries
(
ext
),
library_dirs
=
ext
.
library_dirs
,
runtime_library_dirs
=
ext
.
runtime_library_dirs
,
...
...
@@ -653,8 +636,28 @@ class build_ext (Command):
# -- Name generators -----------------------------------------------
# (extension names, filenames, whatever)
def
get_ext_fullpath
(
self
,
ext_name
):
"""Returns the path of the filename for a given extension.
The file is located in `build_lib` or directly in the package
(inplace option).
"""
if
self
.
inplace
:
fullname
=
self
.
get_ext_fullname
(
ext_name
)
modpath
=
fullname
.
split
(
'.'
)
package
=
'.'
.
join
(
modpath
[
0
:
-
1
])
base
=
modpath
[
-
1
]
build_py
=
self
.
get_finalized_command
(
'build_py'
)
package_dir
=
os
.
path
.
abspath
(
build_py
.
get_package_dir
(
package
))
return
os
.
path
.
join
(
package_dir
,
base
)
else
:
filename
=
self
.
get_ext_filename
(
ext_name
)
return
os
.
path
.
join
(
self
.
build_lib
,
filename
)
def
get_ext_fullname
(
self
,
ext_name
):
"""Returns the fullname of a given extension name.
def
get_ext_fullname
(
self
,
ext_name
):
Adds the `package.` prefix"""
if
self
.
package
is
None
:
return
ext_name
else
:
...
...
@@ -701,7 +704,7 @@ class build_ext (Command):
# Append '_d' to the python import library on debug builds.
if
sys
.
platform
==
"win32"
:
from
distutils.msvccompiler
import
MSVCCompiler
if
not
isinstance
(
self
.
compiler
,
MSVCCompiler
):
if
not
isinstance
(
self
.
_
compiler
,
MSVCCompiler
):
template
=
"python%d%d"
if
self
.
debug
:
template
=
template
+
'_d'
...
...
tests/test_build_ext.py
View file @
870adffd
...
...
@@ -113,7 +113,7 @@ class BuildExtTestCase(support.TempdirManager,
else
:
_config_vars
[
'Py_ENABLE_SHARED'
]
=
old_var
# make sur
we get some lo
brary dirs under solaris
# make sur
e we get some li
brary dirs under solaris
self
.
assert_
(
len
(
cmd
.
library_dirs
)
>
0
)
def
test_user_site
(
self
):
...
...
@@ -282,13 +282,50 @@ class BuildExtTestCase(support.TempdirManager,
cmd
.
ensure_finalized
()
self
.
assertEquals
(
cmd
.
get_source_files
(),
[
'xxx'
])
def
test_compiler_option
(
self
):
# cmd.compiler is an option and
# should not be overriden by a compiler instance
# when the command is run
dist
=
Distribution
()
cmd
=
build_ext
(
dist
)
cmd
.
compiler
=
'unix'
cmd
.
ensure_finalized
()
cmd
.
run
()
self
.
assertEquals
(
cmd
.
compiler
,
'unix'
)
def
test_get_outputs
(
self
):
modules
=
[
Extension
(
'foo'
,
[
'xxx'
],
optional
=
False
)]
dist
=
Distribution
({
'name'
:
'xx'
,
'ext_modules'
:
modules
})
tmp_dir
=
self
.
mkdtemp
()
c_file
=
os
.
path
.
join
(
tmp_dir
,
'foo.c'
)
self
.
write_file
(
c_file
,
''
)
ext
=
Extension
(
'foo'
,
[
c_file
],
optional
=
False
)
dist
=
Distribution
({
'name'
:
'xx'
,
'ext_modules'
:
[
ext
]})
cmd
=
build_ext
(
dist
)
cmd
.
ensure_finalized
()
self
.
assertEquals
(
len
(
cmd
.
get_outputs
()),
1
)
if
os
.
name
==
"nt"
:
cmd
.
debug
=
sys
.
executable
.
endswith
(
"_d.exe"
)
cmd
.
build_lib
=
os
.
path
.
join
(
self
.
tmp_dir
,
'build'
)
cmd
.
build_temp
=
os
.
path
.
join
(
self
.
tmp_dir
,
'tempt'
)
# issue #5977 : distutils build_ext.get_outputs
# returns wrong result with --inplace
cmd
.
inplace
=
1
cmd
.
run
()
so_file
=
cmd
.
get_outputs
()[
0
]
self
.
assert_
(
os
.
path
.
exists
(
so_file
))
so_dir
=
os
.
path
.
dirname
(
so_file
)
self
.
assertEquals
(
so_dir
,
os
.
getcwd
())
cmd
.
inplace
=
0
cmd
.
run
()
so_file
=
cmd
.
get_outputs
()[
0
]
self
.
assert_
(
os
.
path
.
exists
(
so_file
))
so_dir
=
os
.
path
.
dirname
(
so_file
)
self
.
assertEquals
(
so_dir
,
cmd
.
build_lib
)
def
test_suite
():
src
=
_get_source_filename
()
if
not
os
.
path
.
exists
(
src
):
...
...
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