1
1
//! Tests for the new feature resolver.
2
2
3
3
use cargo_test_support:: cross_compile:: { self , alternate} ;
4
+ use cargo_test_support:: install:: cargo_home;
4
5
use cargo_test_support:: paths:: CargoPathExt ;
5
6
use cargo_test_support:: publish:: validate_crate_contents;
6
7
use cargo_test_support:: registry:: { Dependency , Package } ;
@@ -1987,8 +1988,6 @@ fn doc_optional() {
1987
1988
[DOWNLOADING] crates ...
1988
1989
[DOWNLOADED] spin v1.0.0 [..]
1989
1990
[DOWNLOADED] bar v1.0.0 [..]
1990
- [DOWNLOADING] crates ...
1991
- [DOWNLOADED] enabler v1.0.0 [..]
1992
1991
[DOCUMENTING] bar v1.0.0
1993
1992
[CHECKING] bar v1.0.0
1994
1993
[DOCUMENTING] foo v0.1.0 [..]
@@ -1997,3 +1996,246 @@ fn doc_optional() {
1997
1996
)
1998
1997
. run ( ) ;
1999
1998
}
1999
+
2000
+ #[ cargo_test]
2001
+ fn minimal_download ( ) {
2002
+ // Various checks that it only downloads the minimum set of dependencies
2003
+ // needed in various situations.
2004
+ //
2005
+ // This checks several permutations of the different
2006
+ // host_dep/dev_dep/itarget settings. These 3 are planned to be stabilized
2007
+ // together, so there isn't much need to be concerned about how the behave
2008
+ // independently. However, there are some cases where they do behave
2009
+ // independently. Specifically:
2010
+ //
2011
+ // * `cargo test` forces dev_dep decoupling to be disabled.
2012
+ // * `cargo tree --target=all` forces ignore_inactive_targets off and decouple_dev_deps off.
2013
+ // * `cargo tree --target=all -e normal` forces ignore_inactive_targets off.
2014
+ //
2015
+ // However, `cargo tree` is a little weird because it downloads everything
2016
+ // anyways.
2017
+ //
2018
+ // So to summarize the different permutations:
2019
+ //
2020
+ // dev_dep | host_dep | itarget | Notes
2021
+ // --------|----------|---------|----------------------------
2022
+ // | | | -Zfeatures=compare (new resolver should behave same as old)
2023
+ // | | ✓ | This scenario should not happen.
2024
+ // | ✓ | | `cargo tree --target=all -Zfeatures=all`†
2025
+ // | ✓ | ✓ | `cargo test`
2026
+ // ✓ | | | This scenario should not happen.
2027
+ // ✓ | | ✓ | This scenario should not happen.
2028
+ // ✓ | ✓ | | `cargo tree --target=all -e normal -Z features=all`†
2029
+ // ✓ | ✓ | ✓ | A normal build.
2030
+ //
2031
+ // † — However, `cargo tree` downloads everything.
2032
+ Package :: new ( "normal" , "1.0.0" ) . publish ( ) ;
2033
+ Package :: new ( "normal_pm" , "1.0.0" ) . publish ( ) ;
2034
+ Package :: new ( "normal_opt" , "1.0.0" ) . publish ( ) ;
2035
+ Package :: new ( "dev_dep" , "1.0.0" ) . publish ( ) ;
2036
+ Package :: new ( "dev_dep_pm" , "1.0.0" ) . publish ( ) ;
2037
+ Package :: new ( "build_dep" , "1.0.0" ) . publish ( ) ;
2038
+ Package :: new ( "build_dep_pm" , "1.0.0" ) . publish ( ) ;
2039
+ Package :: new ( "build_dep_opt" , "1.0.0" ) . publish ( ) ;
2040
+
2041
+ Package :: new ( "itarget_normal" , "1.0.0" ) . publish ( ) ;
2042
+ Package :: new ( "itarget_normal_pm" , "1.0.0" ) . publish ( ) ;
2043
+ Package :: new ( "itarget_dev_dep" , "1.0.0" ) . publish ( ) ;
2044
+ Package :: new ( "itarget_dev_dep_pm" , "1.0.0" ) . publish ( ) ;
2045
+ Package :: new ( "itarget_build_dep" , "1.0.0" ) . publish ( ) ;
2046
+ Package :: new ( "itarget_build_dep_pm" , "1.0.0" ) . publish ( ) ;
2047
+
2048
+ let p = project ( )
2049
+ . file (
2050
+ "Cargo.toml" ,
2051
+ r#"
2052
+ [package]
2053
+ name = "foo"
2054
+ version = "0.1.0"
2055
+
2056
+ [dependencies]
2057
+ normal = "1.0"
2058
+ normal_pm = "1.0"
2059
+ normal_opt = { version = "1.0", optional = true }
2060
+
2061
+ [dev-dependencies]
2062
+ dev_dep = "1.0"
2063
+ dev_dep_pm = "1.0"
2064
+
2065
+ [build-dependencies]
2066
+ build_dep = "1.0"
2067
+ build_dep_pm = "1.0"
2068
+ build_dep_opt = { version = "1.0", optional = true }
2069
+
2070
+ [target.'cfg(whatever)'.dependencies]
2071
+ itarget_normal = "1.0"
2072
+ itarget_normal_pm = "1.0"
2073
+
2074
+ [target.'cfg(whatever)'.dev-dependencies]
2075
+ itarget_dev_dep = "1.0"
2076
+ itarget_dev_dep_pm = "1.0"
2077
+
2078
+ [target.'cfg(whatever)'.build-dependencies]
2079
+ itarget_build_dep = "1.0"
2080
+ itarget_build_dep_pm = "1.0"
2081
+ "# ,
2082
+ )
2083
+ . file ( "src/lib.rs" , "" )
2084
+ . file ( "build.rs" , "fn main() {}" )
2085
+ . build ( ) ;
2086
+
2087
+ let clear = || {
2088
+ cargo_home ( ) . join ( "registry/cache" ) . rm_rf ( ) ;
2089
+ cargo_home ( ) . join ( "registry/src" ) . rm_rf ( ) ;
2090
+ p. build_dir ( ) . rm_rf ( ) ;
2091
+ } ;
2092
+
2093
+ // none
2094
+ // Should be the same as `-Zfeatures=all`
2095
+ p. cargo ( "check -Zfeatures=compare" )
2096
+ . masquerade_as_nightly_cargo ( )
2097
+ . with_stderr_unordered (
2098
+ "\
2099
+ [UPDATING] [..]
2100
+ [DOWNLOADING] crates ...
2101
+ [DOWNLOADED] normal_pm v1.0.0 [..]
2102
+ [DOWNLOADED] normal v1.0.0 [..]
2103
+ [DOWNLOADED] build_dep_pm v1.0.0 [..]
2104
+ [DOWNLOADED] build_dep v1.0.0 [..]
2105
+ [COMPILING] build_dep v1.0.0
2106
+ [COMPILING] build_dep_pm v1.0.0
2107
+ [CHECKING] normal_pm v1.0.0
2108
+ [CHECKING] normal v1.0.0
2109
+ [COMPILING] foo v0.1.0 [..]
2110
+ [FINISHED] [..]
2111
+ " ,
2112
+ )
2113
+ . run ( ) ;
2114
+ clear ( ) ;
2115
+
2116
+ // all
2117
+ p. cargo ( "check -Zfeatures=all" )
2118
+ . masquerade_as_nightly_cargo ( )
2119
+ . with_stderr_unordered (
2120
+ "\
2121
+ [DOWNLOADING] crates ...
2122
+ [DOWNLOADED] normal_pm v1.0.0 [..]
2123
+ [DOWNLOADED] normal v1.0.0 [..]
2124
+ [DOWNLOADED] build_dep_pm v1.0.0 [..]
2125
+ [DOWNLOADED] build_dep v1.0.0 [..]
2126
+ [COMPILING] build_dep v1.0.0
2127
+ [COMPILING] build_dep_pm v1.0.0
2128
+ [CHECKING] normal v1.0.0
2129
+ [CHECKING] normal_pm v1.0.0
2130
+ [COMPILING] foo v0.1.0 [..]
2131
+ [FINISHED] [..]
2132
+ " ,
2133
+ )
2134
+ . run ( ) ;
2135
+ clear ( ) ;
2136
+
2137
+ // This disables decouple_dev_deps.
2138
+ p. cargo ( "test --no-run -Zfeatures=all" )
2139
+ . masquerade_as_nightly_cargo ( )
2140
+ . with_stderr_unordered (
2141
+ "\
2142
+ [DOWNLOADING] crates ...
2143
+ [DOWNLOADED] normal_pm v1.0.0 [..]
2144
+ [DOWNLOADED] normal v1.0.0 [..]
2145
+ [DOWNLOADED] dev_dep_pm v1.0.0 [..]
2146
+ [DOWNLOADED] dev_dep v1.0.0 [..]
2147
+ [DOWNLOADED] build_dep_pm v1.0.0 [..]
2148
+ [DOWNLOADED] build_dep v1.0.0 [..]
2149
+ [COMPILING] build_dep v1.0.0
2150
+ [COMPILING] build_dep_pm v1.0.0
2151
+ [COMPILING] normal_pm v1.0.0
2152
+ [COMPILING] normal v1.0.0
2153
+ [COMPILING] dev_dep_pm v1.0.0
2154
+ [COMPILING] dev_dep v1.0.0
2155
+ [COMPILING] foo v0.1.0 [..]
2156
+ [FINISHED] [..]
2157
+ " ,
2158
+ )
2159
+ . run ( ) ;
2160
+ clear ( ) ;
2161
+
2162
+ // This disables itarget, but leaves decouple_dev_deps enabled. However,
2163
+ // `cargo tree` downloads everything anyways. Ideally `cargo tree` should
2164
+ // be a little smarter, but that would make it a bit more complicated. The
2165
+ // two "Downloading" lines are because `download_accessible` doesn't
2166
+ // download enough (`cargo tree` really wants everything). Again, that
2167
+ // could be cleaner, but is difficult.
2168
+ p. cargo ( "tree -e normal --target=all -Zfeatures=all" )
2169
+ . masquerade_as_nightly_cargo ( )
2170
+ . with_stderr_unordered (
2171
+ "\
2172
+ [DOWNLOADING] crates ...
2173
+ [DOWNLOADING] crates ...
2174
+ [DOWNLOADED] normal v1.0.0 [..]
2175
+ [DOWNLOADED] dev_dep v1.0.0 [..]
2176
+ [DOWNLOADED] normal_pm v1.0.0 [..]
2177
+ [DOWNLOADED] build_dep v1.0.0 [..]
2178
+ [DOWNLOADED] dev_dep_pm v1.0.0 [..]
2179
+ [DOWNLOADED] build_dep_pm v1.0.0 [..]
2180
+ [DOWNLOADED] itarget_normal v1.0.0 [..]
2181
+ [DOWNLOADED] itarget_dev_dep v1.0.0 [..]
2182
+ [DOWNLOADED] itarget_normal_pm v1.0.0 [..]
2183
+ [DOWNLOADED] itarget_build_dep v1.0.0 [..]
2184
+ [DOWNLOADED] itarget_dev_dep_pm v1.0.0 [..]
2185
+ [DOWNLOADED] itarget_build_dep_pm v1.0.0 [..]
2186
+ " ,
2187
+ )
2188
+ . with_stdout (
2189
+ "\
2190
+ foo v0.1.0 ([ROOT]/foo)
2191
+ ├── itarget_normal v1.0.0
2192
+ ├── itarget_normal_pm v1.0.0
2193
+ ├── normal v1.0.0
2194
+ └── normal_pm v1.0.0
2195
+ " ,
2196
+ )
2197
+ . run ( ) ;
2198
+ clear ( ) ;
2199
+
2200
+ // This disables itarget and decouple_dev_deps.
2201
+ p. cargo ( "tree --target=all -Zfeatures=all" )
2202
+ . masquerade_as_nightly_cargo ( )
2203
+ . with_stderr_unordered (
2204
+ "\
2205
+ [DOWNLOADING] crates ...
2206
+ [DOWNLOADED] normal_pm v1.0.0 [..]
2207
+ [DOWNLOADED] normal v1.0.0 [..]
2208
+ [DOWNLOADED] itarget_normal_pm v1.0.0 [..]
2209
+ [DOWNLOADED] itarget_normal v1.0.0 [..]
2210
+ [DOWNLOADED] itarget_dev_dep_pm v1.0.0 [..]
2211
+ [DOWNLOADED] itarget_dev_dep v1.0.0 [..]
2212
+ [DOWNLOADED] itarget_build_dep_pm v1.0.0 [..]
2213
+ [DOWNLOADED] itarget_build_dep v1.0.0 [..]
2214
+ [DOWNLOADED] dev_dep_pm v1.0.0 [..]
2215
+ [DOWNLOADED] dev_dep v1.0.0 [..]
2216
+ [DOWNLOADED] build_dep_pm v1.0.0 [..]
2217
+ [DOWNLOADED] build_dep v1.0.0 [..]
2218
+ " ,
2219
+ )
2220
+ . with_stdout (
2221
+ "\
2222
+ foo v0.1.0 ([ROOT]/foo)
2223
+ ├── itarget_normal v1.0.0
2224
+ ├── itarget_normal_pm v1.0.0
2225
+ ├── normal v1.0.0
2226
+ └── normal_pm v1.0.0
2227
+ [build-dependencies]
2228
+ ├── build_dep v1.0.0
2229
+ ├── build_dep_pm v1.0.0
2230
+ ├── itarget_build_dep v1.0.0
2231
+ └── itarget_build_dep_pm v1.0.0
2232
+ [dev-dependencies]
2233
+ ├── dev_dep v1.0.0
2234
+ ├── dev_dep_pm v1.0.0
2235
+ ├── itarget_dev_dep v1.0.0
2236
+ └── itarget_dev_dep_pm v1.0.0
2237
+ " ,
2238
+ )
2239
+ . run ( ) ;
2240
+ clear ( ) ;
2241
+ }
0 commit comments