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

Clean up dependency and code base #1759

Merged
merged 8 commits into from
Apr 19, 2019
Merged
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
71 changes: 22 additions & 49 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@ vendored-openssl = ['openssl/vendored']
# Include in the default set to disable self-update and uninstall.
no-self-update = []

# Sorted by alphabetic order
[dependencies]
clap = "2"
dirs = "1"
download = { path = "download" }
clap = "2"
error-chain = "0.12"
flate2 = "1"
itertools = "0.8"
git-testament = "0.1.4"
lazy_static = "1"
libc = "0.2"
markdown = "0.2"
ole32-sys = "0.2"
# Used by `curl` or `reqwest` backend although it isn't imported
# by our rustup.
openssl = { version = "0.10", optional = true }
rand = "0.6"
regex = "1"
remove_dir_all = "0.5.1"
same-file = "1"
semver = "0.9"
scopeguard = "1"
semver = "0.9"
sha2 = "0.8"
tar = "0.4"
tempdir = "0.3.4"
Expand All @@ -46,17 +50,11 @@ url = "1"
wait-timeout = "0.2"
walkdir = "2"
xz2 = "0.1.3"
openssl = { version = "0.10", optional = true }
git-testament = "0.1.4"
lazy_static = "1"

[target."cfg(windows)".dependencies]
cc = "1"
winapi = { version = "0.3", features = ["combaseapi", "errhandlingapi", "fileapi", "handleapi", "ioapiset", "jobapi", "jobapi2", "minwindef", "processthreadsapi", "psapi", "shlobj", "shtypes", "synchapi", "sysinfoapi", "tlhelp32", "userenv", "winbase", "winerror", "winioctl", "winnt", "winuser"] }
winreg = "0.6"
cc = "1"

[dev-dependencies]
lazy_static = "1"

[workspace]
members = ["download"]
Expand Down
32 changes: 16 additions & 16 deletions src/cli/help.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub static RUSTUP_HELP: &'static str = r"DISCUSSION:
pub static RUSTUP_HELP: &str = r"DISCUSSION:
rustup installs The Rust Programming Language from the official
release channels, enabling you to easily switch between stable,
beta, and nightly compilers and keep them updated. It makes
Expand All @@ -8,7 +8,7 @@ pub static RUSTUP_HELP: &'static str = r"DISCUSSION:
If you are new to Rust consider running `rustup doc --book` to
learn Rust.";

pub static SHOW_HELP: &'static str = r"DISCUSSION:
pub static SHOW_HELP: &str = r"DISCUSSION:
Shows the name of the active toolchain and the version of `rustc`.

If the active toolchain has installed support for additional
Expand All @@ -17,7 +17,7 @@ pub static SHOW_HELP: &'static str = r"DISCUSSION:
If there are multiple toolchains installed then all installed
toolchains are listed as well.";

pub static SHOW_ACTIVE_TOOLCHAIN_HELP: &'static str = r"DISCUSSION:
pub static SHOW_ACTIVE_TOOLCHAIN_HELP: &str = r"DISCUSSION:
Shows the name of the active toolchain.

This is useful for figuring out the active tool chain from
Expand All @@ -26,24 +26,24 @@ pub static SHOW_ACTIVE_TOOLCHAIN_HELP: &'static str = r"DISCUSSION:
You should use `rustc --print sysroot` to get the sysroot, or
`rustc --version` to get the toolchain version.";

pub static UPDATE_HELP: &'static str = r"DISCUSSION:
pub static UPDATE_HELP: &str = r"DISCUSSION:
With no toolchain specified, the `update` command updates each of
the installed toolchains from the official release channels, then
updates rustup itself.

If given a toolchain argument then `update` updates that
toolchain, the same as `rustup toolchain install`.";

pub static INSTALL_HELP: &'static str = r"DISCUSSION:
pub static INSTALL_HELP: &str = r"DISCUSSION:
Installs a specific rust toolchain.

The 'install' command is an alias for 'rustup update <toolchain>'.";

pub static DEFAULT_HELP: &'static str = r"DISCUSSION:
pub static DEFAULT_HELP: &str = r"DISCUSSION:
Sets the default toolchain to the one specified. If the toolchain
is not already installed then it is installed first.";

