Skip to content

Commit

Permalink
ref: use xclogger to generate compile commands
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed Jun 25, 2022
1 parent 2edaa8b commit 2d7c458
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 176 deletions.
97 changes: 49 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xclog"
version = "0.2.9"
version = "0.3.0"
edition = "2021"
description = "xcodebuild build-log formater and parser"
license = "MIT OR Apache-2.0"
Expand All @@ -26,7 +26,7 @@ tracing-subscriber = { version = "0.3.9", features = ["env-filter"], optiona

anyhow = "1.0.57"
async-stream = "0.3.3"
process-stream = "0.2.2"
process-stream = "0.3.2"
paste = "1.0.7"
derive_is_enum_variant = "0.1.1"
serde = { version = "1.0.137", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion src/build_settings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use process_stream::{Process, StreamExt};
use process_stream::{Process, ProcessExt, StreamExt};
use std::{
io::Read,
path::{Path, PathBuf},
Expand Down
48 changes: 3 additions & 45 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ mod tests;
mod util;

use crate::parser::XCLOG_MATCHER;
use crate::XCLogger;
use anyhow::{Context, Result};
use process_stream::{Process, ProcessItem, StreamExt};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::{Path, PathBuf};
Expand All @@ -35,50 +33,10 @@ impl IntoIterator for XCCompilationDatabase {
}

impl XCCompilationDatabase {
/// Generate completion database from running xcodebuild arguments in a given root.
pub async fn generate<P, I, S>(root: P, args: I) -> Result<Self>
where
P: AsRef<Path> + Send,
I: IntoIterator<Item = S> + Send,
S: AsRef<std::ffi::OsStr> + Send,
{
let mut process = Process::new("/usr/bin/xcodebuild");
process.current_dir(&root);
process.arg("clean");
process.args(args);
let result = process.spawn_and_stream()?.collect::<Vec<_>>().await;
if let Some(ProcessItem::Exit(code)) = result.iter().find(|item| item.is_exit()) {
if code != "0" {
let logs = XCLogger::new_from_lines(
PathBuf::default(),
result.iter().map(|s| s.to_string()).collect::<Vec<_>>(),
)?
.stream
.collect::<Vec<_>>()
.await;

return Err(anyhow::anyhow!(
"{}",
logs.iter()
.map(|l| l.to_string())
.collect::<Vec<_>>()
.join("\n")
));
}
}

result
.into_iter()
.filter_map(|o| {
XCLOG_MATCHER
.get_compile_command(o.to_string().as_str())
.and_then(XCCompileCommand::from_compile_command_data)
})
.collect::<Vec<_>>()
.pipe(Self)
.pipe(Ok)
/// new XCCompilationDatabase from commands
pub fn new(commands: Vec<XCCompileCommand>) -> Self {
Self(commands)
}

/// Generate XCCompilationDatabase from a vector build log lines
///
/// Note root is set to default
Expand Down
5 changes: 0 additions & 5 deletions src/compile/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ impl XCCompileArgs {
/// Generate compile flags from [`XCCompileCommand`] command field
///
///
/// # Example
///
/// ```no_run
/// XCCompileArgs::try_from_str(&compile_command.command);
/// ```
///
/// [`XCCompileCommand`]: crate::XCCompileCommand
pub fn try_from_str(command: &str) -> Result<Self> {
Expand Down
Loading

0 comments on commit 2d7c458

Please sign in to comment.