Skip to content

Commit f834803

Browse files
fix: work around SPM executable binary target bug (#1792)
Ignore errors from `swift package` commands caused by executable products depending on binary targets Work around #1781 (comment) --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 742d001 commit f834803

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

swiftpkg/internal/repository_utils.bzl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _execute_spm_command(
5656
environment = exec_env,
5757
working_directory = working_directory,
5858
)
59-
if exec_result.return_code != 0:
59+
if exec_result.return_code != 0 and not _can_ignore_spm_error(exec_result):
6060
if err_msg_tpl == None:
6161
err_msg_tpl = """\
6262
Failed to execute SPM command. \
@@ -73,6 +73,21 @@ return_code: {return_code}\
7373
))
7474
return exec_result.stdout
7575

76+
def _can_ignore_spm_error(exec_result):
77+
"""Determine if the error from an exec result can be ignored.
78+
79+
SPM throws an error during `swift package describe` if an executable
80+
product depends on a binary target. It also outputs valid JSON so we
81+
can move past the error.
82+
83+
https://github.com/swiftlang/swift-package-manager/issues/8101"""
84+
85+
# Error message:
86+
# https://github.com/swiftlang/swift-package-manager/blob/339afc838a0083ea0b4da002dc53cfb8005d5978/Sources/PackageLoading/Diagnostics.swift#L83-L88
87+
return exec_result.stderr.endswith(
88+
"an executable target requires a 'main.swift' file\n",
89+
)
90+
7691
def _parsed_json_from_spm_command(
7792
repository_ctx,
7893
arguments,

0 commit comments

Comments
 (0)