mirror of
https://github.com/ONLYOFFICE/build_tools.git
synced 2026-02-10 20:45:38 +08:00
FIx symlinks for entire folder
This commit is contained in:
@ -5,6 +5,7 @@ sys.path.append('../../../scripts')
|
||||
import base
|
||||
import os
|
||||
import shutil
|
||||
import fix_symlinks
|
||||
|
||||
def bash_chroot(command, sysroot):
|
||||
base.cmd2('sudo -S chroot', [sysroot, '/bin/bash -c', '\"' + command + ' \"'])
|
||||
@ -31,10 +32,6 @@ def download_sysroot():
|
||||
bash_chroot('apt upgrade -y', tmp_sysroot_ubuntu_dir)
|
||||
bash_chroot('apt install -y build-essential curl libpthread-stubs0-dev zlib1g-dev', tmp_sysroot_ubuntu_dir)
|
||||
|
||||
# fix link to a libdl
|
||||
bash_chroot('rm /usr/lib/x86_64-linux-gnu/libdl.so', tmp_sysroot_ubuntu_dir)
|
||||
bash_chroot('ln -s /lib/x86_64-linux-gnu/libdl.so.2 /usr/lib/x86_64-linux-gnu/libdl.so', tmp_sysroot_ubuntu_dir)
|
||||
|
||||
# # downloading arm toolchain
|
||||
arm_toolchain_url = 'https://releases.linaro.org/components/toolchain/binaries/5.3-2016.05/aarch64-linux-gnu/'
|
||||
arm_toolchain_tar_filename = 'gcc-linaro-5.3.1-2016.05-x86_64_aarch64-linux-gnu.tar.xz'
|
||||
@ -48,6 +45,9 @@ def download_sysroot():
|
||||
base.cmd2('sudo -S mv', [tmp_sysroot_ubuntu_dir + '/', dst_sysroot_ubuntu_dir + '/'])
|
||||
base.cmd2('sudo -S chmod', ['-R', 'u+rwx', dst_sysroot_ubuntu_dir])
|
||||
|
||||
# fix symlinks
|
||||
fix_symlinks.fix_symlinks(dst_sysroot_ubuntu_dir)
|
||||
|
||||
return
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
48
tools/linux/sysroot/fix_symlinks.py
Normal file
48
tools/linux/sysroot/fix_symlinks.py
Normal file
@ -0,0 +1,48 @@
|
||||
import os
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
# change symbolic link to relative paths
|
||||
def fix_symlinks(top_dir='./sysroot_ubuntu_1604'):
|
||||
for root, dirs, files in os.walk(top_dir):
|
||||
for name in files:
|
||||
path = os.path.join(root, name)
|
||||
if not os.path.islink(path):
|
||||
continue
|
||||
|
||||
try:
|
||||
target = os.readlink(path)
|
||||
except OSError as e:
|
||||
print(f"Error reading link '{path}': {e}", file=sys.stderr)
|
||||
continue
|
||||
|
||||
if not target.startswith('/lib/'):
|
||||
continue
|
||||
|
||||
new_target = "../../../lib" + target[4:]
|
||||
temp_name = f".tmp.{uuid.uuid4().hex}"
|
||||
temp_path = os.path.join(root, temp_name)
|
||||
|
||||
try:
|
||||
os.symlink(new_target, temp_path)
|
||||
except OSError as e:
|
||||
print(f"Failed to create temporary symlink for '{path}': {e}", file=sys.stderr)
|
||||
continue
|
||||
|
||||
try:
|
||||
os.replace(temp_path, path)
|
||||
print(f"Updated: {path} -> {new_target}")
|
||||
except OSError as e:
|
||||
print(f"Failed to replace symlink '{path}': {e}", file=sys.stderr)
|
||||
try:
|
||||
os.unlink(temp_path)
|
||||
except OSError:
|
||||
pass
|
||||
break # no subfolders
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
directory = sys.argv[1]
|
||||
else:
|
||||
directory = './sysroot_ubuntu_1604'
|
||||
fix_symlinks(directory)
|
||||
Reference in New Issue
Block a user