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

Make it possible to turn off subcommands that include dependencies #8384

Closed
wants to merge 7 commits into from
Closed
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
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ log = "0.4.6"
libgit2-sys = "0.12.7"
memchr = "2.1.3"
num_cpus = "1.0"
opener = "0.4"
opener = { version = "0.4", optional = true }
percent-encoding = "2.0"
remove_dir_all = "0.5.2"
rustfix = "0.5.0"
rustfix = { version = "0.5.0", optional = true }
same-file = "1"
semver = { version = "0.10", features = ["serde"] }
serde = { version = "1.0.82", features = ["derive"] }
Expand All @@ -59,12 +58,12 @@ serde_json = { version = "1.0.30", features = ["raw_value"] }
shell-escape = "0.1.4"
strip-ansi-escapes = "0.1.0"
tar = { version = "0.4.26", default-features = false }
tempfile = "3.0"
tempfile = { version = "3.0", optional = true }
termcolor = "1.0"
toml = "0.5.3"
unicode-xid = "0.2.0"
url = "2.0"
walkdir = "2.2"
walkdir = { version = "2.2", optional = true }
clap = "2.31.2"
unicode-width = "0.1.5"
openssl = { version = '0.10.11', optional = true }
Expand Down Expand Up @@ -106,13 +105,19 @@ features = [
[dev-dependencies]
cargo-test-macro = { path = "crates/cargo-test-macro", version = "0.1.0" }
cargo-test-support = { path = "crates/cargo-test-support", version = "0.1.0" }
walkdir = "2.2"

[[bin]]
name = "cargo"
test = false
doc = false

[features]
default = ["op-install", "op-doc-open", "op-fix", "op-package-publish"]
deny-warnings = []
vendored-openssl = ["openssl/vendored"]
pretty-env-logger = ["pretty_env_logger"]
op-install = ["tempfile"]
op-doc-open = ["opener"]
op-fix = ["rustfix"]
op-package-publish = ["walkdir"]
10 changes: 10 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ jobs:
variables:
TOOLCHAIN: stable

- job: no_default_features
pool:
vmImage: ubuntu-16.04
steps:
- template: ci/azure-install-rust.yml
- bash: cargo check --no-default-features
displayName: "cargo check --no-default-features"
variables:
TOOLCHAIN: stable

- job: build_std
pool:
vmImage: ubuntu-16.04
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-test-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
doctest = false

[dependencies]
cargo = { path = "../.." }
cargo = { path = "../..", default-features = false }
cargo-test-macro = { path = "../cargo-test-macro" }
filetime = "0.2"
flate2 = { version = "1.0", default-features = false, features = ["zlib"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/resolver-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Alex Crichton <alex@alexcrichton.com>"]
edition = "2018"

[dependencies]
cargo = { path = "../.." }
cargo = { path = "../..", default-features = false }
proptest = "0.9.1"
lazy_static = "1.3.0"
varisat = "0.2.1"
Expand Down
12 changes: 12 additions & 0 deletions src/bin/cargo/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ pub fn builtin() -> Vec<App> {
clean::cli(),
doc::cli(),
fetch::cli(),
#[cfg(feature = "op-fix")]
fix::cli(),
generate_lockfile::cli(),
git_checkout::cli(),
init::cli(),
#[cfg(feature = "op-install")]
install::cli(),
locate_project::cli(),
login::cli(),
metadata::cli(),
new::cli(),
owner::cli(),
#[cfg(feature = "op-package-publish")]
package::cli(),
pkgid::cli(),
#[cfg(feature = "op-package-publish")]
publish::cli(),
read_manifest::cli(),
run::cli(),
Expand All @@ -45,18 +49,22 @@ pub fn builtin_exec(cmd: &str) -> Option<fn(&mut Config, &ArgMatches<'_>) -> Cli
"clean" => clean::exec,
"doc" => doc::exec,
"fetch" => fetch::exec,
#[cfg(feature = "op-fix")]
"fix" => fix::exec,
"generate-lockfile" => generate_lockfile::exec,
"git-checkout" => git_checkout::exec,
"init" => init::exec,
#[cfg(feature = "op-install")]
"install" => install::exec,
"locate-project" => locate_project::exec,
"login" => login::exec,
"metadata" => metadata::exec,
"new" => new::exec,
"owner" => owner::exec,
#[cfg(feature = "op-package-publish")]
"package" => package::exec,
"pkgid" => pkgid::exec,
#[cfg(feature = "op-package-publish")]
"publish" => publish::exec,
"read-manifest" => read_manifest::exec,
"run" => run::exec,
Expand All @@ -82,18 +90,22 @@ pub mod check;
pub mod clean;
pub mod doc;
pub mod fetch;
#[cfg(feature = "op-fix")]
pub mod fix;
pub mod generate_lockfile;
pub mod git_checkout;
pub mod init;
#[cfg(feature = "op-install")]
pub mod install;
pub mod locate_project;
pub mod login;
pub mod metadata;
pub mod new;
pub mod owner;
#[cfg(feature = "op-package-publish")]
pub mod package;
pub mod pkgid;
#[cfg(feature = "op-package-publish")]
pub mod publish;
pub mod read_manifest;
pub mod run;
Expand Down
7 changes: 6 additions & 1 deletion src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ fn main() {
}
};

let result = match cargo::ops::fix_maybe_exec_rustc() {
#[cfg(feature = "op-fix")]
let fix_maybe_exec_rustc = cargo::ops::fix_maybe_exec_rustc();
#[cfg(not(feature = "op-fix"))]
let fix_maybe_exec_rustc = CargoResult::Ok(false);

let result = match fix_maybe_exec_rustc {
Ok(true) => Ok(()),
Ok(false) => {
let _token = cargo::util::job::setup();
Expand Down
7 changes: 7 additions & 0 deletions src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,17 @@ fn open_docs(path: &Path, shell: &mut Shell) -> CargoResult<()> {
}
}
None => {
#[cfg(feature = "op-doc-open")]
if let Err(e) = opener::open(&path) {
let e = e.into();
crate::display_warning_with_error("couldn't open docs", &e, shell);
}
#[cfg(not(feature = "op-doc-open"))]
shell.warn(
"Ability to open docs disabled at build time. \
Please set the BROWSER env var. "
.to_string(),
)?;
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/cargo/ops/common_for_install_and_uninstall.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(feature = "op-install"), allow(dead_code))]

use std::collections::{btree_map, BTreeMap, BTreeSet};
use std::env;
use std::io::prelude::*;
Expand Down
10 changes: 9 additions & 1 deletion src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@ pub use self::cargo_fetch::{fetch, FetchOptions};
pub use self::cargo_generate_lockfile::generate_lockfile;
pub use self::cargo_generate_lockfile::update_lockfile;
pub use self::cargo_generate_lockfile::UpdateOptions;
#[cfg(feature = "op-install")]
pub use self::cargo_install::{install, install_list};
pub use self::cargo_new::{init, new, NewOptions, VersionControl};
pub use self::cargo_output_metadata::{output_metadata, ExportInfo, OutputMetadataOptions};
#[cfg(feature = "op-package-publish")]
pub use self::cargo_package::{package, PackageOpts};
pub use self::cargo_pkgid::pkgid;
pub use self::cargo_read_manifest::{read_package, read_packages};
pub use self::cargo_run::run;
pub use self::cargo_test::{run_benches, run_tests, TestOptions};
pub use self::cargo_uninstall::uninstall;
#[cfg(feature = "op-fix")]
pub use self::fix::{fix, fix_maybe_exec_rustc, FixOptions};
pub use self::lockfile::{load_pkg_lockfile, resolve_to_string, write_pkg_lockfile};
#[cfg(feature = "op-package-publish")]
pub use self::registry::publish;
pub use self::registry::HttpTimeout;
pub use self::registry::{configure_http_handle, http_handle_and_timeout};
pub use self::registry::{http_handle, needs_custom_http_transport, registry_login, search};
pub use self::registry::{modify_owners, yank, OwnersOptions, PublishOpts};
pub use self::registry::{publish, registry_configuration, RegistryConfig};
pub use self::registry::{registry_configuration, RegistryConfig};
pub use self::resolve::{
add_overrides, get_resolved_packages, resolve_with_previous, resolve_ws, resolve_ws_with_opts,
};
Expand All @@ -34,16 +39,19 @@ mod cargo_compile;
mod cargo_doc;
mod cargo_fetch;
mod cargo_generate_lockfile;
#[cfg(feature = "op-install")]
mod cargo_install;
mod cargo_new;
mod cargo_output_metadata;
#[cfg(feature = "op-package-publish")]
mod cargo_package;
mod cargo_pkgid;
mod cargo_read_manifest;
mod cargo_run;
mod cargo_test;
mod cargo_uninstall;
mod common_for_install_and_uninstall;
#[cfg(feature = "op-fix")]
mod fix;
mod lockfile;
mod registry;
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(feature = "op-package-publish"), allow(unused))]

use std::collections::{BTreeMap, HashSet};
use std::fs::File;
use std::io::{self, BufRead};
Expand All @@ -16,6 +18,7 @@ use crate::core::dependency::DepKind;
use crate::core::manifest::ManifestMetadata;
use crate::core::source::Source;
use crate::core::{Package, SourceId, Workspace};
#[cfg(feature = "op-package-publish")]
use crate::ops;
use crate::sources::{RegistrySource, SourceConfigMap, CRATES_IO_REGISTRY};
use crate::util::config::{self, Config, SslVersionConfig, SslVersionConfigRange};
Expand Down Expand Up @@ -50,6 +53,7 @@ pub struct PublishOpts<'cfg> {
pub no_default_features: bool,
}

#[cfg(feature = "op-package-publish")]
pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
let pkg = ws.current()?;

Expand Down Expand Up @@ -170,6 +174,7 @@ fn verify_dependencies(
Ok(())
}

#[cfg(feature = "op-package-publish")]
fn transmit(
config: &Config,
pkg: &Package,
Expand Down