From 0a590aa8a405db8ba35f2caa843e6a0d1758973c Mon Sep 17 00:00:00 2001 From: x0f5c3 Date: Thu, 24 Dec 2020 22:29:02 +0100 Subject: [PATCH] Removed libgit due to dependency on openssl --- CHANGELOG.md | 13 +----- Cargo.lock | 115 +++++++++++------------------------------------ Cargo.toml | 2 +- src/error.rs | 2 - src/goversion.rs | 32 ++++++++----- src/main.rs | 27 ++++++++--- 6 files changed, 72 insertions(+), 119 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15c390d..7d177ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,19 +2,10 @@ # v0.7.0 (2020-12-24): +- [Removed] libgit due to dependency on openssl - [Added] interactive mode, choosing version -- [Added] new options to git journal -- [Changed] git journal - [Feature] add option to choose specific version -- [Removed] test download -- [Modified] gitignore to exclude target -- [Feature] Use manic and switch to libgit -- [Update] main.rs -- [Update] README.md -- [Add] new version to changelog -- [Add] codecov badge -- [Added] new changelog, modified gitignore, formatted -- [Removed] openssl to easier compile on musl targets +- [Feature] Use manic # v0.6.5 (2020-12-11): - [Removed] openssl to easier compile on musl targets diff --git a/Cargo.lock b/Cargo.lock index 28b039f..adeae9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,9 +138,6 @@ name = "cc" version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66120af515773fb005778dc07c261bd201ec8ce50bd6e7144c927753fe013381" -dependencies = [ - "jobserver", -] [[package]] name = "cfg-if" @@ -232,6 +229,18 @@ dependencies = [ "generic-array", ] +[[package]] +name = "duct" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90a9c3a25aafbd538c7d40a53f83c4487ee8216c12d1c8ef2c01eb2f6ea1553" +dependencies = [ + "libc", + "once_cell", + "os_pipe", + "shared_child", +] + [[package]] name = "either" version = "1.6.0" @@ -392,21 +401,6 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" -[[package]] -name = "git2" -version = "0.13.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186dd99cc77576e58344ad614fa9bb27bad9d048f85de3ca850c1f4e8b048260" -dependencies = [ - "bitflags", - "libc", - "libgit2-sys", - "log", - "openssl-probe", - "openssl-sys", - "url", -] - [[package]] name = "go_version_manager" version = "0.7.0" @@ -414,7 +408,7 @@ dependencies = [ "colored", "console", "dialoguer", - "git2", + "duct", "human-panic", "indicatif", "leg", @@ -630,15 +624,6 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" -[[package]] -name = "jobserver" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2" -dependencies = [ - "libc", -] - [[package]] name = "js-sys" version = "0.3.45" @@ -692,31 +677,6 @@ version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235" -[[package]] -name = "libgit2-sys" -version = "0.12.16+1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f91b2f931ee975a98155195be8cd82d02e8e029d7d793d2bac1b8181ac97020" -dependencies = [ - "cc", - "libc", - "libz-sys", - "openssl-sys", - "pkg-config", -] - -[[package]] -name = "libz-sys" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "602113192b08db8f38796c4e85c39e960c145965140e918018bcde1952429655" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "log" version = "0.4.11" @@ -930,32 +890,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] -name = "openssl-probe" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" - -[[package]] -name = "openssl-src" -version = "111.13.0+1.1.1i" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "045e4dc48af57aad93d665885789b43222ae26f4886494da12d1ed58d309dcb6" -dependencies = [ - "cc", -] - -[[package]] -name = "openssl-sys" -version = "0.9.59" +name = "os_pipe" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de52d8eabd217311538a39bba130d7dea1f1e118010fee7a033d966845e7d5fe" +checksum = "fb233f06c2307e1f5ce2ecad9f8121cffbbee2c95428f44ea85222e460d0d213" dependencies = [ - "autocfg 1.0.1", - "cc", "libc", - "openssl-src", - "pkg-config", - "vcpkg", + "winapi 0.3.9", ] [[package]] @@ -1049,12 +990,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" - [[package]] name = "ppv-lite86" version = "0.2.9" @@ -1488,6 +1423,16 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "shared_child" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cebcf3a403e4deafaf34dc882c4a1b6a648b43e5670aa2e4bb985914eaeb2d2" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "signal-hook-registry" version = "1.2.1" @@ -1950,12 +1895,6 @@ dependencies = [ "rand 0.7.3", ] -[[package]] -name = "vcpkg" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" - [[package]] name = "vec_map" version = "0.8.2" diff --git a/Cargo.toml b/Cargo.toml index 4c97f05..d130a2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,9 +24,9 @@ structopt = "0.3.21" console = "0.13.0" manic = { version = "0.2.3", features = ["progress"] } thiserror = "1.0.22" -git2 = { version = "0.13.14", default-features = false, features = ["https", "vendored-openssl"] } dialoguer = "0.7.1" quit = "1.1.2" +duct = "*" leg = "0.4.1" colored = "^1.8.0" [dependencies.reqwest] diff --git a/src/error.rs b/src/error.rs index 5935e1e..ca82fde 100644 --- a/src/error.rs +++ b/src/error.rs @@ -15,8 +15,6 @@ pub enum Error { PathBufErr, #[error("Failed to get version")] NoVersion, - #[error("Git error: {0}")] - GitError(#[from] git2::Error), #[error("No sha256 found")] NoSha, #[error("Failed to parse version")] diff --git a/src/goversion.rs b/src/goversion.rs index 4bf7797..a74bc97 100644 --- a/src/goversion.rs +++ b/src/goversion.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use versions::Versioning; use crate::error::Error; use manic::progress::downloader; -use git2::{Remote, Direction}; +use duct::cmd; #[cfg(target_os = "linux")] static FILE_EXT: &str = "linux-amd64.tar.gz"; #[cfg(target_os = "windows")] @@ -29,17 +29,15 @@ pub struct GoVersion { impl GoVersion { /// Gets golang versions from git tags fn get_git_versions() -> Result, Error> { - let mut detached = Remote::create_detached("https://github.com/golang/go")?; - detached.connect(Direction::Fetch)?; - let output = detached.list()?; - let tags: Vec = output - .iter() - .map(|x| x.name().trim()) - .filter(|x| x.contains("go")) - .map(|x| x.split('/').nth(2).unwrap()) - .map(|x| x.replace("go", "")) - .collect(); - Ok(tags) + let output: Vec = cmd!("git", "ls-remote", "--tags", "https://github.com/golang/go").read()? + .trim() + .lines() + .filter(|x| x.contains("go")) + .filter_map(|x| x.split('\t').nth(1)) + .filter_map(|x| x.split('/').nth(2)) + .map(|x| x.replace("go", "")) + .collect(); + Ok(output) } /// Parses the versions into Versioning structs pub fn get_versions() -> Result, Error> { @@ -119,3 +117,13 @@ impl GoVersion { }) } } + +pub fn check_git() -> bool { + match cmd!("git", "version").stdout_null().run() { + Ok(_) => return true, + Err(e) => match e.kind() { + std::io::ErrorKind::NotFound => return false, + _ => return true, + } + } +} diff --git a/src/main.rs b/src/main.rs index ff25f5a..44e0d0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use colored::Colorize; use console::Term; use dialoguer::{theme::ColorfulTheme, Select}; use error::Error; -use goversion::GoVersion; +use goversion::{check_git, GoVersion}; use human_panic::setup_panic; use std::path::PathBuf; use structopt::StructOpt; @@ -30,14 +30,24 @@ async fn main() -> Result<(), Error> { setup_panic!(); let opt = Opt::from_args(); let term = Term::stdout(); + let git_present = check_git(); let golang = { if let Some(vers) = opt.version { goversion::GoVersion::version(vers).await? - } else if opt.interactive { + } else if opt.interactive && git_present { let vers = ask_for_version(&term)?; goversion::GoVersion::version(vers).await? } else { - goversion::GoVersion::latest().await? + if git_present { + goversion::GoVersion::latest().await? + } else { + leg::error( + "You requested the latest version and git is not installed, please install git", + None, + None, + ); + quit::with_code(127); + } } }; format!("Downloading golang version {}", &golang.version); @@ -50,7 +60,10 @@ async fn main() -> Result<(), Error> { None, ); let file_path = golang.download(opt.output, opt.workers).await?; - let path_str = file_path.to_str().expect("Couldn't convert path to str").to_string(); + let path_str = file_path + .to_str() + .expect("Couldn't convert path to str") + .to_string(); leg::success( &format!("Golang has been downloaded to {}", path_str), None, @@ -74,7 +87,11 @@ fn ask_for_version(term: &Term) -> Result { if let Some(index) = selection { Ok(versions[index].clone()) } else { - leg::error(&format!("{}", "You didn't select anything".red().bold()), None, None); + leg::error( + &format!("{}", "You didn't select anything".red().bold()), + None, + None, + ); quit::with_code(127); } }