mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
Any work that can take noticeable time now runs under the UI's status line: a Reporter's Status with a label message, or a LoggedCmd step. The UI: - status lines are a stack: a Status or LoggedCmd inside another shows its own line, then the outer one is drawn again, where before it ended the outer one for good - a message (Info, Warn, Note, Say, data on Stdout/Stderr) clears the line, prints and draws it again below; an unended line holds it - a question (Ask, Confirm, Answer, Secret), the picker and ui.Terminal hold it until they're done - no status line starts once the run is interrupted, as nothing would clear it - the run log's path is read without the log's lock, as the status line reads it under outMu Covered, by site and label: - finder.target: finding_vm; Lima's limactl --version: checking_backend - bringUp's checks (seeds, instance, recordFolder, hostChecks, ssh, requirements) and a running VM's go-on (proxy, pins, mount check): checking_vm; startOnce after the agent: starting; the self-check's probes: checking_network; pinHostKeys: reading_host_keys - setUpVM (sync, ssh config, links, clone seed): setting_up_vm; each devcontainer command: running_script; makeMachine: creating; buildOnce: checking_image; paste's count and rm: reading_pasted - volumeOf's lookup (diskutil), for launch, adopt, move, ls and rm: looking_up_volume - vm.ListAll (devvm ls): reading_vms; devvm doctor's checks: doctor_checking - devvm agent import: agent_import_reading (walk, links, opencode), agent_store_saving (copy, marketplace git checks, tmutil); devvm agent save: agent_save_reading, agent_save_comparing, agent_store_saving - devvm stop (from its pins check on): checking_vm; a delete, an orphan's teardown and Lima's DeleteImage: deleting; devvm git-protect and clone on/off's .git work (leftBehind, mountFolder, unmountFolder): git_protecting; git-protect's re-read: finding_vm - devvm clone add: clone_reading, clone_adding; clone fetch: clone_fetching; planClone: clone_planning; the clone check before rm or a remake: clone_checking; history export and import: history_exporting, history_importing; a remake's home: saving_home, restoring_home - devvm upgrade's install: upgrade_installing; the shared tools' step back and .NET's downloads: resolving_tools; gc's caches: reading_space; the retention settings (daily and in gc): retaining Work that takes the terminal stays off: the shell, ssh-add's passphrase (checkAgent, Agent.Ensure, reloadAgent) and an agent's login. Tests and guard: - msg.Fake: OnStatus and Showing; its LoggedCmd shows its step - backendtest.Fake: OnCall - TestLaunchStatusLines: every backend call of a new, running and stopped VM's launch runs under a status line but the shell's and Running's (pid files) - TestSSHAddOffStatusLine: ssh-add, on the user's agent or devvm's, never runs under one; chflagsCalls fails a .git lock or unlock with none - the structure test's status-lines rule (statusSites, statusFree) - TestStatusLinesNest, TestMessagesClearTheStatusLine, TestQuestionsHoldTheStatusLine, TestSecretAndPickerHoldTheStatusLine, TestTerminalHoldsTheStatusLine, TestNoStatusLineOnceInterrupted, TestFakeStatus, TestAgentImportStatus, TestAgentSaveStatus, TestDoctorReport, TestProblems, TestList, TestListLooksUpVolumesOnce, TestVolumeOfCache, TestWithSDKDownloads, TestRetainStatus, TestSetCloneOn, TestTeardownLeavesNothing The rule is written in the cli skill (rule 14, checklist, review), the codebase-standards skill (Show what devvm waits for, its checklist line and rules.md's row), Contributing's CLI page (Status lines), its tests and structure pages, and the troubleshooting page. Co-Authored-By: Claude Opus 5.5 <[email protected]>
175 lines
5.2 KiB
Go
175 lines
5.2 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"maps"
|
|
"regexp"
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/devvmhq/devvm/internal/fetch"
|
|
"github.com/devvmhq/devvm/internal/image"
|
|
"github.com/devvmhq/devvm/internal/msg"
|
|
)
|
|
|
|
// The .NET SDK's downloads. mise locks dotnet's version alone, without a
|
|
// download, as its installer runs Microsoft's install script, which
|
|
// nothing pins and which checks nothing. So devvm adds each platform's SDK
|
|
// archive and its SHA-512 to the lock's dotnet entries from Microsoft's
|
|
// release metadata, as mise does for the other tools from their releases'
|
|
// checksums, and shared-tools/build.sh checks the archive against the lock.
|
|
|
|
// dotnetReleases is where Microsoft lists a .NET channel's releases, each
|
|
// SDK with its files and their SHA-512: a format taking the channel, such
|
|
// as 10.0.
|
|
const dotnetReleases = "https://builds.dotnet.microsoft.com/dotnet/release-metadata/%s/releases.json"
|
|
|
|
// dotnetFiles is where every SDK archive the lock records comes from.
|
|
const dotnetFiles = "https://builds.dotnet.microsoft.com/dotnet/"
|
|
|
|
// releasesCap caps a channel's release list, which is a few MB.
|
|
const releasesCap = 32 << 20
|
|
|
|
var (
|
|
dotnetVersion = regexp.MustCompile(`^([0-9]+\.[0-9]+)\.[0-9]+$`)
|
|
sha512Hex = regexp.MustCompile(`^[0-9a-f]{128}$`)
|
|
)
|
|
|
|
// dotnetRID is Microsoft's name for a lock's platform: linux-x64-musl is
|
|
// linux-musl-x64.
|
|
func dotnetRID(platform string) string {
|
|
arch, musl := strings.CutSuffix(strings.TrimPrefix(platform, "linux-"), "-musl")
|
|
if musl {
|
|
return "linux-musl-" + arch
|
|
}
|
|
return "linux-" + arch
|
|
}
|
|
|
|
// dotnetSDK is an SDK release as a channel's releases.json has it.
|
|
type dotnetSDK struct {
|
|
Version string `json:"version"`
|
|
Files []struct {
|
|
Name string `json:"name"`
|
|
RID string `json:"rid"`
|
|
URL string `json:"url"`
|
|
Hash string `json:"hash"`
|
|
} `json:"files"`
|
|
}
|
|
|
|
// download is the SDK's archive for a lock's platform and its SHA-512, in
|
|
// hex: false when Microsoft lists none, or one that isn't an https URL of
|
|
// its own downloads with a SHA-512.
|
|
func (s dotnetSDK) download(platform string) (url, sha512 string, ok bool) {
|
|
rid := dotnetRID(platform)
|
|
for _, f := range s.Files {
|
|
h := strings.ToLower(f.Hash)
|
|
if f.RID == rid && f.Name == "dotnet-sdk-"+rid+".tar.gz" && strings.HasPrefix(f.URL, dotnetFiles) &&
|
|
strings.HasSuffix(f.URL, ".tar.gz") && sha512Hex.MatchString(h) {
|
|
return f.URL, h, true
|
|
}
|
|
}
|
|
return "", "", false
|
|
}
|
|
|
|
// dotnetSDKs reads a channel's releases.json: its SDKs, each release's
|
|
// own and the others it lists.
|
|
func dotnetSDKs(data []byte) ([]dotnetSDK, error) {
|
|
var doc struct {
|
|
Releases []struct {
|
|
SDK *dotnetSDK `json:"sdk"`
|
|
SDKs []dotnetSDK `json:"sdks"`
|
|
} `json:"releases"`
|
|
}
|
|
if err := json.Unmarshal(data, &doc); err != nil {
|
|
return nil, err
|
|
}
|
|
var out []dotnetSDK
|
|
for _, r := range doc.Releases {
|
|
if r.SDK != nil {
|
|
out = append(out, *r.SDK)
|
|
}
|
|
out = append(out, r.SDKs...)
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// withSDKDownloads returns the lock with Microsoft's downloads added to
|
|
// each entry of a tool build.sh fetches itself (image.OwnDownload) that
|
|
// lacks one for some platform: the SDK's archive, for each platform
|
|
// Microsoft has one for, and its SHA-512. Entries with all of them stay as
|
|
// they are, and so does a lock where all have them. A version Microsoft
|
|
// doesn't list keeps none, which the step back sees; a channel's list it
|
|
// can't get fails.
|
|
func (t Versions) withSDKDownloads(ctx context.Context, lock Lock) (Lock, error) {
|
|
defer t.Status(msg.ResolvingTools())()
|
|
channels := map[string][]dotnetSDK{}
|
|
for _, d := range image.SharedTools {
|
|
for _, tool := range d.Members {
|
|
if !image.OwnDownload(tool) {
|
|
continue
|
|
}
|
|
es := slices.Clone(lock.entries(tool))
|
|
changed := false
|
|
for i, e := range es {
|
|
if hasDownload(e, t.platforms()) {
|
|
continue
|
|
}
|
|
sdk, err := t.dotnetSDK(ctx, channels, str(e, "version"))
|
|
if err != nil {
|
|
return Lock{}, err
|
|
}
|
|
e = maps.Clone(e)
|
|
for _, p := range t.platforms() {
|
|
if url, sum, ok := sdk.download(p); ok {
|
|
e["platforms."+p] = map[string]any{"checksum": "sha512:" + sum, "url": url}
|
|
es[i], changed = e, true
|
|
}
|
|
}
|
|
}
|
|
if !changed {
|
|
continue
|
|
}
|
|
var err error
|
|
if lock, err = lock.withEntries(tool, es); err != nil {
|
|
return Lock{}, err
|
|
}
|
|
}
|
|
}
|
|
return lock, nil
|
|
}
|
|
|
|
// dotnetSDK returns the SDK of a version from its channel's releases.json,
|
|
// which it gets once per channel (channels): an empty one when the
|
|
// version isn't shaped like an SDK's or the channel doesn't list it.
|
|
func (t Versions) dotnetSDK(ctx context.Context, channels map[string][]dotnetSDK, version string) (dotnetSDK, error) {
|
|
m := dotnetVersion.FindStringSubmatch(version)
|
|
if m == nil {
|
|
return dotnetSDK{}, nil
|
|
}
|
|
sdks, ok := channels[m[1]]
|
|
if !ok {
|
|
url := fmt.Sprintf(t.dotnetURL, m[1])
|
|
var data []byte
|
|
err := fetch.Retry(ctx, downloadRetries, t.RetryDelay, func() (bool, error) {
|
|
var err error
|
|
data, err = fetch.Get(ctx, t.Client, url, releasesCap)
|
|
return fetch.Transient(err), err
|
|
})
|
|
if err == nil {
|
|
sdks, err = dotnetSDKs(data)
|
|
}
|
|
if err != nil {
|
|
return dotnetSDK{}, fmt.Errorf("dotnet's releases: %w", err)
|
|
}
|
|
channels[m[1]] = sdks
|
|
}
|
|
for _, s := range sdks {
|
|
if s.Version == version {
|
|
return s, nil
|
|
}
|
|
}
|
|
return dotnetSDK{}, nil
|
|
}
|