Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
8f71406d
Commit
8f71406d
authored
Mar 31, 2017
by
Jeroen Demeyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Automatically add include_dirs for externs
parent
bd0bd943
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
11 deletions
+49
-11
Cython/Build/Dependencies.py
Cython/Build/Dependencies.py
+40
-9
tests/run/cimport_from_sys_path.srctree
tests/run/cimport_from_sys_path.srctree
+9
-2
No files found.
Cython/Build/Dependencies.py
View file @
8f71406d
...
@@ -375,14 +375,30 @@ def normalize_existing(base_path, rel_paths):
...
@@ -375,14 +375,30 @@ def normalize_existing(base_path, rel_paths):
@
cached_function
@
cached_function
def
normalize_existing0
(
base_dir
,
rel_paths
):
def
normalize_existing0
(
base_dir
,
rel_paths
):
"""
Given some base directory ``base_dir`` and a list of path names
``rel_paths``, normalize each relative path name ``rel`` by
replacing it by ``os.path.join(base, rel)`` if that file exists.
Return a couple ``(normalized, needed_base)`` where ``normalized``
if the list of normalized file names and ``needed_base`` is
``base_dir`` if we actually needed ``base_dir``. If no paths were
changed (for example, if all paths were already absolute), then
``needed_base`` is ``None``.
"""
normalized
=
[]
normalized
=
[]
needed_base
=
None
for
rel
in
rel_paths
:
for
rel
in
rel_paths
:
if
os
.
path
.
isabs
(
rel
):
normalized
.
append
(
rel
)
continue
path
=
join_path
(
base_dir
,
rel
)
path
=
join_path
(
base_dir
,
rel
)
if
path_exists
(
path
):
if
path_exists
(
path
):
normalized
.
append
(
os
.
path
.
normpath
(
path
))
normalized
.
append
(
os
.
path
.
normpath
(
path
))
needed_base
=
base_dir
else
:
else
:
normalized
.
append
(
rel
)
normalized
.
append
(
rel
)
return
normalized
return
(
normalized
,
needed_base
)
def
resolve_depends
(
depends
,
include_dirs
):
def
resolve_depends
(
depends
,
include_dirs
):
...
@@ -483,20 +499,25 @@ class DependencyTree(object):
...
@@ -483,20 +499,25 @@ class DependencyTree(object):
return
all
return
all
@
cached_method
@
cached_method
def
cimports_
and_extern
s
(
self
,
filename
):
def
cimports_
externs_incdir
s
(
self
,
filename
):
# This is really ugly. Nested cimports are resolved with respect to the
# This is really ugly. Nested cimports are resolved with respect to the
# includer, but includes are resolved with respect to the includee.
# includer, but includes are resolved with respect to the includee.
cimports
,
includes
,
externs
=
self
.
parse_dependencies
(
filename
)[:
3
]
cimports
,
includes
,
externs
=
self
.
parse_dependencies
(
filename
)[:
3
]
cimports
=
set
(
cimports
)
cimports
=
set
(
cimports
)
externs
=
set
(
externs
)
externs
=
set
(
externs
)
incdirs
=
set
()
for
include
in
self
.
included_files
(
filename
):
for
include
in
self
.
included_files
(
filename
):
included_cimports
,
included_externs
=
self
.
cimports_and_extern
s
(
include
)
included_cimports
,
included_externs
,
included_incdirs
=
self
.
cimports_externs_incdir
s
(
include
)
cimports
.
update
(
included_cimports
)
cimports
.
update
(
included_cimports
)
externs
.
update
(
included_externs
)
externs
.
update
(
included_externs
)
return
tuple
(
cimports
),
normalize_existing
(
filename
,
externs
)
incdirs
.
update
(
included_incdirs
)
externs
,
incdir
=
normalize_existing
(
filename
,
externs
)
if
incdir
:
incdirs
.
add
(
incdir
)
return
tuple
(
cimports
),
externs
,
incdirs
def
cimports
(
self
,
filename
):
def
cimports
(
self
,
filename
):
return
self
.
cimports_
and_extern
s
(
filename
)[
0
]
return
self
.
cimports_
externs_incdir
s
(
filename
)[
0
]
def
package
(
self
,
filename
):
def
package
(
self
,
filename
):
return
package
(
filename
)
return
package
(
filename
)
...
@@ -579,12 +600,22 @@ class DependencyTree(object):
...
@@ -579,12 +600,22 @@ class DependencyTree(object):
def
distutils_info0
(
self
,
filename
):
def
distutils_info0
(
self
,
filename
):
info
=
self
.
parse_dependencies
(
filename
)[
3
]
info
=
self
.
parse_dependencies
(
filename
)[
3
]
externs
=
self
.
cimports_and_externs
(
filename
)[
1
]
kwds
=
info
.
values
cimports
,
externs
,
incdirs
=
self
.
cimports_externs_incdirs
(
filename
)
# Add dependencies on "cdef extern from ..." files
if
externs
:
if
externs
:
if
'depends'
in
info
.
value
s
:
if
'depends'
in
kwd
s
:
info
.
values
[
'depends'
]
=
list
(
set
(
info
.
value
s
[
'depends'
]).
union
(
externs
))
kwds
[
'depends'
]
=
list
(
set
(
kwd
s
[
'depends'
]).
union
(
externs
))
else
:
else
:
info
.
values
[
'depends'
]
=
list
(
externs
)
kwds
[
'depends'
]
=
list
(
externs
)
# Add include_dirs to ensure that the C compiler will find the
# "cdef extern from ..." files
if
incdirs
:
include_dirs
=
kwds
.
get
(
'include_dirs'
,
[])
for
inc
in
incdirs
:
if
inc
not
in
include_dirs
:
include_dirs
=
include_dirs
+
[
inc
]
kwds
[
'include_dirs'
]
=
include_dirs
return
info
return
info
def
distutils_info
(
self
,
filename
,
aliases
=
None
,
base
=
None
):
def
distutils_info
(
self
,
filename
,
aliases
=
None
,
base
=
None
):
...
...
tests/run/cimport_from_sys_path.srctree
View file @
8f71406d
...
@@ -19,8 +19,15 @@ setup(
...
@@ -19,8 +19,15 @@ setup(
######## site-packages/b/other.pxd ########
######## site-packages/b/other.pxd ########
cdef inline foo(int a):
cdef extern from "foo.c":
return a**2
int foo(int)
######## site-packages/b/foo.c ########
static int foo(int a)
{
return a * a;
}
######## a.pyx ########
######## a.pyx ########
...
...
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