#
cargo/ops/
mod.rs

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