#
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_run::run;
    21pub use self::cargo_test::{TestOptions, run_benches, run_tests};
    22pub use self::cargo_uninstall::uninstall;
    23pub use self::cargo_update::UpdateOptions;
    24pub use self::cargo_update::generate_lockfile;
    25pub use self::cargo_update::print_lockfile_changes;
    26pub use self::cargo_update::update_lockfile;
    27pub use self::cargo_update::upgrade_manifests;
    28pub use self::cargo_update::write_manifest_upgrades;
    29pub use self::common_for_install_and_uninstall::{InstallTracker, resolve_root};
    30pub use self::fix::{
    31    EditionFixMode, FixOptions, fix, fix_edition, fix_exec_rustc, fix_get_proxy_lock_addr,
    32};
    33pub use self::lockfile::{load_pkg_lockfile, resolve_to_string, write_pkg_lockfile};
    34pub use self::registry::OwnersOptions;
    35pub use self::registry::PublishOpts;
    36pub use self::registry::RegistryCredentialConfig;
    37pub use self::registry::RegistryOrIndex;
    38pub use self::registry::info;
    39pub use self::registry::modify_owners;
    40pub use self::registry::publish;
    41pub use self::registry::registry_login;
    42pub use self::registry::registry_logout;
    43pub use self::registry::search;
    44pub use self::registry::yank;
    45pub use self::resolve::{
    46    WorkspaceResolve, add_overrides, get_resolved_packages, resolve_with_previous, resolve_ws,
    47    resolve_ws_with_opts,
    48};
    49pub use self::vendor::{VendorOptions, vendor};
    50
    51pub mod cargo_add;
    52mod cargo_clean;
    53pub(crate) mod cargo_compile;
    54pub mod cargo_config;
    55mod cargo_doc;
    56mod cargo_fetch;
    57mod cargo_install;
    58mod cargo_new;
    59mod cargo_output_metadata;
    60mod cargo_package;
    61mod cargo_pkgid;
    62mod cargo_read_manifest;
    63pub mod cargo_remove;
    64mod cargo_run;
    65mod cargo_test;
    66mod cargo_uninstall;
    67mod cargo_update;
    68mod common_for_install_and_uninstall;
    69mod fix;
    70pub(crate) mod lockfile;
    71pub(crate) mod registry;
    72pub(crate) mod resolve;
    73pub mod tree;
    74mod vendor;
    75
    76/// Returns true if the dependency is either git or path, false otherwise
    77/// Error if a git/path dep is transitive, but has no version (registry source).
    78/// This check is performed on dependencies before publishing or packaging
    79fn check_dep_has_version(dep: &crate::core::Dependency, publish: bool) -> crate::CargoResult<bool> {
    80    let which = if dep.source_id().is_path() {
    81        "path"
    82    } else if dep.source_id().is_git() {
    83        "git"
    84    } else {
    85        return Ok(false);
    86    };
    87
    88    if !dep.specified_req() && dep.is_transitive() {
    89        let dep_version_source = dep.registry_id().map_or_else(
    90            || CRATES_IO_DOMAIN.to_string(),
    91            |registry_id| registry_id.display_registry_name(),
    92        );
    93        anyhow::bail!(
    94            "all dependencies must have a version requirement specified when {}.\n\
    95             dependency `{}` does not specify a version\n\
    96             Note: The {} dependency will use the version from {},\n\
    97             the `{}` specification will be removed from the dependency declaration.",
    98            if publish { "publishing" } else { "packaging" },
    99            dep.package_name(),
    100            if publish { "published" } else { "packaged" },
    101            dep_version_source,
    102            which,
    103        )
    104    }
    105    Ok(true)
    106}