Skip to content

Commit

Permalink
Restore fallback romfs behavior
Browse files Browse the repository at this point in the history
Address review comments and minor cleanup
  • Loading branch information
ian-h-chamberlain committed Jun 9, 2024
1 parent e499df1 commit a8d9d15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ toml = "0.5.6"
clap = { version = "4.0.15", features = ["derive", "wrap_help"] }
shlex = "1.3.0"
serde_json = "1.0.108"
camino = "1.1.7"
camino = "1.1"
32 changes: 15 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
pub mod command;
mod graph;

use core::fmt;
use std::ffi::OsStr;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use std::process::{Command, ExitStatus, Stdio};
use std::{env, io, process};
use std::{env, fmt, io, process};

use camino::{Utf8Path, Utf8PathBuf};
use cargo_metadata::{Message, MetadataCommand, Package};
use command::{Input, Test};
use rustc_version::Channel;
use semver::Version;
use tee::TeeReader;

use crate::command::{CargoCmd, Run};
use crate::command::{CargoCmd, Input, Run, Test};
use crate::graph::UnitGraph;

/// Build a command using [`make_cargo_build_command`] and execute it,
Expand Down Expand Up @@ -286,7 +284,8 @@ pub fn get_metadata(messages: &[Message]) -> CTRConfig {

if !icon_path.exists() {
icon_path = Utf8PathBuf::from(env::var("DEVKITPRO").unwrap())
.join(Utf8Path::new("libctru/default_icon.png"));
.join("libctru")
.join("default_icon.png");
}

// for now assume a single "kind" since we only support one output artifact
Expand All @@ -307,25 +306,21 @@ pub fn get_metadata(messages: &[Message]) -> CTRConfig {
authors: package.authors,
description: package
.description
.clone()
.unwrap_or_else(|| String::from("Homebrew Application")),
icon_path,
romfs_dir,
manifest_dir: package.manifest_path.parent().unwrap().into(),
target_path: artifact.executable.unwrap(),
}
}

fn get_romfs_dir(package: &Package) -> Option<Utf8PathBuf> {
if let Some(romfs_dir) = package
package
.metadata
.get("cargo-3ds")?
.get("romfs_dir")?
.as_str()
{
Some(package.manifest_path.parent()?.join(romfs_dir))
} else {
None
}
.map(Utf8PathBuf::from)
}

/// Builds the 3dsx using `3dsxtool`.
Expand All @@ -337,11 +332,7 @@ pub fn build_3dsx(config: &CTRConfig, verbose: bool) {
.arg(config.path_3dsx())
.arg(format!("--smdh={}", config.path_smdh()));

let romfs = config
.romfs_dir
.as_deref()
.unwrap_or(Utf8Path::new("romfs"));

let romfs = config.romfs_dir();
if romfs.is_dir() {
eprintln!("Adding RomFS from {romfs}");
command.arg(format!("--romfs={romfs}"));
Expand Down Expand Up @@ -397,6 +388,7 @@ pub struct CTRConfig {
description: String,
icon_path: Utf8PathBuf,
target_path: Utf8PathBuf,
manifest_dir: Utf8PathBuf,
romfs_dir: Option<Utf8PathBuf>,
}

Expand All @@ -411,6 +403,12 @@ impl CTRConfig {
self.target_path.with_extension("smdh")
}

/// Get the absolute path to the romfs directory, defaulting to `romfs` if not specified.
pub fn romfs_dir(&self) -> Utf8PathBuf {
self.manifest_dir
.join(self.romfs_dir.as_deref().unwrap_or(Utf8Path::new("romfs")))
}

/// Builds the smdh using `smdhtool`.
/// This will fail if `smdhtool` is not within the running directory or in a directory found in $PATH
pub fn build_smdh(&self, verbose: bool) {
Expand Down

0 comments on commit a8d9d15

Please sign in to comment.