Skip to content

Commit

Permalink
Specified more values in toolchain file (#8)
Browse files Browse the repository at this point in the history
* Specified more values in toolchain file

* fixed clippy errors and suppressed the placeholders

* fmt

* fixed pre releease for aarch64-unknown-linux-gnu

* implemented config loading. NOTE: need to specify non-linux systems

* Update rust-toolchain.toml

---------

Co-authored-by: shivanandvp <[email protected]>
  • Loading branch information
FerrisWasTaken and pvshvp-oss authored Mar 8, 2024
1 parent 72b7a9d commit 0f0c20d
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pre_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ jobs:
with:
name: ${{ matrix.target }} Unstable
path: output
- name: Install dependencies
id: install_dependencies
run: apt-get install libssl-dev openssl
- name: 🖩 Generate CheckSum
id: generate_checksum_step
run: |
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "1"
members = [
"paxy",
"paxy_build", "paxy_install",
Expand Down
2 changes: 2 additions & 0 deletions paxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ categories = ["development-tools::build-utils", "command-line-utilities"]

[dependencies]
clap = { version = "4.0", features = ["derive", "help"] }
home = "0.5.9"
pollster = "0.3"
reqwest = "0.11"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
snafu = "0.7"
toml = "0.8.10"
url = { version = "2.3", features = ["serde"] }
69 changes: 62 additions & 7 deletions paxy/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,72 @@
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::{
fs::{self, create_dir_all, File}, io::Write, path::PathBuf
};
use url::Url;

#[derive(Default, Serialize, Deserialize)]
#[derive(Serialize, Deserialize)]
pub struct Config {
pub repositories: Vec<Url>,
pub system_install_location: Option<PathBuf>,
pub user_install_location: Option<PathBuf>,
pub default_install_type: Option<InstallType>,
pub repositories: Option<Vec<Url>>,
pub system_install_location: PathBuf,
pub user_install_location: PathBuf,
pub default_install_type: InstallType,
}

#[derive(Serialize, Deserialize)]
impl Default for Config {
fn default() -> Self {
let mut user: PathBuf = match home::home_dir() {
Some(path) => path,
None => panic!("Impossible to get your home dir!"),
};
user.push(".paxy");
user.push("pkgs");
let system = if cfg!(linux) {
PathBuf::from("/")
} else {
PathBuf::from("")
};

let conf = Config {
repositories: Some(vec![
Url::parse("https://github.com/Pax-Hub/Packages.git").unwrap()
]),
user_install_location: user.clone(), // Not harmful since the value is dropped in the very next line
system_install_location: system,
default_install_type: InstallType::default(),
};
if !user.is_dir() {
create_dir_all(user.clone()).expect("No permission"); // Not harmful since the value is dropped in the soon
user.pop();
user.push("config.ini");
if user.is_file() {
fs::remove_file(user.clone()).unwrap();
}
if !user.is_file() {
let mut file = File::create(user).unwrap();
file.write_all(toml::to_string(&conf).unwrap().as_bytes()).expect("Permission error");
}
}
conf
}
}

#[derive(Serialize, Deserialize, Default)]
pub enum InstallType {
User,
#[default]
System,
}

#[allow(dead_code)]
fn load_conf() -> Config {
let mut conf_path: PathBuf = match home::home_dir() {
Some(path) => path,
None => panic!("Impossible to get your home dir!"),
};
conf_path.push(".paxy");
conf_path.push("config.ini");
match toml::from_str::<Config>(fs::read_to_string(&conf_path).unwrap().as_str()) {
Ok(val) => val,
Err(_) => Config::default()
}
}
2 changes: 1 addition & 1 deletion paxy_build/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod package;
pub mod package;
13 changes: 6 additions & 7 deletions paxy_build/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ use snafu::prelude::*;
use std::{fmt::Display, path::PathBuf, str::FromStr};
use url::Url;

#[cfg(feature = "nested_sources")]
pub use nested_sources::*;

lazy_static! {
static ref MANIFEST_FILE_STEM: &'static str = "manifest";
}
Expand Down Expand Up @@ -187,7 +184,9 @@ mod nested_sources {
static ref MAX_DEPTH: usize = 5;
}

#[allow(dead_code)]
fn parse_packages(package_path: &Path) -> Result<Vec<Package>, Error> {

Check failure on line 188 in paxy_build/src/package.rs

View workflow job for this annotation

GitHub Actions / 📎 Clippy (x86_64-pc-windows-msvc)

the `Err`-variant returned from this function is very large
#[allow(clippy::manual_try_fold)]
let packages = WalkDir::new(package_path)
.follow_links(true) // to respect symlinks
.min_depth(*MIN_DEPTH) // to at least look inside the directory
Expand All @@ -202,10 +201,10 @@ mod nested_sources {
|mut acc: Result<Option<Vec<Package>>, Error>,
manifest_path: PathBuf|
-> Result<Option<Vec<Package>>, Error> {
let package: Result<Package, Error> = match manifest_path.extension().map(|e| {
e.to_str()
.map(|es| TryInto::<ManifestFileExtensions>::try_into(es))
}) {
let package: Result<Package, Error> = match manifest_path
.extension()
.map(|e| e.to_str().map(TryInto::<ManifestFileExtensions>::try_into))
{
Some(Some(Ok(ManifestFileExtensions::Yaml))) => serde_yaml::from_reader(
File::open(&manifest_path).context(ManifestCannotBeReadSnafu {
path: &manifest_path,
Expand Down
1 change: 1 addition & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ targets = [
"aarch64-unknown-linux-gnu",
"aarch64-apple-darwin",
]
components = ["rustc", "cargo", "rust-std", "rustfmt"]

0 comments on commit 0f0c20d

Please sign in to comment.