Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: treating swift-frontend as error #4

Merged
merged 3 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 92 additions & 33 deletions src/logger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::parser::{parse, XCLOG_MATCHER};
use crate::parser::{parse, XCOutput, XCOutputTask, XCLOG_MATCHER};
use crate::XCCompileCommand;
use anyhow::Result;
use async_stream::stream;
Expand Down Expand Up @@ -31,41 +31,22 @@ impl ProcessExt for XCLogger {
fn spawn_and_stream(
&mut self,
) -> std::io::Result<Pin<Box<dyn Stream<Item = ProcessItem> + Send>>> {
let mut output_stream = self._spawn_and_stream()?;
let compile_commands = self.compile_commands.clone();
let process_stream = self._spawn_and_stream()?;
let mut output_stream = self.process_stream(process_stream);

Ok(stream! {
let mut compile_commands = compile_commands.lock().await;
while let Some(output) = output_stream.next().await {
match output {
ProcessItem::Error(line) => {
match parse(line, &mut output_stream).await {
Ok(Some(lines)) => {
for line in lines.into_iter() {
yield ProcessItem::Error(line.to_string())
} },
Err(e) => tracing::error!("ParseError: {e}"),
_ => ()
}
},
ProcessItem::Output(line) => {
if let Some(cmd) = XCLOG_MATCHER.get_compile_command(line.as_str()).and_then(XCCompileCommand::from_compile_command_data) {
compile_commands.push(cmd);
} else {
match parse(line, &mut output_stream).await {
Ok(Some(lines)) => {
for line in lines.into_iter() {
yield ProcessItem::Output(line.to_string())
} },
Err(e) => tracing::error!("ParseError: {e}"),
_ => ()
}
}

},
output => yield output
}
}
match output.kind {
XCOutputTask::Task | XCOutputTask::Test | XCOutputTask::Warning => {
yield ProcessItem::Output(output.to_string())
}
XCOutputTask::Error => yield ProcessItem::Error(output.to_string()),
XCOutputTask::Exit => yield ProcessItem::Exit(output.value),
XCOutputTask::Result => {
yield ProcessItem::Output(output.to_string())
}
};
};
}
.boxed())
}
Expand Down Expand Up @@ -99,4 +80,82 @@ impl XCLogger {
compile_commands: Default::default(),
})
}

pub(crate) fn process_stream(
&self,
mut output_stream: Pin<Box<dyn Stream<Item = ProcessItem> + Send>>,
) -> Pin<Box<dyn Stream<Item = XCOutput> + Send>> {
let compile_commands = self.compile_commands.clone();

stream! {
let mut compile_commands = compile_commands.lock().await;
while let Some(output) = output_stream.next().await {

// Try to process compile command first
if let ProcessItem::Output(line) = &output {
if let Some(cmd) = XCLOG_MATCHER
.get_compile_command(line.as_str())
.and_then(XCCompileCommand::from_compile_command_data)
{
compile_commands.push(cmd);
continue;
};
};

match output {
ProcessItem::Error(line) => {
match parse(line, &mut output_stream).await {
Ok(Some(lines)) => {
for output in lines.into_iter() {
yield output
} },
Err(e) => tracing::error!("ParseError: {e}"),
_ => ()
}
},
ProcessItem::Output(line) => {
match parse(line, &mut output_stream).await {
Ok(Some(outputs)) => {
for output in outputs.into_iter() {
yield output
} },
Err(e) => tracing::error!("ParseError: {e}"),
_ => ()
}

},
ProcessItem::Exit(exit) => {
let value = exit.trim();
yield XCOutput {
kind: XCOutputTask::Exit,
value: value.into()
};
}
}
}
}
.boxed()
}
}

#[tokio::test]
#[tracing_test::traced_test]
async fn case_d() {
let logger = XCLogger::new("", [""]).expect("Create logger");
let stream = stream! {
let content = include_str!("../tests/case_d.log");
let lines = content.split("\n");
for line in lines {
yield ProcessItem::Output(line.to_string())
}
}
.boxed();
let error_outputs = logger
.process_stream(stream)
.collect::<Vec<_>>()
.await
.into_iter()
.filter(|t| t.is_error())
.collect::<Vec<_>>();
assert_eq!(error_outputs.len(), 0, "{error_outputs:#?}")
}
19 changes: 18 additions & 1 deletion src/parser/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,23 @@ define! [
}
}
},
{
ident: SwiftCompile,
kind: Task,
desc: r"SwiftCompile",
captures: [ arch, filename, project, target ],
format: "[{target}] Compiling {filename}",
pattern: r"SwiftCompile\s(?P<arch>\S+)\s(?P<filepath>.+/)(?P<filename>[^/]+)\s\(in\starget\s'(?P<target>.*)'\sfrom\sproject\s'(?P<project>.*)'\)",
tests: {
"SwiftCompile normal arm64 /source/Home/State/HomeStateAction.swift (in target 'xxx' from project 'xxx')" =>
|captures| {
assert_eq!("normal", &captures["arch"]);
assert_eq!("HomeStateAction.swift", &captures["filename"]);
assert_eq!("xxx", &captures["project"]);
assert_eq!("xxx", &captures["target"]);
}
}
},
{
ident: CompileStoryboard,
kind: Task,
Expand Down Expand Up @@ -939,7 +956,7 @@ define! [
desc: r"duplicate symbols location",
captures: [ message ],
format: "{message}",
pattern: r"\s+(?P<message>/.*\.o[\)]?)$",
pattern: r" (?P<message>/.*\.o[\)]?)$",
tests: {}
},
{
Expand Down
6 changes: 4 additions & 2 deletions src/parser/output.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Kinds of outputs
#[derive(Clone, derive_is_enum_variant::is_enum_variant)]
#[derive(Clone, derive_is_enum_variant::is_enum_variant, Debug)]
pub enum XCOutputTask {
/// Task like Compile, Mkdir ..
Task,
Expand All @@ -11,10 +11,12 @@ pub enum XCOutputTask {
Error,
/// End Result
Result,
/// Process exit
Exit
}

/// Formatted results of a given match
#[derive(Clone, derive_deref_rs::Deref)]
#[derive(Clone, derive_deref_rs::Deref, Debug)]
pub struct XCOutput {
#[deref]
/// output value
Expand Down
Loading