#
cargo/ops/
mod.rs

    1use crate::sources::CRATES_IO_DOMAIN;
    2
    3pub use self::cargo_clean::{CleanContext, CleanOptions, clean};
    4pub use self::cargo_compile::unit_generator::UnitGenerator;
    5pub use self::cargo_compile::{CompileFilter, FilterRule, LibRule, Packages};
    6pub use self::cargo_compile::{
    7    CompileOptions, compile, compile_with_exec, compile_ws, create_bcx, print, resolve_all_features,
    8};
    9pub use self::cargo_doc::{DocOptions, OutputFormat, doc};
    10pub use self::cargo_fetch::{FetchOptions, fetch};
    11pub use self::cargo_install::{install, install_list};
    12pub use self::cargo_new::{NewOptions, NewProjectKind, VersionControl, init, new};
    13pub use self::cargo_output_metadata::{ExportInfo, OutputMetadataOptions, output_metadata};
    14pub use self::cargo_package::PackageMessageFormat;
    15pub use self::cargo_package::PackageOpts;
    16pub use self::cargo_package::check_yanked;
    17pub use self::cargo_package::package;
    18pub use self::cargo_pkgid::pkgid;
    19pub use self::cargo_read_manifest::read_package;
    20pub use self::cargo_report::rebuilds::ReportRebuildsOptions;
    21pub use self::cargo_report::rebuilds::report_rebuilds;
    22pub use self::cargo_report::sessions::ReportSessionsOptions;
    23pub use self::cargo_report::sessions::report_sessions;
    24pub use self::cargo_report::timings::ReportTimingsOptions;
    25pub use self::cargo_report::timings::report_timings;
    26pub use self::cargo_run::run;
    27pub use self::cargo_test::{TestOptions, run_benches, run_tests};
    28pub use self::cargo_uninstall::uninstall;
    29pub use self::cargo_update::UpdateOptions;
    30pub use self::cargo_update::generate_lockfile;
    31pub use self::cargo_update::print_lockfile_changes;
    32pub use self::cargo_update::update_lockfile;
    33pub use self::cargo_update::upgrade_manifests;
    34pub use self::cargo_update::write_manifest_upgrades;
    35pub use self::common_for_install_and_uninstall::{InstallTracker, resolve_root};
    36pub use self::fix::{
    37    EditionFixMode, FixOptions, fix, fix_edition, fix_exec_rustc, fix_get_proxy_lock_addr,
    38};
    39pub use self::lockfile::{load_pkg_lockfile, resolve_to_string, write_pkg_lockfile};
    40pub use self::registry::OwnersOptions;
    41pub use self::registry::PublishOpts;
    42pub use self::registry::RegistryCredentialConfig;
    43pub use self::registry::RegistryOrIndex;
    44pub use self::registry::info;
    45pub use self::registry::modify_owners;
    46pub use self::registry::publish;
    47pub use self::registry::registry_login;
    48pub use self::registry::registry_logout;
    49pub use self::registry::search;
    50pub use self::registry::yank;
    51pub use self::resolve::{
    52    WorkspaceResolve, add_overrides, get_resolved_packages, resolve_with_previous, resolve_ws,
    53    resolve_ws_with_opts,
    54};
    55pub use self::vendor::{VendorOptions, vendor};
    56
    57pub mod cargo_add;
    58mod cargo_clean;
    59pub(crate) mod cargo_compile;
    60pub mod cargo_config;
    61mod cargo_doc;
    62mod cargo_fetch;
    63mod cargo_install;
    64mod cargo_new;
    65mod cargo_output_metadata;
    66mod cargo_package;
    67mod cargo_pkgid;
    68mod cargo_read_manifest;
    69pub mod cargo_remove;
    70mod cargo_report;
    71mod cargo_run;
    72mod cargo_test;
    73mod cargo_uninstall;
    74mod cargo_update;
    75mod common_for_install_and_uninstall;
    76mod fix;
    77pub(crate) mod lockfile;
    78pub(crate) mod registry;
    79pub(crate) mod resolve;
    80pub mod tree;
    81mod vendor;
    82
    83/// Returns true if the dependency is either git or path, false otherwise
    84/// Error if a git/path dep is transitive, but has no version (registry source).
    85/// This check is performed on dependencies before publishing or packaging
    86fn check_dep_has_version(dep: &crate::core::Dependency, publish: bool) -> crate::CargoResult<bool> {
    87    let which = if dep.source_id().is_path() {
    88        "path"
    89    } else if dep.source_id().is_git() {
    90        "git"
    91    } else {
    92        return Ok(false);
    93    };
    94
    95    if !dep.specified_req() && dep.is_transitive() {
    96        let dep_version_source = dep.registry_id().map_or_else(
    97            || CRATES_IO_DOMAIN.to_string(),
    98            |registry_id| registry_id.display_registry_name(),
    99        );
    100        anyhow::bail!(
    101            "all dependencies must have a version requirement specified when {}.\n\
    102             dependency `{}` does not specify a version\n\
    103             Note: The {} dependency will use the version from {},\n\
    104             the `{}` specification will be removed from the dependency declaration.",
    105            if publish { "publishing" } else { "packaging" },
    106            dep.package_name(),
    107            if publish { "published" } else { "packaged" },
    108            dep_version_source,
    109            which,
    110        )
    111    }
    112    Ok(true)
    113}