summaryrefslogtreecommitdiffstats
path: root/src/tools/cargo/tests/testsuite/build_plan.rs
blob: 647bc123463c5b761bcc4b974210d2210909174b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//! Tests for --build-plan feature.

use cargo_test_support::registry::Package;
use cargo_test_support::{basic_bin_manifest, basic_manifest, main_file, project};

#[cargo_test]
fn cargo_build_plan_simple() {
    let p = project()
        .file("Cargo.toml", &basic_bin_manifest("foo"))
        .file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
        .build();

    p.cargo("build --build-plan -Zunstable-options")
        .masquerade_as_nightly_cargo(&["build-plan"])
        .with_json(
            r#"
            {
                "inputs": [
                    "[..]/foo/Cargo.toml"
                ],
                "invocations": [
                    {
                        "args": "{...}",
                        "cwd": "[..]/cit/[..]/foo",
                        "deps": [],
                        "env": "{...}",
                        "kind": null,
                        "links": "{...}",
                        "outputs": "{...}",
                        "package_name": "foo",
                        "package_version": "0.5.0",
                        "program": "rustc",
                        "target_kind": ["bin"],
                        "compile_mode": "build"
                    }
                ]
            }
            "#,
        )
        .run();
    assert!(!p.bin("foo").is_file());
}

#[cargo_test]
fn cargo_build_plan_single_dep() {
    let p = project()
        .file(
            "Cargo.toml",
            r#"
                [package]
                name = "foo"
                authors = []
                version = "0.5.0"

                [dependencies]
                bar = { path = "bar" }
            "#,
        )
        .file(
            "src/lib.rs",
            r#"
                extern crate bar;
                pub fn foo() { bar::bar(); }

                #[test]
                fn test() { foo(); }
            "#,
        )
        .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
        .file("bar/src/lib.rs", "pub fn bar() {}")
        .build();
    p.cargo("build --build-plan -Zunstable-options")
        .masquerade_as_nightly_cargo(&["build-plan"])
        .with_json(
            r#"
            {
                "inputs": [
                    "[..]/foo/Cargo.toml",
                    "[..]/foo/bar/Cargo.toml"
                ],
                "invocations": [
                    {
                        "args": "{...}",
                        "cwd": "[..]/cit/[..]/foo",
                        "deps": [],
                        "env": "{...}",
                        "kind": null,
                        "links": "{...}",
                        "outputs": [
                            "[..]/foo/target/debug/deps/libbar-[..].rlib",
                            "[..]/foo/target/debug/deps/libbar-[..].rmeta"
                        ],
                        "package_name": "bar",
                        "package_version": "0.0.1",
                        "program": "rustc",
                        "target_kind": ["lib"],
                        "compile_mode": "build"
                    },
                    {
                        "args": "{...}",
                        "cwd": "[..]/cit/[..]/foo",
                        "deps": [0],
                        "env": "{...}",
                        "kind": null,
                        "links": "{...}",
                        "outputs": [
                            "[..]/foo/target/debug/deps/libfoo-[..].rlib",
                            "[..]/foo/target/debug/deps/libfoo-[..].rmeta"
                        ],
                        "package_name": "foo",
                        "package_version": "0.5.0",
                        "program": "rustc",
                        "target_kind": ["lib"],
                        "compile_mode": "build"
                    }
                ]
            }
            "#,
        )
        .run();
}

#[cargo_test]
fn cargo_build_plan_build_script() {
    let p = project()
        .file(
            "Cargo.toml",
            r#"
                [package]

                name = "foo"
                version = "0.5.0"
                authors = ["wycats@example.com"]
                build = "build.rs"
            "#,
        )
        .file("src/main.rs", r#"fn main() {}"#)
        .file("build.rs", r#"fn main() {}"#)
        .build();

    p.cargo("build --build-plan -Zunstable-options")
        .masquerade_as_nightly_cargo(&["build-plan"])
        .with_json(
            r#"
            {
                "inputs": [
                    "[..]/foo/Cargo.toml"
                ],
                "invocations": [
                    {
                        "args": "{...}",
                        "cwd": "[..]/cit/[..]/foo",
                        "deps": [],
                        "env": "{...}",
                        "kind": null,
                        "links": "{...}",
                        "outputs": "{...}",
                        "package_name": "foo",
                        "package_version": "0.5.0",
                        "program": "rustc",
                        "target_kind": ["custom-build"],
                        "compile_mode": "build"
                    },
                    {
                        "args": "{...}",
                        "cwd": "[..]/cit/[..]/foo",
                        "deps": [0],
                        "env": "{...}",
                        "kind": null,
                        "links": "{...}",
                        "outputs": [],
                        "package_name": "foo",
                        "package_version": "0.5.0",
                        "program": "[..]/build-script-build",
                        "target_kind": ["custom-build"],
                        "compile_mode": "run-custom-build"
                    },
                    {
                        "args": "{...}",
                        "cwd": "[..]/cit/[..]/foo",
                        "deps": [1],
                        "env": "{...}",
                        "kind": null,
                        "links": "{...}",
                        "outputs": "{...}",
                        "package_name": "foo",
                        "package_version": "0.5.0",
                        "program": "rustc",
                        "target_kind": ["bin"],
                        "compile_mode": "build"
                    }
                ]
            }
            "#,
        )
        .run();
}

#[cargo_test]
fn build_plan_with_dev_dep() {
    Package::new("bar", "0.1.0").publish();

    let p = project()
        .file(
            "Cargo.toml",
            r#"
                [package]
                name = "foo"
                version = "0.5.0"
                authors = []

                [dev-dependencies]
                bar = "*"
            "#,
        )
        .file("src/lib.rs", "")
        .build();

    p.cargo("build --build-plan -Zunstable-options")
        .masquerade_as_nightly_cargo(&["build-plan"])
        .run();
}