-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::{Context, Result}; | ||
|
||
include!(concat!(env!("OUT_DIR"), "/methods.rs")); | ||
|
||
pub fn export_elf(elf_path: &PathBuf) -> Result<()> { | ||
// Create output directory if it doesn't exist | ||
fs::create_dir_all(elf_path).context("Failed to create ELF output directory")?; | ||
|
||
// Get the current crate's directory | ||
let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
|
||
// Iterate over entries in cargo_dir | ||
for entry in fs::read_dir(&cargo_dir) | ||
.with_context(|| format!("Failed to read directory {:?}", cargo_dir))? | ||
{ | ||
let entry = entry?; | ||
let path = entry.path(); | ||
if path.is_dir() { | ||
if let Some(folder_name) = path.file_name().and_then(|n| n.to_str()) { | ||
if folder_name.starts_with("guest-") { | ||
let cache_dir = path.join("cache"); | ||
if cache_dir.is_dir() { | ||
for file in fs::read_dir(&cache_dir).with_context(|| { | ||
format!("Failed to read cache directory {:?}", cache_dir) | ||
})? { | ||
let file = file?; | ||
let file_path = file.path(); | ||
if file_path.is_file() | ||
&& file_path.extension().and_then(|s| s.to_str()) == Some("elf") | ||
{ | ||
let file_name = file_path.file_name().unwrap(); | ||
let dest_file = elf_path.join(file_name); | ||
fs::copy(&file_path, &dest_file).with_context(|| { | ||
format!("Failed to copy {:?} to {:?}", file_path, dest_file) | ||
})?; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} |