Skip to content

Commit f7815d0

Browse files
committed
Add the build link bisect tool to the website (#3902)
* Add the bisect tool * Add `cargo run explore` to open bisect tool * Website cleanup * Bug fixes * Fix again
1 parent 4c45c88 commit f7815d0

File tree

9 files changed

+881
-13
lines changed

9 files changed

+881
-13
lines changed

tools/cargo-run/src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod requirements;
66
pub enum Action {
77
Run,
88
Build,
9+
Explore(Option<String>),
910
}
1011

1112
pub enum Target {
@@ -36,6 +37,7 @@ impl Task {
3637
let (action, args) = match args.first() {
3738
Some(&"build") => (Action::Build, &args[1..]),
3839
Some(&"run") => (Action::Run, &args[1..]),
40+
Some(&"explore") => (Action::Explore(args.get(1).map(|s| s.to_string())), &[] as &[&str]),
3941
Some(&"help") => return None,
4042
_ => (Action::Run, args),
4143
};
@@ -74,6 +76,34 @@ pub fn npm_run_in_frontend_dir(args: &str) -> Result<(), Error> {
7476
run_from(&format!("{npm} run {args}"), Some(&frontend_dir))
7577
}
7678

79+
pub fn open_url(url: &str) -> Result<(), Error> {
80+
#[cfg(target_os = "windows")]
81+
let mut cmd = process::Command::new("cmd");
82+
#[cfg(target_os = "windows")]
83+
cmd.args(["/c", "start", url]);
84+
85+
#[cfg(target_os = "macos")]
86+
let mut cmd = process::Command::new("open");
87+
#[cfg(target_os = "macos")]
88+
cmd.arg(url);
89+
90+
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
91+
let mut cmd = process::Command::new("xdg-open");
92+
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
93+
cmd.arg(url);
94+
95+
let command_str = format!("{:?}", cmd);
96+
let exit_code = cmd
97+
.spawn()
98+
.map_err(|e| Error::Io(e, format!("Failed to spawn command '{command_str}'")))?
99+
.wait()
100+
.map_err(|e| Error::Io(e, format!("Failed to wait for command '{command_str}'")))?;
101+
if !exit_code.success() {
102+
return Err(Error::Command(command_str, exit_code));
103+
}
104+
Ok(())
105+
}
106+
77107
fn run_from(command: &str, dir: Option<&PathBuf>) -> Result<(), Error> {
78108
let command = command.split_whitespace().collect::<Vec<_>>();
79109
let mut cmd = process::Command::new(command[0]);

tools/cargo-run/src/main.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn usage() {
1515
println!("<command>:");
1616
println!(" [run] Run the selected target (default)");
1717
println!(" build Build the selected target");
18+
println!(" explore Open an assortment of tools for exploring the codebase");
1819
println!(" help Show this message");
1920
println!("<target>:");
2021
println!(" [web] Web app (default)");
@@ -50,7 +51,35 @@ fn main() -> ExitCode {
5051
ExitCode::SUCCESS
5152
}
5253

54+
fn explore_usage() {
55+
println!();
56+
println!("USAGE:");
57+
println!(" cargo run explore <tool>");
58+
println!();
59+
println!("OPTIONS:");
60+
println!("<tool>:");
61+
println!(" bisect Binary search through recent commits to find which introduced a bug or feature");
62+
println!(" editor View an interactive outline of the editor's message system architecture");
63+
println!();
64+
}
65+
5366
fn run_task(task: &Task) -> Result<(), Error> {
67+
if let Action::Explore(tool) = &task.action {
68+
match tool.as_deref() {
69+
Some("bisect") => return open_url("https://graphite.art/volunteer/guide/codebase-overview/debugging-tips/#build-bisect-tool"),
70+
Some("editor") => return open_url("https://graphite.art/volunteer/guide/codebase-overview/editor-structure/#editor-outline"),
71+
None | Some("--help") => {
72+
explore_usage();
73+
return Ok(());
74+
}
75+
Some(other) => {
76+
eprintln!("Unknown explore tool: '{other}'");
77+
explore_usage();
78+
return Ok(());
79+
}
80+
}
81+
}
82+
5483
requirements::check(task)?;
5584

5685
match (&task.action, &task.target, &task.profile) {
@@ -65,6 +94,7 @@ fn run_task(task: &Task) -> Result<(), Error> {
6594
profile = match action {
6695
Action::Run => &Profile::Debug,
6796
Action::Build => &Profile::Release,
97+
Action::Explore(_) => unreachable!(),
6898
}
6999
}
70100

@@ -94,6 +124,8 @@ fn run_task(task: &Task) -> Result<(), Error> {
94124

95125
(Action::Build, Target::Cli, Profile::Debug) => run("cargo build -p graphene-cli")?,
96126
(Action::Build, Target::Cli, Profile::Release | Profile::Default) => run("cargo build -r -p graphene-cli")?,
127+
128+
(Action::Explore(_), _, _) => unreachable!(),
97129
}
98130
Ok(())
99131
}

website/content/about.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Adam is a pragmatic problem solver with a talent for simplifying complexity. He
166166
</section>
167167

168168
<section>
169-
<div class="triptych">
169+
<div class="triptych" id="extras">
170170

171171
<div class="block">
172172

website/content/volunteer/guide/codebase-overview/debugging-tips.md

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,103 @@ title = "Debugging tips"
33

44
[extra]
55
order = 2 # Page number after chapter intro
6+
css = ["/page/contributor-guide/bisect-tool.css"]
7+
js = ["/js/page/contributor-guide/bisect-tool.js"]
68
+++
79

810
The Wasm-based editor has some unique limitations about how you are able to debug it. This page offers tips and best practices to get the most out of your problem-solving efforts.
911

1012
## Comparing with deployed builds
1113

12-
When tracking down a bug, first check if the issue you are noticing also exists in `master` or just in your branch. Open up [dev.graphite.art](https://dev.graphite.art) which always deploys the lastest commit, as opposed to [editor.graphite.art](https://editor.graphite.art) which deploys the latest stable release. Build links for any commit may be found by clicking the "comment" icon on the right side of any commit in the [GitHub repo commits list](https://github.com/GraphiteEditor/Graphite/commits/master/).
13-
14-
Use *Help* > *About Graphite* in the editor to view any build's Git commit hash.
15-
16-
Beware of one potential pitfall: all deploys and build links are built with release optimizations enabled. This means some bugs (like crashes from bounds checks or debug assertions) may exist in `master` and would appear if run locally, but not in the deployed version.
14+
When tracking down a bug, first check if the issue you are noticing also exists in `master` or just in your branch. Open up [dev.graphite.art](https://dev.graphite.art) which always deploys the lastest commit, as opposed to [editor.graphite.art](https://editor.graphite.art) which deploys the latest stable release. Build links for any commit may be found by clicking the "comment" icon on the right side of any commit in the GitHub repo [commits list](https://github.com/GraphiteEditor/Graphite/commits/master/).
15+
16+
Use *Help* > *About Graphite…* in the editor to view any build's Git commit hash.
17+
18+
Beware of a potential pitfall: all deploys and build links are built with release optimizations enabled. This means some bugs (like crashes from bounds checks or debug assertions) may exist in `master` and would appear if run locally, but not in the deployed version.
19+
20+
## Build bisect tool
21+
22+
```sh
23+
# Access this quickly in the future:
24+
cargo run explore bisect
25+
```
26+
27+
This interactive tool helps you binary search through recent commits, test the build links of each, and pinpoint which change introduced a regression or added a feature.
28+
29+
<div class="bisect-tool">
30+
31+
<div class="phase active" data-phase="setup">
32+
<div class="setup-section">
33+
<div class="section-label">
34+
<span><strong>What are you looking for?</strong></span>
35+
</div>
36+
<label>
37+
<input type="radio" name="bisect-mode" value="regression" checked />
38+
<span>Find when a regression or bug started</span>
39+
</label>
40+
<label>
41+
<input type="radio" name="bisect-mode" value="feature" />
42+
<span>Find when a feature was added or fixed</span>
43+
</label>
44+
</div>
45+
<div class="setup-section">
46+
<div class="section-label">
47+
<span><strong>When do you estimate this changed?</strong></span>
48+
</div>
49+
<label>
50+
<input type="radio" name="start-method" value="date" checked />
51+
<span>Date</span>
52+
</label>
53+
<label>
54+
<input type="radio" name="start-method" value="hash" />
55+
<span>Commit</span>
56+
</label>
57+
</div>
58+
<div class="commit-inputs">
59+
<div class="start-input" data-input="date">
60+
<input type="date" data-commit-date />
61+
</div>
62+
<div class="start-input hidden" data-input="hash">
63+
<input data-commit-hash placeholder="Commit hash" pattern="[0-9a-fA-F]{7,40}" />
64+
</div>
65+
<span class="button arrow" data-start-button>Begin bisect</span>
66+
</div>
67+
</div>
68+
69+
<div class="phase" data-phase="bisect">
70+
<div class="block feature-box-narrow">
71+
<div class="step-header">
72+
<span class="step-label" data-step-label><strong>Bisect step 1</strong></span>
73+
<span class="go-back hidden" data-go-back-button>(<a>go back</a>)</span>
74+
</div>
75+
<div class="progress-info" data-progress-info></div>
76+
<div class="commit-info" data-commit-info></div>
77+
<span class="button arrow" data-test-build-button>Test this build</span>
78+
<span class="findings">After testing, what have you found?</span>
79+
<div class="bisect-actions">
80+
<span class="button" data-issue-present-button></span>
81+
<span class="button" data-issue-absent-button></span>
82+
</div>
83+
</div>
84+
</div>
85+
86+
<div class="error-message" data-message-box></div>
87+
88+
</div>
1789

1890
## Printing to the console
1991

20-
Use the browser console (<kbd>F12</kbd>) to check for warnings and errors. Use the Rust macro `debug!("The number is {}", some_number);` to print to the browser console. These statements should be for temporary debugging. Remove them before your code is reviewed. Print-based debugging is necessary because breakpoints are not supported in WebAssembly.
92+
Use the browser console (<kbd>F12</kbd>) to check for warnings and errors. In Rust, use `log::debug!("The number is {some_number}");` to print to the browser console. These statements should be for temporary debugging. Remove them before your code is reviewed. Print-based debugging is necessary because breakpoints are not supported in WebAssembly.
2193

2294
Additional print statements are available that *should* be committed:
2395

24-
- `error!()` is for descriptive user-facing error messages arising from a bug
25-
- `warn!()` is for non-critical problems that likely indicate a bug somewhere
26-
- `trace!()` is for verbose logs of ordinary internal activity, hidden by default but viewable by activating *Help* > *Debug: Print Trace Logs*
96+
- `log::error!()` is for descriptive user-facing error messages arising from a bug
97+
- `log::warn!()` is for non-critical problems that likely indicate a bug somewhere
98+
- `log::trace!()` is for verbose logs of ordinary internal activity, hidden by default but viewable by activating *Help* > *Debug: Print Trace Logs*
2799

28100
## Message system logs
29101

30-
To also view logs of the messages dispatched by the message system, activate *Help* > *Debug: Print Messages* > *Only Names*. Or use *Full Contents* for a more verbose view containing the actual data being passed. This is an invaluable window into the activity of the message flow and works well together with `debug!()` printouts for tracking down message-related defects.
102+
To also view logs of the messages dispatched by the message system, activate *Help* > *Debug: Print Messages* > *Only Names*. Or use *Full Contents* for a more verbose view containing the actual data being passed. This is an invaluable window into the activity of the message flow and works well together with `log::debug!()` printouts for tracking down message-related defects.
31103

32104
## Node/layer and document IDs
33105

website/content/volunteer/guide/codebase-overview/editor-structure.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ The dispatcher lives at the root of the editor hierarchy and acts as the owner o
1717

1818
## Editor outline
1919

20-
Click to explore the outline of the editor subsystem hierarchy which forms the structure of the editor's subsystems, state, and interactions. Bookmark this page to reference it later.
20+
```sh
21+
# Access this quickly in the future:
22+
cargo run explore editor
23+
```
24+
25+
Click to explore the outline of the editor subsystem hierarchy which forms the structure of the editor's subsystems, state, and interactions.
2126

2227
<div class="structure-outline">
2328
<!-- replacements::hierarchical_message_system_tree() -->

website/content/volunteer/guide/starting-a-task/code-quality-guidelines.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Please ensure Clippy is enabled. This should be set up automatically in VS Code.
1313

1414
## Naming
1515

16-
Please use descriptive variable/function/symbol names and keep abbreviations to a minimum. Prefer spelling out full words most of the time, so `gen_doc_fmt` should be written out as `generate_document_format` instead.
16+
Please use descriptive variable/function/symbol names and keep abbreviations to a minimum. Prefer spelling out full words most of the time, such as `generate_document_format` instead of `gen_doc_fmt`.
1717

1818
This avoids the mental burden of expanding abbreviations into semantic meaning. Monitors are wide enough to display long variable/function names, so descriptive is better than cryptic.
1919

website/sass/page/about.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@
4545
}
4646
}
4747
}
48+
49+
#extras .button {
50+
margin-top: 0;
51+
}

0 commit comments

Comments
 (0)