Skip to content

Commit

Permalink
fix(developer): compiler crash when no project loaded
Browse files Browse the repository at this point in the history
Fixes #9889.

This arises from a deprecated way of using Keyman Developer by starting
Keyman Developer by opening a keyboard .kmn file from Explorer, which
causes Developer to run in a 'projectless' mode. This was not tested in
the new compiler integration, and that has caused this crash.

In 'projectless' mode, there is still a global 'untitled' project, but
the files loaded do not 'belong' to it. The compiler settings are
inherited from the global 'untitled' project in this case.
  • Loading branch information
mcdurdin committed Oct 30, 2023
1 parent d71686b commit f3e4507
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ implementation
System.Classes,
System.SysUtils,

Keyman.Developer.System.Project.Project,
Keyman.Developer.System.Project.ProjectLog,
Keyman.Developer.System.KeymanDeveloperPaths,
compile,
Expand Down Expand Up @@ -50,11 +51,11 @@ function TKmcWrapper.Compile(
cmdline := Format('"%s" build --log-format tsv --log-level info "%s"', [TKeymanDeveloperPaths.KmcPath, infile]);
if outfile <> '' then
cmdline := cmdline + Format(' --out-file "%s"', [outfile]);
if ProjectFile.Project.Options.CompilerWarningsAsErrors then
if FGlobalProject.Options.CompilerWarningsAsErrors then
cmdline := cmdline + ' --compiler-warnings-as-errors'
else
cmdline := cmdline + ' --no-compiler-warnings-as-errors';
if not ProjectFile.Project.Options.WarnDeprecatedCode then
if FGlobalProject.Options.WarnDeprecatedCode then
cmdline := cmdline + ' --no-warn-deprecated-code';

Result := TUtilExecute.Console(cmdline, ExtractFileDir(infile), logtext, ec);
Expand All @@ -63,8 +64,8 @@ function TKmcWrapper.Compile(

if not Result then
begin
ProjectFile.Project.Log(plsError, infile,
Format('Compiler failed to start with error %d: %s', [GetLastError, SysErrorMessage(GetLastError)]), CERR_ERROR, 0);
FGlobalProject.Log(plsError, infile,
Format('Compiler failed to start with error %d: %s', [GetLastError, SysErrorMessage(GetLastError)]), CERR_ERROR, 0);
end;

Result := Result and (ec = 0);
Expand Down Expand Up @@ -93,7 +94,7 @@ function TKmcWrapper.Compile(
else if msgType = 'warn' then
begin
state := plsWarning;
if ProjectFile.Project.Options.CompilerWarningsAsErrors then
if FGlobalProject.Options.CompilerWarningsAsErrors then
Result := False;
end
else if msgType = 'error' then
Expand All @@ -108,10 +109,10 @@ function TKmcWrapper.Compile(
end
else // assume msgType = 'info'
state := plsInfo;
ProjectFile.Project.Log(state, msgFilename, msgText, msgCode, msgLine);
FGlobalProject.Log(state, msgFilename, msgText, msgCode, msgLine);
end
else
ProjectFile.Project.Log(plsInfo, infile, line, 0, 0);
FGlobalProject.Log(plsInfo, infile, line, 0, 0);
end;
finally
s.Free;
Expand Down

0 comments on commit f3e4507

Please sign in to comment.