From a157f899a902c85843f57e6e8ffd7435abfe731b Mon Sep 17 00:00:00 2001 From: John Flanagan Date: Wed, 27 Aug 2025 13:37:05 -0500 Subject: [PATCH 1/3] fix: work around SPM executable binary target bug --- swiftpkg/internal/repository_utils.bzl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/swiftpkg/internal/repository_utils.bzl b/swiftpkg/internal/repository_utils.bzl index 1dad0607a..f985e12ea 100644 --- a/swiftpkg/internal/repository_utils.bzl +++ b/swiftpkg/internal/repository_utils.bzl @@ -56,7 +56,7 @@ def _execute_spm_command( environment = exec_env, working_directory = working_directory, ) - if exec_result.return_code != 0: + if exec_result.return_code != 0 and not _can_ignore_spm_error(exec_result): if err_msg_tpl == None: err_msg_tpl = """\ Failed to execute SPM command. \ @@ -73,6 +73,18 @@ return_code: {return_code}\ )) return exec_result.stdout +def _can_ignore_spm_error(exec_result): + """Ignore error that can occur when an SPM executable product depends on a + binary target. + + https://github.com/swiftlang/swift-package-manager/issues/8101""" + + # Error message: + # https://github.com/swiftlang/swift-package-manager/blob/339afc838a0083ea0b4da002dc53cfb8005d5978/Sources/PackageLoading/Diagnostics.swift#L83-L88 + return exec_result.stderr.endswith( + "an executable target requires a 'main.swift' file\n" + ) + def _parsed_json_from_spm_command( repository_ctx, arguments, From 26159ee22c4198b1c0bfc38cd129b29b7367262f Mon Sep 17 00:00:00 2001 From: John Flanagan Date: Wed, 27 Aug 2025 13:42:26 -0500 Subject: [PATCH 2/3] tidy --- swiftpkg/internal/repository_utils.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swiftpkg/internal/repository_utils.bzl b/swiftpkg/internal/repository_utils.bzl index f985e12ea..531741943 100644 --- a/swiftpkg/internal/repository_utils.bzl +++ b/swiftpkg/internal/repository_utils.bzl @@ -76,13 +76,13 @@ return_code: {return_code}\ def _can_ignore_spm_error(exec_result): """Ignore error that can occur when an SPM executable product depends on a binary target. - + https://github.com/swiftlang/swift-package-manager/issues/8101""" # Error message: # https://github.com/swiftlang/swift-package-manager/blob/339afc838a0083ea0b4da002dc53cfb8005d5978/Sources/PackageLoading/Diagnostics.swift#L83-L88 return exec_result.stderr.endswith( - "an executable target requires a 'main.swift' file\n" + "an executable target requires a 'main.swift' file\n", ) def _parsed_json_from_spm_command( From 31da1b2a87ac59ce25e2c46bb64243c3d21b8f0e Mon Sep 17 00:00:00 2001 From: John Flanagan Date: Tue, 2 Sep 2025 09:08:18 -0500 Subject: [PATCH 3/3] Update doc comment --- swiftpkg/internal/repository_utils.bzl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/swiftpkg/internal/repository_utils.bzl b/swiftpkg/internal/repository_utils.bzl index 531741943..10865c866 100644 --- a/swiftpkg/internal/repository_utils.bzl +++ b/swiftpkg/internal/repository_utils.bzl @@ -74,8 +74,11 @@ return_code: {return_code}\ return exec_result.stdout def _can_ignore_spm_error(exec_result): - """Ignore error that can occur when an SPM executable product depends on a - binary target. + """Determine if the error from an exec result can be ignored. + + SPM throws an error during `swift package describe` if an executable + product depends on a binary target. It also outputs valid JSON so we + can move past the error. https://github.com/swiftlang/swift-package-manager/issues/8101"""