Skip to content

Commit

Permalink
fix(run): running wrong correct output
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed May 17, 2022
1 parent b3f90e2 commit a3a8edd
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ pub async fn ensure_server_config(root: &path::PathBuf) -> Result<()> {

let mut file = tokio::fs::File::create(path).await?;
let config = serde_json::json! ({
"name": "xbase Server",
// FIXME: Point to user xcode-build-server
"name": "Xbase",
// FIXME: Point to user xbase-server
"argv": ["/Users/tami5/repos/neovim/xbase.nvim/target/debug/xbase-server"],
"version": "0.1",
"bspVersion": "0.2",
Expand Down
5 changes: 3 additions & 2 deletions src/daemon/requests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{nvim::BufferDirection, types::BuildConfiguration};
use std::fmt::Debug;

#[cfg(feature = "daemon")]
use crate::constants::DAEMON_STATE;
use {crate::constants::DAEMON_STATE, crate::xcode::append_build_root};

/// Build a project.
#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -26,9 +26,10 @@ impl Handler for Build {
let nvim = state.clients.get(pid)?;
let direction = self.direction.clone();

let args = append_build_root(&root, config.as_args())?;
let (success, _) = nvim
.new_logger("build", &config.target, &direction)
.log_build_stream(&root, &config.as_args(), true, true)
.log_build_stream(&root, &args, true, true)
.await?;

if !success {
Expand Down
11 changes: 6 additions & 5 deletions src/daemon/requests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{

#[cfg(feature = "daemon")]
use {
crate::constants::DAEMON_STATE, crate::types::SimDevice, crate::Error,
xcodebuild::runner::build_settings,
crate::constants::DAEMON_STATE, crate::types::SimDevice, crate::xcode::append_build_root,
crate::Error, xcodebuild::runner::build_settings,
};

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -51,7 +51,8 @@ impl Handler for Run {
if let Some(platform) = platform {
args.extend(platform.sdk_simulator_args())
}
args

append_build_root(&root, args)?
};

let build_settings = build_settings(&root, &args).await?;
Expand All @@ -65,10 +66,10 @@ impl Handler for Run {
// Path doesn't point to local directory build
let ref path_to_app = build_settings.metal_library_output_dir;

tracing::debug!("{app_id}: {:?}", path_to_app);
tracing::warn!("{app_id}: {:?}", path_to_app);
let (success, ref win) = nvim
.new_logger("Build", &config.target, &direction)
.log_build_stream(&root, &args, false, true)
.log_build_stream(&root, &args, true, true)
.await?;

if !success {
Expand Down
1 change: 1 addition & 0 deletions src/nvim/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl<'a> Logger<'a> {
}

pub async fn open_win(&self) -> Result<Window<NvimConnection>> {
// TOOD(nvim): Only open logger buffer if it's not already opened
let open_cmd = self.open_cmd().await;

self.nvim.exec(&open_cmd, false).await?;
Expand Down
20 changes: 3 additions & 17 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use tap::Pipe;

pub use extensions::*;

static SERVER_NAME: &str = "xbase-build-server";
use crate::util::fs::get_build_cache_dir;

static SERVER_NAME: &str = "Xbase";
static SERVER_VERSION: &str = "0.1";

/// SourceKit-lsp Build Server
Expand Down Expand Up @@ -225,19 +227,3 @@ fn get_compile_filepath(params: &InitializeBuild) -> Option<PathBuf> {
.pipe(PathBuf::from)
.pipe(|path| path.is_file().then(|| path))
}

/// Try to get build cache_dir
fn get_build_cache_dir(root_path: &PathBuf) -> Result<String> {
let path = || {
let parent = root_path.parent()?.file_name()?.to_str()?;
let name = root_path.file_name()?.to_str()?;
Some(
dirs::cache_dir()?
.join("xbase-build-server")
.join(format!("{parent}-{name}"))
.to_string_lossy()
.to_string(),
)
};
path().ok_or_else(|| anyhow::anyhow!("Fail to generate build_cache directory"))
}
10 changes: 5 additions & 5 deletions src/types/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(feature = "daemon")]
use crate::util::fs::get_dirname_dir_root;

use super::Root;
use serde::{Deserialize, Serialize};

Expand All @@ -7,13 +10,10 @@ pub struct Client {
pub root: Root,
}

#[cfg(feature = "daemon")]
impl Client {
pub fn abbrev_root(&self) -> String {
self.root
.strip_prefix(self.root.ancestors().nth(2).unwrap())
.unwrap()
.display()
.to_string()
get_dirname_dir_root(&self.root).unwrap_or_default()
}
}

Expand Down
44 changes: 39 additions & 5 deletions src/util/fs.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,58 @@
//! Functions to query filesystem for files and directories
#[cfg(any(feature = "server", feature = "daemon"))]
use anyhow::Result;
use std::{
fs::read_to_string,
path::{Path, PathBuf},
};
use std::path::Path;
use tap::Pipe;

#[cfg(any(feature = "server", feature = "daemon"))]
use std::path::PathBuf;

/// Get all files in SwiftFileList file.
#[cfg(any(feature = "server", feature = "daemon"))]
pub fn get_files_list<T, P>(file_lists: P) -> Result<Vec<T>>
where
T: From<String>,
P: AsRef<Path>,
{
read_to_string(file_lists)?
std::fs::read_to_string(file_lists)?
.pipe(|s| shell_words::split(&s))?
.into_iter()
.map(T::from)
.collect::<Vec<_>>()
.pipe(Result::Ok)
}

pub fn get_dirname_dir_root<P>(path: P) -> Option<String>
where
P: AsRef<Path>,
{
let path = path.as_ref();
path.strip_prefix(path.ancestors().nth(2)?)
.ok()?
.display()
.to_string()
.pipe(Some)
}

#[cfg(any(feature = "server", feature = "daemon"))]
pub fn get_build_cache_dir<P: AsRef<Path> + std::fmt::Debug>(root_path: P) -> Result<String> {
let path = || {
let name = get_dirname_dir_root(&root_path)?;
Some(
dirs::cache_dir()?
.join("Xbase")
.join(name)
.to_string_lossy()
.to_string(),
)
};
path()
.ok_or_else(|| anyhow::anyhow!("Fail to generate build_cache directory for {root_path:?}"))
}

/// Find All swift files in a directory.
#[tracing::instrument(skip_all)]
#[cfg(any(feature = "server", feature = "daemon"))]
pub fn find_swift_files(project_root: &Path) -> Result<Vec<String>> {
wax::walk("**/*.swift", project_root, usize::MAX)?
.enumerate()
Expand All @@ -38,6 +69,7 @@ pub fn find_swift_files(project_root: &Path) -> Result<Vec<String>> {

/// Is the given directory is a directory and has .git?
#[tracing::instrument]
#[cfg(any(feature = "server", feature = "daemon"))]
fn is_project_root(directory: &Path) -> bool {
if directory.is_dir() {
directory.join(".git").exists()
Expand All @@ -49,6 +81,7 @@ fn is_project_root(directory: &Path) -> bool {

/// Find Header directory and frameworks from path.
#[tracing::instrument(ret, skip_all)]
#[cfg(any(feature = "server", feature = "daemon"))]
pub fn find_header_dirs(root: &Path) -> Result<(Vec<String>, Vec<String>)> {
wax::walk("**/*.h", root, usize::MAX)?
.flatten()
Expand Down Expand Up @@ -81,6 +114,7 @@ pub fn find_header_dirs(root: &Path) -> Result<(Vec<String>, Vec<String>)> {

/// Find directory, swiftflags and comple file from a path to file within a project.
#[tracing::instrument(ret)]
#[cfg(any(feature = "server", feature = "daemon"))]
pub fn find_swift_module_root(
file_path: &Path,
) -> (Option<PathBuf>, Option<PathBuf>, Option<PathBuf>) {
Expand Down
1 change: 0 additions & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! General utilities
#[cfg(any(feature = "server", feature = "daemon"))]
pub mod fs;
#[cfg(feature = "lua")]
pub mod mlua;
Expand Down
2 changes: 1 addition & 1 deletion src/watcher/handle/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async fn generate_compiled_commands<'a>(
return Err(err);
}

tracing::info!("Updated `{project_name}/.compile` ");
tracing::info!("Updated `{project_name}/.compile`");

Ok(())
}
Expand Down
4 changes: 3 additions & 1 deletion src/watcher/handle/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::{WatchArguments, WatchError};
use crate::constants::DAEMON_STATE;
use crate::daemon::{WatchKind, WatchTarget};
use crate::types::{BuildConfiguration, Client};
use crate::xcode::append_build_root;
use anyhow::Result;
use notify::{event::ModifyKind, Event, EventKind};
use std::time::{Duration, SystemTime};
Expand Down Expand Up @@ -46,7 +47,8 @@ pub async fn create(req: WatchArguments) -> Result<(), WatchError> {

match kind {
WatchKind::Build => {
let ref args = config.as_args();
let ref args = append_build_root(root, config.as_args())
.map_err(|e| WatchError::stop(e.into()))?;

nvim.new_logger("Build", &config.target, &None)
.log_build_stream(root, args, false, false)
Expand Down
25 changes: 23 additions & 2 deletions src/xcode.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use anyhow::Result;
use async_stream::stream;
use std::path::Path;
use tap::Pipe;
use tokio_stream::{Stream, StreamExt};
use xcodebuild::{parser, runner::spawn};

use crate::util::fs::get_build_cache_dir;

#[cfg(feature = "daemon")]
pub async fn stream_build<'a, P: 'a>(
root: P,
Expand Down Expand Up @@ -36,7 +39,7 @@ where
}

#[cfg(feature = "daemon")]
pub async fn fresh_build<'a, P: AsRef<Path> + 'a>(
pub async fn fresh_build<'a, P: AsRef<Path> + 'a + std::fmt::Debug>(
root: P,
) -> Result<impl Stream<Item = parser::Step> + 'a> {
/*
Expand All @@ -52,5 +55,23 @@ pub async fn fresh_build<'a, P: AsRef<Path> + 'a>(
runArguments: [];
```
*/
spawn(root, &["clean", "build"]).await
append_build_root(&root, vec!["clean".into(), "build".into()])?
.pipe(|args| spawn(root, args))
.await
}

pub fn append_build_root<P: AsRef<Path> + std::fmt::Debug>(
root: P,
mut args: Vec<String>,
) -> Result<Vec<String>> {
get_build_cache_dir(&root)?
.pipe(|path| format!("SYMROOT={path}|CONFIGURATION_BUILD_DIR={path}|BUILD_DIR={path}"))
.split("|")
.map(ToString::to_string)
.collect::<Vec<String>>()
.pipe(|extra| {
args.extend(extra);
args
})
.pipe(Ok)
}

0 comments on commit a3a8edd

Please sign in to comment.