Skip to content
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
7 changes: 7 additions & 0 deletions changes/build-output-wording.polish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- The build system's messages read more consistently:
- counts use the singular for one (`Parsed 1 source file`, `Compiled 1 module`), and the cleanup step reports `Cleaned N stale modules`;
- a failed build ends with `Build failed: see the errors above.`, without a terminal escape sequence when redirected;
- a redirected one-shot build ends with `Finished compilation`, like watch mode;
- warnings and verbose logs are labeled inline (`warning: …`, `debug: …`, `trace: …`), and a missing source folder is a warning;
- parse errors no longer get an `Error in <package>:` header;
- compiler errors and warnings are uncolored when output is redirected or `NO_COLOR` is set.
14 changes: 4 additions & 10 deletions rewatch-ocaml/build.ml
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,17 @@ let run_with_warning_state ~poll ~warning_state ~request ~no_timing ~verbosity
if attempt.freshness_mode = Build_attempt.Initialize_freshness then
Source_dirs.write_build ~root_config attempt.session;
Build_report.report_failure report ~compile_seconds;
prerr_string output;
prerr_string (Output.compiler_output ~color:colors output);
prerr_newline ();
Build_attempt.cleanup_artifacts attempt;
raise
(Reported_failure
("Incremental build failed. Error: \027[2K\r Failed to Compile. "
^ "See Errors Above"))
raise (Reported_failure "Build failed: see the errors above.")
in
let report_parse_failure output =
Build_attempt.finalize_logs attempt;
Build_report.report_parse_failure report ~output;
Build_attempt.cleanup_artifacts attempt;
raise
(Reported_failure
"Incremental build failed. Error: \027[2K\r Could not parse Source \
Files")
(Reported_failure "Build failed: could not parse the source files above.")
in
let format_cycle cycle (by_key : (string, Module_graph.cycle_node) Hashtbl.t)
=
Expand Down Expand Up @@ -352,8 +347,7 @@ let run_with_warning_state ~poll ~warning_state ~request ~no_timing ~verbosity
(Output.compiler_cleanup_message ~color:colors ~step:"1/3");
print_endline
(Output.cleanup_message ~color:colors ~step:"1/3"
~cleaned:attempt.cleaned ~total:attempt.previous_asts
~seconds:(phase_seconds seconds))))
~cleaned:attempt.cleaned ~seconds:(phase_seconds seconds))))
in
(preparation.prepared, preparation.cycle)
in
Expand Down
9 changes: 1 addition & 8 deletions rewatch-ocaml/build_artifacts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ let generated_output_details_for_suffixes suffixes path =

type cleanup_result = {
removed_modules: string list;
previous_ast_count: int;
present_public_outputs: (string, unit) Hashtbl.t;
}

