Skip to content

Commit

Permalink
[CI] Add the -no_warn_duplicate_libraries ldflag when running inv t…
Browse files Browse the repository at this point in the history
…est on `XCode >15` (#23628)

* [CI] Add -no_warn_duplicate_libraries flag when running inv test on XCode >15

* Remove leftover flag

* Create get_xcode_version function
  • Loading branch information
amenasria authored Mar 12, 2024
1 parent 34f0fcf commit 39eea0d
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions tasks/libs/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ def get_embedded_path(ctx):
return embedded_path


def get_xcode_version(ctx):
"""
Get the version of XCode used depending on how it's installed.
"""
if sys.platform != "darwin":
raise ValueError("The get_xcode_version function is only available on macOS")
xcode_path = ctx.run("xcode-select -p", hide=True).stdout.strip()
if xcode_path == "/Library/Developer/CommandLineTools":
xcode_version = ctx.run("pkgutil --pkg-info=com.apple.pkg.CLTools_Executables", hide=True).stdout.strip()
xcode_version = re.search(r"version: ([0-9.]+)", xcode_version).group(1)
xcode_version = re.search(r"([0-9]+.[0-9]+)", xcode_version).group(1)
elif xcode_path.startswith("/Applications/Xcode.app"):
xcode_version = ctx.run(
"xcodebuild -version | grep -Eo 'Xcode [0-9.]+' | awk '{print $2}'", hide=True
).stdout.strip()
else:
raise ValueError(f"Unknown XCode installation at {xcode_path}.")
return xcode_version


def get_build_flags(
ctx,
static=False,
Expand Down Expand Up @@ -228,10 +248,24 @@ def get_build_flags(
elif os.environ.get("NO_GO_OPT"):
gcflags = "-N -l"

# On macOS work around https://github.com/golang/go/issues/38824
# as done in https://go-review.googlesource.com/c/go/+/372798
if sys.platform == "darwin":
extldflags += "-Wl,-bind_at_load "
# On macOS work around https://github.com/golang/go/issues/38824
# as done in https://go-review.googlesource.com/c/go/+/372798
extldflags += "-Wl,-bind_at_load"

# On macOS when using XCode 15 the -no_warn_duplicate_libraries linker flag is needed to avoid getting ld warnings
# for duplicate libraries: `ld: warning: ignoring duplicate libraries: '-ldatadog-agent-rtloader', '-ldl'`.
# Gotestsum sees the ld warnings as errors, breaking the test invoke task, so we have to remove them.
# See https://indiestack.com/2023/10/xcode-15-duplicate-library-linker-warnings/
try:
xcode_version = get_xcode_version(ctx)
if int(xcode_version.split('.')[0]) >= 15:
extldflags += ",-no_warn_duplicate_libraries "
except ValueError:
print(
"Could not determine XCode version, not adding -no_warn_duplicate_libraries to extldflags",
file=sys.stderr,
)

if extldflags:
ldflags += f"'-extldflags={extldflags}' "
Expand Down

0 comments on commit 39eea0d

Please sign in to comment.