From 67941f939a95e4161ca2be75ec58a5c1c7feaf15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Thu, 22 Aug 2024 13:01:50 +0200 Subject: [PATCH 1/3] Add error handling for linker flag sub commands --- src/compiler/crystal/compiler.cr | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/compiler/crystal/compiler.cr b/src/compiler/crystal/compiler.cr index 38880ee9ed64..69db2d9b981d 100644 --- a/src/compiler/crystal/compiler.cr +++ b/src/compiler/crystal/compiler.cr @@ -411,7 +411,24 @@ module Crystal if program.has_flag? "msvc" lib_flags = program.lib_flags # Execute and expand `subcommands`. - lib_flags = lib_flags.gsub(/`(.*?)`/) { `#{$1}` } if expand + if expand + lib_flags = lib_flags.gsub(/`(.*?)`/) do + command = $1 + begin + error_io = IO::Memory.new + output = Process.run(command, shell: true, output: :pipe, error: error_io) do |process| + process.output.gets_to_end + end + unless $?.success? + error_io.rewind + error "Error executing subcommand for linker flags: #{command.inspect}: #{error_io.gets_to_end}" + end + output + rescue exc + error "Error executeing subcommand for linker flags: #{command.inspect}: #{exc}" + end + end + end object_arg = Process.quote_windows(object_names) output_arg = Process.quote_windows("/Fe#{output_filename}") From f96e42c234f073e2b5d48b657ce4dcfe511d132e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Thu, 22 Aug 2024 17:35:58 +0200 Subject: [PATCH 2/3] Update src/compiler/crystal/compiler.cr Co-authored-by: Quinton Miller --- src/compiler/crystal/compiler.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/crystal/compiler.cr b/src/compiler/crystal/compiler.cr index 69db2d9b981d..585667cd2ffb 100644 --- a/src/compiler/crystal/compiler.cr +++ b/src/compiler/crystal/compiler.cr @@ -425,7 +425,7 @@ module Crystal end output rescue exc - error "Error executeing subcommand for linker flags: #{command.inspect}: #{exc}" + error "Error executing subcommand for linker flags: #{command.inspect}: #{exc}" end end end From 8f07e067faf3d5de1382a5391ed8fb27604c125a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Thu, 22 Aug 2024 21:01:27 +0200 Subject: [PATCH 3/3] Use `IO::Memory#to_s` directly --- src/compiler/crystal/compiler.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/crystal/compiler.cr b/src/compiler/crystal/compiler.cr index 585667cd2ffb..f25713c6385e 100644 --- a/src/compiler/crystal/compiler.cr +++ b/src/compiler/crystal/compiler.cr @@ -421,7 +421,7 @@ module Crystal end unless $?.success? error_io.rewind - error "Error executing subcommand for linker flags: #{command.inspect}: #{error_io.gets_to_end}" + error "Error executing subcommand for linker flags: #{command.inspect}: #{error_io}" end output rescue exc