Skip to content

Commit

Permalink
Add warning on unset edition (#1663)
Browse files Browse the repository at this point in the history
Closes #1662
  • Loading branch information
DelevoXDG authored Oct 28, 2024
1 parent 49a2803 commit cfd945a
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 13 deletions.
15 changes: 12 additions & 3 deletions scarb/src/core/manifest/toml_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::core::manifest::{ManifestDependency, ManifestMetadata, Summary, Targe
use crate::core::package::PackageId;
use crate::core::source::{GitReference, SourceId};
use crate::core::{
DepKind, DependencyVersionReq, InliningStrategy, ManifestBuilder, ManifestCompilerConfig,
PackageName, TargetKind, TestTargetProps, TestTargetType,
Config, DepKind, DependencyVersionReq, InliningStrategy, ManifestBuilder,
ManifestCompilerConfig, PackageName, TargetKind, TestTargetProps, TestTargetType,
};
use crate::internal::fsx;
use crate::internal::fsx::PathBufUtf8Ext;
Expand Down Expand Up @@ -407,6 +407,7 @@ impl TomlManifest {
source_id: SourceId,
profile: Profile,
workspace_manifest: Option<&TomlManifest>,
config: &Config,
) -> Result<Manifest> {
let root = manifest_path
.parent()
Expand Down Expand Up @@ -582,7 +583,15 @@ impl TomlManifest {
.clone()
.map(|edition| edition.resolve("edition", || inheritable_package.edition()))
.transpose()?
.unwrap_or_default();
.unwrap_or_else(|| {
if !targets.iter().any(Target::is_cairo_plugin) {
config.ui().warn(format!(
"`edition` field not set in `[package]` section for package `{}`",
package_id.name
));
}
Edition::default()
});

// TODO (#1040): add checking for fields that are not present in ExperimentalFeaturesConfig
let experimental_features = package.experimental_features.clone();
Expand Down
2 changes: 2 additions & 0 deletions scarb/src/ops/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ fn read_workspace_root<'c>(
source_id,
config.profile(),
Some(&toml_manifest),
config,
)
.with_context(|| format!("failed to parse manifest at: {manifest_path}"))?;
let manifest = Box::new(manifest);
Expand Down Expand Up @@ -119,6 +120,7 @@ fn read_workspace_root<'c>(
source_id,
config.profile(),
Some(&toml_manifest),
config,
)
.with_context(|| format!("failed to parse manifest at: {manifest_path}"))?;
let manifest = Box::new(manifest);
Expand Down
37 changes: 37 additions & 0 deletions scarb/tests/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fn registry_with_version() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand All @@ -24,6 +25,7 @@ fn registry_with_version() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand All @@ -40,6 +42,7 @@ fn registry_with_caret_version_req() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand All @@ -48,6 +51,7 @@ fn registry_with_caret_version_req() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand All @@ -64,6 +68,7 @@ fn registry_without_version() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
"#})
.failure()
.stdout_matches(indoc! {r#"
Expand All @@ -80,11 +85,13 @@ fn no_dependencies_section() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
"#})
.output(indoc! {r#"
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = "1.0.0"
Expand All @@ -100,6 +107,7 @@ fn dry_run() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand Down Expand Up @@ -128,11 +136,13 @@ fn path() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
"#})
.output(indoc! {r#"
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = { path = "../dep" }
Expand All @@ -158,11 +168,13 @@ fn path_version() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
"#})
.output(indoc! {r#"
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = { version = "1.0.0", path = "../dep" }
Expand All @@ -188,11 +200,13 @@ fn runs_resolver_if_network_is_allowed() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
"#})
.output(indoc! {r#"
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = { version = "1.0.0", path = "../dep" }
Expand All @@ -212,11 +226,13 @@ fn git() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
"#})
.output(indoc! {r#"
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = { git = "https://example.com/" }
Expand All @@ -232,11 +248,13 @@ fn git_version() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
"#})
.output(indoc! {r#"
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = { version = "1.0.0", git = "https://example.com/" }
Expand All @@ -256,11 +274,13 @@ fn git_spec(what: &str) {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
"#})
.output(formatdoc! {r#"
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = {{ git = "https://example.com/", {what} = "abcd" }}
Expand All @@ -276,6 +296,7 @@ fn overwrite_registry_version() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = "1.0.0"
Expand All @@ -284,6 +305,7 @@ fn overwrite_registry_version() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = "2.0.0"
Expand All @@ -299,6 +321,7 @@ fn overwrite_registry_version_simplifies() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = { version = "1.0.0" }
Expand All @@ -307,6 +330,7 @@ fn overwrite_registry_version_simplifies() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = "2.0.0"
Expand Down Expand Up @@ -338,6 +362,7 @@ fn overwrite_change_source_from_path_to_git() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = { version = "1.2.3", path = "../dep" }
Expand All @@ -346,6 +371,7 @@ fn overwrite_change_source_from_path_to_git() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
dep = { version = "1.2.3", git = "https://example.com/", branch = "abc" }
Expand All @@ -361,6 +387,7 @@ fn should_sort_if_already_sorted() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand All @@ -371,6 +398,7 @@ fn should_sort_if_already_sorted() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand All @@ -386,6 +414,7 @@ fn should_sort_if_already_sorted() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand All @@ -397,6 +426,7 @@ fn should_sort_if_already_sorted() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand All @@ -413,6 +443,7 @@ fn should_sort_if_already_sorted() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand All @@ -425,6 +456,7 @@ fn should_sort_if_already_sorted() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand All @@ -445,6 +477,7 @@ fn should_not_sort_if_already_unsorted() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand All @@ -455,6 +488,7 @@ fn should_not_sort_if_already_unsorted() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dependencies]
bar = "1.0.0"
Expand All @@ -473,11 +507,13 @@ fn add_dev_dep() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
"#})
.output(indoc! {r#"
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
[dev-dependencies]
foo = "1.0.0"
Expand All @@ -493,6 +529,7 @@ fn add_git_dep_with_invalid_url() {
[package]
name = "hello"
version = "1.0.0"
edition = "2023_01"
"#})
.failure()
.stdout_matches(indoc! {r#"
Expand Down
Loading

0 comments on commit cfd945a

Please sign in to comment.