Skip to content

Commit

Permalink
Revert "Fix diagnostics reporter main crates setup (#1514)" (#1540)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciektr authored Aug 26, 2024
1 parent 2fc6baf commit 569dde3
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 15 deletions.
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,9 +56,9 @@ impl Compiler for LibCompiler {

let target_dir = unit.target_dir(ws);

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

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

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

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,9 +227,9 @@ impl Compiler for StarknetContractCompiler {

let target_dir = unit.target_dir(ws);

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

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

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

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

diagnostics_reporter
.with_crates(&main_crate_ids)
Expand Down
4 changes: 1 addition & 3 deletions scarb/src/compiler/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ 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 @@ -44,8 +43,7 @@ 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: 2 additions & 3 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, collect_main_crate_ids};
use crate::compiler::helpers::build_compiler_config;
use crate::compiler::plugin::proc_macro;
use crate::compiler::{CairoCompilationUnit, CompilationUnit, CompilationUnitAttributes};
use crate::core::{
Expand Down Expand Up @@ -193,9 +193,8 @@ 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, &main_crate_ids, ws);
let mut compiler_config = build_compiler_config(&unit, 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
46 changes: 46 additions & 0 deletions scarb/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,52 @@ fn warnings_can_be_disallowed() {
}

#[test]
fn does_show_errors_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 {
;
12
}
"#})
.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(&second)
.assert()
.failure()
.stdout_matches(indoc! {r#"
[..]Compiling second v1.0.0 ([..]Scarb.toml)
error: Skipped tokens. Expected: statement.
--> [..]lib.cairo:2:5
;
^
error: could not compile `second` due to previous error
"#});
}

#[test]
#[ignore = "fix(maciektr): hide warnings from dependencies"]
fn does_not_show_warnings_from_deps() {
let t = TempDir::new().unwrap();
let first = t.child("first");
Expand Down

0 comments on commit 569dde3

Please sign in to comment.