patch_paddle_lite.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. import sys
  16. import shutil
  17. import subprocess
  18. import platform
  19. import sys
  20. def process_paddle_lite(paddle_lite_so_path):
  21. if platform.system().lower() != "linux":
  22. return
  23. rpaths = ["$ORIGIN", "$ORIGIN/mklml/lib/"]
  24. patchelf_exe = os.getenv("PATCHELF_EXE", "patchelf")
  25. for root, dirs, files in os.walk(paddle_lite_so_path):
  26. for lib in files:
  27. if ".so" in lib:
  28. paddle_lite_so_file = os.path.join(root, lib)
  29. command = "{} --set-rpath '{}' {}".format(
  30. patchelf_exe, ":".join(rpaths), paddle_lite_so_file
  31. )
  32. if platform.machine() != "sw_64" and platform.machine() != "mips64":
  33. assert (
  34. os.system(command) == 0
  35. ), "patchelf {} failed, the command: {}".format(
  36. paddle_lite_so_file, command
  37. )
  38. if __name__ == "__main__":
  39. process_paddle_lite(sys.argv[1])