Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to get better list of boards #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "rune"
version = "0.1.2"
edition = "2021"
authors = ["Alexander von Gluck IV <[email protected]>"]
license = "MIT"

Expand Down
64 changes: 57 additions & 7 deletions src/boards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern crate curl;
use std::env;
use std::error::Error;
use curl::easy::Easy;
use fs::File;
use crate::fs::File;

pub const MANIFEST_URI: &str = "https://github.com/haiku/firmware/raw/master/u-boot/manifest.json";

Expand All @@ -27,6 +27,27 @@ pub struct Board {
pub files: Vec<String>,
}

// sort boards based on ID only
impl Ord for Board {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
(self.id).cmp(&(other.id))
}
}

impl PartialOrd for Board {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl PartialEq for Board {
fn eq(&self, other: &Self) -> bool {
(self.id) == (other.id)
}
}

impl Eq for Board {}

fn get_boards_local(path: String) -> Result<Vec<Board>, Box<dyn Error>> {
// Get boards from local manifest
let file = File::open(path)?;
Expand Down Expand Up @@ -60,6 +81,20 @@ pub fn get_boards() -> Result<Vec<Board>, Box<dyn Error>> {
}
}

pub fn get_architectures() -> Result<Vec<String>, Box<dyn Error>> {
// TODO: this is horrible, we read board file like three times.
// Not so bad with local file, but CURLing it three times from Github is a bit... eh
let boards = get_boards()?;
let mut architectures: Vec<String> = Vec::new();
for i in boards {
if !architectures.contains(&i.arch) {
architectures.push(i.arch);
}
}
architectures.sort();
return Ok(architectures)
}

pub fn get_arch(arch: String) -> Result<Vec<Board>, Box<dyn Error>> {
let boards = get_boards()?;
let mut results: Vec<Board> = Vec::new();
Expand All @@ -68,6 +103,7 @@ pub fn get_arch(arch: String) -> Result<Vec<Board>, Box<dyn Error>> {
results.push(i);
}
}
results.sort();
return Ok(results)
}

Expand All @@ -81,14 +117,28 @@ pub fn get_board(board_id: String) -> Result<Board, Box<dyn Error>> {
return Err(From::from("Unknown target board!"));
}

pub fn print(arch: String) {
print!("{}\n===\n", arch);
let arch_boards = match get_arch(arch) {
Ok(m) => { m },
pub fn print() {
let architectures: Vec<String> = match get_architectures() {
Ok(a) => {a},
Err(e) => { println!(" Error: {}", e); return },
};

if architectures.len() == 0 {
println!("No architectures were found");
return
}

print!(" {:20} {:10} {:20}\n", "Board", "SOC", "Name");
for board in arch_boards {
print!(" {:20} {:10} {:20}\n", board.id, board.soc, board.name);
for arch in architectures {
let arch_boards = match get_arch(arch.clone()) {
Ok(m) => { m },
Err(e) => { println!(" Error: {}", e); return },
};
if arch_boards.len() > 0 {
print!("{}\n===\n", arch);
for board in arch_boards {
print!(" {:20} {:10} {:20}\n", board.id, board.soc, board.name);
}
}
}
}
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use fatfs::{BufStream, FileSystem, FsOptions};
use getopts::Options;
use url::Url;
use indicatif::{ProgressBar,ProgressStyle};
use partition::Partition;
use crate::partition::Partition;
use regex::Regex;

mod boards;
Expand Down Expand Up @@ -223,8 +223,7 @@ fn main() {
print_version();
return;
} else if matches.opt_present("l") {
//XXX This needs to be better and dynamic!
boards::print("arm".to_string());
boards::print();
process::exit(1);
}

Expand Down