aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/mason-core/installer/managers/build.lua48
-rw-r--r--lua/mason-core/installer/registry/expr.lua10
-rw-r--r--lua/mason-core/installer/registry/init.lua2
-rw-r--r--lua/mason-core/installer/registry/link.lua8
-rw-r--r--lua/mason-core/installer/registry/providers/generic/build.lua40
-rw-r--r--lua/mason-core/installer/registry/providers/generic/download.lua (renamed from lua/mason-core/installer/registry/providers/generic.lua)8
-rw-r--r--lua/mason-core/installer/registry/providers/generic/init.lua36
-rw-r--r--lua/mason-core/installer/registry/providers/github/build.lua53
-rw-r--r--lua/mason-core/installer/registry/providers/github/init.lua2
9 files changed, 163 insertions, 44 deletions
diff --git a/lua/mason-core/installer/managers/build.lua b/lua/mason-core/installer/managers/build.lua
new file mode 100644
index 00000000..a1549a28
--- /dev/null
+++ b/lua/mason-core/installer/managers/build.lua
@@ -0,0 +1,48 @@
+local _ = require "mason-core.functional"
+local a = require "mason-core.async"
+local async_uv = require "mason-core.async.uv"
+local installer = require "mason-core.installer"
+local log = require "mason-core.log"
+local platform = require "mason-core.platform"
+local powershell = require "mason-core.managers.powershell"
+
+local M = {}
+
+---@class BuildInstruction
+---@field target? Platform | Platform[]
+---@field run string
+---@field staged? boolean
+---@field env? table<string, string>
+
+---@async
+---@param build BuildInstruction
+---@return Result
+---@nodiscard
+function M.run(build)
+ log.fmt_debug("build: run %s", build)
+ local ctx = installer.context()
+ if build.staged == false then
+ ctx:promote_cwd()
+ end
+ return platform.when {
+ unix = function()
+ return ctx.spawn.bash {
+ on_spawn = a.scope(function(_, stdio)
+ local stdin = stdio[1]
+ async_uv.write(stdin, "set -euxo pipefail;\n")
+ async_uv.write(stdin, build.run)
+ async_uv.shutdown(stdin)
+ async_uv.close(stdin)
+ end),
+ env = build.env,
+ }
+ end,
+ win = function()
+ return powershell.command(build.run, {
+ env = build.env,
+ }, ctx.spawn)
+ end,
+ }
+end
+
+return M
diff --git a/lua/mason-core/installer/registry/expr.lua b/lua/mason-core/installer/registry/expr.lua
index 5dc016eb..2bb3a149 100644
--- a/lua/mason-core/installer/registry/expr.lua
+++ b/lua/mason-core/installer/registry/expr.lua
@@ -13,15 +13,21 @@ local parse_expr = _.compose(
_.split "|"
)
----@param predicate fun(value: string): boolean
+---@param predicate (fun(value: string): boolean) | boolean
---@param value string
local take_if = _.curryN(function(predicate, value)
+ if type(predicate) == "boolean" then
+ predicate = _.always(predicate)
+ end
return predicate(value) and value or nil
end, 2)
----@param predicate fun(value: string): boolean
+---@param predicate (fun(value: string): boolean) | boolean
---@param value string
local take_if_not = _.curryN(function(predicate, value)
+ if type(predicate) == "boolean" then
+ predicate = _.always(predicate)
+ end
return (not predicate(value)) and value or nil
end, 2)
diff --git a/lua/mason-core/installer/registry/init.lua b/lua/mason-core/installer/registry/init.lua
index 3ece857d..6c22d227 100644
--- a/lua/mason-core/installer/registry/init.lua
+++ b/lua/mason-core/installer/registry/init.lua
@@ -132,6 +132,8 @@ function M.parse(spec, opts)
source = parsed_source,
purl = purl,
}
+ end):on_failure(function(err)
+ log.debug("Failed to parse spec spec", spec.name, err)
end)
end
diff --git a/lua/mason-core/installer/registry/link.lua b/lua/mason-core/installer/registry/link.lua
index 5d6a8f16..2b4027e9 100644
--- a/lua/mason-core/installer/registry/link.lua
+++ b/lua/mason-core/installer/registry/link.lua
@@ -149,7 +149,13 @@ end
local function expand_bin(ctx, spec, purl, source)
log.debug("Registering bin links", ctx.package, spec.bin)
return Result.try(function(try)
- local expr_ctx = { version = purl.version, source = source }
+ local expr_ctx = {
+ version = purl.version,
+ source = source,
+ is_platform = function(target)
+ return platform.is[target]
+ end,
+ }
local bin_table = spec.bin
if not bin_table then
diff --git a/lua/mason-core/installer/registry/providers/generic/build.lua b/lua/mason-core/installer/registry/providers/generic/build.lua
new file mode 100644
index 00000000..6d2769e1
--- /dev/null
+++ b/lua/mason-core/installer/registry/providers/generic/build.lua
@@ -0,0 +1,40 @@
+local Result = require "mason-core.result"
+local _ = require "mason-core.functional"
+local build = require "mason-core.installer.managers.build"
+local expr = require "mason-core.installer.registry.expr"
+local util = require "mason-core.installer.registry.util"
+
+local M = {}
+
+---@class GenericBuildSource : RegistryPackageSource
+---@field build BuildInstruction | BuildInstruction[]
+
+---@param source GenericBuildSource
+---@param purl Purl
+---@param opts PackageInstallOpts
+function M.parse(source, purl, opts)
+ return Result.try(function(try)
+ ---@type BuildInstruction
+ local build_instruction = try(util.coalesce_by_target(source.build, opts):ok_or "PLATFORM_UNSUPPORTED")
+
+ if build_instruction.env then
+ local expr_ctx = { version = purl.version, target = build_instruction.target }
+ build_instruction.env = try(expr.tbl_interpolate(build_instruction.env, expr_ctx))
+ end
+
+ ---@class ParsedGenericBuildSource : ParsedPackageSource
+ local parsed_source = {
+ build = build_instruction,
+ }
+ return parsed_source
+ end)
+end
+
+---@async
+---@param ctx InstallContext
+---@param source ParsedGenericBuildSource
+function M.install(ctx, source)
+ return build.run(source.build)
+end
+
+return M
diff --git a/lua/mason-core/installer/registry/providers/generic.lua b/lua/mason-core/installer/registry/providers/generic/download.lua
index 5f5cb6bf..a7e4d046 100644
--- a/lua/mason-core/installer/registry/providers/generic.lua
+++ b/lua/mason-core/installer/registry/providers/generic/download.lua
@@ -9,10 +9,10 @@ local M = {}
---@field target (Platform | Platform[])?
---@field files table<string, string>
----@class GenericSource : RegistryPackageSource
+---@class GenericDownloadSource : RegistryPackageSource
---@field download GenericDownload | GenericDownload[]
----@param source GenericSource
+---@param source GenericDownloadSource
---@param purl Purl
---@param opts PackageInstallOpts
function M.parse(source, purl, opts)
@@ -23,7 +23,7 @@ function M.parse(source, purl, opts)
---@type { files: table<string, string> }
local interpolated_download = try(expr.tbl_interpolate(download, expr_ctx))
- ---@class ParsedGenericSource : ParsedPackageSource
+ ---@class ParsedGenericDownloadSource : ParsedPackageSource
local parsed_source = {
download = interpolated_download,
}
@@ -33,7 +33,7 @@ end
---@async
---@param ctx InstallContext
----@param source ParsedGenericSource
+---@param source ParsedGenericDownloadSource
function M.install(ctx, source)
local std = require "mason-core.installer.managers.std"
return Result.try(function(try)
diff --git a/lua/mason-core/installer/registry/providers/generic/init.lua b/lua/mason-core/installer/registry/providers/generic/init.lua
new file mode 100644
index 00000000..a511471e
--- /dev/null
+++ b/lua/mason-core/installer/registry/providers/generic/init.lua
@@ -0,0 +1,36 @@
+local Result = require "mason-core.result"
+local _ = require "mason-core.functional"
+
+local M = {}
+
+---@param source GenericDownloadSource | GenericBuildSource
+---@param purl Purl
+---@param opts PackageInstallOpts
+function M.parse(source, purl, opts)
+ if source.download then
+ source = source --[[@as GenericDownloadSource]]
+ return require("mason-core.installer.registry.providers.generic.download").parse(source, purl, opts)
+ elseif source.build then
+ source = source --[[@as GenericBuildSource]]
+ return require("mason-core.installer.registry.providers.generic.build").parse(source, purl, opts)
+ else
+ return Result.failure "Unknown source type."
+ end
+end
+
+---@async
+---@param ctx InstallContext
+---@param source ParsedGenericDownloadSource | ParsedGenericBuildSource
+function M.install(ctx, source)
+ if source.download then
+ source = source --[[@as ParsedGenericDownloadSource]]
+ return require("mason-core.installer.registry.providers.generic.download").install(ctx, source)
+ elseif source.build then
+ source = source --[[@as ParsedGenericBuildSource]]
+ return require("mason-core.installer.registry.providers.generic.build").install(ctx, source)
+ else
+ return Result.failure "Unknown source type."
+ end
+end
+
+return M
diff --git a/lua/mason-core/installer/registry/providers/github/build.lua b/lua/mason-core/installer/registry/providers/github/build.lua
index e41cac33..bda0b655 100644
--- a/lua/mason-core/installer/registry/providers/github/build.lua
+++ b/lua/mason-core/installer/registry/providers/github/build.lua
@@ -1,27 +1,32 @@
local Result = require "mason-core.result"
local _ = require "mason-core.functional"
-local a = require "mason-core.async"
-local async_uv = require "mason-core.async.uv"
-local platform = require "mason-core.platform"
+local build = require "mason-core.installer.managers.build"
+local expr = require "mason-core.installer.registry.expr"
local util = require "mason-core.installer.registry.util"
----@class GitHubBuildInstruction
----@field target? Platform | Platform[]
----@field run string
+local M = {}
---@class GitHubBuildSource : RegistryPackageSource
----@field build GitHubBuildInstruction | GitHubBuildInstruction[]
-
-local M = {}
+---@field build BuildInstruction | BuildInstruction[]
---@param source GitHubBuildSource
---@param purl Purl
---@param opts PackageInstallOpts
function M.parse(source, purl, opts)
return Result.try(function(try)
- ---@type { run: string }
+ ---@type BuildInstruction
local build_instruction = try(util.coalesce_by_target(source.build, opts):ok_or "PLATFORM_UNSUPPORTED")
+ local expr_ctx = { version = purl.version }
+
+ -- TODO: In a few releases of the core registry, r-languageserver reads $MASON_VERSION directly. Remove this
+ -- some time in the future.
+ local default_env = {
+ MASON_VERSION = purl.version,
+ }
+ build_instruction.env =
+ vim.tbl_extend("force", default_env, try(expr.tbl_interpolate(build_instruction.env or {}, expr_ctx)))
+
---@class ParsedGitHubBuildSource : ParsedPackageSource
local parsed_source = {
build = build_instruction,
@@ -35,35 +40,11 @@ end
---@async
---@param ctx InstallContext
---@param source ParsedGitHubBuildSource
----@param purl Purl
-function M.install(ctx, source, purl)
+function M.install(ctx, source)
local std = require "mason-core.installer.managers.std"
return Result.try(function(try)
try(std.clone(source.repo, { rev = source.rev }))
- try(platform.when {
- unix = function()
- return ctx.spawn.bash {
- on_spawn = a.scope(function(_, stdio)
- local stdin = stdio[1]
- async_uv.write(stdin, "set -euxo pipefail;\n")
- async_uv.write(stdin, source.build.run)
- async_uv.shutdown(stdin)
- async_uv.close(stdin)
- end),
- env = {
- MASON_VERSION = purl.version,
- },
- }
- end,
- win = function()
- local powershell = require "mason-core.managers.powershell"
- return powershell.command(source.build.run, {
- env = {
- MASON_VERSION = purl.version,
- },
- }, ctx.spawn)
- end,
- })
+ try(build.run(source.build))
end)
end
diff --git a/lua/mason-core/installer/registry/providers/github/init.lua b/lua/mason-core/installer/registry/providers/github/init.lua
index f5c66d36..41dd893d 100644
--- a/lua/mason-core/installer/registry/providers/github/init.lua
+++ b/lua/mason-core/installer/registry/providers/github/init.lua
@@ -26,7 +26,7 @@ function M.install(ctx, source, purl)
return require("mason-core.installer.registry.providers.github.release").install(ctx, source)
elseif source.build then
source = source--[[@as ParsedGitHubBuildSource]]
- return require("mason-core.installer.registry.providers.github.build").install(ctx, source, purl)
+ return require("mason-core.installer.registry.providers.github.build").install(ctx, source)
else
return Result.failure "Unknown source type."
end