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
+4563
-266
No files matched your search
+170
-22
@@ -4,8 +4,22 @@
|
||||
let usage : String =
|
||||
#|orbit - packages as OCI artifacts
|
||||
#|
|
||||
#|usage:
|
||||
#| orbit init create folders and config.toml
|
||||
#|usage (project workflow, when orbit.toml is present):
|
||||
#| 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]
|
||||
#| log in to an OCI registry
|
||||
#| orbit logout <host> remove stored registry credentials
|
||||
@@ -13,19 +27,21 @@ let usage : String =
|
||||
#| orbit channel add <name> <url> [--plain-http]
|
||||
#| orbit publish <dir> [--channel <name>] [--no-latest]
|
||||
#| push <dir>/orbit.json + <dir>/files/
|
||||
#| orbit install [channel::]<name>[@constraint]...
|
||||
#| install with dependencies
|
||||
#| orbit remove <name>... [--force] remove, then drop unused dependencies
|
||||
#| orbit upgrade [name...] upgrade within constraints
|
||||
#| orbit rollback <name> switch to the previous build
|
||||
#| orbit list installed packages
|
||||
#| orbit install [-g] [channel::]<name>[@constraint]...
|
||||
#| install globally with SAT dependency solving
|
||||
#| orbit remove [-g] <name>... [--force] remove, then drop unused dependencies
|
||||
#| orbit upgrade [-g] [name...] jointly upgrade within constraints
|
||||
#| orbit rollback <name> switch to the previous global build
|
||||
#| orbit list [-g] installed global packages
|
||||
#| orbit info [channel::]<name> installed package details (local only)
|
||||
#| orbit versions <name> published versions
|
||||
#| orbit search [term] list repositories (needs catalog API)
|
||||
#| 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
|
||||
#|credentials: <orbit root>/auth.json (falls back to ~/.docker/config.json)
|
||||
#|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 {
|
||||
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 username : String? = None
|
||||
let mut password : String? = None
|
||||
let mut force_global = false
|
||||
let mut manifest_path : String? = None
|
||||
let mut i = 1
|
||||
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]
|
||||
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() {
|
||||
raise OrbitError("usage: orbit publish <dir> --channel <name>")
|
||||
}
|
||||
@@ -118,14 +187,23 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
||||
}
|
||||
match cmd {
|
||||
"help" | "-h" | "--help" => println(usage)
|
||||
"init" => {
|
||||
if pos.length() > 0 {
|
||||
raise OrbitError(
|
||||
"init takes no arguments; use `orbit channel add <name> <url>`",
|
||||
)
|
||||
"new" => {
|
||||
if force_global {
|
||||
raise OrbitError("--global cannot be used with `orbit new`")
|
||||
}
|
||||
cmd_init()
|
||||
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 {
|
||||
raise OrbitError(
|
||||
"init takes no arguments; use `orbit channel add <name> <url>` or `orbit new <dir>`",
|
||||
)
|
||||
}
|
||||
cmd_init()
|
||||
}
|
||||
"login" => {
|
||||
need(
|
||||
pos,
|
||||
@@ -160,20 +238,90 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
||||
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" => {
|
||||
need(pos, 1, "publish <dir>")
|
||||
let ch = find_channel(load_ctx(), publish_to)
|
||||
publish(ch, pos[0], !flags.contains("--no-latest"))
|
||||
}
|
||||
"install" | "add" => cmd_install(load_ctx(), pos)
|
||||
"remove" | "rm" => cmd_remove(load_ctx(), pos, flags.contains("--force"))
|
||||
"upgrade" | "up" => cmd_upgrade(load_ctx(), pos)
|
||||
"install" =>
|
||||
match resolve_project_or_none(force_global, manifest_path) {
|
||||
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" => {
|
||||
need(pos, 1, "rollback <name>")
|
||||
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" => {
|
||||
need(pos, 1, "info [channel::]<name>")
|
||||
cmd_info(load_ctx(), pos[0])
|
||||
|
||||
+53
-3
@@ -179,6 +179,21 @@ fn valid_rel_path(p : String) -> Bool {
|
||||
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 {
|
||||
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")
|
||||
}
|
||||
}
|
||||
for dep, _ in m.depends {
|
||||
if !valid_name(dep) {
|
||||
for dep, constraint in m.depends {
|
||||
if !valid_dep_key(dep) {
|
||||
raise OrbitError("orbit.json: invalid dependency name '\{dep}'")
|
||||
}
|
||||
if !valid_constraint(constraint) {
|
||||
raise OrbitError(
|
||||
"orbit.json: invalid version constraint '\{constraint}' for '\{dep}'",
|
||||
)
|
||||
}
|
||||
}
|
||||
m
|
||||
}
|
||||
@@ -367,15 +387,45 @@ fn bin_dir(ctx : Ctx) -> String {
|
||||
ctx.root + "/bin"
|
||||
}
|
||||
|
||||
///|
|
||||
fn cache_dir(root : String) -> String {
|
||||
root + "/cache/manifests"
|
||||
}
|
||||
|
||||
///|
|
||||
test "manifest roundtrip" {
|
||||
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.bins, ["bin/hello"])
|
||||
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("/bin/sh"))
|
||||
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)
|
||||
}
|
||||
+277
-190
@@ -8,19 +8,11 @@ struct Step {
|
||||
version : String
|
||||
digest : String
|
||||
manifest : Manifest
|
||||
mut explicit : Bool
|
||||
mut constraint : String
|
||||
explicit : Bool
|
||||
constraint : String
|
||||
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 {
|
||||
Manifest::{
|
||||
@@ -34,172 +26,217 @@ fn manifest_of_installed(p : Installed) -> Manifest {
|
||||
}
|
||||
|
||||
///|
|
||||
/// Every constraint that currently applies to `name`: the request itself,
|
||||
/// the user's own constraint if they installed it explicitly, and what each
|
||||
/// other package requires (using planned manifests for packages being replaced).
|
||||
fn constraints_for(
|
||||
p : Planner,
|
||||
name : String,
|
||||
requested : String,
|
||||
) -> Array[String] {
|
||||
let cons : Array[String] = [requested]
|
||||
match p.ctx.state.get(name) {
|
||||
Some(inst) =>
|
||||
if inst.explicit && inst.constraint != "" && inst.constraint != requested {
|
||||
cons.push(inst.constraint)
|
||||
/// "[channel::]name[@constraint]" -> (channel, name, constraint, has_explicit_constraint)
|
||||
fn parse_spec_full(
|
||||
spec : String,
|
||||
) -> (String?, String, String, Bool) raise OrbitError {
|
||||
let (channel, rest) = split_channel(spec)
|
||||
match channel {
|
||||
Some(ch) =>
|
||||
if !valid_name(ch) {
|
||||
raise OrbitError("invalid channel name '\{ch}'")
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
for other, inst in p.ctx.state {
|
||||
if other == name {
|
||||
continue
|
||||
}
|
||||
let deps = match p.steps.get(other) {
|
||||
Some(st) => st.manifest.depends
|
||||
None => inst.depends
|
||||
}
|
||||
match deps.get(name) {
|
||||
Some(c) => cons.push(c)
|
||||
None => ()
|
||||
let (name, c) = split_first(rest, '@')
|
||||
if !valid_name(name) {
|
||||
raise OrbitError("invalid package name '\{name}'")
|
||||
}
|
||||
if c == "" {
|
||||
(channel, name, "*", false)
|
||||
} else {
|
||||
if !valid_constraint(c) {
|
||||
raise OrbitError("invalid version constraint '\{c}' for '\{name}'")
|
||||
}
|
||||
(channel, name, c, true)
|
||||
}
|
||||
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 {
|
||||
inst.constraint
|
||||
},
|
||||
keep: true,
|
||||
}
|
||||
p.steps[name] = st
|
||||
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]"
|
||||
fn parse_spec(spec : String) -> (String?, String, String) raise OrbitError {
|
||||
let (channel, rest) = split_channel(spec)
|
||||
let (name, c) = split_first(rest, '@')
|
||||
if !valid_name(name) {
|
||||
raise OrbitError("invalid package name '\{name}'")
|
||||
let (channel, name, c, _) = parse_spec_full(spec)
|
||||
(channel, name, 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
|
||||
}
|
||||
(channel, name, if c == "" { "*" } else { 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
|
||||
for st in p.order {
|
||||
for st in steps {
|
||||
if st.keep {
|
||||
match ctx.state.get(st.name) {
|
||||
Some(inst) => {
|
||||
@@ -345,57 +382,106 @@ 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 {
|
||||
if specs.length() == 0 {
|
||||
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 {
|
||||
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
|
||||
/// constraints allow. Dependencies are moved only when required.
|
||||
/// Upgrade the named packages (or everything) jointly to the newest versions
|
||||
/// their constraints allow.
|
||||
async fn cmd_upgrade(ctx : Ctx, names : Array[String]) -> Unit raise OrbitError {
|
||||
let targets : Array[String] = []
|
||||
let reqs : Array[(String?, String, String, String)] = []
|
||||
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)
|
||||
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 {
|
||||
for n in names {
|
||||
if !ctx.state.contains(n) {
|
||||
raise OrbitError("\{n} is not installed")
|
||||
let inst = match ctx.state.get(n) {
|
||||
Some(i) => i
|
||||
None => raise OrbitError("\{n} is not installed")
|
||||
}
|
||||
targets.push(n)
|
||||
reqs.push((
|
||||
Some(inst.channel),
|
||||
n,
|
||||
if inst.constraint == "" {
|
||||
"*"
|
||||
} else {
|
||||
inst.constraint
|
||||
},
|
||||
"installed \{n}",
|
||||
))
|
||||
}
|
||||
}
|
||||
let p = new_planner(ctx, targets)
|
||||
for n in targets {
|
||||
match ctx.state.get(n) {
|
||||
Some(inst) => visit(p, n, "*", inst.explicit, None)
|
||||
None => ()
|
||||
}
|
||||
let steps = plan_global(ctx, reqs, targets, Map([]))
|
||||
apply_plan(ctx, steps)
|
||||
if names.length() == 0 {
|
||||
autoremove(ctx)
|
||||
save_state(ctx)
|
||||
}
|
||||
apply_plan(ctx, p)
|
||||
}
|
||||
|
||||
///|
|
||||
fn reverse_deps(ctx : Ctx, name : String) -> Array[String] {
|
||||
let r : Array[String] = []
|
||||
for other, p in ctx.state {
|
||||
if other != name && p.depends.contains(name) {
|
||||
r.push(other)
|
||||
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
|
||||
@@ -506,7 +592,8 @@ async fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
println("\{name}: \{from} -> \{prev.version}")
|
||||
let missing : Array[String] = []
|
||||
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) =>
|
||||
if !satisfies_all(d.version, [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))
|
||||
}
|
||||
|
||||
///|
|
||||
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.
|
||||
async fn fetch_manifest(
|
||||
async fn fetch_manifest_with_raw(
|
||||
ch : Channel,
|
||||
name : String,
|
||||
digest : String,
|
||||
) -> Manifest raise OrbitError {
|
||||
) -> (Manifest, String) raise OrbitError {
|
||||
with_spinner("Reading metadata for \{ch.name}::\{name}", () => {
|
||||
let repo = channel_repo_path(ch, name)
|
||||
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 {
|
||||
raise OrbitError(
|
||||
"\{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? {
|
||||
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")
|
||||
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.version, "1.2.0")
|
||||
assert_eq(mf.description, "Mock OCI tool")
|
||||
assert_eq(mf.bins, ["bin/mytool"])
|
||||
|
||||
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 installed_dir = fetch_into_store(ctx, ch, "mytool", d1)
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
///|
|
||||
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
|
||||
}
|
||||
}
|
||||
+231
-35
@@ -1,12 +1,13 @@
|
||||
// Minimal semantic versions and constraints.
|
||||
//
|
||||
// Constraint forms:
|
||||
// Constraint forms (comma-separated clauses are ANDed together):
|
||||
// "" | "*" | "latest" any stable version
|
||||
// "1.2.3" | "=1.2.3" exact
|
||||
// "1" | "1.2" prefix (1.x.x / 1.2.x)
|
||||
// "1.2.3" | "=1.2.3" | "==1.2.3" exact
|
||||
// "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 and minor, >= base
|
||||
// ">=1.2.3" at least base
|
||||
// "~1.2.3" same major and minor (or major if ~1), >= 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 '-'.
|
||||
|
||||
///|
|
||||
@@ -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 {
|
||||
let c = trim(c0)
|
||||
@@ -85,42 +193,80 @@ fn satisfies(v : Ver, c0 : String) -> Bool {
|
||||
if v.pre != "" && !(has_char(c, '-')) {
|
||||
return false
|
||||
}
|
||||
let with_base = fn(rest : String, rule : (Ver) -> Bool) -> Bool {
|
||||
match parse_ver(rest) {
|
||||
Some(b) => cmp_ver(v, b) >= 0 && rule(b)
|
||||
let pieces = split_on(c, ',')
|
||||
for piece in pieces {
|
||||
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
|
||||
}
|
||||
}
|
||||
if has_prefix(c, ">=") {
|
||||
with_base(drop_chars(c, 2), fn(_b) { true })
|
||||
} 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] && v.nums[1] == b.nums[1]
|
||||
})
|
||||
if has_prefix(c, ">=") || has_prefix(c, "<=") {
|
||||
parse_ver(trim(drop_chars(c, 2))) is Some(_)
|
||||
} else if has_prefix(c, "!=") || has_prefix(c, "==") {
|
||||
check_exact_or_wild(drop_chars(c, 2))
|
||||
} else if has_prefix(c, ">") ||
|
||||
has_prefix(c, "<") ||
|
||||
has_prefix(c, "^") ||
|
||||
has_prefix(c, "~") {
|
||||
parse_ver(trim(drop_chars(c, 1))) is Some(_)
|
||||
} else if has_prefix(c, "=") {
|
||||
check_exact_or_wild(drop_chars(c, 1))
|
||||
} else {
|
||||
let exact = if has_prefix(c, "=") { drop_chars(c, 1) } else { 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
|
||||
}
|
||||
None => false
|
||||
}
|
||||
check_exact_or_wild(c)
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn valid_constraint(c0 : String) -> Bool {
|
||||
let c = trim(c0)
|
||||
if c == "" || c == "*" || c == "latest" {
|
||||
return true
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
///|
|
||||
fn satisfies_all(version : String, cons : Array[String]) -> Bool {
|
||||
match parse_ver(version) {
|
||||
@@ -136,7 +282,11 @@ fn satisfies_all(version : String, cons : Array[String]) -> Bool {
|
||||
None => {
|
||||
for c in cons {
|
||||
let t = trim(c)
|
||||
if t != "" && t != "*" && t != version {
|
||||
if t != "" &&
|
||||
t != "*" &&
|
||||
t != version &&
|
||||
t != "=" + version &&
|
||||
t != "==" + version {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -239,3 +389,49 @@ test "pick" {
|
||||
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"])
|
||||
}
|
||||
|
||||
///|
|
||||
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