From 8cf8d8e916e205811526a8dac1e62bbfb7e2d061 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Thu, 28 Nov 2024 16:08:15 +0000 Subject: [PATCH] feat(lib): use different tool_storage structure, chmod on unix * Fix for tools which don't already provide zips with binaries that have their executable bit set, by executing chmod before attempting to run. * Uses a different tool_storage structure to prevent changing the tool name and causing confusion for tools which change their help menu binary name based on the current exe name. --- toolchainlib/src/init.luau | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/toolchainlib/src/init.luau b/toolchainlib/src/init.luau index 3fcfc60..5aa9590 100644 --- a/toolchainlib/src/init.luau +++ b/toolchainlib/src/init.luau @@ -73,6 +73,22 @@ local function downloadAndDecompress(asset: { end) :: Option end +-- NOTE: number must be an octal or a string mode +local function chmod(path: pathfs.Path, mode: number | string) + if process.os == "windows" then + return + end + + local result = process.spawn( + "chmod", + { if typeof(mode) == "string" then mode else string.format("%o", mode), path:toString() } + ) + + if not result.ok then + return error(result.stderr) + end +end + local function toolAliasOrDefault(tool: ToolId): string return tool.alias:unwrapOr(string.split((tool :: ToolId).repo, "/")[2]) end @@ -201,6 +217,7 @@ function installTool(tool: ToolId, installPath: pathfs.Path) -- Now we can use `path` to figure out the real tool to execute -- ... ]] + chmod(installPath, 755) runTool(installPath) end @@ -225,7 +242,7 @@ return setmetatable( local ERROR_PREFIX = `{stdio.color("red")}{stdio.style("bold")}error{stdio.color("reset")}:` local repo, version = string.match(tool, "([^@]+)@?(.*)") - if repo == nil then + if repo == nil or version == nil then stdio.ewrite(`{ERROR_PREFIX} Invalid tool provided\n`) return 1 end @@ -251,11 +268,19 @@ return setmetatable( return 0, manifest.version end + local versionOrDefault = version + if versionOrDefault == "" then + local code, ver = manifestVersion() + if code ~= 0 then + return code + end + + versionOrDefault = ver :: string + end + local toolId = string.gsub(repo :: string, "/", "+") local toolAlias = string.split(toolId, "+")[2] - local toolInstallPath = TOOL_STORAGE_DIR:join(toolId):join( - `{toolAlias}-` .. if version ~= "" then version :: string else manifestVersion() - ) + local toolInstallPath = TOOL_STORAGE_DIR:join(toolId):join(versionOrDefault):join(toolAlias) if pathfs.isFile(toolInstallPath) then return lib.runTool(toolInstallPath)