Fix fullstack cli progress (#2787)
* Fix progress for fullstack builds * Fix internal logs
This commit is contained in:
1 parent
469ab66341
commit
e4abe79276
1 file changed
+84
-60
@@ -61,7 +61,8 @@ impl From<TargetPlatform> for LogSource {
|
|||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct BuildProgress {
|
pub struct BuildProgress {
|
||||||
build_logs: HashMap<LogSource, ActiveBuild>,
|
internal_logs: Vec<BuildMessage>,
|
||||||
|
build_logs: HashMap<TargetPlatform, ActiveBuild>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuildProgress {
|
impl BuildProgress {
|
||||||
@@ -189,7 +190,6 @@ impl Output {
|
|||||||
/// Add a message from stderr to the logs
|
/// Add a message from stderr to the logs
|
||||||
fn push_stderr(&mut self, platform: TargetPlatform, stderr: String) {
|
fn push_stderr(&mut self, platform: TargetPlatform, stderr: String) {
|
||||||
self.set_tab(Tab::BuildLog);
|
self.set_tab(Tab::BuildLog);
|
||||||
let source = platform.into();
|
|
||||||
|
|
||||||
self.running_apps
|
self.running_apps
|
||||||
.get_mut(&platform)
|
.get_mut(&platform)
|
||||||
@@ -201,7 +201,7 @@ impl Output {
|
|||||||
.push_str(&stderr);
|
.push_str(&stderr);
|
||||||
self.build_progress
|
self.build_progress
|
||||||
.build_logs
|
.build_logs
|
||||||
.get_mut(&source)
|
.get_mut(&platform)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.messages
|
.messages
|
||||||
.push(BuildMessage {
|
.push(BuildMessage {
|
||||||
@@ -213,8 +213,6 @@ impl Output {
|
|||||||
|
|
||||||
/// Add a message from stdout to the logs
|
/// Add a message from stdout to the logs
|
||||||
fn push_stdout(&mut self, platform: TargetPlatform, stdout: String) {
|
fn push_stdout(&mut self, platform: TargetPlatform, stdout: String) {
|
||||||
let source = platform.into();
|
|
||||||
|
|
||||||
self.running_apps
|
self.running_apps
|
||||||
.get_mut(&platform)
|
.get_mut(&platform)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -225,7 +223,7 @@ impl Output {
|
|||||||
.push_str(&stdout);
|
.push_str(&stdout);
|
||||||
self.build_progress
|
self.build_progress
|
||||||
.build_logs
|
.build_logs
|
||||||
.get_mut(&source)
|
.get_mut(&platform)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.messages
|
.messages
|
||||||
.push(BuildMessage {
|
.push(BuildMessage {
|
||||||
@@ -330,6 +328,19 @@ impl Output {
|
|||||||
/// versions of the cli would just eat build logs making debugging issues harder than they needed
|
/// versions of the cli would just eat build logs making debugging issues harder than they needed
|
||||||
/// to be.
|
/// to be.
|
||||||
fn drain_print_logs(&mut self) {
|
fn drain_print_logs(&mut self) {
|
||||||
|
fn log_build_message(platform: &LogSource, message: &BuildMessage) {
|
||||||
|
match &message.message {
|
||||||
|
MessageType::Text(text) => {
|
||||||
|
for line in text.lines() {
|
||||||
|
println!("{platform}: {line}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MessageType::Cargo(diagnostic) => {
|
||||||
|
println!("{platform}: {diagnostic}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// todo: print the build info here for the most recent build, and then the logs of the most recent build
|
// todo: print the build info here for the most recent build, and then the logs of the most recent build
|
||||||
for (platform, build) in self.build_progress.build_logs.iter_mut() {
|
for (platform, build) in self.build_progress.build_logs.iter_mut() {
|
||||||
if build.messages.is_empty() {
|
if build.messages.is_empty() {
|
||||||
@@ -339,17 +350,15 @@ impl Output {
|
|||||||
let messages = build.messages.drain(0..);
|
let messages = build.messages.drain(0..);
|
||||||
|
|
||||||
for message in messages {
|
for message in messages {
|
||||||
match &message.message {
|
log_build_message(&LogSource::Target(*platform), &message);
|
||||||
MessageType::Cargo(diagnostic) => {
|
|
||||||
println!(
|
|
||||||
"{platform}: {}",
|
|
||||||
diagnostic.rendered.as_deref().unwrap_or_default()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
MessageType::Text(t) => println!("{platform}: {t}"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log the internal logs
|
||||||
|
let messaegs = self.build_progress.internal_logs.drain(..);
|
||||||
|
for message in messaegs {
|
||||||
|
log_build_message(&LogSource::Internal, &message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle an input event, returning `true` if the event should cause the program to restart.
|
/// Handle an input event, returning `true` if the event should cause the program to restart.
|
||||||
@@ -481,21 +490,24 @@ impl Output {
|
|||||||
let source = platform.into();
|
let source = platform.into();
|
||||||
let snapped = self.is_snapped(source);
|
let snapped = self.is_snapped(source);
|
||||||
|
|
||||||
self.build_progress
|
match source {
|
||||||
.build_logs
|
LogSource::Internal => self.build_progress.internal_logs.push(message),
|
||||||
.entry(source)
|
LogSource::Target(platform) => self
|
||||||
.or_default()
|
.build_progress
|
||||||
.stdout_logs
|
.build_logs
|
||||||
.push(message);
|
.entry(platform)
|
||||||
|
.or_default()
|
||||||
|
.stdout_logs
|
||||||
|
.push(message),
|
||||||
|
}
|
||||||
|
|
||||||
if snapped {
|
if snapped {
|
||||||
self.scroll_to_bottom();
|
self.scroll_to_bottom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_build_logs(&mut self, platform: impl Into<LogSource>, update: UpdateBuildProgress) {
|
pub fn new_build_logs(&mut self, platform: TargetPlatform, update: UpdateBuildProgress) {
|
||||||
let source = platform.into();
|
let snapped = self.is_snapped(LogSource::Target(platform));
|
||||||
let snapped = self.is_snapped(source);
|
|
||||||
|
|
||||||
// when the build is finished, switch to the console
|
// when the build is finished, switch to the console
|
||||||
if update.stage == Stage::Finished {
|
if update.stage == Stage::Finished {
|
||||||
@@ -504,7 +516,7 @@ impl Output {
|
|||||||
|
|
||||||
self.build_progress
|
self.build_progress
|
||||||
.build_logs
|
.build_logs
|
||||||
.entry(source)
|
.entry(platform)
|
||||||
.or_default()
|
.or_default()
|
||||||
.update(update);
|
.update(update);
|
||||||
|
|
||||||
@@ -545,8 +557,7 @@ impl Output {
|
|||||||
self.running_apps.insert(platform, app);
|
self.running_apps.insert(platform, app);
|
||||||
|
|
||||||
// Finish the build progress for the platform that just finished building
|
// Finish the build progress for the platform that just finished building
|
||||||
let source = platform.into();
|
if let Some(build) = self.build_progress.build_logs.get_mut(&platform) {
|
||||||
if let Some(build) = self.build_progress.build_logs.get_mut(&source) {
|
|
||||||
build.stage = Stage::Finished;
|
build.stage = Stage::Finished;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -646,7 +657,7 @@ impl Output {
|
|||||||
.build_progress
|
.build_progress
|
||||||
.build_logs
|
.build_logs
|
||||||
.values()
|
.values()
|
||||||
.min_by(|a, b| a.partial_cmp(b).unwrap())
|
.min_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
spans.extend_from_slice(&build.spans(Rect::new(
|
spans.extend_from_slice(&build.spans(Rect::new(
|
||||||
0,
|
0,
|
||||||
@@ -712,6 +723,42 @@ impl Output {
|
|||||||
// handle the wrapping and scrolling
|
// handle the wrapping and scrolling
|
||||||
let mut paragraph_text: Text<'_> = Text::default();
|
let mut paragraph_text: Text<'_> = Text::default();
|
||||||
|
|
||||||
|
let mut add_build_message = |message: &BuildMessage| {
|
||||||
|
use ansi_to_tui::IntoText;
|
||||||
|
match &message.message {
|
||||||
|
MessageType::Text(line) => {
|
||||||
|
for line in line.lines() {
|
||||||
|
let text = line.into_text().unwrap_or_default();
|
||||||
|
for line in text.lines {
|
||||||
|
let source = format!("[{}] ", message.source);
|
||||||
|
|
||||||
|
let msg_span = Span::from(source);
|
||||||
|
let msg_span = match message.source {
|
||||||
|
MessageSource::App => msg_span.light_blue(),
|
||||||
|
MessageSource::Dev => msg_span.dark_gray(),
|
||||||
|
MessageSource::Build => msg_span.light_yellow(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut out_line = vec![msg_span];
|
||||||
|
for span in line.spans {
|
||||||
|
out_line.push(span);
|
||||||
|
}
|
||||||
|
let newline = Line::from(out_line);
|
||||||
|
paragraph_text.push_line(newline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MessageType::Cargo(diagnostic) => {
|
||||||
|
let diagnostic = diagnostic.rendered.as_deref().unwrap_or_default();
|
||||||
|
|
||||||
|
for line in diagnostic.lines() {
|
||||||
|
paragraph_text.extend(line.into_text().unwrap_or_default());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// First log each platform's build logs
|
||||||
for platform in self.build_progress.build_logs.keys() {
|
for platform in self.build_progress.build_logs.keys() {
|
||||||
let build = self.build_progress.build_logs.get(platform).unwrap();
|
let build = self.build_progress.build_logs.get(platform).unwrap();
|
||||||
|
|
||||||
@@ -721,40 +768,13 @@ impl Output {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for span in msgs.iter() {
|
for span in msgs.iter() {
|
||||||
use ansi_to_tui::IntoText;
|
add_build_message(span);
|
||||||
match &span.message {
|
|
||||||
MessageType::Text(line) => {
|
|
||||||
for line in line.lines() {
|
|
||||||
let text = line.into_text().unwrap_or_default();
|
|
||||||
for line in text.lines {
|
|
||||||
let source = format!("[{}] ", span.source);
|
|
||||||
|
|
||||||
let msg_span = Span::from(source);
|
|
||||||
let msg_span = match span.source {
|
|
||||||
MessageSource::App => msg_span.light_blue(),
|
|
||||||
MessageSource::Dev => msg_span.dark_gray(),
|
|
||||||
MessageSource::Build => msg_span.light_yellow(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut out_line = vec![msg_span];
|
|
||||||
for span in line.spans {
|
|
||||||
out_line.push(span);
|
|
||||||
}
|
|
||||||
let newline = Line::from(out_line);
|
|
||||||
paragraph_text.push_line(newline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MessageType::Cargo(diagnostic) => {
|
|
||||||
let diagnostic = diagnostic.rendered.as_deref().unwrap_or_default();
|
|
||||||
|
|
||||||
for line in diagnostic.lines() {
|
|
||||||
paragraph_text.extend(line.into_text().unwrap_or_default());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Then log the internal logs
|
||||||
|
for message in self.build_progress.internal_logs.iter() {
|
||||||
|
add_build_message(message);
|
||||||
|
}
|
||||||
|
|
||||||
let paragraph = Paragraph::new(paragraph_text)
|
let paragraph = Paragraph::new(paragraph_text)
|
||||||
.left_aligned()
|
.left_aligned()
|
||||||
@@ -868,6 +888,10 @@ impl ActiveBuild {
|
|||||||
fn update(&mut self, update: UpdateBuildProgress) {
|
fn update(&mut self, update: UpdateBuildProgress) {
|
||||||
match update.update {
|
match update.update {
|
||||||
UpdateStage::Start => {
|
UpdateStage::Start => {
|
||||||
|
// If we are already past the stage, don't roll back
|
||||||
|
if self.stage > update.stage {
|
||||||
|
return;
|
||||||
|
}
|
||||||
self.stage = update.stage;
|
self.stage = update.stage;
|
||||||
self.progress = 0.0;
|
self.progress = 0.0;
|
||||||
self.failed = None;
|
self.failed = None;
|
||||||
|
|||||||
Reference in new issue
Block a user