1 use std
::collections
::HashMap
;
2 use std
::fs
::{self, File}
;
3 use std
::io
::prelude
::*;
8 use crate::support
::cargo_process
;
9 use crate::support
::git
;
10 use crate::support
::paths
;
11 use crate::support
::registry
::{cksum, Package}
;
12 use crate::support
::{basic_manifest, project, ProjectBuilder}
;
15 let root
= paths
::root();
16 t
!(fs
::create_dir(&root
.join(".cargo")));
17 t
!(t
!(File
::create(root
.join(".cargo/config"))).write_all(
20 replace-with = 'my-awesome-local-registry'
22 [source.my-awesome-local-registry]
28 struct VendorPackage
{
29 p
: Option
<ProjectBuilder
>,
35 package
: Option
<String
>,
36 files
: HashMap
<String
, String
>,
40 fn new(name
: &str) -> VendorPackage
{
42 p
: Some(project().at(&format
!("index/{}", name
))),
44 package
: Some(String
::new()),
45 files
: HashMap
::new(),
50 fn file(&mut self, name
: &str, contents
: &str) -> &mut VendorPackage
{
51 self.p
= Some(self.p
.take().unwrap().file(name
, contents
));
54 .insert(name
.to_string(), cksum(contents
.as_bytes()));
58 fn disable_checksum(&mut self) -> &mut VendorPackage
{
59 self.cksum
.package
= None
;
63 fn no_manifest(mut self) -> Self {
64 self.p
= self.p
.map(|pb
| pb
.no_manifest());
69 let p
= self.p
.take().unwrap();
70 let json
= serde_json
::to_string(&self.cksum
).unwrap();
71 let p
= p
.file(".cargo-checksum.json", &json
);
80 VendorPackage
::new("bar")
81 .file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
82 .file("src/lib.rs", "pub fn bar() {}")
100 "extern crate bar; pub fn foo() { bar::bar(); }",
107 [COMPILING] bar v0.1.0
108 [COMPILING] foo v0.1.0 ([CWD])
116 fn simple_install() {
119 VendorPackage
::new("foo")
120 .file("src/lib.rs", "pub fn foo() {}")
123 VendorPackage
::new("bar")
138 "extern crate foo; pub fn main() { foo::foo(); }",
142 cargo_process("install bar")
145 [INSTALLING] bar v0.1.0
146 [COMPILING] foo v0.0.1
147 [COMPILING] bar v0.1.0
148 [FINISHED] release [optimized] target(s) in [..]s
149 [INSTALLING] [..]bar[..]
150 [INSTALLED] package `bar v0.1.0` (executable `bar[EXE]`)
151 [WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
158 fn simple_install_fail() {
161 VendorPackage
::new("foo")
162 .file("src/lib.rs", "pub fn foo() {}")
165 VendorPackage
::new("bar")
181 "extern crate foo; pub fn main() { foo::foo(); }",
185 cargo_process("install bar")
188 " Installing bar v0.1.0
189 error: failed to compile `bar v0.1.0`, intermediate artifacts can be found at `[..]`
192 no matching package named `baz` found
193 location searched: registry `https://github.com/rust-lang/crates.io-index`
194 perhaps you meant: bar or foo
195 required by package `bar v0.1.0`
202 fn install_without_feature_dep() {
205 VendorPackage
::new("foo")
206 .file("src/lib.rs", "pub fn foo() {}")
209 VendorPackage
::new("bar")
220 baz = { version = "9.8.7", optional = true }
228 "extern crate foo; pub fn main() { foo::foo(); }",
232 cargo_process("install bar")
235 [INSTALLING] bar v0.1.0
236 [COMPILING] foo v0.0.1
237 [COMPILING] bar v0.1.0
238 [FINISHED] release [optimized] target(s) in [..]s
239 [INSTALLING] [..]bar[..]
240 [INSTALLED] package `bar v0.1.0` (executable `bar[EXE]`)
241 [WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
251 let _
= project().at("index").build();
268 "extern crate bar; pub fn foo() { bar::bar(); }",
276 error: no matching package named `bar` found
277 location searched: [..]
278 required by package `foo v0.1.0 ([..])`
288 VendorPackage
::new("bar-0.1.0")
289 .file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
290 .file("src/lib.rs", "pub fn bar() {}")
291 .file(".cargo-checksum", "")
294 VendorPackage
::new("bar-0.2.0")
295 .file("Cargo.toml", &basic_manifest("bar", "0.2.0"))
296 .file("src/lib.rs", "pub fn bar() {}")
297 .file(".cargo-checksum", "")
315 "extern crate bar; pub fn foo() { bar::bar(); }",
322 [COMPILING] bar v0.1.0
323 [COMPILING] foo v0.1.0 ([CWD])
331 fn crates_io_then_directory() {
347 "extern crate bar; pub fn foo() { bar::bar(); }",
351 let cksum
= Package
::new("bar", "0.1.0")
352 .file("src/lib.rs", "pub fn bar() -> u32 { 0 }")
358 [UPDATING] `[..]` index
359 [DOWNLOADING] crates ...
360 [DOWNLOADED] bar v0.1.0 ([..])
361 [COMPILING] bar v0.1.0
362 [COMPILING] foo v0.1.0 ([CWD])
370 let mut v
= VendorPackage
::new("bar");
371 v
.file("Cargo.toml", &basic_manifest("bar", "0.1.0"));
372 v
.file("src/lib.rs", "pub fn bar() -> u32 { 1 }");
373 v
.cksum
.package
= Some(cksum
);
379 [COMPILING] bar v0.1.0
380 [COMPILING] foo v0.1.0 ([CWD])
388 fn crates_io_then_bad_checksum() {
402 .file("src/lib.rs", "")
405 Package
::new("bar", "0.1.0").publish();
407 p
.cargo("build").run();
410 VendorPackage
::new("bar")
411 .file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
412 .file("src/lib.rs", "")
419 error: checksum for `bar v0.1.0` changed between lock files
421 this could be indicative of a few possible errors:
423 * the lock file is corrupt
424 * a replacement source in use (e.g., a mirror) returned a different checksum
425 * the source itself may be corrupt in one way or another
427 unable to verify that `bar v0.1.0` is the same as when the lockfile was generated
435 fn bad_file_checksum() {
438 VendorPackage
::new("bar")
439 .file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
440 .file("src/lib.rs", "")
443 let mut f
= t
!(File
::create(paths
::root().join("index/bar/src/lib.rs")));
444 t
!(f
.write_all(b
"fn bar() -> u32 { 0 }"));
459 .file("src/lib.rs", "")
466 error: the listed checksum of `[..]lib.rs` has changed:
470 directory sources are not intended to be edited, if modifications are \
471 required then it is recommended that [replace] is used with a forked copy of \
479 fn only_dot_files_ok() {
482 VendorPackage
::new("bar")
483 .file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
484 .file("src/lib.rs", "")
486 VendorPackage
::new("foo")
504 .file("src/lib.rs", "")
507 p
.cargo("build").run();
511 fn random_files_ok() {
514 VendorPackage
::new("bar")
515 .file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
516 .file("src/lib.rs", "")
518 VendorPackage
::new("foo")
537 .file("src/lib.rs", "")
540 p
.cargo("build").run();
544 fn git_lock_file_doesnt_change() {
545 let git
= git
::new("git", |p
| {
546 p
.file("Cargo.toml", &basic_manifest("git", "0.5.0"))
547 .file("src/lib.rs", "")
551 VendorPackage
::new("git")
552 .file("Cargo.toml", &basic_manifest("git", "0.5.0"))
553 .file("src/lib.rs", "")
568 git = {{ git = '{0}' }}
573 .file("src/lib.rs", "")
576 p
.cargo("build").run();
578 let mut lock1
= String
::new();
579 t
!(t
!(File
::open(p
.root().join("Cargo.lock"))).read_to_string(&mut lock1
));
581 let root
= paths
::root();
582 t
!(fs
::create_dir(&root
.join(".cargo")));
583 t
!(t
!(File
::create(root
.join(".cargo/config"))).write_all(
588 replace-with = 'my-awesome-local-registry'
590 [source.my-awesome-local-registry]
608 let mut lock2
= String
::new();
609 t
!(t
!(File
::open(p
.root().join("Cargo.lock"))).read_to_string(&mut lock2
));
610 assert_eq
!(lock1
, lock2
, "lock files changed");
614 fn git_override_requires_lockfile() {
615 VendorPackage
::new("git")
616 .file("Cargo.toml", &basic_manifest("git", "0.5.0"))
617 .file("src/lib.rs", "")
631 git = { git = 'https://example.com/' }
634 .file("src/lib.rs", "")
637 let root
= paths
::root();
638 t
!(fs
::create_dir(&root
.join(".cargo")));
639 t
!(t
!(File
::create(root
.join(".cargo/config"))).write_all(
642 git = 'https://example.com/'
643 replace-with = 'my-awesome-local-registry'
645 [source.my-awesome-local-registry]
654 error: failed to load source for a dependency on `git`
657 Unable to update [..]
660 the source my-git-repo requires a lock file to be present first before it can be
661 used against vendored source code
663 remove the source replacement configuration, generate a lock file, and then
664 restore the source replacement configuration to continue the build
672 fn workspace_different_locations() {
686 .file("foo/src/lib.rs", "")
687 .file("foo/vendor/baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
688 .file("foo/vendor/baz/src/lib.rs", "")
689 .file("foo/vendor/baz/.cargo-checksum.json", "{\"files\":{}}")
701 .file("bar/src/lib.rs", "")
706 target-dir = './target'
709 replace-with = 'my-awesome-local-registry'
711 [source.my-awesome-local-registry]
712 directory = 'foo/vendor'
717 p
.cargo("build").cwd("foo").run();
730 fn version_missing() {
733 VendorPackage
::new("foo")
734 .file("src/lib.rs", "pub fn foo() {}")
737 VendorPackage
::new("bar")
750 .file("src/main.rs", "fn main() {}")
753 cargo_process("install bar")
756 [INSTALLING] bar v0.1.0
757 error: failed to compile [..]
760 failed to select a version for the requirement `foo = \"^2\"`
761 candidate versions found which didn't match: 0.0.1
762 location searched: directory source `[..] (which is replacing registry `[..]`)
763 required by package `bar v0.1.0`
764 perhaps a crate was updated and forgotten to be re-vendored?