setup.py.in 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# module of pack whl installer for Paddle-lite

import shutil
import os
from setuptools import setup, Distribution


class BinaryDistribution(Distribution):
    'binary distribution'
    def has_ext_modules(foo):
        return True


# get paddle-lite version, if it's not based on a release tag, we use commit id instead
PADDLELITE_COMMITE = "@PADDLE_LITE_COMMIT@"
PADDLELITE_TAG = "@PADDLE_LITE_TAG@"
if PADDLELITE_TAG == "":
    PADDLELITE_VERSION = PADDLELITE_COMMITE
else:
    PADDLELITE_VERSION = PADDLELITE_TAG

# core lib of paddlelite is stored as lite.so
Z
zhupengyang 已提交
36 37 38 39 40 41 42
files = os.listdir('${PADDLE_BINARY_DIR}')
INFERENCE_LITE_LIB_PATH = ''
for file in files:
    if file.find('inference_lite_lib') == 0:
        INFERENCE_LITE_LIB_PATH = '${PADDLE_BINARY_DIR}/' + file
        break
LITE_PATH = INFERENCE_LITE_LIB_PATH + '/python/install/lite'
43
PACKAGE_DATA = {'paddlelite': ['lite.so' if os.name!='nt' else 'lite.pyd']}
44 45 46 47

# copy scripts of paddlelite
shutil.copy('${PADDLE_SOURCE_DIR}/lite/api/python/bin/paddle_lite_opt', LITE_PATH)

48 49
# put all thirdparty libraries in paddlelite.libs
PACKAGE_DATA['paddlelite.libs'] = []
Z
zhupengyang 已提交
50
LIB_PATH = INFERENCE_LITE_LIB_PATH + '/python/install/libs/'
51 52 53
if '${WITH_MKL}' == 'ON':
    shutil.copy('${MKLML_SHARED_IOMP_LIB}', LIB_PATH)
    shutil.copy('${MKLML_SHARED_LIB}', LIB_PATH)
54 55 56 57 58 59
    if os.name != 'nt':
        PACKAGE_DATA['paddlelite.libs'] += ['libmklml_intel.so', 'libiomp5.so']
    else:
        PACKAGE_DATA['paddlelite.libs'] += ['libiomp5md.dll', 'mklml.dll']
        shutil.copy('${MKLML_SHARED_LIB_DEPS}', LIB_PATH)
        PACKAGE_DATA['paddlelite.libs'] += ['msvcr120.dll']
60
# link lite.so to paddlelite.libs
61
if os.name != 'nt':
62
    COMMAND = "patchelf --set-rpath '$ORIGIN/libs/' " + LITE_PATH + "/lite.so"
63 64 65 66
    if os.system(COMMAND) != 0:
        raise Exception("patch third_party libs failed, command: %s" % COMMAND)

  
67 68 69 70 71 72 73 74 75 76 77 78 79

# remove unused paddle/libs/__init__.py
if os.path.isfile(LIB_PATH+'/__init__.py'):
    os.remove(LIB_PATH+'/__init__.py')

# set dir path of each package
PACKAGE_DIR = {
    # The paddle.fluid.proto will be generated while compiling.
    # So that package points to other directory.
    'paddlelite.libs': LIB_PATH,
    'paddlelite': LITE_PATH
}

80 81 82 83 84 85 86 87
if os.name == 'nt':
    # fix the path separator under windows
    fix_package_dir = {}
    for k, v in PACKAGE_DIR.items():
        fix_package_dir[k] = v.replace('/', '\\')
    PACKAGE_DIR = fix_package_dir


88 89 90 91
setup(
    name='paddlelite',
    version=PADDLELITE_VERSION,
    description='Paddle-Lite Library',
92
    scripts=['lite/paddle_lite_opt'],
93 94 95 96 97
    packages=['paddlelite', 'paddlelite.libs'],
    package_dir=PACKAGE_DIR,
    package_data=PACKAGE_DATA,
    distclass=BinaryDistribution
)