summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSkyler Saleh <skylersaleh@gmail.com>2021-05-22 15:18:43 -0700
committerSkyler Saleh <skylersaleh@gmail.com>2021-05-22 15:37:47 -0700
commitabea411bdc9383ef261ea1dc39729e920a2afeaa (patch)
treea7c69aff1c5980a9f1112e5d2733ad91a456cfe0
parent76ed9310f290075073d1b7c49de3cae1f59113db (diff)
Apple M1: Detect incompatible universal merges
Adds a step to detect when the Intel and arm64 build trees cannot be merged safely. This can occur when each side has files/folders that are named the same but are of different types or symlinks that are the same name but need to point to different locations for each architecture. Before this change, this would just fail silently.
-rwxr-xr-xBuildMacOSUniversalBinary.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/BuildMacOSUniversalBinary.py b/BuildMacOSUniversalBinary.py
index 11d856de54..5ed4808bfd 100755
--- a/BuildMacOSUniversalBinary.py
+++ b/BuildMacOSUniversalBinary.py
@@ -162,6 +162,32 @@ def recursive_merge_binaries(src0, src1, dst):
the source trees
"""
+ # Check that all files present in the folder are of the same type and that
+ # links link to the same relative location
+ for newpath0 in glob.glob(src0+"/*"):
+ filename = os.path.basename(newpath0)
+ newpath1 = os.path.join(src1, filename)
+ if not os.path.exists(newpath1):
+ continue
+
+ if os.path.islink(newpath0) and os.path.islink(newpath1):
+ if os.path.relpath(newpath0,src0) == os.path.relpath(newpath1,src1):
+ continue
+
+ if os.path.isdir(newpath0) and os.path.isdir(newpath1):
+ continue
+
+ # isfile() can be true for links so check that both are not links
+ # before checking if they are both files
+ if (not os.path.islink(newpath0)) and (not os.path.islink(newpath1)):
+ if os.path.isfile(newpath0) and os.path.isfile(newpath1):
+ continue
+
+ raise Exception(f"{newpath0} and {newpath1} cannot be " +
+ "merged into a universal binary because they are of " +
+ "incompatible types. Perhaps the installed libraries" +
+ " are from different versions for each architecture")
+
for newpath0 in glob.glob(src0+"/*"):
filename = os.path.basename(newpath0)
newpath1 = os.path.join(src1, filename)
@@ -171,7 +197,11 @@ def recursive_merge_binaries(src0, src1, dst):
continue
if not os.path.exists(newpath1):
- shutil.copy(newpath0, new_dst_path)
+ if os.path.isdir(newpath0):
+ shutil.copytree(newpath0, new_dst_path)
+ else:
+ shutil.copy(newpath0, new_dst_path)
+
continue
if os.path.isdir(newpath1):