From a7e39c16b19636fcc8269c073126f19ce445bbd1 Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 27 Mar 2026 12:31:30 +0100 Subject: [PATCH] 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 --- tools/in-build-gimp.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/in-build-gimp.py b/tools/in-build-gimp.py index b29e59dc8d..088c6e8841 100644 --- a/tools/in-build-gimp.py +++ b/tools/in-build-gimp.py @@ -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)