2019-09-12 17:14:29 +00:00
|
|
|
use crate::git::repo;
|
|
|
|
use crate::paths;
|
2018-12-30 04:46:15 +00:00
|
|
|
use cargo::sources::CRATES_IO_INDEX;
|
2018-03-01 17:45:56 +00:00
|
|
|
use cargo::util::Sha256;
|
2015-02-27 01:04:25 +00:00
|
|
|
use flate2::write::GzEncoder;
|
2018-08-28 09:20:03 +00:00
|
|
|
use flate2::Compression;
|
2019-09-12 17:14:29 +00:00
|
|
|
use std::collections::HashMap;
|
2021-01-28 19:54:27 +00:00
|
|
|
use std::fmt::Write as _;
|
2019-09-12 17:14:29 +00:00
|
|
|
use std::fs::{self, File};
|
2021-01-28 19:54:27 +00:00
|
|
|
use std::io::{BufRead, BufReader, Write};
|
|
|
|
use std::net::TcpListener;
|
2019-09-12 17:14:29 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
2021-01-28 19:54:27 +00:00
|
|
|
use std::thread;
|
2016-01-20 17:07:47 +00:00
|
|
|
use tar::{Builder, Header};
|
2014-10-23 05:05:30 +00:00
|
|
|
use url::Url;
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Gets the path to the local index pretending to be crates.io. This is a Git repo
|
2019-01-11 23:56:46 +00:00
|
|
|
/// initialized with a `config.json` file pointing to `dl_path` for downloads
|
|
|
|
/// and `api_path` for uploads.
|
2018-03-14 15:17:44 +00:00
|
|
|
pub fn registry_path() -> PathBuf {
|
2019-12-17 03:31:01 +00:00
|
|
|
generate_path("registry")
|
2018-03-14 15:17:44 +00:00
|
|
|
}
|
2019-01-11 23:56:46 +00:00
|
|
|
pub fn registry_url() -> Url {
|
2019-12-17 03:31:01 +00:00
|
|
|
generate_url("registry")
|
2018-03-14 15:17:44 +00:00
|
|
|
}
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Gets the path for local web API uploads. Cargo will place the contents of a web API
|
|
|
|
/// request here. For example, `api/v1/crates/new` is the result of publishing a crate.
|
2018-07-17 02:20:39 +00:00
|
|
|
pub fn api_path() -> PathBuf {
|
2019-12-17 03:31:01 +00:00
|
|
|
generate_path("api")
|
2018-07-17 02:20:39 +00:00
|
|
|
}
|
2019-01-11 23:56:46 +00:00
|
|
|
pub fn api_url() -> Url {
|
2019-12-17 03:31:01 +00:00
|
|
|
generate_url("api")
|
2019-01-11 23:56:46 +00:00
|
|
|
}
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Gets the path where crates can be downloaded using the web API endpoint. Crates
|
2019-01-11 23:56:46 +00:00
|
|
|
/// should be organized as `{name}/{version}/download` to match the web API
|
|
|
|
/// endpoint. This is rarely used and must be manually set up.
|
2018-03-14 15:17:44 +00:00
|
|
|
pub fn dl_path() -> PathBuf {
|
2019-12-17 03:31:01 +00:00
|
|
|
generate_path("dl")
|
2018-03-14 15:17:44 +00:00
|
|
|
}
|
|
|
|
pub fn dl_url() -> Url {
|
2019-12-17 03:31:01 +00:00
|
|
|
generate_url("dl")
|
2018-03-14 15:17:44 +00:00
|
|
|
}
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Gets the alternative-registry version of `registry_path`.
|
2018-03-14 15:17:44 +00:00
|
|
|
pub fn alt_registry_path() -> PathBuf {
|
2019-12-17 03:31:01 +00:00
|
|
|
generate_path("alternative-registry")
|
2018-03-14 15:17:44 +00:00
|
|
|
}
|
2019-01-11 23:56:46 +00:00
|
|
|
pub fn alt_registry_url() -> Url {
|
2019-12-17 03:31:01 +00:00
|
|
|
generate_url("alternative-registry")
|
2018-03-14 15:17:44 +00:00
|
|
|
}
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Gets the alternative-registry version of `dl_path`.
|
2018-03-14 15:17:44 +00:00
|
|
|
pub fn alt_dl_path() -> PathBuf {
|
2019-12-17 03:31:01 +00:00
|
|
|
generate_path("alt_dl")
|
2018-03-14 15:17:44 +00:00
|
|
|
}
|
2017-12-18 23:22:04 +00:00
|
|
|
pub fn alt_dl_url() -> String {
|
2019-12-17 03:31:01 +00:00
|
|
|
generate_alt_dl_url("alt_dl")
|
2017-12-18 23:22:04 +00:00
|
|
|
}
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Gets the alternative-registry version of `api_path`.
|
2018-03-14 15:17:44 +00:00
|
|
|
pub fn alt_api_path() -> PathBuf {
|
2019-12-17 03:31:01 +00:00
|
|
|
generate_path("alt_api")
|
2018-03-14 15:17:44 +00:00
|
|
|
}
|
|
|
|
pub fn alt_api_url() -> Url {
|
2019-12-17 03:31:01 +00:00
|
|
|
generate_url("alt_api")
|
2018-03-14 15:17:44 +00:00
|
|
|
}
|
2019-12-14 03:42:00 +00:00
|
|
|
|
2019-12-17 03:31:01 +00:00
|
|
|
pub fn generate_path(name: &str) -> PathBuf {
|
2019-12-14 03:42:00 +00:00
|
|
|
paths::root().join(name)
|
2019-12-13 12:54:07 +00:00
|
|
|
}
|
2019-12-17 00:59:45 +00:00
|
|
|
pub fn generate_url(name: &str) -> Url {
|
2019-12-14 03:42:00 +00:00
|
|
|
Url::from_file_path(generate_path(name)).ok().unwrap()
|
|
|
|
}
|
2019-12-17 03:31:01 +00:00
|
|
|
pub fn generate_alt_dl_url(name: &str) -> String {
|
2019-12-14 03:42:00 +00:00
|
|
|
let base = Url::from_file_path(generate_path(name)).ok().unwrap();
|
|
|
|
format!("{}/{{crate}}/{{version}}/{{crate}}-{{version}}.crate", base)
|
2019-12-13 12:54:07 +00:00
|
|
|
}
|
2014-10-23 05:05:30 +00:00
|
|
|
|
2021-01-28 19:54:27 +00:00
|
|
|
/// A builder for initializing registries.
|
|
|
|
pub struct RegistryBuilder {
|
|
|
|
/// If `true`, adds source replacement for crates.io to a registry on the filesystem.
|
|
|
|
replace_crates_io: bool,
|
|
|
|
/// If `true`, configures a registry named "alternative".
|
|
|
|
alternative: bool,
|
|
|
|
/// If set, sets the API url for the "alternative" registry.
|
|
|
|
/// This defaults to a directory on the filesystem.
|
|
|
|
alt_api_url: Option<String>,
|
|
|
|
/// If `true`, configures `.cargo/credentials` with some tokens.
|
|
|
|
add_tokens: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RegistryBuilder {
|
|
|
|
pub fn new() -> RegistryBuilder {
|
|
|
|
RegistryBuilder {
|
|
|
|
replace_crates_io: true,
|
|
|
|
alternative: false,
|
|
|
|
alt_api_url: None,
|
|
|
|
add_tokens: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets whether or not to replace crates.io with a registry on the filesystem.
|
|
|
|
/// Default is `true`.
|
|
|
|
pub fn replace_crates_io(&mut self, replace: bool) -> &mut Self {
|
|
|
|
self.replace_crates_io = replace;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets whether or not to initialize an alternative registry named "alternative".
|
|
|
|
/// Default is `false`.
|
|
|
|
pub fn alternative(&mut self, alt: bool) -> &mut Self {
|
|
|
|
self.alternative = alt;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets the API url for the "alternative" registry.
|
|
|
|
/// Defaults to a path on the filesystem ([`alt_api_path`]).
|
|
|
|
pub fn alternative_api_url(&mut self, url: &str) -> &mut Self {
|
|
|
|
self.alternative = true;
|
|
|
|
self.alt_api_url = Some(url.to_string());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets whether or not to initialize `.cargo/credentials` with some tokens.
|
|
|
|
/// Defaults to `true`.
|
|
|
|
pub fn add_tokens(&mut self, add: bool) -> &mut Self {
|
|
|
|
self.add_tokens = add;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Initializes the registries.
|
|
|
|
pub fn build(&self) {
|
|
|
|
let config_path = paths::home().join(".cargo/config");
|
|
|
|
if config_path.exists() {
|
|
|
|
panic!(
|
|
|
|
"{} already exists, the registry may only be initialized once, \
|
|
|
|
and must be done before the config file is created",
|
|
|
|
config_path.display()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
t!(fs::create_dir_all(config_path.parent().unwrap()));
|
|
|
|
let mut config = String::new();
|
|
|
|
if self.replace_crates_io {
|
|
|
|
write!(
|
|
|
|
&mut config,
|
|
|
|
"
|
|
|
|
[source.crates-io]
|
|
|
|
replace-with = 'dummy-registry'
|
|
|
|
|
|
|
|
[source.dummy-registry]
|
|
|
|
registry = '{}'
|
|
|
|
",
|
|
|
|
registry_url()
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
if self.alternative {
|
|
|
|
write!(
|
|
|
|
config,
|
|
|
|
"
|
|
|
|
[registries.alternative]
|
|
|
|
index = '{}'
|
|
|
|
",
|
|
|
|
alt_registry_url()
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
t!(fs::write(&config_path, config));
|
|
|
|
|
|
|
|
if self.add_tokens {
|
|
|
|
let credentials = paths::home().join(".cargo/credentials");
|
|
|
|
t!(fs::write(
|
|
|
|
&credentials,
|
|
|
|
r#"
|
|
|
|
[registry]
|
|
|
|
token = "api-token"
|
|
|
|
|
|
|
|
[registries.alternative]
|
|
|
|
token = "api-token"
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.replace_crates_io {
|
|
|
|
init_registry(
|
|
|
|
registry_path(),
|
|
|
|
dl_url().into_string(),
|
|
|
|
api_url(),
|
|
|
|
api_path(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.alternative {
|
|
|
|
init_registry(
|
|
|
|
alt_registry_path(),
|
|
|
|
alt_dl_url(),
|
|
|
|
self.alt_api_url
|
|
|
|
.as_ref()
|
|
|
|
.map_or_else(alt_api_url, |url| Url::parse(&url).expect("valid url")),
|
|
|
|
alt_api_path(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Initializes the registries, and sets up an HTTP server for the
|
|
|
|
/// "alternative" registry.
|
|
|
|
///
|
|
|
|
/// The given callback takes a `Vec` of headers when a request comes in.
|
|
|
|
/// The first entry should be the HTTP command, such as
|
|
|
|
/// `PUT /api/v1/crates/new HTTP/1.1`.
|
|
|
|
///
|
|
|
|
/// The callback should return the HTTP code for the response, and the
|
|
|
|
/// response body.
|
|
|
|
///
|
|
|
|
/// This method returns a `JoinHandle` which you should call
|
|
|
|
/// `.join().unwrap()` on before exiting the test.
|
|
|
|
pub fn build_api_server<'a>(
|
|
|
|
&mut self,
|
|
|
|
handler: &'static (dyn (Fn(Vec<String>) -> (u32, &'a dyn AsRef<[u8]>)) + Sync),
|
|
|
|
) -> thread::JoinHandle<()> {
|
|
|
|
let server = TcpListener::bind("127.0.0.1:0").unwrap();
|
|
|
|
let addr = server.local_addr().unwrap();
|
|
|
|
let api_url = format!("http://{}", addr);
|
|
|
|
|
|
|
|
self.replace_crates_io(false)
|
|
|
|
.alternative_api_url(&api_url)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let t = thread::spawn(move || {
|
|
|
|
let mut conn = BufReader::new(server.accept().unwrap().0);
|
|
|
|
let headers: Vec<_> = (&mut conn)
|
|
|
|
.lines()
|
|
|
|
.map(|s| s.unwrap())
|
|
|
|
.take_while(|s| s.len() > 2)
|
|
|
|
.map(|s| s.trim().to_string())
|
|
|
|
.collect();
|
|
|
|
let (code, response) = handler(headers);
|
|
|
|
let response = response.as_ref();
|
|
|
|
let stream = conn.get_mut();
|
|
|
|
write!(
|
|
|
|
stream,
|
|
|
|
"HTTP/1.1 {}\r\n\
|
|
|
|
Content-Length: {}\r\n\
|
|
|
|
\r\n",
|
|
|
|
code,
|
|
|
|
response.len()
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
stream.write_all(response).unwrap();
|
|
|
|
});
|
|
|
|
|
|
|
|
t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-24 22:09:38 +00:00
|
|
|
/// A builder for creating a new package in a registry.
|
|
|
|
///
|
|
|
|
/// This uses "source replacement" using an automatically generated
|
|
|
|
/// `.cargo/config` file to ensure that dependencies will use these packages
|
|
|
|
/// instead of contacting crates.io. See `source-replacement.md` for more
|
|
|
|
/// details on how source replacement works.
|
|
|
|
///
|
|
|
|
/// Call `publish` to finalize and create the package.
|
|
|
|
///
|
|
|
|
/// If no files are specified, an empty `lib.rs` file is automatically created.
|
|
|
|
///
|
|
|
|
/// The `Cargo.toml` file is automatically generated based on the methods
|
|
|
|
/// called on `Package` (for example, calling `dep()` will add to the
|
|
|
|
/// `[dependencies]` automatically). You may also specify a `Cargo.toml` file
|
|
|
|
/// to override the generated one.
|
|
|
|
///
|
|
|
|
/// This supports different registry types:
|
|
|
|
/// - Regular source replacement that replaces `crates.io` (the default).
|
|
|
|
/// - A "local registry" which is a subset for vendoring (see
|
|
|
|
/// `Package::local`).
|
|
|
|
/// - An "alternative registry" which requires specifying the registry name
|
|
|
|
/// (see `Package::alternative`).
|
|
|
|
///
|
|
|
|
/// This does not support "directory sources". See `directory.rs` for
|
|
|
|
/// `VendorPackage` which implements directory sources.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
/// ```
|
|
|
|
/// // Publish package "a" depending on "b".
|
|
|
|
/// Package::new("a", "1.0.0")
|
|
|
|
/// .dep("b", "1.0.0")
|
|
|
|
/// .file("src/lib.rs", r#"
|
|
|
|
/// extern crate b;
|
|
|
|
/// pub fn f() -> i32 { b::f() * 2 }
|
|
|
|
/// "#)
|
|
|
|
/// .publish();
|
|
|
|
///
|
|
|
|
/// // Publish package "b".
|
|
|
|
/// Package::new("b", "1.0.0")
|
|
|
|
/// .file("src/lib.rs", r#"
|
|
|
|
/// pub fn f() -> i32 { 12 }
|
|
|
|
/// "#)
|
|
|
|
/// .publish();
|
|
|
|
///
|
|
|
|
/// // Create a project that uses package "a".
|
|
|
|
/// let p = project()
|
|
|
|
/// .file("Cargo.toml", r#"
|
|
|
|
/// [package]
|
|
|
|
/// name = "foo"
|
|
|
|
/// version = "0.0.1"
|
|
|
|
///
|
|
|
|
/// [dependencies]
|
|
|
|
/// a = "1.0"
|
|
|
|
/// "#)
|
|
|
|
/// .file("src/main.rs", r#"
|
|
|
|
/// extern crate a;
|
|
|
|
/// fn main() { println!("{}", a::f()); }
|
|
|
|
/// "#)
|
|
|
|
/// .build();
|
|
|
|
///
|
2018-08-29 06:37:21 +00:00
|
|
|
/// p.cargo("run").with_stdout("24").run();
|
2018-08-24 22:09:38 +00:00
|
|
|
/// ```
|
2019-04-02 20:27:42 +00:00
|
|
|
#[must_use]
|
2015-11-11 02:08:06 +00:00
|
|
|
pub struct Package {
|
|
|
|
name: String,
|
|
|
|
vers: String,
|
2016-03-14 22:45:05 +00:00
|
|
|
deps: Vec<Dependency>,
|
2015-11-11 02:08:06 +00:00
|
|
|
files: Vec<(String, String)>,
|
2017-09-14 17:07:15 +00:00
|
|
|
extra_files: Vec<(String, String)>,
|
2015-11-11 02:08:06 +00:00
|
|
|
yanked: bool,
|
2016-03-14 22:45:05 +00:00
|
|
|
features: HashMap<String, Vec<String>>,
|
2016-02-05 23:14:17 +00:00
|
|
|
local: bool,
|
2017-08-30 05:55:31 +00:00
|
|
|
alternative: bool,
|
2019-05-06 18:35:17 +00:00
|
|
|
invalid_json: bool,
|
2020-03-15 22:59:42 +00:00
|
|
|
proc_macro: bool,
|
2020-05-22 15:38:40 +00:00
|
|
|
links: Option<String>,
|
2020-03-24 21:31:28 +00:00
|
|
|
rust_version: Option<String>,
|
|
|
|
cargo_features: Vec<String>,
|
2016-03-14 22:45:05 +00:00
|
|
|
}
|
|
|
|
|
2018-09-07 16:37:06 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Dependency {
|
2016-03-14 22:45:05 +00:00
|
|
|
name: String,
|
|
|
|
vers: String,
|
|
|
|
kind: String,
|
|
|
|
target: Option<String>,
|
|
|
|
features: Vec<String>,
|
2017-10-22 07:44:11 +00:00
|
|
|
registry: Option<String>,
|
2018-09-07 16:37:06 +00:00
|
|
|
package: Option<String>,
|
|
|
|
optional: bool,
|
2015-11-11 02:08:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 19:54:27 +00:00
|
|
|
/// Initializes the on-disk registry and sets up the config so that crates.io
|
|
|
|
/// is replaced with the one on disk.
|
Add sha256 checksums to the lockfile
This commit changes how lock files are encoded by checksums for each package in
the lockfile to the `[metadata]` section. The previous commit implemented the
ability to redirect sources, but the core assumption there was that a package
coming from two different locations was always the same. An inevitable case,
however, is that a source gets corrupted or, worse, ships a modified version of
a crate to introduce instability between two "mirrors".
The purpose of adding checksums will be to resolve this discrepancy. Each crate
coming from crates.io will now record its sha256 checksum in the lock file. When
a lock file already exists, the new checksum for a crate will be checked against
it, and if they differ compilation will be aborted. Currently only registry
crates will have sha256 checksums listed, all other sources do not have
checksums at this time.
The astute may notice that if the lock file format is changing, then a lock file
generated by a newer Cargo might be mangled by an older Cargo. In anticipation
of this, however, all Cargo versions published support a `[metadata]` section of
the lock file which is transparently carried forward if encountered. This means
that older Cargos compiling with a newer lock file will not verify checksums in
the lock file, but they will carry forward the checksum information and prevent
it from being removed.
There are, however, a few situations where problems may still arise:
1. If an older Cargo takes a newer lockfile (with checksums) and updates it with
a modified `Cargo.toml` (e.g. a package was added, removed, or updated), then
the `[metadata]` section will not be updated appropriately. This modification
would require a newer Cargo to come in and update the checksums for such a
modification.
2. Today Cargo can only calculate checksums for registry sources, but we may
eventually want to support other sources like git (or just straight-up path
sources). If future Cargo implements support for this sort of checksum, then
it's the same problem as above where older Cargos will not know how to keep
the checksum in sync
2016-02-03 19:04:07 +00:00
|
|
|
pub fn init() {
|
2014-11-21 17:36:18 +00:00
|
|
|
let config = paths::home().join(".cargo/config");
|
2020-04-17 01:41:03 +00:00
|
|
|
if config.exists() {
|
2018-03-14 15:17:44 +00:00
|
|
|
return;
|
2015-11-11 02:08:06 +00:00
|
|
|
}
|
2021-01-28 19:54:27 +00:00
|
|
|
RegistryBuilder::new().build();
|
|
|
|
}
|
2017-08-30 05:55:31 +00:00
|
|
|
|
2021-01-28 19:54:27 +00:00
|
|
|
/// Variant of `init` that initializes the "alternative" registry.
|
|
|
|
pub fn alt_init() {
|
|
|
|
RegistryBuilder::new().alternative(true).build();
|
2019-12-14 03:42:00 +00:00
|
|
|
}
|
2019-12-13 12:54:07 +00:00
|
|
|
|
2021-01-28 19:54:27 +00:00
|
|
|
/// Creates a new on-disk registry.
|
2019-12-17 05:12:27 +00:00
|
|
|
pub fn init_registry(registry_path: PathBuf, dl_url: String, api_url: Url, api_path: PathBuf) {
|
|
|
|
// Initialize a new registry.
|
|
|
|
repo(®istry_path)
|
2019-12-13 12:54:07 +00:00
|
|
|
.file(
|
|
|
|
"config.json",
|
2021-01-28 19:54:27 +00:00
|
|
|
&format!(r#"{{"dl":"{}","api":"{}"}}"#, dl_url, api_url),
|
2019-12-13 12:54:07 +00:00
|
|
|
)
|
|
|
|
.build();
|
2019-12-17 05:12:27 +00:00
|
|
|
fs::create_dir_all(api_path.join("api/v1/crates")).unwrap();
|
2014-10-23 05:05:30 +00:00
|
|
|
}
|
|
|
|
|
2015-11-11 02:08:06 +00:00
|
|
|
impl Package {
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Creates a new package builder.
|
2018-08-24 22:09:38 +00:00
|
|
|
/// Call `publish()` to finalize and build the package.
|
2015-11-11 02:08:06 +00:00
|
|
|
pub fn new(name: &str, vers: &str) -> Package {
|
|
|
|
init();
|
|
|
|
Package {
|
|
|
|
name: name.to_string(),
|
|
|
|
vers: vers.to_string(),
|
|
|
|
deps: Vec::new(),
|
|
|
|
files: Vec::new(),
|
2017-09-14 17:07:15 +00:00
|
|
|
extra_files: Vec::new(),
|
2015-11-11 02:08:06 +00:00
|
|
|
yanked: false,
|
2016-03-14 22:45:05 +00:00
|
|
|
features: HashMap::new(),
|
2016-02-05 23:14:17 +00:00
|
|
|
local: false,
|
2017-08-30 05:55:31 +00:00
|
|
|
alternative: false,
|
2019-05-06 18:35:17 +00:00
|
|
|
invalid_json: false,
|
2020-03-15 22:59:42 +00:00
|
|
|
proc_macro: false,
|
2020-05-22 15:38:40 +00:00
|
|
|
links: None,
|
2020-03-24 21:31:28 +00:00
|
|
|
rust_version: None,
|
|
|
|
cargo_features: Vec::new(),
|
2015-11-11 02:08:06 +00:00
|
|
|
}
|
2014-10-23 05:05:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 22:09:38 +00:00
|
|
|
/// Call with `true` to publish in a "local registry".
|
|
|
|
///
|
|
|
|
/// See `source-replacement.html#local-registry-sources` for more details
|
|
|
|
/// on local registries. See `local_registry.rs` for the tests that use
|
|
|
|
/// this.
|
2016-02-05 23:14:17 +00:00
|
|
|
pub fn local(&mut self, local: bool) -> &mut Package {
|
|
|
|
self.local = local;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2018-08-24 22:09:38 +00:00
|
|
|
/// Call with `true` to publish in an "alternative registry".
|
|
|
|
///
|
|
|
|
/// The name of the alternative registry is called "alternative".
|
|
|
|
///
|
2019-02-11 23:16:13 +00:00
|
|
|
/// See `src/doc/src/reference/registries.md` for more details on
|
2018-08-24 22:09:38 +00:00
|
|
|
/// alternative registries. See `alt_registry.rs` for the tests that use
|
|
|
|
/// this.
|
2017-08-30 05:55:31 +00:00
|
|
|
pub fn alternative(&mut self, alternative: bool) -> &mut Package {
|
|
|
|
self.alternative = alternative;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Adds a file to the package.
|
2015-11-11 02:08:06 +00:00
|
|
|
pub fn file(&mut self, name: &str, contents: &str) -> &mut Package {
|
|
|
|
self.files.push((name.to_string(), contents.to_string()));
|
|
|
|
self
|
|
|
|
}
|
2014-10-23 05:05:30 +00:00
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Adds an "extra" file that is not rooted within the package.
|
2018-08-24 22:09:38 +00:00
|
|
|
///
|
|
|
|
/// Normal files are automatically placed within a directory named
|
|
|
|
/// `$PACKAGE-$VERSION`. This allows you to override that behavior,
|
|
|
|
/// typically for testing invalid behavior.
|
2017-09-14 17:07:15 +00:00
|
|
|
pub fn extra_file(&mut self, name: &str, contents: &str) -> &mut Package {
|
2018-03-14 15:17:44 +00:00
|
|
|
self.extra_files
|
|
|
|
.push((name.to_string(), contents.to_string()));
|
2017-09-14 17:07:15 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Adds a normal dependency. Example:
|
2018-08-24 22:09:38 +00:00
|
|
|
/// ```
|
|
|
|
/// [dependencies]
|
|
|
|
/// foo = {version = "1.0"}
|
|
|
|
/// ```
|
2015-11-11 02:08:06 +00:00
|
|
|
pub fn dep(&mut self, name: &str, vers: &str) -> &mut Package {
|
2018-09-07 16:37:06 +00:00
|
|
|
self.add_dep(&Dependency::new(name, vers))
|
2016-03-14 22:45:05 +00:00
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Adds a dependency with the given feature. Example:
|
2018-08-24 22:09:38 +00:00
|
|
|
/// ```
|
|
|
|
/// [dependencies]
|
|
|
|
/// foo = {version = "1.0", "features": ["feat1", "feat2"]}
|
|
|
|
/// ```
|
2018-03-14 15:17:44 +00:00
|
|
|
pub fn feature_dep(&mut self, name: &str, vers: &str, features: &[&str]) -> &mut Package {
|
2018-09-07 16:37:06 +00:00
|
|
|
self.add_dep(Dependency::new(name, vers).enable_features(features))
|
2016-01-26 00:54:10 +00:00
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Adds a platform-specific dependency. Example:
|
2018-08-24 22:09:38 +00:00
|
|
|
/// ```
|
|
|
|
/// [target.'cfg(windows)'.dependencies]
|
|
|
|
/// foo = {version = "1.0"}
|
|
|
|
/// ```
|
2018-03-14 15:17:44 +00:00
|
|
|
pub fn target_dep(&mut self, name: &str, vers: &str, target: &str) -> &mut Package {
|
2018-09-07 16:37:06 +00:00
|
|
|
self.add_dep(Dependency::new(name, vers).target(target))
|
2017-10-22 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Adds a dependency to the alternative registry.
|
2018-12-30 04:46:15 +00:00
|
|
|
pub fn registry_dep(&mut self, name: &str, vers: &str) -> &mut Package {
|
|
|
|
self.add_dep(Dependency::new(name, vers).registry("alternative"))
|
2015-11-11 02:08:06 +00:00
|
|
|
}
|
2014-10-23 19:21:08 +00:00
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Adds a dev-dependency. Example:
|
2018-08-24 22:09:38 +00:00
|
|
|
/// ```
|
|
|
|
/// [dev-dependencies]
|
|
|
|
/// foo = {version = "1.0"}
|
|
|
|
/// ```
|
2015-11-11 02:08:06 +00:00
|
|
|
pub fn dev_dep(&mut self, name: &str, vers: &str) -> &mut Package {
|
2018-09-07 16:37:06 +00:00
|
|
|
self.add_dep(Dependency::new(name, vers).dev())
|
2016-03-14 22:45:05 +00:00
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Adds a build-dependency. Example:
|
2018-08-24 22:09:38 +00:00
|
|
|
/// ```
|
|
|
|
/// [build-dependencies]
|
|
|
|
/// foo = {version = "1.0"}
|
|
|
|
/// ```
|
2018-08-24 04:49:43 +00:00
|
|
|
pub fn build_dep(&mut self, name: &str, vers: &str) -> &mut Package {
|
2018-09-07 16:37:06 +00:00
|
|
|
self.add_dep(Dependency::new(name, vers).build())
|
2018-08-24 04:49:43 +00:00
|
|
|
}
|
|
|
|
|
2018-09-07 16:37:06 +00:00
|
|
|
pub fn add_dep(&mut self, dep: &Dependency) -> &mut Package {
|
|
|
|
self.deps.push(dep.clone());
|
2015-11-11 02:08:06 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Specifies whether or not the package is "yanked".
|
2015-11-11 02:08:06 +00:00
|
|
|
pub fn yanked(&mut self, yanked: bool) -> &mut Package {
|
|
|
|
self.yanked = yanked;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-03-15 22:59:42 +00:00
|
|
|
/// Specifies whether or not this is a proc macro.
|
|
|
|
pub fn proc_macro(&mut self, proc_macro: bool) -> &mut Package {
|
|
|
|
self.proc_macro = proc_macro;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Adds an entry in the `[features]` section.
|
2018-09-07 16:37:06 +00:00
|
|
|
pub fn feature(&mut self, name: &str, deps: &[&str]) -> &mut Package {
|
|
|
|
let deps = deps.iter().map(|s| s.to_string()).collect();
|
|
|
|
self.features.insert(name.to_string(), deps);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-03-24 21:31:28 +00:00
|
|
|
/// Specify a minimal Rust version.
|
|
|
|
pub fn rust_version(&mut self, rust_version: &str) -> &mut Package {
|
|
|
|
self.rust_version = Some(rust_version.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-05-06 18:35:17 +00:00
|
|
|
/// Causes the JSON line emitted in the index to be invalid, presumably
|
|
|
|
/// causing Cargo to skip over this version.
|
|
|
|
pub fn invalid_json(&mut self, invalid: bool) -> &mut Package {
|
|
|
|
self.invalid_json = invalid;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-22 15:38:40 +00:00
|
|
|
pub fn links(&mut self, links: &str) -> &mut Package {
|
|
|
|
self.links = Some(links.to_string());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-03-24 21:31:28 +00:00
|
|
|
pub fn cargo_feature(&mut self, feature: &str) -> &mut Package {
|
|
|
|
self.cargo_features.push(feature.to_owned());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Creates the package and place it in the registry.
|
2018-08-24 22:09:38 +00:00
|
|
|
///
|
|
|
|
/// This does not actually use Cargo's publishing system, but instead
|
|
|
|
/// manually creates the entry in the registry on the filesystem.
|
|
|
|
///
|
|
|
|
/// Returns the checksum for the package.
|
2016-07-05 17:28:51 +00:00
|
|
|
pub fn publish(&self) -> String {
|
2015-11-11 02:08:06 +00:00
|
|
|
self.make_archive();
|
2014-10-23 05:05:30 +00:00
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
// Figure out what we're going to write into the index.
|
2018-08-28 09:20:03 +00:00
|
|
|
let deps = self
|
|
|
|
.deps
|
2018-03-14 15:17:44 +00:00
|
|
|
.iter()
|
|
|
|
.map(|dep| {
|
2018-12-30 04:46:15 +00:00
|
|
|
// In the index, the `registry` is null if it is from the same registry.
|
|
|
|
// In Cargo.toml, it is None if it is from crates.io.
|
2020-03-16 01:51:38 +00:00
|
|
|
let registry_url = match (self.alternative, dep.registry.as_deref()) {
|
|
|
|
(false, None) => None,
|
|
|
|
(false, Some("alternative")) => Some(alt_registry_url().to_string()),
|
|
|
|
(true, None) => Some(CRATES_IO_INDEX.to_string()),
|
|
|
|
(true, Some("alternative")) => None,
|
|
|
|
_ => panic!("registry_dep currently only supports `alternative`"),
|
|
|
|
};
|
2018-12-11 01:55:13 +00:00
|
|
|
serde_json::json!({
|
2018-09-07 16:37:06 +00:00
|
|
|
"name": dep.name,
|
|
|
|
"req": dep.vers,
|
|
|
|
"features": dep.features,
|
|
|
|
"default_features": true,
|
|
|
|
"target": dep.target,
|
|
|
|
"optional": dep.optional,
|
|
|
|
"kind": dep.kind,
|
2018-12-30 04:46:15 +00:00
|
|
|
"registry": registry_url,
|
2018-09-07 16:37:06 +00:00
|
|
|
"package": dep.package,
|
|
|
|
})
|
2018-12-08 11:19:47 +00:00
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
2015-11-11 02:08:06 +00:00
|
|
|
let cksum = {
|
2020-04-17 04:10:11 +00:00
|
|
|
let c = t!(fs::read(&self.archive_dst()));
|
2015-11-11 02:08:06 +00:00
|
|
|
cksum(&c)
|
|
|
|
};
|
2019-05-06 18:35:17 +00:00
|
|
|
let name = if self.invalid_json {
|
|
|
|
serde_json::json!(1)
|
|
|
|
} else {
|
|
|
|
serde_json::json!(self.name)
|
|
|
|
};
|
2018-12-11 01:55:13 +00:00
|
|
|
let line = serde_json::json!({
|
2019-05-06 18:35:17 +00:00
|
|
|
"name": name,
|
2017-02-10 20:01:52 +00:00
|
|
|
"vers": self.vers,
|
|
|
|
"deps": deps,
|
|
|
|
"cksum": cksum,
|
|
|
|
"features": self.features,
|
|
|
|
"yanked": self.yanked,
|
2020-05-22 15:38:40 +00:00
|
|
|
"links": self.links,
|
2018-12-08 11:19:47 +00:00
|
|
|
})
|
|
|
|
.to_string();
|
2016-03-14 22:45:05 +00:00
|
|
|
|
2015-11-11 02:08:06 +00:00
|
|
|
let file = match self.name.len() {
|
|
|
|
1 => format!("1/{}", self.name),
|
|
|
|
2 => format!("2/{}", self.name),
|
|
|
|
3 => format!("3/{}/{}", &self.name[..1], self.name),
|
|
|
|
_ => format!("{}/{}/{}", &self.name[0..2], &self.name[2..4], self.name),
|
|
|
|
};
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
let registry_path = if self.alternative {
|
|
|
|
alt_registry_path()
|
|
|
|
} else {
|
|
|
|
registry_path()
|
|
|
|
};
|
2017-08-30 05:55:31 +00:00
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
// Write file/line in the index.
|
2016-02-05 23:14:17 +00:00
|
|
|
let dst = if self.local {
|
2017-08-30 05:55:31 +00:00
|
|
|
registry_path.join("index").join(&file)
|
2016-02-05 23:14:17 +00:00
|
|
|
} else {
|
2017-08-30 05:55:31 +00:00
|
|
|
registry_path.join(&file)
|
2016-02-05 23:14:17 +00:00
|
|
|
};
|
2020-04-30 22:48:38 +00:00
|
|
|
let prev = fs::read_to_string(&dst).unwrap_or_default();
|
2016-05-26 00:06:25 +00:00
|
|
|
t!(fs::create_dir_all(dst.parent().unwrap()));
|
2020-04-17 04:10:11 +00:00
|
|
|
t!(fs::write(&dst, prev + &line[..] + "\n"));
|
2015-11-11 02:08:06 +00:00
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
// Add the new file to the index.
|
2016-02-05 23:14:17 +00:00
|
|
|
if !self.local {
|
2017-08-30 05:55:31 +00:00
|
|
|
let repo = t!(git2::Repository::open(®istry_path));
|
2016-02-05 23:14:17 +00:00
|
|
|
let mut index = t!(repo.index());
|
|
|
|
t!(index.add_path(Path::new(&file)));
|
|
|
|
t!(index.write());
|
|
|
|
let id = t!(index.write_tree());
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
// Commit this change.
|
2016-02-05 23:14:17 +00:00
|
|
|
let tree = t!(repo.find_tree(id));
|
|
|
|
let sig = t!(repo.signature());
|
|
|
|
let parent = t!(repo.refname_to_id("refs/heads/master"));
|
|
|
|
let parent = t!(repo.find_commit(parent));
|
2018-03-14 15:17:44 +00:00
|
|
|
t!(repo.commit(
|
|
|
|
Some("HEAD"),
|
|
|
|
&sig,
|
|
|
|
&sig,
|
|
|
|
"Another commit",
|
|
|
|
&tree,
|
|
|
|
&[&parent]
|
|
|
|
));
|
2016-02-05 23:14:17 +00:00
|
|
|
}
|
2016-07-05 17:28:51 +00:00
|
|
|
|
2018-08-08 22:57:20 +00:00
|
|
|
cksum
|
2014-10-23 05:05:30 +00:00
|
|
|
}
|
|
|
|
|
2015-11-11 02:08:06 +00:00
|
|
|
fn make_archive(&self) {
|
2020-04-17 18:20:38 +00:00
|
|
|
let dst = self.archive_dst();
|
|
|
|
t!(fs::create_dir_all(dst.parent().unwrap()));
|
|
|
|
let f = t!(File::create(&dst));
|
|
|
|
let mut a = Builder::new(GzEncoder::new(f, Compression::default()));
|
|
|
|
|
|
|
|
if !self.files.iter().any(|(name, _)| name == "Cargo.toml") {
|
|
|
|
self.append_manifest(&mut a);
|
|
|
|
}
|
|
|
|
if self.files.is_empty() {
|
|
|
|
self.append(&mut a, "src/lib.rs", "");
|
|
|
|
} else {
|
|
|
|
for &(ref name, ref contents) in self.files.iter() {
|
|
|
|
self.append(&mut a, name, contents);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for &(ref name, ref contents) in self.extra_files.iter() {
|
|
|
|
self.append_extra(&mut a, name, contents);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn append_manifest<W: Write>(&self, ar: &mut Builder<W>) {
|
2020-03-24 21:31:28 +00:00
|
|
|
let mut manifest = String::new();
|
|
|
|
|
|
|
|
if !self.cargo_features.is_empty() {
|
|
|
|
manifest.push_str(&format!(
|
|
|
|
"cargo-features = {}\n\n",
|
|
|
|
toml::to_string(&self.cargo_features).unwrap()
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
manifest.push_str(&format!(
|
2018-03-14 15:17:44 +00:00
|
|
|
r#"
|
2019-04-10 02:08:43 +00:00
|
|
|
[package]
|
2015-11-11 02:08:06 +00:00
|
|
|
name = "{}"
|
|
|
|
version = "{}"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2019-04-10 02:08:43 +00:00
|
|
|
self.name, self.vers
|
2020-03-24 21:31:28 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
if let Some(version) = &self.rust_version {
|
|
|
|
manifest.push_str(&format!("rust-version = \"{}\"", version));
|
|
|
|
}
|
|
|
|
|
2016-03-14 22:45:05 +00:00
|
|
|
for dep in self.deps.iter() {
|
|
|
|
let target = match dep.target {
|
|
|
|
None => String::new(),
|
2016-10-20 22:07:18 +00:00
|
|
|
Some(ref s) => format!("target.'{}'.", s),
|
2016-01-26 00:54:10 +00:00
|
|
|
};
|
2016-03-14 22:45:05 +00:00
|
|
|
let kind = match &dep.kind[..] {
|
2015-11-11 02:08:06 +00:00
|
|
|
"build" => "build-",
|
|
|
|
"dev" => "dev-",
|
2018-03-14 15:17:44 +00:00
|
|
|
_ => "",
|
2016-01-26 00:54:10 +00:00
|
|
|
};
|
2018-03-14 15:17:44 +00:00
|
|
|
manifest.push_str(&format!(
|
|
|
|
r#"
|
2016-01-26 00:54:10 +00:00
|
|
|
[{}{}dependencies.{}]
|
|
|
|
version = "{}"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
target, kind, dep.name, dep.vers
|
|
|
|
));
|
2018-12-30 04:46:15 +00:00
|
|
|
if let Some(registry) = &dep.registry {
|
2018-12-31 00:07:58 +00:00
|
|
|
assert_eq!(registry, "alternative");
|
2019-01-11 23:56:46 +00:00
|
|
|
manifest.push_str(&format!("registry-index = \"{}\"", alt_registry_url()));
|
2018-12-30 04:46:15 +00:00
|
|
|
}
|
2015-11-11 02:08:06 +00:00
|
|
|
}
|
2020-03-15 22:59:42 +00:00
|
|
|
if self.proc_macro {
|
|
|
|
manifest.push_str("[lib]\nproc-macro = true\n");
|
|
|
|
}
|
2014-10-23 05:05:30 +00:00
|
|
|
|
2020-04-17 18:20:38 +00:00
|
|
|
self.append(ar, "Cargo.toml", &manifest);
|
2015-11-11 02:08:06 +00:00
|
|
|
}
|
|
|
|
|
2016-01-20 17:07:47 +00:00
|
|
|
fn append<W: Write>(&self, ar: &mut Builder<W>, file: &str, contents: &str) {
|
2018-03-14 15:17:44 +00:00
|
|
|
self.append_extra(
|
|
|
|
ar,
|
|
|
|
&format!("{}-{}/{}", self.name, self.vers, file),
|
|
|
|
contents,
|
|
|
|
);
|
2017-09-14 17:07:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn append_extra<W: Write>(&self, ar: &mut Builder<W>, path: &str, contents: &str) {
|
2016-01-20 17:07:47 +00:00
|
|
|
let mut header = Header::new_ustar();
|
2015-11-11 02:08:06 +00:00
|
|
|
header.set_size(contents.len() as u64);
|
2017-09-14 17:07:15 +00:00
|
|
|
t!(header.set_path(path));
|
2015-11-11 02:08:06 +00:00
|
|
|
header.set_cksum();
|
2016-05-26 00:06:25 +00:00
|
|
|
t!(ar.append(&header, contents.as_bytes()));
|
2015-11-11 02:08:06 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 22:09:38 +00:00
|
|
|
/// Returns the path to the compressed package file.
|
2015-11-11 02:08:06 +00:00
|
|
|
pub fn archive_dst(&self) -> PathBuf {
|
2016-02-05 23:14:17 +00:00
|
|
|
if self.local {
|
2018-03-14 15:17:44 +00:00
|
|
|
registry_path().join(format!("{}-{}.crate", self.name, self.vers))
|
2017-12-18 23:22:04 +00:00
|
|
|
} else if self.alternative {
|
|
|
|
alt_dl_path()
|
|
|
|
.join(&self.name)
|
|
|
|
.join(&self.vers)
|
|
|
|
.join(&format!("{}-{}.crate", self.name, self.vers))
|
2016-02-05 23:14:17 +00:00
|
|
|
} else {
|
2017-12-18 23:22:04 +00:00
|
|
|
dl_path().join(&self.name).join(&self.vers).join("download")
|
2016-02-05 23:14:17 +00:00
|
|
|
}
|
2015-11-11 02:08:06 +00:00
|
|
|
}
|
2014-10-23 05:05:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-05 17:28:51 +00:00
|
|
|
pub fn cksum(s: &[u8]) -> String {
|
Import the cargo-vendor subcommand into Cargo
This commit imports the external [alexcrichton/cargo-vendor
repository][repo] into Cargo itself. This means it will no longer be
necessary to install the `cargo-vendor` subcommand in order to vendor
dependencies. Additionally it'll always support the latest feature set
of Cargo as it'll be built into Cargo!
All tests were imported as part of this commit, but not all features
were imported. Some flags have been left out that were added later in
the lifetime of `cargo vendor` which seem like they're more questionable
to stabilize. I'm hoping that they can have separate PRs adding their
implementation here, and we can make a decision of their stabilization
at a later date.
The current man page for `cargo vendor -h` will look like:
cargo-vendor
Vendor all dependencies for a project locally
USAGE:
cargo vendor [OPTIONS] [--] [path]
OPTIONS:
-q, --quiet No output printed to stdout
--manifest-path <PATH> Path to Cargo.toml
--no-delete Don't delete older crates in the vendor directory
-s, --sync <TOML>... Additional `Cargo.toml` to sync and vendor
--respect-source-config Respect `[source]` config in `.cargo/config`
-v, --verbose Use verbose output (-vv very verbose/build.rs output)
--color <WHEN> Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z <FLAG>... Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
-h, --help Prints help information
ARGS:
<path> Where to vendor crates (`vendor` by default)
This cargo subcommand will vendor all crates.io and git dependencies for a
project into the specified directory at `<path>`. After this command completes
the vendor directory specified by `<path>` will contain all remote sources from
dependencies specified. Additionally manifest beyond the default one can be
specified with the `-s` option.
The `cargo vendor` command will also print out the configuration necessary
to use the vendored sources, which when needed is then encoded into
`.cargo/config`.
Since this change is not importing 100% of the functionality of the
existing `cargo vendor` this change does run a risk of being a breaking
change for any folks using such functionality. Executing `cargo vendor`
will favor the built-in command rather than an external subcommand,
causing unimplemented features to become errors about flag usage.
[repo]: https://github.com/alexcrichton/cargo-vendor
2019-04-23 00:54:27 +00:00
|
|
|
Sha256::new().update(s).finish_hex()
|
2014-10-23 05:05:30 +00:00
|
|
|
}
|
2018-09-07 16:37:06 +00:00
|
|
|
|
|
|
|
impl Dependency {
|
|
|
|
pub fn new(name: &str, vers: &str) -> Dependency {
|
|
|
|
Dependency {
|
|
|
|
name: name.to_string(),
|
|
|
|
vers: vers.to_string(),
|
|
|
|
kind: "normal".to_string(),
|
|
|
|
target: None,
|
|
|
|
features: Vec::new(),
|
|
|
|
package: None,
|
|
|
|
optional: false,
|
|
|
|
registry: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Changes this to `[build-dependencies]`.
|
2018-09-07 16:37:06 +00:00
|
|
|
pub fn build(&mut self) -> &mut Self {
|
|
|
|
self.kind = "build".to_string();
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Changes this to `[dev-dependencies]`.
|
2018-09-07 16:37:06 +00:00
|
|
|
pub fn dev(&mut self) -> &mut Self {
|
|
|
|
self.kind = "dev".to_string();
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Changes this to `[target.$target.dependencies]`.
|
2018-09-07 16:37:06 +00:00
|
|
|
pub fn target(&mut self, target: &str) -> &mut Self {
|
|
|
|
self.target = Some(target.to_string());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Adds `registry = $registry` to this dependency.
|
2018-09-07 16:37:06 +00:00
|
|
|
pub fn registry(&mut self, registry: &str) -> &mut Self {
|
|
|
|
self.registry = Some(registry.to_string());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Adds `features = [ ... ]` to this dependency.
|
2018-09-07 16:37:06 +00:00
|
|
|
pub fn enable_features(&mut self, features: &[&str]) -> &mut Self {
|
|
|
|
self.features.extend(features.iter().map(|s| s.to_string()));
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Adds `package = ...` to this dependency.
|
2018-09-07 16:37:06 +00:00
|
|
|
pub fn package(&mut self, pkg: &str) -> &mut Self {
|
|
|
|
self.package = Some(pkg.to_string());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Changes this to an optional dependency.
|
2018-09-07 16:37:06 +00:00
|
|
|
pub fn optional(&mut self, optional: bool) -> &mut Self {
|
|
|
|
self.optional = optional;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|