Skip to content

Commit 3ae16f1

Browse files
committed
fix(build): stop forcing a relink on every incremental build
The metadata files are link inputs, so pre-build and the metadata generator now leave them alone unless their content changed. The strip script skips simulator builds, whose extra architectures never ship.
1 parent 600f903 commit 3ae16f1

5 files changed

Lines changed: 56 additions & 19 deletions

File tree

‎metadata-generator/build-step-metadata-generator.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import shlex
55
import subprocess
6+
import filecmp
67
import sys
78

89
print("Python version: " + sys.version)
@@ -126,7 +127,7 @@ def save_stream_to_file(filename, stream):
126127
def generate_metadata(arch):
127128
# metadata generator arguments
128129
generator_call = ["./objc-metadata-generator", "-verbose",
129-
"-output-bin", "{}/metadata-{}.bin".format(conf_build_dir, arch),
130+
"-output-bin", "{}/metadata-{}.bin.tmp".format(conf_build_dir, arch),
130131
"-output-umbrella", "{}/umbrella-{}.h".format(conf_build_dir, arch),
131132
"-docset-path", docset_path]
132133

@@ -192,6 +193,14 @@ def generate_metadata(arch):
192193
print(error_stream_content)
193194
sys.exit(1)
194195

196+
# Generated during linking, but also an input of the link (-sectcreate):
197+
# replacing unchanged metadata would make Xcode relink on every build.
198+
output_bin = "{}/metadata-{}.bin".format(conf_build_dir, arch)
199+
if os.path.exists(output_bin) and filecmp.cmp(output_bin + ".tmp", output_bin, shallow=False):
200+
os.remove(output_bin + ".tmp")
201+
else:
202+
os.replace(output_bin + ".tmp", output_bin)
203+
195204

196205
for arch in env("ARCHS").split():
197206
# skip metadata generation for architectures different than the one specified in the command line
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
#!/usr/bin/env bash
22

33
# Ignore errors while inserting environment variables (some could be readonly)
4-
(echo "set +e"; echo "set +o posix"; export; echo "set -o posix"; echo "set -e";) > ./.build_env_vars.sh
4+
ENV_FILE=./.build_env_vars.sh
5+
(echo "set +e"; echo "set +o posix"; export; echo "set -o posix"; echo "set -e";) > "$ENV_FILE.tmp"
6+
if cmp -s "$ENV_FILE.tmp" "$ENV_FILE"; then
7+
rm "$ENV_FILE.tmp"
8+
else
9+
mv "$ENV_FILE.tmp" "$ENV_FILE"
10+
fi
511

6-
# create temporary empty metadata files for XCode LD/LDPLUSPLUS flag analysis
12+
# create temporary empty metadata files for XCode LD/LDPLUSPLUS flag analysis.
13+
# Never touch existing ones: the link step reads them, so a newer timestamp
14+
# would make Xcode relink on every build.
715
for arch in $VALID_ARCHS
816
do :
9-
touch "$CONFIGURATION_BUILD_DIR/metadata-$arch.bin"
17+
[ -e "$CONFIGURATION_BUILD_DIR/metadata-$arch.bin" ] || touch "$CONFIGURATION_BUILD_DIR/metadata-$arch.bin"
1018
done

‎project-template-ios/internal/strip-dynamic-framework-architectures.sh‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,21 @@ if [ ! -e "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}" ]; then
4141
exit 0
4242
fi
4343

44-
echo "Stripping frameworks"
44+
# Simulator builds never ship, so extra architectures in them are harmless.
45+
if [[ "${PLATFORM_NAME}" == *simulator ]]; then
46+
exit 0
47+
fi
48+
4549
cd "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}"
4650

