Release v0.1.2: embedded stdlib, docs, and extension branch policy.
Embed lib/*.mq.md in binary; marqdo version --check; public writeback/subtask pages; restore /vscode-extension/ ignore. VSIX built from branch vscode-extension only (see doc/design/vscode-extension-commit.md). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3da7b276d3
commit
2e65c055b8
23 files changed
+469
-53
No files matched your search
@@ -0,0 +1,32 @@
|
||||
//! Official `lib/*.mq.md` baked into the binary (fallback when disk `lib/` is absent).
|
||||
|
||||
use include_dir::{include_dir, Dir};
|
||||
|
||||
static LIB: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/lib");
|
||||
|
||||
/// Read `lib/<remainder>` from the embedded tree (e.g. `text.mq.md`).
|
||||
pub fn read_file(remainder: &str) -> Option<String> {
|
||||
let key = remainder.replace('\\', "/");
|
||||
LIB.get_file(&key)
|
||||
.and_then(|f| f.contents_utf8().map(|s| s.to_string()))
|
||||
}
|
||||
|
||||
pub fn has_file(remainder: &str) -> bool {
|
||||
let key = remainder.replace('\\', "/");
|
||||
LIB.get_file(&key).is_some()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn embedded_has_core_libs() {
|
||||
assert!(has_file("text.mq.md"));
|
||||
assert!(has_file("subtask.mq.md"));
|
||||
assert!(has_file("writeback.mq.md"));
|
||||
assert!(read_file("math.mq.md")
|
||||
.unwrap()
|
||||
.contains("host_math_add"));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ pub mod capture;
|
||||
pub mod catalog;
|
||||
pub mod debug;
|
||||
pub mod diagnostics;
|
||||
pub mod embedded_lib;
|
||||
pub mod ext_cli;
|
||||
pub mod foreign;
|
||||
pub mod formula;
|
||||
@@ -21,6 +22,7 @@ pub mod lex;
|
||||
pub mod load;
|
||||
pub mod parse;
|
||||
pub mod value;
|
||||
pub mod version_check;
|
||||
pub mod view;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
+45
-3
@@ -8,6 +8,7 @@ use anyhow::{bail, Context, Result};
|
||||
|
||||
use crate::ast::{Function, Module};
|
||||
use crate::diagnostics::Diagnostic;
|
||||
use crate::embedded_lib;
|
||||
use crate::parse::parse_source;
|
||||
|
||||
/// Load `path` and recursively merge imported modules' top-level functions.
|
||||
@@ -24,7 +25,7 @@ fn load_module_inner(path: &Path, visited: &mut HashSet<PathBuf>) -> Result<Modu
|
||||
bail!("circular import involving {}", path.display());
|
||||
}
|
||||
|
||||
let source = std::fs::read_to_string(path)
|
||||
let source = read_module_source(path)
|
||||
.with_context(|| format!("failed to read {}", path.display()))?;
|
||||
let mut module = parse_source(&source).map_err(|e| attach_path(path, e))?;
|
||||
|
||||
@@ -41,8 +42,38 @@ fn load_module_inner(path: &Path, visited: &mut HashSet<PathBuf>) -> Result<Modu
|
||||
Ok(module)
|
||||
}
|
||||
|
||||
fn read_module_source(path: &Path) -> Result<String> {
|
||||
if path.is_file() {
|
||||
return std::fs::read_to_string(path).map_err(Into::into);
|
||||
}
|
||||
if let Some(source) = read_embedded_for_path(path) {
|
||||
return Ok(source);
|
||||
}
|
||||
std::fs::read_to_string(path).map_err(Into::into)
|
||||
}
|
||||
|
||||
fn read_embedded_for_path(path: &Path) -> Option<String> {
|
||||
lib_remainder(path).as_deref().and_then(embedded_lib::read_file)
|
||||
}
|
||||
|
||||
fn lib_remainder(path: &Path) -> Option<String> {
|
||||
let s = path.to_string_lossy().replace('\\', "/");
|
||||
if let Some(rest) = s.strip_prefix("lib/") {
|
||||
return Some(rest.to_string());
|
||||
}
|
||||
// Absolute or relative paths ending in lib/foo.mq.md
|
||||
let parts: Vec<&str> = s.split('/').collect();
|
||||
if let Some(pos) = parts.iter().position(|&p| p == "lib") {
|
||||
if pos + 1 < parts.len() {
|
||||
return Some(parts[pos + 1..].join("/"));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Resolve an import path: relative to the importer first; `lib/…` / `std/…`
|
||||
/// and `ext/…` also search official roots (`MARQDO_LIB` / `MARQDO_EXT`, cwd, near the binary).
|
||||
/// and `ext/…` also search official roots (`MARQDO_LIB` / `MARQDO_EXT`, cwd, near the binary),
|
||||
/// then the embedded stdlib baked into the binary.
|
||||
pub fn resolve_import(from_dir: &Path, rel: &str) -> Result<PathBuf> {
|
||||
let rel = rel.replace('\\', "/");
|
||||
let direct = from_dir.join(&rel);
|
||||
@@ -67,8 +98,11 @@ pub fn resolve_import(from_dir: &Path, rel: &str) -> Result<PathBuf> {
|
||||
return Ok(as_repo_root);
|
||||
}
|
||||
}
|
||||
if embedded_lib::has_file(remainder) {
|
||||
return Ok(PathBuf::from("lib").join(remainder));
|
||||
}
|
||||
bail!(
|
||||
"cannot resolve library import `{rel}` (set MARQDO_LIB or keep a lib/ next to the project)"
|
||||
"cannot resolve library import `{rel}` (set MARQDO_LIB, keep lib/ next to the project, or use a binary with embedded stdlib)"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -175,4 +209,12 @@ mod tests {
|
||||
let p2 = resolve_import(Path::new("tests/keywords"), "std/text.mq.md").unwrap();
|
||||
assert!(p2.ends_with("text.mq.md"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_embedded_lib_source() {
|
||||
let p = resolve_import(Path::new("/nonexistent"), "lib/writeback.mq.md").unwrap();
|
||||
assert!(p.to_string_lossy().replace('\\', "/").contains("lib/writeback.mq.md"));
|
||||
let src = read_module_source(&p).unwrap();
|
||||
assert!(src.contains("host_writeback"));
|
||||
}
|
||||
}
|
||||
+13
@@ -115,6 +115,11 @@ enum Commands {
|
||||
#[command(subcommand)]
|
||||
action: ExtAction,
|
||||
},
|
||||
/// Print version; `--check` compares with the latest GitHub release
|
||||
Version {
|
||||
#[arg(long)]
|
||||
check: bool,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
@@ -262,5 +267,13 @@ fn try_main() -> Result<i32> {
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
Commands::Version { check } => {
|
||||
if check {
|
||||
marqdo::version_check::check_latest().map_err(|e| anyhow::anyhow!(e))?;
|
||||
} else {
|
||||
marqdo::version_check::print_version();
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
//! Optional check against GitHub Releases (`marqdo version --check`).
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
const REPO: &str = "cflmy/marqdo";
|
||||
|
||||
pub fn print_version() {
|
||||
println!("marqdo {}", env!("CARGO_PKG_VERSION"));
|
||||
}
|
||||
|
||||
pub fn check_latest() -> Result<(), String> {
|
||||
let current = env!("CARGO_PKG_VERSION");
|
||||
let url = format!("https://api.github.com/repos/{REPO}/releases/latest");
|
||||
let response = ureq::get(&url)
|
||||
.set("Accept", "application/vnd.github+json")
|
||||
.set("User-Agent", &format!("marqdo/{current}"))
|
||||
.call()
|
||||
.map_err(|e| format!("version check failed: {e}"))?;
|
||||
let body = response
|
||||
.into_string()
|
||||
.map_err(|e| format!("version check read failed: {e}"))?;
|
||||
let tag = parse_tag_name(&body).ok_or_else(|| "version check: missing tag_name".to_string())?;
|
||||
let latest = tag.trim_start_matches('v');
|
||||
match compare_semver(latest, current) {
|
||||
Ordering::Greater => {
|
||||
println!("Update available: v{latest} (you have {current})");
|
||||
println!("https://github.com/{REPO}/releases/latest");
|
||||
}
|
||||
_ => println!("marqdo {current} is up to date (latest v{latest})."),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_tag_name(json: &str) -> Option<String> {
|
||||
let needle = "\"tag_name\"";
|
||||
let start = json.find(needle)? + needle.len();
|
||||
let rest = json[start..].trim_start();
|
||||
if !rest.starts_with(':') {
|
||||
return None;
|
||||
}
|
||||
let rest = rest[1..].trim_start();
|
||||
if !rest.starts_with('"') {
|
||||
return None;
|
||||
}
|
||||
let rest = &rest[1..];
|
||||
let end = rest.find('"')?;
|
||||
Some(rest[..end].to_string())
|
||||
}
|
||||
|
||||
fn compare_semver(a: &str, b: &str) -> Ordering {
|
||||
let pa: Vec<u32> = a
|
||||
.split('-')
|
||||
.next()
|
||||
.unwrap_or(a)
|
||||
.split('.')
|
||||
.map(|s| s.parse().unwrap_or(0))
|
||||
.collect();
|
||||
let pb: Vec<u32> = b
|
||||
.split('-')
|
||||
.next()
|
||||
.unwrap_or(b)
|
||||
.split('.')
|
||||
.map(|s| s.parse().unwrap_or(0))
|
||||
.collect();
|
||||
for i in 0..3 {
|
||||
let da = pa.get(i).copied().unwrap_or(0);
|
||||
let db = pb.get(i).copied().unwrap_or(0);
|
||||
match da.cmp(&db) {
|
||||
Ordering::Equal => {}
|
||||
other => return other,
|
||||
}
|
||||
}
|
||||
Ordering::Equal
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parse_release_tag() {
|
||||
let json = r#"{"tag_name":"v0.1.2","name":"Marqdo"}"#;
|
||||
assert_eq!(parse_tag_name(json).as_deref(), Some("v0.1.2"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn semver_order() {
|
||||
assert_eq!(compare_semver("0.1.2", "0.1.1"), Ordering::Greater);
|
||||
assert_eq!(compare_semver("0.1.1", "0.1.2"), Ordering::Less);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user