]> git.proxmox.com Git - rustc.git/blame - src/tools/cargo/src/cargo/ops/mod.rs
New upstream version 1.70.0+dfsg2
[rustc.git] / src / tools / cargo / src / cargo / ops / mod.rs
CommitLineData
0a29b90c
FG
1use crate::sources::CRATES_IO_DOMAIN;
2
3pub use self::cargo_clean::{clean, 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};
9pub use self::cargo_fetch::{fetch, FetchOptions};
10pub use self::cargo_generate_lockfile::generate_lockfile;
11pub use self::cargo_generate_lockfile::update_lockfile;
12pub use self::cargo_generate_lockfile::UpdateOptions;
13pub use self::cargo_install::{install, install_list};
14pub use self::cargo_new::{init, new, NewOptions, NewProjectKind, VersionControl};
15pub use self::cargo_output_metadata::{output_metadata, ExportInfo, OutputMetadataOptions};
16pub use self::cargo_package::{check_yanked, package, package_one, PackageOpts};
17pub use self::cargo_pkgid::pkgid;
18pub use self::cargo_read_manifest::{read_package, read_packages};
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::fix::{fix, fix_exec_rustc, fix_get_proxy_lock_addr, FixOptions};
23pub use self::lockfile::{load_pkg_lockfile, resolve_to_string, write_pkg_lockfile};
24pub use self::registry::HttpTimeout;
25pub use self::registry::{configure_http_handle, http_handle, http_handle_and_timeout};
26pub use self::registry::{modify_owners, yank, OwnersOptions, PublishOpts};
27pub use self::registry::{needs_custom_http_transport, registry_login, registry_logout, search};
28pub use self::registry::{publish, RegistryCredentialConfig};
29pub use self::resolve::{
30 add_overrides, get_resolved_packages, resolve_with_previous, resolve_ws, resolve_ws_with_opts,
31 WorkspaceResolve,
32};
33pub use self::vendor::{vendor, VendorOptions};
34
35pub mod cargo_add;
36mod cargo_clean;
37pub(crate) mod cargo_compile;
38pub mod cargo_config;
39mod cargo_doc;
40mod cargo_fetch;
41mod cargo_generate_lockfile;
42mod cargo_install;
43mod cargo_new;
44mod cargo_output_metadata;
45mod cargo_package;
46mod cargo_pkgid;
47mod cargo_read_manifest;
48pub mod cargo_remove;
49mod cargo_run;
50mod cargo_test;
51mod cargo_uninstall;
52mod common_for_install_and_uninstall;
53mod fix;
54pub(crate) mod lockfile;
55pub(crate) mod registry;
56pub(crate) mod resolve;
57pub mod tree;
58mod vendor;
59
60/// Returns true if the dependency is either git or path, false otherwise
61/// Error if a git/path dep is transitive, but has no version (registry source).
62/// This check is performed on dependencies before publishing or packaging
63fn check_dep_has_version(dep: &crate::core::Dependency, publish: bool) -> crate::CargoResult<bool> {
64 let which = if dep.source_id().is_path() {
65 "path"
66 } else if dep.source_id().is_git() {
67 "git"
68 } else {
69 return Ok(false);
70 };
71
72 if !dep.specified_req() && dep.is_transitive() {
73 let dep_version_source = dep.registry_id().map_or_else(
74 || CRATES_IO_DOMAIN.to_string(),
75 |registry_id| registry_id.display_registry_name(),
76 );
77 anyhow::bail!(
78 "all dependencies must have a version specified when {}.\n\
79 dependency `{}` does not specify a version\n\
80 Note: The {} dependency will use the version from {},\n\
81 the `{}` specification will be removed from the dependency declaration.",
82 if publish { "publishing" } else { "packaging" },
83 dep.package_name(),
84 if publish { "published" } else { "packaged" },
85 dep_version_source,
86 which,
87 )
88 }
89 Ok(true)
90}