forked from chipsalliance/verible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write install receipts (chipsalliance#379)
- Loading branch information
1 parent
63f6b21
commit e8530f4
Showing
51 changed files
with
522 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
local log = require "nvim-lsp-installer.log" | ||
local process = require "nvim-lsp-installer.process" | ||
local platform = require "nvim-lsp-installer.platform" | ||
|
||
---@param url string The url to fetch. | ||
---@param callback fun(err: string|nil, raw_data: string) | ||
local function fetch(url, callback) | ||
local stdio = process.in_memory_sink() | ||
log.fmt_debug("Fetching URL %s", url) | ||
local on_exit = function(success) | ||
if success then | ||
log.fmt_debug("Successfully fetched URL %s", url) | ||
callback(nil, table.concat(stdio.buffers.stdout, "")) | ||
else | ||
local stderr = table.concat(stdio.buffers.stderr, "") | ||
log.fmt_warn("Failed to fetch URL %s. stderr=%s", url, stderr) | ||
callback(("Failed to fetch url %q.\n%s"):format(url, stderr), nil) | ||
end | ||
end | ||
|
||
local job_variants = { | ||
process.lazy_spawn("wget", { | ||
args = { "-nv", "-O", "-", url }, | ||
stdio_sink = stdio.sink, | ||
}), | ||
process.lazy_spawn("curl", { | ||
args = { "-fsSL", url }, | ||
stdio_sink = stdio.sink, | ||
}), | ||
} | ||
|
||
if platform.is_win then | ||
local ps_script = { | ||
"$ProgressPreference = 'SilentlyContinue'", | ||
("Write-Output (iwr -UseBasicParsing -Uri %q).Content"):format(url), | ||
} | ||
table.insert( | ||
job_variants, | ||
1, | ||
process.lazy_spawn("powershell.exe", { | ||
args = { "-NoProfile", "-Command", table.concat(ps_script, ";") }, | ||
stdio_sink = stdio.sink, | ||
env = process.graft_env({}, { "PSMODULEPATH" }), | ||
}) | ||
) | ||
end | ||
|
||
process.attempt { | ||
jobs = job_variants, | ||
on_iterate = function() | ||
log.debug "Flushing stdout/stderr buffers." | ||
stdio.buffers.stdout = {} | ||
stdio.buffers.stderr = {} | ||
end, | ||
on_finish = on_exit, | ||
} | ||
end | ||
|
||
return fetch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
local M = {} | ||
|
||
---@alias InstallerReceiptSource table | ||
|
||
---@class InstallReceiptBuilder | ||
---@field private secondary_sources InstallerReceiptSource[] | ||
---@field private epoch_time number | ||
local InstallReceiptBuilder = {} | ||
InstallReceiptBuilder.__index = InstallReceiptBuilder | ||
|
||
function InstallReceiptBuilder.new() | ||
return setmetatable({ | ||
secondary_sources = {}, | ||
}, InstallReceiptBuilder) | ||
end | ||
|
||
---@param name string | ||
function InstallReceiptBuilder:with_name(name) | ||
self.name = name | ||
return self | ||
end | ||
|
||
---@alias InstallerReceiptSchemaVersion | ||
---| '"1.0"' | ||
|
||
---@param version InstallerReceiptSchemaVersion | ||
function InstallReceiptBuilder:with_schema_version(version) | ||
self.schema_version = version | ||
return self | ||
end | ||
|
||
---@param source InstallerReceiptSource | ||
function InstallReceiptBuilder:with_primary_source(source) | ||
self.primary_source = source | ||
return self | ||
end | ||
|
||
---@param source InstallerReceiptSource | ||
function InstallReceiptBuilder:with_secondary_source(source) | ||
table.insert(self.secondary_sources, source) | ||
return self | ||
end | ||
|
||
---@param seconds integer | ||
---@param microseconds integer | ||
local function to_ms(seconds, microseconds) | ||
return (seconds * 1000) + math.floor(microseconds / 1000) | ||
end | ||
|
||
---vim.loop.gettimeofday() | ||
---@param seconds integer | ||
---@param microseconds integer | ||
function InstallReceiptBuilder:with_completion_time(seconds, microseconds) | ||
self.completion_time = to_ms(seconds, microseconds) | ||
return self | ||
end | ||
|
||
---vim.loop.gettimeofday() | ||
---@param seconds integer | ||
---@param microseconds integer | ||
function InstallReceiptBuilder:with_start_time(seconds, microseconds) | ||
self.start_time = to_ms(seconds, microseconds) | ||
return self | ||
end | ||
|
||
function InstallReceiptBuilder:build() | ||
assert(self.name, "name is required") | ||
assert(self.schema_version, "schema_version is required") | ||
assert(self.start_time, "start_time is required") | ||
assert(self.completion_time, "completion_time is required") | ||
assert(self.primary_source, "primary_source is required") | ||
return { | ||
name = self.name, | ||
schema_version = self.schema_version, | ||
metrics = { | ||
start_time = self.start_time, | ||
completion_time = self.completion_time, | ||
}, | ||
primary_source = self.primary_source, | ||
secondary_sources = self.secondary_sources, | ||
} | ||
end | ||
|
||
---@param type string | ||
local function package_source(type) | ||
---@param package string | ||
return function(package) | ||
return { type = type, package = package } | ||
end | ||
end | ||
|
||
InstallReceiptBuilder.npm = package_source "npm" | ||
InstallReceiptBuilder.pip3 = package_source "pip3" | ||
InstallReceiptBuilder.gem = package_source "gem" | ||
InstallReceiptBuilder.go = package_source "go" | ||
InstallReceiptBuilder.dotnet = package_source "dotnet" | ||
|
||
InstallReceiptBuilder.unmanaged = { type = "unmanaged" } | ||
|
||
---@param dependency string | ||
function InstallReceiptBuilder.system(dependency) | ||
return { type = "system", dependency = dependency } | ||
end | ||
|
||
---@param remote_url string | ||
---@param revision string | ||
function InstallReceiptBuilder.git_remote(remote_url, revision) | ||
return { type = "git", remote = remote_url, revision = revision } | ||
end | ||
|
||
---@param ctx ServerInstallContext | ||
---@param opts UseGithubReleaseOpts|nil | ||
function InstallReceiptBuilder.github_release_file(ctx, opts) | ||
opts = opts or {} | ||
return { | ||
type = "github_release_file", | ||
repo = ctx.github_repo, | ||
file = ctx.github_release_file, | ||
release = ctx.requested_server_version, | ||
tag_name_pattern = opts.tag_name_pattern, | ||
} | ||
end | ||
|
||
function InstallReceiptBuilder.github_tag(ctx) | ||
return { | ||
type = "github_tag", | ||
repo = ctx.github_repo, | ||
tag = ctx.requested_server_version, | ||
} | ||
end | ||
|
||
M.InstallReceiptBuilder = InstallReceiptBuilder | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.