From 6cb835a47e52105d8fb6739c567b6eb38ae1bd5b Mon Sep 17 00:00:00 2001 From: GabMus Date: Tue, 15 Aug 2023 15:31:36 +0000 Subject: [PATCH] feat: add format check to ci --- .gitlab-ci.yml | 13 ++++++++++++ src/adb.rs | 10 +++++---- src/builders/mod.rs | 8 +++---- src/dependencies/basalt_deps.rs | 2 +- src/dependencies/libsurvive_deps.rs | 2 +- src/dependencies/mercury_deps.rs | 2 +- src/dependencies/mod.rs | 10 ++++----- src/device_prober.rs | 4 +--- src/downloader.rs | 2 +- src/env_var_descriptions.rs | 6 ++++-- src/file_builders/mod.rs | 2 +- src/file_builders/openvrpaths_vrpath.rs | 4 +++- src/file_utils.rs | 7 +++++-- src/log_level.rs | 15 +++++++------ src/main.rs | 6 +++--- src/paths.rs | 2 +- src/profiles/mod.rs | 6 +++--- src/runner_pipeline.rs | 12 ++++++----- src/ui/about_dialog.rs | 2 +- src/ui/build_window.rs | 6 ++---- src/ui/main_view.rs | 24 ++++++++++++++------- src/ui/mod.rs | 28 ++++++++++++------------- src/ui/preference_rows.rs | 2 +- src/ui/wivrn_conf_editor.rs | 18 +++++++++------- src/xr_devices.rs | 10 +++++++-- 25 files changed, 122 insertions(+), 81 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f2ae124..16c0f50 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,9 +1,22 @@ image: "debian:testing" stages: + - check - test - deploy +cargo:fmtcheck: + image: "rust:slim" + stage: check + script: + - rustup component add rustfmt + # Create blank versions of our configured files + # so rustfmt does not yell about non-existent files or completely empty files + - echo -e "" >> src/constants.rs + - rustc -Vv && cargo -Vv + - cargo fmt --version + - cargo fmt --all -- --check + cargo:test: stage: test script: diff --git a/src/adb.rs b/src/adb.rs index 659e233..f1fe7ed 100644 --- a/src/adb.rs +++ b/src/adb.rs @@ -1,11 +1,13 @@ -use std::path::Path; use crate::runner::Runner; +use std::path::Path; pub fn get_adb_install_runner(apk_path: &String) -> Runner { let path = Path::new(apk_path); path.try_exists().expect("APK file provided does not exist"); - let runner = Runner::new(None, "adb".into(), vec![ - "install".into(), path.to_str().unwrap().to_string() - ]); + let runner = Runner::new( + None, + "adb".into(), + vec!["install".into(), path.to_str().unwrap().to_string()], + ); runner } diff --git a/src/builders/mod.rs b/src/builders/mod.rs index 2fc9c68..03f25aa 100644 --- a/src/builders/mod.rs +++ b/src/builders/mod.rs @@ -1,6 +1,6 @@ -pub mod build_monado; -pub mod build_libsurvive; -pub mod build_opencomposite; pub mod build_basalt; -pub mod build_wivrn; +pub mod build_libsurvive; pub mod build_mercury; +pub mod build_monado; +pub mod build_opencomposite; +pub mod build_wivrn; diff --git a/src/dependencies/basalt_deps.rs b/src/dependencies/basalt_deps.rs index 93b5be3..678392d 100644 --- a/src/dependencies/basalt_deps.rs +++ b/src/dependencies/basalt_deps.rs @@ -1,4 +1,4 @@ -use crate::depcheck::{check_dependencies, Dependency, DependencyCheckResult, DepType}; +use crate::depcheck::{check_dependencies, DepType, Dependency, DependencyCheckResult}; fn basalt_deps() -> Vec { vec![ diff --git a/src/dependencies/libsurvive_deps.rs b/src/dependencies/libsurvive_deps.rs index d46ef25..b209ee0 100644 --- a/src/dependencies/libsurvive_deps.rs +++ b/src/dependencies/libsurvive_deps.rs @@ -1,4 +1,4 @@ -use crate::depcheck::{Dependency, DepType, check_dependencies, DependencyCheckResult}; +use crate::depcheck::{check_dependencies, DepType, Dependency, DependencyCheckResult}; fn libsurvive_deps() -> Vec { vec![ diff --git a/src/dependencies/mercury_deps.rs b/src/dependencies/mercury_deps.rs index bc799ee..b788e9c 100644 --- a/src/dependencies/mercury_deps.rs +++ b/src/dependencies/mercury_deps.rs @@ -1,4 +1,4 @@ -use crate::depcheck::{Dependency, DepType, DependencyCheckResult, check_dependencies}; +use crate::depcheck::{check_dependencies, DepType, Dependency, DependencyCheckResult}; fn mercury_deps() -> Vec { vec![ diff --git a/src/dependencies/mod.rs b/src/dependencies/mod.rs index 0e095ac..751c939 100644 --- a/src/dependencies/mod.rs +++ b/src/dependencies/mod.rs @@ -1,7 +1,7 @@ -pub mod monado_deps; -pub mod libsurvive_deps; -pub mod basalt_deps; -pub mod wivrn_deps; pub mod adb_dep; -pub mod pkexec_dep; +pub mod basalt_deps; +pub mod libsurvive_deps; pub mod mercury_deps; +pub mod monado_deps; +pub mod pkexec_dep; +pub mod wivrn_deps; diff --git a/src/device_prober.rs b/src/device_prober.rs index 092b894..9da96de 100644 --- a/src/device_prober.rs +++ b/src/device_prober.rs @@ -2,9 +2,7 @@ use std::fmt::Display; use crate::{ profile::Profile, - profiles::{ - lighthouse::lighthouse_profile, wivrn::wivrn_profile, - }, + profiles::{lighthouse::lighthouse_profile, wivrn::wivrn_profile}, }; #[derive(Debug, PartialEq, Eq)] diff --git a/src/downloader.rs b/src/downloader.rs index bbd5d2f..aeb3dd3 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -43,7 +43,7 @@ pub fn download_file(url: String, path: String) -> JoinHandle Err(e) + Err(e) => Err(e), } }) } diff --git a/src/env_var_descriptions.rs b/src/env_var_descriptions.rs index 4e6c557..e31ad4c 100644 --- a/src/env_var_descriptions.rs +++ b/src/env_var_descriptions.rs @@ -18,7 +18,9 @@ pub static ENV_VAR_DESCRIPTIONS: Map<&str, &str> = phf_map! { }; pub fn env_var_descriptions_as_paragraph() -> String { - ENV_VAR_DESCRIPTIONS.into_iter() + ENV_VAR_DESCRIPTIONS + .into_iter() .map(|(k, v)| format!("{}: {}", k, v)) - .collect::>().join("\n\n") + .collect::>() + .join("\n\n") } diff --git a/src/file_builders/mod.rs b/src/file_builders/mod.rs index 24f87e0..ab8ccfc 100644 --- a/src/file_builders/mod.rs +++ b/src/file_builders/mod.rs @@ -1,4 +1,4 @@ pub mod active_runtime_json; +pub mod monado_autorun; pub mod openvrpaths_vrpath; pub mod wivrn_config; -pub mod monado_autorun; diff --git a/src/file_builders/openvrpaths_vrpath.rs b/src/file_builders/openvrpaths_vrpath.rs index da5533a..0ce3983 100644 --- a/src/file_builders/openvrpaths_vrpath.rs +++ b/src/file_builders/openvrpaths_vrpath.rs @@ -125,7 +125,9 @@ pub fn set_current_openvrpaths_to_profile(profile: &Profile) -> Result<(), ()> { let dest = get_openvrpaths_vrpath_path(); checkerr!(set_file_readonly(&dest, false)); backup_steam_openvrpaths(); - checkerr!(dump_current_openvrpaths(&build_profile_openvrpaths(profile))); + checkerr!(dump_current_openvrpaths(&build_profile_openvrpaths( + profile + ))); checkerr!(set_file_readonly(&dest, true)); Ok(()) } diff --git a/src/file_utils.rs b/src/file_utils.rs index 6fcb9b8..4be5a43 100644 --- a/src/file_utils.rs +++ b/src/file_utils.rs @@ -1,5 +1,8 @@ use crate::runner::Runner; -use nix::{sys::statvfs::{statvfs, FsFlags}, errno::Errno}; +use nix::{ + errno::Errno, + sys::statvfs::{statvfs, FsFlags}, +}; use std::{ fs::{self, copy, create_dir_all, remove_dir_all, File, OpenOptions}, io::{BufReader, BufWriter}, @@ -102,7 +105,7 @@ pub fn mount_has_nosuid(path_s: &str) -> Result { let path = Path::new(path_s); match statvfs(path) { Ok(fstats) => Ok(fstats.flags().contains(FsFlags::ST_NOSUID)), - Err(e) => Err(e) + Err(e) => Err(e), } } diff --git a/src/log_level.rs b/src/log_level.rs index b2fc926..375b28e 100644 --- a/src/log_level.rs +++ b/src/log_level.rs @@ -21,22 +21,25 @@ impl<'de> Visitor<'de> for LogLevelStringVisitor { } fn visit_borrowed_str(self, v: &'de str) -> Result - where - E: serde::de::Error, { + where + E: serde::de::Error, + { Ok(LogLevel::from_string(v.to_string())) } fn visit_string(self, v: String) -> Result - where - E: serde::de::Error, { + where + E: serde::de::Error, + { Ok(LogLevel::from_string(v)) } } impl<'de> Deserialize<'de> for LogLevel { fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de> { + where + D: serde::Deserializer<'de>, + { deserializer.deserialize_string(LogLevelStringVisitor) } } diff --git a/src/main.rs b/src/main.rs index b259a1d..b7dbb69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,9 @@ use relm4::{ use ui::app::{App, AppInit}; pub mod adb; +pub mod build_tools; pub mod builders; +pub mod checkerr; pub mod config; pub mod constants; pub mod depcheck; @@ -30,11 +32,9 @@ pub mod profile; pub mod profiles; pub mod runner; pub mod runner_pipeline; +pub mod steamvr_utils; pub mod ui; pub mod xr_devices; -pub mod build_tools; -pub mod checkerr; -pub mod steamvr_utils; fn restore_steam_xr_files() { let active_runtime = get_current_active_runtime(); diff --git a/src/paths.rs b/src/paths.rs index 618b83e..cfbdfb9 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -1,5 +1,5 @@ -use std::{env, path::Path, fs::create_dir_all}; use crate::constants::CMD_NAME; +use std::{env, fs::create_dir_all, path::Path}; pub fn data_opencomposite_path() -> String { format!("{data}/opencomposite", data = get_data_dir()) diff --git a/src/profiles/mod.rs b/src/profiles/mod.rs index f9550b0..1f9b3c3 100644 --- a/src/profiles/mod.rs +++ b/src/profiles/mod.rs @@ -1,4 +1,4 @@ -pub mod valve_index; -pub mod system_valve_index; -pub mod wivrn; pub mod lighthouse; +pub mod system_valve_index; +pub mod valve_index; +pub mod wivrn; diff --git a/src/runner_pipeline.rs b/src/runner_pipeline.rs index 060b410..6e1c66c 100644 --- a/src/runner_pipeline.rs +++ b/src/runner_pipeline.rs @@ -35,7 +35,9 @@ impl RunnerPipeline { } self.has_started = true; match self.get_current_runner() { - None => { return; }, + None => { + return; + } Some(runner) => { runner.borrow_mut().start(); } @@ -48,7 +50,7 @@ impl RunnerPipeline { } match self.get_current_runner() { - None => {}, + None => {} Some(c_runner) => { let (status, log) = { let mut runner = c_runner.borrow_mut(); @@ -56,7 +58,7 @@ impl RunnerPipeline { }; self.log.extend(log); match status { - RunnerStatus::Running => {}, + RunnerStatus::Running => {} RunnerStatus::Stopped(ecode) => { match ecode { None => {} // should never get here @@ -64,7 +66,7 @@ impl RunnerPipeline { self.last_exit_status = Some(0); self.current_index += 1; match self.get_current_runner() { - None => {}, + None => {} Some(c_runner) => { c_runner.borrow_mut().start(); } @@ -91,7 +93,7 @@ impl RunnerPipeline { pub fn status(&self) -> RunnerStatus { match self.get_current_runner() { None => RunnerStatus::Stopped(self.last_exit_status), - Some(_) => RunnerStatus::Running + Some(_) => RunnerStatus::Running, } } } diff --git a/src/ui/about_dialog.rs b/src/ui/about_dialog.rs index da8ffb0..0445c93 100644 --- a/src/ui/about_dialog.rs +++ b/src/ui/about_dialog.rs @@ -1,4 +1,4 @@ -use crate::constants::{get_developers, APP_NAME, REPO_URL, SINGLE_DEVELOPER, VERSION, APP_ID}; +use crate::constants::{get_developers, APP_ID, APP_NAME, REPO_URL, SINGLE_DEVELOPER, VERSION}; use relm4::gtk::traits::GtkWindowExt; use relm4::prelude::*; use relm4::{ComponentParts, SimpleComponent}; diff --git a/src/ui/build_window.rs b/src/ui/build_window.rs index 50c06bb..32f194a 100644 --- a/src/ui/build_window.rs +++ b/src/ui/build_window.rs @@ -149,10 +149,8 @@ impl SimpleComponent for BuildWindow { let mut n_content = self.content.clone(); n_content.push_str(n_lines.as_str()); self.set_content(n_content); - self.textbuf.insert( - &mut self.textbuf.end_iter(), - n_lines.as_str() - ); + self.textbuf + .insert(&mut self.textbuf.end_iter(), n_lines.as_str()); let textbuf = self.textbuf.clone(); let textview = self.textview.as_ref().unwrap().clone(); if is_at_bottom { diff --git a/src/ui/main_view.rs b/src/ui/main_view.rs index 065a4cc..6e32734 100644 --- a/src/ui/main_view.rs +++ b/src/ui/main_view.rs @@ -409,10 +409,14 @@ impl SimpleComponent for MainView { .emit(InstallWivrnBoxMsg::ClockTicking); } Self::Input::StartStopClicked => { - sender.output(Self::Output::DoStartStopXRService).expect("Sender output failed"); + sender + .output(Self::Output::DoStartStopXRService) + .expect("Sender output failed"); } Self::Input::RestartXRService => { - sender.output(Self::Output::RestartXRService).expect("Sender output failed"); + sender + .output(Self::Output::RestartXRService) + .expect("Sender output failed"); } Self::Input::XRServiceActiveChanged(active, profile) => { self.set_xrservice_active(active); @@ -473,9 +477,11 @@ impl SimpleComponent for MainView { self.set_selected_profile(self.profiles.get(index as usize).unwrap().clone()); } Self::Input::ProfileSelected(position) => { - sender.output(MainViewOutMsg::ProfileSelected( - self.profiles.get(position as usize).unwrap().clone(), - )).expect("Sender output failed"); + sender + .output(MainViewOutMsg::ProfileSelected( + self.profiles.get(position as usize).unwrap().clone(), + )) + .expect("Sender output failed"); } Self::Input::EditProfile => { if self.selected_profile.editable { @@ -500,7 +506,9 @@ impl SimpleComponent for MainView { self.profile_delete_confirm_dialog.present(); } Self::Input::SaveProfile(prof) => { - sender.output(Self::Output::SaveProfile(prof)).expect("Sender output failed"); + sender + .output(Self::Output::SaveProfile(prof)) + .expect("Sender output failed"); } Self::Input::DuplicateProfile => { if self.selected_profile.can_be_built { @@ -570,7 +578,9 @@ impl SimpleComponent for MainView { let pdc_sender = sender.clone(); profile_delete_confirm_dialog.connect_response(None, move |_, res| { if res == "yes" { - pdc_sender.output(Self::Output::DeleteProfile).expect("Sender output failed"); + pdc_sender + .output(Self::Output::DeleteProfile) + .expect("Sender output failed"); } }); } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index feef1da..81adc39 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,16 +1,16 @@ -pub mod app; -pub mod main_view; pub mod about_dialog; -pub mod debug_view; -pub mod build_window; -pub mod libsurvive_setup_window; -pub mod install_wivrn_box; -pub mod steam_launch_options_box; -pub mod profile_editor; -pub mod factories; -pub mod wivrn_conf_editor; -pub mod devices_box; -pub mod preference_rows; -pub mod macros; -pub mod util; pub mod alert; +pub mod app; +pub mod build_window; +pub mod debug_view; +pub mod devices_box; +pub mod factories; +pub mod install_wivrn_box; +pub mod libsurvive_setup_window; +pub mod macros; +pub mod main_view; +pub mod preference_rows; +pub mod profile_editor; +pub mod steam_launch_options_box; +pub mod util; +pub mod wivrn_conf_editor; diff --git a/src/ui/preference_rows.rs b/src/ui/preference_rows.rs index f3e8ed5..959c836 100644 --- a/src/ui/preference_rows.rs +++ b/src/ui/preference_rows.rs @@ -132,7 +132,7 @@ pub fn path_row) + 'static + Clone>( row } -pub fn combo_row( +pub fn combo_row( title: &str, description: Option<&str>, value: &str, diff --git a/src/ui/wivrn_conf_editor.rs b/src/ui/wivrn_conf_editor.rs index 4b4b718..3c6bd3e 100644 --- a/src/ui/wivrn_conf_editor.rs +++ b/src/ui/wivrn_conf_editor.rs @@ -1,4 +1,6 @@ -use crate::file_builders::wivrn_config::{dump_wivrn_config, get_wivrn_config, WivrnConfig, Encoder}; +use crate::file_builders::wivrn_config::{ + dump_wivrn_config, get_wivrn_config, Encoder, WivrnConfig, +}; use adw::prelude::*; use relm4::prelude::*; @@ -125,13 +127,15 @@ impl SimpleComponent for WivrnConfEditor { let scalex = self.scalex_entry.as_ref().unwrap().text().parse::(); let scaley = self.scaley_entry.as_ref().unwrap().text().parse::(); if scalex.is_ok() && scaley.is_ok() { - self.conf.scale = Some([scalex.as_ref().unwrap().clone(), scaley.as_ref().unwrap().clone()]); + self.conf.scale = Some([ + scalex.as_ref().unwrap().clone(), + scaley.as_ref().unwrap().clone(), + ]); } if scalex.is_ok() || scaley.is_ok() { let scale = scalex.unwrap_or(scaley.unwrap()); self.conf.scale = Some([scale, scale]); - } - else { + } else { self.conf.scale = None } @@ -141,14 +145,12 @@ impl SimpleComponent for WivrnConfEditor { enc.bitrate = Some(bitrate.unwrap()); } let encoders = Encoder::as_vec(); - let encoder = encoders.get( - self.encoder_combo.as_ref().unwrap().selected() as usize - ); + let encoder = + encoders.get(self.encoder_combo.as_ref().unwrap().selected() as usize); if encoder.is_some() { enc.encoder = encoder.unwrap().clone(); } self.conf.encoders.insert(0, enc); - dump_wivrn_config(&self.conf); self.win.as_ref().unwrap().close(); diff --git a/src/xr_devices.rs b/src/xr_devices.rs index a1b4b95..4b7ba8e 100644 --- a/src/xr_devices.rs +++ b/src/xr_devices.rs @@ -1,6 +1,12 @@ #[derive(Debug, Clone, PartialEq, Eq)] pub enum XRDevice { - Head, Left, Right, Gamepad, Eyes, HandTrackingLeft, HandTrackingRight + Head, + Left, + Right, + Gamepad, + Eyes, + HandTrackingLeft, + HandTrackingRight, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -43,7 +49,7 @@ impl XRDevices { break; } match row.trim().split(": ").collect::>()[..] { - [_, ""] => {}, + [_, ""] => {} ["head", val] => devs.head = Some(val.to_string()), ["left", val] => devs.left = Some(val.to_string()), ["right", val] => devs.right = Some(val.to_string()),