adjustments on capabilities on cartridges
This commit is contained in:
@@ -7,11 +7,9 @@ const FORBIDDEN_IDENT_TOKENS: &[&str] = &[
|
||||
// HIP must be fully removed from code
|
||||
"hip",
|
||||
"HIP",
|
||||
|
||||
// Legacy RC API surface (exact token only)
|
||||
"release",
|
||||
"Release",
|
||||
|
||||
// Legacy scope helpers (exact tokens only)
|
||||
"enter_scope",
|
||||
"exit_scope",
|
||||
@@ -22,7 +20,6 @@ const FORBIDDEN_IDENT_TOKENS: &[&str] = &[
|
||||
"borrow_scope",
|
||||
"mutate_scope",
|
||||
"peek_scope",
|
||||
|
||||
// Legacy handle/gate/retain-release naming that is almost certainly RC/HIP-related
|
||||
"GateHandle",
|
||||
"gate_handle",
|
||||
@@ -48,7 +45,8 @@ const FORBIDDEN_PATH_SEGMENTS: &[&str] = &[
|
||||
|
||||
#[test]
|
||||
fn test_no_legacy_artifacts() {
|
||||
let workspace_root = find_workspace_root().expect("Failed to locate workspace root with [workspace] Cargo.toml");
|
||||
let workspace_root =
|
||||
find_workspace_root().expect("Failed to locate workspace root with [workspace] Cargo.toml");
|
||||
|
||||
// Collect Rust files under crates/**/src/**/*.rs and any build.rs under crates/**
|
||||
let files = collect_rust_files(&workspace_root);
|
||||
@@ -70,14 +68,21 @@ fn test_no_legacy_artifacts() {
|
||||
|
||||
for (tok, line, col) in toks {
|
||||
if is_forbidden_ident(&tok) {
|
||||
violations.insert(format!("{}:{}:{} identifier '{}': legacy token",
|
||||
rel(&workspace_root, path), line, col, tok));
|
||||
violations.insert(format!(
|
||||
"{}:{}:{} identifier '{}': legacy token",
|
||||
rel(&workspace_root, path),
|
||||
line,
|
||||
col,
|
||||
tok
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !violations.is_empty() {
|
||||
let mut msg = String::from("Legacy artifacts detected (RC/HIP/scope helpers). Please remove or rename.\n");
|
||||
let mut msg = String::from(
|
||||
"Legacy artifacts detected (RC/HIP/scope helpers). Please remove or rename.\n",
|
||||
);
|
||||
for v in &violations {
|
||||
msg.push_str(" - ");
|
||||
msg.push_str(v);
|
||||
@@ -110,15 +115,18 @@ fn find_workspace_root() -> Option<PathBuf> {
|
||||
fn collect_rust_files(root: &Path) -> Vec<PathBuf> {
|
||||
let mut out = Vec::new();
|
||||
let crates_dir = root.join("crates");
|
||||
if !crates_dir.exists() { return out; }
|
||||
if !crates_dir.exists() {
|
||||
return out;
|
||||
}
|
||||
|
||||
let mut stack = vec![crates_dir];
|
||||
while let Some(dir) = stack.pop() {
|
||||
// Exclude noisy/non-code directories early
|
||||
let name_lc = dir.file_name().and_then(|s| s.to_str()).unwrap_or("").to_ascii_lowercase();
|
||||
if matches!(name_lc.as_str(),
|
||||
"target" | "docs" | "files" | "sdcard" | "test-cartridges" | "temp")
|
||||
|| name_lc.starts_with("dist")
|
||||
if matches!(
|
||||
name_lc.as_str(),
|
||||
"target" | "docs" | "files" | "sdcard" | "test-cartridges" | "temp"
|
||||
) || name_lc.starts_with("dist")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -143,10 +151,8 @@ fn collect_rust_files(root: &Path) -> Vec<PathBuf> {
|
||||
}
|
||||
|
||||
fn path_segment_violation(path: &Path) -> Option<String> {
|
||||
let mut segs: Vec<String> = path
|
||||
.components()
|
||||
.filter_map(|c| c.as_os_str().to_str().map(|s| s.to_string()))
|
||||
.collect();
|
||||
let mut segs: Vec<String> =
|
||||
path.components().filter_map(|c| c.as_os_str().to_str().map(|s| s.to_string())).collect();
|
||||
if let Some(fname) = path.file_stem().and_then(|s| s.to_str()) {
|
||||
segs.push(fname.to_string());
|
||||
}
|
||||
@@ -154,10 +160,7 @@ fn path_segment_violation(path: &Path) -> Option<String> {
|
||||
let seg_lc = seg.to_ascii_lowercase();
|
||||
for &bad in FORBIDDEN_PATH_SEGMENTS {
|
||||
if seg_lc == bad.to_ascii_lowercase() {
|
||||
return Some(format!(
|
||||
"{} path-segment '{}'",
|
||||
path.display(), seg
|
||||
));
|
||||
return Some(format!("{} path-segment '{}'", path.display(), seg));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,15 +191,22 @@ fn tokenize_identifiers(text: &str) -> Vec<(String, usize, usize)> {
|
||||
let start_line = line;
|
||||
let start_col = col;
|
||||
let start = i;
|
||||
i += 1; col += 1;
|
||||
i += 1;
|
||||
col += 1;
|
||||
while i < bytes.len() {
|
||||
let c = bytes[i] as char;
|
||||
if is_ident_part(c) { i += 1; col += 1; } else { break; }
|
||||
if is_ident_part(c) {
|
||||
i += 1;
|
||||
col += 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let tok = &text[start..i];
|
||||
out.push((tok.to_string(), start_line, start_col));
|
||||
} else {
|
||||
i += 1; col += 1;
|
||||
i += 1;
|
||||
col += 1;
|
||||
}
|
||||
}
|
||||
out
|
||||
@@ -221,14 +231,20 @@ fn strip_comments_and_strings(src: &str) -> String {
|
||||
while i < b.len() {
|
||||
let c = b[i] as char;
|
||||
// Preserve newlines to maintain line numbers
|
||||
if c == '\n' { out.push('\n'); i += 1; continue; }
|
||||
if c == '\n' {
|
||||
out.push('\n');
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try to match line comment
|
||||
if c == '/' && i + 1 < b.len() && b[i + 1] as char == '/' {
|
||||
i += 2;
|
||||
while i < b.len() {
|
||||
let ch = b[i] as char;
|
||||
if ch == '\n' { break; }
|
||||
if ch == '\n' {
|
||||
break;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
continue; // newline is handled at top on next loop
|
||||
@@ -239,8 +255,13 @@ fn strip_comments_and_strings(src: &str) -> String {
|
||||
i += 2;
|
||||
while i + 1 < b.len() {
|
||||
let ch = b[i] as char;
|
||||
if ch == '\n' { out.push('\n'); }
|
||||
if ch == '*' && b[i + 1] as char == '/' { i += 2; break; }
|
||||
if ch == '\n' {
|
||||
out.push('\n');
|
||||
}
|
||||
if ch == '*' && b[i + 1] as char == '/' {
|
||||
i += 2;
|
||||
break;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
continue;
|
||||
@@ -251,7 +272,10 @@ fn strip_comments_and_strings(src: &str) -> String {
|
||||
let mut j = i + 1;
|
||||
let mut hashes = 0usize;
|
||||
if j < b.len() && b[j] as char == '#' {
|
||||
while j < b.len() && b[j] as char == '#' && hashes < 10 { hashes += 1; j += 1; }
|
||||
while j < b.len() && b[j] as char == '#' && hashes < 10 {
|
||||
hashes += 1;
|
||||
j += 1;
|
||||
}
|
||||
}
|
||||
if j < b.len() && b[j] as char == '"' {
|
||||
// Found start of raw string
|
||||
@@ -259,13 +283,18 @@ fn strip_comments_and_strings(src: &str) -> String {
|
||||
let mut end_found = false;
|
||||
while j < b.len() {
|
||||
let ch = b[j] as char;
|
||||
if ch == '\n' { out.push('\n'); j += 1; continue; }
|
||||
if ch == '\n' {
|
||||
out.push('\n');
|
||||
j += 1;
|
||||
continue;
|
||||
}
|
||||
if ch == '"' {
|
||||
// check for closing hashes
|
||||
let mut k = j + 1;
|
||||
let mut matched = 0usize;
|
||||
while matched < hashes && k < b.len() && b[k] as char == '#' {
|
||||
matched += 1; k += 1;
|
||||
matched += 1;
|
||||
k += 1;
|
||||
}
|
||||
if matched == hashes {
|
||||
i = k; // consume entire raw string
|
||||
@@ -278,7 +307,9 @@ fn strip_comments_and_strings(src: &str) -> String {
|
||||
}
|
||||
j += 1;
|
||||
}
|
||||
if !end_found { i = j; } // EOF inside string
|
||||
if !end_found {
|
||||
i = j;
|
||||
} // EOF inside string
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -288,12 +319,17 @@ fn strip_comments_and_strings(src: &str) -> String {
|
||||
i += 1; // skip starting quote
|
||||
while i < b.len() {
|
||||
let ch = b[i] as char;
|
||||
if ch == '\n' { out.push('\n'); }
|
||||
if ch == '\n' {
|
||||
out.push('\n');
|
||||
}
|
||||
if ch == '\\' {
|
||||
i += 2; // skip escaped char
|
||||
continue;
|
||||
}
|
||||
if ch == '"' { i += 1; break; }
|
||||
if ch == '"' {
|
||||
i += 1;
|
||||
break;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
continue;
|
||||
@@ -320,22 +356,38 @@ mod pathdiff {
|
||||
// pop common prefix
|
||||
let mut comps_a: Vec<Component> = Vec::new();
|
||||
let mut comps_b: Vec<Component> = Vec::new();
|
||||
for c in ita { comps_a.push(c); }
|
||||
for c in itb { comps_b.push(c); }
|
||||
for c in ita {
|
||||
comps_a.push(c);
|
||||
}
|
||||
for c in itb {
|
||||
comps_b.push(c);
|
||||
}
|
||||
|
||||
let mut i = 0usize;
|
||||
while i < comps_a.len() && i < comps_b.len() && comps_a[i] == comps_b[i] { i += 1; }
|
||||
while i < comps_a.len() && i < comps_b.len() && comps_a[i] == comps_b[i] {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
let mut result = PathBuf::new();
|
||||
for _ in i..comps_a.len() { result.push(".."); }
|
||||
for c in &comps_b[i..] { result.push(c.as_os_str()); }
|
||||
for _ in i..comps_a.len() {
|
||||
result.push("..");
|
||||
}
|
||||
for c in &comps_b[i..] {
|
||||
result.push(c.as_os_str());
|
||||
}
|
||||
Some(result)
|
||||
}
|
||||
|
||||
trait Absolutize { fn absolutize(&self) -> PathBuf; }
|
||||
trait Absolutize {
|
||||
fn absolutize(&self) -> PathBuf;
|
||||
}
|
||||
impl Absolutize for Path {
|
||||
fn absolutize(&self) -> PathBuf {
|
||||
if self.is_absolute() { self.to_path_buf() } else { std::env::current_dir().unwrap().join(self) }
|
||||
if self.is_absolute() {
|
||||
self.to_path_buf()
|
||||
} else {
|
||||
std::env::current_dir().unwrap().join(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user