Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an error in scarb package with non-[lib] packages #856

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion scarb/src/ops/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::{Seek, SeekFrom, Write};

use anyhow::{bail, ensure, Context, Result};
use camino::Utf8PathBuf;
use indoc::{indoc, writedoc};
use indoc::{formatdoc, indoc, writedoc};

use crate::sources::client::PackageRepository;

Expand Down Expand Up @@ -192,6 +192,19 @@ fn list_one_impl(
}

fn prepare_archive_recipe(pkg: &Package, opts: &PackageOpts) -> Result<ArchiveRecipe> {
ensure!(
pkg.manifest.targets.iter().any(|x| x.is_lib()),
formatdoc!(
r#"
cannot archive package `{package_name}` without a `lib` target
help: add `[lib]` section to package manifest
--> Scarb.toml
+ [lib]
"#,
package_name = pkg.id.name,
)
);

let mut recipe = source_files(pkg)?;

// Sort the recipe before any checks, to ensure generated errors are reproducible.
Expand Down
25 changes: 25 additions & 0 deletions scarb/tests/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,3 +1039,28 @@ fn ignore_whitelist_pattern() {
src/lib.cairo
"#}));
}

#[test]
fn no_lib_target() {
let t = TempDir::new().unwrap();
ProjectBuilder::start()
.name("foo")
.version("1.0.0")
.manifest_extra(indoc! {r#"
[[target.starknet-contract]]
"#})
.build(&t);

Scarb::quick_snapbox()
.arg("package")
.current_dir(&t)
.assert()
.failure()
.stdout_matches(indoc! {r#"
[..] Packaging foo v1.0.0 [..]
error: cannot archive package `foo` without a `lib` target
help: add `[lib]` section to package manifest
--> Scarb.toml
+ [lib]
"#});
}