pub static TOOLCHAIN_HELP: &'static str = r"DISCUSSION:
pub static TOOLCHAIN_HELP: &str = r"DISCUSSION:
Many `rustup` commands deal with *toolchains*, a single
installation of the Rust compiler. `rustup` supports multiple
types of toolchains. The most basic track the official release
Expand Down Expand Up @@ -80,7 +80,7 @@ pub static TOOLCHAIN_HELP: &'static str = r"DISCUSSION:
often used to for developing Rust itself. For more information see
`rustup toolchain help link`.";

pub static TOOLCHAIN_LINK_HELP: &'static str = r"DISCUSSION:
pub static TOOLCHAIN_LINK_HELP: &str = r"DISCUSSION:
'toolchain' is the custom name to be assigned to the new toolchain.
Any name is permitted as long as it does not fully match an initial
substring of a standard release channel. For example, you can use
Expand All @@ -99,7 +99,7 @@ pub static TOOLCHAIN_LINK_HELP: &'static str = r"DISCUSSION:
If you now compile a crate in the current directory, the custom
toolchain 'latest-stage1' will be used.";

pub static OVERRIDE_HELP: &'static str = r"DISCUSSION:
pub static OVERRIDE_HELP: &str = r"DISCUSSION:
Overrides configure rustup to use a specific toolchain when
running in a specific directory.

Expand All @@ -120,14 +120,14 @@ pub static OVERRIDE_HELP: &'static str = r"DISCUSSION:
override and use the default toolchain again, `rustup override
unset`.";

pub static OVERRIDE_UNSET_HELP: &'static str = r"DISCUSSION:
pub static OVERRIDE_UNSET_HELP: &str = r"DISCUSSION:
If `--path` argument is present, removes the override toolchain
for the specified directory. If `--nonexistent` argument is
present, removes the override toolchain for all nonexistent
directories. Otherwise, removes the override toolchain for the
current directory.";

pub static RUN_HELP: &'static str = r"DISCUSSION:
pub static RUN_HELP: &str = r"DISCUSSION:
Configures an environment to use the given toolchain and then runs
the specified program. The command may be any program, not just
rustc or cargo. This can be used for testing arbitrary toolchains
Expand All @@ -142,14 +142,14 @@ pub static RUN_HELP: &'static str = r"DISCUSSION:

$ rustup run nightly cargo build";

pub static DOC_HELP: &'static str = r"DISCUSSION:
pub static DOC_HELP: &str = r"DISCUSSION:
Opens the documentation for the currently active toolchain with
the default browser.

By default, it opens the documentation index. Use the various
flags to open specific pieces of documentation.";

pub static COMPLETIONS_HELP: &'static str =
pub static COMPLETIONS_HELP: &str =
r"DISCUSSION:
One can generate a completion script for `rustup` that is
compatible with a given shell. The script is output on `stdout`
Expand Down Expand Up @@ -268,6 +268,6 @@ r"DISCUSSION:

$ rustup completions zsh cargo > ~/.zfunc/_cargo";

pub static TOOLCHAIN_ARG_HELP: &'static str = "Toolchain name, such as 'stable', 'nightly', \
or '1.8.0'. For more information see `rustup \
help toolchain`";
pub static TOOLCHAIN_ARG_HELP: &str = "Toolchain name, such as 'stable', 'nightly', \
or '1.8.0'. For more information see `rustup \
help toolchain`";
5 changes: 0 additions & 5 deletions src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@ mod term2;

use crate::errors::*;
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
use std::alloc::System;
use std::env;
use std::path::PathBuf;

// Always use the system allocator, to reduce binary size.
#[global_allocator]
static _ALLOCATOR: System = System;

fn main() {
if let Err(ref e) = run_rustup() {
common::report_error(e);
Expand Down
19 changes: 12 additions & 7 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use crate::common::{self, Confirm};
use crate::errors::*;
use crate::term2;
use regex::Regex;
use rustup::dist::dist;
use rustup::utils::utils;
use rustup::{DUP_TOOLS, TOOLS};
Expand Down Expand Up @@ -170,7 +169,7 @@ This will uninstall all Rust toolchains and data, and remove
};
}

