@@ -10,7 +10,7 @@ use cargo::{
1010use cargo_test_support:: paths:: { root, CargoPathExt } ;
1111use cargo_test_support:: registry:: Package ;
1212use cargo_test_support:: {
13- basic_bin_manifest, basic_lib_manifest, basic_manifest, is_nightly, lines_match_unordered,
13+ basic_bin_manifest, basic_lib_manifest, basic_manifest, git , is_nightly, lines_match_unordered,
1414 main_file, paths, project, rustc_host, sleep_ms, symlink_supported, t, Execs , ProjectBuilder ,
1515} ;
1616use std:: env;
@@ -5179,3 +5179,83 @@ fn build_script_o0_default_even_with_release() {
51795179 . with_stderr_does_not_contain ( "[..]build_script_build[..]opt-level[..]" )
51805180 . run ( ) ;
51815181}
5182+
5183+ #[ cargo_test]
5184+ fn primary_package_env_var ( ) {
5185+ // "foo" depends on "bar" (local) which depends on "baz" (git) which depends on "qux" (registry)
5186+ // Test that CARGO_PRIMARY_PACKAGE is enabled only for "foo".
5187+
5188+ Package :: new ( "qux" , "1.0.0" )
5189+ . file ( "src/lib.rs" , "" )
5190+ . publish ( ) ;
5191+
5192+ let baz = git:: new ( "baz" , |project| {
5193+ project
5194+ . file (
5195+ "Cargo.toml" ,
5196+ r#"
5197+ [package]
5198+ name = "baz"
5199+ version = "1.0.0"
5200+
5201+ [dependencies]
5202+ qux = "1.0"
5203+ "# ,
5204+ )
5205+ . file ( "src/lib.rs" , "extern crate qux;" )
5206+ } ) ;
5207+
5208+ let foo = project ( )
5209+ . file (
5210+ "Cargo.toml" ,
5211+ r#"
5212+ [package]
5213+ name = "foo"
5214+ version = "1.0.0"
5215+
5216+ [dependencies]
5217+ bar = {path = "bar"}
5218+ "# ,
5219+ )
5220+ . file ( "src/lib.rs" , "extern crate bar;" )
5221+ . file (
5222+ "bar/Cargo.toml" ,
5223+ & format ! (
5224+ r#"
5225+ [package]
5226+ name = "bar"
5227+ version = "1.0.0"
5228+
5229+ [dependencies]
5230+ baz = {{ git = '{}' }}
5231+ "# ,
5232+ baz. url( )
5233+ ) ,
5234+ )
5235+ . file ( "bar/src/lib.rs" , "extern crate baz;" )
5236+ . build ( ) ;
5237+
5238+ foo. cargo ( "build -vv" )
5239+ . with_stderr_contains ( "[COMPILING] qux[..]" )
5240+ . with_stderr_line_without (
5241+ & [ "[RUNNING]" , "CARGO_CRATE_NAME=qux" ] ,
5242+ & [ "CARGO_PRIMARY_PACKAGE=1" ] ,
5243+ )
5244+ . with_stderr_contains ( "[COMPILING] baz[..]" )
5245+ . with_stderr_line_without (
5246+ & [ "[RUNNING]" , "CARGO_CRATE_NAME=baz" ] ,
5247+ & [ "CARGO_PRIMARY_PACKAGE=1" ] ,
5248+ )
5249+ . with_stderr_contains ( "[COMPILING] bar[..]" )
5250+ . with_stderr_line_without (
5251+ & [ "[RUNNING]" , "CARGO_CRATE_NAME=bar" ] ,
5252+ & [ "CARGO_PRIMARY_PACKAGE=1" ] ,
5253+ )
5254+ . with_stderr_contains (
5255+ "\
5256+ [COMPILING] foo[..]
5257+ [RUNNING] [..] CARGO_CRATE_NAME=foo [..] CARGO_PRIMARY_PACKAGE=1 [..]
5258+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]" ,
5259+ )
5260+ . run ( ) ;
5261+ }
0 commit comments