Repository navigation
feat: declare target platforms in dbc.toml - #608
Conversation
zeroshade
left a comment
There was a problem hiding this comment.
Nice design overall: matching on canonical targets with alias duplicates rejected, older-version fallback only as an explicit opt-in via platforms (so #584's default is unchanged), a missing build as a plain error rather than ErrPackageMiss, platforms in the lock file kept canonical, unique and enforced per driver, and measureDeclared checking extraction and signature before recording a measured hash. go vet and go test ./cmd/dbc/ ./ pass on the head.
Requesting changes for the first inline comment: relock re-resolves silently in cases where fromLock refuses, so changing platforms can move a driver to another version or registry without any message. The other comments are non-blocking.
Before merge: the base is feat/lock-without-host-build, so this needs retargeting once #607 lands, and it conflicts with #601's new ResolvePackage(drivers, indexErr, …) signature in both add.go and syncPlanner.resolve.
| } | ||
| if bound.HasQuery { | ||
| // Artifacts cannot be added from it (see fromLock). | ||
| return plannedDriver{}, false, nil |
There was a problem hiding this comment.
Blocking: when the locked registry URL has a query string, this returns kept=false and the driver is resolved again from the merged index, which can change its version and registry just because platforms changed. Only the signer check (oldSigner) guards it. fromLock refuses the same situation with "cannot be completed; delete the driver's entry from the lock file…". Could relock return that error too (or at least emit a warning that the entry was re-resolved)?
| d.Source.URL, name, redactRegistryError(err, p.registries, bound.BaseURL)) | ||
| } | ||
| drv, err := findDriver(name, drivers) | ||
| if err != nil || !coversPlatforms(drv, v, p.platforms) { |
There was a problem hiding this comment.
Blocking (same issue): a findDriver error, meaning the driver is no longer in its locked registry, is swallowed here and the driver silently re-resolved elsewhere. !coversPlatforms falling through to re-resolution is the intended behaviour, but a missing driver should be an error, as it is in fromLock.
| if err != nil { | ||
| return plannedDriver{}, false, fmt.Errorf("driver %s: %w", name, redactRegistryError(err, p.registries, bound.BaseURL)) | ||
| } | ||
| d.Artifacts = artifacts |
There was a problem hiding this comment.
Non-blocking: this replaces all artifacts with the declared ones plus whatever the current index publishes. Hashes for platforms that are not listed, measured earlier because the registry publishes none, are lost, and published ones are silently replaced from the current index. The impact is limited while platforms is declared, since sync refuses unlisted hosts, but it shows up once the declaration is removed. Keeping existing artifacts for unlisted targets would avoid that.
| } | ||
| // The copy shares the artifacts of the entry, so the measured hash is | ||
| // recorded there. The library proof only applies to the current target. | ||
| other := plannedDriver{Name: pd.Name, Entry: pd.Entry, Package: pkg, ArchiveSize: pd.Entry.Artifacts[i].Size, Signer: pd.Signer} |
There was a problem hiding this comment.
Non-blocking: the measured hash only reaches pd.Entry because checkDownloadedArchive writes through &pd.Entry.Artifacts[i] into the backing array the copy shares. Any future append/clone there would silently drop it. Writing the digest back to pd.Entry.Artifacts[i] explicitly after the download would make this robust.
|
|
||
| // eligibleVersion reports whether v may be selected for spec without a pin, | ||
| // like Driver.GetLatestVersionAnyPlatform does. | ||
| func eligibleVersion(spec driverSpec, v *semver.Version) bool { |
There was a problem hiding this comment.
Non-blocking: this repeats the eligibility rules of Driver.GetLatestVersionAnyPlatform (constraint decides prerelease eligibility, otherwise prerelease = 'allow'). A shared helper would keep them from drifting apart.
| // platformPackage returns the one package of version v for target t. A | ||
| // missing package and several packages for the same target (aliases or | ||
| // duplicates) are errors. | ||
| func platformPackage(d dbc.Driver, v *semver.Version, t resolution.Target) (dbc.PackageInfo, error) { |
There was a problem hiding this comment.
Non-blocking: coversPlatforms counts a version with two packages for the same target as covered, so newestCoveringVersion selects it and this then hard-errors without trying an older version that would work. Erroring is defensible for a required platform, but the docs or the message could say so.
| if hadLock && pd.Entry.Signer != oldSigner { | ||
| return nil, nil, signerChangedError(name, oldSigner) | ||
| } | ||
| if proof != "" && pd.Package.Version.String() != pin.String() { |
There was a problem hiding this comment.
Non-blocking: a dropped v1 pin is reported only when a checksum was recorded. Without one, the locked version changes with no message. A warning whenever the pin is dropped for not covering platforms would make that visible.
b285212 to
816ba91
Compare
|
I rebased onto the updated #607 branch and addressed the review in d2561d6 and 816ba91.
|
zeroshade
left a comment
There was a problem hiding this comment.
Thanks, d2561d6 and 816ba91 address everything: relock now fails like fromLock for a registry URL with a query string or a driver the registry no longer lists, and warns when re-resolution changes the version or registry. It keeps recorded artifacts and checks coverage only for missing declared platforms. measureDeclared writes the measured digest back explicitly. Eligibility is shared through resolution.VersionEligible. Ambiguous builds are documented, and a dropped v1 pin is always reported. The single warning for an undeclared platform in dbc lock is a nice touch. go vet ./... and the cmd/dbc, root and internal/resolution tests pass on the head.
Remaining before merge, as you noted: retarget to main after #607 lands, and resolve the #601 ResolvePackage conflict.
A top-level `platforms` list in dbc.toml selects, for dbc add, dbc lock and dbc sync, the newest allowed version that has a build for every listed platform. A missing build is not a package miss, so it never makes another registry serve the driver. A declared platform is handled like the current one: its archive is recorded with the hash the registry publishes, or downloaded, checked (safe extraction and, unless --no-verify is set, the signature) and measured. As before, other platforms with a published hash are recorded too. dbc sync fails on a platform that is not declared. dbc.lock records the declaration, and every driver has an artifact for each declared platform. A new or changed declaration resolves the drivers again, keeping the locked source, version and archive hashes where the version has a build for every declared platform; removing it keeps the lock entries. Without platforms, dbc add no longer needs a build of the selected version for the current platform either.
An entry that already records every declared platform is replayed as it is, without fetching any index, so a changed declaration cannot move a driver to another registry or change its hashes just because its registry no longer lists the locked version. An entry that is extended keeps the locked archive size of the current platform for the download check, as a replayed entry does. The lock reference now describes the cases without and with declared platforms separately.
- relock keeps every recorded artifact, declared or not, and checks only the declared platforms the entry does not record yet. - A locked registry with a query string or without the driver is an error, as in fromLock, instead of a silent re-resolution. - Warn when re-resolution or a dropped v1 pin selects another version or registry, and once when dbc lock runs on an undeclared platform. - Write the measured hash of a declared platform back explicitly. - Share version eligibility through internal/resolution.VersionEligible. - Name an ambiguous platform build in the error.
Part of #592. As noted in the review of #575, `dbc lock` required a build for the current platform, so a Linux CI runner could not lock a macOS-only driver. If the selected version has no build for the current platform, `dbc lock` records builds with published archive hashes. It downloads no archives for other platforms and fails if it cannot record any. If an existing entry lacks an artifact for the current platform and the locked version has no build for it, `dbc lock` keeps the entry. Version and registry selection remain independent of the current platform (#584). If the selected version lacks a build for that platform, `dbc sync` fails without switching versions or registries. Upgrading a v1 entry also fails if its library checksum was recorded for the current platform and there is no build to check it against. #608 adds declared platforms to `dbc.toml`.
816ba91 to
9338096
Compare
Close #592, and the project-side answer to the first review point of #584: instead of falling back to an older version that has a build for the machine running the command, a project can declare the platforms its drivers must support.
dbc add,dbc lockanddbc syncchoose the newest allowed version with a build for every listed platform, on every machine. A missing build does not trigger registry fallback. If the selected version lists more than one package for a listed platform that needs an artifact, dbc reports an error instead of selecting an older version. The list must contain at least one valid, distinct platform (an alias such asdarwin_arm64counts as a duplicate), and the current platform is not added implicitly.dbc syncrequires the current platform to be listed.dbc.lockrecords the declaration and an artifact for each listed platform. A listed platform is handled like the current one: for a new artifact, dbc records the published hash when available, and otherwise downloads the archive, checks it with the installation's extraction safeguards, verifies its signature unless--no-verifyis set, and records the measured hash. Other platforms are still recorded from published hashes.dbc lockwarns once when the current platform is not listed, becausedbc syncwill refuse it. It also warns when a v1 pin is dropped because its version lacks a listed platform, even if there was no checksum.Without
platforms, the implicit platform means two different things, on purpose:Treating the undeclared case as "every platform" would download every platform's archive to measure the hashes a registry does not publish; treating it as "the current platform" for selection would make the locked version depend on the machine.
dbc addnow also accepts a version without a build for the current platform.dbc install,dbc search -v,dbc infoanddbc listignoreplatforms:installpicks the newest version with a build for the current platform (#584),search -vlists the versions available for it,infoshows the latest version's packages for every platform, andlistshows installed drivers.