Skip to content

Commit

Permalink
binarize: copy files from addons folder
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Oct 30, 2023
1 parent 8d8fb22 commit 3b9ca4c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 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())?;

Check failure on line 116 in bin/src/commands/launch.rs

View workflow job for this annotation

GitHub Actions / ubuntu

mismatched types

Check failure on line 116 in bin/src/commands/launch.rs

View workflow job for this annotation

GitHub Actions / beta

mismatched types

error[E0308]: mismatched types --> bin/src/commands/launch.rs:116:28 | 116 | create_link(&link, ctx.build_folder())?; | ----------- ^^^^^^^^^^^^^^^^^^ expected `&str`, found `&PathBuf` | | | arguments to this function are incorrect | = note: expected reference `&str` found reference `&std::path::PathBuf` note: function defined here --> bin/src/utils/link.rs:51:8 | 51 | pub fn create_link(link: &PathBuf, target: &str) -> Result<(), Error> { | ^^^^^^^^^^^ ------------

Check failure on line 116 in bin/src/commands/launch.rs

View workflow job for this annotation

GitHub Actions / stable

mismatched types

error[E0308]: mismatched types --> bin/src/commands/launch.rs:116:28 | 116 | create_link(&link, ctx.build_folder())?; | ----------- ^^^^^^^^^^^^^^^^^^ expected `&str`, found `&PathBuf` | | | arguments to this function are incorrect | = note: expected reference `&str` found reference `&std::path::PathBuf` note: function defined here --> bin/src/utils/link.rs:51:8 | 51 | pub fn create_link(link: &PathBuf, target: &str) -> Result<(), Error> { | ^^^^^^^^^^^ ------------
}

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)?;

Check failure on line 136 in bin/src/executor.rs

View workflow job for this annotation

GitHub Actions / ubuntu

mismatched types

Check failure on line 136 in bin/src/executor.rs

View workflow job for this annotation

GitHub Actions / beta

mismatched types

error[E0308]: mismatched types --> bin/src/executor.rs:136:33 | 136 | create_link(&tmp_addon, &target)?; | ----------- ^^^^^^^ expected `&str`, found `&PathBuf` | | | arguments to this function are incorrect | = note: expected reference `&str` found reference `&std::path::PathBuf` note: function defined here --> bin/src/utils/link.rs:51:8 | 51 | pub fn create_link(link: &PathBuf, target: &str) -> Result<(), Error> { | ^^^^^^^^^^^ ------------

Check failure on line 136 in bin/src/executor.rs

View workflow job for this annotation

GitHub Actions / stable

mismatched types

error[E0308]: mismatched types --> bin/src/executor.rs:136:33 | 136 | create_link(&tmp_addon, &target)?; | ----------- ^^^^^^^ expected `&str`, found `&PathBuf` | | | arguments to this function are incorrect | = note: expected reference `&str` found reference `&std::path::PathBuf` note: function defined here --> bin/src/utils/link.rs:51:8 | 51 | pub fn create_link(link: &PathBuf, target: &str) -> Result<(), Error> { | ^^^^^^^^^^^ ------------
}
// 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)?;

Check failure on line 173 in bin/src/executor.rs

View workflow job for this annotation

GitHub Actions / ubuntu

mismatched types

Check failure on line 173 in bin/src/executor.rs

View workflow job for this annotation

GitHub Actions / beta

mismatched types

error[E0308]: mismatched types --> bin/src/executor.rs:173:43 | 173 | create_link(&tmp_mod, &prefix)?; | ----------- ^^^^^^^ expected `&str`, found `&PathBuf` | | | arguments to this function are incorrect | = note: expected reference `&str` found reference `&std::path::PathBuf` note: function defined here --> bin/src/utils/link.rs:51:8 | 51 | pub fn create_link(link: &PathBuf, target: &str) -> Result<(), Error> { | ^^^^^^^^^^^ ------------

Check failure on line 173 in bin/src/executor.rs

View workflow job for this annotation

GitHub Actions / stable

mismatched types

error[E0308]: mismatched types --> bin/src/executor.rs:173:43 | 173 | create_link(&tmp_mod, &prefix)?; | ----------- ^^^^^^^ expected `&str`, found `&PathBuf` | | | arguments to this function are incorrect | = note: expected reference `&str` found reference `&std::path::PathBuf` note: function defined here --> bin/src/utils/link.rs:51:8 | 51 | pub fn create_link(link: &PathBuf, target: &str) -> Result<(), Error> { | ^^^^^^^^^^^ ------------
}
}
}
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('/', "\\")),

Check failure on line 26 in bin/src/modules/file_patching.rs

View workflow job for this annotation

GitHub Actions / ubuntu

mismatched types

Check failure on line 26 in bin/src/modules/file_patching.rs

View workflow job for this annotation

GitHub Actions / beta

mismatched types

error[E0308]: mismatched types --> bin/src/modules/file_patching.rs:26:21 | 22 | create_link( | ----------- arguments to this function are incorrect ... 26 | &ctx.project_folder().join(addon.folder().replace('/', "\\")), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found `&PathBuf` | = note: expected reference `&str` found reference `&std::path::PathBuf` note: function defined here --> bin/src/utils/link.rs:51:8 | 51 | pub fn create_link(link: &PathBuf, target: &str) -> Result<(), Error> { | ^^^^^^^^^^^ ------------

Check failure on line 26 in bin/src/modules/file_patching.rs

View workflow job for this annotation

GitHub Actions / stable

mismatched types

error[E0308]: mismatched types --> bin/src/modules/file_patching.rs:26:21 | 22 | create_link( | ----------- arguments to this function are incorrect ... 26 | &ctx.project_folder().join(addon.folder().replace('/', "\\")), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found `&PathBuf` | = note: expected reference `&str` found reference `&std::path::PathBuf` note: function defined here --> bin/src/utils/link.rs:51:8 | 51 | pub fn create_link(link: &PathBuf, target: &str) -> Result<(), Error> { | ^^^^^^^^^^^ ------------
)
})
.collect::<Result<(), Error>>()
Expand Down
11 changes: 7 additions & 4 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,9 @@ 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> {
pub fn create_link(link: &PathBuf, target: &str) -> Result<(), Error> {
let target = target.replace('\\', "/");
trace!("link {:?} => {:?}", link, target);
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

0 comments on commit 3b9ca4c

Please sign in to comment.