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

Fix diagnostics reporter main crates setup #1514

Merged
merged 1 commit into from
Aug 12, 2024
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
4 changes: 2 additions & 2 deletions scarb/src/compiler/compilers/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ impl Compiler for LibCompiler {

let target_dir = unit.target_dir(ws);

let compiler_config = build_compiler_config(&unit, ws);

let main_crate_ids = collect_main_crate_ids(&unit, db);

let compiler_config = build_compiler_config(&unit, &main_crate_ids, ws);

validate_compiler_config(db, &compiler_config, &unit, ws);

let sierra_program: VersionedProgram = {
Expand Down
4 changes: 2 additions & 2 deletions scarb/src/compiler/compilers/starknet_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ impl Compiler for StarknetContractCompiler {

let target_dir = unit.target_dir(ws);

let compiler_config = build_compiler_config(&unit, ws);

let main_crate_ids = collect_main_crate_ids(&unit, db);

let compiler_config = build_compiler_config(&unit, &main_crate_ids, ws);

let contracts = find_project_contracts(
db.upcast_mut(),
ws.config().ui(),
Expand Down
3 changes: 2 additions & 1 deletion scarb/src/compiler/compilers/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ impl Compiler for TestCompiler {
&& plugin.package.id.source_id == SourceId::for_std()
});

let diagnostics_reporter = build_compiler_config(&unit, ws).diagnostics_reporter;
let diagnostics_reporter =
build_compiler_config(&unit, &main_crate_ids, ws).diagnostics_reporter;

diagnostics_reporter
.with_crates(&main_crate_ids)
Expand Down
4 changes: 3 additions & 1 deletion scarb/src/compiler/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::flock::Filesystem;

pub fn build_compiler_config<'c>(
unit: &CairoCompilationUnit,
main_crate_ids: &[CrateId],
ws: &Workspace<'c>,
) -> CompilerConfig<'c> {
let diagnostics_reporter = DiagnosticsReporter::callback({
Expand Down Expand Up @@ -43,7 +44,8 @@ pub fn build_compiler_config<'c>(
}
};
}
});
})
.with_crates(main_crate_ids);
CompilerConfig {
diagnostics_reporter: if unit.compiler_config.allow_warnings {
diagnostics_reporter.allow_warnings()
Expand Down
5 changes: 3 additions & 2 deletions scarb/src/ops/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use scarb_ui::components::Status;
use scarb_ui::HumanDuration;

use crate::compiler::db::{build_scarb_root_database, has_starknet_plugin, ScarbDatabase};
use crate::compiler::helpers::build_compiler_config;
use crate::compiler::helpers::{build_compiler_config, collect_main_crate_ids};
use crate::compiler::plugin::proc_macro;
use crate::compiler::{CairoCompilationUnit, CompilationUnit, CompilationUnitAttributes};
use crate::core::{
Expand Down Expand Up @@ -193,8 +193,9 @@ fn check_unit(unit: CompilationUnit, ws: &Workspace<'_>) -> Result<()> {
CompilationUnit::ProcMacro(unit) => proc_macro::check_unit(unit, ws),
CompilationUnit::Cairo(unit) => {
let ScarbDatabase { db, .. } = build_scarb_root_database(&unit, ws)?;
let main_crate_ids = collect_main_crate_ids(&unit, &db);
check_starknet_dependency(&unit, ws, &db, &package_name);
let mut compiler_config = build_compiler_config(&unit, ws);
let mut compiler_config = build_compiler_config(&unit, &main_crate_ids, ws);
compiler_config
.diagnostics_reporter
.ensure(&db)
Expand Down
6 changes: 3 additions & 3 deletions scarb/src/ops/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ fn do_expand(
ws: &Workspace<'_>,
) -> Result<()> {
let ScarbDatabase { db, .. } = build_scarb_root_database(compilation_unit, ws)?;
let mut compiler_config = build_compiler_config(compilation_unit, ws);
// Report diagnostics, but do not fail.
let _ = compiler_config.diagnostics_reporter.check(&db);
let main_crate_id = db.intern_crate(CrateLongId::Real(
compilation_unit.main_component().cairo_package_name(),
));
let mut compiler_config = build_compiler_config(compilation_unit, &[main_crate_id], ws);
// Report diagnostics, but do not fail.
let _ = compiler_config.diagnostics_reporter.check(&db);
let main_module = ModuleId::CrateRoot(main_crate_id);
let module_file = db
.module_main_file(main_module)
Expand Down
51 changes: 51 additions & 0 deletions scarb/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,57 @@ fn warnings_can_be_disallowed() {
"#});
}

#[test]
fn does_not_show_warnings_from_deps() {
let t = TempDir::new().unwrap();
let first = t.child("first");
let second = t.child("second");
ProjectBuilder::start()
.name("first")
.lib_cairo(indoc! {r#"
fn hello() -> felt252 {
let a = 41;
let b = 42;
b
}
"#})
.manifest_extra(indoc! {r#"
[cairo]
allow-warnings = false
"#})
.build(&first);
ProjectBuilder::start()
.name("second")
.lib_cairo(indoc! {r#"
fn hello() -> felt252 { 42 }
"#})
.dep("first", &first)
.manifest_extra(indoc! {r#"
[cairo]
allow-warnings = false
"#})
.build(&second);
Scarb::quick_snapbox()
.arg("build")
.current_dir(&first)
.assert()
.failure()
.stdout_matches(indoc! {r#"
[..] Compiling [..] v1.0.0 ([..]Scarb.toml)
warn[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
--> [..]lib.cairo:2:9
let a = 41;
^

error: could not compile [..] due to previous error
"#});
Scarb::quick_snapbox()
.arg("build")
.current_dir(&second)
.assert()
.success();
}

#[test]
fn error_codes_shown_in_json_output() {
let t = TempDir::new().unwrap();
Expand Down
Loading