Skip to content

Commit

Permalink
Check API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
reyoung committed Jul 4, 2018
1 parent 3d99e2e commit 94e3cff
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
15 changes: 15 additions & 0 deletions paddle/scripts/paddle_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,20 @@ EOF
fi
}

function assert_api_not_changed() {
mkdir -p ${PADDLE_ROOT}/build/.check_api_workspace
cd ${PADDLE_ROOT}/build/.check_api_workspace
virtualenv .env
source .env/bin/activate
pip install ${PADDLE_ROOT}/build/python/dist/*whl
curl ${PADDLE_API_SPEC_URL:-https://raw.githubusercontent.com/reyoung/FluidAPISpec/master/API.spec} \
> origin.spec
python ${PADDLE_ROOT}/tools/print_signatures.py paddle.fluid > new.spec
python ${PADDLE_ROOT}/tools/diff_api.py origin.spec new.spec
deactivate
}


function single_test() {
TEST_NAME=$1
if [ -z "${TEST_NAME}" ]; then
Expand Down Expand Up @@ -550,6 +564,7 @@ function main() {
cicheck)
cmake_gen ${PYTHON_ABI:-""}
build
assert_api_not_changed
run_test
gen_capi_package
gen_fluid_inference_lib
Expand Down
31 changes: 31 additions & 0 deletions tools/diff_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python
from __future__ import print_function
import difflib
import sys

with open(sys.argv[1], 'r') as f:
origin = f.read()
origin = origin.splitlines()

with open(sys.argv[2], 'r') as f:
new = f.read()
new = new.splitlines()

differ = difflib.Differ()
result = differ.compare(origin, new)

error = False
print('API Difference is: ')
for each_diff in result:
if each_diff[0] in ['-', '?']: # delete or change API is not allowed
error = True
elif each_diff[0] == '+':
# only new layers is allowed.
if not each_diff.startswith('+ paddle.fluid.layers.'):
error = True

if each_diff[0] != ' ':
print(each_diff)

if error:
sys.exit(1)

0 comments on commit 94e3cff

Please sign in to comment.