2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for publishing using the `--target` flag.
|
|
|
|
|
2017-08-27 06:49:17 +00:00
|
|
|
use std::fs::File;
|
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::{cross_compile, project, publish, registry};
|
2017-08-27 06:49:17 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-08-27 06:49:17 +00:00
|
|
|
fn simple_cross_package() {
|
2018-03-14 15:17:44 +00:00
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
repository = "bar"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/main.rs",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
use std::env;
|
|
|
|
fn main() {{
|
|
|
|
assert_eq!(env::consts::ARCH, "{}");
|
|
|
|
}}
|
|
|
|
"#,
|
2018-03-14 15:17:44 +00:00
|
|
|
cross_compile::alternate_arch()
|
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-08-27 06:49:17 +00:00
|
|
|
|
|
|
|
let target = cross_compile::alternate();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("package --target")
|
|
|
|
.arg(&target)
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2021-06-27 19:18:36 +00:00
|
|
|
"\
|
|
|
|
[PACKAGING] foo v0.0.0 ([CWD])
|
|
|
|
[VERIFYING] foo v0.0.0 ([CWD])
|
|
|
|
[COMPILING] foo v0.0.0 ([CWD]/target/package/foo-0.0.0)
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2022-10-21 03:05:34 +00:00
|
|
|
[PACKAGED] 4 files, [..] ([..] compressed)
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-08-27 06:49:17 +00:00
|
|
|
|
|
|
|
// Check that the tarball contains the files
|
|
|
|
let f = File::open(&p.root().join("target/package/foo-0.0.0.crate")).unwrap();
|
2018-12-30 04:46:15 +00:00
|
|
|
publish::validate_crate_contents(
|
|
|
|
f,
|
|
|
|
"foo-0.0.0.crate",
|
2019-06-10 19:38:51 +00:00
|
|
|
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
|
2018-12-30 04:46:15 +00:00
|
|
|
&[],
|
|
|
|
);
|
2017-08-27 06:49:17 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-08-27 06:49:17 +00:00
|
|
|
fn publish_with_target() {
|
2018-03-14 15:17:44 +00:00
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-27 06:49:17 +00:00
|
|
|
|
2022-10-07 20:19:40 +00:00
|
|
|
// `publish` generally requires a remote registry
|
|
|
|
let registry = registry::RegistryBuilder::new().http_api().build();
|
2017-08-27 06:49:17 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
repository = "bar"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/main.rs",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
use std::env;
|
|
|
|
fn main() {{
|
|
|
|
assert_eq!(env::consts::ARCH, "{}");
|
|
|
|
}}
|
|
|
|
"#,
|
2018-03-14 15:17:44 +00:00
|
|
|
cross_compile::alternate_arch()
|
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-08-27 06:49:17 +00:00
|
|
|
|
|
|
|
let target = cross_compile::alternate();
|
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("publish")
|
|
|
|
.replace_crates_io(registry.index_url())
|
2018-08-28 09:20:03 +00:00
|
|
|
.arg("--target")
|
|
|
|
.arg(&target)
|
2021-06-27 19:18:36 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
2022-08-31 05:53:47 +00:00
|
|
|
[UPDATING] crates.io index
|
2021-06-27 19:18:36 +00:00
|
|
|
[PACKAGING] foo v0.0.0 ([CWD])
|
|
|
|
[VERIFYING] foo v0.0.0 ([CWD])
|
|
|
|
[COMPILING] foo v0.0.0 ([CWD]/target/package/foo-0.0.0)
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2022-10-21 03:05:34 +00:00
|
|
|
[PACKAGED] [..]
|
2021-06-27 19:18:36 +00:00
|
|
|
[UPLOADING] foo v0.0.0 ([CWD])
|
2023-02-17 17:44:53 +00:00
|
|
|
[UPLOADED] foo v0.0.0 to registry `crates-io`
|
2023-02-14 20:57:25 +00:00
|
|
|
note: Waiting [..]
|
|
|
|
You may press ctrl-c [..]
|
2023-02-17 17:44:53 +00:00
|
|
|
[PUBLISHED] foo v0.0.0 at registry `crates-io`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2021-06-27 19:18:36 +00:00
|
|
|
)
|
2018-12-08 11:19:47 +00:00
|
|
|
.run();
|
2017-07-22 03:12:21 +00:00
|
|
|
}
|