Skip to content

Commit 78790ed

Browse files
authored
Merge pull request #11963 from reyoung/API_diff
Check API changes
2 parents 3d99e2e + 26d1280 commit 78790ed

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

paddle/scripts/paddle_build.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,20 @@ EOF
312312
fi
313313
}
314314

315+
function assert_api_not_changed() {
316+
mkdir -p ${PADDLE_ROOT}/build/.check_api_workspace
317+
cd ${PADDLE_ROOT}/build/.check_api_workspace
318+
virtualenv .env
319+
source .env/bin/activate
320+
pip install ${PADDLE_ROOT}/build/python/dist/*whl
321+
curl ${PADDLE_API_SPEC_URL:-https://raw.githubusercontent.com/reyoung/FluidAPISpec/master/API.spec} \
322+
> origin.spec
323+
python ${PADDLE_ROOT}/tools/print_signatures.py paddle.fluid > new.spec
324+
python ${PADDLE_ROOT}/tools/diff_api.py origin.spec new.spec
325+
deactivate
326+
}
327+
328+
315329
function single_test() {
316330
TEST_NAME=$1
317331
if [ -z "${TEST_NAME}" ]; then
@@ -550,6 +564,7 @@ function main() {
550564
cicheck)
551565
cmake_gen ${PYTHON_ABI:-""}
552566
build
567+
assert_api_not_changed
553568
run_test
554569
gen_capi_package
555570
gen_fluid_inference_lib

tools/diff_api.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function
3+
import difflib
4+
import sys
5+
6+
with open(sys.argv[1], 'r') as f:
7+
origin = f.read()
8+
origin = origin.splitlines()
9+
10+
with open(sys.argv[2], 'r') as f:
11+
new = f.read()
12+
new = new.splitlines()
13+
14+
differ = difflib.Differ()
15+
result = differ.compare(origin, new)
16+
17+
error = False
18+
print('API Difference is: ')
19+
for each_diff in result:
20+
if each_diff[0] in ['-', '?']: # delete or change API is not allowed
21+
error = True
22+
elif each_diff[0] == '+':
23+
# only new layers is allowed.
24+
if not each_diff.startswith('+ paddle.fluid.layers.'):
25+
error = True
26+
27+
if each_diff[0] != ' ':
28+
print(each_diff)
29+
30+
if error:
31+
sys.exit(1)

0 commit comments

Comments
 (0)