Skip to content

Commit 2b247ff

Browse files
committed
make cargo script ignore surrounding workspace
1 parent 03a2a29 commit 2b247ff

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/cargo/util/toml/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use cargo_platform::Platform;
1313
use cargo_util::paths;
1414
use cargo_util_schemas::manifest::{
1515
self, PackageName, PathBaseName, TomlDependency, TomlDetailedDependency, TomlManifest,
16+
TomlWorkspace,
1617
};
1718
use cargo_util_schemas::manifest::{RustVersion, StringOrBool};
1819
use itertools::Itertools;
@@ -80,7 +81,8 @@ pub fn read_manifest(
8081
let empty = Vec::new();
8182
let cargo_features = original_toml.cargo_features.as_ref().unwrap_or(&empty);
8283
let features = Features::new(cargo_features, gctx, &mut warnings, source_id.is_path())?;
83-
let workspace_config = to_workspace_config(&original_toml, path, gctx, &mut warnings)?;
84+
let workspace_config =
85+
to_workspace_config(&original_toml, path, is_embedded, gctx, &mut warnings)?;
8486
if let WorkspaceConfig::Root(ws_root_config) = &workspace_config {
8587
let package_root = path.parent().unwrap();
8688
gctx.ws_roots
@@ -211,9 +213,14 @@ fn stringify(dst: &mut String, path: &serde_ignored::Path<'_>) {
211213
fn to_workspace_config(
212214
original_toml: &manifest::TomlManifest,
213215
manifest_file: &Path,
216+
is_embedded: bool,
214217
gctx: &GlobalContext,
215218
warnings: &mut Vec<String>,
216219
) -> CargoResult<WorkspaceConfig> {
220+
if is_embedded {
221+
let ws_root_config = to_workspace_root_config(&TomlWorkspace::default(), manifest_file);
222+
return Ok(WorkspaceConfig::Root(ws_root_config));
223+
}
217224
let workspace_config = match (
218225
original_toml.workspace.as_ref(),
219226
original_toml.package().and_then(|p| p.workspace.as_ref()),

tests/testsuite/script.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1923,19 +1923,17 @@ members = [
19231923

19241924
p.cargo("-Zscript -v script/echo.rs")
19251925
.masquerade_as_nightly_cargo(&["script"])
1926-
.with_stdout_data(str![[r#""#]])
1926+
.with_stdout_data(str![[r#"
1927+
bin: [ROOT]/home/.cargo/target/[HASH]/debug/echo[EXE]
1928+
args: []
1929+
1930+
"#]])
19271931
.with_stderr_data(str![[r#"
19281932
[WARNING] `package.edition` is unspecified, defaulting to `2024`
1929-
[ERROR] failed to load manifest for workspace member `[ROOT]/foo/inner`
1930-
referenced by workspace at `[ROOT]/foo/Cargo.toml`
1931-
1932-
Caused by:
1933-
failed to parse manifest at `[ROOT]/foo/inner/Cargo.toml`
1934-
1935-
Caused by:
1936-
registry index was not found in any configuration: `test-reg`
1933+
[COMPILING] echo v0.0.0 ([ROOT]/foo/script/echo.rs)
1934+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1935+
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/echo[EXE]`
19371936
19381937
"#]])
1939-
.with_status(101)
19401938
.run();
19411939
}

0 commit comments

Comments
 (0)