Add Pixi-style project environments and SAT dependency solver
- Add orbit.toml project manifests, deterministic orbit.lock files, [tasks], and `orbit run` - Add per-project .orbit/bin environments; `-g`/`--global` targets the global environment - Replace greedy global resolution with a lazy CDCL SAT solver that explains conflicts - Support channel::pkg dependency pins and comma-separated, comparison, and wildcard constraints - Cache immutable sha256 manifests under ~/.orbit/cache/manifests - Validate dependency keys and constraints in orbit.json
This commit is contained in:
1 parent
0919ce105c
commit
13aa7d7f77
9 files changed
+4552
-255
No files matched your search
@@ -7,13 +7,14 @@ A small package manager written in MoonBit that uses any OCI registry (Gitea, GH
|
|||||||
## What it does
|
## What it does
|
||||||
|
|
||||||
- **Publish:** `orbit publish <dir>` packs `<dir>/files/` into `pkg.tar.gz` and pushes it with `<dir>/orbit.json` as the OCI config blob.
|
- **Publish:** `orbit publish <dir>` packs `<dir>/files/` into `pkg.tar.gz` and pushes it with `<dir>/orbit.json` as the OCI config blob.
|
||||||
- **Install with dependencies:** it reads only the small config blob from the OCI registry to plan, then streams the layers by digest with SHA-256 verification.
|
- **Lazy CDCL SAT solver:** resolves global and project dependency graphs with backtracking, conflict explanations, and `channel::pkg` dependency pins, reading only needed config blobs and caching immutable `sha256` manifests under `~/.orbit/cache/manifests/`.
|
||||||
- **Version constraints:** `1.2.3`, `1.2`, `^1.2.0`, `~1.2.0`, `>=1.2`, `*`. Prereleases match only when the constraint asks for one.
|
- **Pixi-style project environments:** `orbit new`, `orbit.toml` manifests, deterministic `orbit.lock` lockfiles, `[tasks]`, `orbit run`, and isolated `.orbit/bin/` environments symlinked from the shared store (`-g` / `--global` targets the global environment inside a project).
|
||||||
- **Content-addressed store:** packages unpack into `~/.orbit/store/<name>/<digest>/`, and their binaries are symlinked into `~/.orbit/bin/`.
|
- **Version constraints:** `1.2.3`, `=1.2.3`, `==1.2.3`, `1.2`, `1.2.*`, `^1.2.0`, `~1.2.0`, `>=1.2`, `<=2.0`, `>1.0`, `<2.0`, `!=1.3.0`, `*`, and comma-separated ranges (`>=1.2.0, <2.0.0`). Prereleases match only when the constraint mentions a `-`.
|
||||||
|
- **Content-addressed store:** packages unpack into `~/.orbit/store/<name>/<digest>/`, and their binaries are symlinked into `~/.orbit/bin/` (global) or `<project>/.orbit/bin/` (project).
|
||||||
- **File ownership:** two packages can't provide the same binary.
|
- **File ownership:** two packages can't provide the same binary.
|
||||||
- **Upgrade and rollback:** the previous two builds are kept, and `orbit rollback <name>` switches back instantly with no network.
|
- **Upgrade and rollback:** global installs keep the previous two builds, and `orbit rollback <name>` switches back instantly with no network.
|
||||||
- **Remove:** `orbit remove` refuses to delete what other packages need, then autoremoves orphaned dependencies.
|
- **Remove:** `orbit remove` refuses to delete what other global packages need and autoremoves orphaned dependencies; in projects it updates `orbit.toml` and `orbit.lock`.
|
||||||
- **gc** deletes builds that are neither current nor kept for rollback.
|
- **gc** deletes store builds that are neither globally current nor kept for rollback.
|
||||||
|
|
||||||
## Package format
|
## Package format
|
||||||
|
|
||||||
@@ -52,6 +53,8 @@ Because these are ordinary OCI artifacts, you can sign them with `cosign` or `no
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
### Global environment
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
orbit login git.site.latha.org # once, with a Gitea token (needed to publish)
|
orbit login git.site.latha.org # once, with a Gitea token (needed to publish)
|
||||||
eval "$(orbit env)"
|
eval "$(orbit env)"
|
||||||
@@ -64,6 +67,40 @@ orbit rollback hello
|
|||||||
orbit remove hello
|
orbit remove hello
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Project workflow (Pixi-style)
|
||||||
|
|
||||||
|
Inside a directory with `orbit.toml` (or pass `--manifest-path <path>`), commands target the project unless you pass `-g` / `--global`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
orbit new myapp && cd myapp
|
||||||
|
orbit add hello example::greet
|
||||||
|
orbit run greet
|
||||||
|
orbit lock --update
|
||||||
|
orbit install --locked
|
||||||
|
orbit update
|
||||||
|
orbit remove hello
|
||||||
|
```
|
||||||
|
|
||||||
|
An `orbit.toml` looks like:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[project]
|
||||||
|
name = "myapp"
|
||||||
|
version = "0.1.0"
|
||||||
|
channels = ["example", "main"]
|
||||||
|
|
||||||
|
[[channels]]
|
||||||
|
name = "example"
|
||||||
|
url = "git.site.latha.org/nandi/example"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
hello = "^1.0.0"
|
||||||
|
greet = { version = ">=1.0.0, <2.0.0", channel = "example" }
|
||||||
|
|
||||||
|
[tasks]
|
||||||
|
hi = "greet"
|
||||||
|
```
|
||||||
|
|
||||||
Credentials are stored in `~/.orbit/auth.json` (`$ORBIT_ROOT/auth.json`, mode `0600`). Orbit also falls back to `~/.docker/config.json` (`$DOCKER_CONFIG/config.json`) including `credHelpers` and `credsStore`. Use `orbit logout <host>` to remove stored credentials from Orbit.
|
Credentials are stored in `~/.orbit/auth.json` (`$ORBIT_ROOT/auth.json`, mode `0600`). Orbit also falls back to `~/.docker/config.json` (`$DOCKER_CONFIG/config.json`) including `credHelpers` and `credsStore`. Use `orbit logout <host>` to remove stored credentials from Orbit.
|
||||||
|
|
||||||
## Channels
|
## Channels
|
||||||
@@ -159,12 +196,15 @@ src/main/
|
|||||||
sha256.mbt streaming FIPS 180-4 SHA-256 (+ tests)
|
sha256.mbt streaming FIPS 180-4 SHA-256 (+ tests)
|
||||||
auth.mbt credentials store (~/.orbit/auth.json + Docker config fallback)
|
auth.mbt credentials store (~/.orbit/auth.json + Docker config fallback)
|
||||||
oci.mbt OCI Distribution v2 HTTP transport, Bearer/Basic auth, redirects
|
oci.mbt OCI Distribution v2 HTTP transport, Bearer/Basic auth, redirects
|
||||||
semver.mbt versions, constraints, tag selection (+ tests)
|
semver.mbt versions, relational/compound constraints, tag selection (+ tests)
|
||||||
model.mbt orbit.json / state.json / config.json (+ tests)
|
model.mbt orbit.json / state.json / config.json (+ tests)
|
||||||
registry.mbt OCI registry ops: tags, resolve, fetch, publish, login verify
|
registry.mbt OCI registry ops: tags, resolve, cached manifests, fetch, publish, login
|
||||||
ops.mbt dependency planner, install/remove/upgrade/rollback/gc
|
solver.mbt lazy Resolvo-style CDCL SAT solver & UNSAT explainer (+ tests)
|
||||||
|
ops.mbt SAT-backed global install/upgrade, remove/rollback/gc/search
|
||||||
|
project.mbt orbit.toml, orbit.lock, .orbit/ environments, project CLI (+ tests)
|
||||||
channels.mbt config.toml, channel priority and lookup (+ tests)
|
channels.mbt config.toml, channel priority and lookup (+ tests)
|
||||||
main.mbt CLI
|
main.mbt CLI
|
||||||
|
registry_wbtest.mbt mock-OCI registry, SAT global, and project workflow tests
|
||||||
```
|
```
|
||||||
|
|
||||||
## Toolchain notes
|
## Toolchain notes
|
||||||
@@ -178,7 +218,7 @@ Fixes needed for current MoonBit, kept here in case you build with an older comp
|
|||||||
|
|
||||||
## Known limits
|
## Known limits
|
||||||
|
|
||||||
- Dependency resolution is greedy (highest satisfying version, first come), not a SAT solver.
|
|
||||||
- There's no lock file for concurrent runs, and no install hooks, by design.
|
- There's no lock file for concurrent runs, and no install hooks, by design.
|
||||||
- `orbit info <name>` reads installed package details without contacting the registry. Use `orbit versions <name>` to check published versions.
|
- `orbit gc` only preserves global current and rollback builds (run `orbit install` / `orbit sync` in a project to re-populate missing store entries from its `orbit.lock`).
|
||||||
|
- `orbit info <name>` reads globally installed package details without contacting the registry. Use `orbit versions <name>` to check published versions.
|
||||||
- `search` needs the registry's catalog API, which Gitea doesn't expose. Use `orbit versions <name>` if you already know the package name.
|
- `search` needs the registry's catalog API, which Gitea doesn't expose. Use `orbit versions <name>` if you already know the package name.
|
||||||
+166
-18
@@ -4,8 +4,22 @@
|
|||||||
let usage : String =
|
let usage : String =
|
||||||
#|orbit - packages as OCI artifacts
|
#|orbit - packages as OCI artifacts
|
||||||
#|
|
#|
|
||||||
#|usage:
|
#|usage (project workflow, when orbit.toml is present):
|
||||||
#| orbit init create folders and config.toml
|
#| orbit new [dir] create a project orbit.toml
|
||||||
|
#| orbit add [channel::]<name>[@constraint]...
|
||||||
|
#| solve, pin in orbit.toml, lock & sync
|
||||||
|
#| orbit install [--locked | --frozen] sync .orbit/ from orbit.toml / orbit.lock
|
||||||
|
#| orbit sync [--locked | --frozen] same as `orbit install` in a project
|
||||||
|
#| orbit lock [--update] resolve and write orbit.lock
|
||||||
|
#| orbit update [name...] upgrade locked packages within constraints
|
||||||
|
#| orbit remove <name>... remove from orbit.toml, re-lock & sync
|
||||||
|
#| orbit run [--locked | --frozen] <cmd|task> [args...]
|
||||||
|
#| run a command or [tasks] entry in .orbit
|
||||||
|
#| orbit list show locked project packages
|
||||||
|
#| orbit env print PATH for .orbit/bin + global bin
|
||||||
|
#|
|
||||||
|
#|usage (global & registry commands; add -g/--global inside a project):
|
||||||
|
#| orbit init [--project] create ~/.orbit (or --project for orbit.toml)
|
||||||
#| orbit login <host> [-u <user>] [-p <pass> | --password-stdin] [--plain-http]
|
#| orbit login <host> [-u <user>] [-p <pass> | --password-stdin] [--plain-http]
|
||||||
#| log in to an OCI registry
|
#| log in to an OCI registry
|
||||||
#| orbit logout <host> remove stored registry credentials
|
#| orbit logout <host> remove stored registry credentials
|
||||||
@@ -13,19 +27,21 @@ let usage : String =
|
|||||||
#| orbit channel add <name> <url> [--plain-http]
|
#| orbit channel add <name> <url> [--plain-http]
|
||||||
#| orbit publish <dir> [--channel <name>] [--no-latest]
|
#| orbit publish <dir> [--channel <name>] [--no-latest]
|
||||||
#| push <dir>/orbit.json + <dir>/files/
|
#| push <dir>/orbit.json + <dir>/files/
|
||||||
#| orbit install [channel::]<name>[@constraint]...
|
#| orbit install [-g] [channel::]<name>[@constraint]...
|
||||||
#| install with dependencies
|
#| install globally with SAT dependency solving
|
||||||
#| orbit remove <name>... [--force] remove, then drop unused dependencies
|
#| orbit remove [-g] <name>... [--force] remove, then drop unused dependencies
|
||||||
#| orbit upgrade [name...] upgrade within constraints
|
#| orbit upgrade [-g] [name...] jointly upgrade within constraints
|
||||||
#| orbit rollback <name> switch to the previous build
|
#| orbit rollback <name> switch to the previous global build
|
||||||
#| orbit list installed packages
|
#| orbit list [-g] installed global packages
|
||||||
#| orbit info [channel::]<name> installed package details (local only)
|
#| orbit info [channel::]<name> installed package details (local only)
|
||||||
#| orbit versions <name> published versions
|
#| orbit versions <name> published versions
|
||||||
#| orbit search [term] list repositories (needs catalog API)
|
#| orbit search [term] list repositories (needs catalog API)
|
||||||
#| orbit gc delete unused builds from the store
|
#| orbit gc delete unused builds from the store
|
||||||
#| orbit env print the PATH line for your shell
|
#| orbit env [-g] print the PATH line for your shell
|
||||||
#|
|
#|
|
||||||
#|constraints: 1.2.3 =1.2.3 1.2 ^1.2.0 ~1.2.0 >=1.2 *
|
#|flags: -g, --global --manifest-path <path> --locked --frozen
|
||||||
|
#|constraints: 1.2.3 =1.2.3 ==1.2.3 1.2.* ^1.2.0 ~1.2.0 >=1.2 <2.0 !=1.3.0 *
|
||||||
|
#| (comma-separated clauses are ANDed, e.g. ">=1.2.0, <2.0.0")
|
||||||
#|config: <orbit root>/config.toml
|
#|config: <orbit root>/config.toml
|
||||||
#|credentials: <orbit root>/auth.json (falls back to ~/.docker/config.json)
|
#|credentials: <orbit root>/auth.json (falls back to ~/.docker/config.json)
|
||||||
#|environment: ORBIT_ROOT (default ~/.orbit); ORBIT_REGISTRY and
|
#|environment: ORBIT_ROOT (default ~/.orbit); ORBIT_REGISTRY and
|
||||||
@@ -62,6 +78,34 @@ fn need(pos : Array[String], n : Int32, what : String) -> Unit raise OrbitError
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
async fn resolve_project_or_none(
|
||||||
|
force_global : Bool,
|
||||||
|
manifest_path : String?,
|
||||||
|
) -> String? raise OrbitError {
|
||||||
|
if force_global {
|
||||||
|
if manifest_path is Some(_) {
|
||||||
|
raise OrbitError("--global cannot be used with --manifest-path")
|
||||||
|
}
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
find_project_manifest(manifest_path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
async fn require_project_manifest(
|
||||||
|
manifest_path : String?,
|
||||||
|
) -> String raise OrbitError {
|
||||||
|
match find_project_manifest(manifest_path) {
|
||||||
|
Some(mf) => mf
|
||||||
|
None =>
|
||||||
|
raise OrbitError(
|
||||||
|
"no orbit.toml found in current or parent directories (run `orbit new` to create one)",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
||||||
if args.length() == 0 {
|
if args.length() == 0 {
|
||||||
@@ -74,10 +118,35 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
|||||||
let mut publish_to = MAIN_CHANNEL
|
let mut publish_to = MAIN_CHANNEL
|
||||||
let mut username : String? = None
|
let mut username : String? = None
|
||||||
let mut password : String? = None
|
let mut password : String? = None
|
||||||
|
let mut force_global = false
|
||||||
|
let mut manifest_path : String? = None
|
||||||
let mut i = 1
|
let mut i = 1
|
||||||
while i < args.length() {
|
while i < args.length() {
|
||||||
|
if cmd == "run" && pos.length() > 0 {
|
||||||
|
// Forward all flags/args after the command/task name verbatim.
|
||||||
|
pos.push(args[i])
|
||||||
|
i = i + 1
|
||||||
|
continue
|
||||||
|
}
|
||||||
let a = args[i]
|
let a = args[i]
|
||||||
if a == "--channel" {
|
if a == "--" {
|
||||||
|
i = i + 1
|
||||||
|
while i < args.length() {
|
||||||
|
pos.push(args[i])
|
||||||
|
i = i + 1
|
||||||
|
}
|
||||||
|
break
|
||||||
|
} else if a == "-g" || a == "--global" {
|
||||||
|
force_global = true
|
||||||
|
} else if a == "--manifest-path" {
|
||||||
|
if i + 1 >= args.length() {
|
||||||
|
raise OrbitError("usage: --manifest-path <path>")
|
||||||
|
}
|
||||||
|
manifest_path = Some(args[i + 1])
|
||||||
|
i = i + 1
|
||||||
|
} else if has_prefix(a, "--manifest-path=") {
|
||||||
|
manifest_path = Some(drop_chars(a, 16))
|
||||||
|
} else if a == "--channel" {
|
||||||
if cmd != "publish" || i + 1 >= args.length() {
|
if cmd != "publish" || i + 1 >= args.length() {
|
||||||
raise OrbitError("usage: orbit publish <dir> --channel <name>")
|
raise OrbitError("usage: orbit publish <dir> --channel <name>")
|
||||||
}
|
}
|
||||||
@@ -118,10 +187,19 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
|||||||
}
|
}
|
||||||
match cmd {
|
match cmd {
|
||||||
"help" | "-h" | "--help" => println(usage)
|
"help" | "-h" | "--help" => println(usage)
|
||||||
"init" => {
|
"new" => {
|
||||||
|
if force_global {
|
||||||
|
raise OrbitError("--global cannot be used with `orbit new`")
|
||||||
|
}
|
||||||
|
cmd_project_init(if pos.length() > 0 { Some(pos[0]) } else { None })
|
||||||
|
}
|
||||||
|
"init" =>
|
||||||
|
if flags.contains("--project") {
|
||||||
|
cmd_project_init(if pos.length() > 0 { Some(pos[0]) } else { None })
|
||||||
|
} else {
|
||||||
if pos.length() > 0 {
|
if pos.length() > 0 {
|
||||||
raise OrbitError(
|
raise OrbitError(
|
||||||
"init takes no arguments; use `orbit channel add <name> <url>`",
|
"init takes no arguments; use `orbit channel add <name> <url>` or `orbit new <dir>`",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
cmd_init()
|
cmd_init()
|
||||||
@@ -160,20 +238,90 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
|||||||
other => raise OrbitError("unknown channel command '\{other}'")
|
other => raise OrbitError("unknown channel command '\{other}'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"env" => println("export PATH=\"\{orbit_root()}/bin:$PATH\"")
|
"lock" => {
|
||||||
|
if force_global {
|
||||||
|
raise OrbitError("--global cannot be used with `orbit lock`")
|
||||||
|
}
|
||||||
|
let mf = require_project_manifest(manifest_path)
|
||||||
|
cmd_project_lock(load_ctx(), mf, flags.contains("--update"))
|
||||||
|
}
|
||||||
|
"sync" => {
|
||||||
|
if force_global {
|
||||||
|
raise OrbitError("--global cannot be used with `orbit sync`")
|
||||||
|
}
|
||||||
|
let mf = require_project_manifest(manifest_path)
|
||||||
|
cmd_project_sync(
|
||||||
|
load_ctx(),
|
||||||
|
mf,
|
||||||
|
flags.contains("--locked"),
|
||||||
|
flags.contains("--frozen"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
"run" => {
|
||||||
|
if force_global {
|
||||||
|
raise OrbitError("--global cannot be used with `orbit run`")
|
||||||
|
}
|
||||||
|
let mf = require_project_manifest(manifest_path)
|
||||||
|
need(pos, 1, "run [--locked|--frozen] <command|task> [args...]")
|
||||||
|
cmd_project_run(
|
||||||
|
load_ctx(),
|
||||||
|
mf,
|
||||||
|
pos,
|
||||||
|
flags.contains("--locked"),
|
||||||
|
flags.contains("--frozen"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
"env" =>
|
||||||
|
match resolve_project_or_none(force_global, manifest_path) {
|
||||||
|
Some(mf) => cmd_project_env(load_ctx(), mf)
|
||||||
|
None => println("export PATH=\"\{orbit_root()}/bin:$PATH\"")
|
||||||
|
}
|
||||||
"publish" => {
|
"publish" => {
|
||||||
need(pos, 1, "publish <dir>")
|
need(pos, 1, "publish <dir>")
|
||||||
let ch = find_channel(load_ctx(), publish_to)
|
let ch = find_channel(load_ctx(), publish_to)
|
||||||
publish(ch, pos[0], !flags.contains("--no-latest"))
|
publish(ch, pos[0], !flags.contains("--no-latest"))
|
||||||
}
|
}
|
||||||
"install" | "add" => cmd_install(load_ctx(), pos)
|
"install" =>
|
||||||
"remove" | "rm" => cmd_remove(load_ctx(), pos, flags.contains("--force"))
|
match resolve_project_or_none(force_global, manifest_path) {
|
||||||
"upgrade" | "up" => cmd_upgrade(load_ctx(), pos)
|
Some(mf) =>
|
||||||
|
if pos.length() == 0 {
|
||||||
|
cmd_project_sync(
|
||||||
|
load_ctx(),
|
||||||
|
mf,
|
||||||
|
flags.contains("--locked"),
|
||||||
|
flags.contains("--frozen"),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
raise OrbitError(
|
||||||
|
"in a project (found \{mf}), use `orbit add <pkg>...` to add dependencies or `orbit install -g <pkg>...` to install globally",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
None => cmd_install(load_ctx(), pos)
|
||||||
|
}
|
||||||
|
"add" =>
|
||||||
|
match resolve_project_or_none(force_global, manifest_path) {
|
||||||
|
Some(mf) => cmd_project_add(load_ctx(), mf, pos)
|
||||||
|
None => cmd_install(load_ctx(), pos)
|
||||||
|
}
|
||||||
|
"remove" | "rm" =>
|
||||||
|
match resolve_project_or_none(force_global, manifest_path) {
|
||||||
|
Some(mf) => cmd_project_remove(load_ctx(), mf, pos)
|
||||||
|
None => cmd_remove(load_ctx(), pos, flags.contains("--force"))
|
||||||
|
}
|
||||||
|
"upgrade" | "up" | "update" =>
|
||||||
|
match resolve_project_or_none(force_global, manifest_path) {
|
||||||
|
Some(mf) => cmd_project_update(load_ctx(), mf, pos)
|
||||||
|
None => cmd_upgrade(load_ctx(), pos)
|
||||||
|
}
|
||||||
"rollback" => {
|
"rollback" => {
|
||||||
need(pos, 1, "rollback <name>")
|
need(pos, 1, "rollback <name>")
|
||||||
cmd_rollback(load_ctx(), pos[0])
|
cmd_rollback(load_ctx(), pos[0])
|
||||||
}
|
}
|
||||||
"list" | "ls" => cmd_list(load_ctx())
|
"list" | "ls" =>
|
||||||
|
match resolve_project_or_none(force_global, manifest_path) {
|
||||||
|
Some(mf) => cmd_project_list(load_ctx(), mf)
|
||||||
|
None => cmd_list(load_ctx())
|
||||||
|
}
|
||||||
"info" => {
|
"info" => {
|
||||||
need(pos, 1, "info [channel::]<name>")
|
need(pos, 1, "info [channel::]<name>")
|
||||||
cmd_info(load_ctx(), pos[0])
|
cmd_info(load_ctx(), pos[0])
|
||||||
|
|||||||
+53
-3
@@ -179,6 +179,21 @@ fn valid_rel_path(p : String) -> Bool {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Split a dependency key "[channel::]name" into (channel_pin, package_name).
|
||||||
|
fn parse_dep_key(key : String) -> (String?, String) {
|
||||||
|
split_channel(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn valid_dep_key(key : String) -> Bool {
|
||||||
|
let (ch, name) = parse_dep_key(key)
|
||||||
|
match ch {
|
||||||
|
Some(c) => valid_name(c) && valid_name(name)
|
||||||
|
None => valid_name(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
fn parse_manifest(text : String) -> Manifest raise OrbitError {
|
fn parse_manifest(text : String) -> Manifest raise OrbitError {
|
||||||
let o = parse_object(text, "orbit.json")
|
let o = parse_object(text, "orbit.json")
|
||||||
@@ -203,10 +218,15 @@ fn parse_manifest(text : String) -> Manifest raise OrbitError {
|
|||||||
raise OrbitError("orbit.json: bin path '\{b}' must be relative")
|
raise OrbitError("orbit.json: bin path '\{b}' must be relative")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for dep, _ in m.depends {
|
for dep, constraint in m.depends {
|
||||||
if !valid_name(dep) {
|
if !valid_dep_key(dep) {
|
||||||
raise OrbitError("orbit.json: invalid dependency name '\{dep}'")
|
raise OrbitError("orbit.json: invalid dependency name '\{dep}'")
|
||||||
}
|
}
|
||||||
|
if !valid_constraint(constraint) {
|
||||||
|
raise OrbitError(
|
||||||
|
"orbit.json: invalid version constraint '\{constraint}' for '\{dep}'",
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m
|
m
|
||||||
}
|
}
|
||||||
@@ -367,15 +387,45 @@ fn bin_dir(ctx : Ctx) -> String {
|
|||||||
ctx.root + "/bin"
|
ctx.root + "/bin"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn cache_dir(root : String) -> String {
|
||||||
|
root + "/cache/manifests"
|
||||||
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
test "manifest roundtrip" {
|
test "manifest roundtrip" {
|
||||||
let m = parse_manifest(
|
let m = parse_manifest(
|
||||||
"{\"name\":\"hello\",\"version\":\"1.0.0\",\"bin\":[\"bin/hello\"],\"depends\":{\"lib\":\"^1\"}}",
|
"{\"name\":\"hello\",\"version\":\"1.0.0\",\"bin\":[\"bin/hello\"],\"depends\":{\"lib\":\"^1\",\"example::greet\":\">=1.0.0, <2.0.0\"}}",
|
||||||
)
|
)
|
||||||
assert_eq(m.name, "hello")
|
assert_eq(m.name, "hello")
|
||||||
assert_eq(m.bins, ["bin/hello"])
|
assert_eq(m.bins, ["bin/hello"])
|
||||||
assert_eq(m.depends.get("lib"), Some("^1"))
|
assert_eq(m.depends.get("lib"), Some("^1"))
|
||||||
|
assert_eq(m.depends.get("example::greet"), Some(">=1.0.0, <2.0.0"))
|
||||||
|
assert_eq(parse_dep_key("example::greet"), (Some("example"), "greet"))
|
||||||
|
assert_eq(parse_dep_key("lib"), (None, "lib"))
|
||||||
assert_true(!valid_rel_path("../x"))
|
assert_true(!valid_rel_path("../x"))
|
||||||
assert_true(!valid_rel_path("/bin/sh"))
|
assert_true(!valid_rel_path("/bin/sh"))
|
||||||
assert_eq(store_id("sha256:0123456789abcdef0123"), "0123456789abcdef")
|
assert_eq(store_id("sha256:0123456789abcdef0123"), "0123456789abcdef")
|
||||||
|
|
||||||
|
let bad_dep = try {
|
||||||
|
parse_manifest(
|
||||||
|
"{\"name\":\"hello\",\"version\":\"1.0.0\",\"depends\":{\"BadName\":\"^1\"}}",
|
||||||
|
)
|
||||||
|
|> ignore
|
||||||
|
false
|
||||||
|
} catch {
|
||||||
|
OrbitError(_) => true
|
||||||
|
}
|
||||||
|
assert_true(bad_dep)
|
||||||
|
|
||||||
|
let bad_con = try {
|
||||||
|
parse_manifest(
|
||||||
|
"{\"name\":\"hello\",\"version\":\"1.0.0\",\"depends\":{\"lib\":\">=abc\"}}",
|
||||||
|
)
|
||||||
|
|> ignore
|
||||||
|
false
|
||||||
|
} catch {
|
||||||
|
OrbitError(_) => true
|
||||||
|
}
|
||||||
|
assert_true(bad_con)
|
||||||
}
|
}
|
||||||
+274
-187
@@ -8,19 +8,11 @@ struct Step {
|
|||||||
version : String
|
version : String
|
||||||
digest : String
|
digest : String
|
||||||
manifest : Manifest
|
manifest : Manifest
|
||||||
mut explicit : Bool
|
explicit : Bool
|
||||||
mut constraint : String
|
constraint : String
|
||||||
keep : Bool // already installed at this digest; nothing to fetch
|
keep : Bool // already installed at this digest; nothing to fetch
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
|
||||||
struct Planner {
|
|
||||||
ctx : Ctx
|
|
||||||
steps : Map[String, Step]
|
|
||||||
order : Array[Step] // dependencies before dependents
|
|
||||||
upgrade : Array[String] // names allowed to move even if satisfied
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
///|
|
||||||
fn manifest_of_installed(p : Installed) -> Manifest {
|
fn manifest_of_installed(p : Installed) -> Manifest {
|
||||||
Manifest::{
|
Manifest::{
|
||||||
@@ -34,172 +26,217 @@ fn manifest_of_installed(p : Installed) -> Manifest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
/// Every constraint that currently applies to `name`: the request itself,
|
/// "[channel::]name[@constraint]" -> (channel, name, constraint, has_explicit_constraint)
|
||||||
/// the user's own constraint if they installed it explicitly, and what each
|
fn parse_spec_full(
|
||||||
/// other package requires (using planned manifests for packages being replaced).
|
spec : String,
|
||||||
fn constraints_for(
|
) -> (String?, String, String, Bool) raise OrbitError {
|
||||||
p : Planner,
|
let (channel, rest) = split_channel(spec)
|
||||||
name : String,
|
match channel {
|
||||||
requested : String,
|
Some(ch) =>
|
||||||
) -> Array[String] {
|
if !valid_name(ch) {
|
||||||
let cons : Array[String] = [requested]
|
raise OrbitError("invalid channel name '\{ch}'")
|
||||||
match p.ctx.state.get(name) {
|
|
||||||
Some(inst) =>
|
|
||||||
if inst.explicit && inst.constraint != "" && inst.constraint != requested {
|
|
||||||
cons.push(inst.constraint)
|
|
||||||
}
|
}
|
||||||
None => ()
|
None => ()
|
||||||
}
|
}
|
||||||
for other, inst in p.ctx.state {
|
let (name, c) = split_first(rest, '@')
|
||||||
if other == name {
|
if !valid_name(name) {
|
||||||
continue
|
raise OrbitError("invalid package name '\{name}'")
|
||||||
}
|
}
|
||||||
let deps = match p.steps.get(other) {
|
if c == "" {
|
||||||
Some(st) => st.manifest.depends
|
(channel, name, "*", false)
|
||||||
None => inst.depends
|
|
||||||
}
|
|
||||||
match deps.get(name) {
|
|
||||||
Some(c) => cons.push(c)
|
|
||||||
None => ()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for other, st in p.steps {
|
|
||||||
if other != name && !p.ctx.state.contains(other) {
|
|
||||||
match st.manifest.depends.get(name) {
|
|
||||||
Some(c) => cons.push(c)
|
|
||||||
None => ()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cons
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
async fn visit(
|
|
||||||
p : Planner,
|
|
||||||
name : String,
|
|
||||||
requested : String,
|
|
||||||
explicit : Bool,
|
|
||||||
pin : String?, // channel the user asked for
|
|
||||||
) -> Unit raise OrbitError {
|
|
||||||
match p.steps.get(name) {
|
|
||||||
Some(st) => {
|
|
||||||
if pin is Some(c) && c != st.channel {
|
|
||||||
raise OrbitError(
|
|
||||||
"conflict: \{name} is planned from channel '\{st.channel}' but '\{c}' was requested",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if !satisfies_all(st.version, [requested]) {
|
|
||||||
raise OrbitError(
|
|
||||||
"conflict: \{name} \{st.version} is planned but '\{requested}' is required",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if explicit {
|
|
||||||
st.explicit = true
|
|
||||||
st.constraint = requested
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
None => ()
|
|
||||||
}
|
|
||||||
let cons = constraints_for(p, name, requested)
|
|
||||||
let upgrading = p.upgrade.contains(name)
|
|
||||||
match p.ctx.state.get(name) {
|
|
||||||
Some(inst) => {
|
|
||||||
let same_channel = match pin {
|
|
||||||
Some(c) => c == inst.channel
|
|
||||||
None => true
|
|
||||||
}
|
|
||||||
if !upgrading && same_channel && satisfies_all(inst.version, cons) {
|
|
||||||
let st = Step::{
|
|
||||||
name,
|
|
||||||
channel: inst.channel,
|
|
||||||
version: inst.version,
|
|
||||||
digest: inst.digest,
|
|
||||||
manifest: manifest_of_installed(inst),
|
|
||||||
explicit: explicit || inst.explicit,
|
|
||||||
constraint: if explicit {
|
|
||||||
requested
|
|
||||||
} else {
|
} else {
|
||||||
inst.constraint
|
if !valid_constraint(c) {
|
||||||
},
|
raise OrbitError("invalid version constraint '\{c}' for '\{name}'")
|
||||||
keep: true,
|
|
||||||
}
|
}
|
||||||
p.steps[name] = st
|
(channel, name, c, true)
|
||||||
p.order.push(st)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => ()
|
|
||||||
}
|
|
||||||
// An installed package stays on its channel unless the user names another.
|
|
||||||
let wanted = match pin {
|
|
||||||
Some(c) => Some(c)
|
|
||||||
None => p.ctx.state.get(name).map(fn(i) { i.channel })
|
|
||||||
}
|
|
||||||
let (ch, tags) = locate(p.ctx, name, wanted)
|
|
||||||
let tag = match pick_tag(tags, cons) {
|
|
||||||
Some(t) => t
|
|
||||||
None => {
|
|
||||||
let avail = sorted_versions(tags)
|
|
||||||
raise OrbitError(
|
|
||||||
"no version of \{name} in channel '\{ch.name}' satisfies [\{join(cons, ", ")}]; available: \{join(avail, ", ")}",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let digest = resolve_digest(ch, name, tag)
|
|
||||||
let prev = p.ctx.state.get(name)
|
|
||||||
// An unchanged build with a saved description needs no metadata fetch.
|
|
||||||
let m = match prev {
|
|
||||||
Some(i) =>
|
|
||||||
if i.digest == digest && i.description != "" {
|
|
||||||
manifest_of_installed(i)
|
|
||||||
} else {
|
|
||||||
fetch_manifest(ch, name, digest)
|
|
||||||
}
|
|
||||||
None => fetch_manifest(ch, name, digest)
|
|
||||||
}
|
|
||||||
let st = Step::{
|
|
||||||
name,
|
|
||||||
channel: ch.name,
|
|
||||||
version: m.version,
|
|
||||||
digest,
|
|
||||||
manifest: m,
|
|
||||||
explicit: explicit ||
|
|
||||||
(match prev {
|
|
||||||
Some(i) => i.explicit
|
|
||||||
None => false
|
|
||||||
}),
|
|
||||||
constraint: if explicit {
|
|
||||||
requested
|
|
||||||
} else {
|
|
||||||
match prev {
|
|
||||||
Some(i) => i.constraint
|
|
||||||
None => "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
keep: match prev {
|
|
||||||
Some(i) => i.digest == digest
|
|
||||||
None => false
|
|
||||||
},
|
|
||||||
}
|
|
||||||
// Register before recursing so dependency cycles terminate.
|
|
||||||
p.steps[name] = st
|
|
||||||
for dep, dc in m.depends {
|
|
||||||
visit(p, dep, dc, false, None)
|
|
||||||
}
|
|
||||||
p.order.push(st)
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
///|
|
||||||
/// "[channel::]name[@constraint]"
|
/// "[channel::]name[@constraint]"
|
||||||
fn parse_spec(spec : String) -> (String?, String, String) raise OrbitError {
|
fn parse_spec(spec : String) -> (String?, String, String) raise OrbitError {
|
||||||
let (channel, rest) = split_channel(spec)
|
let (channel, name, c, _) = parse_spec_full(spec)
|
||||||
let (name, c) = split_first(rest, '@')
|
(channel, name, c)
|
||||||
if !valid_name(name) {
|
|
||||||
raise OrbitError("invalid package name '\{name}'")
|
|
||||||
}
|
}
|
||||||
(channel, name, if c == "" { "*" } else { c })
|
|
||||||
|
///|
|
||||||
|
/// Build a SAT-solved install/upgrade plan for global state.
|
||||||
|
async fn plan_global(
|
||||||
|
ctx : Ctx,
|
||||||
|
req_specs : Array[(String?, String, String, String)],
|
||||||
|
upgrade : Array[String],
|
||||||
|
explicit_new : Map[String, String],
|
||||||
|
) -> Array[Step] raise OrbitError {
|
||||||
|
let ch_by_name : Map[String, Channel] = Map([])
|
||||||
|
for c in ctx.channels {
|
||||||
|
ch_by_name[c.name] = c
|
||||||
|
}
|
||||||
|
let tags_cache : Map[String, (Channel, Array[String])] = Map([])
|
||||||
|
let digest_cache : Map[String, String] = Map([])
|
||||||
|
let manifest_cache : Map[String, Manifest] = Map([])
|
||||||
|
|
||||||
|
let locked_bins : Map[String, String] = Map([])
|
||||||
|
for name, inst in ctx.state {
|
||||||
|
if !upgrade.contains(name) && !explicit_new.contains(name) {
|
||||||
|
for b in inst.bins {
|
||||||
|
locked_bins[basename(b)] = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let provider = SolverProvider::{
|
||||||
|
candidates: async fn(name, pin) {
|
||||||
|
let wanted = match pin {
|
||||||
|
Some(c) => Some(c)
|
||||||
|
None =>
|
||||||
|
match ctx.state.get(name) {
|
||||||
|
Some(inst) => Some(inst.channel)
|
||||||
|
None => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let cache_key = name + "|" + wanted.unwrap_or("")
|
||||||
|
let (ch, tags) = match tags_cache.get(cache_key) {
|
||||||
|
Some(pair) => pair
|
||||||
|
None => {
|
||||||
|
let pair = locate(ctx, name, wanted)
|
||||||
|
tags_cache[cache_key] = pair
|
||||||
|
ch_by_name[pair.0.name] = pair.0
|
||||||
|
pair
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let favored = if upgrade.contains(name) {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
match ctx.state.get(name) {
|
||||||
|
Some(inst) =>
|
||||||
|
if inst.channel == ch.name {
|
||||||
|
Some((inst.channel, inst.version, inst.digest))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
None => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(ch.name, candidates_from_tags(name, ch.name, tags, favored))
|
||||||
|
},
|
||||||
|
details: async fn(cand) {
|
||||||
|
if false {
|
||||||
|
@async.sleep(0)
|
||||||
|
}
|
||||||
|
if cand.favored && cand.digest != "" {
|
||||||
|
match ctx.state.get(cand.name) {
|
||||||
|
Some(inst) =>
|
||||||
|
if inst.digest == cand.digest && inst.channel == cand.channel {
|
||||||
|
return CandidateDetail::{
|
||||||
|
digest: cand.digest,
|
||||||
|
manifest: manifest_of_installed(inst),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let ch = match ch_by_name.get(cand.channel) {
|
||||||
|
Some(c) => c
|
||||||
|
None => find_channel(ctx, cand.channel)
|
||||||
|
}
|
||||||
|
let dkey = cand.channel + "::" + cand.name + "@" + cand.tag
|
||||||
|
let digest = match digest_cache.get(dkey) {
|
||||||
|
Some(d) => d
|
||||||
|
None => {
|
||||||
|
let d = resolve_digest(ch, cand.name, cand.tag)
|
||||||
|
digest_cache[dkey] = d
|
||||||
|
d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mkey = cand.channel + "::" + cand.name + "@" + digest
|
||||||
|
let m = match manifest_cache.get(mkey) {
|
||||||
|
Some(mf) => mf
|
||||||
|
None => {
|
||||||
|
let mf = fetch_manifest_cached(ctx.root, ch, cand.name, digest)
|
||||||
|
manifest_cache[mkey] = mf
|
||||||
|
mf
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CandidateDetail::{ digest, manifest: m }
|
||||||
|
},
|
||||||
|
extra_reqs: fn(pkg_name) {
|
||||||
|
let reqs : Array[SolveReq] = []
|
||||||
|
match ctx.state.get(pkg_name) {
|
||||||
|
Some(inst) =>
|
||||||
|
if inst.explicit && !explicit_new.contains(pkg_name) {
|
||||||
|
reqs.push(SolveReq::{
|
||||||
|
name: pkg_name,
|
||||||
|
channel: Some(inst.channel),
|
||||||
|
constraint: if inst.constraint == "" {
|
||||||
|
"*"
|
||||||
|
} else {
|
||||||
|
inst.constraint
|
||||||
|
},
|
||||||
|
label: "installed \{pkg_name}",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
for other, oinst in ctx.state {
|
||||||
|
if other != pkg_name &&
|
||||||
|
!upgrade.contains(other) &&
|
||||||
|
!explicit_new.contains(other) {
|
||||||
|
for dk, dc in oinst.depends {
|
||||||
|
let (dch, dname) = parse_dep_key(dk)
|
||||||
|
if dname == pkg_name {
|
||||||
|
reqs.push(SolveReq::{
|
||||||
|
name: pkg_name,
|
||||||
|
channel: dch,
|
||||||
|
constraint: dc,
|
||||||
|
label: "installed \{other} \{oinst.version}",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reqs
|
||||||
|
},
|
||||||
|
locked_bins,
|
||||||
|
}
|
||||||
|
|
||||||
|
let reqs : Array[SolveReq] = []
|
||||||
|
for item in req_specs {
|
||||||
|
let (pin, name, constraint, label) = item
|
||||||
|
reqs.push(SolveReq::{ name, channel: pin, constraint, label })
|
||||||
|
}
|
||||||
|
let solved = solve(reqs, provider)
|
||||||
|
let steps : Array[Step] = []
|
||||||
|
for sp in solved {
|
||||||
|
let prev = ctx.state.get(sp.name)
|
||||||
|
let explicit = explicit_new.contains(sp.name) ||
|
||||||
|
(match prev {
|
||||||
|
Some(i) => i.explicit
|
||||||
|
None => false
|
||||||
|
})
|
||||||
|
let constraint = match explicit_new.get(sp.name) {
|
||||||
|
Some(c) => c
|
||||||
|
None =>
|
||||||
|
match prev {
|
||||||
|
Some(i) => i.constraint
|
||||||
|
None => "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let keep = match prev {
|
||||||
|
Some(i) => i.digest == sp.digest && i.channel == sp.channel
|
||||||
|
None => false
|
||||||
|
}
|
||||||
|
steps.push(Step::{
|
||||||
|
name: sp.name,
|
||||||
|
channel: sp.channel,
|
||||||
|
version: sp.version,
|
||||||
|
digest: sp.digest,
|
||||||
|
manifest: sp.manifest,
|
||||||
|
explicit,
|
||||||
|
constraint,
|
||||||
|
keep,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
steps
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
@@ -321,9 +358,9 @@ async fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
async fn apply_plan(ctx : Ctx, p : Planner) -> Unit raise OrbitError {
|
async fn apply_plan(ctx : Ctx, steps : Array[Step]) -> Unit raise OrbitError {
|
||||||
let mut changed = 0
|
let mut changed = 0
|
||||||
for st in p.order {
|
for st in steps {
|
||||||
if st.keep {
|
if st.keep {
|
||||||
match ctx.state.get(st.name) {
|
match ctx.state.get(st.name) {
|
||||||
Some(inst) => {
|
Some(inst) => {
|
||||||
@@ -345,59 +382,108 @@ async fn apply_plan(ctx : Ctx, p : Planner) -> Unit raise OrbitError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
|
||||||
fn new_planner(ctx : Ctx, upgrade : Array[String]) -> Planner {
|
|
||||||
Planner::{ ctx, steps: Map([]), order: [], upgrade, }
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
///|
|
||||||
async fn cmd_install(ctx : Ctx, specs : Array[String]) -> Unit raise OrbitError {
|
async fn cmd_install(ctx : Ctx, specs : Array[String]) -> Unit raise OrbitError {
|
||||||
if specs.length() == 0 {
|
if specs.length() == 0 {
|
||||||
raise OrbitError("usage: orbit install [channel::]<name>[@constraint]...")
|
raise OrbitError("usage: orbit install [channel::]<name>[@constraint]...")
|
||||||
}
|
}
|
||||||
let p = new_planner(ctx, [])
|
let reqs : Array[(String?, String, String, String)] = []
|
||||||
|
let explicit_new : Map[String, String] = Map([])
|
||||||
for s in specs {
|
for s in specs {
|
||||||
let (channel, name, c) = parse_spec(s)
|
let (channel, name, c) = parse_spec(s)
|
||||||
visit(p, name, c, true, channel)
|
reqs.push((channel, name, c, "command line"))
|
||||||
|
explicit_new[name] = c
|
||||||
}
|
}
|
||||||
apply_plan(ctx, p)
|
let steps = plan_global(ctx, reqs, [], explicit_new)
|
||||||
|
apply_plan(ctx, steps)
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
/// Upgrade the named packages (or everything) to the newest versions their
|
/// Upgrade the named packages (or everything) jointly to the newest versions
|
||||||
/// constraints allow. Dependencies are moved only when required.
|
/// their constraints allow.
|
||||||
async fn cmd_upgrade(ctx : Ctx, names : Array[String]) -> Unit raise OrbitError {
|
async fn cmd_upgrade(ctx : Ctx, names : Array[String]) -> Unit raise OrbitError {
|
||||||
let targets : Array[String] = []
|
let targets : Array[String] = []
|
||||||
|
let reqs : Array[(String?, String, String, String)] = []
|
||||||
if names.length() == 0 {
|
if names.length() == 0 {
|
||||||
for name, _ in ctx.state {
|
if ctx.state.length() == 0 {
|
||||||
|
println("no packages installed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let mut has_explicit = false
|
||||||
|
for name, inst in ctx.state {
|
||||||
targets.push(name)
|
targets.push(name)
|
||||||
|
if inst.explicit {
|
||||||
|
has_explicit = true
|
||||||
|
reqs.push((
|
||||||
|
Some(inst.channel),
|
||||||
|
name,
|
||||||
|
if inst.constraint == "" {
|
||||||
|
"*"
|
||||||
|
} else {
|
||||||
|
inst.constraint
|
||||||
|
},
|
||||||
|
"installed \{name}",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !has_explicit {
|
||||||
|
for name, inst in ctx.state {
|
||||||
|
reqs.push((
|
||||||
|
Some(inst.channel),
|
||||||
|
name,
|
||||||
|
if inst.constraint == "" {
|
||||||
|
"*"
|
||||||
|
} else {
|
||||||
|
inst.constraint
|
||||||
|
},
|
||||||
|
"installed \{name}",
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for n in names {
|
for n in names {
|
||||||
if !ctx.state.contains(n) {
|
let inst = match ctx.state.get(n) {
|
||||||
raise OrbitError("\{n} is not installed")
|
Some(i) => i
|
||||||
|
None => raise OrbitError("\{n} is not installed")
|
||||||
}
|
}
|
||||||
targets.push(n)
|
targets.push(n)
|
||||||
|
reqs.push((
|
||||||
|
Some(inst.channel),
|
||||||
|
n,
|
||||||
|
if inst.constraint == "" {
|
||||||
|
"*"
|
||||||
|
} else {
|
||||||
|
inst.constraint
|
||||||
|
},
|
||||||
|
"installed \{n}",
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let p = new_planner(ctx, targets)
|
let steps = plan_global(ctx, reqs, targets, Map([]))
|
||||||
for n in targets {
|
apply_plan(ctx, steps)
|
||||||
match ctx.state.get(n) {
|
if names.length() == 0 {
|
||||||
Some(inst) => visit(p, n, "*", inst.explicit, None)
|
autoremove(ctx)
|
||||||
None => ()
|
save_state(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apply_plan(ctx, p)
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
///|
|
||||||
fn reverse_deps(ctx : Ctx, name : String) -> Array[String] {
|
fn reverse_deps(ctx : Ctx, name : String) -> Array[String] {
|
||||||
let r : Array[String] = []
|
let r : Array[String] = []
|
||||||
for other, p in ctx.state {
|
for other, p in ctx.state {
|
||||||
if other != name && p.depends.contains(name) {
|
if other != name {
|
||||||
|
let mut uses = false
|
||||||
|
for dk, _ in p.depends {
|
||||||
|
if parse_dep_key(dk).1 == name {
|
||||||
|
uses = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if uses {
|
||||||
r.push(other)
|
r.push(other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,7 +592,8 @@ async fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
|||||||
println("\{name}: \{from} -> \{prev.version}")
|
println("\{name}: \{from} -> \{prev.version}")
|
||||||
let missing : Array[String] = []
|
let missing : Array[String] = []
|
||||||
for dep, c in inst.depends {
|
for dep, c in inst.depends {
|
||||||
match ctx.state.get(dep) {
|
let (_, dep_name) = parse_dep_key(dep)
|
||||||
|
match ctx.state.get(dep_name) {
|
||||||
Some(d) =>
|
Some(d) =>
|
||||||
if !satisfies_all(d.version, [c]) {
|
if !satisfies_all(d.version, [c]) {
|
||||||
missing.push(dep + "@" + c)
|
missing.push(dep + "@" + c)
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
+63
-4
@@ -284,13 +284,33 @@ async fn fetch_raw_manifest(
|
|||||||
utf8_decode(fetch_raw_manifest_bytes(ch, name, ref_str))
|
utf8_decode(fetch_raw_manifest_bytes(ch, name, ref_str))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn manifest_cache_path(root : String, digest : String) -> String? {
|
||||||
|
if root == "" || !has_prefix(digest, "sha256:") {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
let hex = drop_chars(digest, 7)
|
||||||
|
if hex == "" {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
for c in hex {
|
||||||
|
let ok = (c >= '0' && c <= '9') ||
|
||||||
|
(c >= 'a' && c <= 'f') ||
|
||||||
|
(c >= 'A' && c <= 'F')
|
||||||
|
if !ok {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(cache_dir(root) + "/" + ascii_lower(hex) + ".json")
|
||||||
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
/// Fetch only the config blob (orbit.json); no layer download needed to plan.
|
/// Fetch only the config blob (orbit.json); no layer download needed to plan.
|
||||||
async fn fetch_manifest(
|
async fn fetch_manifest_with_raw(
|
||||||
ch : Channel,
|
ch : Channel,
|
||||||
name : String,
|
name : String,
|
||||||
digest : String,
|
digest : String,
|
||||||
) -> Manifest raise OrbitError {
|
) -> (Manifest, String) raise OrbitError {
|
||||||
with_spinner("Reading metadata for \{ch.name}::\{name}", () => {
|
with_spinner("Reading metadata for \{ch.name}::\{name}", () => {
|
||||||
let repo = channel_repo_path(ch, name)
|
let repo = channel_repo_path(ch, name)
|
||||||
let manifest_text = fetch_raw_manifest(ch, name, digest)
|
let manifest_text = fetch_raw_manifest(ch, name, digest)
|
||||||
@@ -323,16 +343,55 @@ async fn fetch_manifest(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let m = parse_manifest(utf8_decode(body))
|
let raw = utf8_decode(body)
|
||||||
|
let m = parse_manifest(raw)
|
||||||
if m.name != name {
|
if m.name != name {
|
||||||
raise OrbitError(
|
raise OrbitError(
|
||||||
"\{name}@\{digest} declares name '\{m.name}'; refusing to install",
|
"\{name}@\{digest} declares name '\{m.name}'; refusing to install",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
m
|
(m, raw)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Fetch config blob (orbit.json) using a digest-keyed local cache under
|
||||||
|
/// `<root>/cache/manifests/<hex>.json`. Pass `root = ""` to skip caching.
|
||||||
|
async fn fetch_manifest_cached(
|
||||||
|
root : String,
|
||||||
|
ch : Channel,
|
||||||
|
name : String,
|
||||||
|
digest : String,
|
||||||
|
) -> Manifest raise OrbitError {
|
||||||
|
match manifest_cache_path(root, digest) {
|
||||||
|
Some(path) =>
|
||||||
|
match read_text(path) {
|
||||||
|
Some(raw) => {
|
||||||
|
let cached : Manifest? = Some(parse_manifest(raw)) catch { _ => None }
|
||||||
|
match cached {
|
||||||
|
Some(m) => if m.name == name { return m }
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
let (m, raw) = fetch_manifest_with_raw(ch, name, digest)
|
||||||
|
match manifest_cache_path(root, digest) {
|
||||||
|
Some(path) => {
|
||||||
|
try {
|
||||||
|
@fs.mkdir(cache_dir(root), recursive=true, allow_exist=true)
|
||||||
|
write_text_atomic(path, raw)
|
||||||
|
} catch {
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
m
|
||||||
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
fn find_pkg_layer_digest(manifest_obj : Map[String, Json]) -> String? {
|
fn find_pkg_layer_digest(manifest_obj : Map[String, Json]) -> String? {
|
||||||
let layers = match manifest_obj.get("layers") {
|
let layers = match manifest_obj.get("layers") {
|
||||||
|
|||||||
@@ -185,13 +185,15 @@ async test "native OCI publish, search catalog, tags pagination, resolve, and in
|
|||||||
let d2 = resolve_digest(ch, "mytool", "1.2.0")
|
let d2 = resolve_digest(ch, "mytool", "1.2.0")
|
||||||
assert_eq(d1, d2)
|
assert_eq(d1, d2)
|
||||||
|
|
||||||
let mf = fetch_manifest(ch, "mytool", d1)
|
let mf = fetch_manifest_cached("", ch, "mytool", d1)
|
||||||
assert_eq(mf.name, "mytool")
|
assert_eq(mf.name, "mytool")
|
||||||
assert_eq(mf.version, "1.2.0")
|
assert_eq(mf.version, "1.2.0")
|
||||||
assert_eq(mf.description, "Mock OCI tool")
|
assert_eq(mf.description, "Mock OCI tool")
|
||||||
assert_eq(mf.bins, ["bin/mytool"])
|
assert_eq(mf.bins, ["bin/mytool"])
|
||||||
|
|
||||||
let orbit_dir = work + "/orbit"
|
let orbit_dir = work + "/orbit"
|
||||||
|
let mf_cached = fetch_manifest_cached(orbit_dir, ch, "mytool", d1)
|
||||||
|
assert_eq(mf_cached.version, "1.2.0")
|
||||||
let ctx = Ctx::{ root: orbit_dir, channels: [ch], state: Map([]) }
|
let ctx = Ctx::{ root: orbit_dir, channels: [ch], state: Map([]) }
|
||||||
let installed_dir = fetch_into_store(ctx, ch, "mytool", d1)
|
let installed_dir = fetch_into_store(ctx, ch, "mytool", d1)
|
||||||
assert_true(exists(installed_dir + "/bin/mytool"))
|
assert_true(exists(installed_dir + "/bin/mytool"))
|
||||||
@@ -374,3 +376,497 @@ async test "channel locate falls through on 404 and fails on 500" {
|
|||||||
assert_true(failed)
|
assert_true(failed)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn split_sub(s : String, sep : String) -> (String, String)? {
|
||||||
|
let a = chars(s)
|
||||||
|
let b = chars(sep)
|
||||||
|
if b.length() == 0 || a.length() < b.length() {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
for i = 0; i + b.length() <= a.length(); i = i + 1 {
|
||||||
|
let mut ok = true
|
||||||
|
for j = 0; j < b.length(); j = j + 1 {
|
||||||
|
if a[i + j] != b[j] {
|
||||||
|
ok = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
return Some((slice(a, 0, i), slice(a, i + b.length(), a.length())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
struct MockOciState {
|
||||||
|
blobs : Map[String, Bytes]
|
||||||
|
manifests : Map[String, Map[String, (String, Bytes)]]
|
||||||
|
tags : Map[String, Array[String]]
|
||||||
|
blob_gets : Ref[Int32]
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn new_mock_oci_state() -> MockOciState {
|
||||||
|
MockOciState::{
|
||||||
|
blobs: Map([]),
|
||||||
|
manifests: Map([]),
|
||||||
|
tags: Map([]),
|
||||||
|
blob_gets: Ref(0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
async fn handle_mock_oci(
|
||||||
|
st : MockOciState,
|
||||||
|
upload_seq : Ref[Int32],
|
||||||
|
req : @http.Request,
|
||||||
|
req_bytes : Bytes,
|
||||||
|
conn : @http.ServerConnection,
|
||||||
|
) -> Unit {
|
||||||
|
let (path, query) = strip_query(req.path)
|
||||||
|
if req.meth is Get && path == "/v2/_catalog" {
|
||||||
|
let repos : Array[Json] = []
|
||||||
|
for r, _ in st.tags {
|
||||||
|
repos.push(Json::string(r))
|
||||||
|
}
|
||||||
|
let top : Map[String, Json] = Map([])
|
||||||
|
top["repositories"] = Json::array(repos)
|
||||||
|
conn.send_response(200, "OK", extra_headers={
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
})
|
||||||
|
conn.write(Json::object(top).stringify())
|
||||||
|
conn.end_response()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !has_prefix(path, "/v2/") {
|
||||||
|
conn.send_response(404, "Not Found")
|
||||||
|
conn.end_response()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let rest = drop_chars(path, 4)
|
||||||
|
match split_sub(rest, "/tags/list") {
|
||||||
|
Some((repo, "")) =>
|
||||||
|
match st.tags.get(repo) {
|
||||||
|
Some(ts) => {
|
||||||
|
let jtags = ts.map(fn(t) { Json::string(t) })
|
||||||
|
let obj : Map[String, Json] = Map([])
|
||||||
|
obj["name"] = Json::string(repo)
|
||||||
|
obj["tags"] = Json::array(jtags)
|
||||||
|
conn.send_response(200, "OK", extra_headers={
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
})
|
||||||
|
conn.write(Json::object(obj).stringify())
|
||||||
|
conn.end_response()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
conn.send_response(404, "Not Found")
|
||||||
|
conn.end_response()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
match split_sub(rest, "/blobs/uploads/") {
|
||||||
|
Some((repo, _id)) => {
|
||||||
|
if req.meth is Post {
|
||||||
|
upload_seq.val = upload_seq.val + 1
|
||||||
|
conn.send_response(202, "Accepted", extra_headers={
|
||||||
|
"Location": "/v2/" + repo + "/blobs/uploads/" + upload_seq.val.to_string(),
|
||||||
|
})
|
||||||
|
conn.end_response()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.meth is Put {
|
||||||
|
let (_, dq) = split_first(query, '=')
|
||||||
|
let digest = @percent.decode(dq) catch { _ => "" }
|
||||||
|
st.blobs[repo + "|" + digest] = req_bytes
|
||||||
|
conn.send_response(201, "Created", extra_headers={
|
||||||
|
"Docker-Content-Digest": digest,
|
||||||
|
})
|
||||||
|
conn.end_response()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
match split_sub(rest, "/blobs/") {
|
||||||
|
Some((repo, digest)) => {
|
||||||
|
match st.blobs.get(repo + "|" + digest) {
|
||||||
|
Some(data) => {
|
||||||
|
if !(req.meth is Head) {
|
||||||
|
st.blob_gets.val = st.blob_gets.val + 1
|
||||||
|
}
|
||||||
|
conn.send_response(200, "OK", extra_headers={
|
||||||
|
"Content-Type": "application/octet-stream",
|
||||||
|
"Docker-Content-Digest": digest,
|
||||||
|
"Content-Length": data.length().to_string(),
|
||||||
|
})
|
||||||
|
if !(req.meth is Head) {
|
||||||
|
conn.write(data)
|
||||||
|
}
|
||||||
|
conn.end_response()
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
conn.send_response(404, "Not Found")
|
||||||
|
conn.end_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
match split_sub(rest, "/manifests/") {
|
||||||
|
Some((repo, ref_str)) => {
|
||||||
|
if req.meth is Put {
|
||||||
|
let d = sha256_digest(req_bytes)
|
||||||
|
let repo_map = match st.manifests.get(repo) {
|
||||||
|
Some(m) => m
|
||||||
|
None => {
|
||||||
|
let m : Map[String, (String, Bytes)] = Map([])
|
||||||
|
st.manifests[repo] = m
|
||||||
|
m
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repo_map[ref_str] = (d, req_bytes)
|
||||||
|
repo_map[d] = (d, req_bytes)
|
||||||
|
let ts = match st.tags.get(repo) {
|
||||||
|
Some(xs) => xs
|
||||||
|
None => {
|
||||||
|
let xs : Array[String] = []
|
||||||
|
st.tags[repo] = xs
|
||||||
|
xs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !ts.contains(ref_str) {
|
||||||
|
ts.push(ref_str)
|
||||||
|
}
|
||||||
|
conn.send_response(201, "Created", extra_headers={
|
||||||
|
"Docker-Content-Digest": d,
|
||||||
|
})
|
||||||
|
conn.end_response()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
match st.manifests.get(repo) {
|
||||||
|
Some(repo_map) =>
|
||||||
|
match repo_map.get(ref_str) {
|
||||||
|
Some((d, data)) => {
|
||||||
|
conn.send_response(200, "OK", extra_headers={
|
||||||
|
"Content-Type": OCI_MANIFEST_MEDIA_TYPE,
|
||||||
|
"Docker-Content-Digest": d,
|
||||||
|
"Content-Length": data.length().to_string(),
|
||||||
|
})
|
||||||
|
if !(req.meth is Head) {
|
||||||
|
conn.write(data)
|
||||||
|
}
|
||||||
|
conn.end_response()
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
conn.send_response(404, "Not Found")
|
||||||
|
conn.end_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
conn.send_response(404, "Not Found")
|
||||||
|
conn.end_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
conn.send_response(404, "Not Found")
|
||||||
|
conn.end_response()
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
async fn publish_mock_pkg(
|
||||||
|
ch : Channel,
|
||||||
|
work : String,
|
||||||
|
name : String,
|
||||||
|
version : String,
|
||||||
|
depends : Map[String, String],
|
||||||
|
bins : Array[String],
|
||||||
|
script? : String = "#!/bin/sh\necho ok\n",
|
||||||
|
) -> Unit raise Error {
|
||||||
|
let pkg_dir = work + "/stage-" + name + "-" + version
|
||||||
|
@fs.mkdir(pkg_dir + "/files/bin", recursive=true)
|
||||||
|
let mf_obj : Map[String, Json] = Map([])
|
||||||
|
mf_obj["name"] = Json::string(name)
|
||||||
|
mf_obj["version"] = Json::string(version)
|
||||||
|
mf_obj["description"] = Json::string("Mock " + name + " " + version)
|
||||||
|
mf_obj["bin"] = strs_json(bins)
|
||||||
|
mf_obj["depends"] = map_json(depends)
|
||||||
|
@fs.write_file(
|
||||||
|
pkg_dir + "/orbit.json",
|
||||||
|
Json::object(mf_obj).stringify(indent=2) + "\n",
|
||||||
|
create_mode=CreateOrTruncate,
|
||||||
|
)
|
||||||
|
for b in bins {
|
||||||
|
let p = pkg_dir + "/files/" + b
|
||||||
|
@fs.mkdir(path_dirname(p), recursive=true, allow_exist=true)
|
||||||
|
@fs.write_file(p, script, create_mode=CreateOrTruncate, permission=0o755)
|
||||||
|
}
|
||||||
|
publish(ch, pkg_dir, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
async test "SAT global install, backtracking, manifest cache, and joint upgrade" {
|
||||||
|
token_cache.clear()
|
||||||
|
let work = @fs.tmpdir(prefix="orbit-wb-sat-global-")
|
||||||
|
defer (@fs.rmdir(work, recursive=true, allow_missing=true) catch { _ => () })
|
||||||
|
|
||||||
|
let st = new_mock_oci_state()
|
||||||
|
let upload_seq = Ref(0)
|
||||||
|
let server = @http.Server(@socket.Addr::parse("127.0.0.1:0"))
|
||||||
|
@async.with_task_group(group => {
|
||||||
|
defer server.close()
|
||||||
|
group.spawn_bg(no_wait=true, () => {
|
||||||
|
server.run_forever((req, body, conn) => {
|
||||||
|
let req_bytes = body.read_all().binary()
|
||||||
|
handle_mock_oci(st, upload_seq, req, req_bytes, conn)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
let addr = "127.0.0.1:" + server.addr.port().to_string()
|
||||||
|
let main_ch = Channel::{
|
||||||
|
name: "main",
|
||||||
|
url: addr + "/main",
|
||||||
|
plain_http: true,
|
||||||
|
}
|
||||||
|
let extra_ch = Channel::{
|
||||||
|
name: "extra",
|
||||||
|
url: addr + "/extra",
|
||||||
|
plain_http: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
publish_mock_pkg(main_ch, work, "lib", "1.0.0", Map([]), [])
|
||||||
|
publish_mock_pkg(main_ch, work, "lib", "2.0.0", Map([]), [])
|
||||||
|
publish_mock_pkg(
|
||||||
|
main_ch,
|
||||||
|
work,
|
||||||
|
"app",
|
||||||
|
"1.0.0",
|
||||||
|
Map([("lib", "^1.0")]),
|
||||||
|
["bin/app"],
|
||||||
|
script="#!/bin/sh\necho app-1.0.0\n",
|
||||||
|
)
|
||||||
|
publish_mock_pkg(
|
||||||
|
main_ch,
|
||||||
|
work,
|
||||||
|
"app",
|
||||||
|
"2.0.0",
|
||||||
|
Map([("lib", "^2.0")]),
|
||||||
|
["bin/app"],
|
||||||
|
script="#!/bin/sh\necho app-2.0.0\n",
|
||||||
|
)
|
||||||
|
publish_mock_pkg(
|
||||||
|
extra_ch,
|
||||||
|
work,
|
||||||
|
"helper",
|
||||||
|
"1.0.0",
|
||||||
|
Map([("main::lib", "^1.0")]),
|
||||||
|
["bin/helper"],
|
||||||
|
script="#!/bin/sh\necho helper-1.0.0\n",
|
||||||
|
)
|
||||||
|
|
||||||
|
let orbit_root = work + "/orbit"
|
||||||
|
let ctx = Ctx::{
|
||||||
|
root: orbit_root,
|
||||||
|
channels: [main_ch, extra_ch],
|
||||||
|
state: Map([]),
|
||||||
|
}
|
||||||
|
cmd_install(ctx, ["app", "helper"])
|
||||||
|
assert_eq(ctx.state["app"].version, "1.0.0")
|
||||||
|
assert_eq(ctx.state["helper"].version, "1.0.0")
|
||||||
|
assert_eq(ctx.state["helper"].channel, "extra")
|
||||||
|
assert_eq(ctx.state["lib"].version, "1.0.0")
|
||||||
|
assert_true(exists(orbit_root + "/bin/app"))
|
||||||
|
assert_true(exists(orbit_root + "/bin/helper"))
|
||||||
|
let cached_files = @fs.readdir(cache_dir(orbit_root))
|
||||||
|
assert_true(cached_files.length() > 0)
|
||||||
|
|
||||||
|
// Verify digest-keyed manifest cache avoids HTTP blob GET on re-solve.
|
||||||
|
let gets_before = st.blob_gets.val
|
||||||
|
let _ = fetch_manifest_cached(
|
||||||
|
orbit_root,
|
||||||
|
main_ch,
|
||||||
|
"app",
|
||||||
|
ctx.state["app"].digest,
|
||||||
|
)
|
||||||
|
assert_eq(st.blob_gets.val, gets_before)
|
||||||
|
|
||||||
|
// Publish helper 2.0.0 compatible with lib ^2.0, then upgrade jointly.
|
||||||
|
publish_mock_pkg(
|
||||||
|
extra_ch,
|
||||||
|
work,
|
||||||
|
"helper",
|
||||||
|
"2.0.0",
|
||||||
|
Map([("main::lib", "^2.0")]),
|
||||||
|
["bin/helper"],
|
||||||
|
script="#!/bin/sh\necho helper-2.0.0\n",
|
||||||
|
)
|
||||||
|
cmd_upgrade(ctx, [])
|
||||||
|
assert_eq(ctx.state["app"].version, "2.0.0")
|
||||||
|
assert_eq(ctx.state["helper"].version, "2.0.0")
|
||||||
|
assert_eq(ctx.state["lib"].version, "2.0.0")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
async test "Pixi-style project workflow: new, add, sync --locked, run, update, remove" {
|
||||||
|
try {
|
||||||
|
token_cache.clear()
|
||||||
|
let work = @fs.tmpdir(prefix="orbit-wb-project-")
|
||||||
|
defer (@fs.rmdir(work, recursive=true, allow_missing=true) catch { _ => () })
|
||||||
|
|
||||||
|
let st = new_mock_oci_state()
|
||||||
|
let upload_seq = Ref(0)
|
||||||
|
let server = @http.Server(@socket.Addr::parse("127.0.0.1:0"))
|
||||||
|
@async.with_task_group(group => {
|
||||||
|
defer server.close()
|
||||||
|
group.spawn_bg(no_wait=true, () => {
|
||||||
|
server.run_forever((req, body, conn) => {
|
||||||
|
let req_bytes = body.read_all().binary()
|
||||||
|
handle_mock_oci(st, upload_seq, req, req_bytes, conn)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
let addr = "127.0.0.1:" + server.addr.port().to_string()
|
||||||
|
let main_ch = Channel::{
|
||||||
|
name: "main",
|
||||||
|
url: addr + "/main",
|
||||||
|
plain_http: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
publish_mock_pkg(main_ch, work, "lib", "1.0.0", Map([]), [])
|
||||||
|
publish_mock_pkg(main_ch, work, "lib", "2.0.0", Map([]), [])
|
||||||
|
publish_mock_pkg(
|
||||||
|
main_ch,
|
||||||
|
work,
|
||||||
|
"app",
|
||||||
|
"1.0.0",
|
||||||
|
Map([("lib", "^1.0")]),
|
||||||
|
["bin/app"],
|
||||||
|
script="#!/bin/sh\necho proj-app-1\n",
|
||||||
|
)
|
||||||
|
publish_mock_pkg(
|
||||||
|
main_ch,
|
||||||
|
work,
|
||||||
|
"app",
|
||||||
|
"2.0.0",
|
||||||
|
Map([("lib", "^2.0")]),
|
||||||
|
["bin/app"],
|
||||||
|
script="#!/bin/sh\necho proj-app-2\n",
|
||||||
|
)
|
||||||
|
publish_mock_pkg(
|
||||||
|
main_ch,
|
||||||
|
work,
|
||||||
|
"helper",
|
||||||
|
"1.0.0",
|
||||||
|
Map([("lib", "^1.0")]),
|
||||||
|
["bin/helper"],
|
||||||
|
script="#!/bin/sh\nexit 0\n",
|
||||||
|
)
|
||||||
|
|
||||||
|
let proj = work + "/proj"
|
||||||
|
cmd_project_init(Some(proj))
|
||||||
|
let mf = proj + "/orbit.toml"
|
||||||
|
assert_true(exists(mf))
|
||||||
|
|
||||||
|
// Configure project channel + tasks.
|
||||||
|
let m0 = parse_project_manifest(
|
||||||
|
"[project]\nname = \"proj\"\nversion = \"0.1.0\"\n\n[[channels]]\nname = \"main\"\nurl = \"" +
|
||||||
|
main_ch.url +
|
||||||
|
"\"\nplain-http = true\n\n[dependencies]\n\n[tasks]\nshow = \"app\"\ncheck = [\"helper\", \"--ok\"]\n",
|
||||||
|
"proj",
|
||||||
|
)
|
||||||
|
write_text_atomic(mf, project_to_toml(m0))
|
||||||
|
|
||||||
|
let orbit_root = work + "/orbit"
|
||||||
|
let ctx = Ctx::{ root: orbit_root, channels: [main_ch], state: Map([]) }
|
||||||
|
|
||||||
|
// Discovery via explicit directory & manifest path.
|
||||||
|
assert_eq(find_project_manifest(Some(proj)).unwrap(), mf)
|
||||||
|
assert_eq(find_project_manifest(Some(mf)).unwrap(), mf)
|
||||||
|
|
||||||
|
// Add packages -> SAT solver picks 1.0.0 + 1.0.0 + lib 1.0.0, pins ^1.0.0,
|
||||||
|
// writes orbit.lock, and syncs .orbit/bin.
|
||||||
|
cmd_project_add(ctx, mf, ["app", "helper"])
|
||||||
|
let m_after_add = parse_project_manifest(read_text(mf).unwrap(), "proj")
|
||||||
|
assert_eq(m_after_add.dependencies["app"].constraint, "^1.0.0")
|
||||||
|
assert_eq(m_after_add.dependencies["helper"].constraint, "^1.0.0")
|
||||||
|
let lock1 = parse_lockfile(read_text(proj + "/orbit.lock").unwrap())
|
||||||
|
assert_eq(lock1.packages.length(), 3)
|
||||||
|
assert_true(exists(proj + "/.orbit/.gitignore"))
|
||||||
|
assert_true(exists(proj + "/.orbit/bin/app"))
|
||||||
|
assert_true(exists(proj + "/.orbit/bin/helper"))
|
||||||
|
|
||||||
|
// Run tasks and direct commands through .orbit/bin.
|
||||||
|
assert_eq(run_project_command(ctx, mf, ["show"], false, false), 0)
|
||||||
|
assert_eq(run_project_command(ctx, mf, ["check"], true, false), 0)
|
||||||
|
assert_eq(run_project_command(ctx, mf, ["helper", "--direct"], true, false), 0)
|
||||||
|
|
||||||
|
// --locked passes while in sync.
|
||||||
|
cmd_project_sync(ctx, mf, true, false)
|
||||||
|
|
||||||
|
// Transactional rollback on failed `orbit add`: files remain identical.
|
||||||
|
let saved_toml = read_text(mf).unwrap()
|
||||||
|
let saved_lock = read_text(proj + "/orbit.lock").unwrap()
|
||||||
|
let bad_add = try {
|
||||||
|
cmd_project_add(ctx, mf, ["missingpkg"])
|
||||||
|
false
|
||||||
|
} catch {
|
||||||
|
OrbitError(_) => true
|
||||||
|
}
|
||||||
|
assert_true(bad_add)
|
||||||
|
assert_eq(read_text(mf).unwrap(), saved_toml)
|
||||||
|
assert_eq(read_text(proj + "/orbit.lock").unwrap(), saved_lock)
|
||||||
|
|
||||||
|
// Require >=2.0.0 so lockfile (at 1.0.0) is out of date -> --locked fails.
|
||||||
|
m_after_add.dependencies["app"].constraint = ">=2.0.0"
|
||||||
|
write_text_atomic(mf, project_to_toml(m_after_add))
|
||||||
|
let locked_fail = try {
|
||||||
|
cmd_project_sync(ctx, mf, true, false)
|
||||||
|
false
|
||||||
|
} catch {
|
||||||
|
OrbitError(_) => true
|
||||||
|
}
|
||||||
|
assert_true(locked_fail)
|
||||||
|
|
||||||
|
// Broaden constraints to "*", re-lock, then publish helper 2.0.0 and update.
|
||||||
|
m_after_add.dependencies["app"].constraint = "*"
|
||||||
|
m_after_add.dependencies["helper"].constraint = "*"
|
||||||
|
write_text_atomic(mf, project_to_toml(m_after_add))
|
||||||
|
cmd_project_lock(ctx, mf, false)
|
||||||
|
|
||||||
|
// Publish helper 2.0.0 -> update upgrades app, helper, lib to 2.0.0.
|
||||||
|
publish_mock_pkg(
|
||||||
|
main_ch,
|
||||||
|
work,
|
||||||
|
"helper",
|
||||||
|
"2.0.0",
|
||||||
|
Map([("lib", "^2.0")]),
|
||||||
|
["bin/helper"],
|
||||||
|
script="#!/bin/sh\nexit 0\n",
|
||||||
|
)
|
||||||
|
cmd_project_update(ctx, mf, [])
|
||||||
|
let lock2 = parse_lockfile(read_text(proj + "/orbit.lock").unwrap())
|
||||||
|
for p in lock2.packages {
|
||||||
|
assert_eq(p.version, "2.0.0")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove packages -> cleans dependencies, orbit.lock, and .orbit/bin.
|
||||||
|
cmd_project_remove(ctx, mf, ["app", "helper"])
|
||||||
|
let m_final = parse_project_manifest(read_text(mf).unwrap(), "proj")
|
||||||
|
assert_eq(m_final.dependencies.length(), 0)
|
||||||
|
let lock_final = parse_lockfile(read_text(proj + "/orbit.lock").unwrap())
|
||||||
|
assert_eq(lock_final.packages.length(), 0)
|
||||||
|
assert_false(exists(proj + "/.orbit/bin/app"))
|
||||||
|
assert_false(exists(proj + "/.orbit/bin/helper"))
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
OrbitError(msg) => fail("unexpected OrbitError: " + msg)
|
||||||
|
e => raise e
|
||||||
|
}
|
||||||
|
}
|
||||||
+227
-31
@@ -1,12 +1,13 @@
|
|||||||
// Minimal semantic versions and constraints.
|
// Minimal semantic versions and constraints.
|
||||||
//
|
//
|
||||||
// Constraint forms:
|
// Constraint forms (comma-separated clauses are ANDed together):
|
||||||
// "" | "*" | "latest" any stable version
|
// "" | "*" | "latest" any stable version
|
||||||
// "1.2.3" | "=1.2.3" exact
|
// "1.2.3" | "=1.2.3" | "==1.2.3" exact
|
||||||
// "1" | "1.2" prefix (1.x.x / 1.2.x)
|
// "1" | "1.2" | "1.*" | "1.2.*" prefix (1.x.x / 1.2.x)
|
||||||
// "^1.2.3" same major (same minor while major is 0), >= base
|
// "^1.2.3" same major (same minor while major is 0), >= base
|
||||||
// "~1.2.3" same major and minor, >= base
|
// "~1.2.3" same major and minor (or major if ~1), >= base
|
||||||
// ">=1.2.3" at least base
|
// ">=1.2.3" | "<=1.2.3" | ">1.2.3" | "<1.2.3" relational
|
||||||
|
// "!=1.2.3" | "!=1.2.*" exclusion
|
||||||
// Prerelease versions (1.0.0-rc1) only match constraints that mention a '-'.
|
// Prerelease versions (1.0.0-rc1) only match constraints that mention a '-'.
|
||||||
|
|
||||||
///|
|
///|
|
||||||
@@ -76,6 +77,113 @@ fn cmp_ver(a : Ver, b : Ver) -> Int32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn strip_dot_star(s : String) -> (String, Bool) {
|
||||||
|
let a = chars(s)
|
||||||
|
let n = a.length()
|
||||||
|
if n >= 2 && a[n - 2] == '.' && a[n - 1] == '*' {
|
||||||
|
(slice(a, 0, n - 2), true)
|
||||||
|
} else {
|
||||||
|
(s, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn matches_prefix(v : Ver, b : Ver) -> Bool {
|
||||||
|
for i = 0; i < b.parts; i = i + 1 {
|
||||||
|
if v.nums[i] != b.nums[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn satisfies_clause(v : Ver, cl : String) -> Bool {
|
||||||
|
let c = trim(cl)
|
||||||
|
if c == "*" || c == "latest" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
let with_base = fn(rest : String, rule : (Ver) -> Bool) -> Bool {
|
||||||
|
match parse_ver(trim(rest)) {
|
||||||
|
Some(b) => cmp_ver(v, b) >= 0 && rule(b)
|
||||||
|
None => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if has_prefix(c, ">=") {
|
||||||
|
with_base(drop_chars(c, 2), fn(_b) { true })
|
||||||
|
} else if has_prefix(c, "<=") {
|
||||||
|
match parse_ver(trim(drop_chars(c, 2))) {
|
||||||
|
Some(b) => cmp_ver(v, b) <= 0
|
||||||
|
None => false
|
||||||
|
}
|
||||||
|
} else if has_prefix(c, "!=") {
|
||||||
|
let (ver_str, had_wild) = strip_dot_star(trim(drop_chars(c, 2)))
|
||||||
|
match parse_ver(ver_str) {
|
||||||
|
Some(b) =>
|
||||||
|
if b.parts < 3 || had_wild {
|
||||||
|
if had_wild && b.parts == 3 {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
!matches_prefix(v, b)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmp_ver(v, b) != 0
|
||||||
|
}
|
||||||
|
None => false
|
||||||
|
}
|
||||||
|
} else if has_prefix(c, "==") {
|
||||||
|
let (ver_str, had_wild) = strip_dot_star(trim(drop_chars(c, 2)))
|
||||||
|
match parse_ver(ver_str) {
|
||||||
|
Some(b) =>
|
||||||
|
if had_wild && b.parts == 3 {
|
||||||
|
false
|
||||||
|
} else if b.parts == 3 && !had_wild {
|
||||||
|
cmp_ver(v, b) == 0
|
||||||
|
} else {
|
||||||
|
matches_prefix(v, b)
|
||||||
|
}
|
||||||
|
None => false
|
||||||
|
}
|
||||||
|
} else if has_prefix(c, ">") {
|
||||||
|
match parse_ver(trim(drop_chars(c, 1))) {
|
||||||
|
Some(b) => cmp_ver(v, b) > 0
|
||||||
|
None => false
|
||||||
|
}
|
||||||
|
} else if has_prefix(c, "<") {
|
||||||
|
match parse_ver(trim(drop_chars(c, 1))) {
|
||||||
|
Some(b) => cmp_ver(v, b) < 0
|
||||||
|
None => false
|
||||||
|
}
|
||||||
|
} else if has_prefix(c, "^") {
|
||||||
|
with_base(drop_chars(c, 1), fn(b) {
|
||||||
|
v.nums[0] == b.nums[0] && (b.nums[0] != 0 || v.nums[1] == b.nums[1])
|
||||||
|
})
|
||||||
|
} else if has_prefix(c, "~") {
|
||||||
|
with_base(drop_chars(c, 1), fn(b) {
|
||||||
|
v.nums[0] == b.nums[0] && (b.parts == 1 || v.nums[1] == b.nums[1])
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
let exact = if has_prefix(c, "=") {
|
||||||
|
trim(drop_chars(c, 1))
|
||||||
|
} else {
|
||||||
|
c
|
||||||
|
}
|
||||||
|
let (ver_str, had_wild) = strip_dot_star(exact)
|
||||||
|
match parse_ver(ver_str) {
|
||||||
|
Some(b) =>
|
||||||
|
if had_wild && b.parts == 3 {
|
||||||
|
false
|
||||||
|
} else if b.parts == 3 && !had_wild {
|
||||||
|
cmp_ver(v, b) == 0
|
||||||
|
} else {
|
||||||
|
matches_prefix(v, b)
|
||||||
|
}
|
||||||
|
None => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
fn satisfies(v : Ver, c0 : String) -> Bool {
|
fn satisfies(v : Ver, c0 : String) -> Bool {
|
||||||
let c = trim(c0)
|
let c = trim(c0)
|
||||||
@@ -85,40 +193,78 @@ fn satisfies(v : Ver, c0 : String) -> Bool {
|
|||||||
if v.pre != "" && !(has_char(c, '-')) {
|
if v.pre != "" && !(has_char(c, '-')) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
let with_base = fn(rest : String, rule : (Ver) -> Bool) -> Bool {
|
let pieces = split_on(c, ',')
|
||||||
match parse_ver(rest) {
|
for piece in pieces {
|
||||||
Some(b) => cmp_ver(v, b) >= 0 && rule(b)
|
let p = trim(piece)
|
||||||
|
if p == "" || !satisfies_clause(v, p) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn valid_semver_clause(cl : String) -> Bool {
|
||||||
|
let c = trim(cl)
|
||||||
|
if c == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if c == "*" || c == "latest" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
let check_exact_or_wild = fn(raw : String) -> Bool {
|
||||||
|
let (ver_str, had_wild) = strip_dot_star(trim(raw))
|
||||||
|
match parse_ver(ver_str) {
|
||||||
|
Some(b) => !(had_wild && b.parts == 3)
|
||||||
None => false
|
None => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if has_prefix(c, ">=") {
|
if has_prefix(c, ">=") || has_prefix(c, "<=") {
|
||||||
with_base(drop_chars(c, 2), fn(_b) { true })
|
parse_ver(trim(drop_chars(c, 2))) is Some(_)
|
||||||
} else if has_prefix(c, "^") {
|
} else if has_prefix(c, "!=") || has_prefix(c, "==") {
|
||||||
with_base(drop_chars(c, 1), fn(b) {
|
check_exact_or_wild(drop_chars(c, 2))
|
||||||
v.nums[0] == b.nums[0] && (b.nums[0] != 0 || v.nums[1] == b.nums[1])
|
} else if has_prefix(c, ">") ||
|
||||||
})
|
has_prefix(c, "<") ||
|
||||||
} else if has_prefix(c, "~") {
|
has_prefix(c, "^") ||
|
||||||
with_base(drop_chars(c, 1), fn(b) {
|
has_prefix(c, "~") {
|
||||||
v.nums[0] == b.nums[0] && v.nums[1] == b.nums[1]
|
parse_ver(trim(drop_chars(c, 1))) is Some(_)
|
||||||
})
|
} else if has_prefix(c, "=") {
|
||||||
|
check_exact_or_wild(drop_chars(c, 1))
|
||||||
} else {
|
} else {
|
||||||
let exact = if has_prefix(c, "=") { drop_chars(c, 1) } else { c }
|
check_exact_or_wild(c)
|
||||||
match parse_ver(exact) {
|
|
||||||
Some(b) =>
|
|
||||||
if b.parts == 3 {
|
|
||||||
cmp_ver(v, b) == 0
|
|
||||||
} else {
|
|
||||||
let mut ok = true
|
|
||||||
for i = 0; i < b.parts; i = i + 1 {
|
|
||||||
if v.nums[i] != b.nums[i] {
|
|
||||||
ok = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ok
|
|
||||||
|
///|
|
||||||
|
fn valid_constraint(c0 : String) -> Bool {
|
||||||
|
let c = trim(c0)
|
||||||
|
if c == "" || c == "*" || c == "latest" {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
None => false
|
if !has_char(c, ',') && valid_semver_clause(c) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if has_char(c, ',') {
|
||||||
|
let pieces = split_on(c, ',')
|
||||||
|
for piece in pieces {
|
||||||
|
if !valid_semver_clause(piece) {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Allow non-semver literal tag pins (e.g. "edge") when they aren't malformed
|
||||||
|
// version numbers or operator expressions.
|
||||||
|
let a = chars(c)
|
||||||
|
let looks_like_ver = a.length() > 0 &&
|
||||||
|
(
|
||||||
|
(a[0] >= '0' && a[0] <= '9') ||
|
||||||
|
(a.length() > 1 && a[0] == 'v' && a[1] >= '0' && a[1] <= '9')
|
||||||
|
)
|
||||||
|
if looks_like_ver {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
valid_name(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
@@ -136,7 +282,11 @@ fn satisfies_all(version : String, cons : Array[String]) -> Bool {
|
|||||||
None => {
|
None => {
|
||||||
for c in cons {
|
for c in cons {
|
||||||
let t = trim(c)
|
let t = trim(c)
|
||||||
if t != "" && t != "*" && t != version {
|
if t != "" &&
|
||||||
|
t != "*" &&
|
||||||
|
t != version &&
|
||||||
|
t != "=" + version &&
|
||||||
|
t != "==" + version {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -239,3 +389,49 @@ test "pick" {
|
|||||||
assert_eq(pick_tag(tags, ["^3"]), None)
|
assert_eq(pick_tag(tags, ["^3"]), None)
|
||||||
assert_eq(sorted_versions(tags), ["2.1.0-rc1", "2.0.0", "1.2.0", "1.0.0"])
|
assert_eq(sorted_versions(tags), ["2.1.0-rc1", "2.0.0", "1.2.0", "1.0.0"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "compound and relational constraints" {
|
||||||
|
let v142 = parse_ver("1.4.2").unwrap()
|
||||||
|
let v120 = parse_ver("1.2.0").unwrap()
|
||||||
|
let v200 = parse_ver("2.0.0").unwrap()
|
||||||
|
let v150 = parse_ver("1.5.0").unwrap()
|
||||||
|
let v120rc = parse_ver("1.2.0-rc1").unwrap()
|
||||||
|
|
||||||
|
assert_true(satisfies(v142, "<2.0.0"))
|
||||||
|
assert_true(!satisfies(v200, "<2.0.0"))
|
||||||
|
assert_true(satisfies(v200, "<=2.0.0"))
|
||||||
|
assert_true(satisfies(v142, ">1.4.0"))
|
||||||
|
assert_true(!satisfies(v120, ">1.2.0"))
|
||||||
|
assert_true(satisfies(v142, "==1.4.2"))
|
||||||
|
assert_true(!satisfies(v142, "!=1.4.2"))
|
||||||
|
assert_true(satisfies(v150, "!=1.4.2"))
|
||||||
|
assert_true(satisfies(v142, "1.*"))
|
||||||
|
assert_true(satisfies(v142, "1.4.*"))
|
||||||
|
assert_true(!satisfies(v150, "1.4.*"))
|
||||||
|
assert_true(satisfies(v142, "!=1.2.*"))
|
||||||
|
assert_true(!satisfies(v120, "!=1.2.*"))
|
||||||
|
assert_true(satisfies(v142, ">=1.2.0, <2.0.0"))
|
||||||
|
assert_true(!satisfies(v200, ">=1.2.0, <2.0.0"))
|
||||||
|
assert_true(satisfies(v150, ">=1.0, !=1.4.2, <2.0"))
|
||||||
|
assert_true(!satisfies(v142, ">=1.0, !=1.4.2, <2.0"))
|
||||||
|
assert_true(satisfies(v120rc, ">=1.0.0-rc1, <2.0.0"))
|
||||||
|
assert_true(!satisfies(v120rc, ">=1.0.0, <2.0.0"))
|
||||||
|
assert_true(satisfies(v142, "~1"))
|
||||||
|
|
||||||
|
assert_true(satisfies_all("edge", ["edge"]))
|
||||||
|
assert_true(satisfies_all("edge", ["=edge"]))
|
||||||
|
assert_true(satisfies_all("edge", ["==edge"]))
|
||||||
|
assert_true(!satisfies_all("edge", [">=1.0"]))
|
||||||
|
|
||||||
|
assert_true(valid_constraint(">=1.2.0, <2.0.0"))
|
||||||
|
assert_true(valid_constraint("1.4.*"))
|
||||||
|
assert_true(valid_constraint("edge"))
|
||||||
|
assert_false(valid_constraint(">=abc"))
|
||||||
|
assert_false(valid_constraint(">=1,"))
|
||||||
|
assert_false(valid_constraint("<="))
|
||||||
|
assert_false(valid_constraint("^^1.0"))
|
||||||
|
assert_false(valid_constraint("1.2.3.4"))
|
||||||
|
assert_false(valid_constraint("1.2.3.*"))
|
||||||
|
assert_false(valid_constraint("~>1.0"))
|
||||||
|
}
|
||||||
+1568
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user