47-
for file in $(find . -type f); do
48-
# Skip non-dynamic libraries
49-
if ! [[ "$(file "$file")" == *"dynamically linked shared library"* ]]; then
51+
shopt -s nullglob
52+
for file in *.framework/* *.dylib; do
53+
# Only a framework's main binary (named after it) and loose dylibs are Mach-O
54+
if [[ "$file" == *.framework/* && "$(basename "$file")" != "$(basename "$(dirname "$file")" .framework)" ]]; then
5055
continue
5156
fi
52-
# Get architectures for current file
53-
archs="$(lipo -info "${file}" | rev | cut -d ':' -f1 | rev)"
57+
58+
archs="$(lipo -archs "$file" 2>/dev/null)" || continue
5459
stripped=""
5560
for arch in $archs; do
5661
if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then
@@ -59,6 +64,7 @@ for file in $(find . -type f); do
5964
stripped="$stripped $arch"
6065
fi
6166
done
67+
6268
if [[ "$stripped" != "" ]]; then
6369
echo "Stripped $file of architectures:$stripped"
6470
if [ "${CODE_SIGNING_ALLOWED}" == "YES" ]; then
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
#!/usr/bin/env bash
22

33
# Ignore errors while inserting environment variables (some could be readonly)
4-
(echo "set +e"; echo "set +o posix"; export; echo "set -o posix"; echo "set -e";) > ./.build_env_vars.sh
4+
ENV_FILE=./.build_env_vars.sh
5+
(echo "set +e"; echo "set +o posix"; export; echo "set -o posix"; echo "set -e";) > "$ENV_FILE.tmp"
6+
if cmp -s "$ENV_FILE.tmp" "$ENV_FILE"; then
7+
rm "$ENV_FILE.tmp"
8+
else
9+
mv "$ENV_FILE.tmp" "$ENV_FILE"
10+
fi
511

6-
# create temporary empty metadata files for XCode LD/LDPLUSPLUS flag analysis
12+
# create temporary empty metadata files for XCode LD/LDPLUSPLUS flag analysis.
13+
# Never touch existing ones: the link step reads them, so a newer timestamp
14+
# would make Xcode relink on every build.
715
for arch in $VALID_ARCHS
816
do :
9-
touch "$CONFIGURATION_BUILD_DIR/metadata-$arch.bin"
17+
[ -e "$CONFIGURATION_BUILD_DIR/metadata-$arch.bin" ] || touch "$CONFIGURATION_BUILD_DIR/metadata-$arch.bin"
1018
done

‎project-template-vision/internal/strip-dynamic-framework-architectures.sh‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,21 @@ if [ ! -e "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}" ]; then
4141
exit 0
4242
fi
4343

44-
echo "Stripping frameworks"
44+
# Simulator builds never ship, so extra architectures in them are harmless.
45+
if [[ "${PLATFORM_NAME}" == *simulator ]]; then
46+
exit 0
47+
fi
48+
4549
cd "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}"
4650

47-
for file in $(find . -type f); do
48-
# Skip non-dynamic libraries
49-
if ! [[ "$(file "$file")" == *"dynamically linked shared library"* ]]; then
51+
shopt -s nullglob
52+
for file in *.framework/* *.dylib; do
53+
# Only a framework's main binary (named after it) and loose dylibs are Mach-O
54+
if [[ "$file" == *.framework/* && "$(basename "$file")" != "$(basename "$(dirname "$file")" .framework)" ]]; then
5055
continue
5156
fi
52-
# Get architectures for current file
53-
archs="$(lipo -info "${file}" | rev | cut -d ':' -f1 | rev)"
57+
58+
archs="$(lipo -archs "$file" 2>/dev/null)" || continue
5459
stripped=""
5560
for arch in $archs; do
5661
if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then
@@ -59,6 +64,7 @@ for file in $(find . -type f); do
5964
stripped="$stripped $arch"
6065
fi
6166
done
67+
6268
if [[ "$stripped" != "" ]]; then
6369
echo "Stripped $file of architectures:$stripped"
6470
if [ "${CODE_SIGNING_ALLOWED}" == "YES" ]; then

0 commit comments

Comments
 (0)