Skip to content

Commit

Permalink
Binarize: copy files from addons folder (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson authored Oct 30, 2023
1 parent 8d8fb22 commit 80435a6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
5 changes: 1 addition & 4 deletions bin/src/commands/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ pub fn execute(matches: &ArgMatches) -> Result<(), Error> {

let link = prefix_folder.join(ctx.config().prefix());
if !link.exists() {
create_link(
link.display().to_string().as_str(),
ctx.build_folder().display().to_string().as_str(),
)?;
create_link(&link, ctx.build_folder())?;
}

let mut args: Vec<String> = [
Expand Down
26 changes: 24 additions & 2 deletions bin/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,29 @@ fn setup_tmp(ctx: &Context) -> Result<(), Error> {
.trim_start_matches('/')
.replace('/', "\\"),
);
create_link(tmp_addon.to_str().unwrap(), target.to_str().unwrap())?;
create_link(&tmp_addon, &target)?;
}
// maybe replace with config or rhai in the future?
let addons = ctx.project_folder().join("addons");
for file in std::fs::read_dir(addons)? {
let file = file?.path();
if file.is_dir() {
continue;
}
let tmp_file = tmp
.join(ctx.addons().first().unwrap().prefix().as_pathbuf())
.parent()
.unwrap()
.join(file.file_name().unwrap());
// check size of file
if file.metadata()?.len() > 1024 * 1024 * 10 {
warn!(
"File `{}` is larger than 10MB, this will slow builds.",
file.display()
);
}
trace!("copying `{}` to tmp for binarization", file.display());
std::fs::copy(&file, &tmp_file)?;
}
let include = ctx.project_folder().join("include");
if !include.exists() {
Expand All @@ -148,7 +170,7 @@ fn setup_tmp(ctx: &Context) -> Result<(), Error> {
if prefix.is_dir() {
let tmp_mod = tmp_outer_prefix.join(prefix.file_name().unwrap());
create_dir_all(tmp_mod.parent().unwrap())?;
create_link(tmp_mod.to_str().unwrap(), prefix.to_str().unwrap())?;
create_link(&tmp_mod, &prefix)?;
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions bin/src/modules/file_patching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ impl Module for FilePatching {
create_link(
&ctx.build_folder()
.join("addons")
.join(addon.name().replace('/', "\\"))
.display()
.to_string(),
&ctx.project_folder()
.join(addon.folder().replace('/', "\\"))
.display()
.to_string(),
.join(addon.name().replace('/', "\\")),
&ctx.project_folder().join(addon.folder().replace('/', "\\")),
)
})
.collect::<Result<(), Error>>()
Expand Down
12 changes: 7 additions & 5 deletions bin/src/utils/link.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use crate::error::Error;

#[allow(clippy::module_name_repetitions)]
Expand All @@ -7,11 +9,11 @@ use crate::error::Error;
/// # Errors
/// - [`Error::Link`] if the link could not be created
/// - [`std::io::Error`] if the link command could not be executed
pub fn create_link(link: &str, target: &str) -> Result<(), Error> {
pub fn create_link(link: &PathBuf, target: &PathBuf) -> Result<(), Error> {
use std::process::Command;
trace!("link {:?} => {:?}", link, target);

// attempt junction
trace!("junction link {:?} => {:?}", link, target);
let mut out = Command::new("cmd")
.arg("/C")
.arg("mklink")
Expand All @@ -22,6 +24,7 @@ pub fn create_link(link: &str, target: &str) -> Result<(), Error> {

if !out.status.success() {
// fall-back to directory symbolic link
trace!("directory symbolic link {:?} => {:?}", link, target);
out = Command::new("cmd")
.arg("/C")
.arg("mklink")
Expand All @@ -45,9 +48,8 @@ pub fn create_link(link: &str, target: &str) -> Result<(), Error> {
///
/// # Errors
/// - [`std::io::Error`] if the link could not be created
pub fn create_link(link: &str, target: &str) -> Result<(), Error> {
let target = target.replace('\\', "/");
trace!("link {:?} => {:?}", link, target);
pub fn create_link(link: &PathBuf, target: &PathBuf) -> Result<(), Error> {
trace!("symlink {:?} => {:?}", link, target);
std::os::unix::fs::symlink(target, link)?;
Ok(())
}
1 change: 1 addition & 0 deletions bin/tests/alpha/addons/model.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/shrug
1 change: 1 addition & 0 deletions libs/common/src/project/addon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct AddonConfig {
/// Files to exclude from the pbo
/// Supports glob patterns
exclude: Vec<String>,

#[serde(default)]
/// Files to exclude from the pbo
files: FilesConfig,
Expand Down
5 changes: 4 additions & 1 deletion libs/common/src/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ impl Workspace {
missions: Vec::new(),
};
for entry in workspace.vfs.walk_dir()? {
let entry = entry?;
let Ok(entry) = entry else {
trace!("unknown issue with entry: {:?}", entry);
continue;
};
if entry.is_dir()? {
continue;
}
Expand Down

0 comments on commit 80435a6

Please sign in to comment.