static MSVC_MESSAGE: &'static str = r#"# Rust Visual C++ prerequisites
static MSVC_MESSAGE: &str = r#"# Rust Visual C++ prerequisites

Rust requires the Microsoft C++ build tools for Visual Studio 2013 or
later, but they don't seem to be installed.
Expand All @@ -196,7 +195,7 @@ doing then it is fine to continue installation without the build
tools, but otherwise, install the C++ build tools before proceeding.
"#;

static UPDATE_ROOT: &'static str = "https://static.rust-lang.org/rustup";
static UPDATE_ROOT: &str = "https://static.rust-lang.org/rustup";

/// `CARGO_HOME` suitable for display, possibly with $HOME
/// substituted for the directory prefix
Expand All @@ -219,7 +218,7 @@ fn canonical_cargo_home() -> Result<String> {
}

/// Installing is a simple matter of coping the running binary to
/// `CARGO_HOME`/bin, hardlinking the various Rust tools to it,
/// `CARGO_HOME`/bin, hard-linking the various Rust tools to it,
/// and adding `CARGO_HOME`/bin to PATH.
pub fn install(no_prompt: bool, verbose: bool, mut opts: InstallOpts) -> Result<()> {
do_pre_install_sanity_checks()?;
Expand Down Expand Up @@ -464,7 +463,7 @@ fn do_anti_sudo_check(no_prompt: bool) -> Result<()> {
libc::getpwuid_r(
libc::geteuid(),
&mut pwd,
&mut buf as *mut [u8] as *mut i8,
&mut buf as *mut [u8] as *mut libc::c_char,
buf.len(),
&mut pwdp,
)
Expand Down Expand Up @@ -1378,8 +1377,14 @@ fn get_new_rustup_version(path: &Path) -> Option<String> {
}

fn parse_new_rustup_version(version: String) -> String {
let re = Regex::new(r"\d+.\d+.\d+[0-9a-zA-Z-]*").unwrap();
let capture = re.captures(&version);
use lazy_static::lazy_static;
use regex::Regex;

lazy_static! {
static ref RE: Regex = Regex::new(r"\d+.\d+.\d+[0-9a-zA-Z-]*").unwrap();
}

let capture = RE.captures(&version);
nrc marked this conversation as resolved.
Show resolved Hide resolved
let matched_version = match capture {
Some(cap) => cap.get(0).unwrap().as_str(),
None => "(unknown)",
Expand Down
75 changes: 40 additions & 35 deletions src/dist/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ use crate::dist::temp;
use crate::errors::*;
use crate::utils::utils;

use lazy_static::lazy_static;
use regex::Regex;

use std::env;
use std::fmt;
use std::path::Path;

use regex::Regex;

pub const DEFAULT_DIST_SERVER: &str = "https://static.rust-lang.org";
pub static DEFAULT_DIST_SERVER: &str = "https://static.rust-lang.org";

// Deprecated
pub const DEFAULT_DIST_ROOT: &str = "https://static.rust-lang.org/dist";
pub static DEFAULT_DIST_ROOT: &str = "https://static.rust-lang.org/dist";

// A toolchain descriptor from rustup's perspective. These contain
// 'partial target triples', which allow toolchain names like
Expand Down Expand Up @@ -56,7 +57,7 @@ pub struct TargetTriple(String);
// These lists contain the targets known to rustup, and used to build
// the PartialTargetTriple.

static LIST_ARCHS: &'static [&'static str] = &[
static LIST_ARCHS: &[&str] = &[
"i386",
"i586",
"i686",
Expand All @@ -74,7 +75,7 @@ static LIST_ARCHS: &'static [&'static str] = &[
"powerpc64le",
"s390x",
];
static LIST_OSES: &'static [&'static str] = &[
static LIST_OSES: &[&str] = &[
"pc-windows",
"unknown-linux",
"apple-darwin",
Expand All @@ -84,7 +85,7 @@ static LIST_OSES: &'static [&'static str] = &[
"rumprun-netbsd",
"unknown-freebsd",
];
static LIST_ENVS: &'static [&'static str] = &[
static LIST_ENVS: &[&str] = &[
"gnu",
"msvc",
"gnueabi",
Expand All @@ -100,14 +101,14 @@ static LIST_ENVS: &'static [&'static str] = &[
// Hence we could distinguish between the variants with compile-time cfg()
// attributes alone.
#[cfg(all(not(windows), target_endian = "big"))]
const TRIPLE_MIPS_UNKNOWN_LINUX_GNU: &str = "mips-unknown-linux-gnu";
static TRIPLE_MIPS_UNKNOWN_LINUX_GNU: &str = "mips-unknown-linux-gnu";
#[cfg(all(not(windows), target_endian = "little"))]
const TRIPLE_MIPS_UNKNOWN_LINUX_GNU: &str = "mipsel-unknown-linux-gnu";
static TRIPLE_MIPS_UNKNOWN_LINUX_GNU: &str = "mipsel-unknown-linux-gnu";

#[cfg(all(not(windows), target_endian = "big"))]
const TRIPLE_MIPS64_UNKNOWN_LINUX_GNUABI64: &str = "mips64-unknown-linux-gnuabi64";
static TRIPLE_MIPS64_UNKNOWN_LINUX_GNUABI64: &str = "mips64-unknown-linux-gnuabi64";
#[cfg(all(not(windows), target_endian = "little"))]
const TRIPLE_MIPS64_UNKNOWN_LINUX_GNUABI64: &str = "mips64el-unknown-linux-gnuabi64";
static TRIPLE_MIPS64_UNKNOWN_LINUX_GNUABI64: &str = "mips64el-unknown-linux-gnuabi64";

impl TargetTriple {
pub fn from_str(name: &str) -> Self {
Expand Down Expand Up @@ -223,15 +224,16 @@ impl PartialTargetTriple {
// we can count on all triple components being
// delineated by it.
let name = format!("-{}", name);
let pattern = format!(
r"^(?:-({}))?(?:-({}))?(?:-({}))?$",
LIST_ARCHS.join("|"),
LIST_OSES.join("|"),
LIST_ENVS.join("|")
);

let re = Regex::new(&pattern).unwrap();
re.captures(&name).map(|c| {
lazy_static! {
static ref PATTERN: String = format!(
r"^(?:-({}))?(?:-({}))?(?:-({}))?$",
LIST_ARCHS.join("|"),
LIST_OSES.join("|"),
LIST_ENVS.join("|")
);
static ref RE: Regex = Regex::new(&PATTERN).unwrap();
}
RE.captures(&name).map(|c| {
fn fn_map(s: &str) -> Option<String> {
if s == "" {
None
Expand All @@ -251,21 +253,22 @@ impl PartialTargetTriple {

impl PartialToolchainDesc {
pub fn from_str(name: &str) -> Result<Self> {
let channels = [
static CHANNELS: &[&str] = &[
"nightly",
"beta",
"stable",
r"\d{1}\.\d{1}\.\d{1}",
r"\d{1}\.\d{2}\.\d{1}",
];

let pattern = format!(
r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?(?:-(.*))?$",
channels.join("|")
);

let re = Regex::new(&pattern).unwrap();
let d = re.captures(name).map(|c| {
lazy_static! {
static ref PATTERN: String = format!(
r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?(?:-(.*))?$",
CHANNELS.join("|")
);
static ref RE: Regex = Regex::new(&PATTERN).unwrap();
}
let d = RE.captures(name).map(|c| {
fn fn_map(s: &str) -> Option<String> {
if s == "" {
None
Expand Down Expand Up @@ -341,21 +344,23 @@ impl PartialToolchainDesc {

impl ToolchainDesc {
pub fn from_str(name: &str) -> Result<Self> {
let channels = [
static CHANNELS: &[&str] = &[
"nightly",
"beta",
"stable",
r"\d{1}\.\d{1}\.\d{1}",
r"\d{1}\.\d{2}\.\d{1}",
];

let pattern = format!(
r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?-(.*)?$",
channels.join("|"),
);
lazy_static! {
static ref PATTERN: String = format!(
r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?-(.*)?$",
CHANNELS.join("|"),
);
static ref RE: Regex = Regex::new(&PATTERN).unwrap();
}

let re = Regex::new(&pattern).unwrap();
re.captures(name)
RE.captures(name)
.map(|c| {
fn fn_map(s: &str) -> Option<String> {
if s == "" {
Expand Down
Loading