tools: lock the script so that it can only be run once at a time on macOS.
This will be an alternative way to fix #14236, without needing to have every usage depend on another (which is messy and bug-prone because then we have to follow the list of dependencies and see which was the last use of gimp_exe, and with the risk of errors depending on which build options are ON or OFF). This fixes such errors: > error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: > for: /Users/Shared/work/GNOME/gimp/_build-x86_64/plug-ins/common/test-plug-ins/film/film (for architecture x86_64) > option "-add_rpath /Users/Shared/work/GNOME/gimp/_build-x86_64/libgimpcolor" would duplicate path, file already > has LC_RPATH for: /Users/Shared/work/GNOME/gimp/_build-x86_64/libgimpcolor
This commit is contained in:
parent
75eb99dca3
commit
a7e39c16b1
1 changed files with 17 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
import fcntl
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
|
|
@ -9,6 +10,16 @@ import sys
|
|||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
# In some case, this script may not be run concurrently, in particular
|
||||
# on macOS where we need to set rpath and install_name_tool doesn't like
|
||||
# when a RPATH already exists.
|
||||
lock = None
|
||||
|
||||
def cleanup(lock):
|
||||
if lock is not None:
|
||||
fcntl.flock(lock, fcntl.LOCK_UN)
|
||||
os.close(lock)
|
||||
|
||||
try:
|
||||
GIMP_GLOBAL_BUILD_ROOT = os.environ.get("GIMP_GLOBAL_BUILD_ROOT", ".")
|
||||
|
||||
|
|
@ -33,6 +44,9 @@ try:
|
|||
f"{GIMP_GLOBAL_BUILD_ROOT}/libgimpwidgets"]
|
||||
|
||||
if "GIMP_TEMP_UPDATE_RPATH" in os.environ:
|
||||
lock = os.open(__file__, os.O_RDONLY)
|
||||
fcntl.flock(lock, fcntl.LOCK_EX)
|
||||
|
||||
for binary in os.environ["GIMP_TEMP_UPDATE_RPATH"].split(":"):
|
||||
result = subprocess.run(['otool', '-l', binary], stdout=subprocess.PIPE)
|
||||
out = result.stdout.decode('utf-8', errors='replace')
|
||||
|
|
@ -79,6 +93,7 @@ try:
|
|||
for new_rpath in rpath_array:
|
||||
if new_rpath in regex:
|
||||
subprocess.run(["install_name_tool", "-delete_rpath", new_rpath, binary], check=True)
|
||||
cleanup(lock)
|
||||
|
||||
# Clean-up the temporary config directory after each usage, yet making sure we
|
||||
# don't get tricked by weird redirections or anything of the sort. In particular
|
||||
|
|
@ -104,8 +119,10 @@ try:
|
|||
sys.exit(1)
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
cleanup(lock)
|
||||
sys.stderr.write(f"Command failed with exit code {e.returncode}: {e.cmd}")
|
||||
sys.exit(e.returncode)
|
||||
except Exception as e:
|
||||
cleanup(lock)
|
||||
sys.stderr.write(f"Error: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
|
|
|||
Loading…
Reference in a new issue