Merge pull request #751 from LookImEcho-Rick/codex/issue-582-settings-search
🤖 Agent: Merged. CI parity passed 94 of 95. The one miss, tooltip_display, passes locally on main with this branch, and so does options. Thanks LookImEcho-Rick!
This commit is contained in:
@@ -212,8 +212,15 @@ const DONE: u64 = id("options.done", 0);
|
||||
const ROW: u64 = id("options.row", 0);
|
||||
const STYLE: u64 = id("options.style", 0);
|
||||
const LEVEL: u64 = id("options.level", 0);
|
||||
const SEARCH: u64 = id("options.search", 0);
|
||||
const ROW_H: f32 = 12.0 + CONTROL + 12.0;
|
||||
const HEADER_H: f32 = 40.0;
|
||||
pub(crate) fn searchable_section(section: usize) -> bool {
|
||||
matches!(
|
||||
SECTIONS.get(section).map(|s| s.name),
|
||||
Some("Video" | "Controls")
|
||||
)
|
||||
}
|
||||
|
||||
/// Whether an option is an on/off switch, and its value.
|
||||
fn switch_value(opt: Opt, s: &Settings) -> Option<bool> {
|
||||
@@ -263,6 +270,7 @@ fn caption_value(opt: Opt, s: &Settings) -> (String, String) {
|
||||
enum Target {
|
||||
Nav(usize),
|
||||
Done,
|
||||
Search,
|
||||
Row(usize),
|
||||
Slider(Item, f32),
|
||||
Style(usize),
|
||||
@@ -288,6 +296,22 @@ fn horizon_batch(framebuffer: [i32; 2]) -> HudBatch {
|
||||
HudBatch::new([framebuffer[0].max(1) as u32, framebuffer[1].max(1) as u32])
|
||||
}
|
||||
impl OptionsUi {
|
||||
fn horizon_rows(&self, s: &Settings, section: usize) -> Vec<HRow> {
|
||||
let rows = (SECTIONS[section].rows)(s);
|
||||
let query = self.settings_search.value.to_lowercase();
|
||||
if query.is_empty() || !searchable_section(section) {
|
||||
return rows;
|
||||
}
|
||||
rows.into_iter()
|
||||
.filter(|row| match row {
|
||||
HRow::Opt(opt) => caption_value(*opt, s).0.to_lowercase().contains(&query),
|
||||
HRow::Graphics(item, ..) => item.caption_value(s).0.to_lowercase().contains(&query),
|
||||
HRow::Page(label, ..) => label.to_lowercase().contains(&query),
|
||||
HRow::Level => true,
|
||||
_ => false,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
/// Lay out (and draw, on a real frame) the Horizon options shell.
|
||||
/// Returns the sliders' tracks and the scroll area for pointer input.
|
||||
fn horizon_layout(&mut self, s: &Settings, ui: &mut Ui, backdrop: f32) -> HorizonLayout {
|
||||
@@ -326,8 +350,17 @@ impl OptionsUi {
|
||||
let sec = &SECTIONS[section];
|
||||
let mut y = 36.0;
|
||||
y += ui.page_header(x, y, sec.name, sec.blurb) + 24.0;
|
||||
if searchable_section(section) {
|
||||
ui.text_field(
|
||||
SEARCH,
|
||||
[x + cw - 240.0, y, 240.0, CONTROL],
|
||||
&self.settings_search.value,
|
||||
self.settings_search.focused,
|
||||
);
|
||||
y += CONTROL + 12.0;
|
||||
}
|
||||
let top = y;
|
||||
let rows = (sec.rows)(s);
|
||||
let rows = self.horizon_rows(s, section);
|
||||
let content: f32 = rows
|
||||
.iter()
|
||||
.map(|r| {
|
||||
@@ -586,6 +619,9 @@ impl OptionsUi {
|
||||
let Some(hit) = ui.hit((x, y)) else {
|
||||
return (None, scrollbar, cursor);
|
||||
};
|
||||
if hit == SEARCH {
|
||||
return (Some(Target::Search), scrollbar, cursor);
|
||||
}
|
||||
let section = self.section.min(SECTIONS.len() - 1);
|
||||
if (NAV..NAV + SECTIONS.len() as u64).contains(&hit) {
|
||||
return (Some(Target::Nav((hit - NAV) as usize)), scrollbar, cursor);
|
||||
@@ -610,7 +646,7 @@ impl OptionsUi {
|
||||
let Some(i) = hit.checked_sub(ROW).map(|i| i as usize) else {
|
||||
return (None, scrollbar, cursor);
|
||||
};
|
||||
let rows = (SECTIONS[section].rows)(s);
|
||||
let rows = self.horizon_rows(s, section);
|
||||
let item = match rows.get(i) {
|
||||
Some(HRow::Opt(opt)) => Some(Item::Vanilla(*opt)),
|
||||
Some(HRow::Graphics(item, ..)) => Some(*item),
|
||||
@@ -687,6 +723,7 @@ impl OptionsUi {
|
||||
);
|
||||
}
|
||||
let (target, scrollbar, cursor) = self.horizon_target(s, atlas, x, y, framebuffer);
|
||||
self.settings_search.focused = false;
|
||||
// AbstractScrollArea.updateScrolling grabs anywhere in the scrollbar column.
|
||||
if !right
|
||||
&& let Some(scrollbar) = scrollbar
|
||||
@@ -697,9 +734,16 @@ impl OptionsUi {
|
||||
}
|
||||
match target {
|
||||
Some(Target::Nav(i)) => {
|
||||
if searchable_section(self.section) || searchable_section(i) {
|
||||
self.settings_search.set_value("");
|
||||
}
|
||||
self.section = i;
|
||||
self.hscroll = 0.0;
|
||||
}
|
||||
Some(Target::Search) => {
|
||||
self.settings_search.focused = true;
|
||||
self.settings_search.move_cursor_to_end(false);
|
||||
}
|
||||
Some(Target::Done) => events.extend(self.back(s)),
|
||||
Some(Target::Style(i)) => {
|
||||
t::set_style(if i == 1 {
|
||||
@@ -723,7 +767,7 @@ impl OptionsUi {
|
||||
}
|
||||
Some(Target::Row(i)) => {
|
||||
let section = self.section.min(SECTIONS.len() - 1);
|
||||
match (SECTIONS[section].rows)(s).get(i) {
|
||||
match self.horizon_rows(s, section).get(i) {
|
||||
Some(HRow::Opt(opt)) => {
|
||||
opt.cycle(s, right, framebuffer);
|
||||
if *opt == Opt::Preset {
|
||||
|
||||
@@ -826,6 +826,7 @@ pub struct OptionsUi {
|
||||
pub languages: Vec<LanguageInfo>,
|
||||
language_choice: Option<String>,
|
||||
language_search: ui::EditBox,
|
||||
pub(crate) settings_search: ui::EditBox,
|
||||
/// Packs: the packs found and the selection the screen opens with.
|
||||
pub pack_infos: Vec<crate::pack_screen::PackInfo>,
|
||||
pub pack_selection: Vec<String>,
|
||||
@@ -844,6 +845,8 @@ impl Default for OptionsUi {
|
||||
fn default() -> Self {
|
||||
let mut search = ui::EditBox::new(0.0, 0.0, 200.0, 15.0);
|
||||
search.max_length = 32;
|
||||
let mut settings_search = ui::EditBox::new(0.0, 0.0, 200.0, 15.0);
|
||||
settings_search.focused = false;
|
||||
Self {
|
||||
stack: vec![Page::Main],
|
||||
scroll: 0.0,
|
||||
@@ -860,6 +863,7 @@ impl Default for OptionsUi {
|
||||
languages: Vec::new(),
|
||||
language_choice: None,
|
||||
language_search: search,
|
||||
settings_search,
|
||||
pack_infos: Vec::new(),
|
||||
pack_selection: Vec::new(),
|
||||
pack_screen: None,
|
||||
@@ -921,6 +925,13 @@ fn pairs(opts: &[Opt]) -> Vec<Row> {
|
||||
.collect()
|
||||
}
|
||||
impl OptionsUi {
|
||||
fn settings_search_active(&self) -> bool {
|
||||
self.settings_search.focused
|
||||
&& (matches!(self.page(), Page::Video | Page::Controls | Page::KeyBinds)
|
||||
|| (crate::ui_theme::horizon()
|
||||
&& self.page() == Page::Main
|
||||
&& crate::options_horizon::searchable_section(self.section)))
|
||||
}
|
||||
pub fn page(&self) -> Page {
|
||||
*self.stack.last().unwrap_or(&Page::Main)
|
||||
}
|
||||
@@ -948,6 +959,10 @@ impl OptionsUi {
|
||||
self.stack.push(page);
|
||||
self.scroll = 0.0;
|
||||
self.scrollbar_drag_y = None;
|
||||
if matches!(page, Page::Video | Page::Controls | Page::KeyBinds) {
|
||||
self.settings_search.set_value("");
|
||||
self.settings_search.focused = false;
|
||||
}
|
||||
if page == Page::Language {
|
||||
self.language_choice = None;
|
||||
self.language_search.set_value("");
|
||||
@@ -996,6 +1011,33 @@ impl OptionsUi {
|
||||
_ => 163.0,
|
||||
}
|
||||
}
|
||||
fn filter_option_rows(&self, rows: Vec<Row>) -> Vec<Row> {
|
||||
let query = self.settings_search.value.to_lowercase();
|
||||
if query.is_empty() {
|
||||
return rows;
|
||||
}
|
||||
rows.into_iter()
|
||||
.flat_map(|row| match row {
|
||||
Row::Big(opt) if lang::get(opt.caption()).to_lowercase().contains(&query) => {
|
||||
vec![Row::Big(opt)]
|
||||
}
|
||||
Row::Pair(a, b) => {
|
||||
let matches =
|
||||
|opt: Opt| lang::get(opt.caption()).to_lowercase().contains(&query);
|
||||
pairs(
|
||||
&[Some(a), b]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter(|opt| matches(*opt))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}
|
||||
// Keep navigation available and omit section headers with no visible options.
|
||||
Row::Buttons(a, b) => vec![Row::Buttons(a, b)],
|
||||
_ => Vec::new(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
fn list_rows(&self, s: &Settings) -> Vec<Row> {
|
||||
match self.page() {
|
||||
Page::Extras => crate::extras::rows()
|
||||
@@ -1083,7 +1125,7 @@ impl OptionsUi {
|
||||
Opt::AttackIndicator,
|
||||
Opt::ChunkFade,
|
||||
]));
|
||||
rows
|
||||
self.filter_option_rows(rows)
|
||||
}
|
||||
Page::Sound => {
|
||||
let mut rows = vec![Row::Big(Opt::Volume(0))];
|
||||
@@ -1125,7 +1167,7 @@ impl OptionsUi {
|
||||
),
|
||||
None,
|
||||
));
|
||||
rows
|
||||
self.filter_option_rows(rows)
|
||||
}
|
||||
Page::Controller => {
|
||||
let mut rows = vec![Row::Buttons(
|
||||
@@ -1230,6 +1272,10 @@ impl OptionsUi {
|
||||
let mut out = Vec::new();
|
||||
let page = self.page();
|
||||
let cx = (w / 2.0).floor();
|
||||
if matches!(page, Page::Video | Page::Controls | Page::KeyBinds) {
|
||||
self.settings_search.x = cx - 100.0;
|
||||
self.settings_search.y = 17.0;
|
||||
}
|
||||
let done = |y: f32| button(cx - 100.0, y, 200.0, tr("gui.done"), Act::Done);
|
||||
// (list top, list bottom, content height)
|
||||
let (mut top, mut bottom, mut content) = (33.0, h - 33.0, 0.0);
|
||||
@@ -1279,9 +1325,10 @@ impl OptionsUi {
|
||||
bottom = 0.0;
|
||||
}
|
||||
Page::KeyBinds => {
|
||||
top = 38.0;
|
||||
out.push(Widget {
|
||||
x: 0.0,
|
||||
y: 12.0,
|
||||
y: 4.0,
|
||||
w,
|
||||
h: 9.0,
|
||||
kind: WKind::Text {
|
||||
@@ -1293,6 +1340,10 @@ impl OptionsUi {
|
||||
});
|
||||
let mut mappings: Vec<(&str, &str)> =
|
||||
MAPPINGS.iter().map(|(n, _, c)| (*n, *c)).collect();
|
||||
let query = self.settings_search.value.to_lowercase();
|
||||
mappings.retain(|(name, _)| {
|
||||
query.is_empty() || lang::get(name).to_lowercase().contains(&query)
|
||||
});
|
||||
mappings.sort_by(|a, b| {
|
||||
let ca = CATEGORIES.iter().position(|c| *c == a.1).unwrap_or(99);
|
||||
let cb = CATEGORIES.iter().position(|c| *c == b.1).unwrap_or(99);
|
||||
@@ -1561,9 +1612,16 @@ impl OptionsUi {
|
||||
// Drawn by `pack_screen`.
|
||||
Page::Packs => {}
|
||||
_ => {
|
||||
if matches!(page, Page::Video | Page::Controls) {
|
||||
top = 38.0;
|
||||
}
|
||||
out.push(Widget {
|
||||
x: 0.0,
|
||||
y: 12.0,
|
||||
y: if matches!(page, Page::Video | Page::Controls) {
|
||||
4.0
|
||||
} else {
|
||||
12.0
|
||||
},
|
||||
w,
|
||||
h: 9.0,
|
||||
kind: WKind::Text {
|
||||
@@ -1895,6 +1953,23 @@ impl OptionsUi {
|
||||
}
|
||||
self.language_search = search;
|
||||
}
|
||||
if matches!(self.page(), Page::Video | Page::Controls | Page::KeyBinds) {
|
||||
let mut search = self.settings_search.clone();
|
||||
search.draw(batch, atlas, None);
|
||||
if search.value.is_empty() && !search.focused {
|
||||
batch.text_styled(
|
||||
atlas,
|
||||
&Text::literal("Search settings...")
|
||||
.with_color(text::GRAY)
|
||||
.italic(),
|
||||
search.text_x(),
|
||||
search.text_y(),
|
||||
u32::MAX,
|
||||
true,
|
||||
);
|
||||
}
|
||||
self.settings_search = search;
|
||||
}
|
||||
if let Some(lines) = tooltip {
|
||||
ui::tooltip(batch, atlas, &lines, cursor);
|
||||
}
|
||||
@@ -1978,6 +2053,16 @@ impl OptionsUi {
|
||||
}
|
||||
let (widgets, top, bottom, content) = self.layout(s, size.0, size.1);
|
||||
let mut events = Vec::new();
|
||||
if !drag && matches!(self.page(), Page::Video | Page::Controls | Page::KeyBinds) {
|
||||
let search = &mut self.settings_search;
|
||||
search.focused = ui::hovered((x, y), search.x, search.y, search.width, search.height);
|
||||
if search.focused {
|
||||
search.click(atlas, x, false, false);
|
||||
self.scroll = 0.0;
|
||||
events.push(Event::ButtonClick);
|
||||
return events;
|
||||
}
|
||||
}
|
||||
if drag {
|
||||
if let Some(previous_y) = self.scrollbar_drag_y {
|
||||
if let Some((_, thumb)) = ui::scrollbar_thumb(top, bottom, content, self.scroll) {
|
||||
@@ -2253,6 +2338,9 @@ impl OptionsUi {
|
||||
if self.page() == Page::Language {
|
||||
self.language_search.insert_text(text);
|
||||
self.scroll = 0.0;
|
||||
} else if self.settings_search_active() {
|
||||
self.settings_search.insert_text(text);
|
||||
self.scroll = 0.0;
|
||||
}
|
||||
}
|
||||
/// Ctrl+A/C/V/X in the language or pack search box; false when neither
|
||||
@@ -2278,6 +2366,12 @@ impl OptionsUi {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if self.settings_search_active() {
|
||||
if self.settings_search.shortcut(shortcut, clipboard) {
|
||||
self.scroll = 0.0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
fn bind_key(&mut self, s: &mut Settings, value: String) -> Vec<Event> {
|
||||
@@ -2361,6 +2455,16 @@ impl OptionsUi {
|
||||
}
|
||||
}
|
||||
self.scroll = 0.0;
|
||||
} else if self.settings_search_active() {
|
||||
if !self.settings_search.key(key, false, false)
|
||||
&& let Some(t) = text
|
||||
{
|
||||
let typed: String = t.chars().filter(|c| !c.is_control()).collect();
|
||||
if !typed.is_empty() {
|
||||
self.settings_search.insert_text(&typed);
|
||||
}
|
||||
}
|
||||
self.scroll = 0.0;
|
||||
}
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
@@ -1042,6 +1042,49 @@ impl<'a> Ui<'a> {
|
||||
self.opacity = saved;
|
||||
hover
|
||||
}
|
||||
/// A search field styled like the launcher's rounded text inputs.
|
||||
pub fn text_field(&mut self, id: u64, rect: [f32; 4], value: &str, focused: bool) {
|
||||
let [x, y, w, h] = rect;
|
||||
self.record_label(value, rect, true, crate::widgets::Kind::Button);
|
||||
let hover = self.interact(id, x, y, w, h, true);
|
||||
self.rounded(
|
||||
x,
|
||||
y,
|
||||
w,
|
||||
h,
|
||||
8.0,
|
||||
if focused { color::HOVER } else { color::RAISED },
|
||||
);
|
||||
self.rounded(
|
||||
x,
|
||||
y,
|
||||
w,
|
||||
h,
|
||||
8.0,
|
||||
color::with_alpha(color::HOVER, hover * 0.5),
|
||||
);
|
||||
let display = if value.is_empty() {
|
||||
"Search settings".to_owned()
|
||||
} else if focused {
|
||||
format!("{value}|")
|
||||
} else {
|
||||
value.to_owned()
|
||||
};
|
||||
let display = self.fit(Face::Regular, BODY, &display, w - 24.0);
|
||||
self.text_line(
|
||||
Face::Regular,
|
||||
BODY,
|
||||
h,
|
||||
x + 12.0,
|
||||
y,
|
||||
if value.is_empty() {
|
||||
color::FAINT
|
||||
} else {
|
||||
color::TEXT
|
||||
},
|
||||
&display,
|
||||
);
|
||||
}
|
||||
/// The width the launcher's button gives a label (padding 16, or 24 large).
|
||||
pub fn button_width(&self, label: &str, large: bool) -> f32 {
|
||||
let (size, pad) = if large { (LARGE, 24.0) } else { (BODY, 16.0) };
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from pathlib import Path
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
@@ -151,6 +152,7 @@ class ShardTests(unittest.TestCase):
|
||||
self.assertEqual(parity.base_name("x#2"), "x")
|
||||
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "oracle PATH shimming uses Unix executable symlink semantics")
|
||||
class OracleReuseTests(unittest.TestCase):
|
||||
"""tools/parity_shim.py replays a run only when its inputs and outputs are as recorded."""
|
||||
|
||||
|
||||
+26
-25
@@ -36,8 +36,9 @@ import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from pathlib import Path, PurePosixPath
|
||||
import re
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
@@ -61,14 +62,14 @@ SHIM = STATE_DIR / "shim"
|
||||
# so a harness whose inputs match one that passed elsewhere doesn't run again.
|
||||
SHARED = Path(os.environ.get("PARITY_SHARED") or (LOCAL / "minecraft").resolve().parent / "parity-shared")
|
||||
MACHINE_JOBS = int(os.environ.get("PARITY_MACHINE_JOBS") or max(1, (os.cpu_count() or 4) // 2))
|
||||
HOST = os.uname().nodename.split(".")[0]
|
||||
HOST = socket.gethostname().split(".")[0]
|
||||
DEFAULT_MEMORY = 3 << 30 # assumed peak for a harness that never ran here
|
||||
|
||||
|
||||
def harness_settings(path):
|
||||
"""PARITY_SHARDS and PARITY_RUST_SCOPE, read from a harness's source without running it."""
|
||||
import ast
|
||||
text = Path(path).read_text()
|
||||
text = Path(path).read_text(encoding="utf-8")
|
||||
settings = {}
|
||||
if "PARITY_" in text:
|
||||
for node in ast.parse(text).body:
|
||||
@@ -102,7 +103,7 @@ def base_name(name):
|
||||
|
||||
|
||||
def load_state():
|
||||
return json.loads(STATE.read_text()) if STATE.exists() else {"harnesses": {}, "hashes": {}}
|
||||
return json.loads(STATE.read_text(encoding="utf-8")) if STATE.exists() else {"harnesses": {}, "hashes": {}}
|
||||
|
||||
|
||||
def save_state(state):
|
||||
@@ -129,7 +130,7 @@ class Hasher:
|
||||
if cached and cached[0] == stamp:
|
||||
return cached[1]
|
||||
if keep:
|
||||
digest = hashlib.sha256(crate_root_without_modules(Path(real).read_text(), set(keep.split(","))).encode()).hexdigest()
|
||||
digest = hashlib.sha256(crate_root_without_modules(Path(real).read_text(encoding="utf-8"), set(keep.split(","))).encode()).hexdigest()
|
||||
else:
|
||||
with open(real, "rb") as stream:
|
||||
digest = hashlib.file_digest(stream, "sha256").hexdigest()
|
||||
@@ -168,7 +169,7 @@ def environment_key(hasher):
|
||||
return (result.stdout + result.stderr).strip()
|
||||
except FileNotFoundError:
|
||||
return "missing"
|
||||
lock = json.loads((ROOT / "research-lock.json").read_text())
|
||||
lock = json.loads((ROOT / "research-lock.json").read_text(encoding="utf-8"))
|
||||
version_dir = LOCAL / "minecraft" / lock["minecraft"]["version"]
|
||||
parts = [version(["rustc", "-V"]), version(["java", "-version"]), version(["javac", "-version"]),
|
||||
json.dumps(PROFILE, sort_keys=True), hasher(ROOT / "research-lock.json"), hasher(ROOT / "Cargo.lock"),
|
||||
@@ -197,7 +198,7 @@ def dep_info(binary):
|
||||
if not info.exists():
|
||||
return []
|
||||
sources = []
|
||||
for line in info.read_text().splitlines():
|
||||
for line in info.read_text(encoding="utf-8").splitlines():
|
||||
_, separator, rest = line.partition(": ")
|
||||
if separator:
|
||||
sources += [part.replace("\\ ", " ") for part in re.split(r"(?<!\\) ", rest.strip()) if part]
|
||||
@@ -371,17 +372,17 @@ def narrow_rust_sources(sources, scope):
|
||||
for candidate in (crate_dir / "src" / Path(*parts[:count - 1]) / f"{parts[count - 1]}.rs",
|
||||
crate_dir / "src" / Path(*parts[:count]) / "mod.rs"):
|
||||
if candidate.is_file():
|
||||
return str(candidate.relative_to(ROOT)), count
|
||||
return candidate.relative_to(ROOT).as_posix(), count
|
||||
return None, 0
|
||||
|
||||
def module_path(path):
|
||||
parts = list(Path(*Path(path).parts[3:]).with_suffix("").parts) # crates/<crate>/src/...
|
||||
parts = list(PurePosixPath(path).parts[3:-1] + (PurePosixPath(path).with_suffix("").name,))
|
||||
return parts[:-1] if parts[-1] in ("mod", "lib") else parts
|
||||
|
||||
defined_types, used_macros, kept_modules = set(), set(), {}
|
||||
for path in inner + entry:
|
||||
text = rust_code((ROOT / path).read_text(errors="replace"))
|
||||
crate_name = Path(path).parts[1].replace("-", "_")
|
||||
text = rust_code((ROOT / path).read_text(encoding="utf-8", errors="replace"))
|
||||
crate_name = PurePosixPath(path).parts[1].replace("-", "_")
|
||||
nesting = inline_modules(text)
|
||||
if re.search(r"\binclude!\s*\(", text):
|
||||
return sources, f"{path} includes source"
|
||||
@@ -401,7 +402,7 @@ def narrow_rust_sources(sources, scope):
|
||||
if head in crates: # a workspace crate
|
||||
base, crate_name = [], head
|
||||
elif head.startswith(("crate", "self", "super")) and path in inner:
|
||||
own, crate_name = module_path(path) + nesting(match.start()), Path(path).parts[1].replace("-", "_")
|
||||
own, crate_name = module_path(path) + nesting(match.start()), PurePosixPath(path).parts[1].replace("-", "_")
|
||||
ups = head.count("super")
|
||||
if head != "crate" and ups <= len(nesting(match.start())):
|
||||
continue # within this file
|
||||
@@ -415,14 +416,14 @@ def narrow_rust_sources(sources, scope):
|
||||
item = (base + parts)[0]
|
||||
defined_in_root = root.is_file() and re.search(
|
||||
rf"^\s*(?:pub(?:\([^)]*\))?\s+)?(?:const|static|fn|struct|enum|type|trait|union)\s+{item}\b",
|
||||
root.read_text(), re.MULTILINE)
|
||||
root.read_text(encoding="utf-8"), re.MULTILINE)
|
||||
if not defined_in_root:
|
||||
return sources, f"{path} names {head}::{rest}, which the crate root doesn't define itself"
|
||||
continue
|
||||
if not scoped(target):
|
||||
return sources, f"{path} names {head}::{rest} ({target})"
|
||||
for path in outside:
|
||||
text = rust_code((ROOT / path).read_text(errors="replace"))
|
||||
text = rust_code((ROOT / path).read_text(encoding="utf-8", errors="replace"))
|
||||
defined = set(RUST_MACRO_DEFINITION.findall(text)) & used_macros
|
||||
if defined:
|
||||
return sources, f"the scope uses macro {sorted(defined)[0]}! defined in {path}"
|
||||
@@ -433,7 +434,7 @@ def narrow_rust_sources(sources, scope):
|
||||
kept = [path for path in sources if path not in outside and not path.endswith("/src/lib.rs")]
|
||||
for path in sources:
|
||||
if path.endswith("/src/lib.rs"):
|
||||
modules = kept_modules.get(Path(path).parts[1].replace("-", "_")) or {"-"} # "-": no module of it is reachable
|
||||
modules = kept_modules.get(PurePosixPath(path).parts[1].replace("-", "_")) or {"-"} # "-": no module of it is reachable
|
||||
kept.append(f"{path}{KEEP}{','.join(sorted(modules))}")
|
||||
return sorted(kept), None
|
||||
|
||||
@@ -549,7 +550,7 @@ def clear_large_outputs(name, trace):
|
||||
everything else large under the harness's .local directories is rebuilt on
|
||||
its next run."""
|
||||
local = LOCAL.resolve()
|
||||
keep = {os.path.realpath(line) for line in outputs_listing(name).read_text().splitlines() if line}
|
||||
keep = {os.path.realpath(line) for line in outputs_listing(name).read_text(encoding="utf-8").splitlines() if line}
|
||||
directories = set()
|
||||
for command in trace["commands"]:
|
||||
for argument in command[1:]:
|
||||
@@ -600,7 +601,7 @@ def memory_available():
|
||||
"""Bytes the system can give harnesses now: MemAvailable on Linux, free and reclaimable pages on macOS."""
|
||||
meminfo = Path("/proc/meminfo")
|
||||
if meminfo.exists():
|
||||
for line in meminfo.read_text().splitlines():
|
||||
for line in meminfo.read_text(encoding="utf-8").splitlines():
|
||||
if line.startswith("MemAvailable:"):
|
||||
return int(line.split()[1]) * 1024
|
||||
try:
|
||||
@@ -634,7 +635,7 @@ def outcome(name, script, passed, elapsed, trace_path, hasher=None):
|
||||
record = {"status": "pass" if passed else "fail", "seconds": round(elapsed, 1),
|
||||
"finished": time.strftime("%Y-%m-%dT%H:%M:%S"), "host": HOST}
|
||||
try:
|
||||
trace = json.loads(Path(trace_path).read_text())
|
||||
trace = json.loads(Path(trace_path).read_text(encoding="utf-8"))
|
||||
except (OSError, ValueError):
|
||||
trace = None # killed before writing it, or the disk was full: the pass can't be keyed
|
||||
if trace:
|
||||
@@ -726,7 +727,7 @@ class LocalExecutor:
|
||||
def host_config():
|
||||
"""tools/parity_hosts.json: the machines harnesses can run on, and the harnesses that must stay local."""
|
||||
path = ROOT / "tools" / "parity_hosts.json"
|
||||
return json.loads(path.read_text()) if path.exists() else {"default": [], "hosts": {}, "local_only": {}}
|
||||
return json.loads(path.read_text(encoding="utf-8")) if path.exists() else {"default": [], "hosts": {}, "local_only": {}}
|
||||
|
||||
|
||||
class RemoteExecutor:
|
||||
@@ -1017,11 +1018,11 @@ def stale(name, state, hasher, environment):
|
||||
candidates = [record] if record and record.get("dependencies") else []
|
||||
template = SHARED / "dependencies" / f"{name}.json"
|
||||
if template.exists():
|
||||
candidates.append(json.loads(template.read_text()))
|
||||
candidates.append(json.loads(template.read_text(encoding="utf-8")))
|
||||
for candidate in candidates:
|
||||
shared = SHARED / "passes" / name / f"{key(candidate, hasher, environment)}.json"
|
||||
if shared.exists():
|
||||
state["harnesses"][name] = dict(json.loads(shared.read_text()), shared=True)
|
||||
state["harnesses"][name] = dict(json.loads(shared.read_text(encoding="utf-8")), shared=True)
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -1088,7 +1089,7 @@ def changed_harnesses(found, records, ref):
|
||||
for name, script in found.items():
|
||||
specific = [path for path in records.get(name, {}).get("dependencies", [])
|
||||
if path.startswith("mods/horizon/src/test/") or "/examples/" in path or "/src/bin/" in path]
|
||||
if str(Path(script).relative_to(ROOT)) in changed or any(path in changed for path in specific):
|
||||
if Path(script).relative_to(ROOT).as_posix() in changed or any(path in changed for path in specific):
|
||||
found_changed.add(name)
|
||||
return found_changed
|
||||
|
||||
@@ -1103,8 +1104,8 @@ def affected_harnesses(found, records, changed):
|
||||
dependencies = records.get(name, {}).get("dependencies")
|
||||
template = SHARED / "dependencies" / f"{name}.json"
|
||||
if dependencies is None and template.exists():
|
||||
dependencies = json.loads(template.read_text()).get("dependencies")
|
||||
if dependencies is None or str(Path(script).relative_to(ROOT)) in changed or \
|
||||
dependencies = json.loads(template.read_text(encoding="utf-8")).get("dependencies")
|
||||
if dependencies is None or Path(script).relative_to(ROOT).as_posix() in changed or \
|
||||
any(path.split(KEEP)[0] in changed for path in dependencies):
|
||||
affected.add(name)
|
||||
return affected
|
||||
@@ -1180,7 +1181,7 @@ def main():
|
||||
chosen = [name for name in found if records.get(name, {}).get("status") == "fail"]
|
||||
elif args.changed or args.changed_files:
|
||||
if args.changed_files:
|
||||
changed, since = set(Path(args.changed_files).read_text().split("\n")) - {""}, ""
|
||||
changed, since = set(Path(args.changed_files).read_text(encoding="utf-8").split("\n")) - {""}, ""
|
||||
else:
|
||||
changed, since = changed_files(args.changed), f" since the merge base with {args.changed}"
|
||||
if changed is None:
|
||||
|
||||
+63
-1
@@ -29,6 +29,10 @@ import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
if os.name == "nt":
|
||||
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
||||
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
FLEET_SHARED = Path.home() / "code" / "horizon-parity" / "shared-local" / "parity-shared"
|
||||
@@ -184,7 +188,7 @@ def line_counts(base, changed):
|
||||
for path in git("ls-files", "--others", "--exclude-standard").splitlines():
|
||||
if path in changed:
|
||||
try:
|
||||
counts[path] = (len((ROOT / path).read_text().splitlines()), 0)
|
||||
counts[path] = (len((ROOT / path).read_text(encoding="utf-8").splitlines()), 0)
|
||||
except (UnicodeDecodeError, OSError):
|
||||
pass
|
||||
return counts
|
||||
@@ -303,6 +307,9 @@ def run_script(steps, host, verbose):
|
||||
"""Runs the steps in one shell on host (here for "local"), each between markers, reading results as they come."""
|
||||
if not steps:
|
||||
return
|
||||
if host == "local" and os.name == "nt":
|
||||
run_windows(steps, verbose)
|
||||
return
|
||||
parts = [HOST_SETUP.get(host, ""), "set +e"]
|
||||
for index, step in enumerate(steps):
|
||||
parts.append(f"echo '@@pr_ready:begin:{index}'; started=$(date +%s)\n( {step.command}\n) 2>&1 < /dev/null\n"
|
||||
@@ -338,6 +345,61 @@ def run_script(steps, host, verbose):
|
||||
finish(step, verbose)
|
||||
|
||||
|
||||
def run_windows(steps, verbose):
|
||||
"""Run local checks directly on Windows without requiring a Unix shell."""
|
||||
for step in steps:
|
||||
command = shlex.split(step.command)
|
||||
cwd = ROOT
|
||||
env = os.environ.copy()
|
||||
env["PYTHONUTF8"] = "1"
|
||||
if step.name == "Public tree":
|
||||
command = [sys.executable, "tools/check_public_tree.py"]
|
||||
elif step.name == "Python tests":
|
||||
command = [sys.executable, "-m", "unittest", "discover", "-s", "tests"]
|
||||
elif step.name == "rustfmt":
|
||||
command = ["cargo", "fmt", "--all", "--", "--check"]
|
||||
elif step.name == "clippy":
|
||||
command = ["cargo", "clippy", "--workspace", "--all-targets", "--locked", "--", "-D", "warnings"]
|
||||
elif step.name.startswith("tests"):
|
||||
command = shlex.split(step.command)
|
||||
elif step.name == "tokens.css up to date":
|
||||
command = shlex.split(step.command)
|
||||
elif step.name == "launcher rustfmt":
|
||||
command = ["cargo", "fmt", "--check"]
|
||||
cwd = ROOT / "launcher"
|
||||
elif step.name == "launcher clippy":
|
||||
command = ["cargo", "clippy", "--all-targets", "--locked", "--", "-D", "warnings"]
|
||||
cwd = ROOT / "launcher"
|
||||
elif step.name == "launcher tests":
|
||||
command = ["cargo", "test", "--locked", "--lib"]
|
||||
cwd = ROOT / "launcher"
|
||||
elif step.name == "Parity":
|
||||
command = shlex.split(step.command)
|
||||
if command and command[0] == "PARITY_HOSTS=":
|
||||
command.pop(0)
|
||||
if command and command[0] == "python3":
|
||||
command[0] = sys.executable
|
||||
env["PARITY_HOSTS"] = ""
|
||||
elif command and command[0] == "python3":
|
||||
command[0] = sys.executable
|
||||
|
||||
print(f" {step.name}...", file=sys.stderr, flush=True)
|
||||
started = time.monotonic()
|
||||
try:
|
||||
with subprocess.Popen(command, cwd=cwd, env=env, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT, text=True, errors="replace") as process:
|
||||
for line in process.stdout:
|
||||
step.output += line
|
||||
if verbose:
|
||||
print(" " + line, end="", file=sys.stderr)
|
||||
status = process.wait()
|
||||
step.status = "pass" if status == 0 else "fail"
|
||||
except OSError as error:
|
||||
step.status, step.detail = "fail", str(error)
|
||||
step.seconds = int(time.monotonic() - started)
|
||||
finish(step, verbose)
|
||||
|
||||
|
||||
def finish(step, verbose):
|
||||
if step.status == "pass" and step.summary:
|
||||
step.detail = step.summary(step.output)
|
||||
|
||||
Reference in New Issue
Block a user