Skip to content

Commit 9b625e7

Browse files
committed
console compiler: exit with error status on serious warnings
Non-serious warnings do not cause an error exit status. We can enable that behavior later with a flag if desired. Issue #1373
1 parent d61db5d commit 9b625e7

File tree

6 files changed

+50
-26
lines changed

6 files changed

+50
-26
lines changed

documentation/release-notes/source/2022.1.rst

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Compiler
3232
the :file:`sbin` (static executables binary) directory of the
3333
personal-root.
3434

35+
* To aid in scripting tasks the ``dylan-compiler`` and ``dylan-environment``
36+
executables now return an error exit status if any serious warnings are
37+
generated.
38+
3539
Tooling
3640
=======
3741

sources/environment/commands/build.dylan

+18-5
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ end command-line build;
205205

206206
define method do-execute-command
207207
(context :: <environment-context>, command :: <build-project-command>)
208-
=> ()
208+
=> (exit-code :: <integer>)
209209
let project = command.%project | context.context-project;
210210
let messages = if (command.%verbose?) #"internal" else #"external" end;
211211
let stream = context.context-server.server-output-stream;
@@ -217,7 +217,14 @@ define method do-execute-command
217217
else
218218
curry(note-build-progress, context, #f)
219219
end;
220+
let serious-warnings? = #f;
220221
block ()
222+
local method warning-callback (warning)
223+
note-compiler-warning(context, warning);
224+
if (instance?(warning, <serious-compiler-warning-object>))
225+
serious-warnings? := #t;
226+
end;
227+
end;
221228
if (build-project
222229
(project,
223230
process-subprojects?: command.%subprojects?,
@@ -228,7 +235,7 @@ define method do-execute-command
228235
output: command.%output,
229236
dispatch-coloring: command.%dispatch-coloring,
230237
progress-callback: progress-callback,
231-
warning-callback: curry(note-compiler-warning, context),
238+
warning-callback: warning-callback,
232239
error-handler: curry(compiler-condition-handler, context)))
233240
if (command.%link?)
234241
let project-context = context.context-project-context;
@@ -247,10 +254,16 @@ define method do-execute-command
247254
progress-callback: progress-callback,
248255
error-handler: curry(compiler-condition-handler, context))
249256
end;
250-
message(context, "Build of '%s' completed", project.project-name)
257+
message(context, "Build of '%s' completed", project.project-name);
258+
if (serious-warnings?)
259+
$error-exit-code
260+
else
261+
$success-exit-code
262+
end
251263
else
252-
message(context, "Build of '%s' aborted", project.project-name)
253-
end;
264+
message(context, "Build of '%s' aborted", project.project-name);
265+
$error-exit-code
266+
end
254267
exception (error :: <file-system-error>)
255268
command-error("%s", error)
256269
end

sources/environment/commands/command-line.dylan

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Warranty: Distributed WITHOUT WARRANTY OF ANY KIND
88

99
/// Useful constants
1010

11+
define constant $success-exit-code = 0;
12+
define constant $error-exit-code = -1;
13+
1114
define constant $whitespace = #[' ', '\t', '\n'];
1215
define constant $quote-characters = #['\'', '"'];
1316

sources/environment/commands/module.dylan

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ define module command-lines
8686
command-line-loop,
8787
display-command-prompt,
8888
execute-command-line,
89-
execute-server-command;
89+
execute-server-command,
90+
$error-exit-code,
91+
$success-exit-code;
9092

9193
// Command line user interface
9294
export command-line-choose-file,

sources/environment/console/command-line.dylan

+22-18
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ end class <basic-main-command>;
7777

7878
define method execute-main-command
7979
(context :: <server-context>, command :: <basic-main-command>)
80-
=> (status-code :: <integer>)
81-
local method run
82-
(class :: subclass(<command>), #rest arguments) => ()
80+
=> (exit-code :: <integer>)
81+
local method run (class :: subclass(<command>), #rest arguments)
82+
=> (#rest values)
8383
let command = apply(make, class, server: context, arguments);
8484
execute-command(command)
8585
end method run;
@@ -96,21 +96,25 @@ define method execute-main-command
9696
run(<open-project-command>, file: filename)
9797
end;
9898
let build? = command.%build?;
99+
let exit-code = #f;
99100
if (build? | command.%compile?)
100-
run(<build-project-command>,
101-
clean?: command.%clean?,
102-
link?: #f,
103-
release?: command.%release?,
104-
verbose?: command.%verbose?,
105-
subprojects: command.%subprojects?,
106-
output: begin
107-
let output = make(<stretchy-object-vector>);
108-
if (command.%assemble?) add!(output, #"assembler") end;
109-
if (command.%dfm?) add!(output, #"dfm") end;
110-
if (command.%harp?) add!(output, #"harp") end;
111-
output
112-
end,
113-
dispatch-coloring: command.%dispatch-coloring)
101+
// The build command returns an error status for serious warnings. This
102+
// makes it possible for scripting to abort on serious warnings.
103+
exit-code
104+
:= run(<build-project-command>,
105+
clean?: command.%clean?,
106+
link?: #f,
107+
release?: command.%release?,
108+
verbose?: command.%verbose?,
109+
subprojects: command.%subprojects?,
110+
output: begin
111+
let output = make(<stretchy-object-vector>);
112+
if (command.%assemble?) add!(output, #"assembler") end;
113+
if (command.%dfm?) add!(output, #"dfm") end;
114+
if (command.%harp?) add!(output, #"harp") end;
115+
output
116+
end,
117+
dispatch-coloring: command.%dispatch-coloring);
114118
end;
115119
if (build? | command.%link?)
116120
let target = command.%target;
@@ -123,7 +127,7 @@ define method execute-main-command
123127
subprojects: command.%subprojects?,
124128
unify?: command.%unify?)
125129
end;
126-
$success-exit-code;
130+
exit-code | $success-exit-code
127131
end method execute-main-command;
128132

129133
define method execute-main-loop

sources/environment/console/start.dylan

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc.
66
License: See License.txt in this distribution for details.
77
Warranty: Distributed WITHOUT WARRANTY OF ANY KIND
88

9-
define constant $success-exit-code = 0;
10-
define constant $error-exit-code = -1;
119

1210
define function main
1311
(arguments :: <string>)

0 commit comments

Comments
 (0)