function PLUGIN:PostInstall(ctx)
local file = require("file")
local root_path = ctx.rootPath
local version = nil
for _, info in pairs(ctx.sdkInfo) do
version = info.version
break
end
if not version then
error("Could not determine version from sdkInfo")
end
local temp_path = root_path .. "-temp"
local parent_path = file.join_path(root_path, "cmdline-tools")
local target_path = file.join_path(root_path, "cmdline-tools", version)
local is_windows = RUNTIME.osType == "windows"
if is_windows then
local cmd = require("cmd")
local system_root = os.getenv("SystemRoot") or "C:\\Windows"
local function run_powershell(command, env)
cmd.exec("powershell.exe -NoLogo -NoProfile -NonInteractive -Command " .. command, {
cwd = system_root,
env = env,
})
end
if file.exists(temp_path) then
run_powershell("Remove-Item -LiteralPath $env:TEMP_PATH -Recurse -Force", {
TEMP_PATH = temp_path,
})
end
run_powershell("Move-Item -LiteralPath $env:ROOT_PATH -Destination $env:TEMP_PATH", {
ROOT_PATH = root_path,
TEMP_PATH = temp_path,
})
run_powershell("New-Item -ItemType Directory -Force -Path $env:PARENT_PATH", {
PARENT_PATH = parent_path,
})
run_powershell("Move-Item -LiteralPath $env:TEMP_PATH -Destination $env:TARGET_PATH", {
TEMP_PATH = temp_path,
TARGET_PATH = target_path,
})
else
os.execute('rm -rf "' .. temp_path .. '"')
os.execute('mv "' .. root_path .. '" "' .. temp_path .. '"')
os.execute('mkdir -p "' .. parent_path .. '"')
os.execute('mv "' .. temp_path .. '" "' .. target_path .. '"')
end
local sdkmanager_name = is_windows and "sdkmanager.bat" or "sdkmanager"
local sdkmanager_path = file.join_path(target_path, "bin", sdkmanager_name)
if not file.exists(sdkmanager_path) then
error("Installation verification failed: sdkmanager not found at " .. sdkmanager_path)
end
if not is_windows then
os.execute('chmod +x "' .. file.join_path(target_path, "bin") .. '"/* 2>/dev/null || true')
end
end