Merge remote-tracking branch 'eupn/xtask-simplify' into swap

This commit is contained in:
bunnie 2024-04-01 14:20:45 +08:00
commit 5add97db90
8 changed files with 173 additions and 222 deletions

View file

@ -472,6 +472,7 @@ perform the Xous firmware upgrade. This requires running manual update commands,
- @gsora has added the `hidapi` - apps can now register a HID descriptor for custom interactions over USB. See `apps/hidv2` for democumentation.
- change kernel and loader targets to riscv-unknown-elf-none because `xous` is now a proper target (required for Rust 1.76 compatibility)
- `curve25519-dalek` API is now at 4.1.2, thanks to @kotval for pulling it together. The new API removes `engine-25519` and rolls hardware allocate/release into the forked crate, similar to how sha2 was ported. `engine-25519` crate now removed from source tree, as it is now depracted since all the functionality was pulled into `curve25519-dalek`.
- keymap is checked on every call to send a key to the USB keyboard. This allows us to toggle the keymap temporarily to allow typing into hosts with a different keymap (instead of requiring a reboot)
## Roadmap
- Lots of testing and bug fixes

View file

@ -85,8 +85,6 @@ pub(crate) fn main_hw() -> ! {
let tt = ticktimer_server::Ticktimer::new().unwrap();
#[cfg(not(feature = "minimal"))]
let native_kbd = keyboard::Keyboard::new(&xns).unwrap();
#[cfg(not(feature = "minimal"))]
let native_map = native_kbd.get_keymap().unwrap();
#[cfg(not(feature = "minimal"))]
let serial_number = format!("{:x}", llio.soc_dna().unwrap());
@ -1165,6 +1163,7 @@ pub(crate) fn main_hw() -> ! {
match view {
Views::FidoWithKbd => {
if usb_dev.state() == UsbDeviceState::Configured {
let native_map = native_kbd.get_keymap().unwrap();
let mut codes = Vec::<Keyboard>::new();
if code0 != 0 {
codes.push(match native_map {
@ -1262,6 +1261,9 @@ pub(crate) fn main_hw() -> ! {
match view {
#[cfg(not(feature = "minimal"))]
Views::FidoWithKbd => {
// check keymap on every call because we may need to toggle this for e.g. plugging
// into a new host with a different map
let native_map = native_kbd.get_keymap().unwrap();
for ch in usb_send.s.as_str().unwrap().chars() {
// ASSUME: user's keyboard type matches the preference on their Precursor device.
let codes = match native_map {

View file

@ -51,7 +51,7 @@ pub(crate) fn generate_app_menus(apps: &Vec<String>) {
// derive a working_set that is just the apps we requested
for app in apps {
if let Some(manifest) = manifest.get(app) {
working_set.insert(app.to_string(), &manifest);
working_set.insert(app.to_string(), manifest);
}
}
@ -63,7 +63,7 @@ pub(crate) fn generate_app_menus(apps: &Vec<String>) {
writeln!(
gam_tokens,
"pub const APP_NAME_{}: &'static str = \"{}\";",
app_name.to_uppercase().replace("-", "_"),
app_name.to_uppercase().replace('-', "_"),
manifest.context_name,
)
.unwrap();
@ -73,7 +73,7 @@ pub(crate) fn generate_app_menus(apps: &Vec<String>) {
gam_tokens,
"pub const APP_MENU_{}_{}: &'static str = \"{} Submenu {}\";",
i,
app_name.to_uppercase().replace("-", "_"),
app_name.to_uppercase().replace('-', "_"),
manifest.context_name,
i,
)
@ -83,10 +83,10 @@ pub(crate) fn generate_app_menus(apps: &Vec<String>) {
}
writeln!(gam_tokens, "\npub const EXPECTED_APP_CONTEXTS: &[&'static str] = &[").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!(gam_tokens, " APP_MENU_{}_{},", i, app_name.to_uppercase().replace("-", "_"),)
writeln!(gam_tokens, " APP_MENU_{}_{},", i, app_name.to_uppercase().replace('-', "_"),)
.unwrap();
}
}
@ -98,7 +98,7 @@ pub(crate) fn generate_app_menus(apps: &Vec<String>) {
let mut menu = String::new();
writeln!(menu, "#![cfg_attr(rustfmt, rustfmt_skip)]").unwrap();
writeln!(menu, "// This file is auto-generated by xtask/main.rs generate_app_menus()").unwrap();
if apps.len() == 0 {
if apps.is_empty() {
writeln!(menu, "// NO APPS SELECTED: suppressing warning messages!").unwrap();
writeln!(menu, "#![allow(dead_code)]").unwrap();
writeln!(menu, "#![allow(unused_imports)]").unwrap();
@ -139,7 +139,7 @@ pub(crate) fn app_dispatch(gam: &gam::Gam, token: [u32; 4], index: usize) -> Res
Ok(())
}},",
index,
app_name.to_uppercase().replace("-", "_")
app_name.to_uppercase().replace('-', "_")
)
.unwrap();
}
@ -170,7 +170,7 @@ pub(crate) fn app_menu_items(menu_items: &mut Vec::<MenuItem>, status_conn: u32)
.unwrap();
for (index, (_app_name, manifest)) in working_set.iter().enumerate() {
writeln!(menu, " menu_items.push(MenuItem {{",).unwrap();
assert!(manifest.menu_name.len() == 1, "Improper menu name record entry");
assert_eq!(manifest.menu_name.len(), 1, "Improper menu name record entry");
for name in manifest.menu_name.keys() {
writeln!(menu, " name: xous_ipc::String::from_str(t!(\"{}\", locales::LANG)),", name)
.unwrap();

View file

@ -15,7 +15,7 @@ pub(crate) enum BuildStream {
Release,
}
impl BuildStream {
pub fn to_str(&self) -> &str {
pub fn as_str(&self) -> &str {
match self {
BuildStream::Debug => "debug",
BuildStream::Release => "release",
@ -180,7 +180,7 @@ impl Builder {
/// Specify an alternate loader key, as a String that can encode a file name
/// in the local directory, or a path + filename.
#[allow(dead_code)]
pub fn loader_key_file<'a>(&'a mut self, filename: String) -> &'a mut Builder {
pub fn loader_key_file(&mut self, filename: String) -> &mut Builder {
self.loader_key = filename;
self
}
@ -188,7 +188,7 @@ impl Builder {
/// Specify an alternate loader key, as a String that can encode a file name
/// in the local directory, or a path + filename.
#[allow(dead_code)]
pub fn kernel_key_file<'a>(&'a mut self, filename: String) -> &'a mut Builder {
pub fn kernel_key_file(&mut self, filename: String) -> &mut Builder {
self.kernel_key = filename;
self
}
@ -202,26 +202,26 @@ impl Builder {
/// Set the build stream (debug or release)
#[allow(dead_code)]
pub fn stream<'a>(&'a mut self, stream: BuildStream) -> &'a mut Builder {
pub fn stream(&mut self, stream: BuildStream) -> &mut Builder {
self.stream = stream;
self
}
/// Disable default features on the loader
#[allow(dead_code)]
pub fn loader_disable_defaults<'a>(&'a mut self) -> &'a mut Builder {
pub fn loader_disable_defaults(&mut self) -> &mut Builder {
self.loader_disable_defaults = true;
self
}
/// Disable default features on the loader
#[allow(dead_code)]
pub fn kernel_disable_defaults<'a>(&'a mut self) -> &'a mut Builder {
pub fn kernel_disable_defaults(&mut self) -> &mut Builder {
self.kernel_disable_defaults = true;
self
}
pub fn add_global_flag<'a>(&'a mut self, flag: &str) -> &'a mut Builder {
pub fn add_global_flag(&mut self, flag: &str) -> &mut Builder {
self.global_flags.push(flag.to_string());
self
}
@ -233,19 +233,19 @@ impl Builder {
/// version. Eventually (on the order of many months or years), this code gets retired,
/// otherwise we accumulate rarely-used code ad nauseam.
#[allow(dead_code)]
pub fn set_min_xous_ver<'a>(&'a mut self, min_ver_string: &str) -> &'a mut Builder {
pub fn set_min_xous_ver(&mut self, min_ver_string: &str) -> &mut Builder {
self.min_ver = min_ver_string.to_string();
self
}
/// specify a locale string to override for the current build
pub fn override_locale<'a>(&'a mut self, locale: &str) -> &'a mut Builder {
pub fn override_locale(&mut self, locale: &str) -> &mut Builder {
self.locale_override = Some(locale.into());
self
}
/// Configure for hosted mode
pub fn target_hosted<'a>(&'a mut self) -> &'a mut Builder {
pub fn target_hosted(&mut self) -> &mut Builder {
self.loader = CrateSpec::None;
self.target = None;
self.target_kernel = None;
@ -256,7 +256,7 @@ impl Builder {
}
/// Configure for renode targets
pub fn target_renode<'a>(&'a mut self) -> &'a mut Builder {
pub fn target_renode(&mut self) -> &mut Builder {
self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string());
self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string());
self.stream = BuildStream::Release;
@ -268,9 +268,9 @@ impl Builder {
}
/// Configure for precursor targets. This is the default, but it's good practice
/// to call it anyways just in case the defaults change. The `soc_version` should
/// to call it anyway just in case the defaults change. The `soc_version` should
/// be just the gitrev of the soc version, not the entire feature name.
pub fn target_precursor<'a>(&'a mut self, soc_version: &str) -> &'a mut Builder {
pub fn target_precursor(&mut self, soc_version: &str) -> &mut Builder {
self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string());
self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string());
self.stream = BuildStream::Release;
@ -281,7 +281,7 @@ impl Builder {
self
}
pub fn target_precursor_no_image<'a>(&'a mut self, soc_version: &str) -> &'a mut Builder {
pub fn target_precursor_no_image(&mut self, soc_version: &str) -> &mut Builder {
self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string());
self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string());
self.stream = BuildStream::Release;
@ -304,7 +304,7 @@ impl Builder {
}
/// Configure various Cramium targets
pub fn target_cramium_fpga<'a>(&'a mut self) -> &'a mut Builder {
pub fn target_cramium_fpga(&mut self) -> &mut Builder {
self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string());
self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string());
self.stream = BuildStream::Release;
@ -315,7 +315,7 @@ impl Builder {
self
}
pub fn target_cramium_soc<'a>(&'a mut self) -> &'a mut Builder {
pub fn target_cramium_soc(&mut self) -> &mut Builder {
self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string());
self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string());
self.stream = BuildStream::Release;
@ -329,14 +329,14 @@ impl Builder {
/// Override the default kernel. For example, to use the kernel from crates.io, specify as
/// "xous-kernel@0.9.9"
#[allow(dead_code)]
pub fn use_kernel<'a>(&'a mut self, spec: &str) -> &'a mut Builder {
pub fn use_kernel(&mut self, spec: &str) -> &mut Builder {
self.kernel = spec.into();
self
}
/// Override the default loader
#[allow(dead_code)]
pub fn use_loader<'a>(&'a mut self, spec: &str) -> &'a mut Builder {
pub fn use_loader(&mut self, spec: &str) -> &mut Builder {
self.loader = spec.into();
self
}
@ -360,7 +360,7 @@ impl Builder {
}
/// Add just one service
pub fn add_service<'a>(&'a mut self, service_spec: &str, region: LoaderRegion) -> &'a mut Builder {
pub fn add_service(&mut self, service_spec: &str, region: LoaderRegion) -> &mut Builder {
let mut spec: CrateSpec = service_spec.into();
spec.set_region(region);
self.services.push(spec);
@ -368,16 +368,16 @@ impl Builder {
}
/// Add a list of services
pub fn add_services<'a>(&'a mut self, service_list: &Vec<String>) -> &'a mut Builder {
pub fn add_services<S: AsRef<str>>(&mut self, service_list: impl IntoIterator<Item = S>) -> &mut Builder {
for service in service_list {
self.services.push(service.as_str().into());
self.services.push(service.as_ref().into());
}
self
}
/// Add just one app. Apps can be remote or downloaded externally.
#[allow(dead_code)]
pub fn add_app<'a>(&'a mut self, app_spec: &str, region: LoaderRegion) -> &'a mut Builder {
pub fn add_app(&mut self, app_spec: &str, region: LoaderRegion) -> &mut Builder {
let mut spec: CrateSpec = app_spec.into();
spec.set_region(region);
self.apps.push(spec);
@ -385,22 +385,22 @@ impl Builder {
}
/// Add a list of apps. Apps can be remote or downloaded externally.
pub fn add_apps<'a>(&'a mut self, app_list: &Vec<String>) -> &'a mut Builder {
pub fn add_apps<S: AsRef<str>>(&mut self, app_list: impl IntoIterator<Item = S>) -> &mut Builder {
for app in app_list {
self.apps.push(app.as_str().into());
self.apps.push(app.as_ref().into());
}
self
}
/// add a feature to be passed on to services
pub fn add_feature<'a>(&'a mut self, feature: &str) -> &'a mut Builder {
pub fn add_feature(&mut self, feature: &str) -> &mut Builder {
self.features.push(feature.into());
self
}
/// remove a feature previously added by a previous call
#[allow(dead_code)]
pub fn remove_feature<'a>(&'a mut self, feature: &str) -> &'a mut Builder {
pub fn remove_feature(&mut self, feature: &str) -> &mut Builder {
self.features.retain(|x| x != feature);
self
}
@ -409,20 +409,20 @@ impl Builder {
pub fn has_feature(&self, feature: &str) -> bool { self.features.contains(&feature.to_string()) }
/// add a feature to be passed on to just the loader
pub fn add_loader_feature<'a>(&'a mut self, feature: &str) -> &'a mut Builder {
pub fn add_loader_feature(&mut self, feature: &str) -> &mut Builder {
self.loader_features.push(feature.into());
self
}
/// add a feature to be passed on to just the loader
#[allow(dead_code)]
pub fn add_kernel_feature<'a>(&'a mut self, feature: &str) -> &'a mut Builder {
pub fn add_kernel_feature(&mut self, feature: &str) -> &mut Builder {
self.kernel_features.push(feature.into());
self
}
/// only build a hosted target. don't run it. Used exclusively to confirm that hosted mode builds in CI.
pub fn hosted_build_only<'a>(&'a mut self) -> &'a mut Builder {
pub fn hosted_build_only(&mut self) -> &mut Builder {
self.dry_run = true;
self
}
@ -432,12 +432,12 @@ impl Builder {
/// method, and it gets called repeatedly to build the kernel, loader, and services.
fn builder(
&self,
packages: &Vec<CrateSpec>,
features: &Vec<String>,
packages: &[CrateSpec],
features: &[String],
target: &Option<&str>,
// the stream is specified separately here because the loader is special-case always release
stream: BuildStream,
extra_args: &Vec<String>,
extra_args: &[String],
no_default_features: bool,
) -> Result<Vec<String>, DynError> {
// list of build artifacts, as full paths specific to the host OS
@ -456,7 +456,7 @@ impl Builder {
Some(t) => format!("{}/", t),
None => "".to_string(),
},
stream.to_str(),
stream.as_str(),
);
remote_args.push(&output_root);
@ -494,13 +494,13 @@ impl Builder {
let mut remote_pkgs = Vec::<(&str, &str)>::new();
for pkg in packages.iter() {
match pkg {
CrateSpec::Local(name, _region) => local_pkgs.push(&name),
CrateSpec::Local(name, _region) => local_pkgs.push(name),
CrateSpec::CratesIo(name, version, _region) => remote_pkgs.push((&name, &version)),
_ => {}
}
}
if local_pkgs.len() > 0 {
if !local_pkgs.is_empty() {
for pkg in local_pkgs {
local_args.push("--package");
local_args.push(pkg);
@ -509,7 +509,7 @@ impl Builder {
if no_default_features {
local_args.push("--no-default-features");
}
if features.len() > 0 {
if !features.is_empty() {
for feature in features {
local_args.push("--features");
local_args.push(feature);
@ -528,12 +528,12 @@ impl Builder {
return Err("Local build failed".into());
}
}
if remote_pkgs.len() > 0 {
if !remote_pkgs.is_empty() {
// remote packages are installed one at a time
if no_default_features {
local_args.push("--no-default-features");
}
if features.len() > 0 {
if !features.is_empty() {
for feature in features {
remote_args.push("--features");
remote_args.push(feature);
@ -609,14 +609,14 @@ impl Builder {
// the service wasn't found in any of the other lists, mark it as non-xip
inie.push(service.to_string());
}
assert!(inie.len() + inif.len() + inis.len() == services.len());
assert_eq!(inie.len() + inif.len() + inis.len(), services.len());
(inie, inif, inis)
}
/// Consume the builder and execute the configured build task. This handles dispatching all
/// configurations, including renode, hosted, and hardware targets.
pub fn build(mut self) -> Result<(), DynError> {
if self.apps.len() == 0 && self.services.len() == 0 {
if self.apps.is_empty() && self.services.is_empty() {
// no services were specified - don't build anything
return Ok(());
}
@ -658,8 +658,8 @@ impl Builder {
return Err("Target unknown: please check your UTRA target".into());
}
crate::utils::ensure_compiler(&self.target.as_ref().map(|s| s.as_str()), false, false)?;
crate::utils::ensure_kernel_compiler(&self.target_kernel.as_ref().map(|s| s.as_str()), false)?;
crate::utils::ensure_compiler(&self.target.as_deref(), false, false)?;
crate::utils::ensure_kernel_compiler(&self.target_kernel.as_deref(), false)?;
self.locale_override(); // apply the locale override
// ------ build the services & apps ------
@ -668,12 +668,9 @@ impl Builder {
match app {
CrateSpec::Local(name, _region) => app_names.push(name.into()),
CrateSpec::CratesIo(name, _version, _region) => app_names.push(name.into()),
CrateSpec::BinaryFile(name, _location, _region) => {
CrateSpec::BinaryFile(Some(name), _location, _region) => {
// 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 {
}
app_names.push(name.to_string())
}
_ => {}
}
@ -684,7 +681,7 @@ impl Builder {
&self.features,
&self.target.as_deref(),
self.stream,
&vec![],
&[],
false,
)?;
@ -698,11 +695,8 @@ impl Builder {
// hosted mode doesn't specify a cross-compilation target!
// throw a warning if prebuilt files are specified for hosted mode
for item in [&self.services[..], &self.apps[..]].concat() {
match item {
CrateSpec::Prebuilt(name, _, _region) => {
println!("Warning! Pre-built binaries not supported for hosted mode ({})", name)
}
_ => {}
if let CrateSpec::Prebuilt(name, _, _region) = item {
println!("Warning! Pre-built binaries not supported for hosted mode ({})", name);
}
}
// fixup windows paths
@ -712,9 +706,8 @@ impl Builder {
}
}
let mut hosted_args = vec!["run"];
match self.stream {
BuildStream::Release => hosted_args.push("--release"),
_ => {}
if let BuildStream::Release = self.stream {
hosted_args.push("--release");
}
hosted_args.push("--");
for service in services_path.iter() {
@ -733,8 +726,8 @@ impl Builder {
}
for f in canonicalized_paths {
let path_as_str = f.to_str().expect("Couldn't canonicalize executable target").to_string();
let windows_clean_path = if path_as_str.starts_with("\\\\?\\") {
path_as_str[4..].to_owned()
let windows_clean_path = if let Some(stripped) = path_as_str.strip_prefix("\\\\?\\") {
stripped.to_owned()
} else {
path_as_str
};
@ -759,11 +752,11 @@ impl Builder {
} else {
// confirm the kernel can build before quitting
let _ = self.builder(
&vec![CrateSpec::Local("xous-kernel".into(), LoaderRegion::Ram)],
&[CrateSpec::Local("xous-kernel".into(), LoaderRegion::Ram)],
&self.kernel_features,
&self.target_kernel.as_deref(),
self.stream,
&vec![],
&[],
false,
)?;
println!("Dry run requested: only building and not running");
@ -775,7 +768,7 @@ impl Builder {
kernel_extra.push("--no-default-features".to_string());
}
let kernel_path = self.builder(
&vec![self.kernel.clone()],
&[self.kernel.clone()],
&self.kernel_features,
&self.target_kernel.as_deref(),
self.stream,
@ -786,18 +779,18 @@ impl Builder {
// ------ build the loader ------
// stash any LTO settings applied to the kernel; proper layout of the loader
// block depends on the loader being compact and highly optimized.
let existing_lto = std::env::var("CARGO_PROFILE_RELEASE_LTO").map(|v| Some(v)).unwrap_or(None);
let existing_lto = env::var("CARGO_PROFILE_RELEASE_LTO").map(Some).unwrap_or(None);
let existing_codegen_units =
std::env::var("CARGO_PROFILE_RELEASE_CODEGEN_UNITS").map(|v| Some(v)).unwrap_or(None);
env::var("CARGO_PROFILE_RELEASE_CODEGEN_UNITS").map(Some).unwrap_or(None);
// these settings will generate the most compact code (but also the hardest to debug)
std::env::set_var("CARGO_PROFILE_RELEASE_LTO", "true");
std::env::set_var("CARGO_PROFILE_RELEASE_CODEGEN_UNITS", "1");
env::set_var("CARGO_PROFILE_RELEASE_LTO", "true");
env::set_var("CARGO_PROFILE_RELEASE_CODEGEN_UNITS", "1");
let mut loader_extra = vec![];
if self.loader_disable_defaults {
loader_extra.push("--no-default-features".to_string());
}
let loader = self.builder(
&vec![self.loader.clone()],
&[self.loader.clone()],
&self.loader_features,
&self.target_kernel.as_deref(),
BuildStream::Release, // loader doesn't fit if you build with Debug
@ -806,17 +799,17 @@ impl Builder {
)?;
// restore the LTO settings
if let Some(existing) = existing_lto {
std::env::set_var("CARGO_PROFILE_RELEASE_LTO", existing);
env::set_var("CARGO_PROFILE_RELEASE_LTO", existing);
}
if let Some(existing) = existing_codegen_units {
std::env::set_var("CARGO_PROFILE_RELEASE_CODEGEN_UNITS", existing);
env::set_var("CARGO_PROFILE_RELEASE_CODEGEN_UNITS", existing);
}
// ------ if targeting renode, regenerate the Platform file -----
if self.run_svd2repl {
Command::new(cargo())
.current_dir(project_root())
.args(&[
.args([
"run",
"-p",
"svd2repl",
@ -831,9 +824,9 @@ impl Builder {
let svd_spec_path = format!(
"target/{}/{}/build/SVD_PATH",
self.target.as_ref().expect("target"),
self.stream.to_str()
self.stream.as_str()
);
let mut svd_spec_file = OpenOptions::new().read(true).open(&svd_spec_path)?;
let mut svd_spec_file = OpenOptions::new().read(true).open(svd_spec_path)?;
let mut svd_path_str = String::new();
svd_spec_file.read_to_string(&mut svd_path_str)?;
let mut svd_paths = Vec::new();
@ -857,7 +850,7 @@ impl Builder {
loader_presign.push("loader_presign.bin");
let status = Command::new(cargo())
.current_dir(project_root())
.args(&[
.args([
"run",
"--package",
"tools",
@ -874,7 +867,7 @@ impl Builder {
let status = Command::new(cargo())
.current_dir(project_root())
.args(&[
.args([
"run",
"--package",
"tools",
@ -900,7 +893,7 @@ impl Builder {
let status = Command::new(cargo())
.current_dir(project_root())
.args(&[
.args([
"run",
"--package",
"tools",
@ -939,19 +932,8 @@ impl Builder {
inis: &[String],
memory_spec: Vec<String>,
) -> Result<PathBuf, DynError> {
let stream = self.stream.to_str();
let mut args = vec!["run", "--package", "tools", "--bin", "create-image"];
args.push("--features");
if self.utra_target.contains("renode") {
args.push("renode");
} else if self.utra_target.contains("precursor") {
args.push("precursor");
} else if self.utra_target.contains("atsama5d2") {
args.push("atsama5d2");
} else if self.utra_target.contains("cramium-soc") {
args.push("cramium-soc")
}
args.push("--");
let stream = self.stream.as_str();
let mut args = vec!["run", "--package", "tools", "--bin", "create-image", "--"];
let mut output_file = PathBuf::new();
output_file.push("target");
@ -966,14 +948,14 @@ impl Builder {
for i in init {
args.push("--init");
// strip '@' version specifiers out of the package names, if they exist.
let i = if i.contains("@") { i.split("@").next().unwrap() } else { i };
let i = if i.contains('@') { i.split('@').next().unwrap() } else { i };
args.push(i);
}
for i in inif {
args.push("--inif");
// strip '@' version specifiers out of the package names, if they exist.
let i = if i.contains("@") { i.split("@").next().unwrap() } else { i };
let i = if i.contains('@') { i.split('@').next().unwrap() } else { i };
args.push(i);
}
@ -1002,7 +984,7 @@ impl Builder {
args.push(&memory_spec[0]);
for spec in memory_spec[1..].iter() {
args.push("--extra-svd");
args.push(&spec);
args.push(spec);
}
}
@ -1017,28 +999,25 @@ impl Builder {
fn fetch_prebuilds(&self) -> Result<Vec<String>, DynError> {
let mut paths = Vec::<String>::new();
for item in [&self.services[..], &self.apps[..]].concat() {
match item {
CrateSpec::Prebuilt(name, url, _region) => {
let exec_name = format!(
"target/{}/{}/{}",
self.target.as_ref().expect("target"),
self.stream.to_str(),
name
);
println!("Fetching {} executable from build server...", name);
let mut exec_file = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&exec_name)
.expect("Can't open our version file for writing");
let mut freader = ureq::get(&url).call()?.into_reader();
std::io::copy(&mut freader, &mut exec_file)?;
println!("{} pre-built exec is {} bytes", name, exec_file.metadata().unwrap().len());
paths.push(exec_name);
}
_ => {}
if let CrateSpec::Prebuilt(name, url, _region) = item {
let exec_name = format!(
"target/{}/{}/{}",
self.target.as_ref().expect("target"),
self.stream.as_str(),
name
);
println!("Fetching {} executable from build server...", name);
let mut exec_file = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&exec_name)
.expect("Can't open our version file for writing");
let mut freader = ureq::get(&url).call()?.into_reader();
std::io::copy(&mut freader, &mut exec_file)?;
println!("{} pre-built exec is {} bytes", name, exec_file.metadata().unwrap().len());
paths.push(exec_name);
}
}
Ok(paths)
@ -1047,11 +1026,8 @@ impl Builder {
fn enumerate_binary_files(&self) -> Result<Vec<String>, DynError> {
let mut paths = Vec::<String>::new();
for item in [&self.services[..], &self.apps[..]].concat() {
match item {
CrateSpec::BinaryFile(_name, path, _region) => {
paths.push(path);
}
_ => {}
if let CrateSpec::BinaryFile(_name, path, _region) = item {
paths.push(path);
}
}
Ok(paths)
@ -1075,7 +1051,7 @@ impl Builder {
.truncate(true)
.open("locales/src/locale.rs")
.expect("Can't open locale for modification");
write!(locale_override, "pub const LANG: &str = \"{}\";\n", locale).unwrap();
writeln!(locale_override, "pub const LANG: &str = \"{}\";", locale).unwrap();
}
}

View file

@ -31,7 +31,7 @@ const PRECURSOR_SOC_VERSION: &str = "pvt";
Backups older than this cannot be parsed because the migration code for that backup
was deprecated. The main purpose of this field is to assist the restore script
in selecting a kernel: it will automatically downgrade a kernel as far as it must
to read a very old backup. This tag is *not* useful for enforcing a minimum
read a very old backup. This tag is *not* useful for enforcing a minimum
version of the kernel to read a very *new* backup.
Instead, when picking a kernel to restore from, the latest kernel should always be picked,
@ -118,11 +118,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// ---- extract position independent args ----
let loader_key = get_flag("--lkey")?;
if loader_key.len() != 0 {
if !loader_key.is_empty() {
builder.loader_key_file(loader_key[0].to_string());
}
let kernel_key = get_flag("--kkey")?;
if kernel_key.len() != 0 {
if !kernel_key.is_empty() {
builder.kernel_key_file(kernel_key[0].to_string());
}
let swap_key = get_flag("--swap")?;
@ -209,36 +209,24 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
// ----- renode configs --------
Some("renode-image") => {
builder
.target_renode()
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_apps(&get_cratespecs());
builder.target_renode().add_services(&user_pkgs).add_apps(&get_cratespecs());
}
Some("renode-image-debug") => {
builder
.target_renode()
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_services(&user_pkgs)
.stream(BuildStream::Debug)
.add_apps(&get_cratespecs());
}
Some("renode-test") => {
builder
.target_renode()
.add_services(&base_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
builder.target_renode().add_services(&base_pkgs).add_services(&get_cratespecs());
}
Some("libstd-test") => {
builder
.target_renode()
.add_services(&base_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
builder.target_renode().add_services(&base_pkgs).add_services(&get_cratespecs());
builder.add_loader_feature("renode-bypass");
}
Some("libstd-net") => {
builder
.target_renode()
.add_services(&base_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
builder.target_renode().add_services(&base_pkgs).add_services(&get_cratespecs());
builder.add_loader_feature("renode-bypass").add_loader_feature("renode-minimal");
builder
.add_service("net", LoaderRegion::Ram)
@ -247,16 +235,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.add_service("dns", LoaderRegion::Ram);
}
Some("renode-aes-test") => {
builder
.target_renode()
.add_services(&aes_test_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
builder.target_renode().add_services(&aes_test_pkgs).add_services(&get_cratespecs());
}
Some("ffi-test") => {
builder
.target_renode()
.add_services(&gfx_base_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
builder.target_renode().add_services(&gfx_base_pkgs).add_services(&get_cratespecs());
builder.add_service("ffi-test", LoaderRegion::Ram);
builder.add_loader_feature("renode-bypass");
}
@ -280,7 +262,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("run") => {
builder
.target_hosted()
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_services(&user_pkgs)
.add_feature("pddbtest")
.add_feature("ditherpunk")
.add_feature("tracking-alloc")
@ -291,14 +273,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("pddb-ci") => {
builder
.target_hosted()
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_services(&user_pkgs)
.add_feature("pddb/ci")
.add_feature("pddb/deterministic");
}
Some("pddb-btest") => {
builder
.target_hosted()
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_services(&user_pkgs)
.add_feature("pddbtest")
.add_feature("autobasis") // this will make secret basis tracking synthetic and automated for stress testing
.add_feature("autobasis-ci")
@ -307,7 +289,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("hosted-debug") => {
builder
.target_hosted()
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_services(&user_pkgs)
.add_feature("pddbtest")
.add_feature("ditherpunk")
.add_feature("tracking-alloc")
@ -318,30 +300,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("gfx-dev") => {
builder
.target_hosted()
.add_services(&gfx_base_pkgs.into_iter().map(String::from).collect())
.add_services(&gfx_base_pkgs)
.add_services(&get_cratespecs())
.add_feature("graphics-server/gfx-testing");
}
Some("hosted-ci") => {
builder
.target_hosted()
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.hosted_build_only()
.add_apps(&get_cratespecs());
builder.target_hosted().add_services(&user_pkgs).hosted_build_only().add_apps(&get_cratespecs());
}
// ------ Precursor hardware image configs ------
Some("app-image") => {
builder
.target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_services(&user_pkgs)
.add_feature("mass-storage") // add this in by default to help with testing
.add_apps(&get_cratespecs());
}
Some("app-image-xip") => {
builder
.target_precursor(PRECURSOR_SOC_VERSION)
//.add_services(&user_pkgs.into_iter().map(String::from).collect())
//.add_services(&user_pkgs)
.add_feature("mass-storage"); // add this in by default to help with testing
for service in user_pkgs {
if (service != "shellchat") && (service != "ime-plugin-shell" && (service != "net")) {
@ -371,7 +349,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// by the usb_update script.
builder
.target_precursor("c809403-perflib")
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_services(&user_pkgs)
.add_apps(&get_cratespecs())
.add_feature("perfcounter")
.add_kernel_feature("v2p");
@ -399,7 +377,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
pkgs.push("ime-plugin-tts");
pkgs.retain(|&pkg| pkg != "ime-plugin-shell");
builder.add_services(&pkgs.into_iter().map(String::from).collect())
builder.add_services(&pkgs)
.add_apps(&get_cratespecs())
.add_service("espeak-embedded#https://ci.betrusted.io/job/espeak-embedded/lastSuccessfulBuild/artifact/target/riscv32imac-unknown-xous-elf/release/espeak-embedded",
LoaderRegion::Ram)
@ -410,13 +388,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("tiny") => {
builder
.target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&base_pkgs.into_iter().map(String::from).collect())
.add_services(&base_pkgs)
.add_services(&get_cratespecs());
}
Some("usbdev") => {
builder
.target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&base_pkgs.into_iter().map(String::from).collect())
.add_services(&base_pkgs)
.add_services(&get_cratespecs());
//builder.add_service("usb-test");
builder.add_service("usb-device-xous", LoaderRegion::Ram);
@ -424,31 +402,29 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("pddb-dev") => {
builder
.target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&pddb_dev_pkgs.into_iter().map(String::from).collect())
.add_services(&pddb_dev_pkgs)
.add_services(&get_cratespecs());
}
Some("trng-test") => {
builder
.target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_services(&user_pkgs)
.add_feature("urandomtest");
}
Some("ro-test") => {
builder
.target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_services(&user_pkgs)
.add_feature("ringosctest");
}
Some("av-test") => {
builder
.target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_services(&user_pkgs)
.add_feature("avalanchetest");
}
Some("compile-apps") => {
builder
.target_precursor_no_image(PRECURSOR_SOC_VERSION)
.add_services(&gfx_base_pkgs.into_iter().map(String::from).collect());
builder.target_precursor_no_image(PRECURSOR_SOC_VERSION).add_services(&gfx_base_pkgs);
}
// ------ Cramium hardware image configs ------
@ -473,11 +449,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("arm-tiny") => {
builder
.target_arm()
.add_services(&vec![
"xous-log".to_string(),
"xous-ticktimer".to_string(),
"xous-names".to_string(),
"ticktimer-test-client".to_string(),
.add_services([
"xous-log",
"xous-ticktimer",
"xous-names",
"ticktimer-test-client",
])
.add_kernel_feature("v2p") // required to use LCD DMA with lcd-console
.add_feature("atsama5d27")

View file

@ -82,7 +82,7 @@ fn get_sysroot(target: Option<&str>, check_version: bool) -> Result<Option<Strin
version_path.push("RUST_VERSION");
if let Ok(mut vp) = File::open(&version_path) {
let mut version_str = String::new();
if let Err(_) = vp.read_to_string(&mut version_str) {
if vp.read_to_string(&mut version_str).is_err() {
return Err("Unable to get version string".to_owned());
}
@ -102,10 +102,8 @@ fn get_sysroot(target: Option<&str>, check_version: bool) -> Result<Option<Strin
// return Err("Outdated toolchain installed".to_owned());
return Ok(None);
}
} else {
if !std::path::Path::new(&version_path).exists() {
return Ok(None);
}
} else if !Path::new(&version_path).exists() {
return Ok(None);
}
}
@ -145,7 +143,7 @@ pub(crate) fn ensure_kernel_compiler(target: &Option<&str>, force_install: bool)
let rustup_command = Command::new("rustup")
.stderr(Stdio::null())
.stdout(Stdio::piped())
.args(&["target", "add", target])
.args(["target", "add", target])
.spawn()
.map_err(|e| format!("could not run rustup: {}", e))?;
@ -184,7 +182,7 @@ pub(crate) fn ensure_compiler(
if remove_existing {
println!("Target path exists, removing it");
std::fs::remove_dir_all(version_path)
.or_else(|e| Err(format!("unable to remove existing toolchain: {}", e)))?;
.map_err(|e| format!("unable to remove existing toolchain: {}", e))?;
println!("Also removing target directories for existing toolchain");
let mut target_main = project_root();
target_main.push("target");
@ -234,7 +232,7 @@ pub(crate) fn ensure_compiler(
let url = TOOLCHAIN_RELEASE_URLS
.get(target)
.ok_or_else(|| format!("Can't find toolchain URL for target {}", target))?;
let j: serde_json::Value = ureq::get(&url)
let j: serde_json::Value = ureq::get(url)
.set("Accept", "application/vnd.github.v3+json")
.call()
.map_err(|e| format!("{}", e))?
@ -272,7 +270,7 @@ pub(crate) fn ensure_compiler(
},
};
let first_asset = match assets.get(0) {
let first_asset = match assets.first() {
None => continue,
Some(s) => s,
};
@ -313,7 +311,7 @@ pub(crate) fn ensure_compiler(
/// Extract the zipfile to the target directory, ensuring that all files
/// contained within are created.
fn extract_zip<P: std::io::Read + std::io::Seek, P2: AsRef<Path>>(
fn extract_zip<P: Read + std::io::Seek, P2: AsRef<Path>>(
archive_data: P,
extract_to: P2,
) -> Result<(), String> {
@ -335,12 +333,12 @@ pub(crate) fn ensure_compiler(
// Create the parent directory if necessary
if let Some(parent) = output_path.parent() {
if !parent.exists() {
std::fs::create_dir_all(&parent).map_err(|e| {
std::fs::create_dir_all(parent).map_err(|e| {
format!("unable to create directory {}: {}", output_path.display(), e)
})?;
}
}
let mut outfile = std::fs::File::create(&output_path)
let mut outfile = File::create(&output_path)
.map_err(|e| format!("unable to create file {}: {}", output_path.display(), e))?;
std::io::copy(&mut entry_in_archive, &mut outfile).map_err(|e| {
format!("unable to write extracted file {}: {}", output_path.display(), e)
@ -364,11 +362,11 @@ pub(crate) fn generate_locales() -> Result<(), std::io::Error> {
filetime::set_file_mtime("locales/src/lib.rs", ts)?;
let mut path = project_root();
path.push("locales");
let status = Command::new(cargo()).current_dir(path).args(&["build", "--package", "locales"]).status()?;
let status = Command::new(cargo()).current_dir(path).args(["build", "--package", "locales"]).status()?;
if !status.success() {
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Couldn't generate the locales"));
}
return Ok(());
Ok(())
}
/// Import the Wycheproof test vectors
@ -377,7 +375,7 @@ pub(crate) fn wycheproof_import() -> Result<(), crate::DynError> {
let output_file = "services/shellchat/src/cmds/x25519_test.bin";
let status = Command::new(cargo())
.current_dir(project_root())
.args(&["run", "--package", "wycheproof-import", "--", input_file, output_file])
.args(["run", "--package", "wycheproof-import", "--", input_file, output_file])
.status()?;
if !status.success() {
return Err("wycheproof-import failed. If any, the output will not be usable.".into());
@ -386,23 +384,23 @@ pub(crate) fn wycheproof_import() -> Result<(), crate::DynError> {
println!();
println!("Wrote wycheproof x25519 testvectors to '{}'.", output_file);
return Ok(());
Ok(())
}
pub(crate) fn track_language_changes(last_lang: &str) -> Result<(), crate::DynError> {
let last_config = "target/LAST_LANG";
let mut contents = String::new();
let changed = match OpenOptions::new().read(true).open(&last_config) {
let changed = match OpenOptions::new().read(true).open(last_config) {
Ok(mut file) => {
file.read_to_string(&mut contents).unwrap();
if contents != last_lang { true } else { false }
contents != last_lang
}
_ => true,
};
if changed {
println!("Locale language changed to {}", last_lang);
let mut file = OpenOptions::new().create(true).write(true).truncate(true).open(&last_config).unwrap();
let mut file = OpenOptions::new().create(true).write(true).truncate(true).open(last_config).unwrap();
write!(file, "{}", last_lang).unwrap();
generate_locales()?
} else {

View file

@ -53,7 +53,7 @@ pub fn verify(spec: CrateSpec, hard_failure: bool) -> Result<(), DynError> {
cache_leaf.push_str(&regdir);
}
}
if cache_leaf.len() == 0 {
if cache_leaf.is_empty() {
return Err("Can't find expected registry source location".into());
}
// this now has the path to the cache directory
@ -79,20 +79,18 @@ pub fn verify(spec: CrateSpec, hard_failure: bool) -> Result<(), DynError> {
&& name != "svd2utra"
{
Path::new(&subdir)
} else if name == "xous" {
Path::new("./xous-rs")
} else if name == "xous-ipc" {
Path::new("./xous-ipc")
} else if name == "xous-kernel" {
Path::new("./kernel")
} else if name == "utralib" {
Path::new("./utralib")
} else if name == "svd2utra" {
Path::new("./svd2utra")
} else {
if name == "xous" {
Path::new("./xous-rs")
} else if name == "xous-ipc" {
Path::new("./xous-ipc")
} else if name == "xous-kernel" {
Path::new("./kernel")
} else if name == "utralib" {
Path::new("./utralib")
} else if name == "svd2utra" {
Path::new("./svd2utra")
} else {
panic!("Consistency error: special case handling did not find either xous or xous-ipc");
}
panic!("Consistency error: special case handling did not find either xous or xous-ipc");
};
// now recurse through the source path and check that it matches the cache, except for Cargo.toml

View file

@ -1,5 +1,5 @@
// Versioning infrastructure
// This generates the SEMVER data that is displayed when quering `xous ver`
// This generates the SEMVER data that is displayed when querying `xous ver`
// It also generates timestamps, if demanded.
use std::fs::OpenOptions;
@ -46,10 +46,10 @@ pub(crate) fn generate_version(add_timestamp: bool) {
write!(new_data, "#[allow(dead_code)]\npub const TIMESTAMP: &'static str = \"unavailable\";\n")
.expect("couldn't add our timestamp");
}
write!(
writeln!(
new_data,
"pub const SEMVER: &'static str = \"{}\";\n",
semver.strip_suffix("\r\n").or(semver.strip_suffix("\n")).unwrap_or(&semver)
"pub const SEMVER: &'static str = \"{}\";",
semver.strip_suffix("\r\n").or(semver.strip_suffix('\n')).unwrap_or(&semver)
)
.expect("couldn't add our semver");
@ -61,7 +61,7 @@ pub(crate) fn generate_version(add_timestamp: bool) {
.truncate(true)
.open(version_file)
.expect("Can't open our version file for writing");
vfile.write_all(&mut new_data).expect("couldn't write new timestamp to version.rs");
vfile.write_all(&new_data).expect("couldn't write new timestamp to version.rs");
}
}