From 53320d7ef26752942d20fcf780003b5930d10661 Mon Sep 17 00:00:00 2001 From: Alex Messier Date: Tue, 22 Feb 2022 23:12:41 -0500 Subject: [PATCH] Add descriptive error message when pkg-config fails The pkg_config helper for premake was not checking for errors. When it failed to run, either when it is not installed or the queried package is not found, a cryptic error message would be printed: "Error: .../xenia/third_party/premake-core/src/base/string.lua:36: attempt to index a nil value (upvalue 's')" Fix this by checking the return status when calling pkg-config and printing a descriptive error message. --- tools/build/scripts/pkg_config.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/build/scripts/pkg_config.lua b/tools/build/scripts/pkg_config.lua index 2042491b9..bc83ae1c0 100644 --- a/tools/build/scripts/pkg_config.lua +++ b/tools/build/scripts/pkg_config.lua @@ -2,12 +2,21 @@ pkg_config = {} +local function pkg_config_call(lib, what) + local result, code = os.outputof("pkg-config --"..what.." "..lib) + if result then + return result + else + error("Failed to run 'pkg-config' for library '"..lib.."'. Are the development files installed?") + end +end + function pkg_config.cflags(lib) if not os.istarget("linux") then return end buildoptions({ - ({os.outputof("pkg-config --cflags "..lib)})[1], + pkg_config_call(lib, "cflags"), }) end @@ -16,12 +25,12 @@ function pkg_config.lflags(lib) return end linkoptions({ - ({os.outputof("pkg-config --libs-only-L " ..lib)})[1], - ({os.outputof("pkg-config --libs-only-other "..lib)})[1], + pkg_config_call(lib, "libs-only-L"), + pkg_config_call(lib, "libs-only-other"), }) -- We can't just drop the stdout of the `--libs` command in -- linkoptions because library order matters - local output = ({os.outputof("pkg-config --libs-only-l "..lib)})[1] + local output = pkg_config_call(lib, "libs-only-l") for k, flag in next, string.explode(output, " ") do -- remove "-l" if flag ~= "" then