Skip to content

Commit

Permalink
added gen-manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Jun 12, 2023
1 parent eeabb3f commit b834414
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 13 deletions.
91 changes: 91 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions common/ipk/src/ipk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ use std::borrow::Cow;
use std::collections::HashMap;
use std::fs::File;
use std::io::{Error, ErrorKind, Read};
use std::path::Path;

use debpkg::{Control, DebPkg};
use path_slash::CowExt;

use crate::{AppInfo, Component, Package, PackageInfo, ServiceInfo, Symlinks};

impl Package {
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
return File::open(path.as_ref()).and_then(|file| Package::parse(file));
}

pub fn parse<R>(read: R) -> Result<Self, Error>
where
R: Read,
Expand Down
4 changes: 4 additions & 0 deletions common/ipk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ pub struct PackageInfo {
}

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AppInfo {
pub id: String,
pub version: String,
pub r#type: String,
pub title: String,
pub app_description: Option<String>,
pub main: String,
}

Expand Down
2 changes: 1 addition & 1 deletion packages/fw-extract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ name = "webosbrew-toolbox-fw-symbols"
section = "devel"
assets = [
["target/release/fw-extract", "usr/bin/webosbrew-fw-symbols-extract", "755"],
["../../data/**/*", "usr/share/webosbrew/compat-checker/data/", "644"]
["../../common/data/**/*", "usr/share/webosbrew/compat-checker/data/", "644"]
]
features = ["linux-install"]
8 changes: 5 additions & 3 deletions packages/gen-manifest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ license = "Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[dependencies.ipk-lib]
path = "../../common/ipk"
serde = { version = "1.0.160", features = ["derive"] }
serde_json = "1.0.96"
clap = { version = "4.2.4", features = ["derive"] }
ipk-lib = { path = "../../common/ipk" }
sha256 = "1.1.3"

[package.metadata.deb]
name = "webosbrew-toolbox-gen-manifest"
Expand Down
12 changes: 12 additions & 0 deletions packages/gen-manifest/src/hash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::io::Error;
use std::path::Path;

use crate::IpkHash;

impl IpkHash {
pub(crate) fn from<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
return Ok(Self {
sha256: sha256::try_digest(path.as_ref())?,
});
}
}
92 changes: 91 additions & 1 deletion packages/gen-manifest/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,93 @@
mod hash;

use std::fs::File;
use std::path::PathBuf;

use clap::{Parser, ValueEnum};
use ipk_lib::Package;
use serde::{Serialize, Serializer};

#[derive(Parser, Debug)]
struct Args {
#[arg(short, long)]
appinfo: Option<String>,
#[arg(short, long)]
pkgfile: PathBuf,
#[arg(short, long)]
output: Option<PathBuf>,
#[arg(short, long)]
icon: String,
#[arg(short, long)]
link: String,
#[arg(short, long, value_enum)]
root: Option<RootRequired>,
}

#[derive(Debug, Clone, PartialEq, ValueEnum)]
enum RootRequired {
True,
False,
Optional,
}

impl Serialize for RootRequired {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
return match self {
RootRequired::True => serializer.serialize_bool(true),
RootRequired::False => serializer.serialize_bool(false),
RootRequired::Optional => serializer.serialize_str("optional"),
};
}
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
struct IpkHash {
sha256: String,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
struct HomebrewManifest {
id: String,
version: String,
r#type: String,
title: String,
#[serde(skip_serializing_if = "Option::is_none")]
app_description: Option<String>,
icon_url: String,
source_url: String,
#[serde(skip_serializing_if = "Option::is_none")]
root_required: Option<RootRequired>,
ipk_url: String,
ipk_hash: IpkHash,
}

fn main() {
println!("Hello, world!");
let args = Args::parse();
if args.appinfo.is_some() {
eprintln!("--appinfo option is not needed anymore.");
}
let package = Package::open(&args.pkgfile).unwrap();
let app_info = package.app.info;
let manifest = HomebrewManifest {
id: app_info.id,
version: app_info.version,
r#type: app_info.r#type,
title: app_info.title,
app_description: app_info.app_description,
icon_url: args.icon,
source_url: args.link,
root_required: args.root,
ipk_url: String::from(args.pkgfile.file_name().unwrap().to_string_lossy()),
ipk_hash: IpkHash::from(&args.pkgfile).unwrap(),
};
if let Some(output) = args.output {
serde_json::to_writer_pretty(&mut File::create(&output).unwrap(), &manifest).unwrap();
} else {
serde_json::to_writer_pretty(&mut std::io::stdout(), &manifest).unwrap();
}
}
6 changes: 1 addition & 5 deletions packages/ipk-verify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ prettytable-rs = "^0.10"
semver = "1.0.17"
is-terminal = "0.4.7"
term = "0.7.0"
clap = { version = "4.2.4", features = ["derive"] }
verify-lib = { path = "../../common/verify", features = ["ipk"] }


[dependencies.clap]
version = "4.2.4"
features = ["derive"]

[dependencies.fw-lib]
path = "../../common/fw"

Expand Down
6 changes: 3 additions & 3 deletions packages/ipk-verify/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io::{Error, Write};
use std::iter;
use std::path::PathBuf;

use clap::Parser;
use clap::{Parser, ValueEnum};
use is_terminal::IsTerminal;
use prettytable::{Cell, Row, Table};
use semver::VersionReq;
Expand Down Expand Up @@ -31,7 +31,7 @@ struct Args {
debug: u8,
}

#[derive(Debug, Clone, PartialEq, clap::ValueEnum)]
#[derive(Debug, Clone, PartialEq, ValueEnum)]
pub enum OutputFormat {
Markdown,
Terminal,
Expand Down Expand Up @@ -73,7 +73,7 @@ fn main() {
eprintln!("No firmware found");
}
for package in args.packages {
let package = match File::open(&package).and_then(|file| Package::parse(file)) {
let package = match Package::open(&package) {
Ok(package) => package,
Err(e) => {
eprintln!(
Expand Down

0 comments on commit b834414

Please sign in to comment.