Expand Down Expand Up @@ -209,7 +208,6 @@ let cleanup_stale ~artifact_files ~ast_sources ~present_source_files
Config.namespace_compiler_name config.namespace
|> Option.iter (fun namespace ->
add_expected namespace [".cmi"; ".cmj"; ".cmt"; ".mlmap"]);
let previous_ast_count = ref 0 in
let removed_modules = ref [] in
artifact_files
|> List.iter (fun path ->
Expand All @@ -218,7 +216,6 @@ let cleanup_stale ~artifact_files ~ast_sources ~present_source_files
Filename.check_suffix basename ".ast"
|| Filename.check_suffix basename ".iast"
in
if is_ast then incr previous_ast_count;
if
Compile_assets.is_managed_basename basename
&& ((not (Hashtbl.mem expected_artifacts basename))
Expand All @@ -239,8 +236,4 @@ let cleanup_stale ~artifact_files ~ast_sources ~present_source_files
Hashtbl.remove present_public_outputs (path ^ ".map");
File_util.remove_file path;
File_util.remove_file (path ^ ".map"));
{
removed_modules = !removed_modules;
previous_ast_count = !previous_ast_count;
present_public_outputs;
}
{removed_modules = !removed_modules; present_public_outputs}
1 change: 0 additions & 1 deletion rewatch-ocaml/build_artifacts.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
type cleanup_result = {
removed_modules: string list;
previous_ast_count: int;
present_public_outputs: (string, unit) Hashtbl.t;
}
(** Artifact cleanup first classifies ownership and builds a deletion plan.
Expand Down
2 changes: 0 additions & 2 deletions rewatch-ocaml/build_attempt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type t = {
freshness_mode: freshness_mode;
session: Build_session.t;
mutable cleaned: int;
mutable previous_asts: int;
mutable parsed: int;
mutable compiled: int;
mutable parse_seconds: float;
Expand Down Expand Up @@ -64,7 +63,6 @@ let create ~freshness_mode ~session ~process_poll ~progress ~verbosity =
freshness_mode;
session;
cleaned = 0;
previous_asts = 0;
parsed = 0;
compiled = 0;
parse_seconds = 0.;
Expand Down
1 change: 0 additions & 1 deletion rewatch-ocaml/build_attempt.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type t = {
freshness_mode: freshness_mode;
session: Build_session.t;
mutable cleaned: int;
mutable previous_asts: int;
mutable parsed: int;
mutable compiled: int;
mutable parse_seconds: float;
Expand Down
2 changes: 1 addition & 1 deletion rewatch-ocaml/build_lock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let valid_owner value =

let malformed_error () =
Project_context.Error
"Could not start Rescript build: Could not parse lockfile PID\n\
"Could not start ReScript build: Could not parse lockfile PID\n\
\ (try removing it and running the command again)"

(* A writer that cannot link creates the lock and then writes its PID, so an
Expand Down
4 changes: 1 addition & 3 deletions rewatch-ocaml/build_preparation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ let run ~(root_config : Config.t) ~prod ~features ~warn_error ~filter ~watch
| None -> cleanup_stale package
in
Build_attempt.set_cleanup_result attempt package.root cleanup;
attempt.cleaned <- attempt.cleaned + List.length cleanup.removed_modules;
attempt.previous_asts <-
attempt.previous_asts + cleanup.previous_ast_count)
attempt.cleaned <- attempt.cleaned + List.length cleanup.removed_modules)
cleanups_before_clean;
let compile_assets =
if attempt.compiler_cleaned || Hashtbl.length attempt.removed_modules > 0
Expand Down
24 changes: 15 additions & 9 deletions rewatch-ocaml/build_report.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ let prepare report ~success ~compile_seconds =
else (
(match report.kind with
| One_shot | Initial_watch | Full_watch ->
Printf.printf "Cleaned %d/%d\n%!" attempt.cleaned attempt.previous_asts
Printf.printf "Cleaned %s\n%!"
(Output.stale_modules ~cleaned:attempt.cleaned)
| Incremental_watch -> ());
Printf.printf "Parsed %d source files\n%!" attempt.parsed;
if success then Printf.printf "Compiled %d modules\n%!" attempt.compiled
else Printf.eprintf "Compiled %d modules\n%!" attempt.compiled);
Printf.printf "Parsed %s\n%!"
(Output.count_of attempt.parsed "source file");
let compiled = Output.count_of attempt.compiled "module" in
if success then Printf.printf "Compiled %s\n%!" compiled
else Printf.eprintf "Compiled %s\n%!" compiled);
let diagnostics =
match report.kind with
| Incremental_watch | Full_watch -> []
Expand All @@ -62,13 +65,16 @@ let prepare report ~success ~compile_seconds =
Warning_state.entries (Build_session.warning_state attempt.session)
in
List.iter
(fun entry -> prerr_string entry.Warning_state.output)
(fun entry ->
prerr_string
(Output.compiler_output ~color:report.colors entry.Warning_state.output))
warning_entries;
if warning_entries <> [] then prerr_newline ();
flush stderr;
if diagnostics <> [] then
diagnostics
|> List.map (fun diagnostic ->
let diagnostic = String.trim diagnostic in
if report.colors then Output.yellow diagnostic else diagnostic)
|> String.concat "\n\n" |> prerr_endline;
diagnostics
Expand All @@ -87,7 +93,7 @@ let report_completion report diagnostics =
(Build_session.warning_state report.attempt.session)
<> [])
~seconds)
else if report.kind <> One_shot && report.show_progress then
else if report.show_progress then
Printf.printf "Finished %scompilation\n%!"
Comment thread
cknitt marked this conversation as resolved.
Resolved
(match report.kind with
| Initial_watch -> "initial "
Expand All @@ -111,7 +117,7 @@ let report_parse_failure report ~output =
else if report.show_progress then
match report.kind with
| One_shot | Initial_watch | Full_watch ->
Printf.printf "Cleaned %d/%d\n%!" report.attempt.cleaned
report.attempt.previous_asts
Printf.printf "Cleaned %s\n%!"
(Output.stale_modules ~cleaned:report.attempt.cleaned)
| Incremental_watch -> ());
prerr_endline output
prerr_endline (Output.compiler_output ~color:report.colors output)
4 changes: 3 additions & 1 deletion rewatch-ocaml/clean.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ let run ~poll ~verbosity ~folder ~prod =
else None)
|> String.concat ", "
in
let generated_files = suffixes ^ " files" in
let generated_files =
if suffixes = "" then "generated files" else suffixes ^ " files"
in
let generated_started = Unix.gettimeofday () in
print_cleaning ~step:"2/2" generated_files;
remove_generated_outputs cleanup;
Expand Down
4 changes: 2 additions & 2 deletions rewatch-ocaml/compiler_scheduler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ let run ~poll ~warning_state ~compile_assets ~build_state ~candidates
|> List.filter candidate_requires_compile
|> List.sort (fun first second -> String.compare first.key second.key)
|> List.iter (fun candidate ->
Printf.printf "compile dirty: %s\n%!" candidate.key);
Output.trace ~verbosity ("compile dirty: " ^ candidate.key));
(* The scheduler only needs dirty modules and their transitive dependents.
Dependencies outside that universe already have usable artifacts, while
keeping every module in the subprocess graph makes small edits scale with
Expand Down Expand Up @@ -401,7 +401,7 @@ let run ~poll ~warning_state ~compile_assets ~build_state ~candidates
in
Output.Progress.finish progress;
Output.trace ~verbosity
(Printf.sprintf "Compiled %d out of %d in the universe" !completed_modules
(Printf.sprintf "compiled %d of the %d modules to check" !completed_modules
(List.length scheduled_modules));
let failures =
scheduled_modules
Expand Down
2 changes: 1 addition & 1 deletion rewatch-ocaml/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ let load path =
|> List.map (fun field ->
Printf.sprintf
"The field '%s' found in the package config of '%s' is not \
supported by ReScript 12's new build system."
supported by the ReScript build system."
field name))
@ (unknown_fields fields
|> List.map (fun field ->
Expand Down
5 changes: 4 additions & 1 deletion rewatch-ocaml/format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ let format_files ?poll ~check files =
prerr_endline (format_check_summary (List.length !unformatted));
List.iter
(fun (path, message) ->
prerr_endline (formatting_error (display path) message))
prerr_endline
(Output.compiler_output
~color:(Output.colors_enabled ~interactive:(Unix.isatty Unix.stderr))
(formatting_error (display path) message)))
(List.sort compare !failures);
match (!failures, !unformatted) with
| [], [] -> ()
Expand Down
40 changes: 26 additions & 14 deletions rewatch-ocaml/output.ml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
let line_clear = "\027[2K\r"

(* [count_of 1 "module"] is "1 module", [count_of 2 "module"] "2 modules". *)
let count_of count noun =
Printf.sprintf "%d %s%s" count noun (if count = 1 then "" else "s")

(* Logs go to stdout by default. Commands whose stdout is machine-readable
output (compiler-args, format) log to stderr instead. *)
let log ?(channel = stdout) ~minimum ~verbosity ~label message =
if verbosity >= minimum then
Printf.fprintf channel "%s:\n%s\n%!" label message
if verbosity >= minimum then Printf.fprintf channel "%s: %s\n%!" label message

let debug ?channel ~verbosity message =
log ?channel ~minimum:1 ~verbosity ~label:"DEBUG" message
log ?channel ~minimum:1 ~verbosity ~label:"debug" message

let trace ?channel ~verbosity message =
log ?channel ~minimum:2 ~verbosity ~label:"TRACE" message
log ?channel ~minimum:2 ~verbosity ~label:"trace" message
let trace_enabled verbosity = verbosity >= 2

let format_step ~color step =
Expand Down Expand Up @@ -73,7 +76,7 @@ module Progress = struct
if verbosity >= 1 then (
let redraw = progress.enabled && Option.is_some progress.phase in
if redraw then Printf.printf "%s%!" line_clear;
log ~minimum:1 ~verbosity ~label:"DEBUG" message;
log ~minimum:1 ~verbosity ~label:"debug" message;
if redraw then draw ~force:true progress)

let start_grouped progress ~step ~symbol ~label groups =
Expand Down Expand Up @@ -157,9 +160,12 @@ let duration = function
| Some seconds -> Printf.sprintf " in %.2fs" seconds
| None -> ""

let cleanup_message ~color ~step ~cleaned ~total ~seconds =
Printf.sprintf "%s%s %sCleaned %d/%d%s" line_clear (format_step ~color step)
Platform.clean_symbol cleaned total (duration seconds)
(* What a build's cleanup step removed: the modules whose sources are gone. *)
let stale_modules ~cleaned = count_of cleaned "stale module"

let cleanup_message ~color ~step ~cleaned ~seconds =
Printf.sprintf "%s%s %sCleaned %s%s" line_clear (format_step ~color step)
Platform.clean_symbol (stale_modules ~cleaned) (duration seconds)

let compiler_cleanup_message ~color ~step =
Printf.sprintf "%s%s %sCleaned previous build due to compiler update"
Expand All @@ -174,20 +180,22 @@ let cleaned_command_message ~color ~step ~target ~seconds =
Platform.clean_symbol target (duration seconds)

let parsing_message ~color ~step ~count ~seconds =
Printf.sprintf "%s%s %sParsed %d source files%s" line_clear
(format_step ~color step) Platform.parse_symbol count (duration seconds)
Printf.sprintf "%s%s %sParsed %s%s" line_clear (format_step ~color step)
Platform.parse_symbol
(count_of count "source file")
(duration seconds)

let parsing_failed_message ~color ~step ~seconds =
Printf.sprintf "%s%s %sError parsing source files%s" line_clear
(format_step ~color step) Platform.error_symbol (duration seconds)

let compiling_message ~color ~step ~count ~seconds =
Printf.sprintf "%s%s %sCompiled %d modules%s" line_clear
(format_step ~color step) Platform.build_symbol count (duration seconds)
Printf.sprintf "%s%s %sCompiled %s%s" line_clear (format_step ~color step)
Platform.build_symbol (count_of count "module") (duration seconds)

let compilation_failed_message ~color ~step ~count ~seconds =
Printf.sprintf "%s%s %sCompiled %d modules%s" line_clear
(format_step ~color step) Platform.error_symbol count (duration seconds)
Printf.sprintf "%s%s %sCompiled %s%s" line_clear (format_step ~color step)
Platform.error_symbol (count_of count "module") (duration seconds)

type compilation_label = Standard | Initial | Incremental

Expand All @@ -207,3 +215,7 @@ let finished_compilation_message ~label ~warnings ~seconds =

let should_clear_screen ~clear_screen ~show_progress ~interactive =
clear_screen && show_progress && interactive

(* The compiler always colors its diagnostics, which stay colored in
.compiler.log for editors; printed, they follow the color policy. *)
let compiler_output ~color text = if color then text else strip_sgr text
14 changes: 8 additions & 6 deletions rewatch-ocaml/output.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ val colors_enabled_with :

val colors_enabled : interactive:bool -> bool
val strip_sgr : string -> string
val compiler_output : color:bool -> string -> string

val count_of : int -> string -> string
(** [count_of 1 "module"] is ["1 module"], [count_of 2 "module"]
["2 modules"]. *)

val stale_modules : cleaned:int -> string

val cleanup_message :
color:bool ->
step:string ->
cleaned:int ->
total:int ->
seconds:float option ->
string
color:bool -> step:string -> cleaned:int -> seconds:float option -> string

val compiler_cleanup_message : color:bool -> step:string -> string
val cleaning_command_message : color:bool -> step:string -> string -> string
Expand Down
9 changes: 4 additions & 5 deletions rewatch-ocaml/package_diagnostics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,16 @@ let report_missing_source_folder (config : Config.t) path =
else path
in
Printf.eprintf
"ERROR:\n\
Could not read folder: %S. Specified in dependency: %s, located %S...\n\
"warning: source folder %S of package %s (%s) does not exist or is not a \
folder\n\
%!"
relative config.name config.root

let report_missing_sources ~is_root (config : Config.t) =
if (not is_root) && not config.sources_defined then
Printf.eprintf
"WARN:\n\
Package '%s' has not defined any sources, but is not the root package. \
This is likely a mistake. It is located: %s\n\
"warning: package '%s' has not defined any sources, but is not the root \
package. This is likely a mistake. It is located: %s\n\
%!"
config.name config.root

Expand Down
2 changes: 1 addition & 1 deletion rewatch-ocaml/package_graph.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ let discover ~(root_config : Config.t) ~(workspace_config : Config.t) ~prod
~on_missing:(Package_diagnostics.report_missing_source_folder config)
~on_orphan:(fun path ->
Printf.eprintf
"\027[2K\r No implementation file found for interface file \
"warning: no implementation file found for interface file \
(skipping): %s\n\
%!"
path)
Expand Down
4 changes: 1 addition & 3 deletions rewatch-ocaml/package_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ let run ~(package : Package_plan.t) ~(prepared : Build_session.prepared)
match result with
| Build_attempt.Parse_failed {stdout; stderr} ->
Build_session.mark_parse_pending attempt.session pending_path;
let output =
Printf.sprintf "Error in %s:\n%s%s" config.name stderr stdout
in
let output = stderr ^ stdout in
Compiler_log.append root output;
attempt.parse_messages <-
Build_attempt.Parse_error output :: attempt.parse_messages
Expand Down
3 changes: 2 additions & 1 deletion rewatch-ocaml/package_resolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ let resolve resolution ~package_root (declaration : Config.dependency) =
&& not (Hashtbl.mem resolution.reported_duplicates key)
then (
Hashtbl.add resolution.reported_duplicates key ();
Printf.eprintf "Duplicated package: %s %s (chosen) vs %s in %s\n%!"
Printf.eprintf
"warning: duplicated package: %s %s (chosen) vs %s in %s\n%!"
declaration.name
(Project_context.display_path ~root:resolution.root_config.root
selected.directory)
Expand Down
Loading
Loading