3 use std
::fs
::{self, File}
;
4 use std
::io
::prelude
::*;
5 use std
::net
::{TcpListener, TcpStream}
;
7 use std
::sync
::atomic
::{AtomicBool, Ordering}
;
11 use cargo_test_support
::paths
::{self, CargoPathExt}
;
12 use cargo_test_support
::{basic_lib_manifest, basic_manifest, git, main_file, path2url, project}
;
13 use cargo_test_support
::{sleep_ms, t, Project}
;
15 fn disable_git_cli() -> bool
{
16 // mingw git on Windows does not support Windows-style file URIs.
17 // Appveyor in the rust repo has that git up front in the PATH instead
18 // of Git-for-Windows, which causes this to fail.
19 env
::var("CARGO_TEST_DISABLE_GIT_CLI") == Ok("1".to_string())
23 fn cargo_compile_simple_git_dep() {
24 let project
= project();
25 let git_project
= git
::new("dep1", |project
| {
27 .file("Cargo.toml", &basic_lib_manifest("dep1"))
31 pub fn hello() -> &'static str {
47 authors = ["wycats@example.com"]
58 &main_file(r
#""{}", dep1::hello()"#, &["dep1"]),
62 let git_root
= git_project
.root();
66 .with_stderr(&format
!(
67 "[UPDATING] git repository `{}`\n\
68 [COMPILING] dep1 v0.5.0 ({}#[..])\n\
69 [COMPILING] foo v0.5.0 ([CWD])\n\
70 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
76 assert
!(project
.bin("foo").is_file());
79 .process(&project
.bin("foo"))
80 .with_stdout("hello world\n")
85 fn cargo_compile_git_dep_branch() {
86 let project
= project();
87 let git_project
= git
::new("dep1", |project
| {
89 .file("Cargo.toml", &basic_lib_manifest("dep1"))
93 pub fn hello() -> &'static str {
100 // Make a new branch based on the current HEAD commit
101 let repo
= git2
::Repository
::open(&git_project
.root()).unwrap();
102 let head
= repo
.head().unwrap().target().unwrap();
103 let head
= repo
.find_commit(head
).unwrap();
104 repo
.branch("branchy", &head
, true).unwrap();
106 let project
= project
115 authors = ["wycats@example.com"]
128 &main_file(r
#""{}", dep1::hello()"#, &["dep1"]),
132 let git_root
= git_project
.root();
136 .with_stderr(&format
!(
137 "[UPDATING] git repository `{}`\n\
138 [COMPILING] dep1 v0.5.0 ({}?branch=branchy#[..])\n\
139 [COMPILING] foo v0.5.0 ([CWD])\n\
140 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
146 assert
!(project
.bin("foo").is_file());
149 .process(&project
.bin("foo"))
150 .with_stdout("hello world\n")
155 fn cargo_compile_git_dep_tag() {
156 let project
= project();
157 let git_project
= git
::new("dep1", |project
| {
159 .file("Cargo.toml", &basic_lib_manifest("dep1"))
163 pub fn hello() -> &'static str {
170 // Make a tag corresponding to the current HEAD
171 let repo
= git2
::Repository
::open(&git_project
.root()).unwrap();
172 let head
= repo
.head().unwrap().target().unwrap();
175 &repo
.find_object(head
, None
).unwrap(),
176 &repo
.signature().unwrap(),
182 let project
= project
191 authors = ["wycats@example.com"]
203 &main_file(r
#""{}", dep1::hello()"#, &["dep1"]),
207 let git_root
= git_project
.root();
211 .with_stderr(&format
!(
212 "[UPDATING] git repository `{}`\n\
213 [COMPILING] dep1 v0.5.0 ({}?tag=v0.1.0#[..])\n\
214 [COMPILING] foo v0.5.0 ([CWD])\n\
215 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
221 assert
!(project
.bin("foo").is_file());
224 .process(&project
.bin("foo"))
225 .with_stdout("hello world\n")
228 project
.cargo("build").run();
232 fn cargo_compile_with_nested_paths() {
233 let git_project
= git
::new("dep1", |project
| {
242 authors = ["carlhuda@example.com"]
259 pub fn hello() -> &'static str {
264 .file("vendor/dep2/Cargo.toml", &basic_lib_manifest("dep2"))
266 "vendor/dep2/src/dep2.rs",
268 pub fn hello() -> &'static str {
284 authors = ["wycats@example.com"]
300 &main_file(r
#""{}", dep1::hello()"#, &["dep1"]),
304 p
.cargo("build").run();
306 assert
!(p
.bin("foo").is_file());
308 p
.process(&p
.bin("foo")).with_stdout("hello world\n").run();
312 fn cargo_compile_with_malformed_nested_paths() {
313 let git_project
= git
::new("dep1", |project
| {
315 .file("Cargo.toml", &basic_lib_manifest("dep1"))
319 pub fn hello() -> &'static str {
324 .file("vendor/dep2/Cargo.toml", "!INVALID!")
336 authors = ["wycats@example.com"]
352 &main_file(r
#""{}", dep1::hello()"#, &["dep1"]),
356 p
.cargo("build").run();
358 assert
!(p
.bin("foo").is_file());
360 p
.process(&p
.bin("foo")).with_stdout("hello world\n").run();
364 fn cargo_compile_with_meta_package() {
365 let git_project
= git
::new("meta-dep", |project
| {
367 .file("dep1/Cargo.toml", &basic_lib_manifest("dep1"))
371 pub fn hello() -> &'static str {
376 .file("dep2/Cargo.toml", &basic_lib_manifest("dep2"))
380 pub fn hello() -> &'static str {
396 authors = ["wycats@example.com"]
419 r
#""{} {}", dep1::hello(), dep2::hello()"#,
425 p
.cargo("build").run();
427 assert
!(p
.bin("foo").is_file());
429 p
.process(&p
.bin("foo"))
430 .with_stdout("this is dep1 this is dep2\n")
435 fn cargo_compile_with_short_ssh_git() {
436 let url
= "git@github.com:a/dep";
447 authors = ["wycats@example.com"]
462 &main_file(r
#""{}", dep1::hello()"#, &["dep1"]),
469 .with_stderr(&format
!(
471 [ERROR] failed to parse manifest at `[..]`
474 invalid url `{}`: relative URL without a base
482 fn two_revs_same_deps() {
483 let bar
= git
::new("meta-dep", |project
| {
485 .file("Cargo.toml", &basic_manifest("bar", "0.0.0"))
486 .file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
489 let repo
= git2
::Repository
::open(&bar
.root()).unwrap();
490 let rev1
= repo
.revparse_single("HEAD").unwrap().id();
492 // Commit the changes and make sure we trigger a recompile
493 File
::create(&bar
.root().join("src/lib.rs"))
495 .write_all(br
#"pub fn bar() -> i32 { 2 }"#)
498 let rev2
= git
::commit(&repo
);
528 assert_eq!(bar::bar(), 1);
529 assert_eq!(baz::baz(), 2);
558 pub fn baz() -> i32 { bar::bar() }
563 foo
.cargo("build -v").run();
564 assert
!(foo
.bin("foo").is_file());
565 foo
.process(&foo
.bin("foo")).run();
570 let git_project
= git
::new("bar", |project
| {
572 .file("Cargo.toml", &basic_lib_manifest("bar"))
573 .file("src/bar.rs", "pub fn bar() {}")
585 authors = ["wycats@example.com"]
595 .file("src/main.rs", &main_file(r
#""{:?}", bar::bar()"#, &["bar"]))
598 // First time around we should compile both foo and bar
600 .with_stderr(&format
!(
601 "[UPDATING] git repository `{}`\n\
602 [COMPILING] bar v0.5.0 ({}#[..])\n\
603 [COMPILING] foo v0.5.0 ([CWD])\n\
604 [FINISHED] dev [unoptimized + debuginfo] target(s) \
611 // Don't recompile the second time
612 p
.cargo("build").with_stdout("").run();
614 // Modify a file manually, shouldn't trigger a recompile
615 File
::create(&git_project
.root().join("src/bar.rs"))
617 .write_all(br
#"pub fn bar() { println!("hello!"); }"#)
620 p
.cargo("build").with_stdout("").run();
623 .with_stderr(&format
!(
624 "[UPDATING] git repository `{}`",
629 p
.cargo("build").with_stdout("").run();
631 // Commit the changes and make sure we don't trigger a recompile because the
632 // lock file says not to change
633 let repo
= git2
::Repository
::open(&git_project
.root()).unwrap();
637 println
!("compile after commit");
638 p
.cargo("build").with_stdout("").run();
639 p
.root().move_into_the_past();
641 // Update the dependency and carry on!
643 .with_stderr(&format
!(
644 "[UPDATING] git repository `{}`\n\
645 [UPDATING] bar v0.5.0 ([..]) -> #[..]\n\
650 println
!("going for the last compile");
652 .with_stderr(&format
!(
653 "[COMPILING] bar v0.5.0 ({}#[..])\n\
654 [COMPILING] foo v0.5.0 ([CWD])\n\
655 [FINISHED] dev [unoptimized + debuginfo] target(s) \
661 // Make sure clean only cleans one dep
662 p
.cargo("clean -p foo").with_stdout("").run();
665 "[COMPILING] foo v0.5.0 ([CWD])\n\
666 [FINISHED] dev [unoptimized + debuginfo] target(s) \
673 fn update_with_shared_deps() {
674 let git_project
= git
::new("bar", |project
| {
676 .file("Cargo.toml", &basic_lib_manifest("bar"))
677 .file("src/bar.rs", "pub fn bar() {}")
687 authors = ["wycats@example.com"]
698 #[allow(unused_extern_crates)]
700 #[allow(unused_extern_crates)]
712 authors = ["wycats@example.com"]
721 .file("dep1/src/lib.rs", "")
729 authors = ["wycats@example.com"]
738 .file("dep2/src/lib.rs", "")
741 // First time around we should compile both foo and bar
743 .with_stderr(&format
!(
745 [UPDATING] git repository `{git}`
746 [COMPILING] bar v0.5.0 ({git}#[..])
747 [COMPILING] [..] v0.5.0 ([..])
748 [COMPILING] [..] v0.5.0 ([..])
749 [COMPILING] foo v0.5.0 ([CWD])
750 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
751 git
= git_project
.url(),
755 // Modify a file manually, and commit it
756 File
::create(&git_project
.root().join("src/bar.rs"))
758 .write_all(br
#"pub fn bar() { println!("hello!"); }"#)
760 let repo
= git2
::Repository
::open(&git_project
.root()).unwrap();
761 let old_head
= repo
.head().unwrap().target().unwrap();
767 // By default, not transitive updates
768 println
!("dep1 update");
769 p
.cargo("update -p dep1").with_stdout("").run();
771 // Don't do anything bad on a weird --precise argument
772 println
!("bar bad precise update");
773 p
.cargo("update -p bar --precise 0.1.2")
777 [UPDATING] git repository [..]
778 [ERROR] Unable to update [..]
781 revspec '0.1.2' not found; [..]
786 // Specifying a precise rev to the old rev shouldn't actually update
787 // anything because we already have the rev in the db.
788 println
!("bar precise update");
789 p
.cargo("update -p bar --precise")
790 .arg(&old_head
.to_string())
794 // Updating aggressively should, however, update the repo.
795 println
!("dep1 aggressive update");
796 p
.cargo("update -p dep1 --aggressive")
797 .with_stderr(&format
!(
798 "[UPDATING] git repository `{}`\n\
799 [UPDATING] bar v0.5.0 ([..]) -> #[..]\n\
805 // Make sure we still only compile one version of the git repo
808 .with_stderr(&format
!(
810 [COMPILING] bar v0.5.0 ({git}#[..])
811 [COMPILING] [..] v0.5.0 ([CWD][..]dep[..])
812 [COMPILING] [..] v0.5.0 ([CWD][..]dep[..])
813 [COMPILING] foo v0.5.0 ([CWD])
814 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
815 git
= git_project
.url(),
819 // We should be able to update transitive deps
820 p
.cargo("update -p bar")
821 .with_stderr(&format
!(
822 "[UPDATING] git repository `{}`",
829 fn dep_with_submodule() {
830 let project
= project();
831 let git_project
= git
::new("dep1", |project
| {
832 project
.file("Cargo.toml", &basic_manifest("dep1", "0.5.0"))
834 let git_project2
= git
::new("dep2", |project
| project
.file("lib.rs", "pub fn dep() {}"));
836 let repo
= git2
::Repository
::open(&git_project
.root()).unwrap();
837 let url
= path2url(git_project2
.root()).to_string();
838 git
::add_submodule(&repo
, &url
, Path
::new("src"));
841 let project
= project
850 authors = ["wycats@example.com"]
861 "extern crate dep1; pub fn foo() { dep1::dep() }",
869 [UPDATING] git repository [..]
870 [COMPILING] dep1 [..]
872 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
878 fn dep_with_bad_submodule() {
879 let project
= project();
880 let git_project
= git
::new("dep1", |project
| {
881 project
.file("Cargo.toml", &basic_manifest("dep1", "0.5.0"))
883 let git_project2
= git
::new("dep2", |project
| project
.file("lib.rs", "pub fn dep() {}"));
885 let repo
= git2
::Repository
::open(&git_project
.root()).unwrap();
886 let url
= path2url(git_project2
.root()).to_string();
887 git
::add_submodule(&repo
, &url
, Path
::new("src"));
890 // now amend the first commit on git_project2 to make submodule ref point to not-found
892 let repo
= git2
::Repository
::open(&git_project2
.root()).unwrap();
893 let original_submodule_ref
= repo
.refname_to_id("refs/heads/master").unwrap();
894 let commit
= repo
.find_commit(original_submodule_ref
).unwrap();
897 Some("refs/heads/master"),
901 Some("something something"),
915 authors = ["wycats@example.com"]
926 "extern crate dep1; pub fn foo() { dep1::dep() }",
930 let expected
= format
!(
932 [UPDATING] git repository [..]
933 [ERROR] failed to load source for a dependency on `dep1`
939 failed to update submodule `src`
942 object not found - no match for id [..]
944 path2url(git_project
.root())
948 .with_stderr(expected
)
954 fn two_deps_only_update_one() {
955 let project
= project();
956 let git1
= git
::new("dep1", |project
| {
958 .file("Cargo.toml", &basic_manifest("dep1", "0.5.0"))
959 .file("src/lib.rs", "")
961 let git2
= git
::new("dep2", |project
| {
963 .file("Cargo.toml", &basic_manifest("dep2", "0.5.0"))
964 .file("src/lib.rs", "")
976 authors = ["wycats@example.com"]
987 .file("src/main.rs", "fn main() {}")
990 fn oid_to_short_sha(oid
: git2
::Oid
) -> String
{
991 oid
.to_string()[..8].to_string()
993 fn git_repo_head_sha(p
: &Project
) -> String
{
994 let repo
= git2
::Repository
::open(p
.root()).unwrap();
995 let head
= repo
.head().unwrap().target().unwrap();
996 oid_to_short_sha(head
)
999 println
!("dep1 head sha: {}", git_repo_head_sha(&git1
));
1000 println
!("dep2 head sha: {}", git_repo_head_sha(&git2
));
1004 "[UPDATING] git repository `[..]`\n\
1005 [UPDATING] git repository `[..]`\n\
1006 [COMPILING] [..] v0.5.0 ([..])\n\
1007 [COMPILING] [..] v0.5.0 ([..])\n\
1008 [COMPILING] foo v0.5.0 ([CWD])\n\
1009 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
1013 File
::create(&git1
.root().join("src/lib.rs"))
1015 .write_all(br
#"pub fn foo() {}"#)
1017 let repo
= git2
::Repository
::open(&git1
.root()).unwrap();
1019 let oid
= git
::commit(&repo
);
1020 println
!("dep1 head sha: {}", oid_to_short_sha(oid
));
1022 p
.cargo("update -p dep1")
1023 .with_stderr(&format
!(
1024 "[UPDATING] git repository `{}`\n\
1025 [UPDATING] dep1 v0.5.0 ([..]) -> #[..]\n\
1033 fn stale_cached_version() {
1034 let bar
= git
::new("meta-dep", |project
| {
1036 .file("Cargo.toml", &basic_manifest("bar", "0.0.0"))
1037 .file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
1040 // Update the git database in the cache with the current state of the git
1063 fn main() { assert_eq!(bar::bar(), 1) }
1068 foo
.cargo("build").run();
1069 foo
.process(&foo
.bin("foo")).run();
1071 // Update the repo, and simulate someone else updating the lock file and then
1072 // us pulling it down.
1073 File
::create(&bar
.root().join("src/lib.rs"))
1075 .write_all(br
#"pub fn bar() -> i32 { 1 + 0 }"#)
1077 let repo
= git2
::Repository
::open(&bar
.root()).unwrap();
1083 let rev
= repo
.revparse_single("HEAD").unwrap().id();
1085 File
::create(&foo
.root().join("Cargo.lock"))
1094 'bar 0.0.0 (git+{url}#{hash})'
1100 source = 'git+{url}#{hash}'
1111 .with_stderr(&format
!(
1113 [UPDATING] git repository `{bar}`
1114 [COMPILING] bar v0.0.0 ({bar}#[..])
1115 [COMPILING] foo v0.0.0 ([CWD])
1116 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1121 foo
.process(&foo
.bin("foo")).run();
1125 fn dep_with_changed_submodule() {
1126 let project
= project();
1127 let git_project
= git
::new("dep1", |project
| {
1128 project
.file("Cargo.toml", &basic_manifest("dep1", "0.5.0"))
1131 let git_project2
= git
::new("dep2", |project
| {
1132 project
.file("lib.rs", "pub fn dep() -> &'static str { \"project2\" }")
1135 let git_project3
= git
::new("dep3", |project
| {
1136 project
.file("lib.rs", "pub fn dep() -> &'static str { \"project3\" }")
1139 let repo
= git2
::Repository
::open(&git_project
.root()).unwrap();
1140 let mut sub
= git
::add_submodule(&repo
, &git_project2
.url().to_string(), Path
::new("src"));
1151 authors = ["wycats@example.com"]
1162 pub fn main() { println!(\"{}\", dep1::dep()) }
1167 println
!("first run");
1170 "[UPDATING] git repository `[..]`\n\
1171 [COMPILING] dep1 v0.5.0 ([..])\n\
1172 [COMPILING] foo v0.5.0 ([..])\n\
1173 [FINISHED] dev [unoptimized + debuginfo] target(s) in \
1175 [RUNNING] `target/debug/foo[EXE]`\n",
1177 .with_stdout("project2\n")
1180 File
::create(&git_project
.root().join(".gitmodules"))
1184 "[submodule \"src\"]\n\tpath = src\n\turl={}",
1191 // Sync the submodule and reset it to the new remote.
1192 sub
.sync().unwrap();
1194 let subrepo
= sub
.open().unwrap();
1196 .remote_add_fetch("origin", "refs/heads/*:refs/heads/*")
1199 .remote_set_url("origin", &git_project3
.url().to_string())
1201 let mut origin
= subrepo
.find_remote("origin").unwrap();
1202 origin
.fetch(&[], None
, None
).unwrap();
1203 let id
= subrepo
.refname_to_id("refs/remotes/origin/master").unwrap();
1204 let obj
= subrepo
.find_object(id
, None
).unwrap();
1205 subrepo
.reset(&obj
, git2
::ResetType
::Hard
, None
).unwrap();
1207 sub
.add_to_index(true).unwrap();
1212 // Update the dependency and carry on!
1214 p
.cargo("update -v")
1216 .with_stderr(&format
!(
1217 "[UPDATING] git repository `{}`\n\
1218 [UPDATING] dep1 v0.5.0 ([..]) -> #[..]\n\
1224 println
!("last run");
1227 "[COMPILING] dep1 v0.5.0 ([..])\n\
1228 [COMPILING] foo v0.5.0 ([..])\n\
1229 [FINISHED] dev [unoptimized + debuginfo] target(s) in \
1231 [RUNNING] `target/debug/foo[EXE]`\n",
1233 .with_stdout("project3\n")
1238 fn dev_deps_with_testing() {
1239 let p2
= git
::new("bar", |project
| {
1241 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
1245 pub fn gimme() -> &'static str { "zoidberg" }
1259 authors = ["wycats@example.com"]
1261 [dev-dependencies.bar]
1276 #[test] fn foo() { bar::gimme(); }
1282 // Generate a lock file which did not use `bar` to compile, but had to update
1283 // `bar` to generate the lock file
1285 .with_stderr(&format
!(
1287 [UPDATING] git repository `{bar}`
1288 [COMPILING] foo v0.5.0 ([CWD])
1289 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1295 // Make sure we use the previous resolution of `bar` instead of updating it
1300 [COMPILING] [..] v0.5.0 ([..])
1301 [COMPILING] [..] v0.5.0 ([..]
1302 [FINISHED] test [unoptimized + debuginfo] target(s) in [..]
1303 [RUNNING] target/debug/deps/foo-[..][EXE]",
1305 .with_stdout_contains("test tests::foo ... ok")
1310 fn git_build_cmd_freshness() {
1311 let foo
= git
::new("foo", |project
| {
1323 .file("build.rs", "fn main() {}")
1324 .file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
1325 .file(".gitignore", "src/bar.rs")
1327 foo
.root().move_into_the_past();
1334 [COMPILING] foo v0.0.0 ([CWD])
1335 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1340 // Smoke test to make sure it doesn't compile again
1341 println
!("first pass");
1342 foo
.cargo("build").with_stdout("").run();
1344 // Modify an ignored file and make sure we don't rebuild
1345 println
!("second pass");
1346 File
::create(&foo
.root().join("src/bar.rs")).unwrap();
1347 foo
.cargo("build").with_stdout("").run();
1351 fn git_name_not_always_needed() {
1352 let p2
= git
::new("bar", |project
| {
1354 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
1358 pub fn gimme() -> &'static str { "zoidberg" }
1363 let repo
= git2
::Repository
::open(&p2
.root()).unwrap();
1364 let mut cfg
= repo
.config().unwrap();
1365 let _
= cfg
.remove("user.name");
1366 let _
= cfg
.remove("user.email");
1378 [dev-dependencies.bar]
1384 .file("src/main.rs", "fn main() {}")
1387 // Generate a lock file which did not use `bar` to compile, but had to update
1388 // `bar` to generate the lock file
1390 .with_stderr(&format
!(
1392 [UPDATING] git repository `{bar}`
1393 [COMPILING] foo v0.5.0 ([CWD])
1394 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1402 fn git_repo_changing_no_rebuild() {
1403 let bar
= git
::new("bar", |project
| {
1405 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
1406 .file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
1409 // Lock p1 to the first rev in the git repo
1427 .file("src/main.rs", "fn main() {}")
1428 .file("build.rs", "fn main() {}")
1430 p1
.root().move_into_the_past();
1432 .with_stderr(&format
!(
1434 [UPDATING] git repository `{bar}`
1437 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1443 // Make a commit to lock p2 to a different rev
1444 File
::create(&bar
.root().join("src/lib.rs"))
1446 .write_all(br
#"pub fn bar() -> i32 { 2 }"#)
1448 let repo
= git2
::Repository
::open(&bar
.root()).unwrap();
1452 // Lock p2 to the second rev
1469 .file("src/main.rs", "fn main() {}")
1472 .with_stderr(&format
!(
1474 [UPDATING] git repository `{bar}`
1477 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1483 // And now for the real test! Make sure that p1 doesn't get rebuilt
1484 // even though the git repo has changed.
1485 p1
.cargo("build").with_stdout("").run();
1489 fn git_dep_build_cmd() {
1490 let p
= git
::new("foo", |project
| {
1499 authors = ["wycats@example.com"]
1511 .file("src/foo.rs", &main_file(r
#""{}", bar::gimme()"#, &["bar"]))
1519 authors = ["wycats@example.com"]
1528 "bar/src/bar.rs.in",
1530 pub fn gimme() -> i32 { 0 }
1538 fs::copy("src/bar.rs.in", "src/bar.rs").unwrap();
1544 p
.root().join("bar").move_into_the_past();
1546 p
.cargo("build").run();
1548 p
.process(&p
.bin("foo")).with_stdout("0\n").run();
1550 // Touching bar.rs.in should cause the `build` command to run again.
1551 fs
::File
::create(&p
.root().join("bar/src/bar.rs.in"))
1553 .write_all(b
"pub fn gimme() -> i32 { 1 }")
1556 p
.cargo("build").run();
1558 p
.process(&p
.bin("foo")).with_stdout("1\n").run();
1562 fn fetch_downloads() {
1563 let bar
= git
::new("bar", |project
| {
1565 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
1566 .file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
1584 .file("src/main.rs", "fn main() {}")
1587 .with_stderr(&format
!(
1588 "[UPDATING] git repository `{url}`",
1593 p
.cargo("fetch").with_stdout("").run();
1597 fn warnings_in_git_dep() {
1598 let bar
= git
::new("bar", |project
| {
1600 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
1601 .file("src/lib.rs", "fn unused() {}")
1619 .file("src/main.rs", "fn main() {}")
1623 .with_stderr(&format
!(
1624 "[UPDATING] git repository `{}`\n\
1625 [COMPILING] bar v0.5.0 ({}#[..])\n\
1626 [COMPILING] foo v0.5.0 ([CWD])\n\
1627 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
1635 fn update_ambiguous() {
1636 let bar1
= git
::new("bar1", |project
| {
1638 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
1639 .file("src/lib.rs", "")
1641 let bar2
= git
::new("bar2", |project
| {
1643 .file("Cargo.toml", &basic_manifest("bar", "0.6.0"))
1644 .file("src/lib.rs", "")
1646 let baz
= git
::new("baz", |project
| {
1655 authors = ["wycats@example.com"]
1663 .file("src/lib.rs", "")
1684 .file("src/main.rs", "fn main() {}")
1687 p
.cargo("generate-lockfile").run();
1688 p
.cargo("update -p bar")
1692 [ERROR] There are multiple `bar` packages in your project, and the specification `bar` \
1694 Please re-run this command with `-p <spec>` where `<spec>` is one of the \
1704 fn update_one_dep_in_repo_with_many_deps() {
1705 let bar
= git
::new("bar", |project
| {
1707 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
1708 .file("src/lib.rs", "")
1709 .file("a/Cargo.toml", &basic_manifest("a", "0.5.0"))
1710 .file("a/src/lib.rs", "")
1731 .file("src/main.rs", "fn main() {}")
1734 p
.cargo("generate-lockfile").run();
1735 p
.cargo("update -p bar")
1736 .with_stderr(&format
!("[UPDATING] git repository `{}`", bar
.url()))
1741 fn switch_deps_does_not_update_transitive() {
1742 let transitive
= git
::new("transitive", |project
| {
1744 .file("Cargo.toml", &basic_manifest("transitive", "0.5.0"))
1745 .file("src/lib.rs", "")
1747 let dep1
= git
::new("dep1", |project
| {
1756 authors = ["wycats@example.com"]
1758 [dependencies.transitive]
1764 .file("src/lib.rs", "")
1766 let dep2
= git
::new("dep2", |project
| {
1775 authors = ["wycats@example.com"]
1777 [dependencies.transitive]
1783 .file("src/lib.rs", "")
1801 .file("src/main.rs", "fn main() {}")
1805 .with_stderr(&format
!(
1807 [UPDATING] git repository `{}`
1808 [UPDATING] git repository `{}`
1809 [COMPILING] transitive [..]
1810 [COMPILING] dep [..]
1811 [COMPILING] foo [..]
1812 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1819 // Update the dependency to point to the second repository, but this
1820 // shouldn't update the transitive dependency which is the same.
1821 File
::create(&p
.root().join("Cargo.toml"))
1840 .with_stderr(&format
!(
1842 [UPDATING] git repository `{}`
1843 [COMPILING] dep [..]
1844 [COMPILING] foo [..]
1845 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1853 fn update_one_source_updates_all_packages_in_that_git_source() {
1854 let dep
= git
::new("dep", |project
| {
1868 .file("src/lib.rs", "")
1869 .file("a/Cargo.toml", &basic_manifest("a", "0.5.0"))
1870 .file("a/src/lib.rs", "")
1888 .file("src/main.rs", "fn main() {}")
1891 p
.cargo("build").run();
1893 let repo
= git2
::Repository
::open(&dep
.root()).unwrap();
1894 let rev1
= repo
.revparse_single("HEAD").unwrap().id();
1896 // Just be sure to change a file
1897 File
::create(&dep
.root().join("src/lib.rs"))
1899 .write_all(br
#"pub fn bar() -> i32 { 2 }"#)
1904 p
.cargo("update -p dep").run();
1905 let mut lockfile
= String
::new();
1906 File
::open(&p
.root().join("Cargo.lock"))
1908 .read_to_string(&mut lockfile
)
1911 !lockfile
.contains(&rev1
.to_string()),
1919 fn switch_sources() {
1920 let a1
= git
::new("a1", |project
| {
1922 .file("Cargo.toml", &basic_manifest("a", "0.5.0"))
1923 .file("src/lib.rs", "")
1925 let a2
= git
::new("a2", |project
| {
1927 .file("Cargo.toml", &basic_manifest("a", "0.5.1"))
1928 .file("src/lib.rs", "")
1943 .file("src/main.rs", "fn main() {}")
1958 .file("b/src/lib.rs", "pub fn main() {}")
1964 [UPDATING] git repository `file://[..]a1`
1965 [COMPILING] a v0.5.0 ([..]a1#[..]
1966 [COMPILING] b v0.5.0 ([..])
1967 [COMPILING] foo v0.5.0 ([..])
1968 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1973 File
::create(&p
.root().join("b/Cargo.toml"))
1994 [UPDATING] git repository `file://[..]a2`
1995 [COMPILING] a v0.5.1 ([..]a2#[..]
1996 [COMPILING] b v0.5.0 ([..])
1997 [COMPILING] foo v0.5.0 ([..])
1998 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2005 fn dont_require_submodules_are_checked_out() {
2006 let p
= project().build();
2007 let git1
= git
::new("dep1", |p
| {
2018 .file("build.rs", "fn main() {}")
2019 .file("src/lib.rs", "")
2022 let git2
= git
::new("dep2", |p
| p
);
2024 let repo
= git2
::Repository
::open(&git1
.root()).unwrap();
2025 let url
= path2url(git2
.root()).to_string();
2026 git
::add_submodule(&repo
, &url
, Path
::new("a/submodule"));
2029 git2
::Repository
::init(&p
.root()).unwrap();
2030 let url
= path2url(git1
.root()).to_string();
2031 let dst
= paths
::home().join("foo");
2032 git2
::Repository
::clone(&url
, &dst
).unwrap();
2034 git1
.cargo("build -v").cwd(&dst
).run();
2038 fn doctest_same_name() {
2039 let a2
= git
::new("a2", |p
| {
2040 p
.file("Cargo.toml", &basic_manifest("a", "0.5.0"))
2041 .file("src/lib.rs", "pub fn a2() {}")
2044 let a1
= git
::new("a1", |p
| {
2054 a = {{ git = '{}' }}
2059 .file("src/lib.rs", "extern crate a; pub fn a1() {}")
2073 a = {{ git = '{}' }}
2087 p
.cargo("test -v").run();
2091 fn lints_are_suppressed() {
2092 let a
= git
::new("a", |p
| {
2093 p
.file("Cargo.toml", &basic_manifest("a", "0.5.0")).file(
2112 a = {{ git = '{}' }}
2117 .file("src/lib.rs", "")
2123 [UPDATING] git repository `[..]`
2124 [COMPILING] a v0.5.0 ([..])
2125 [COMPILING] foo v0.0.1 ([..])
2126 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2133 fn denied_lints_are_allowed() {
2134 let a
= git
::new("a", |p
| {
2135 p
.file("Cargo.toml", &basic_manifest("a", "0.5.0")).file(
2155 a = {{ git = '{}' }}
2160 .file("src/lib.rs", "")
2166 [UPDATING] git repository `[..]`
2167 [COMPILING] a v0.5.0 ([..])
2168 [COMPILING] foo v0.0.1 ([..])
2169 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2176 fn add_a_git_dep() {
2177 let git
= git
::new("git", |p
| {
2178 p
.file("Cargo.toml", &basic_manifest("git", "0.5.0"))
2179 .file("src/lib.rs", "")
2193 a = {{ path = 'a' }}
2194 git = {{ git = '{}' }}
2199 .file("src/lib.rs", "")
2200 .file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
2201 .file("a/src/lib.rs", "")
2204 p
.cargo("build").run();
2206 File
::create(p
.root().join("a/Cargo.toml"))
2217 git = {{ git = '{}' }}
2225 p
.cargo("build").run();
2229 fn two_at_rev_instead_of_tag() {
2230 let git
= git
::new("git", |p
| {
2231 p
.file("Cargo.toml", &basic_manifest("git1", "0.5.0"))
2232 .file("src/lib.rs", "")
2233 .file("a/Cargo.toml", &basic_manifest("git2", "0.5.0"))
2234 .file("a/src/lib.rs", "")
2237 // Make a tag corresponding to the current HEAD
2238 let repo
= git2
::Repository
::open(&git
.root()).unwrap();
2239 let head
= repo
.head().unwrap().target().unwrap();
2242 &repo
.find_object(head
, None
).unwrap(),
2243 &repo
.signature().unwrap(),
2260 git1 = {{ git = '{0}', rev = 'v0.1.0' }}
2261 git2 = {{ git = '{0}', rev = 'v0.1.0' }}
2266 .file("src/lib.rs", "")
2269 p
.cargo("generate-lockfile").run();
2270 p
.cargo("build -v").run();
2274 fn include_overrides_gitignore() {
2275 // Make sure that `package.include` takes precedence over .gitignore.
2276 let p
= git
::new("foo", |repo
| {
2283 include = ["src/lib.rs", "ignored.txt", "Cargo.toml"]
2294 .file("src/lib.rs", "")
2295 .file("ignored.txt", "")
2296 .file("build.rs", "fn main() {}")
2299 p
.cargo("build").run();
2300 p
.change_file("ignored.txt", "Trigger rebuild.");
2304 [COMPILING] foo v0.5.0 ([..])
2305 [RUNNING] `[..]build-script-build[..]`
2306 [RUNNING] `rustc --crate-name foo src/lib.rs [..]`
2307 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2311 p
.cargo("package --list --allow-dirty")
2323 fn invalid_git_dependency_manifest() {
2324 let project
= project();
2325 let git_project
= git
::new("dep1", |project
| {
2334 authors = ["carlhuda@example.com"]
2335 categories = ["algorithms"]
2336 categories = ["algorithms"]
2346 pub fn hello() -> &'static str {
2353 let project
= project
2362 authors = ["wycats@example.com"]
2373 &main_file(r
#""{}", dep1::hello()"#, &["dep1"]),
2377 let git_root
= git_project
.root();
2382 .with_stderr(&format
!(
2383 "[UPDATING] git repository `{}`\n\
2384 error: failed to load source for a dependency on `dep1`\n\
2387 Unable to update {}\n\
2390 failed to parse manifest at `[..]`\n\
2393 could not parse input as TOML\n\
2396 duplicate key: `categories` for key `project` at line 10 column 17",
2397 path2url(&git_root
),
2398 path2url(&git_root
),
2404 fn failed_submodule_checkout() {
2405 let project
= project();
2406 let git_project
= git
::new("dep1", |project
| {
2407 project
.file("Cargo.toml", &basic_manifest("dep1", "0.5.0"))
2410 let git_project2
= git
::new("dep2", |project
| project
.file("lib.rs", ""));
2412 let listener
= TcpListener
::bind("127.0.0.1:0").unwrap();
2413 let addr
= listener
.local_addr().unwrap();
2414 let done
= Arc
::new(AtomicBool
::new(false));
2415 let done2
= done
.clone();
2417 let t
= thread
::spawn(move || {
2418 while !done2
.load(Ordering
::SeqCst
) {
2419 if let Ok((mut socket
, _
)) = listener
.accept() {
2420 drop(socket
.write_all(b
"foo\r\n"));
2425 let repo
= git2
::Repository
::open(&git_project2
.root()).unwrap();
2426 let url
= format
!("https://{}:{}/", addr
.ip(), addr
.port());
2428 let mut s
= repo
.submodule(&url
, Path
::new("bar"), false).unwrap();
2429 let subrepo
= s
.open().unwrap();
2430 let mut cfg
= subrepo
.config().unwrap();
2431 cfg
.set_str("user.email", "foo@bar.com").unwrap();
2432 cfg
.set_str("user.name", "Foo Bar").unwrap();
2433 git
::commit(&subrepo
);
2434 s
.add_finalize().unwrap();
2439 let repo
= git2
::Repository
::open(&git_project
.root()).unwrap();
2440 let url
= path2url(git_project2
.root()).to_string();
2441 git
::add_submodule(&repo
, &url
, Path
::new("src"));
2445 let project
= project
2456 dep1 = {{ git = '{}' }}
2461 .file("src/lib.rs", "")
2467 .with_stderr_contains(" failed to update submodule `src`")
2468 .with_stderr_contains(" failed to update submodule `bar`")
2473 .with_stderr_contains(" failed to update submodule `src`")
2474 .with_stderr_contains(" failed to update submodule `bar`")
2477 done
.store(true, Ordering
::SeqCst
);
2478 drop(TcpStream
::connect(&addr
));
2484 if disable_git_cli() {
2487 let project
= project();
2488 let git_project
= git
::new("dep1", |project
| {
2490 .file("Cargo.toml", &basic_manifest("dep1", "0.5.0"))
2491 .file("src/lib.rs", "")
2494 let project
= project
2505 dep1 = {{ git = '{}' }}
2510 .file("src/lib.rs", "")
2515 git-fetch-with-cli = true
2521 [UPDATING] git repository `[..]`
2522 [RUNNING] `git fetch [..]`
2523 [COMPILING] dep1 [..]
2524 [RUNNING] `rustc [..]`
2525 [COMPILING] foo [..]
2526 [RUNNING] `rustc [..]`
2530 project
.cargo("build -v").with_stderr(stderr
).run();
2534 fn templatedir_doesnt_cause_problems() {
2535 let git_project2
= git
::new("dep2", |project
| {
2537 .file("Cargo.toml", &basic_manifest("dep2", "0.5.0"))
2538 .file("src/lib.rs", "")
2540 let git_project
= git
::new("dep1", |project
| {
2542 .file("Cargo.toml", &basic_manifest("dep1", "0.5.0"))
2543 .file("src/lib.rs", "")
2556 dep1 = {{ git = '{}' }}
2561 .file("src/main.rs", "fn main() {}")
2564 File
::create(paths
::home().join(".gitconfig"))
2584 p
.cargo("build").run();
2588 fn git_with_cli_force() {
2589 if disable_git_cli() {
2592 // Supports a force-pushed repo.
2593 let git_project
= git
::new("dep1", |project
| {
2595 .file("Cargo.toml", &basic_lib_manifest("dep1"))
2596 .file("src/lib.rs", r
#"pub fn f() { println!("one"); }"#)
2609 dep1 = {{ git = "{}" }}
2614 .file("src
/main
.rs
", "fn main() { dep1::f(); }
")
2619 git
-fetch
-with
-cli
= true
2623 p.cargo("build
").run();
2624 p.rename_run("foo
", "foo1
").with_stdout("one
").run();
2626 // commit --amend a change that will require a force fetch.
2627 let repo = git2::Repository::open(&git_project.root()).unwrap();
2628 git_project.change_file("src
/lib
.rs
", r#"pub fn f() { println!("two"); }
"#);
2630 let id = repo.refname_to_id("HEAD
").unwrap();
2631 let commit = repo.find_commit(id).unwrap();
2632 let tree_id = t!(t!(repo.index()).write_tree());
2639 Some(&t!(repo.find_tree(tree_id)))
2641 // Perform the fetch.
2642 p.cargo("update
").run();
2643 p.cargo("build
").run();
2644 p.rename_run("foo
", "foo2
").with_stdout("two
").run();
2648 fn git_fetch_cli_env_clean() {
2649 if disable_git_cli() {
2652 // This tests that git-fetch-with-cli works when GIT_DIR environment
2653 // variable is set (for whatever reason).
2654 let git_dep = git::new("dep1
", |project| {
2656 .file("Cargo
.toml
", &basic_manifest("dep1
", "0.5.0"))
2657 .file("src
/lib
.rs
", "")
2660 let git_proj = git::new("foo
", |project| {
2670 dep1
= {{ git = '{}'
}}
2675 .file("src
/lib
.rs
", "pub extern crate dep1
;")
2680 git
-fetch
-with
-cli
= true
2685 // The directory set here isn't too important. Pointing to our own git
2686 // directory causes git to be confused and fail. Can also point to an
2687 // empty directory, or a nonexistent one.
2690 .env("GIT_DIR
", git_proj.root().join(".git
"))
2695 fn dirty_submodule() {
2696 // `cargo package` warns for dirty file in submodule.
2697 let (git_project, repo) = git::new_repo("foo
", |project| {
2699 .file("Cargo
.toml
", &basic_manifest("foo
", "0.5.0"))
2700 // This is necessary because `git::add` is too eager.
2701 .file(".gitignore
", "/target
")
2703 let git_project2 = git::new("src
", |project| {
2704 project.no_manifest().file("lib
.rs
", "pub fn f() {}
")
2707 let url = path2url(git_project2.root()).to_string();
2708 git::add_submodule(&repo, &url, Path::new("src
"));
2710 // Submodule added, but not committed.
2712 .cargo("package
--no
-verify
")
2716 [WARNING
] manifest has no
[..]
2718 [ERROR
] 1 files
in the working directory contain changes that were not yet committed into git
:
2722 to proceed despite
[..]
2728 git_project.cargo("package
--no
-verify
").run();
2730 // Modify file, check for warning.
2731 git_project.change_file("src
/lib
.rs
", "");
2733 .cargo("package
--no
-verify
")
2737 [WARNING
] manifest has no
[..]
2739 [ERROR
] 1 files
in the working directory contain changes that were not yet committed into git
:
2743 to proceed despite
[..]
2747 // Commit the change.
2748 let sub_repo = git2::Repository::open(git_project.root().join("src
")).unwrap();
2749 git::add(&sub_repo);
2750 git::commit(&sub_repo);
2753 git_project.cargo("package
--no
-verify
").run();
2755 // Try with a nested submodule.
2756 let git_project3 = git::new("bar
", |project| project.no_manifest().file("mod.rs
", ""));
2757 let url = path2url(git_project3.root()).to_string();
2758 git::add_submodule(&sub_repo, &url, Path::new("bar
"));
2760 .cargo("package
--no
-verify
")
2764 [WARNING
] manifest has no
[..]
2766 [ERROR
] 1 files
in the working directory contain changes that were not yet committed into git
:
2770 to proceed despite
[..]
2775 // Commit the submodule addition.
2776 git::commit(&sub_repo);
2779 git_project.cargo("package
--no
-verify
").run();
2780 // Modify within nested submodule.
2781 git_project.change_file("src
/bar
/mod.rs
", "//test");
2783 .cargo("package --no-verify")
2787 [WARNING] manifest has no [..]
2789 [ERROR] 1 files in the working directory contain changes that were not yet committed into git:
2793 to proceed despite [..]
2797 // And commit the change.
2798 let sub_sub_repo
= git2
::Repository
::open(git_project
.root().join("src/bar")).unwrap();
2799 git
::add(&sub_sub_repo
);
2800 git
::commit(&sub_sub_repo
);
2801 git
::add(&sub_repo
);
2802 git
::commit(&sub_repo
);
2805 git_project
.cargo("package --no-verify").run();