Switch to anyhow and thiserror

Update clap to version 3
Make golang file parseable by removing line breaks
This commit is contained in:
Till Wegmueller 2022-03-24 19:48:41 -03:00
parent d129518d33
commit 3481814af2
12 changed files with 147 additions and 237 deletions

160
Cargo.lock generated
View file

@ -1,13 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "addr2line"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7"
dependencies = [
"gimli",
]
version = 3
[[package]]
name = "adler"
@ -24,6 +17,12 @@ dependencies = [
"memchr",
]
[[package]]
name = "anyhow"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27"
[[package]]
name = "atty"
version = "0.2.14"
@ -41,20 +40,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "backtrace"
version = "0.3.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "base64"
version = "0.13.0"
@ -142,9 +127,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "3.0.0-beta.2"
version = "3.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142"
checksum = "d8c93436c21e4698bacadf42917db28b23017027a4deccb35dbe47a7e7840123"
dependencies = [
"atty",
"bitflags",
@ -155,15 +140,13 @@ dependencies = [
"strsim",
"termcolor",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "clap_derive"
version = "3.0.0-beta.2"
version = "3.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1"
checksum = "da95d038ede1a964ce99f49cbe27a7fb538d1da595e4b4f70b8c8f338d17bf16"
dependencies = [
"heck",
"proc-macro-error",
@ -230,28 +213,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "failure"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86"
dependencies = [
"backtrace",
"failure_derive",
]
[[package]]
name = "failure_derive"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
dependencies = [
"proc-macro2",
"quote",
"syn",
"synstructure",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
@ -379,12 +340,6 @@ dependencies = [
"wasi",
]
[[package]]
name = "gimli"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce"
[[package]]
name = "h2"
version = "0.3.2"
@ -412,12 +367,9 @@ checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
[[package]]
name = "heck"
version = "0.3.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac"
dependencies = [
"unicode-segmentation",
]
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]]
name = "hermit-abi"
@ -563,7 +515,7 @@ checksum = "ba4aede83fc3617411dc6993bc8c70919750c1c257c6ca6a502aed6e0e2394ae"
name = "libips"
version = "0.1.2"
dependencies = [
"failure",
"anyhow",
"maplit 0.1.6",
"object",
"pest",
@ -571,6 +523,7 @@ dependencies = [
"regex",
"sha2",
"sha3",
"thiserror",
]
[[package]]
@ -602,9 +555,9 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
[[package]]
name = "memchr"
version = "2.3.4"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]]
name = "mime"
@ -744,9 +697,12 @@ dependencies = [
[[package]]
name = "os_str_bytes"
version = "2.4.0"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85"
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
dependencies = [
"memchr",
]
[[package]]
name = "percent-encoding"
@ -843,9 +799,8 @@ version = "0.0.1-placeholder"
name = "pkg6dev"
version = "0.1.1"
dependencies = [
"anyhow",
"clap",
"failure",
"failure_derive",
"libips",
"userland",
]
@ -886,9 +841,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.26"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec"
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
dependencies = [
"unicode-xid",
]
@ -1012,12 +967,6 @@ dependencies = [
"winreg",
]
[[package]]
name = "rustc-demangle"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"
[[package]]
name = "ryu"
version = "1.0.5"
@ -1179,27 +1128,15 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.70"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9505f307c872bab8eb46f77ae357c8eba1fdacead58ee5a850116b1d7f82883"
checksum = "ea297be220d52398dcc07ce15a209fce436d361735ac1db700cab3b6cdfb9f54"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "synstructure"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701"
dependencies = [
"proc-macro2",
"quote",
"syn",
"unicode-xid",
]
[[package]]
name = "tempfile"
version = "3.2.0"
@ -1225,11 +1162,28 @@ dependencies = [
[[package]]
name = "textwrap"
version = "0.12.1"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789"
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
[[package]]
name = "thiserror"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
dependencies = [
"unicode-width",
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -1348,18 +1302,6 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796"
[[package]]
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "unicode-xid"
version = "0.2.1"
@ -1382,7 +1324,7 @@ dependencies = [
name = "userland"
version = "0.1.1"
dependencies = [
"failure",
"anyhow",
"maplit 0.1.6",
"pest",
"pest_derive",
@ -1398,12 +1340,6 @@ version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbdbff6266a24120518560b5dc983096efb98462e51d0d68169895b237be3e5d"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version_check"
version = "0.9.3"

View file

@ -17,7 +17,8 @@ keywords = ["packaging", "illumos"]
[dependencies]
regex = "1.3.7"
failure = "0.1.8"
anyhow = "1.0.56"
thiserror = "1.0.30"
maplit = "0.1.6"
object = "0.23.0"
sha2 = "0.9.3"

View file

@ -12,9 +12,9 @@ use std::clone::Clone;
use crate::digest::Digest;
use std::str::FromStr;
use std::path::{Path};
use std::fmt;
use crate::errors::Result;
use anyhow::{anyhow, Result};
use pest::Parser;
use thiserror::Error;
pub trait FacetedAction {
// Add a facet to the action if the facet is already present the function returns false.
@ -220,9 +220,9 @@ impl FacetedAction for File {
}
}
#[derive(Debug, Fail)]
#[derive(Debug, Error)]
pub enum FileError {
#[fail(display = "file path is not a string")]
#[error("file path is not a string")]
FilePathIsNoStringError,
}
@ -459,8 +459,8 @@ impl Manifest {
}
}
pub fn parse_file(f: String) -> Result<Manifest> {
let content = read_to_string(Path::new(&f))?;
pub fn parse_file<P: AsRef<Path>>(f: P) -> Result<Manifest> {
let content = read_to_string(f)?;
Manifest::parse_string(content)
}
@ -544,14 +544,14 @@ impl Default for ActionKind {
}
//TODO Multierror and no failure for these cases
#[derive(Debug, Fail)]
#[derive(Debug, Error)]
pub enum ManifestError {
#[fail(display = "unknown action {} at line {}", action, line)]
#[error("unknown action {action:?} at line {line:?}")]
UnknownAction {
line: usize,
action: String,
},
#[fail(display = "action string \"{}\" at line {} is invalid: {}", action, line, message)]
#[error("action string \"{action:?}\" at line {line:?} is invalid: {message:?}")]
InvalidAction {
line: usize,
action: String,
@ -615,6 +615,6 @@ fn string_to_bool(orig: &str) -> Result<bool> {
"false" => Ok(false),
"t" => Ok(true),
"f" => Ok(false),
_ => Err(failure::err_msg("not a boolean like value"))
_ => Err(anyhow!("not a boolean like value"))
}
}

View file

@ -3,10 +3,14 @@
// MPL was not distributed with this file, You can
// obtain one at https://mozilla.org/MPL/2.0/.
use thiserror::Error;
use anyhow::Result;
use std::str::FromStr;
use sha2::{Digest as Sha2Digest};
#[allow(unused_imports)]
use sha3::{Digest as Sha3Digest};
#[allow(dead_code)]
static DEFAULT_ALGORITHM: DigestAlgorithm = DigestAlgorithm::SHA512;
#[derive(Debug, PartialEq, Clone)]
@ -90,7 +94,7 @@ impl FromStr for Digest {
}
impl Digest {
pub fn from_bytes(b: &[u8], algo: DigestAlgorithm, src: DigestSource) -> Result<Self, failure::Error> {
pub fn from_bytes(b: &[u8], algo: DigestAlgorithm, src: DigestSource) -> Result<Self> {
let hash = match algo {
DigestAlgorithm::SHA256=> {
format!("{:x}", sha2::Sha256::digest(b))
@ -136,13 +140,13 @@ impl Digest {
}
}
#[derive(Debug, Fail)]
#[derive(Debug, Error)]
pub enum DigestError {
#[fail(display = "hashing algorithm {} is not known by this library", algorithm)]
#[error("hashing algorithm {algorithm:?} is not known by this library")]
UnknownAlgorithm {
algorithm: String,
},
#[fail(display = "digest {} is not formatted properly: {}", digest, details)]
#[error("digest {digest:?} is not formatted properly: {details:?}")]
InvalidDigestFormat{
digest: String,
details: String,

View file

@ -7,16 +7,8 @@ pub mod actions;
pub mod digest;
pub mod payload;
mod errors {
use failure::Error;
use std::result::Result as StdResult;
pub type Result<T> = StdResult<T, Error>;
}
extern crate pest;
#[macro_use] extern crate pest_derive;
#[macro_use] extern crate failure;
extern crate maplit;
#[cfg(test)]

View file

@ -4,7 +4,7 @@
// obtain one at https://mozilla.org/MPL/2.0/.
use crate::digest::{Digest, DigestAlgorithm, DigestSource};
use failure::Error;
use anyhow::Error;
use object::Object;
use std::path::Path;

View file

@ -14,6 +14,5 @@ keywords = ["packaging", "illumos"]
[dependencies]
libips = {path = "../libips", version = "0.1.1"}
userland = {path = "../userland", version = "0.1.1"}
failure = "0.1.8"
failure_derive = "0.1.8"
clap = "~3.0.0-beta.2"
anyhow = "1.0.56"
clap = {version = "3.1.6", features = [ "derive" ] }

View file

@ -1,69 +1,58 @@
//#[macro_use]
//extern crate failure_derive;
use clap::{app_from_crate, ArgMatches};
use clap::{Arg, App};
use clap::{Parser, Subcommand};
use libips::actions::{File, Manifest};
mod errors {
use failure::Error;
use std::result::Result as StdResult;
pub type Result<T> = StdResult<T, Error>;
}
use errors::Result;
use anyhow::Result;
use std::collections::HashMap;
use std::fs::{read_dir};
use std::path::Path;
use userland::Makefile;
use userland::repology::{find_newest_version};
fn main() {
let component_arg = Arg::new("component")
.takes_value(true)
.default_value("../sample_data/pkgs/golang-116");
//.default_value("./");
let opts = app_from_crate!().subcommand(App::new("diff-component")
.about("shows differences between sample-manifest and manifests")
.arg(&component_arg)
).subcommand(App::new("show-component")
.about("Show informations about the component")
.arg(&component_arg)
).get_matches();
//.get_matches_from(vec!["pkg6dev", "diff-component"]);
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
#[clap(propagate_version = true)]
struct App {
#[clap(subcommand)]
command: Commands
}
if let Some(diff_component_opts) = opts.subcommand_matches("diff-component") {
let res = diff_component(diff_component_opts);
if res.is_err() {
println!("error: {:?}", res.unwrap_err())
#[derive(Subcommand, Debug)]
enum Commands {
DiffComponent{
component: String,
},
ShowComponent{
component: String,
},
}
fn main() -> Result<()> {
let cli = App::parse();
match &cli.command {
Commands::ShowComponent{ component } => {
show_component_info(component)
}
Commands::DiffComponent{component} => {
diff_component(component)
}
}
}
if let Some(show_component_opts) = opts.subcommand_matches("show-component") {
let res = show_component_info(show_component_opts);
if res.is_err() {
println!("error: {:?}", res.unwrap_err())
}
}
}
fn diff_component(matches: &ArgMatches) -> Result<()> {
let component_path = matches.value_of("component").unwrap();
let files = read_dir(component_path)?;
fn diff_component(component_path: impl AsRef<Path>) -> Result<()> {
let files = read_dir(&component_path)?;
let manifest_files: Vec<String> = files
.filter_map(std::result::Result::ok)
.filter(|d| if let Some(e) = d.path().extension() { e == "p5m" } else {false})
.map(|e| e.path().into_os_string().into_string().unwrap()).collect();
let sample_manifest_file = component_path.to_string() + "/manifests/sample-manifest.p5m";
let sample_manifest_file = &component_path.as_ref().join("/manifests/sample-manifest.p5m");
let manifests_res: Result<Vec<Manifest>> = manifest_files.iter().map(|f|{
Manifest::parse_file(f.to_string())
}).collect();
let sample_manifest = Manifest::parse_file(sample_manifest_file)?;
let manifests: Vec<Manifest> = manifests_res.unwrap();
@ -74,7 +63,7 @@ fn diff_component(matches: &ArgMatches) -> Result<()> {
println!("file {} is missing in the manifests", f.path);
}
let removed_files = find_removed_files(&sample_manifest, manifests.clone(), component_path)?;
let removed_files = find_removed_files(&sample_manifest, manifests.clone(), &component_path)?;
for f in removed_files {
println!("file path={} has been removed from the sample-manifest", f.path);
@ -83,12 +72,12 @@ fn diff_component(matches: &ArgMatches) -> Result<()> {
Ok(())
}
fn show_component_info(opts: &ArgMatches) -> Result<()> {
let component_path = opts.value_of("component").unwrap();
fn show_component_info<P: AsRef<Path>>(component_path: P) -> Result<()> {
let makefile_path = component_path.as_ref().join("Makefile");
let makefile = Makefile::parse_file(Path::new(&(component_path.to_string() + "/Makefile")))?;
println!("{:?}", makefile_path);
//println!("{:#?}", makefile);
let makefile = Makefile::parse_file(&makefile_path)?;
let mut name = String::new();
@ -139,7 +128,7 @@ fn show_component_info(opts: &ArgMatches) -> Result<()> {
}
// Show all files that have been removed in the sample-manifest
fn find_removed_files(sample_manifest: &Manifest, manifests: Vec<Manifest>, component_path: &str) -> Result<Vec<File>> {
fn find_removed_files<P: AsRef<Path>>(sample_manifest: &Manifest, manifests: Vec<Manifest>, component_path: P) -> Result<Vec<File>> {
let f_map = make_file_map(sample_manifest.files.clone());
let all_files: Vec<File> = manifests.iter().map(|m| m.files.clone()).flatten().collect();
@ -149,7 +138,7 @@ fn find_removed_files(sample_manifest: &Manifest, manifests: Vec<Manifest>, comp
match f.get_original_path() {
Some(path) => {
if !f_map.contains_key(path.as_str()) {
if !Path::new(&(component_path.to_string() + "/" + path.as_str())).exists() {
if !component_path.as_ref().join(path).exists() {
removed_files.push(f)
}
}

View file

@ -57,8 +57,8 @@ COMPONENT_BUILD_ENV += GOEXPERIMENT="$(GOEXPERIMENT)"
COMPONENT_BUILD_ENV += GOOS="illumos"
COMPONENT_BUILD_ENV += GOCACHE="$(SOURCE_DIR)/gocache"
COMPONENT_BUILD_ENV += GOPATH="$(SOURCE_DIR)/gopath"
COMPONENT_BUILD_ENV += \
GOROOT_BOOTSTRAP="/usr/lib/golang/$(COMPONENT_MAJOR_VERSION)"
# COMPONENT_BUILD_ENV += \
# GOROOT_BOOTSTRAP="/usr/lib/golang/$(COMPONENT_MAJOR_VERSION)"
# For convenience during installation of supplementary packages.
COMPONENT_INSTALL_ENV += PATH="$(PROTO_DIR)$(GOROOT_FINAL)/bin:$(PATH)"
@ -74,16 +74,16 @@ include $(WS_MAKE_RULES)/common.mk
# We have to fiddle with the package archives to get them into the same source
# directory so that we can use the standard build targets. We're effectively
# building multiple components using a single target.
COMPONENT_POST_UNPACK_ACTION= \
$(MV) go $(COMPONENT_SRC)
# COMPONENT_POST_UNPACK_ACTION= \
# $(MV) go $(COMPONENT_SRC)
# Go doesn't have a standard Makefile-based build process, so override the
# default.
COMPONENT_BUILD_ACTION= \
cd $(@D)/src; $(ENV) $(COMPONENT_BUILD_ENV) ./make.bash
# COMPONENT_BUILD_ACTION= \
# cd $(@D)/src; $(ENV) $(COMPONENT_BUILD_ENV) ./make.bash
COMPONENT_TARGET_DIR= \
$(PROTOUSRLIBDIR)/$(COMPONENT_NAME)/$(COMPONENT_MAJOR_VERSION)
# COMPONENT_TARGET_DIR= \
# $(PROTOUSRLIBDIR)/$(COMPONENT_NAME)/$(COMPONENT_MAJOR_VERSION)
# We can't do any ASLR'ing as the Go 6l linker has no understanding of the
# -z aslr=... option. So just override where needed in the .p5m files.
@ -97,24 +97,24 @@ COMPONENT_TEST_TARGETS=
# Use this Command to copy the Go Source tree into the proto area. In order to deliver the Go SDK under GOROOT
# Additionally nuke all the funky binary files used for test suites. They keep bothering the packaging tools
define COMPONENT_INSTALL_ACTION=
($(MKDIR) $(COMPONENT_TARGET_DIR)/src); \
(cd $(SOURCE_DIR) && \
/usr/gnu/bin/find . -maxdepth 1 -path "./$(COMPONENT_SRC_NAME)" \
-prune -o \( ! -iname ".*" \) -print \
-exec /usr/gnu/bin/cp -r \
--parents {} $(COMPONENT_TARGET_DIR) \;); \
(cd $(BUILD_DIR_64) && \
/usr/gnu/bin/find src -type f \
-exec /usr/gnu/bin/cp --parents {} $(COMPONENT_TARGET_DIR) \;); \
(cd $(BUILD_DIR_64) && $(CP) -r bin $(COMPONENT_TARGET_DIR)/); \
(cd $(BUILD_DIR_64) && $(CP) -r pkg $(COMPONENT_TARGET_DIR)/); \
(rm -r $(COMPONENT_TARGET_DIR)/pkg/obj); \
($(MKDIR) -p $(MEDIATEDUSRSHAREMAN1DIR)); \
/usr/gnu/bin/find $(COMPONENT_TARGET_DIR)/src -type f \
| egrep -v '\.go|\.s|\.bash|\.txt|\.c|\.tmpl|\.h|\.pl|\.md|\.S|\.py|\.dist|\.rc|\.bat|README|Makefile|\.awk|\.rules|\.mod|\.json|LICENSE|PATENTS'\
| xargs rm;
endef
#define COMPONENT_INSTALL_ACTION=
# ($(MKDIR) $(COMPONENT_TARGET_DIR)/src); \
# (cd $(SOURCE_DIR) && \
# /usr/gnu/bin/find . -maxdepth 1 -path "./$(COMPONENT_SRC_NAME)" \
# -prune -o \( ! -iname ".*" \) -print \
# -exec /usr/gnu/bin/cp -r \
# --parents {} $(COMPONENT_TARGET_DIR) \;); \
# (cd $(BUILD_DIR_64) && \
# /usr/gnu/bin/find src -type f \
# -exec /usr/gnu/bin/cp --parents {} $(COMPONENT_TARGET_DIR) \;); \
# (cd $(BUILD_DIR_64) && $(CP) -r bin $(COMPONENT_TARGET_DIR)/); \
# (cd $(BUILD_DIR_64) && $(CP) -r pkg $(COMPONENT_TARGET_DIR)/); \
# (rm -r $(COMPONENT_TARGET_DIR)/pkg/obj); \
# ($(MKDIR) -p $(MEDIATEDUSRSHAREMAN1DIR)); \
# /usr/gnu/bin/find $(COMPONENT_TARGET_DIR)/src -type f \
# | egrep -v '\.go|\.s|\.bash|\.txt|\.c|\.tmpl|\.h|\.pl|\.md|\.S|\.py|\.dist|\.rc|\.bat|README|Makefile|\.awk|\.rules|\.mod|\.json|LICENSE|PATENTS'\
# | xargs rm;
#endef
REQUIRED_PACKAGES += developer/golang-115
# Auto-generated dependencies

View file

@ -9,7 +9,7 @@ description = "Helper tool for IPS package development"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
failure = "0.1.8"
anyhow = "1.0.56"
pest_derive = "2.1.0"
maplit = "0.1.6"
pest = "2.1.0"

View file

@ -1,22 +1,16 @@
pub mod repology;
extern crate pest;
#[macro_use] extern crate pest_derive;
#[macro_use] extern crate failure;
#[macro_use] extern crate serde;
extern crate maplit;
mod errors {
use failure::Error;
use std::result::Result as StdResult;
#[macro_use]
extern crate pest_derive;
pub type Result<T> = StdResult<T, Error>;
}
use errors::Result;
use anyhow::Result;
use std::collections::HashMap;
use std::fs::read_to_string;
use pest::iterators::{Pair, Pairs};
use pest::iterators::{Pairs};
use std::path::Path;
use pest::Parser;

View file

@ -1,17 +1,12 @@
extern crate reqwest;
use reqwest::*;
use crate::errors::Result as EResult;
use anyhow::Result;
use semver::Version;
use serde::{Serialize, Deserialize};
const BASE_URL: &str = "https://repology.org/api/v1/";
#[derive(Debug, Clone)]
pub struct RepologyClient {
client: reqwest::Client,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Package {
repo: String,
@ -31,7 +26,7 @@ pub struct Package {
pub fn project(package: &str) -> Result<Vec<Package>> {
let url = Url::parse(&format!("{}/project/{}",BASE_URL, package)).unwrap();
let url = Url::parse(&format!("{}/project/{}",BASE_URL, package))?;
let json = reqwest::blocking::get(url)?
.json::<Vec<Package>>()?;
@ -39,9 +34,9 @@ pub fn project(package: &str) -> Result<Vec<Package>> {
return Ok(json);
}
pub fn find_newest_version(package: &str) -> EResult<String> {
pub fn find_newest_version(package: &str) -> Result<String> {
let pkgs = project(package)?;
let version_res: EResult<Vec<Version>> = pkgs.iter().map(|p| -> EResult<Version> {
let version_res: Result<Vec<Version>> = pkgs.iter().map(|p| -> Result<Version> {
let v = Version::parse(&p.version);
if v.is_ok() {
return Ok(v?);