Skip to content

Commit

Permalink
Resolve the workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
StratusFearMe21 committed Nov 27, 2023
2 parents 23ea0ca + 26271be commit 485be0a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 47 deletions.
23 changes: 20 additions & 3 deletions src/apprun.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use anyhow::Context;
use std::fs;

fn main() -> anyhow::Result<()> {
let here_dir = std::path::PathBuf::from(std::env::current_exe()?);
let here_dir = std::env::current_exe()?;
let parent = here_dir
.parent()
.with_context(|| format!("{} has no parent directory", &here_dir.display()))?;
std::env::set_current_dir(&parent)?;
std::env::set_current_dir(parent)?;
std::env::set_var(
"LD_LIBRARY_PATH",
format!("{}/usr/lib/:{}/usr/lib/i386-linux-gnu/:{}/usr/lib/x86_64-linux-gnu/:{}/usr/lib32/:{}/usr/lib64/:{}/lib/:{}/lib/i386-linux-gnu/:{}/lib/x86_64-linux-gnu/:{}/lib32/:{}/lib64/{}", parent.display(), parent.display(), parent.display(), parent.display(), parent.display(), parent.display(), parent.display(), parent.display(), parent.display(), parent.display(), if let Ok(ldlibpath) = std::env::var("LD_LIBRARY_PATH") { ":".to_string() + &ldlibpath } else { String::new() }),
Expand All @@ -32,7 +33,23 @@ fn main() -> anyhow::Result<()> {
),
);

let err = exec::execvp(parent.join("usr/bin/bin"), std::env::args());
let Some(executable) = fs::read_dir(parent.join("usr/bin/"))?.next() else {
eprintln!("Error: Executable file not found");
return Ok(());
};

let file_name = executable?.file_name();

let Some(executable_name) = file_name.to_str() else {
eprintln!("Error: Failed to get executable name");
return Ok(());
};

let err = exec::execvp(
parent.join(format!("usr/bin/{executable_name}")),
std::env::args(),
);
eprintln!("Error: {}", err);

Ok(())
}
80 changes: 36 additions & 44 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() -> Result<()> {
let target_prefix = cargo_metadata.target_directory;

if !std::path::Path::new("./icon.png").exists() {
std::fs::write("./icon.png", &[]).context("Failed to generate icon.png")?;
std::fs::write("./icon.png", []).context("Failed to generate icon.png")?;
}

while !Path::new("Cargo.toml").exists() {
Expand Down Expand Up @@ -55,7 +55,7 @@ fn main() -> Result<()> {
std::env::args()
.skip(2)
.find(|arg| arg.starts_with("--target="))
.map(|arg| format!("{}/{}", arg.split_at(9).1.to_string(), profile))
.map(|arg| format!("{}/{}", arg.split_at(9).1, profile))
.unwrap_or_else(|| profile)
};
let link_deps;
Expand All @@ -69,8 +69,7 @@ fn main() -> Result<()> {
match t.get("assets") {
Some(Value::Array(v)) => {
assets = v
.to_vec()
.into_iter()
.iter()
.filter_map(|v| match v {
Value::String(s) => Some(s),
_ => None,
Expand All @@ -83,23 +82,19 @@ fn main() -> Result<()> {
Some(Value::Boolean(v)) => link_deps = v.to_owned(),
_ => link_deps = false,
}
match t.get("args") {
Some(Value::Array(v)) => {
args = v
.to_vec()
.into_iter()
.filter_map(|v| match v {
Value::String(s) => Some(s),
_ => None,
})
.collect()
}
_ => {}
if let Some(Value::Array(v)) = t.get("args") {
args = v
.iter()
.filter_map(|v| match v {
Value::String(s) => Some(s),
_ => None,
})
.collect()
}
if let Some(Value::Array(arr)) = t.get("auto_link_exclude_list") {
for v in arr.iter() {
if let Value::String(s) = v {
link_exclude_list.push(glob::Pattern::new(&s).context(
link_exclude_list.push(glob::Pattern::new(s).context(
"Auto-link exclude list item not a valid glob pattern",
)?);
}
Expand All @@ -121,7 +116,6 @@ fn main() -> Result<()> {
link_deps = false;
}

if meta.bin.is_empty() {}
for currentbin in meta.bin {
let name = currentbin.name.unwrap_or(pkg.name.clone());
let appdirpath = std::path::Path::new(&target_prefix).join(name.clone() + ".AppDir");
Expand Down Expand Up @@ -149,8 +143,8 @@ fn main() -> Result<()> {
.output()
.with_context(|| {
format!(
"Failed to run ldd on {}",
format!("{}/{}/{}", target_prefix, &target, &name)
"Failed to run ldd on {}/{}/{}",
target_prefix, &target, &name
)
})?
.stdout,
Expand All @@ -164,34 +158,33 @@ fn main() -> Result<()> {
fs_extra::dir::create("libs", true).context("Failed to create libs dir")?;

for line in linkedlibs.lines() {
if line.starts_with("/") {
if !std::path::Path::new("libs").join(&line[1..]).exists() {
std::os::unix::fs::symlink(
if line.starts_with('/') && !std::path::Path::new("libs").join(&line[1..]).exists()
{
std::os::unix::fs::symlink(
line,
std::path::Path::new("libs").join(
std::path::Path::new(line)
.file_name()
.with_context(|| format!("No filename for {}", line))?,
),
)
.with_context(|| {
format!(
"Error symlinking {} to {}",
line,
std::path::Path::new("libs").join(
std::path::Path::new(line)
.file_name()
.with_context(|| format!("No filename for {}", line))?,
),
std::path::Path::new("libs").join(&line[1..]).display()
)
.with_context(|| {
format!(
"Error symlinking {} to {}",
line,
std::path::Path::new("libs").join(&line[1..]).display()
)
})?;
}
})?;
}
}
}

if std::path::Path::new("libs").exists() {
for i in std::fs::read_dir("libs").context("Could not read libs dir")? {
let ref path = i?.path();
let path = &i?.path();

// Skip if it matches the exclude list.
if let Some(file_name) = path.file_name().map(|p| p.to_str()).flatten() {
if let Some(file_name) = path.file_name().and_then(|p| p.to_str()) {
if link_exclude_list.iter().any(|p| p.matches(file_name)) {
continue;
}
Expand All @@ -200,7 +193,7 @@ fn main() -> Result<()> {
let link = std::fs::read_link(path)
.with_context(|| format!("Error reading link in libs {}", path.display()))?;

if fs_extra::dir::create_all(
fs_extra::dir::create_all(
appdirpath.join(
&link
.parent()
Expand All @@ -210,9 +203,7 @@ fn main() -> Result<()> {
[1..],
),
false,
)
.is_err()
{}
)?;
let dest = appdirpath.join(
&link
.to_str()
Expand Down Expand Up @@ -276,9 +267,10 @@ fn main() -> Result<()> {
})?;

let mut bin_args = args.to_vec();
bin_args.push(appdirpath.into_os_string().into_string().unwrap());
let appdirpath = appdirpath.into_os_string().into_string().unwrap();
bin_args.push(&appdirpath);

let _ = std::fs::create_dir_all(format!("{}/appimage", &target_prefix))
std::fs::create_dir_all(format!("{}/appimage", &target_prefix))
.context("Unable to create output dir")?;
Command::new("appimagetool")
.args(bin_args)
Expand Down

0 comments on commit 485be0a

Please sign in to comment.