Skip to content

Commit

Permalink
Merge pull request #476 from kotval/out_of_tree_app
Browse files Browse the repository at this point in the history
Modify xtask to permit named BinaryFile
  • Loading branch information
bunnie authored Jan 8, 2024
2 parents f196bcf + 48d0bf4 commit 3c3435f
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 225 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions xtask/src/app_manifest.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// This module supports generating the app menus from the JSON manifest in the apps/ directory.

use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};
use std::{
fs::{OpenOptions, File},
fmt::Write as StdWrite,
fs::{File, OpenOptions},
io::{Read, Write},
string::String,
fmt::Write as StdWrite,
};
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};

#[derive(Deserialize, Serialize, Debug)]
struct AppManifest {
context_name: String,
menu_name: HashMap<String, HashMap<String, String>>,
submenu: Option::<u8>,
submenu: Option<u8>,
}
#[derive(Deserialize, Serialize, Debug)]
struct Locales {
Expand Down Expand Up @@ -89,9 +89,14 @@ pub(crate) fn generate_app_menus(apps: &Vec<String>) {
gam_tokens,
"\npub const EXPECTED_APP_CONTEXTS: &[&'static str] = &["
)
.unwrap();
.unwrap();
for (app_name, manifest) in working_set.iter() {
writeln!(gam_tokens, " APP_NAME_{},", app_name.to_uppercase().replace("-", "_"),).unwrap();
writeln!(
gam_tokens,
" APP_NAME_{},",
app_name.to_uppercase().replace("-", "_"),
)
.unwrap();
if let Some(menu_count) = manifest.submenu {
for i in 0..menu_count {
writeln!(
Expand Down
48 changes: 28 additions & 20 deletions xtask/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ impl BuildStream {
}
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum CrateSpec {
/// name of the crate
Local(String, bool),
/// crates.io: (name of crate, version)
CratesIo(String, String, bool),
/// a prebuilt package: (name of executable, URL for download)
Prebuilt(String, String, bool),
/// a prebuilt binary, done using command line tools
BinaryFile(String, bool),
/// a prebuilt binary, done using command line tools: (Optional name, path)
BinaryFile(Option<String>, String, bool),
/// an empty entry
None,
}
Expand All @@ -41,16 +41,17 @@ impl CrateSpec {
CrateSpec::Local(_s, xip) => *xip,
CrateSpec::CratesIo(_n, _v, xip) => *xip,
CrateSpec::Prebuilt(_n, _u, xip) => *xip,
CrateSpec::BinaryFile(_path, xip) => *xip,
CrateSpec::BinaryFile(_n, _path, xip) => *xip,
_ => false
}
}
pub fn set_xip(&mut self, xip: bool) {
*self = match self {
//TODO: why do these to_strings need to be here?
CrateSpec::Local(s, _xip) => CrateSpec::Local(s.to_string(), xip),
CrateSpec::CratesIo(n, v, _xip) => CrateSpec::CratesIo(n.to_string(), v.to_string(), xip),
CrateSpec::Prebuilt(n, u, _xip) => CrateSpec::Prebuilt(n.to_string(), u.to_string(), xip),
CrateSpec::BinaryFile(path, _xip) => CrateSpec::BinaryFile(path.to_string(), xip),
CrateSpec::BinaryFile(n, path, _xip) => CrateSpec::BinaryFile(n.as_ref().or(None).cloned(), path.to_string(), xip),
CrateSpec::None => CrateSpec::None,
}
}
Expand All @@ -59,22 +60,18 @@ impl CrateSpec {
CrateSpec::Local(s, _xip) => Some(s.to_string()),
CrateSpec::CratesIo(n, _v, _xip) => Some(n.to_string()),
CrateSpec::Prebuilt(n, _u, _xip) => Some(n.to_string()),
CrateSpec::BinaryFile(path, _xip) => Some(path.to_string()),
CrateSpec::BinaryFile(n, path, _xip) => {
if let Some(name) = n {
Some(name.to_string())
}
else {
Some(path.to_string())
}
},
_ => None,
}
}
}
impl Clone for CrateSpec {
fn clone(&self) -> CrateSpec {
match self {
CrateSpec::Local(s, xip) => CrateSpec::Local(s.to_string(), *xip),
CrateSpec::CratesIo(n, v, xip) => CrateSpec::CratesIo(n.to_string(), v.to_string(), *xip),
CrateSpec::Prebuilt(n, u, xip) => CrateSpec::Prebuilt(n.to_string(), u.to_string(), *xip),
CrateSpec::BinaryFile(path, xip) => CrateSpec::BinaryFile(path.to_string(), *xip),
CrateSpec::None => CrateSpec::None,
}
}
}
impl From<&str> for CrateSpec {
fn from(spec: &str) -> CrateSpec {
// remote crates are specified as "name@version", i.e. "[email protected]"
Expand All @@ -99,7 +96,13 @@ impl From<&str> for CrateSpec {
// Note that this is after a test for the '#' character, so that disambiguates URL slashes
// It does mean that files with a '#' character in them are mistaken for URL coded paths, and '@' as remote crates.
} else if spec.contains('/') || spec.contains('\\') {
CrateSpec::BinaryFile(spec.to_string(), false)
//optionally a BinaryFile can have a name associated with it as "name:path"
if spec.find(':').is_some() {
let (name,path) = spec.split_once(':').unwrap();
CrateSpec::BinaryFile(Some(name.to_string()), path.to_string(), false)
} else {
CrateSpec::BinaryFile(None, spec.to_string(), false)
}
} else {
CrateSpec::Local(spec.to_string(), false)
}
Expand Down Expand Up @@ -323,7 +326,6 @@ impl Builder {
}
self
}

/// add a feature to be passed on to services
pub fn add_feature<'a>(&'a mut self, feature: &str) -> &'a mut Builder {
self.features.push(feature.into());
Expand Down Expand Up @@ -595,6 +597,12 @@ impl Builder {
match app {
CrateSpec::Local(name, _xip) => app_names.push(name.into()),
CrateSpec::CratesIo(name, _version, _xip) => app_names.push(name.into()),
CrateSpec::BinaryFile(name, _location, _xip) => {
// if binary file has a name, ensure it ends up in the app menu
if let Some(n) = name {
app_names.push(n.to_string())
} else {}
},
_ => {}
}
}
Expand Down Expand Up @@ -930,7 +938,7 @@ impl Builder {
let mut paths = Vec::<String>::new();
for item in [&self.services[..], &self.apps[..]].concat() {
match item {
CrateSpec::BinaryFile(path, _xip) => {
CrateSpec::BinaryFile(_name, path, _xip) => {
paths.push(path);
}
_ => {}
Expand Down
Loading

0 comments on commit 3c3435f

Please sign in to comment.