Skip to content

Commit

Permalink
feat(core): customize root based on target and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed May 26, 2022
1 parent 8de6112 commit 438cf5a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/types/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ impl BuildConfiguration {
args.extend(device.special_build_args())
}

// TODO: Customize root based on target and configuration
append_build_root(root, args)
append_build_root(root, Some(&self), args)
}
}

Expand Down
44 changes: 36 additions & 8 deletions src/util/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,53 @@ where
.ok()?
.display()
.to_string()
.replace("/", "_")
.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> {
pub fn _get_build_cache_dir<P: AsRef<Path> + std::fmt::Debug>(
root_path: P,
config: Option<&crate::types::BuildConfiguration>,
) -> 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(),
)
let base = dirs::cache_dir()?
.join("Xbase")
.join(name)
.display()
.to_string();

if let Some(config) = config {
Some(
format!(
"{base}/{}_{}",
config.target,
config.configuration.to_string()
)
.replace(" ", "_"),
)
} else {
Some(base)
}
};
path()
.ok_or_else(|| anyhow::anyhow!("Fail to generate build_cache directory for {root_path:?}"))
}

#[cfg(any(feature = "server", feature = "daemon"))]
pub fn get_build_cache_dir<P: AsRef<Path> + std::fmt::Debug>(root_path: P) -> Result<String> {
_get_build_cache_dir(root_path, None)
}

#[cfg(any(feature = "server", feature = "daemon"))]
pub fn get_build_cache_dir_with_config<P: AsRef<Path> + std::fmt::Debug>(
root_path: P,
config: &crate::types::BuildConfiguration,
) -> Result<String> {
_get_build_cache_dir(root_path, Some(config))
}

/// Find All swift files in a directory.
#[tracing::instrument(skip_all)]
#[cfg(any(feature = "server", feature = "daemon"))]
Expand Down
29 changes: 18 additions & 11 deletions src/xcode.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::types::BuildConfiguration;
use crate::util::fs::get_build_cache_dir_with_config;
use crate::Result;
use crate::{nvim::Logger, util::fs::get_build_cache_dir};
use async_stream::stream;
Expand Down Expand Up @@ -48,7 +50,7 @@ where
pub async fn fresh_build<'a, P: AsRef<Path> + 'a + Debug>(
root: P,
) -> Result<impl Stream<Item = parser::Step> + 'a> {
append_build_root(&root, vec!["clean".into(), "build".into()])?
append_build_root(&root, None, vec!["clean".into(), "build".into()])?
.pipe(|args| spawn(root, args))
.await?
.pipe(Ok)
Expand Down Expand Up @@ -94,16 +96,21 @@ pub async fn build_with_logger<'a, P: AsRef<Path>>(

pub fn append_build_root<P: AsRef<Path> + Debug>(
root: P,
config: Option<&BuildConfiguration>,
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)
if let Some(config) = config {
get_build_cache_dir_with_config(&root, config)?
} else {
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 438cf5a

Please sign in to comment.