|
| 1 | +local http = require("http") |
| 2 | +local json = require("json") |
| 3 | +local env = require("env") |
| 4 | + |
| 5 | +function fetchVersions() |
| 6 | + local versionList |
| 7 | + local githubURL = os.getenv("GITHUB_URL") or "https://github.com/" |
| 8 | + -- Fetch from the same manifest as vfox-clang since clang-format versions match clang |
| 9 | + local resp, err = http.get({ |
| 10 | + url = githubURL:gsub("/$", "") .. "/version-fox/vfox-clang/releases/manifest", |
| 11 | + }) |
| 12 | + if err ~= nil then |
| 13 | + error("Failed to request: " .. err) |
| 14 | + end |
| 15 | + if resp.status_code ~= 200 then |
| 16 | + error("Failed to get versions: " .. err .. "\nstatus_code => " .. resp.status_code) |
| 17 | + end |
| 18 | + |
| 19 | + versionList = resp.body:match("<code>(.-)</code>") |
| 20 | + versionList = json.decode(versionList)["conda-forge"] |
| 21 | + |
| 22 | + return versionList |
| 23 | +end |
| 24 | + |
| 25 | +-- available.lua |
| 26 | +function fetchAvailable() |
| 27 | + local result = {} |
| 28 | + |
| 29 | + for i, v in ipairs(fetchVersions()) do |
| 30 | + if i == 1 then |
| 31 | + table.insert(result, { |
| 32 | + version = v, |
| 33 | + note = "latest", |
| 34 | + }) |
| 35 | + else |
| 36 | + table.insert(result, { |
| 37 | + version = v, |
| 38 | + }) |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + return result |
| 43 | +end |
| 44 | + |
| 45 | +-- pre_install.lua |
| 46 | +function getDownloadInfo(version) |
| 47 | + local file |
| 48 | + local ClangVersions = fetchVersions() |
| 49 | + |
| 50 | + if version == "latest" then |
| 51 | + version = ClangVersions[1] |
| 52 | + end |
| 53 | + if not hasValue(ClangVersions, version) then |
| 54 | + print("Unsupported version: " .. version) |
| 55 | + os.exit(1) |
| 56 | + end |
| 57 | + file = generatePixi(RUNTIME.osType, RUNTIME.archType) |
| 58 | + |
| 59 | + return file, version |
| 60 | +end |
| 61 | + |
| 62 | +function hasValue(table, value) |
| 63 | + for _, v in ipairs(table) do |
| 64 | + if v == value then |
| 65 | + return true |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + return false |
| 70 | +end |
| 71 | + |
| 72 | +function generatePixi(osType, archType) |
| 73 | + local file |
| 74 | + local githubURL = os.getenv("GITHUB_URL") or "https://github.com/" |
| 75 | + local releaseURL = githubURL:gsub("/$", "") .. "/prefix-dev/pixi/releases/" |
| 76 | + |
| 77 | + if archType == "arm64" then |
| 78 | + archType = "aarch64" |
| 79 | + elseif archType == "amd64" then |
| 80 | + archType = "x86_64" |
| 81 | + else |
| 82 | + print("Unsupported architecture: " .. archType) |
| 83 | + os.exit(1) |
| 84 | + end |
| 85 | + if osType == "darwin" then |
| 86 | + file = "pixi-" .. archType .. "-apple-darwin.tar.gz" |
| 87 | + elseif osType == "linux" then |
| 88 | + file = "pixi-" .. archType .. "-unknown-linux-musl.tar.gz" |
| 89 | + elseif osType == "windows" then |
| 90 | + file = "pixi-" .. archType .. "-pc-windows-msvc.zip" |
| 91 | + else |
| 92 | + print("Unsupported environment: " .. osType .. "-" .. archType) |
| 93 | + os.exit(1) |
| 94 | + end |
| 95 | + file = releaseURL .. "latest/download/" .. file |
| 96 | + |
| 97 | + return file |
| 98 | +end |
| 99 | + |
| 100 | +-- post_install.lua |
| 101 | +function pixiInstall(path, version) |
| 102 | + local condaForge = os.getenv("Conda_Forge") or "conda-forge" |
| 103 | + local noStdout = RUNTIME.osType == "windows" and " > nul" or " > /dev/null" |
| 104 | + local pixi = RUNTIME.osType == "windows" and path .. "\\pixi.exe" or path .. "/pixi" |
| 105 | + local command = pixi .. " global install -qc " .. condaForge .. " clang-format=" .. version |
| 106 | + env.setenv("PIXI_HOME", path) |
| 107 | + |
| 108 | + local status = os.execute(command .. noStdout) |
| 109 | + if status ~= 0 then |
| 110 | + print("Failed to execute command: " .. command) |
| 111 | + os.exit(1) |
| 112 | + end |
| 113 | + os.remove(pixi) |
| 114 | +end |
0 commit comments