Skip to content

Commit 57bc623

Browse files
reyounggangliao
authored andcommitted
enable swig unittest in travis-ci (#394)
* Init * Add numpy deps * Refine
1 parent f06f4df commit 57bc623

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ addons:
3838
- curl
3939
- lcov
4040
- graphviz
41+
- swig
4142
before_install:
4243
- |
4344
if [ ${JOB} == "BUILD_AND_TEST" ]; then
@@ -51,7 +52,7 @@ before_install:
5152
fi
5253
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo paddle/scripts/travis/before_install.linux.sh; fi
5354
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then paddle/scripts/travis/before_install.osx.sh; fi
54-
- pip install wheel protobuf sphinx breathe recommonmark
55+
- pip install wheel protobuf sphinx breathe recommonmark virtualenv numpy
5556
script:
5657
- paddle/scripts/travis/main.sh
5758
notifications:

paddle/api/paddle_api_config.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ GFLAGS_LOCATION="@GFLAGS_LOCATION@"
1616
CBLAS_LIBRARIES="@CBLAS_LIBS@"
1717

1818
CUDA_LIBRARIES="@CUDA_LIBRARIES@"
19+
WITH_COVERALLS="@ON_COVERALLS@"

paddle/api/paddle_ld_flags.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(self):
4848
self.glog_libs = LIBGLOG_LIBRARY
4949

5050
self.with_gflags = PaddleLDFlag.cmake_bool(WITH_GFLAGS)
51+
self.with_coverage = PaddleLDFlag.cmake_bool(WITH_COVERALLS)
5152
self.gflags_libs = GFLAGS_LIBRARIES
5253
self.gflags_location = GFLAGS_LOCATION
5354
self.cblas_libs = CBLAS_LIBRARIES
@@ -97,6 +98,8 @@ def libs_str(self):
9798
libs.append(self.normalize_flag(self.gflags_libs))
9899
if self.with_gpu:
99100
libs.append(self.normalize_flag(self.curt))
101+
if self.with_coverage:
102+
libs.append("-fprofile-arcs")
100103
return " ".join(filter(lambda l: len(l) != 0, libs))
101104

102105
def normalize_flag(self, cmake_flag):
@@ -133,8 +136,14 @@ def cmake_bool(cmake_str):
133136
return False
134137
else:
135138
return True
136-
139+
def c_flag(self):
140+
if self.with_coverage:
141+
return ["-fprofile-arcs", "-ftest-coverage", "-O0", "-g"]
142+
else:
143+
return None
137144
except ImportError:
138145
class PaddleLDFlag(object):
139146
def ldflag_str(self):
140147
pass
148+
def c_flag(self):
149+
pass

paddle/scripts/travis/build_and_test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ source ./common.sh
33
CMAKE_EXTRA=""
44
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
55
CMAKE_EXTRA="-DPYTHON_LIBRARY=/usr/local/Cellar/python/2.7.12_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib"
6+
else
7+
CMAKE_EXTRA="-DWITH_SWIG_PY=ON"
68
fi
79

810

paddle/setup.py.in

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ is_lin = (system == 'linux')
3131
# because generate paddle LDFLAGS is too complicated to do in setup.py
3232
# it just read COMAKE generated LDFLAGS.
3333
extra_links = []
34-
ldflags = api.paddle_ld_flags.PaddleLDFlag()
35-
ldflags = ldflags.ldflag_str()
34+
obj = api.paddle_ld_flags.PaddleLDFlag()
35+
ldflags = obj.ldflag_str()
3636
if ldflags is not None:
3737
extra_links.extend(ldflags.split(" "))
3838

@@ -51,13 +51,20 @@ elif is_osx == True:
5151

5252
include_dirs = [np.get_include(), "../"] # include numpy and paddle.
5353

54+
extra_c = obj.c_flag()
55+
56+
attr=dict()
57+
if extra_c is not None:
58+
attr["extra_compile_args"] = extra_c
59+
5460
setup(name="py_paddle",
5561
version="@PADDLE_VERSION@",
5662
ext_modules=[
5763
Extension('py_paddle._swig_paddle', # Build SWIG Extension.
5864
['Paddle_wrap.cxx'],
5965
include_dirs = include_dirs,
60-
extra_link_args = extra_links
66+
extra_link_args = extra_links,
67+
**attr
6168
)
6269
],
6370
packages=['py_paddle'],

0 commit comments

Comments
 (0)