mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
feat: add cargo pkgid
support for cargo-script (#14961)
### What does this PR try to resolve? close https://github.com/rust-lang/cargo/issues/14831 In this PR, we added the `cargo pkgid` support for the cargo-script. For the package itself: ```console cargo pkgid --manifest-path foo.rs path+file:///my-project/foo.rs/foo#0.86.0 ``` For its dependence: ```console cargo pkgid --manifest-path foo.rs -p sqlx registry+https://github.com/rust-lang/crates.io-index#sqlx@0.7.4 ``` ### How should we test and review this PR? I have updated the unit tests and also added more test cases for it. ### Additional information None
This commit is contained in:
commit
f6514977ef
@ -18,13 +18,6 @@ pub fn cli() -> Command {
|
||||
|
||||
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
|
||||
let ws = args.workspace(gctx)?;
|
||||
if ws.root_maybe().is_embedded() {
|
||||
return Err(anyhow::format_err!(
|
||||
"{} is unsupported by `cargo pkgid`",
|
||||
ws.root_manifest().display()
|
||||
)
|
||||
.into());
|
||||
}
|
||||
if args.is_present_with_zero_values("package") {
|
||||
print_available_packages(&ws)?
|
||||
}
|
||||
|
@ -393,6 +393,9 @@ impl SourceId {
|
||||
.url
|
||||
.to_file_path()
|
||||
.expect("path sources cannot be remote");
|
||||
if crate::util::toml::is_embedded(&path) {
|
||||
anyhow::bail!("Single file packages cannot be used as dependencies")
|
||||
}
|
||||
Ok(Box::new(PathSource::new(&path, self, gctx)))
|
||||
}
|
||||
SourceKind::Registry | SourceKind::SparseRegistry => Ok(Box::new(
|
||||
|
@ -269,10 +269,11 @@ impl<'gctx> Workspace<'gctx> {
|
||||
let mut ws = Workspace::new_default(package.manifest_path().to_path_buf(), gctx);
|
||||
ws.is_ephemeral = true;
|
||||
ws.require_optional_deps = require_optional_deps;
|
||||
let key = ws.current_manifest.parent().unwrap();
|
||||
let id = package.package_id();
|
||||
let package = MaybePackage::Package(package);
|
||||
ws.packages.packages.insert(key.to_path_buf(), package);
|
||||
ws.packages
|
||||
.packages
|
||||
.insert(ws.current_manifest.clone(), package);
|
||||
ws.target_dir = if let Some(dir) = target_dir {
|
||||
Some(dir)
|
||||
} else {
|
||||
@ -538,11 +539,7 @@ impl<'gctx> Workspace<'gctx> {
|
||||
/// Returns a mutable iterator over all packages in this workspace
|
||||
pub fn members_mut(&mut self) -> impl Iterator<Item = &mut Package> {
|
||||
let packages = &mut self.packages.packages;
|
||||
let members: HashSet<_> = self
|
||||
.members
|
||||
.iter()
|
||||
.map(|path| path.parent().unwrap().to_owned())
|
||||
.collect();
|
||||
let members: HashSet<_> = self.members.iter().map(|path| path).collect();
|
||||
|
||||
packages.iter_mut().filter_map(move |(path, package)| {
|
||||
if members.contains(path) {
|
||||
@ -1163,7 +1160,6 @@ impl<'gctx> Workspace<'gctx> {
|
||||
|
||||
pub fn emit_warnings(&self) -> CargoResult<()> {
|
||||
for (path, maybe_pkg) in &self.packages.packages {
|
||||
let path = path.join("Cargo.toml");
|
||||
if let MaybePackage::Package(pkg) = maybe_pkg {
|
||||
if self.gctx.cli_unstable().cargo_lints {
|
||||
self.emit_lints(pkg, &path)?
|
||||
@ -1792,19 +1788,22 @@ impl<'gctx> Packages<'gctx> {
|
||||
}
|
||||
|
||||
fn maybe_get(&self, manifest_path: &Path) -> Option<&MaybePackage> {
|
||||
self.packages.get(manifest_path.parent().unwrap())
|
||||
self.packages.get(manifest_path)
|
||||
}
|
||||
|
||||
fn maybe_get_mut(&mut self, manifest_path: &Path) -> Option<&mut MaybePackage> {
|
||||
self.packages.get_mut(manifest_path.parent().unwrap())
|
||||
self.packages.get_mut(manifest_path)
|
||||
}
|
||||
|
||||
fn load(&mut self, manifest_path: &Path) -> CargoResult<&MaybePackage> {
|
||||
let key = manifest_path.parent().unwrap();
|
||||
match self.packages.entry(key.to_path_buf()) {
|
||||
match self.packages.entry(manifest_path.to_path_buf()) {
|
||||
Entry::Occupied(e) => Ok(e.into_mut()),
|
||||
Entry::Vacant(v) => {
|
||||
let source_id = SourceId::for_path(key)?;
|
||||
let source_id = if crate::util::toml::is_embedded(manifest_path) {
|
||||
SourceId::for_path(manifest_path)?
|
||||
} else {
|
||||
SourceId::for_path(manifest_path.parent().unwrap())?
|
||||
};
|
||||
let manifest = read_manifest(manifest_path, source_id, self.gctx)?;
|
||||
Ok(v.insert(match manifest {
|
||||
EitherManifest::Real(manifest) => {
|
||||
|
@ -182,8 +182,8 @@ fn depend_on_alt_registry_depends_on_crates_io() {
|
||||
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
|
||||
[CHECKING] baz v0.0.1
|
||||
[CHECKING] bar v0.0.1 (registry `alternative`)
|
||||
[CHECKING] foo v0.0.1 ([ROOT]/foo)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[CHECKING] foo v0.0.1 ([ROOT]/foo)
|
||||
|
||||
"#]]
|
||||
.unordered(),
|
||||
@ -441,8 +441,8 @@ fn alt_registry_and_crates_io_deps() {
|
||||
[DOWNLOADED] alt_reg_dep v0.1.0 (registry `alternative`)
|
||||
[CHECKING] crates_io_dep v0.0.1
|
||||
[CHECKING] alt_reg_dep v0.1.0 (registry `alternative`)
|
||||
[CHECKING] foo v0.0.1 ([ROOT]/foo)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[CHECKING] foo v0.0.1 ([ROOT]/foo)
|
||||
|
||||
"#]]
|
||||
.unordered(),
|
||||
|
@ -602,9 +602,9 @@ fn build_script_with_bin_artifacts() {
|
||||
.with_stderr_data(
|
||||
str![[r#"
|
||||
[LOCKING] 1 package to latest compatible version
|
||||
[COMPILING] foo v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[COMPILING] foo v0.0.0 ([ROOT]/foo)
|
||||
|
||||
"#]]
|
||||
.unordered(),
|
||||
@ -1433,7 +1433,6 @@ fn profile_override_basic() {
|
||||
str![[r#"
|
||||
[LOCKING] 1 package to latest compatible version
|
||||
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
|
||||
[COMPILING] foo v0.0.1 ([ROOT]/foo)
|
||||
[RUNNING] `rustc --crate-name build_script_build [..] -C opt-level=1 [..]`
|
||||
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..] -C opt-level=3 [..]`
|
||||
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..] -C opt-level=1 [..]`
|
||||
@ -1442,6 +1441,7 @@ fn profile_override_basic() {
|
||||
[RUNNING] `rustc --crate-name foo [..] -C opt-level=3 [..]`
|
||||
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
|
||||
[FINISHED] `dev` profile [optimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[COMPILING] foo v0.0.1 ([ROOT]/foo)
|
||||
|
||||
"#]]
|
||||
.unordered(),
|
||||
@ -1870,8 +1870,8 @@ fn allow_dep_renames_with_multiple_versions() {
|
||||
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
|
||||
[COMPILING] bar v1.0.0
|
||||
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
|
||||
[COMPILING] foo v0.0.0 ([ROOT]/foo)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[COMPILING] foo v0.0.0 ([ROOT]/foo)
|
||||
|
||||
"#]]
|
||||
.unordered(),
|
||||
@ -2835,13 +2835,13 @@ fn with_assumed_host_target_and_optional_build_dep() {
|
||||
.with_stderr_data(
|
||||
str![[r#"
|
||||
[LOCKING] 1 package to latest compatible version
|
||||
[COMPILING] foo v0.0.1 ([ROOT]/foo)
|
||||
[COMPILING] d1 v0.0.1 ([ROOT]/foo/d1)
|
||||
[RUNNING] `rustc --crate-name build_script_build --edition=2021 [..]--crate-type bin[..]
|
||||
[RUNNING] `rustc --crate-name d1 --edition=2021 [..]--crate-type bin[..]
|
||||
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
|
||||
[RUNNING] `rustc --crate-name foo --edition=2021 [..]--cfg[..]d1[..]
|
||||
[FINISHED] `dev` profile [..]
|
||||
[COMPILING] foo v0.0.1 ([ROOT]/foo)
|
||||
|
||||
"#]]
|
||||
.unordered(),
|
||||
@ -3199,8 +3199,8 @@ fn decouple_same_target_transitive_dep_from_artifact_dep_and_proc_macro() {
|
||||
[COMPILING] b v0.1.0 ([ROOT]/foo/b)
|
||||
[COMPILING] c v0.1.0 ([ROOT]/foo/c)
|
||||
[COMPILING] bar v0.1.0 ([ROOT]/foo/bar)
|
||||
[COMPILING] foo v0.1.0 ([ROOT]/foo)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
|
||||
[COMPILING] foo v0.1.0 ([ROOT]/foo)
|
||||
|
||||
"#]]
|
||||
.unordered(),
|
||||
|
@ -1814,13 +1814,13 @@ fn workspace_default_features2() {
|
||||
p.cargo("check")
|
||||
.with_stderr_data(
|
||||
str![[r#"
|
||||
[WARNING] [ROOT]/foo/workspace_only/Cargo.toml: `default_features` is deprecated in favor of `default-features` and will not work in the 2024 edition
|
||||
(in the `dep_workspace_only` dependency)
|
||||
[CHECKING] dep_package_only v0.1.0 ([ROOT]/foo/dep_package_only)
|
||||
[CHECKING] dep_workspace_only v0.1.0 ([ROOT]/foo/dep_workspace_only)
|
||||
[CHECKING] package_only v0.1.0 ([ROOT]/foo/package_only)
|
||||
[CHECKING] workspace_only v0.1.0 ([ROOT]/foo/workspace_only)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[WARNING] [ROOT]/foo/workspace_only/Cargo.toml: `default_features` is deprecated in favor of `default-features` and will not work in the 2024 edition
|
||||
|
||||
"#]]
|
||||
.unordered(),
|
||||
|
@ -2479,7 +2479,7 @@ fn main() {
|
||||
.with_stderr_data(str![[r#"
|
||||
[MIGRATING] foo.rs from 2021 edition to 2024
|
||||
[FIXED] foo.rs (1 fix)
|
||||
[CHECKING] foo v0.0.0 ([ROOT]/foo)
|
||||
[CHECKING] foo v0.0.0 ([ROOT]/foo/foo.rs)
|
||||
[MIGRATING] [ROOT]/home/.cargo/target/[HASH]/foo.rs from 2021 edition to 2024
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
|
@ -289,7 +289,7 @@ fn main() {}
|
||||
"edition": "2021",
|
||||
"features": {},
|
||||
"homepage": null,
|
||||
"id": "path+[ROOTURL]/foo#foo::bar@0.0.0",
|
||||
"id": "path+[ROOTURL]/foo/foo::bar.rs#foo::bar@0.0.0",
|
||||
"keywords": [],
|
||||
"license": null,
|
||||
"license_file": null,
|
||||
|
@ -40,7 +40,7 @@ args: []
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] echo v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] echo v0.0.0 ([ROOT]/foo/echo.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/echo[EXE]`
|
||||
|
||||
@ -63,7 +63,7 @@ args: []
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] echo v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] echo v0.0.0 ([ROOT]/foo/echo)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/echo[EXE]`
|
||||
|
||||
@ -117,7 +117,7 @@ args: []
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] echo v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] echo v0.0.0 ([ROOT]/foo/echo.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/echo[EXE]`
|
||||
|
||||
@ -204,7 +204,7 @@ Hello world!
|
||||
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
|
||||
|
||||
@ -234,7 +234,7 @@ Hello world!
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
|
||||
|
||||
@ -262,7 +262,7 @@ msg = undefined
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
|
||||
|
||||
@ -294,7 +294,7 @@ msg = hello
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
|
||||
|
||||
@ -422,7 +422,7 @@ line: 4
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
|
||||
|
||||
@ -446,7 +446,7 @@ args: ["-NotAnArg"]
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] -NotAnArg`
|
||||
|
||||
@ -470,7 +470,7 @@ args: ["-NotAnArg"]
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] -NotAnArg`
|
||||
|
||||
@ -494,7 +494,7 @@ args: ["--help"]
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`
|
||||
|
||||
@ -518,7 +518,7 @@ args: []
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] s-h-w-c- v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] s-h-w-c- v0.0.0 ([ROOT]/foo/s-h.w§c!.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/s-h-w-c-[EXE]`
|
||||
|
||||
@ -542,7 +542,7 @@ args: []
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] answer v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] answer v0.0.0 ([ROOT]/foo/42answer.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/answer[EXE]`
|
||||
|
||||
@ -564,7 +564,7 @@ args: []
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] package v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] package v0.0.0 ([ROOT]/foo/42.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/package[EXE]`
|
||||
|
||||
@ -714,7 +714,7 @@ Hello world!
|
||||
[DOWNLOADING] crates ...
|
||||
[DOWNLOADED] script v1.0.0 (registry `dummy-registry`)
|
||||
[COMPILING] script v1.0.0
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`
|
||||
|
||||
@ -750,7 +750,7 @@ Hello world!
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[LOCKING] 1 package to latest Rust [..] compatible version
|
||||
[COMPILING] bar v0.0.1 ([ROOT]/foo/bar)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`
|
||||
|
||||
@ -778,7 +778,7 @@ Hello world!
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`
|
||||
|
||||
@ -806,7 +806,7 @@ Hello world!
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`
|
||||
|
||||
@ -834,7 +834,7 @@ Hello world!
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`
|
||||
|
||||
@ -858,7 +858,7 @@ args: []
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
|
||||
|
||||
@ -885,7 +885,7 @@ args: []
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
|
||||
|
||||
@ -942,7 +942,7 @@ fn cmd_check_with_embedded() {
|
||||
.with_stdout_data("")
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[CHECKING] script v0.0.0 ([ROOT]/foo)
|
||||
[CHECKING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
"#]])
|
||||
@ -991,7 +991,7 @@ fn cmd_build_with_embedded() {
|
||||
.with_stdout_data("")
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
"#]])
|
||||
@ -1018,7 +1018,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] unittests script.rs ([ROOT]/home/.cargo/target/[HASH]/debug/deps/script-[HASH][EXE])
|
||||
|
||||
@ -1090,7 +1090,7 @@ fn cmd_metadata_with_embedded() {
|
||||
"edition": "2024",
|
||||
"features": {},
|
||||
"homepage": null,
|
||||
"id": "path+[ROOTURL]/foo#script@0.0.0",
|
||||
"id": "path+[ROOTURL]/foo/script.rs#script@0.0.0",
|
||||
"keywords": [],
|
||||
"license": null,
|
||||
"license_file": null,
|
||||
@ -1128,18 +1128,18 @@ fn cmd_metadata_with_embedded() {
|
||||
"dependencies": [],
|
||||
"deps": [],
|
||||
"features": [],
|
||||
"id": "path+[ROOTURL]/foo#script@0.0.0"
|
||||
"id": "path+[ROOTURL]/foo/script.rs#script@0.0.0"
|
||||
}
|
||||
],
|
||||
"root": "path+[ROOTURL]/foo#script@0.0.0"
|
||||
"root": "path+[ROOTURL]/foo/script.rs#script@0.0.0"
|
||||
},
|
||||
"target_directory": "[ROOT]/home/.cargo/target/[HASH]",
|
||||
"version": 1,
|
||||
"workspace_default_members": [
|
||||
"path+[ROOTURL]/foo#script@0.0.0"
|
||||
"path+[ROOTURL]/foo/script.rs#script@0.0.0"
|
||||
],
|
||||
"workspace_members": [
|
||||
"path+[ROOTURL]/foo#script@0.0.0"
|
||||
"path+[ROOTURL]/foo/script.rs#script@0.0.0"
|
||||
],
|
||||
"workspace_root": "[ROOT]/foo"
|
||||
}
|
||||
@ -1174,7 +1174,7 @@ fn cmd_read_manifest_with_embedded() {
|
||||
"edition": "2024",
|
||||
"features": {},
|
||||
"homepage": null,
|
||||
"id": "path+[ROOTURL]/foo#script@0.0.0",
|
||||
"id": "path+[ROOTURL]/foo/script.rs#script@0.0.0",
|
||||
"keywords": [],
|
||||
"license": null,
|
||||
"license_file": null,
|
||||
@ -1230,7 +1230,7 @@ args: []
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
|
||||
|
||||
@ -1247,7 +1247,7 @@ fn cmd_tree_with_embedded() {
|
||||
p.cargo("-Zscript tree --manifest-path script.rs")
|
||||
.masquerade_as_nightly_cargo(&["script"])
|
||||
.with_stdout_data(str![[r#"
|
||||
script v0.0.0 ([ROOT]/foo)
|
||||
script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
@ -1296,18 +1296,128 @@ fn cmd_verify_project_with_embedded() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
#[cargo_test(nightly, reason = "edition2024 hasn't hit stable yet")]
|
||||
fn cmd_pkgid_with_embedded() {
|
||||
let p = cargo_test_support::project()
|
||||
.file("script.rs", ECHO_SCRIPT)
|
||||
.build();
|
||||
|
||||
p.cargo("-Zscript script.rs")
|
||||
.masquerade_as_nightly_cargo(&["script"])
|
||||
.run();
|
||||
|
||||
p.cargo("-Zscript pkgid --manifest-path script.rs")
|
||||
.masquerade_as_nightly_cargo(&["script"])
|
||||
.with_stdout_data(str![[r#"
|
||||
path+[ROOTURL]/foo/script.rs#script@0.0.0
|
||||
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn cmd_pkgid_with_embedded_no_lock_file() {
|
||||
let p = cargo_test_support::project()
|
||||
.file("script.rs", ECHO_SCRIPT)
|
||||
.build();
|
||||
|
||||
p.cargo("-Zscript pkgid --manifest-path script.rs")
|
||||
.masquerade_as_nightly_cargo(&["script"])
|
||||
.with_status(101)
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo pkgid`
|
||||
[ERROR] a Cargo.lock must exist for this command
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test(nightly, reason = "edition2024 hasn't hit stable yet")]
|
||||
fn cmd_pkgid_with_embedded_dep() {
|
||||
Package::new("dep", "1.0.0").publish();
|
||||
let script = r#"#!/usr/bin/env cargo
|
||||
---
|
||||
[dependencies]
|
||||
dep = "1.0.0"
|
||||
---
|
||||
|
||||
fn main() {
|
||||
println!("Hello world!");
|
||||
}"#;
|
||||
let p = cargo_test_support::project()
|
||||
.file("script.rs", script)
|
||||
.build();
|
||||
|
||||
p.cargo("-Zscript script.rs")
|
||||
.masquerade_as_nightly_cargo(&["script"])
|
||||
.run();
|
||||
|
||||
p.cargo("-Zscript pkgid --manifest-path script.rs -p dep")
|
||||
.masquerade_as_nightly_cargo(&["script"])
|
||||
.with_stdout_data(str![[r#"
|
||||
registry+https://github.com/rust-lang/crates.io-index#dep@1.0.0
|
||||
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test(nightly, reason = "edition2024 hasn't hit stable yet")]
|
||||
fn script_as_dep() {
|
||||
let p = cargo_test_support::project()
|
||||
.file("script.rs", ECHO_SCRIPT)
|
||||
.file("src/lib.rs", "pub fn foo() {}")
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
script.path = "script.rs"
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("build")
|
||||
.masquerade_as_nightly_cargo(&["script"])
|
||||
.with_status(101)
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] no edition set: defaulting to the 2015 edition while the latest is 2024
|
||||
[ERROR] failed to get `script` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
|
||||
|
||||
Caused by:
|
||||
failed to load source for dependency `script`
|
||||
|
||||
Caused by:
|
||||
Unable to update [ROOT]/foo/script.rs
|
||||
|
||||
Caused by:
|
||||
Single file packages cannot be used as dependencies
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn cmd_install_with_embedded() {
|
||||
let p = cargo_test_support::project()
|
||||
.file("script.rs", ECHO_SCRIPT)
|
||||
.build();
|
||||
|
||||
p.cargo("-Zscript install --path script.rs")
|
||||
.masquerade_as_nightly_cargo(&["script"])
|
||||
.with_status(101)
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] `[ROOT]/foo/script.rs` is not a directory. --path must point to a directory containing a Cargo.toml file.
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
@ -1369,7 +1479,7 @@ CARGO_MANIFEST_PATH: [ROOT]/foo/script.rs
|
||||
"#]])
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user